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

Revision 13041, 5.4 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/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#include <osgTerrain/Layer>
15
16#include <iostream>
17#include <string>
18
19#include <osg/Vec3>
20#include <osg/Vec4>
21#include <osg/io_utils>
22
23#include <osgDB/ReadFile>
24#include <osgDB/Registry>
25#include <osgDB/Input>
26#include <osgDB/Output>
27#include <osgDB/ParameterOutput>
28
29bool CompositeLayer_readLocalData(osg::Object &obj, osgDB::Input &fr);
30bool CompositeLayer_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
31
32REGISTER_DOTOSGWRAPPER(CompositeLayer_Proxy)
33(
34    new osgTerrain::CompositeLayer,
35    "CompositeLayer",
36    "Object CompositeLayer Layer",
37    CompositeLayer_readLocalData,
38    CompositeLayer_writeLocalData
39);
40
41bool CompositeLayer_readLocalData(osg::Object& obj, osgDB::Input &fr)
42{
43    osgTerrain::CompositeLayer& layer = static_cast<osgTerrain::CompositeLayer&>(obj);
44
45    bool itrAdvanced = false;
46
47    osg::ref_ptr<osgTerrain::Locator> locator = 0;
48
49    do
50    {
51        itrAdvanced = false;
52
53        osg::ref_ptr<osg::Object> readObject = fr.readObjectOfType(osgDB::type_wrapper<osgTerrain::Locator>());
54        locator = dynamic_cast<osgTerrain::Locator*>(readObject.get());
55        if (readObject.valid()) itrAdvanced = true;
56
57        unsigned int minLevel=0;
58        if (fr.read("MinLevel",minLevel))
59        {
60            itrAdvanced = true;
61        }
62
63        unsigned int maxLevel = MAXIMUM_NUMBER_OF_LEVELS;
64        if (fr.read("MaxLevel",maxLevel))
65        {
66            itrAdvanced = true;
67        }
68
69        if (fr.matchSequence("file %s") || fr.matchSequence("file %w") )
70        {
71            layer.addLayer(fr[1].getStr());
72            fr += 2;
73
74            itrAdvanced = true;
75        }
76        else if (fr.matchSequence("ProxyLayer %s") || fr.matchSequence("ProxyLayer %w"))
77        {
78            std::string setname;
79            std::string filename;
80            osgTerrain::extractSetNameAndFileName(fr[1].getStr(),setname, filename);
81            if (!filename.empty())
82            {
83                osgTerrain::ProxyLayer* proxyLayer = new osgTerrain::ProxyLayer;
84                proxyLayer->setFileName(filename);
85                proxyLayer->setName(setname);
86
87                if (locator.valid()) proxyLayer->setLocator(locator.get());
88                if (minLevel!=0) proxyLayer->setMinLevel(minLevel);
89                if (maxLevel!=MAXIMUM_NUMBER_OF_LEVELS) proxyLayer->setMaxLevel(maxLevel);
90
91
92                layer.addLayer(proxyLayer);
93            }
94
95            fr += 2;
96
97            itrAdvanced = true;
98        }
99        else
100        {
101            osg::ref_ptr<osg::Object> readObject = fr.readObjectOfType(osgDB::type_wrapper<osgTerrain::Layer>());
102            osgTerrain::Layer* readLayer = dynamic_cast<osgTerrain::Layer*>(readObject.get());
103            if (readLayer)
104            {
105                if (locator.valid())
106                {
107                    readLayer->setLocator(locator.get());
108                    locator = 0;
109                }
110
111                if (minLevel!=0) readLayer->setMinLevel(minLevel);
112                if (maxLevel!=MAXIMUM_NUMBER_OF_LEVELS) readLayer->setMaxLevel(maxLevel);
113
114                layer.addLayer(readLayer);
115            }
116
117            if (readObject.valid()) itrAdvanced = true;
118        }
119
120    } while (itrAdvanced);
121
122    if (locator.valid()) layer.setLocator(locator.get());
123
124    return itrAdvanced;
125}
126
127bool CompositeLayer_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
128{
129    const osgTerrain::CompositeLayer& layer = static_cast<const osgTerrain::CompositeLayer&>(obj);
130
131    for(unsigned int i=0; i<layer.getNumLayers();++i)
132    {
133        if (layer.getLayer(i))
134        {
135            const osgTerrain::ProxyLayer* proxyLayer = dynamic_cast<const osgTerrain::ProxyLayer*>(layer.getLayer(i));
136            if (proxyLayer)
137            {
138                if (!proxyLayer->getFileName().empty())
139                {
140                    const osgTerrain::Locator* locator = proxyLayer->getLocator();
141                    if (locator && !locator->getDefinedInFile())
142                    {
143                        fw.writeObject(*locator);
144                    }
145
146                    if (proxyLayer->getMinLevel()!=0)
147                    {
148                        fw.indent()<<"MinLevel "<<proxyLayer->getMinLevel()<<std::endl;
149                    }
150
151                    if (proxyLayer->getMaxLevel()!=MAXIMUM_NUMBER_OF_LEVELS)
152                    {
153                        fw.indent()<<"MaxLevel "<<proxyLayer->getMaxLevel()<<std::endl;
154                    }
155
156                    fw.indent()<<"ProxyLayer "<<proxyLayer->getCompoundName()<<std::endl;
157                }
158            }
159            else
160            {
161                fw.writeObject(*(layer.getLayer(i)));
162            }
163        }
164        else if (!layer.getFileName(i).empty())
165        {
166            fw.indent()<<"file "<<layer.getCompoundName(i)<<std::endl;
167        }
168    }
169
170
171
172    return true;
173}
Note: See TracBrowser for help on using the browser.