root/OpenSceneGraph/trunk/src/osgPlugins/osgTerrain/ImageLayer.cpp @ 8840

Revision 8840, 1.9 kB (checked in by robert, 6 years ago)

Introduced TerrainTile::TileLoadedCallback?

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/ParameterOutput>
15
16#include <osgTerrain/TerrainTile>
17
18bool ImageLayer_readLocalData(osg::Object &obj, osgDB::Input &fr);
19bool ImageLayer_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
20
21osgDB::RegisterDotOsgWrapperProxy ImageLayer_Proxy
22(
23    new osgTerrain::ImageLayer,
24    "ImageLayer",
25    "Object Layer ImageLayer",
26    ImageLayer_readLocalData,
27    ImageLayer_writeLocalData
28);
29
30bool ImageLayer_readLocalData(osg::Object& obj, osgDB::Input &fr)
31{
32    osgTerrain::ImageLayer& layer = static_cast<osgTerrain::ImageLayer&>(obj);
33
34    bool itrAdvanced = false;
35   
36    if (fr.matchSequence("file %w") || fr.matchSequence("file %s"))
37    {
38        std::string filename = fr[1].getStr();
39        if (!filename.empty())
40        {
41            bool deferExternalLayerLoading = osgTerrain::TerrainTile::getTileLoadedCallback().valid() ?
42                osgTerrain::TerrainTile::getTileLoadedCallback()->deferExternalLayerLoading() : false;
43
44            layer.setFileName(filename);
45
46            if (!deferExternalLayerLoading)
47            {
48                osg::ref_ptr<osg::Image> image = fr.readImage(filename.c_str());
49                if (image.valid())
50                {
51                    layer.setImage(image.get());
52                }
53            }
54        }
55       
56        fr += 2;
57        itrAdvanced = true;
58    }
59   
60
61    return itrAdvanced;
62}
63
64bool ImageLayer_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
65{
66    const osgTerrain::ImageLayer& layer = static_cast<const osgTerrain::ImageLayer&>(obj);
67   
68    if (!layer.getFileName().empty())
69    {
70        fw.indent()<<"file "<< layer.getFileName() << std::endl;
71    }
72
73    return true;
74}
Note: See TracBrowser for help on using the browser.