diff --git a/include/osg/TransferFunction b/include/osg/TransferFunction index 2a06bcd9b..c0921f8fe 100644 --- a/include/osg/TransferFunction +++ b/include/osg/TransferFunction @@ -31,6 +31,13 @@ class OSG_EXPORT TransferFunction : public osg::Referenced TransferFunction(); + /** Set the texture unit to assign layer to if required. + * Negative values signifies that no texture unit has been assigned. */ + void setTextureUnit(int textureUnit) { _textureUnit = textureUnit; } + + /** Get the texture unit to assign layer to if required.*/ + int getTextureUnit() const { return _textureUnit; } + osg::Image* getImage() { return _image.get(); } const osg::Image* getImage() const { return _image.get(); } @@ -45,7 +52,9 @@ class OSG_EXPORT TransferFunction : public osg::Referenced virtual ~TransferFunction(); typedef std::vector Colors; - Colors _colors; + + int _textureUnit; + Colors _colors; osg::ref_ptr _image; osg::ref_ptr _texture; osg::ref_ptr _shader; diff --git a/include/osgTerrain/Layer b/include/osgTerrain/Layer index f93b848a0..1373c4c97 100644 --- a/include/osgTerrain/Layer +++ b/include/osgTerrain/Layer @@ -36,9 +36,20 @@ class OSGTERRAIN_EXPORT Layer : public osg::Object META_Object(osgTerrain, Layer); + /** Set the file name of the data associated with this layer. */ virtual void setFileName(const std::string& filename) { _filename = filename; } + + /** Get the file name of the layer. */ virtual const std::string& getFileName() const { return _filename; } + /** Set the texture unit to assign layer to if required. + * Negative values signifies that no texture unit has been assigned. */ + void setTextureUnit(int textureUnit) { _textureUnit = textureUnit; } + + /** Get the texture unit to assign layer to if required.*/ + int getTextureUnit() const { return _textureUnit; } + + void setLocator(Locator* locator) { _locator = locator; } Locator* getLocator() { return _locator.get(); } const Locator* getLocator() const { return _locator.get(); } @@ -167,6 +178,7 @@ class OSGTERRAIN_EXPORT Layer : public osg::Object virtual ~Layer(); std::string _filename; + int _textureUnit; osg::ref_ptr _locator; unsigned int _minLevel; unsigned int _maxLevel; diff --git a/src/osg/TransferFunction.cpp b/src/osg/TransferFunction.cpp index a68655f80..8fae2d0b9 100644 --- a/src/osg/TransferFunction.cpp +++ b/src/osg/TransferFunction.cpp @@ -19,7 +19,8 @@ using namespace osg; // // TransferFunction base class // -TransferFunction::TransferFunction() +TransferFunction::TransferFunction(): + _textureUnit(-1) { } diff --git a/src/osgPlugins/ive/IveVersion.h b/src/osgPlugins/ive/IveVersion.h index bb407bd85..8100157c6 100644 --- a/src/osgPlugins/ive/IveVersion.h +++ b/src/osgPlugins/ive/IveVersion.h @@ -31,8 +31,9 @@ #define VERSION_0020 20 #define VERSION_0021 21 #define VERSION_0022 22 +#define VERSION_0023 23 -#define VERSION VERSION_0022 +#define VERSION VERSION_0023 /* The BYTE_SEX tag is used to check the endian of the IVE file being read in. The IVE format diff --git a/src/osgPlugins/ive/Layer.cpp b/src/osgPlugins/ive/Layer.cpp index 0d6bda3d2..ac7246f70 100644 --- a/src/osgPlugins/ive/Layer.cpp +++ b/src/osgPlugins/ive/Layer.cpp @@ -39,6 +39,11 @@ void Layer::write(DataOutputStream* out) LayerHelper helper; helper.writeLocator(out, getLocator()); + if (out->getVersion() >= VERSION_0023) + { + out->writeInt(getTextureUnit()); + } + out->writeUInt(getMinLevel()); out->writeUInt(getMaxLevel()); } @@ -63,6 +68,11 @@ void Layer::read(DataInputStream* in) LayerHelper helper; setLocator(helper.readLocator(in)); + if (in->getVersion() >= VERSION_0023) + { + setTextureUnit(in->readInt()); + } + setMinLevel(in->readUInt()); setMaxLevel(in->readUInt()); diff --git a/src/osgPlugins/osgTerrain/Layer.cpp b/src/osgPlugins/osgTerrain/Layer.cpp index fe513847d..2f8a2af5d 100644 --- a/src/osgPlugins/osgTerrain/Layer.cpp +++ b/src/osgPlugins/osgTerrain/Layer.cpp @@ -35,6 +35,13 @@ bool Layer_readLocalData(osg::Object& obj, osgDB::Input &fr) osgTerrain::Locator* locator = dynamic_cast(readObject.get()); if (locator) layer.setLocator(locator); + int textureUnit=-1; + if (fr.read("TextureUnit",textureUnit)) + { + itrAdvanced = true; + layer.setTextureUnit(textureUnit); + } + unsigned int minLevel=0; if (fr.read("MinLevel",minLevel)) { @@ -61,6 +68,11 @@ bool Layer_writeLocalData(const osg::Object& obj, osgDB::Output& fw) fw.writeObject(*layer.getLocator()); } + if (layer.getTextureUnit()>=0) + { + fw.indent()<<"TextureUnit "< _vertices = new osg::Vec3Array; - if (buffer._geometry.valid()) buffer._geometry->setVertexArray(_vertices.get()); + osg::ref_ptr vertices = new osg::Vec3Array; + if (buffer._geometry.valid()) buffer._geometry->setVertexArray(vertices.get()); // allocate and assign normals - osg::ref_ptr _normals = new osg::Vec3Array; + osg::ref_ptr normals = new osg::Vec3Array; if (buffer._geometry.valid()) { - buffer._geometry->setNormalArray(_normals.get()); + buffer._geometry->setNormalArray(normals.get()); buffer._geometry->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); } @@ -274,18 +274,18 @@ void GeometryTechnique::generateGeometry(Locator* masterLocator, const osg::Vec3 float scaleHeight = 1.0; // allocate and assign tex coords - osg::ref_ptr _texcoords; + osg::ref_ptr texcoords; if (colorLayer) { color_index = texcoord_index; ++texcoord_index; - _texcoords = new osg::Vec2Array; + texcoords = new osg::Vec2Array; - if (buffer._geometry.valid()) buffer._geometry->setTexCoordArray(color_index, _texcoords.get()); + if (buffer._geometry.valid()) buffer._geometry->setTexCoordArray(color_index, texcoords.get()); } - osg::ref_ptr _elevations = new osg::FloatArray; + osg::ref_ptr elevations = new osg::FloatArray; osg::TransferFunction1D* tf = dynamic_cast(colorTF); if (tf) { @@ -294,26 +294,26 @@ void GeometryTechnique::generateGeometry(Locator* masterLocator, const osg::Vec3 if (!colorLayer) { - // _elevations = new osg::FloatArray(numVertices); - if (buffer._geometry.valid()) buffer._geometry->setTexCoordArray(tf_index, _elevations.get()); + // elevations = new osg::FloatArray(numVertices); + if (buffer._geometry.valid()) buffer._geometry->setTexCoordArray(tf_index, elevations.get()); minHeight = tf->getMinimum(); scaleHeight = 1.0f/(tf->getMaximum()-tf->getMinimum()); } } - if (_vertices.valid()) _vertices->reserve(numVertices); - if (_texcoords.valid()) _texcoords->reserve(numVertices); - if (_elevations.valid()) _elevations->reserve(numVertices); - if (_normals.valid()) _normals->reserve(numVertices); + if (vertices.valid()) vertices->reserve(numVertices); + if (texcoords.valid()) texcoords->reserve(numVertices); + if (elevations.valid()) elevations->reserve(numVertices); + if (normals.valid()) normals->reserve(numVertices); // allocate and assign color - osg::ref_ptr _colors = new osg::Vec4Array(1); - (*_colors)[0].set(1.0f,1.0f,1.0f,1.0f); + osg::ref_ptr colors = new osg::Vec4Array(1); + (*colors)[0].set(1.0f,1.0f,1.0f,1.0f); if (buffer._geometry.valid()) { - buffer._geometry->setColorArray(_colors.get()); + buffer._geometry->setColorArray(colors.get()); buffer._geometry->setColorBinding(osg::Geometry::BIND_OVERALL); } @@ -343,12 +343,12 @@ void GeometryTechnique::generateGeometry(Locator* masterLocator, const osg::Vec3 if (validValue) { - indices[iv] = _vertices->size(); + indices[iv] = vertices->size(); osg::Vec3d model; masterLocator->convertLocalToModel(ndc, model); - (*_vertices).push_back(model - centerModel); + (*vertices).push_back(model - centerModel); if (colorLayer) { @@ -356,18 +356,18 @@ void GeometryTechnique::generateGeometry(Locator* masterLocator, const osg::Vec3 { osg::Vec3d color_ndc; Locator::convertLocalCoordBetween(*masterLocator, ndc, *colorLocator, color_ndc); - (*_texcoords).push_back(osg::Vec2(color_ndc.x(), color_ndc.y())); + (*texcoords).push_back(osg::Vec2(color_ndc.x(), color_ndc.y())); } else { - (*_texcoords).push_back(osg::Vec2(ndc.x(), ndc.y())); + (*texcoords).push_back(osg::Vec2(ndc.x(), ndc.y())); } } - if (_elevations.valid()) + if (elevations.valid()) { - (*_elevations).push_back((ndc.z()-minHeight)*scaleHeight); + (*elevations).push_back((ndc.z()-minHeight)*scaleHeight); } // compute the local normal @@ -376,7 +376,7 @@ void GeometryTechnique::generateGeometry(Locator* masterLocator, const osg::Vec3 masterLocator->convertLocalToModel(ndc_one, model_one); model_one = model_one - model; model_one.normalize(); - (*_normals).push_back(model_one); + (*normals).push_back(model_one); } else { @@ -386,7 +386,7 @@ void GeometryTechnique::generateGeometry(Locator* masterLocator, const osg::Vec3 } // populate primitive sets -// bool optimizeOrientations = _elevations!=0; +// bool optimizeOrientations = elevations!=0; bool swapOrientation = !(masterLocator->orientationOpenGL()); osg::ref_ptr elements = new osg::DrawElementsUInt(GL_TRIANGLES); @@ -428,10 +428,10 @@ void GeometryTechnique::generateGeometry(Locator* masterLocator, const osg::Vec3 if (numValid==4) { - float e00 = (*_elevations)[i00]; - float e10 = (*_elevations)[i10]; - float e01 = (*_elevations)[i01]; - float e11 = (*_elevations)[i11]; + float e00 = (*elevations)[i00]; + float e10 = (*elevations)[i10]; + float e01 = (*elevations)[i01]; + float e11 = (*elevations)[i11]; if (fabsf(e00-e11) skirtVectors = new osg::Vec3Array((*_normals)); + osg::ref_ptr skirtVectors = new osg::Vec3Array((*normals)); if (elevationLayer) { smoothGeometry(); - _normals = dynamic_cast(buffer._geometry->getNormalArray()); + normals = dynamic_cast(buffer._geometry->getNormalArray()); - if (!_normals) createSkirt = false; + if (!normals) createSkirt = false; } if (createSkirt) @@ -488,11 +488,11 @@ void GeometryTechnique::generateGeometry(Locator* masterLocator, const osg::Vec3 int orig_i = indices[(r)*numColumns+c]; // index of original vertex of grid if (orig_i>=0) { - unsigned int new_i = _vertices->size(); // index of new index of added skirt point - osg::Vec3 new_v = (*_vertices)[orig_i] - ((*skirtVectors)[orig_i])*skirtHeight; - (*_vertices).push_back(new_v); - if (_normals.valid()) (*_normals).push_back((*_normals)[orig_i]); - if (_texcoords.valid()) (*_texcoords).push_back((*_texcoords)[orig_i]); + unsigned int new_i = vertices->size(); // index of new index of added skirt point + osg::Vec3 new_v = (*vertices)[orig_i] - ((*skirtVectors)[orig_i])*skirtHeight; + (*vertices).push_back(new_v); + if (normals.valid()) (*normals).push_back((*normals)[orig_i]); + if (texcoords.valid()) (*texcoords).push_back((*texcoords)[orig_i]); skirtDrawElements->push_back(orig_i); skirtDrawElements->push_back(new_i); @@ -521,11 +521,11 @@ void GeometryTechnique::generateGeometry(Locator* masterLocator, const osg::Vec3 int orig_i = indices[(r)*numColumns+c]; // index of original vertex of grid if (orig_i>=0) { - unsigned int new_i = _vertices->size(); // index of new index of added skirt point - osg::Vec3 new_v = (*_vertices)[orig_i] - ((*skirtVectors)[orig_i])*skirtHeight; - (*_vertices).push_back(new_v); - if (_normals.valid()) (*_normals).push_back((*_normals)[orig_i]); - if (_texcoords.valid()) (*_texcoords).push_back((*_texcoords)[orig_i]); + unsigned int new_i = vertices->size(); // index of new index of added skirt point + osg::Vec3 new_v = (*vertices)[orig_i] - ((*skirtVectors)[orig_i])*skirtHeight; + (*vertices).push_back(new_v); + if (normals.valid()) (*normals).push_back((*normals)[orig_i]); + if (texcoords.valid()) (*texcoords).push_back((*texcoords)[orig_i]); skirtDrawElements->push_back(orig_i); skirtDrawElements->push_back(new_i); @@ -554,11 +554,11 @@ void GeometryTechnique::generateGeometry(Locator* masterLocator, const osg::Vec3 int orig_i = indices[(r)*numColumns+c]; // index of original vertex of grid if (orig_i>=0) { - unsigned int new_i = _vertices->size(); // index of new index of added skirt point - osg::Vec3 new_v = (*_vertices)[orig_i] - ((*skirtVectors)[orig_i])*skirtHeight; - (*_vertices).push_back(new_v); - if (_normals.valid()) (*_normals).push_back((*_normals)[orig_i]); - if (_texcoords.valid()) (*_texcoords).push_back((*_texcoords)[orig_i]); + unsigned int new_i = vertices->size(); // index of new index of added skirt point + osg::Vec3 new_v = (*vertices)[orig_i] - ((*skirtVectors)[orig_i])*skirtHeight; + (*vertices).push_back(new_v); + if (normals.valid()) (*normals).push_back((*normals)[orig_i]); + if (texcoords.valid()) (*texcoords).push_back((*texcoords)[orig_i]); skirtDrawElements->push_back(orig_i); skirtDrawElements->push_back(new_i); @@ -587,11 +587,11 @@ void GeometryTechnique::generateGeometry(Locator* masterLocator, const osg::Vec3 int orig_i = indices[(r)*numColumns+c]; // index of original vertex of grid if (orig_i>=0) { - unsigned int new_i = _vertices->size(); // index of new index of added skirt point - osg::Vec3 new_v = (*_vertices)[orig_i] - ((*skirtVectors)[orig_i])*skirtHeight; - (*_vertices).push_back(new_v); - if (_normals.valid()) (*_normals).push_back((*_normals)[orig_i]); - if (_texcoords.valid()) (*_texcoords).push_back((*_texcoords)[orig_i]); + unsigned int new_i = vertices->size(); // index of new index of added skirt point + osg::Vec3 new_v = (*vertices)[orig_i] - ((*skirtVectors)[orig_i])*skirtHeight; + (*vertices).push_back(new_v); + if (normals.valid()) (*normals).push_back((*normals)[orig_i]); + if (texcoords.valid()) (*texcoords).push_back((*texcoords)[orig_i]); skirtDrawElements->push_back(orig_i); skirtDrawElements->push_back(new_i); diff --git a/src/osgTerrain/Layer.cpp b/src/osgTerrain/Layer.cpp index 9c7cec6c0..cdca65988 100644 --- a/src/osgTerrain/Layer.cpp +++ b/src/osgTerrain/Layer.cpp @@ -17,6 +17,7 @@ using namespace osgTerrain; Layer::Layer(): + _textureUnit(-1), _minLevel(0), _maxLevel(MAXIMUM_NUMBER_OF_LEVELS) { @@ -25,6 +26,7 @@ Layer::Layer(): Layer::Layer(const Layer& layer,const osg::CopyOp& copyop): osg::Object(layer,copyop), _filename(layer._filename), + _textureUnit(layer._textureUnit), _minLevel(layer._minLevel), _maxLevel(layer._maxLevel) { diff --git a/src/osgWrappers/osg/TransferFunction.cpp b/src/osgWrappers/osg/TransferFunction.cpp index c5a7a30e2..eeafdb0f1 100644 --- a/src/osgWrappers/osg/TransferFunction.cpp +++ b/src/osgWrappers/osg/TransferFunction.cpp @@ -30,6 +30,16 @@ BEGIN_OBJECT_REFLECTOR(osg::TransferFunction) I_Constructor0(____TransferFunction, "", ""); + I_Method1(void, setTextureUnit, IN, int, textureUnit, + Properties::NON_VIRTUAL, + __void__setTextureUnit__int, + "Set the texture unit to assign layer to if required. ", + "Negative values signifies that no texture unit has been assigned. "); + I_Method0(int, getTextureUnit, + Properties::NON_VIRTUAL, + __int__getTextureUnit, + "Get the texture unit to assign layer to if required. ", + ""); I_Method0(osg::Image *, getImage, Properties::NON_VIRTUAL, __osg_Image_P1__getImage, @@ -69,6 +79,9 @@ BEGIN_OBJECT_REFLECTOR(osg::TransferFunction) I_SimpleProperty(osg::Texture *, Texture, __osg_Texture_P1__getTexture, 0); + I_SimpleProperty(int, TextureUnit, + __int__getTextureUnit, + __void__setTextureUnit__int); END_REFLECTOR BEGIN_OBJECT_REFLECTOR(osg::TransferFunction1D) diff --git a/src/osgWrappers/osgTerrain/Layer.cpp b/src/osgWrappers/osgTerrain/Layer.cpp index 888a660e1..f2a0ba1af 100644 --- a/src/osgWrappers/osgTerrain/Layer.cpp +++ b/src/osgWrappers/osgTerrain/Layer.cpp @@ -166,12 +166,12 @@ BEGIN_OBJECT_REFLECTOR(osgTerrain::HeightFieldLayer) I_Method1(void, setFileName, IN, const std::string &, filename, Properties::VIRTUAL, __void__setFileName__C5_std_string_R1, - "", + "Set the file name of the data associated with this layer. ", ""); I_Method0(const std::string &, getFileName, Properties::VIRTUAL, __C5_std_string_R1__getFileName, - "", + "Get the file name of the layer. ", ""); I_Method2(bool, transform, IN, float, offset, IN, float, scale, Properties::VIRTUAL, @@ -287,12 +287,12 @@ BEGIN_OBJECT_REFLECTOR(osgTerrain::ImageLayer) I_Method1(void, setFileName, IN, const std::string &, filename, Properties::VIRTUAL, __void__setFileName__C5_std_string_R1, - "", + "Set the file name of the data associated with this layer. ", ""); I_Method0(const std::string &, getFileName, Properties::VIRTUAL, __C5_std_string_R1__getFileName, - "", + "Get the file name of the layer. ", ""); I_Method2(bool, transform, IN, float, offset, IN, float, scale, Properties::VIRTUAL, @@ -408,12 +408,22 @@ BEGIN_OBJECT_REFLECTOR(osgTerrain::Layer) I_Method1(void, setFileName, IN, const std::string &, filename, Properties::VIRTUAL, __void__setFileName__C5_std_string_R1, - "", + "Set the file name of the data associated with this layer. ", ""); I_Method0(const std::string &, getFileName, Properties::VIRTUAL, __C5_std_string_R1__getFileName, - "", + "Get the file name of the layer. ", + ""); + I_Method1(void, setTextureUnit, IN, int, textureUnit, + Properties::NON_VIRTUAL, + __void__setTextureUnit__int, + "Set the texture unit to assign layer to if required. ", + "Negative values signifies that no texture unit has been assigned. "); + I_Method0(int, getTextureUnit, + Properties::NON_VIRTUAL, + __int__getTextureUnit, + "Get the texture unit to assign layer to if required. ", ""); I_Method1(void, setLocator, IN, osgTerrain::Locator *, locator, Properties::NON_VIRTUAL, @@ -578,6 +588,9 @@ BEGIN_OBJECT_REFLECTOR(osgTerrain::Layer) I_SimpleProperty(unsigned, ModifiedCount, 0, __void__setModifiedCount__unsigned); + I_SimpleProperty(int, TextureUnit, + __int__getTextureUnit, + __void__setTextureUnit__int); I_SimpleProperty(osgTerrain::ValidDataOperator *, ValidDataOperator, __ValidDataOperator_P1__getValidDataOperator, __void__setValidDataOperator__ValidDataOperator_P1); @@ -636,12 +649,12 @@ BEGIN_OBJECT_REFLECTOR(osgTerrain::ProxyLayer) I_Method1(void, setFileName, IN, const std::string &, filename, Properties::VIRTUAL, __void__setFileName__C5_std_string_R1, - "", + "Set the file name of the data associated with this layer. ", ""); I_Method0(const std::string &, getFileName, Properties::VIRTUAL, __C5_std_string_R1__getFileName, - "", + "Get the file name of the layer. ", ""); I_Method0(unsigned int, getNumColumns, Properties::VIRTUAL,