From 2f41234793752ec49be80eef9bb159e09f796ff1 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 16 Aug 2007 14:13:10 +0000 Subject: [PATCH] From Maria Ten, "I divide the init method of the geometrytechnique in submethods to made more easy the inheritance between the user and osg-class. This is a first step to add more functions in osgTerrain. Maybe the subdivision of the method have to be in the terraintechnique because is the base class of GeometryTechnique. If Robert or anyone think that this is better i change this class too." --- include/osgTerrain/GeometryTechnique | 15 +++ src/osgTerrain/GeometryTechnique.cpp | 169 ++++++++++++++++++++------- 2 files changed, 143 insertions(+), 41 deletions(-) diff --git a/include/osgTerrain/GeometryTechnique b/include/osgTerrain/GeometryTechnique index f401a7099..8b3bb8626 100644 --- a/include/osgTerrain/GeometryTechnique +++ b/include/osgTerrain/GeometryTechnique @@ -19,6 +19,7 @@ #include #include +#include namespace osgTerrain { @@ -32,6 +33,20 @@ class OSGTERRAIN_EXPORT GeometryTechnique : public TerrainTechnique GeometryTechnique(const GeometryTechnique&,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); virtual void init(); + + virtual Locator* computeMasterLocator(); + + virtual const osg::Vec3d computeCenterModel(Locator* masterLocator); + + virtual void generateGeometry(Locator* masterLocator, const osg::Vec3d& centerModel); + + virtual void applyColorLayers(); + + virtual void applyTransferFunctions(); + + virtual void applyTransparency(); + + virtual void smoothGeometry(); virtual void update(osgUtil::UpdateVisitor* nv); diff --git a/src/osgTerrain/GeometryTechnique.cpp b/src/osgTerrain/GeometryTechnique.cpp index 34412985f..74d974a00 100644 --- a/src/osgTerrain/GeometryTechnique.cpp +++ b/src/osgTerrain/GeometryTechnique.cpp @@ -96,28 +96,39 @@ void GeometryTechnique::setFilterMatrixAs(FilterType filterType) }; } - void GeometryTechnique::init() { osg::notify(osg::NOTICE)<<"Doing init()"<setThreadSafeRefUnref(true); + + _dirty = false; + + swapBuffers(); +} + +Locator* GeometryTechnique::computeMasterLocator() +{ 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. - if ((elevationLayer==colorLayer) && colorTF) colorLayer = 0; - - osg::notify(osg::NOTICE)<<"elevationLayer = "<getElevationLayer(); + osgTerrain::Layer* colorLayer = _terrain->getColorLayer(0); + osg::TransferFunction* colorTF = _terrain->getColorTransferFunction(0); + + if ((elevationLayer==colorLayer) && colorTF) colorLayer = 0; + + Locator* elevationLocator = elevationLayer ? elevationLayer->getLocator() : 0; + Locator* colorLocator = colorLayer ? colorLayer->getLocator() : 0; + if (!elevationLocator) elevationLocator = masterLocator; if (!colorLocator) colorLocator = masterLocator; - + osg::Vec3d bottomLeftNDC(DBL_MAX, DBL_MAX, 0.0); osg::Vec3d topRightNDC(-DBL_MAX, -DBL_MAX, 0.0); @@ -168,11 +195,7 @@ void GeometryTechnique::init() osg::notify(osg::NOTICE)<<"bottomLeftNDC = "<getImage(); osg::StateSet* stateset = buffer._geode->getOrCreateStateSet(); osg::Texture1D* texture1D = new osg::Texture1D; @@ -456,8 +524,6 @@ void GeometryTechnique::init() texture1D->setFilter(osg::Texture::MAG_FILTER, osg::Texture::NEAREST); stateset->setTextureAttributeAndModes(tf_index, texture1D, osg::StateAttribute::ON); - containsTransparency = image->isImageTranslucent(); - if (colorLayer) { osg::notify(osg::NOTICE)<<"Using fragment program"<getElevationLayer(); + osgTerrain::Layer* colorLayer = _terrain->getColorLayer(0); + osg::TransferFunction* colorTF = _terrain->getColorTransferFunction(0); + + // if the elevationLayer and colorLayer are the same, and there is colorTF then + // simply assing as a texture coordinate. + if ((elevationLayer==colorLayer) && colorTF) colorLayer = 0; + + bool containsTransparency = false; + + if (colorLayer) + { + osgTerrain::ImageLayer* imageLayer = dynamic_cast(colorLayer); + if (imageLayer) { + osg::TransferFunction1D* tf = dynamic_cast(colorTF); + if (tf) containsTransparency = tf->getImage()->isImageTranslucent(); + else containsTransparency = imageLayer->getImage()->isImageTranslucent(); + } + } if (containsTransparency) { @@ -518,23 +609,19 @@ void GeometryTechnique::init() stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); } - // if (_terrainGeometry.valid()) _terrainGeometry->setUseDisplayList(false); - if (buffer._geometry.valid()) buffer._geometry->setUseVertexBufferObjects(true); +} +void GeometryTechnique::smoothGeometry() +{ + BufferData& buffer = getWriteBuffer(); + if (buffer._geometry.valid()) { osgUtil::SmoothingVisitor smoother; smoother.smooth(*buffer._geometry); } - - if (buffer._transform.valid()) buffer._transform->setThreadSafeRefUnref(true); - - _dirty = false; - - swapBuffers(); } - void GeometryTechnique::update(osgUtil::UpdateVisitor* uv) { if (_terrain) _terrain->osg::Group::traverse(*uv);