root/OpenSceneGraph/trunk/src/osgWrappers/deprecated-dotosg/osgTerrain/ImageLayer.cpp @ 13041

Revision 13041, 2.1 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1#include <osgTerrain/Layer>
2
3#include <iostream>
4#include <string>
5
6#include <osg/Vec3>
7#include <osg/Vec4>
8#include <osg/io_utils>
9
10#include <osgDB/ReadFile>
11#include <osgDB/Registry>
12#include <osgDB/Input>
13#include <osgDB/Output>
14#include <osgDB/WriteFile>
15#include <osgDB/ParameterOutput>
16
17#include <osgTerrain/TerrainTile>
18
19bool ImageLayer_readLocalData(osg::Object &obj, osgDB::Input &fr);
20bool ImageLayer_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
21
22REGISTER_DOTOSGWRAPPER(ImageLayer_Proxy)
23(
24    new osgTerrain::ImageLayer,
25    "ImageLayer",
26    "Object Layer ImageLayer",
27    ImageLayer_readLocalData,
28    ImageLayer_writeLocalData
29);
30
31bool ImageLayer_readLocalData(osg::Object& obj, osgDB::Input &fr)
32{
33    osgTerrain::ImageLayer& layer = static_cast<osgTerrain::ImageLayer&>(obj);
34
35    bool itrAdvanced = false;
36
37    if (fr.matchSequence("file %w") || fr.matchSequence("file %s"))
38    {
39        std::string filename = fr[1].getStr();
40        if (!filename.empty())
41        {
42            bool deferExternalLayerLoading = osgTerrain::TerrainTile::getTileLoadedCallback().valid() ?
43                osgTerrain::TerrainTile::getTileLoadedCallback()->deferExternalLayerLoading() : false;
44
45            layer.setFileName(filename);
46
47            if (!deferExternalLayerLoading)
48            {
49                osg::ref_ptr<osg::Image> image = fr.readImage(filename.c_str());
50                if (image.valid())
51                {
52                    layer.setImage(image.get());
53                }
54            }
55        }
56
57        fr += 2;
58        itrAdvanced = true;
59    }
60
61
62    return itrAdvanced;
63}
64
65bool ImageLayer_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
66{
67    const osgTerrain::ImageLayer& layer = static_cast<const osgTerrain::ImageLayer&>(obj);
68
69    std::string fileName = layer.getFileName();
70
71    if (fw.getOutputTextureFiles())
72    {
73        if (fileName.empty())
74        {
75            fileName = fw.getTextureFileNameForOutput();
76        }
77        osgDB::writeImageFile(*layer.getImage(), fileName);
78    }
79    if (!fileName.empty())
80    {
81        fw.indent()<<"file "<< fw.wrapString(fileName) << std::endl;
82    }
83
84    return true;
85}
Note: See TracBrowser for help on using the browser.