Renamed osgTerrain::TerrainNode to osgTerrain::Terrain and introduced basic

.osg read support for osgTerrain::Terrain.
This commit is contained in:
Robert Osfield
2007-08-07 19:53:57 +00:00
parent 1fc50423c6
commit 1c6193ba78
10 changed files with 381 additions and 373 deletions

View File

@@ -47,7 +47,7 @@
#include <osgGA/AnimationPathManipulator>
#include <osgGA/TerrainManipulator>
#include <osgTerrain/TerrainNode>
#include <osgTerrain/Terrain>
#include <osgTerrain/GeometryTechnique>
#include <osgTerrain/Layer>
@@ -672,7 +672,7 @@ int main(int argc, char** argv)
}
osg::ref_ptr<osgTerrain::TerrainNode> terrain = new osgTerrain::TerrainNode;
osg::ref_ptr<osgTerrain::Terrain> terrain = new osgTerrain::Terrain;
osg::ref_ptr<osgTerrain::Locator> locator = new osgTerrain::EllipsoidLocator(-osg::PI, -osg::PI*0.5, 2.0*osg::PI, osg::PI, 0.0);
osg::ref_ptr<osgTerrain::ValidDataOperator> validDataOperator = new osgTerrain::NoDataValue(0.0);
osg::ref_ptr<osgTerrain::Layer> lastAppliedLayer;
@@ -834,12 +834,12 @@ int main(int argc, char** argv)
if (filterName=="NEAREST")
{
osg::notify(osg::NOTICE)<<"--filter "<<filterName<<std::endl;
terrain->setColorFilter(layerNum, osgTerrain::TerrainNode::NEAREST);
terrain->setColorFilter(layerNum, osgTerrain::Terrain::NEAREST);
}
else if (filterName=="LINEAR")
{
osg::notify(osg::NOTICE)<<"--filter "<<filterName<<std::endl;
terrain->setColorFilter(layerNum, osgTerrain::TerrainNode::LINEAR);
terrain->setColorFilter(layerNum, osgTerrain::Terrain::LINEAR);
}
else
{

View File

@@ -11,8 +11,8 @@
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGTERRAIN_TERRAINNODE
#define OSGTERRAIN_TERRAINNODE 1
#ifndef OSGTERRAIN_TERRAIN
#define OSGTERRAIN_TERRAIN 1
#include <osg/Group>
#include <osg/CoordinateSystemNode>
@@ -26,16 +26,16 @@ namespace osgTerrain {
/** Terrain provides a framework for loosly coupling height field data with height rendering algorithms.
* This allows TerrainTechnique's to be pluged in at runtime.*/
class OSGTERRAIN_EXPORT TerrainNode : public osg::Group
class OSGTERRAIN_EXPORT Terrain : public osg::Group
{
public:
TerrainNode();
Terrain();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
TerrainNode(const TerrainNode&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
Terrain(const Terrain&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
META_Node(osgTerrain, TerrainNode);
META_Node(osgTerrain, Terrain);
virtual void traverse(osg::NodeVisitor& nv);
@@ -135,7 +135,7 @@ class OSGTERRAIN_EXPORT TerrainNode : public osg::Group
protected:
virtual ~TerrainNode();
virtual ~Terrain();
struct LayerData
{

View File

@@ -11,8 +11,8 @@
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGTERRAIN_TERRAINTECHNIQUE
#define OSGTERRAIN_TERRAINTECHNIQUE 1
#ifndef OSGTERRAIN_terrainTECHNIQUE
#define OSGTERRAIN_terrainTECHNIQUE 1
#include <osg/Object>
@@ -23,7 +23,7 @@
namespace osgTerrain {
class TerrainNode;
class Terrain;
class OSGTERRAIN_EXPORT TerrainTechnique : public osg::Object
{
@@ -36,8 +36,8 @@ class OSGTERRAIN_EXPORT TerrainTechnique : public osg::Object
META_Object(osgTerrain, TerrainTechnique);
TerrainNode* getTerrainNode() { return _terrainNode; }
const TerrainNode* getTerrainNode() const { return _terrainNode; }
Terrain* getTerrain() { return _terrain; }
const Terrain* getTerrain() const { return _terrain; }
virtual void init();
@@ -61,9 +61,9 @@ class OSGTERRAIN_EXPORT TerrainTechnique : public osg::Object
virtual ~TerrainTechnique();
friend class osgTerrain::TerrainNode;
friend class osgTerrain::Terrain;
TerrainNode* _terrainNode;
Terrain* _terrain;
bool _dirty;
};

View File

@@ -2,9 +2,12 @@
SET(TARGET_SRC
Terrain.cpp
ReaderWriterOsgTerrain.cpp
)
SET(TARGET_ADDED_LIBRARIES osgTerrain )
#### end var setup ###
SETUP_PLUGIN(osgTerrain)

View File

@@ -50,332 +50,52 @@ class ReaderWriterTerrain : public osgDB::ReaderWriter
return 0L;
}
virtual osgDB::ReaderWriter::ReadResult readNode(std::istream& fin, const Options* options) const;
osg::Node* readTerrainNode(osgDB::Input& fr) const;
osgTerrain::Layer* readLayer(osgDB::Input& fr) const;
osg::TransferFunction* readTransferFunction(osgDB::Input& fr) const;
virtual osgDB::ReaderWriter::ReadResult readNode(std::istream& fin, const Options* options) const
{
fin.imbue(std::locale::classic());
osgDB::Input fr;
fr.attach(&fin);
fr.setOptions(options);
osg::ref_ptr<osg::Group> group = new osg::Group;
while(!fr.eof())
{
bool itrAdvanced = false;
if (fr.matchSequence("file %s") || fr.matchSequence("file %w") )
{
osg::Node* node = osgDB::readNodeFile(fr[1].getStr());
if (node) group->addChild(node);
fr += 2;
itrAdvanced = true;
}
osg::ref_ptr<osg::Node> node = fr.readNode();
if (node.valid())
{
group->addChild(node.get());
itrAdvanced = true;
}
if (!itrAdvanced)
{
if (fr[0].getStr()) osg::notify(osg::NOTICE)<<"Terrain file - unreconised token : "<<fr[0].getStr() <<""<< std::endl;
++fr;
}
}
if (group->getNumChildren()>0) return group.release();
else return 0;
}
};
osgDB::ReaderWriter::ReadResult ReaderWriterTerrain::readNode(std::istream& fin, const osgDB::ReaderWriter::Options* options) const
{
fin.imbue(std::locale::classic());
osgDB::Input fr;
fr.attach(&fin);
fr.setOptions(options);
osg::ref_ptr<osg::Group> group = new osg::Group;
while(!fr.eof())
{
bool itrAdvanced = false;
if (fr.matchSequence("file %s") || fr.matchSequence("file %w") )
{
osg::Node* node = osgDB::readNodeFile(fr[1].getStr());
if (node) group->addChild(node);
fr += 2;
itrAdvanced = true;
}
if (fr.matchSequence("TerrainNode {") || fr.matchSequence("Terrain {") )
{
osg::Node* node = readTerrainNode(fr);
if (node) group->addChild(node);
itrAdvanced = true;
}
if (!itrAdvanced)
{
if (fr[0].getStr()) osg::notify(osg::NOTICE)<<"Terrain file - unreconised token : "<<fr[0].getStr() <<""<< std::endl;
++fr;
}
}
if (group->getNumChildren()>0) return group.release();
else return 0;
}
osg::Node* ReaderWriterTerrain::readTerrainNode(osgDB::Input& fr) const
{
osg::ref_ptr<osgTerrain::TerrainNode> terrain = new osgTerrain::TerrainNode;
int entry = fr[0].getNoNestedBrackets();
fr += 2;
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{
bool itrAdvanced = false;
if (fr.matchSequence("Name %s") || fr.matchSequence("Name %w") ||
fr.matchSequence("name %s") || fr.matchSequence("name %w") )
{
terrain->setName(fr[1].getStr());
fr += 2;
itrAdvanced = true;
}
if (fr.matchSequence("ElevationLayer {"))
{
osgTerrain::Layer* layer = readLayer(fr);
if (layer) terrain->setElevationLayer(layer);
itrAdvanced = true;
}
bool firstMatched = false;
if ((firstMatched = fr.matchSequence("ColorLayer %i {")) || fr.matchSequence("ColorLayer {") )
{
unsigned int layerNum = 0;
if (firstMatched)
{
fr[1].getUInt(layerNum);
++fr;
}
osgTerrain::Layer* layer = readLayer(fr);
if (layer) terrain->setColorLayer(layerNum, layer);
itrAdvanced = true;
}
if ((firstMatched = fr.matchSequence("ColorTransferFunction %i {")) || fr.matchSequence("ColorTransferFunction {") )
{
unsigned int layerNum = 0;
if (firstMatched)
{
fr[1].getUInt(layerNum);
++fr;
}
osg::TransferFunction* tf = readTransferFunction(fr);
if (tf) terrain->setColorTransferFunction(layerNum, tf);
itrAdvanced = true;
}
if (fr[0].matchWord("ColorFilter"))
{
unsigned int layerNum = 0;
if (fr.matchSequence("ColorFilter %i"))
{
fr[1].getUInt(layerNum);
fr += 2;
}
else
{
++fr;
}
if (fr[0].matchWord("NEAREST")) terrain->setColorFilter(layerNum, osgTerrain::TerrainNode::NEAREST);
else if (fr[0].matchWord("LINEAR")) terrain->setColorFilter(layerNum, osgTerrain::TerrainNode::LINEAR);
++fr;
itrAdvanced = true;
}
if (!itrAdvanced)
{
if (fr[0].getStr()) osg::notify(osg::NOTICE)<<"Terrain - unreconised token : ["<<fr[0].getStr() <<"]"<< std::endl;
++fr;
}
}
// step over trailing }
++fr;
terrain->setTerrainTechnique(new osgTerrain::GeometryTechnique);
return terrain.release();
}
osgTerrain::Layer* ReaderWriterTerrain::readLayer(osgDB::Input& fr) const
{
osg::ref_ptr<osgTerrain::Layer> layer;
osg::ref_ptr<osgTerrain::Locator> locator;
int entry = fr[0].getNoNestedBrackets();
fr += 2;
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{
bool itrAdvanced = false;
if (fr.matchSequence("Image %w") || fr.matchSequence("image %w") ||
fr.matchSequence("Image %s") || fr.matchSequence("image %s"))
{
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(fr[1].getStr());
if (image.valid())
{
osg::ref_ptr<osgTerrain::ImageLayer> imagelayer = new osgTerrain::ImageLayer;
imagelayer->setImage(image.get());
layer = imagelayer.get();
}
fr += 2;
itrAdvanced = true;
}
if (fr.matchSequence("HeightField %w") || fr.matchSequence("HeightField %s"))
{
osg::ref_ptr<osg::HeightField> hf = osgDB::readHeightFieldFile(fr[1].getStr());
if (hf.valid())
{
osg::ref_ptr<osgTerrain::HeightFieldLayer> hflayer = new osgTerrain::HeightFieldLayer;
hflayer->setHeightField(hf.get());
layer = hflayer.get();
}
fr += 2;
itrAdvanced = true;
}
if (fr.matchSequence("EllipsoidLocator %f %f %f %f"))
{
double x,y,w,h;
fr[1].getFloat(x);
fr[2].getFloat(y);
fr[3].getFloat(w);
fr[4].getFloat(h);
locator = new osgTerrain::EllipsoidLocator(x,y,w,h,0);
fr += 5;
itrAdvanced = true;
}
if (fr.matchSequence("CartesianLocator %f %f %f %f"))
{
double x,y,w,h;
fr[1].getFloat(x);
fr[2].getFloat(y);
fr[3].getFloat(w);
fr[4].getFloat(h);
locator = new osgTerrain::CartesianLocator(x,y,w,h,0);
fr += 5;
itrAdvanced = true;
}
if (!itrAdvanced)
{
if (fr[0].getStr()) osg::notify(osg::NOTICE)<<"Layer - unreconised token : "<<fr[0].getStr() << std::endl;
++fr;
}
}
// step over trailing }
++fr;
if (layer.valid() && locator.valid())
{
layer->setLocator(locator.get());
}
return layer.release();
}
osg::TransferFunction* ReaderWriterTerrain::readTransferFunction(osgDB::Input& fr) const
{
osg::ref_ptr<osg::TransferFunction1D> tf = new osg::TransferFunction1D;
int entry = fr[0].getNoNestedBrackets();
fr += 2;
std::vector<osg::Vec4> colours;
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{
bool itrAdvanced = false;
if (fr.matchSequence("range %f %f"))
{
float minValue,maxValue;
fr[1].getFloat(minValue);
fr[2].getFloat(maxValue);
tf->setInputRange(minValue,maxValue);
fr += 3;
itrAdvanced = true;
}
if (fr.matchSequence("color %f %f %f %f"))
{
float r,g,b,a;
fr[1].getFloat(r);
fr[2].getFloat(g);
fr[3].getFloat(b);
fr[4].getFloat(a);
colours.push_back(osg::Vec4(r,g,b,a));
fr += 5;
itrAdvanced = true;
}
if (fr.matchSequence("color %f %f %f"))
{
float r,g,b;
fr[1].getFloat(r);
fr[2].getFloat(g);
fr[3].getFloat(b);
colours.push_back(osg::Vec4(r,g,b,1.0f));
fr += 5;
itrAdvanced = true;
}
if (!itrAdvanced)
{
if (fr[0].getStr()) osg::notify(osg::NOTICE)<<"TransferFunction - unreconised token : "<<fr[0].getStr() << std::endl;
++fr;
}
}
// step over trailing }
++fr;
if (!colours.empty())
{
tf->allocate(colours.size());
for(unsigned int i=0; i<colours.size(); ++i)
{
tf->setValue(i, colours[i]);
}
}
if (tf->getNumberCellsX()==0)
{
tf->allocate(6);
tf->setValue(0, osg::Vec4(1.0,1.0,1.0,1.0));
tf->setValue(1, osg::Vec4(1.0,0.0,1.0,1.0));
tf->setValue(2, osg::Vec4(1.0,0.0,0.0,1.0));
tf->setValue(3, osg::Vec4(1.0,1.0,0.0,1.0));
tf->setValue(4, osg::Vec4(0.0,1.0,1.0,1.0));
tf->setValue(5, osg::Vec4(0.0,1.0,0.0,1.0));
}
return tf.release();
}
// now register with Registry to instantiate the above
// reader/writer.
REGISTER_OSGPLUGIN(terrain, ReaderWriterTerrain)

View File

@@ -0,0 +1,284 @@
#include <osgTerrain/Terrain>
#include <osgTerrain/GeometryTechnique>
#include <iostream>
#include <string>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/io_utils>
#include <osgDB/ReadFile>
#include <osgDB/Registry>
#include <osgDB/Input>
#include <osgDB/Output>
#include <osgDB/ParameterOutput>
bool Terrain_readLocalData(osg::Object &obj, osgDB::Input &fr);
bool Terrain_writeLocalData(const osg::Object &obj, osgDB::Output &fw);
osgDB::RegisterDotOsgWrapperProxy Terrain_Proxy
(
new osgTerrain::Terrain,
"Terrain",
"Object Terrain Group ",
Terrain_readLocalData,
Terrain_writeLocalData
);
osgTerrain::Layer* readLayer(osgDB::Input& fr)
{
osg::ref_ptr<osgTerrain::Layer> layer;
osg::ref_ptr<osgTerrain::Locator> locator;
int entry = fr[0].getNoNestedBrackets();
fr += 2;
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{
bool itrAdvanced = false;
if (fr.matchSequence("Image %w") || fr.matchSequence("image %w") ||
fr.matchSequence("Image %s") || fr.matchSequence("image %s"))
{
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(fr[1].getStr());
if (image.valid())
{
osg::ref_ptr<osgTerrain::ImageLayer> imagelayer = new osgTerrain::ImageLayer;
imagelayer->setImage(image.get());
layer = imagelayer.get();
}
fr += 2;
itrAdvanced = true;
}
if (fr.matchSequence("HeightField %w") || fr.matchSequence("HeightField %s"))
{
osg::ref_ptr<osg::HeightField> hf = osgDB::readHeightFieldFile(fr[1].getStr());
if (hf.valid())
{
osg::ref_ptr<osgTerrain::HeightFieldLayer> hflayer = new osgTerrain::HeightFieldLayer;
hflayer->setHeightField(hf.get());
layer = hflayer.get();
}
fr += 2;
itrAdvanced = true;
}
if (fr.matchSequence("EllipsoidLocator %f %f %f %f"))
{
double x,y,w,h;
fr[1].getFloat(x);
fr[2].getFloat(y);
fr[3].getFloat(w);
fr[4].getFloat(h);
locator = new osgTerrain::EllipsoidLocator(x,y,w,h,0);
fr += 5;
itrAdvanced = true;
}
if (fr.matchSequence("CartesianLocator %f %f %f %f"))
{
double x,y,w,h;
fr[1].getFloat(x);
fr[2].getFloat(y);
fr[3].getFloat(w);
fr[4].getFloat(h);
locator = new osgTerrain::CartesianLocator(x,y,w,h,0);
fr += 5;
itrAdvanced = true;
}
if (!itrAdvanced)
{
if (fr[0].getStr()) osg::notify(osg::NOTICE)<<"Layer - unreconised token : "<<fr[0].getStr() << std::endl;
++fr;
}
}
// step over trailing }
++fr;
if (layer.valid() && locator.valid())
{
layer->setLocator(locator.get());
}
return layer.release();
}
osg::TransferFunction* readTransferFunction(osgDB::Input& fr)
{
osg::ref_ptr<osg::TransferFunction1D> tf = new osg::TransferFunction1D;
int entry = fr[0].getNoNestedBrackets();
fr += 2;
std::vector<osg::Vec4> colours;
while (!fr.eof() && fr[0].getNoNestedBrackets()>entry)
{
bool itrAdvanced = false;
if (fr.matchSequence("range %f %f"))
{
float minValue,maxValue;
fr[1].getFloat(minValue);
fr[2].getFloat(maxValue);
tf->setInputRange(minValue,maxValue);
fr += 3;
itrAdvanced = true;
}
if (fr.matchSequence("color %f %f %f %f"))
{
float r,g,b,a;
fr[1].getFloat(r);
fr[2].getFloat(g);
fr[3].getFloat(b);
fr[4].getFloat(a);
colours.push_back(osg::Vec4(r,g,b,a));
fr += 5;
itrAdvanced = true;
}
if (fr.matchSequence("color %f %f %f"))
{
float r,g,b;
fr[1].getFloat(r);
fr[2].getFloat(g);
fr[3].getFloat(b);
colours.push_back(osg::Vec4(r,g,b,1.0f));
fr += 5;
itrAdvanced = true;
}
if (!itrAdvanced)
{
if (fr[0].getStr()) osg::notify(osg::NOTICE)<<"TransferFunction - unreconised token : "<<fr[0].getStr() << std::endl;
++fr;
}
}
// step over trailing }
++fr;
if (!colours.empty())
{
tf->allocate(colours.size());
for(unsigned int i=0; i<colours.size(); ++i)
{
tf->setValue(i, colours[i]);
}
}
if (tf->getNumberCellsX()==0)
{
tf->allocate(6);
tf->setValue(0, osg::Vec4(1.0,1.0,1.0,1.0));
tf->setValue(1, osg::Vec4(1.0,0.0,1.0,1.0));
tf->setValue(2, osg::Vec4(1.0,0.0,0.0,1.0));
tf->setValue(3, osg::Vec4(1.0,1.0,0.0,1.0));
tf->setValue(4, osg::Vec4(0.0,1.0,1.0,1.0));
tf->setValue(5, osg::Vec4(0.0,1.0,0.0,1.0));
}
return tf.release();
}
bool Terrain_readLocalData(osg::Object& obj, osgDB::Input &fr)
{
osgTerrain::Terrain& terrain = static_cast<osgTerrain::Terrain&>(obj);
bool itrAdvanced = false;
if (fr.matchSequence("ElevationLayer {"))
{
osgTerrain::Layer* layer = readLayer(fr);
if (layer) terrain.setElevationLayer(layer);
itrAdvanced = true;
}
bool firstMatched = false;
if ((firstMatched = fr.matchSequence("ColorLayer %i {")) || fr.matchSequence("ColorLayer {") )
{
unsigned int layerNum = 0;
if (firstMatched)
{
fr[1].getUInt(layerNum);
++fr;
}
osgTerrain::Layer* layer = readLayer(fr);
if (layer) terrain.setColorLayer(layerNum, layer);
itrAdvanced = true;
}
if ((firstMatched = fr.matchSequence("ColorTransferFunction %i {")) || fr.matchSequence("ColorTransferFunction {") )
{
unsigned int layerNum = 0;
if (firstMatched)
{
fr[1].getUInt(layerNum);
++fr;
}
osg::TransferFunction* tf = readTransferFunction(fr);
if (tf) terrain.setColorTransferFunction(layerNum, tf);
itrAdvanced = true;
}
if (fr[0].matchWord("ColorFilter"))
{
unsigned int layerNum = 0;
if (fr.matchSequence("ColorFilter %i"))
{
fr[1].getUInt(layerNum);
fr += 2;
}
else
{
++fr;
}
if (fr[0].matchWord("NEAREST")) terrain.setColorFilter(layerNum, osgTerrain::Terrain::NEAREST);
else if (fr[0].matchWord("LINEAR")) terrain.setColorFilter(layerNum, osgTerrain::Terrain::LINEAR);
++fr;
itrAdvanced = true;
}
if (!(terrain.getTerrainTechnique()))
{
terrain.setTerrainTechnique(new osgTerrain::GeometryTechnique);
}
return itrAdvanced;
}
bool Terrain_writeLocalData(const osg::Object& obj, osgDB::Output& fw)
{
const osgTerrain::Terrain& terrain = static_cast<const osgTerrain::Terrain&>(obj);
return true;
}

View File

@@ -10,6 +10,7 @@ SET(LIB_PUBLIC_HEADERS
${HEADER_PATH}/Export
${HEADER_PATH}/Locator
${HEADER_PATH}/Layer
${HEADER_PATH}/Terrain
${HEADER_PATH}/TerrainNode
${HEADER_PATH}/TerrainTechnique
${HEADER_PATH}/GeometryTechnique
@@ -23,7 +24,7 @@ ADD_LIBRARY(${LIB_NAME}
${LIB_PUBLIC_HEADERS}
Layer.cpp
Locator.cpp
TerrainNode.cpp
Terrain.cpp
TerrainTechnique.cpp
GeometryTechnique.cpp
Version.cpp

View File

@@ -12,7 +12,7 @@
*/
#include <osgTerrain/GeometryTechnique>
#include <osgTerrain/TerrainNode>
#include <osgTerrain/Terrain>
#include <osgUtil/SmoothingVisitor>
@@ -101,15 +101,15 @@ void GeometryTechnique::init()
{
osg::notify(osg::NOTICE)<<"Doing init()"<<std::endl;
if (!_terrainNode) return;
if (!_terrain) return;
BufferData& buffer = getWriteBuffer();
osgTerrain::Layer* elevationLayer = _terrainNode->getElevationLayer();
osgTerrain::Layer* colorLayer = _terrainNode->getColorLayer(0);
osg::TransferFunction* colorTF = _terrainNode->getColorTransferFunction(0);
osgTerrain::TerrainNode::Filter filter = _terrainNode->getColorFilter(0);
osgTerrain::Layer* elevationLayer = _terrain->getElevationLayer();
osgTerrain::Layer* colorLayer = _terrain->getColorLayer(0);
osg::TransferFunction* colorTF = _terrain->getColorTransferFunction(0);
osgTerrain::Terrain::Filter filter = _terrain->getColorFilter(0);
// if the elevationLayer and colorLayer are the same, and there is colorTF then
// simply assing as a texture coordinate.
@@ -193,7 +193,7 @@ void GeometryTechnique::init()
numRows = elevationLayer->getNumRows();
}
bool treatBoundariesToValidDataAsDefaultValue = _terrainNode->getTreatBoundariesToValidDataAsDefaultValue();
bool treatBoundariesToValidDataAsDefaultValue = _terrain->getTreatBoundariesToValidDataAsDefaultValue();
osg::notify(osg::NOTICE)<<"TreatBoundariesToValidDataAsDefaultValue="<<treatBoundariesToValidDataAsDefaultValue<<std::endl;
unsigned int numVertices = numRows * numColumns;
@@ -427,7 +427,7 @@ void GeometryTechnique::init()
stateset->setTextureAttributeAndModes(color_index, texture2D, osg::StateAttribute::ON);
texture2D->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR);
texture2D->setFilter(osg::Texture::MAG_FILTER, filter==TerrainNode::LINEAR ? osg::Texture::LINEAR : osg::Texture::NEAREST);
texture2D->setFilter(osg::Texture::MAG_FILTER, filter==Terrain::LINEAR ? osg::Texture::LINEAR : osg::Texture::NEAREST);
if (tf)
{
@@ -537,7 +537,7 @@ void GeometryTechnique::init()
void GeometryTechnique::update(osgUtil::UpdateVisitor* uv)
{
if (_terrainNode) _terrainNode->osg::Group::traverse(*uv);
if (_terrain) _terrain->osg::Group::traverse(*uv);
}
@@ -546,7 +546,7 @@ void GeometryTechnique::cull(osgUtil::CullVisitor* cv)
BufferData& buffer = getReadOnlyBuffer();
#if 0
if (buffer._terrainNode) buffer._terrainNode->osg::Group::traverse(*cv);
if (buffer._terrain) buffer._terrain->osg::Group::traverse(*cv);
#else
if (buffer._transform.valid())
{
@@ -558,7 +558,7 @@ void GeometryTechnique::cull(osgUtil::CullVisitor* cv)
void GeometryTechnique::traverse(osg::NodeVisitor& nv)
{
if (!_terrainNode) return;
if (!_terrain) return;
// if app traversal update the frame count.
if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR)

View File

@@ -11,12 +11,12 @@
* OpenSceneGraph Public License for more details.
*/
#include <osgTerrain/TerrainNode>
#include <osgTerrain/Terrain>
using namespace osg;
using namespace osgTerrain;
TerrainNode::TerrainNode():
Terrain::Terrain():
_requiresNormals(true),
_treatBoundariesToValidDataAsDefaultValue(false)
{
@@ -24,7 +24,7 @@ TerrainNode::TerrainNode():
setThreadSafeRefUnref(true);
}
TerrainNode::TerrainNode(const TerrainNode& terrain,const osg::CopyOp& copyop):
Terrain::Terrain(const Terrain& terrain,const osg::CopyOp& copyop):
Group(terrain,copyop),
_elevationLayer(terrain._elevationLayer),
_colorLayers(terrain._colorLayers),
@@ -36,11 +36,11 @@ TerrainNode::TerrainNode(const TerrainNode& terrain,const osg::CopyOp& copyop):
if (terrain.getTerrainTechnique()) setTerrainTechnique(dynamic_cast<TerrainTechnique*>(terrain.getTerrainTechnique()->cloneType()));
}
TerrainNode::~TerrainNode()
Terrain::~Terrain()
{
}
void TerrainNode::traverse(osg::NodeVisitor& nv)
void Terrain::traverse(osg::NodeVisitor& nv)
{
if (_terrainTechnique.valid())
{
@@ -52,7 +52,7 @@ void TerrainNode::traverse(osg::NodeVisitor& nv)
}
}
void TerrainNode::init()
void Terrain::init()
{
if (_terrainTechnique.valid() && _terrainTechnique->isDirty())
{
@@ -61,46 +61,46 @@ void TerrainNode::init()
}
void TerrainNode::setTerrainTechnique(osgTerrain::TerrainTechnique* terrainTechnique)
void Terrain::setTerrainTechnique(osgTerrain::TerrainTechnique* terrainTechnique)
{
if (_terrainTechnique == terrainTechnique) return;
if (_terrainTechnique.valid()) _terrainTechnique->_terrainNode = 0;
if (_terrainTechnique.valid()) _terrainTechnique->_terrain = 0;
_terrainTechnique = terrainTechnique;
if (_terrainTechnique.valid()) _terrainTechnique->_terrainNode = this;
if (_terrainTechnique.valid()) _terrainTechnique->_terrain = this;
}
void TerrainNode::setElevationLayer(osgTerrain::Layer* layer)
void Terrain::setElevationLayer(osgTerrain::Layer* layer)
{
_elevationLayer = layer;
}
void TerrainNode::setColorLayer(unsigned int i, osgTerrain::Layer* layer)
void Terrain::setColorLayer(unsigned int i, osgTerrain::Layer* layer)
{
if (_colorLayers.size() <= i) _colorLayers.resize(i+1);
_colorLayers[i].layer = layer;
}
void TerrainNode::setColorTransferFunction(unsigned int i, osg::TransferFunction* tf)
void Terrain::setColorTransferFunction(unsigned int i, osg::TransferFunction* tf)
{
if (_colorLayers.size() <= i) _colorLayers.resize(i+1);
_colorLayers[i].transferFunction = tf;
}
void TerrainNode::setColorFilter(unsigned int i, Filter filter)
void Terrain::setColorFilter(unsigned int i, Filter filter)
{
if (_colorLayers.size() <= i) _colorLayers.resize(i+1);
_colorLayers[i].filter = filter;
}
osg::BoundingSphere TerrainNode::computeBound() const
osg::BoundingSphere Terrain::computeBound() const
{
osg::BoundingSphere bs;

View File

@@ -12,12 +12,12 @@
*/
#include <osgTerrain/TerrainTechnique>
#include <osgTerrain/TerrainNode>
#include <osgTerrain/Terrain>
using namespace osgTerrain;
TerrainTechnique::TerrainTechnique():
_terrainNode(0),
_terrain(0),
_dirty(true)
{
setThreadSafeRefUnref(true);
@@ -25,7 +25,7 @@ TerrainTechnique::TerrainTechnique():
TerrainTechnique::TerrainTechnique(const TerrainTechnique& TerrainTechnique,const osg::CopyOp& copyop):
osg::Object(TerrainTechnique,copyop),
_terrainNode(0),
_terrain(0),
_dirty(true)
{
}
@@ -44,13 +44,13 @@ void TerrainTechnique::init()
void TerrainTechnique::update(osgUtil::UpdateVisitor* uv)
{
osg::notify(osg::NOTICE)<<className()<<"::update(..) not implementated yet"<<std::endl;
if (_terrainNode) _terrainNode->osg::Group::traverse(*uv);
if (_terrain) _terrain->osg::Group::traverse(*uv);
}
void TerrainTechnique::cull(osgUtil::CullVisitor* cv)
{
osg::notify(osg::NOTICE)<<className()<<"::cull(..) not implementated yet"<<std::endl;
if (_terrainNode) _terrainNode->osg::Group::traverse(*cv);
if (_terrain) _terrain->osg::Group::traverse(*cv);
}
void TerrainTechnique::cleanSceneGraph()
@@ -66,7 +66,7 @@ void TerrainTechnique::dirty()
void TerrainTechnique::traverse(osg::NodeVisitor& nv)
{
if (!_terrainNode) return;
if (!_terrain) return;
// if app traversal update the frame count.
if (nv.getVisitorType()==osg::NodeVisitor::UPDATE_VISITOR)
@@ -94,5 +94,5 @@ void TerrainTechnique::traverse(osg::NodeVisitor& nv)
if (_dirty) init();
// otherwise fallback to the Group::traverse()
_terrainNode->osg::Group::traverse(nv);
_terrain->osg::Group::traverse(nv);
}