diff --git a/src/osgPlugins/ive/CMakeLists.txt b/src/osgPlugins/ive/CMakeLists.txt index d49320c19..04ab4dfff 100644 --- a/src/osgPlugins/ive/CMakeLists.txt +++ b/src/osgPlugins/ive/CMakeLists.txt @@ -2,198 +2,210 @@ SET(TARGET_SRC -AlphaFunc.cpp -AnimationPath.cpp -AnimationPathCallback.cpp -AutoTransform.cpp -AzimElevationSector.cpp -AzimSector.cpp -Billboard.cpp -BlendColor.cpp -BlendFunc.cpp -BlinkSequence.cpp -Camera.cpp -CameraView.cpp -ClipNode.cpp -ClipPlane.cpp -ClusterCullingCallback.cpp -ColorMask.cpp -ConeSector.cpp -ConvexPlanarOccluder.cpp -ConvexPlanarPolygon.cpp -CoordinateSystemNode.cpp -CullFace.cpp -DOFTransform.cpp -DataInputStream.cpp -DataOutputStream.cpp -Depth.cpp -DirectionalSector.cpp -DrawArrayLengths.cpp -DrawArrays.cpp -DrawElementsUByte.cpp -DrawElementsUInt.cpp -DrawElementsUShort.cpp -Drawable.cpp -ElevationSector.cpp -EllipsoidModel.cpp -Exception.cpp -FragmentProgram.cpp -FrontFace.cpp -Geode.cpp -Geometry.cpp -Group.cpp -Image.cpp -Impostor.cpp -LOD.cpp -Light.cpp -LightModel.cpp -LightPoint.cpp -LightPointNode.cpp -LightSource.cpp -LineWidth.cpp -Material.cpp -MatrixTransform.cpp -MultiSwitch.cpp -MultiTextureControl.cpp -Multisample.cpp -Node.cpp -Object.cpp -OccluderNode.cpp -OcclusionQueryNode.cpp -PagedLOD.cpp -Point.cpp -PointSprite.cpp -PolygonMode.cpp -PolygonOffset.cpp -PositionAttitudeTransform.cpp -PrimitiveSet.cpp -Program.cpp -ProxyNode.cpp -ReaderWriterIVE.cpp -Scissor.cpp -Sequence.cpp -ShadeModel.cpp -Shader.cpp -Shape.cpp -ShapeDrawable.cpp -StateSet.cpp -Stencil.cpp -Switch.cpp -TexEnv.cpp -TexEnvCombine.cpp -TexGen.cpp -TexGenNode.cpp -TexMat.cpp -Text.cpp -Texture.cpp -Texture1D.cpp -Texture2D.cpp -Texture3D.cpp -TextureCubeMap.cpp -TextureRectangle.cpp -Transform.cpp -Uniform.cpp -VertexProgram.cpp -Viewport.cpp -VisibilityGroup.cpp + AlphaFunc.cpp + AnimationPath.cpp + AnimationPathCallback.cpp + AutoTransform.cpp + AzimElevationSector.cpp + AzimSector.cpp + Billboard.cpp + BlendColor.cpp + BlendFunc.cpp + BlinkSequence.cpp + Camera.cpp + CameraView.cpp + ClipNode.cpp + ClipPlane.cpp + ClusterCullingCallback.cpp + ColorMask.cpp + ConeSector.cpp + ConvexPlanarOccluder.cpp + ConvexPlanarPolygon.cpp + CoordinateSystemNode.cpp + CullFace.cpp + DOFTransform.cpp + DataInputStream.cpp + DataOutputStream.cpp + Depth.cpp + DirectionalSector.cpp + DrawArrayLengths.cpp + DrawArrays.cpp + DrawElementsUByte.cpp + DrawElementsUInt.cpp + DrawElementsUShort.cpp + Drawable.cpp + ElevationSector.cpp + EllipsoidModel.cpp + Exception.cpp + FragmentProgram.cpp + FrontFace.cpp + Geode.cpp + Geometry.cpp + Group.cpp + Image.cpp + Impostor.cpp + LOD.cpp + Light.cpp + LightModel.cpp + LightPoint.cpp + LightPointNode.cpp + LightSource.cpp + LineWidth.cpp + Material.cpp + MatrixTransform.cpp + MultiSwitch.cpp + MultiTextureControl.cpp + Multisample.cpp + Node.cpp + Object.cpp + OccluderNode.cpp + OcclusionQueryNode.cpp + PagedLOD.cpp + Point.cpp + PointSprite.cpp + PolygonMode.cpp + PolygonOffset.cpp + PositionAttitudeTransform.cpp + PrimitiveSet.cpp + Program.cpp + ProxyNode.cpp + ReaderWriterIVE.cpp + Scissor.cpp + Sequence.cpp + ShadeModel.cpp + Shader.cpp + Shape.cpp + ShapeDrawable.cpp + StateSet.cpp + Stencil.cpp + Switch.cpp + TexEnv.cpp + TexEnvCombine.cpp + TexGen.cpp + TexGenNode.cpp + TexMat.cpp + Text.cpp + Texture.cpp + Texture1D.cpp + Texture2D.cpp + Texture3D.cpp + TextureCubeMap.cpp + TextureRectangle.cpp + Terrain.cpp + Locator.cpp + Layer.cpp + HeightFieldLayer.cpp + ImageLayer.cpp + CompositeLayer.cpp + Transform.cpp + Uniform.cpp + VertexProgram.cpp + Viewport.cpp + VisibilityGroup.cpp ) SET(TARGET_H -AlphaFunc.h -AnimationPath.h -AnimationPathCallback.h -AutoTransform.h -AzimElevationSector.h -AzimSector.h -Billboard.h -BlendColor.h -BlendFunc.h -BlinkSequence.h -Camera.h -CameraView.h -ClipNode.h -ClipPlane.h -ClusterCullingCallback.h -ColorMask.h -ConeSector.h -ConvexPlanarOccluder.h -ConvexPlanarPolygon.h -CoordinateSystemNode.h -CullFace.h -DOFTransform.h -DataInputStream.h -DataOutputStream.h -DataTypeSize.h -Depth.h -DirectionalSector.h -DrawArrayLengths.h -DrawArrays.h -DrawElementsUByte.h -DrawElementsUInt.h -DrawElementsUShort.h -Drawable.h -ElevationSector.h -EllipsoidModel.h -Exception.h -FragmentProgram.h -FrontFace.h -Geode.h -Geometry.h -Group.h -Image.h -Impostor.h -IveVersion.h -LOD.h -Light.h -LightModel.h -LightPoint.h -LightPointNode.h -LightSource.h -LineWidth.h -Material.h -MatrixTransform.h -MultiSwitch.h -MultiTextureControl.h -Node.h -Object.h -OccluderNode.h -OcclusionQueryNode.h -PagedLOD.h -Point.h -PointSprite.h -PolygonMode.h -PolygonOffset.h -PositionAttitudeTransform.h -PrimitiveSet.h -Program.h -ProxyNode.h -ReadWrite.h -Scissor.h -Sequence.h -ShadeModel.h -Shader.h -Shape.h -ShapeDrawable.h -StateSet.h -Stencil.h -Switch.h -TexEnv.h -TexEnvCombine.h -TexGen.h -TexGenNode.h -TexMat.h -Text.h -Texture.h -Texture1D.h -Texture2D.h -Texture3D.h -TextureCubeMap.h -TextureRectangle.h -Transform.h -Uniform.h -VertexProgram.h -Viewport.h -VisibilityGroup.h + AlphaFunc.h + AnimationPath.h + AnimationPathCallback.h + AutoTransform.h + AzimElevationSector.h + AzimSector.h + Billboard.h + BlendColor.h + BlendFunc.h + BlinkSequence.h + Camera.h + CameraView.h + ClipNode.h + ClipPlane.h + ClusterCullingCallback.h + ColorMask.h + ConeSector.h + ConvexPlanarOccluder.h + ConvexPlanarPolygon.h + CoordinateSystemNode.h + CullFace.h + DOFTransform.h + DataInputStream.h + DataOutputStream.h + DataTypeSize.h + Depth.h + DirectionalSector.h + DrawArrayLengths.h + DrawArrays.h + DrawElementsUByte.h + DrawElementsUInt.h + DrawElementsUShort.h + Drawable.h + ElevationSector.h + EllipsoidModel.h + Exception.h + FragmentProgram.h + FrontFace.h + Geode.h + Geometry.h + Group.h + Image.h + Impostor.h + IveVersion.h + LOD.h + Light.h + LightModel.h + LightPoint.h + LightPointNode.h + LightSource.h + LineWidth.h + Material.h + MatrixTransform.h + MultiSwitch.h + MultiTextureControl.h + Node.h + Object.h + OccluderNode.h + OcclusionQueryNode.h + PagedLOD.h + Point.h + PointSprite.h + PolygonMode.h + PolygonOffset.h + PositionAttitudeTransform.h + PrimitiveSet.h + Program.h + ProxyNode.h + ReadWrite.h + Scissor.h + Sequence.h + ShadeModel.h + Shader.h + Shape.h + ShapeDrawable.h + StateSet.h + Stencil.h + Switch.h + TexEnv.h + TexEnvCombine.h + TexGen.h + TexGenNode.h + TexMat.h + Text.h + Texture.h + Texture1D.h + Texture2D.h + Texture3D.h + TextureCubeMap.h + TextureRectangle.h + Terrain.h + Transform.h + Locator.h + Layer.h + HeightFieldLayer.h + ImageLayer.h + CompositeLayer.h + Uniform.h + VertexProgram.h + Viewport.h + VisibilityGroup.h ) -SET(TARGET_ADDED_LIBRARIES osgSim osgFX osgText ) +SET(TARGET_ADDED_LIBRARIES osgSim osgFX osgText osgTerrain) #### end var setup ### SETUP_PLUGIN(ive) diff --git a/src/osgPlugins/ive/CompositeLayer.cpp b/src/osgPlugins/ive/CompositeLayer.cpp new file mode 100644 index 000000000..d0fa0b3c1 --- /dev/null +++ b/src/osgPlugins/ive/CompositeLayer.cpp @@ -0,0 +1,82 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#include "Exception.h" +#include "CompositeLayer.h" +#include "Layer.h" + +using namespace ive; + +void CompositeLayer::write(DataOutputStream* out) +{ + // Write Layer's identification. + out->writeInt(IVECOMPOSITELAYER); + + // If the osg class is inherited by any other class we should also write this to file. + osgTerrain::Layer* layer = dynamic_cast(this); + if (layer) + ((ive::Layer*)(layer))->write(out); + else + throw Exception("CompositeLayer::write(): Could not cast this osgLayer::CompositeLayer to an osgTerrain::Layer."); + + LayerHelper helper; + + out->writeUInt(getNumLayers()); + for(unsigned int i=0; iwriteBool(true); + helper.writeLayer(out, getLayer(i)); + } + else + { + out->writeBool(false); + out->writeString(getFileName(i)); + } + } +} + +void CompositeLayer::read(DataInputStream* in) +{ + // Peek on Layer's identification. + int id = in->peekInt(); + if (id != IVECOMPOSITELAYER) + throw Exception("CompositeLayer::read(): Expected CompositeLayer identification."); + + // Read Layer's identification. + id = in->readInt(); + + // If the osg class is inherited by any other class we should also read this from file. + osgTerrain::Layer* layer = dynamic_cast(this); + if (layer) + ((ive::Layer*)(layer))->read(in); + else + throw Exception("CompositeLayer::read(): Could not cast this osgLayer::Layer to an osg::Group."); + + LayerHelper helper; + + unsigned int numLayers = in->readUInt(); + for(unsigned int i=0; ireadBool(); + if (readInlineLayer) + { + addLayer(helper.readLayer(in)); + } + else + { + addLayer(in->readString()); + } + } +} diff --git a/src/osgPlugins/ive/CompositeLayer.h b/src/osgPlugins/ive/CompositeLayer.h new file mode 100644 index 000000000..de82457e7 --- /dev/null +++ b/src/osgPlugins/ive/CompositeLayer.h @@ -0,0 +1,19 @@ +#ifndef IVE_COMPOSITELAYER +#define IVE_COMPOSITELAYER 1 + +#include +#include "ReadWrite.h" + +namespace ive +{ + +class CompositeLayer : public osgTerrain::CompositeLayer, public ReadWrite +{ +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; + +} + +#endif diff --git a/src/osgPlugins/ive/CoordinateSystemNode.cpp b/src/osgPlugins/ive/CoordinateSystemNode.cpp index aee16adb4..514e4ad58 100644 --- a/src/osgPlugins/ive/CoordinateSystemNode.cpp +++ b/src/osgPlugins/ive/CoordinateSystemNode.cpp @@ -65,8 +65,8 @@ void CoordinateSystemNode::read(DataInputStream* in){ // Read coord string setCoordinateSystem( in->readString()); - bool readEllopsoidModel = in->readBool(); - if (readEllopsoidModel) + bool readEllipsoidModel = in->readBool(); + if (readEllipsoidModel) { osg::EllipsoidModel* em = new osg::EllipsoidModel(); ((ive::EllipsoidModel*)(em))->read(in); diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index e9d4f64d1..fd2a5ebc2 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -89,6 +89,8 @@ #include "Text.h" +#include "Terrain.h" + #include #include #include @@ -1451,6 +1453,10 @@ osg::Node* DataInputStream::readNode() node = new osgFX::MultiTextureControl(); ((ive::MultiTextureControl*)(node))->read(this); } + else if(nodeTypeID== IVETERRAIN){ + node = new osgTerrain::Terrain(); + ((ive::Terrain*)(node))->read(this); + } else{ throw Exception("Unknown node identification in DataInputStream::readNode()"); } diff --git a/src/osgPlugins/ive/DataOutputStream.cpp b/src/osgPlugins/ive/DataOutputStream.cpp index 95c1a6000..32ab98d1d 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -90,6 +90,8 @@ #include "Text.h" +#include "Terrain.h" + #include #include #include @@ -978,7 +980,7 @@ void DataOutputStream::writeNode(const osg::Node* node) else { // id doesn't exist so create a new ID and - // register the stateset. + // register the node. int id = _nodeMap.size(); _nodeMap[node] = id; @@ -1054,6 +1056,9 @@ void DataOutputStream::writeNode(const osg::Node* node) else if(dynamic_cast(node)){ ((ive::MultiTextureControl*)(node))->write(this); } + else if(dynamic_cast(node)){ + ((ive::Terrain*)(node))->write(this); + } else if(dynamic_cast(node)){ ((ive::Group*)(node))->write(this); } diff --git a/src/osgPlugins/ive/ImageLayer.cpp b/src/osgPlugins/ive/ImageLayer.cpp new file mode 100644 index 000000000..306c7e962 --- /dev/null +++ b/src/osgPlugins/ive/ImageLayer.cpp @@ -0,0 +1,86 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#include "Exception.h" +#include "ImageLayer.h" +#include "Layer.h" + +#include + +using namespace ive; + +void ImageLayer::write(DataOutputStream* out) +{ + // Write Layer's identification. + out->writeInt(IVEIMAGELAYER); + + // If the osg class is inherited by any other class we should also write this to file. + osgTerrain::Layer* layer = dynamic_cast(this); + if (layer) + ((ive::Layer*)(layer))->write(out); + else + throw Exception("ImageLayer::write(): Could not cast this osgLayer::ImageLayer to an osgTerrain::Layer."); + + + if (getFileName().empty() && getImage()) + { + // using inline image + out->writeBool(true); + out->writeChar(out->getIncludeImageMode()); + out->writeImage(out->getIncludeImageMode(),getImage()); + } + else + { + // using external image file + out->writeBool(false); + out->writeString(getFileName()); + } + +} + +void ImageLayer::read(DataInputStream* in) +{ + // Peek on Layer's identification. + int id = in->peekInt(); + if (id != IVEIMAGELAYER) + throw Exception("ImageLayer::read(): Expected ImageLayer identification."); + + // Read Layer's identification. + id = in->readInt(); + + // If the osg class is inherited by any other class we should also read this from file. + osgTerrain::Layer* layer = dynamic_cast(this); + if (layer) + ((ive::Layer*)(layer))->read(in); + else + throw Exception("ImageLayer::read(): Could not cast this osgLayer::Layer to an osg::Group."); + + + bool useInlineImage = in->readBool(); + + if (useInlineImage) + { + // Should we read image data from stream + IncludeImageMode includeImg = (IncludeImageMode)in->readChar(); + + setImage(in->readImage(includeImg)); + } + else + { + std::string filename = in->readString(); + setFileName(filename); + + setImage(osgDB::readImageFile(filename,in->getOptions())); + } + +} diff --git a/src/osgPlugins/ive/ImageLayer.h b/src/osgPlugins/ive/ImageLayer.h new file mode 100644 index 000000000..f8f11b88e --- /dev/null +++ b/src/osgPlugins/ive/ImageLayer.h @@ -0,0 +1,32 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef IVE_IMAGELAYER +#define IVE_IMAGELAYER 1 + +#include +#include "ReadWrite.h" + +namespace ive +{ + +class ImageLayer : public osgTerrain::ImageLayer, public ReadWrite +{ +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; + +} + +#endif diff --git a/src/osgPlugins/ive/Layer.cpp b/src/osgPlugins/ive/Layer.cpp new file mode 100644 index 000000000..0d6bda3d2 --- /dev/null +++ b/src/osgPlugins/ive/Layer.cpp @@ -0,0 +1,181 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#include "Exception.h" +#include "Layer.h" +#include "Locator.h" +#include "Object.h" +#include "Locator.h" +#include "ImageLayer.h" +#include "HeightFieldLayer.h" +#include "CompositeLayer.h" + +#include + +using namespace ive; + +void Layer::write(DataOutputStream* out) +{ + // Write Layer's identification. + out->writeInt(IVELAYER); + + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* object = dynamic_cast(this); + if (object) + ((ive::Object*)(object))->write(out); + else + throw Exception("Layer::write(): Could not cast this osgLayer::Layer to an osg::Object."); + + LayerHelper helper; + helper.writeLocator(out, getLocator()); + + out->writeUInt(getMinLevel()); + out->writeUInt(getMaxLevel()); +} + +void Layer::read(DataInputStream* in) +{ + // Peek on Layer's identification. + int id = in->peekInt(); + if (id != IVELAYER) + throw Exception("Layer::read(): Expected Layer identification."); + + // Read Layer's identification. + id = in->readInt(); + + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* object = dynamic_cast(this); + if(object) + ((ive::Object*)(object))->read(in); + else + throw Exception("Layer::read(): Could not cast this osgLayer::Layer to an osg::Group."); + + LayerHelper helper; + setLocator(helper.readLocator(in)); + + setMinLevel(in->readUInt()); + setMaxLevel(in->readUInt()); + +} + +void LayerHelper::writeLayer(DataOutputStream* out, osgTerrain::Layer* layer) +{ + if (layer) + { + out->writeBool(true); + + if (dynamic_cast(layer)) + { + ((ive::HeightFieldLayer*)(layer))->write(out); + } + else if (dynamic_cast(layer)) + { + ((ive::ImageLayer*)(layer))->write(out); + } + else if (dynamic_cast(layer)) + { + ((ive::CompositeLayer*)(layer))->write(out); + } + else if (dynamic_cast(layer)) + { + out->writeInt(IVEPROXYLAYER); + out->writeString(layer->getFileName()); + + osgTerrain::Locator* locator = layer->getLocator(); + bool writeOutLocator = locator && !locator->getDefinedInFile(); + writeLocator(out, writeOutLocator ? locator : 0 ); + + out->writeUInt(layer->getMinLevel()); + out->writeUInt(layer->getMaxLevel()); + } + + } + else + { + out->writeBool(false); + } +} + +osgTerrain::Layer* LayerHelper::readLayer(DataInputStream* in) +{ + bool layerExist = in->readBool(); + if (!layerExist) return 0; + + int id = in->peekInt(); + if (id==IVEHEIGHTFIELDLAYER) + { + osgTerrain::HeightFieldLayer* layer = new osgTerrain::HeightFieldLayer; + ((ive::HeightFieldLayer*)(layer))->read(in); + return layer; + } + else if (id==IVEIMAGELAYER) + { + osgTerrain::ImageLayer* layer = new osgTerrain::ImageLayer; + ((ive::ImageLayer*)(layer))->read(in); + return layer; + } + else if (id==IVECOMPOSITELAYER) + { + osgTerrain::CompositeLayer* layer = new osgTerrain::CompositeLayer; + ((ive::CompositeLayer*)(layer))->read(in); + return layer; + } + else if (id==IVEPROXYLAYER) + { + std::string filename = in->readString(); + osg::ref_ptr object = osgDB::readObjectFile(filename+".gdal"); + osgTerrain::ProxyLayer* proxyLayer = dynamic_cast(object.get()); + + osg::ref_ptr locator = readLocator(in); + unsigned int minLevel = in->readUInt(); + unsigned int maxLevel = in->readUInt(); + + if (proxyLayer) + { + if (locator.valid()) proxyLayer->setLocator(locator.get()); + + proxyLayer->setMinLevel(minLevel); + proxyLayer->setMaxLevel(maxLevel); + } + + return proxyLayer; + } + + return new osgTerrain::ImageLayer; +} + +void LayerHelper::writeLocator(DataOutputStream* out, osgTerrain::Locator* locator) +{ + if (locator) + { + out->writeBool(true); + + ((ive::Locator*)(locator))->write(out); + } + else + { + out->writeBool(false); + } +} + +osgTerrain::Locator* LayerHelper::readLocator(DataInputStream* in) +{ + bool locatorExist = in->readBool(); + if (!locatorExist) return 0; + + osgTerrain::Locator* locator = new osgTerrain::Locator; + + ((ive::Locator*)(locator))->read(in); + + return locator; +} diff --git a/src/osgPlugins/ive/Layer.h b/src/osgPlugins/ive/Layer.h new file mode 100644 index 000000000..b1e8cadab --- /dev/null +++ b/src/osgPlugins/ive/Layer.h @@ -0,0 +1,45 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef IVE_LAYER +#define IVE_LAYER 1 + +#include +#include "ReadWrite.h" + +namespace ive +{ + +class LayerHelper +{ + public: + + LayerHelper() {} + + void writeLayer(DataOutputStream* out, osgTerrain::Layer* layer); + osgTerrain::Layer* readLayer(DataInputStream* in); + + void writeLocator(DataOutputStream* out, osgTerrain::Locator* locator); + osgTerrain::Locator* readLocator(DataInputStream* in); +}; + +class Layer : public osgTerrain::Layer, public ReadWrite +{ + public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; + +} + +#endif diff --git a/src/osgPlugins/ive/Locator.cpp b/src/osgPlugins/ive/Locator.cpp new file mode 100644 index 000000000..2dbe0d629 --- /dev/null +++ b/src/osgPlugins/ive/Locator.cpp @@ -0,0 +1,84 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + + +#include "Exception.h" +#include "Locator.h" +#include "Object.h" +#include "EllipsoidModel.h" + +using namespace ive; + +void Locator::write(DataOutputStream* out) +{ + // Write Locator's identification. + out->writeInt(IVELOCATOR); + + // If the osg class is inherited by any other class we should also write this to file. + osg::Object* object = dynamic_cast(this); + if (object) + ((ive::Object*)(object))->write(out); + else + throw Exception("Layer::write(): Could not cast this osgLayer::Layer to an osg::Object."); + + out->writeInt(getCoordinateSystemType()); + out->writeString(getFormat()); + out->writeString(getCoordinateSystem()); + + out->writeBool(getEllipsoidModel()!=0); + if(getEllipsoidModel()) + { + ((ive::EllipsoidModel*)(getEllipsoidModel()))->write(out); + } + + out->writeBool(getDefinedInFile()); + out->writeBool(getTransformScaledByResolution()); + out->writeMatrixd(getTransform()); +} + +void Locator::read(DataInputStream* in) +{ + // Peek on Locator's identification. + int id = in->peekInt(); + if(id != IVELOCATOR) + { + throw Exception("Locator::read(): Expected Locator identification."); + } + + // Read Locator's identification. + id = in->readInt(); + + // If the osg class is inherited by any other class we should also read this from file. + osg::Object* object = dynamic_cast(this); + if(object) + ((ive::Object*)(object))->read(in); + else + throw Exception("Locator::read(): Could not cast this osgLocator::Locator to an osg::Group."); + + setCoordinateSystemType(static_cast(in->readInt())); + setFormat(in->readString()); + setCoordinateSystem(in->readString()); + + bool readEllipsoidModel = in->readBool(); + if (readEllipsoidModel) + { + osg::EllipsoidModel* em = new osg::EllipsoidModel(); + ((ive::EllipsoidModel*)(em))->read(in); + setEllipsoidModel(em); + } + + setDefinedInFile(in->readBool()); + setTransformScaledByResolution(in->readBool()); + setTransform(in->readMatrixd()); + +} diff --git a/src/osgPlugins/ive/Locator.h b/src/osgPlugins/ive/Locator.h new file mode 100644 index 000000000..d46be90e8 --- /dev/null +++ b/src/osgPlugins/ive/Locator.h @@ -0,0 +1,28 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef IVE_LOCATOR +#define IVE_LOCATOR 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class Locator : public osgTerrain::Locator, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; +} + +#endif diff --git a/src/osgPlugins/ive/ReadWrite.h b/src/osgPlugins/ive/ReadWrite.h index bab338b66..13c3976a3 100644 --- a/src/osgPlugins/ive/ReadWrite.h +++ b/src/osgPlugins/ive/ReadWrite.h @@ -120,6 +120,17 @@ namespace ive { #define IVEVISIBILITYGROUP 0x00100009 #define IVEDIRECTIONALSECTOR 0x0010000A +// osgTerrain classes +#define IVETERRAIN 0x00200001 +#define IVELOCATOR 0x00200002 +#define IVELAYER 0x00200003 +#define IVEIMAGELAYER 0x00200004 +#define IVEHEIGHTFIELDLAYER 0x00200005 +#define IVECOMPOSITELAYER 0x00200006 +#define IVEPROXYLAYER 0x00200007 +#define IVETERRAINTECHNIQUE 0x00200008 +#define IVEGEOMETRYTECHNIQUE 0x00200009 + // osgFX classes #define IVEMULTITEXTURECONTROL 0x01000001 diff --git a/src/osgPlugins/ive/Terrain.cpp b/src/osgPlugins/ive/Terrain.cpp new file mode 100644 index 000000000..cb88f97bf --- /dev/null +++ b/src/osgPlugins/ive/Terrain.cpp @@ -0,0 +1,109 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#include "Exception.h" +#include "Terrain.h" +#include "Group.h" +#include "Layer.h" + +#include + +using namespace ive; + +void Terrain::write(DataOutputStream* out) +{ + // Write Terrain's identification. + out->writeInt(IVETERRAIN); + // If the osg class is inherited by any other class we should also write this to file. + osg::Group* group = dynamic_cast(this); + if(group) + ((ive::Group*)(group))->write(out); + else + throw Exception("Terrain::write(): Could not cast this osgTerrain::Terrain to an osg::Group."); + + LayerHelper helper; + + helper.writeLocator(out, getLocator()); + + helper.writeLayer(out, getElevationLayer()); + + out->writeUInt(getNumColorLayers()); + + for(unsigned int i=0; ipeekInt(); + if (id != IVETERRAIN) throw Exception("Terrain::read(): Expected Terrain identification."); + + // Read Terrain's identification. + id = in->readInt(); + // If the osg class is inherited by any other class we should also read this from file. + osg::Group* group = dynamic_cast(this); + if(group) + ((ive::Group*)(group))->read(in); + else + throw Exception("Terrain::read(): Could not cast this osgTerrain::Terrain to an osg::Group."); + + LayerHelper helper; + + setLocator(helper.readLocator(in)); + + setElevationLayer(helper.readLayer(in)); + + unsigned int numColorLayers = in->readUInt(); + for(unsigned int i=0; i(technique)) + { + out->writeBool(true); + out->writeInt(IVEGEOMETRYTECHNIQUE); + } + else + { + out->writeBool(false); + } +} + +osgTerrain::TerrainTechnique* Terrain::readTerrainTechnique(DataInputStream* in) +{ + bool hasTechnique = in->readBool(); + if (!hasTechnique) return 0; + + int id = in->readInt(); + if (id==IVEGEOMETRYTECHNIQUE) + { + return new osgTerrain::GeometryTechnique; + } + else + { + return 0; + } +} diff --git a/src/osgPlugins/ive/Terrain.h b/src/osgPlugins/ive/Terrain.h new file mode 100644 index 000000000..fe5883793 --- /dev/null +++ b/src/osgPlugins/ive/Terrain.h @@ -0,0 +1,37 @@ +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2008 Robert Osfield + * + * This library is open source and may be redistributed and/or modified under + * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or + * (at your option) any later version. The full license is in LICENSE file + * included with this distribution, and on the openscenegraph.org website. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * OpenSceneGraph Public License for more details. +*/ + +#ifndef IVE_TERRAIN +#define IVE_TERRAIN 1 + +#include + +#include "ReadWrite.h" + +namespace ive +{ + +class Terrain : public osgTerrain::Terrain, public ReadWrite +{ +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); + + void writeTerrainTechnique(DataOutputStream* out, osgTerrain::TerrainTechnique* technique); + osgTerrain::TerrainTechnique* readTerrainTechnique(DataInputStream* out); + +}; + +} + +#endif