~ubuntu-branches/debian/experimental/openscenegraph/experimental

« back to all changes in this revision

Viewing changes to OpenSceneGraph/src/osgPlugins/osgTerrain/HeightFieldLayer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alberto Luaces
  • Date: 2011-01-29 11:36:29 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20110129113629-qisrm2kdqlurc7t3
Tags: 2.9.11-1
* Removed bug-555869-ftbfs_with_binutils_gold.dpatch since upstream has
  already taken care of the issue.
* Removed bug-528229.dpatch since the pkgconfig files are now also split
  in upstream.
* Removed explicit dependency on GLU.
* Upstream no longer includes osgIntrospection (Closes: #592420).
* Disabled zip plugin as its implementation stores an embedded copy of
  zlib.
* Enabled Qt support. Thanks James Goppert.
* Enabled SVG and PDF plugins. Thanks James Goppert.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
bool HeightFieldLayer_readLocalData(osg::Object &obj, osgDB::Input &fr);
17
 
bool HeightFieldLayer_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
18
 
 
19
 
osgDB::RegisterDotOsgWrapperProxy HeightFieldLayer_Proxy
20
 
(
21
 
    new osgTerrain::HeightFieldLayer,
22
 
    "HeightFieldLayer",
23
 
    "Object Layer HeightFieldLayer",
24
 
    HeightFieldLayer_readLocalData,
25
 
    HeightFieldLayer_writeLocalData
26
 
);
27
 
 
28
 
bool 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
 
 
65
 
bool 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::createCompondSetNameAndFileName(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
 
}