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

Revision 13041, 2.2 kB (checked in by robert, 2 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/ParameterOutput>
15
16bool HeightFieldLayer_readLocalData(osg::Object &obj, osgDB::Input &fr);
17bool HeightFieldLayer_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
18
19REGISTER_DOTOSGWRAPPER(HeightFieldLayer_Proxy)
20(
21    new osgTerrain::HeightFieldLayer,
22    "HeightFieldLayer",
23    "Object Layer HeightFieldLayer",
24    HeightFieldLayer_readLocalData,
25    HeightFieldLayer_writeLocalData
26);
27
28bool HeightFieldLayer_readLocalData(osg::Object& obj, osgDB::Input &fr)
29{
30    osgTerrain::HeightFieldLayer& layer = static_cast<osgTerrain::HeightFieldLayer&>(obj);
31
32    bool itrAdvanced = false;
33
34    if (fr.matchSequence("file %w") || fr.matchSequence("file %s"))
35    {
36        std::string setname;
37        std::string filename;
38        osgTerrain::extractSetNameAndFileName(fr[1].getStr(),setname, filename);
39        if (!filename.empty())
40        {
41            osg::ref_ptr<osg::HeightField> hf = osgDB::readHeightFieldFile(filename);
42            if (hf.valid())
43            {
44                layer.setName(setname);
45                layer.setFileName(filename);
46                layer.setHeightField(hf.get());
47            }
48        }
49        fr += 2;
50        itrAdvanced = true;
51    }
52
53    osg::ref_ptr<osg::Object> readObject = fr.readObjectOfType(osgDB::type_wrapper<osg::HeightField>());
54    if (readObject.valid()) itrAdvanced = true;
55
56    osg::HeightField* hf = dynamic_cast<osg::HeightField*>(readObject.get());
57    if (hf)
58    {
59        layer.setHeightField(hf);
60    }
61
62    return itrAdvanced;
63}
64
65bool HeightFieldLayer_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
66{
67    const osgTerrain::HeightFieldLayer& layer = static_cast<const osgTerrain::HeightFieldLayer&>(obj);
68
69    if (!layer.getFileName().empty())
70    {
71        std::string str = osgTerrain::createCompoundSetNameAndFileName(layer.getName(), layer.getFileName());
72        fw.indent()<<"file "<< str << std::endl;
73    }
74    else
75    {
76        if (layer.getHeightField())
77        {
78            fw.writeObject(*layer.getHeightField());
79        }
80    }
81
82    return true;
83}
Note: See TracBrowser for help on using the browser.