From 2b09b0dffaafb11f4967ceb57fc2657bc314b575 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 5 May 2009 18:34:44 +0000 Subject: [PATCH] Added initial cut at support for osgVolume in .ive format. --- src/osgPlugins/ive/CMakeLists.txt | 14 ++- src/osgPlugins/ive/DataInputStream.cpp | 79 +++++++++++++++- src/osgPlugins/ive/DataInputStream.h | 11 ++- src/osgPlugins/ive/DataOutputStream.cpp | 93 ++++++++++++++++++ src/osgPlugins/ive/DataOutputStream.h | 12 ++- src/osgPlugins/ive/ReadWrite.h | 13 ++- src/osgPlugins/ive/ReaderWriterIVE.cpp | 5 + src/osgPlugins/ive/Volume.cpp | 47 +++++++++ src/osgPlugins/ive/Volume.h | 34 +++++++ src/osgPlugins/ive/VolumeCompositeLayer.cpp | 79 ++++++++++++++++ src/osgPlugins/ive/VolumeCompositeLayer.h | 19 ++++ src/osgPlugins/ive/VolumeImageLayer.cpp | 72 ++++++++++++++ src/osgPlugins/ive/VolumeImageLayer.h | 33 +++++++ src/osgPlugins/ive/VolumeLayer.cpp | 61 ++++++++++++ src/osgPlugins/ive/VolumeLayer.h | 33 +++++++ src/osgPlugins/ive/VolumeLocator.cpp | 57 +++++++++++ src/osgPlugins/ive/VolumeLocator.h | 28 ++++++ src/osgPlugins/ive/VolumeTile.cpp | 100 ++++++++++++++++++++ src/osgPlugins/ive/VolumeTile.h | 37 ++++++++ 19 files changed, 821 insertions(+), 6 deletions(-) create mode 100644 src/osgPlugins/ive/Volume.cpp create mode 100644 src/osgPlugins/ive/Volume.h create mode 100644 src/osgPlugins/ive/VolumeCompositeLayer.cpp create mode 100644 src/osgPlugins/ive/VolumeCompositeLayer.h create mode 100644 src/osgPlugins/ive/VolumeImageLayer.cpp create mode 100644 src/osgPlugins/ive/VolumeImageLayer.h create mode 100644 src/osgPlugins/ive/VolumeLayer.cpp create mode 100644 src/osgPlugins/ive/VolumeLayer.h create mode 100644 src/osgPlugins/ive/VolumeLocator.cpp create mode 100644 src/osgPlugins/ive/VolumeLocator.h create mode 100644 src/osgPlugins/ive/VolumeTile.cpp create mode 100644 src/osgPlugins/ive/VolumeTile.h diff --git a/src/osgPlugins/ive/CMakeLists.txt b/src/osgPlugins/ive/CMakeLists.txt index 36b4683f6..d7bbe3674 100644 --- a/src/osgPlugins/ive/CMakeLists.txt +++ b/src/osgPlugins/ive/CMakeLists.txt @@ -23,6 +23,7 @@ SET(TARGET_SRC ClusterCullingCallback.cpp ColorMask.cpp CompositeLayer.cpp + VolumeCompositeLayer.cpp SwitchLayer.cpp ConeSector.cpp ConvexPlanarOccluder.cpp @@ -53,8 +54,10 @@ SET(TARGET_SRC Image.cpp ImageSequence.cpp ImageLayer.cpp + VolumeImageLayer.cpp Impostor.cpp Layer.cpp + VolumeLayer.cpp Light.cpp LightModel.cpp LightPoint.cpp @@ -63,6 +66,7 @@ SET(TARGET_SRC LineStipple.cpp LineWidth.cpp Locator.cpp + VolumeLocator.cpp LOD.cpp Material.cpp MatrixTransform.cpp @@ -95,6 +99,8 @@ SET(TARGET_SRC Stencil.cpp Switch.cpp TerrainTile.cpp + Volume.cpp + VolumeTile.cpp TexEnvCombine.cpp TexEnv.cpp TexGen.cpp @@ -138,6 +144,7 @@ SET(TARGET_H ClipPlane.h ClusterCullingCallback.h ColorMask.h + VolumeCompositeLayer.h CompositeLayer.h SwitchLayer.h ConeSector.h @@ -170,9 +177,11 @@ SET(TARGET_H Image.h ImageSequence.h ImageLayer.h + VolumeImageLayer.h Impostor.h IveVersion.h Layer.h + VolumeLayer.h Light.h LightModel.h LightPoint.h @@ -181,6 +190,7 @@ SET(TARGET_H LineStipple.h LineWidth.h Locator.h + VolumeLocator.h LOD.h Material.h MatrixTransform.h @@ -212,6 +222,8 @@ SET(TARGET_H Stencil.h Switch.h TerrainTile.h + Volume.h + VolumeTile.h TexEnvCombine.h TexEnv.h TexGen.h @@ -238,7 +250,7 @@ SET(TARGET_H Scribe.h SpecularHighlights.h ) -SET(TARGET_ADDED_LIBRARIES osgSim osgFX osgText osgTerrain) +SET(TARGET_ADDED_LIBRARIES osgSim osgFX osgText osgTerrain osgVolume) IF(ZLIB_FOUND) SET(TARGET_LIBRARIES_VARS ZLIB_LIBRARY) diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index 43900fd11..8fa82050d 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -96,6 +96,12 @@ #include "Scribe.h" #include "SpecularHighlights.h" +#include "Volume.h" +#include "VolumeTile.h" +#include "VolumeImageLayer.h" +#include "VolumeCompositeLayer.h" +#include "VolumeLocator.h" + #include "Geometry.h" #include "ShapeDrawable.h" #include "Shape.h" @@ -1721,11 +1727,18 @@ osg::Node* DataInputStream::readNode() node = new osgFX::SpecularHighlights(); ((ive::SpecularHighlights*)(node))->read(this); } - else if(nodeTypeID== IVETERRAINTILE){ node = new osgTerrain::TerrainTile(); ((ive::TerrainTile*)(node))->read(this); } + else if(nodeTypeID== IVEVOLUME){ + node = new osgVolume::Volume(); + ((ive::Volume*)(node))->read(this); + } + else if(nodeTypeID== IVEVOLUMETILE){ + node = new osgVolume::VolumeTile(); + ((ive::VolumeTile*)(node))->read(this); + } else{ throw Exception("Unknown node identification in DataInputStream::readNode()"); } @@ -1808,6 +1821,44 @@ osgTerrain::Layer* DataInputStream::readLayer() return layer; } +osgVolume::Layer* DataInputStream::readVolumeLayer() +{ + // Read node unique ID. + int id = readInt(); + if (id<0) return 0; + + // See if layer is already in the list. + VolumeLayerMap::iterator itr= _volumeLayerMap.find(id); + if (itr!=_volumeLayerMap.end()) return itr->second.get(); + + // Layer is not in list. + // Create a new Layer, + + osgVolume::Layer* layer = 0; + int layerid = peekInt(); + + if (layerid==IVEVOLUMEIMAGELAYER) + { + layer = new osgVolume::ImageLayer; + ((ive::VolumeImageLayer*)(layer))->read(this); + } + else if (layerid==IVEVOLUMECOMPOSITELAYER) + { + layer = new osgVolume::CompositeLayer; + ((ive::VolumeCompositeLayer*)(layer))->read(this); + } + else{ + throw Exception("Unknown layer identification in DataInputStream::readLayer()"); + } + + // and add it to the node map, + _volumeLayerMap[id] = layer; + + + if (_verboseOutput) std::cout<<"read/writeVolumeLayer() ["<second.get(); + + // Locator is not in list. + // Create a new locator, + osgVolume::Locator* locator = new osgVolume::Locator(); + + // read its properties from stream + ((ive::VolumeLocator*)(locator))->read(this); + + // and add it to the locator map, + _volumeLocatorMap[id] = locator; + + if (_verboseOutput) std::cout<<"read/writeVolumeLocator() ["< #include +#include #include @@ -99,9 +100,13 @@ public: osg::Drawable* readDrawable(); osg::Shape* readShape(); osg::Node* readNode(); + osgTerrain::Layer* readLayer(); osgTerrain::Locator* readLocator(); - + + osgVolume::Layer* readVolumeLayer(); + osgVolume::Locator* readVolumeLocator(); + osg::Object* readObject(); // Set and get if must be generated external reference ive files @@ -119,6 +124,8 @@ public: typedef std::map > NodeMap; typedef std::map > LayerMap; typedef std::map > LocatorMap; + typedef std::map > VolumeLayerMap; + typedef std::map > VolumeLocatorMap; bool _verboseOutput; std::istream* _istream; @@ -144,6 +151,8 @@ private: NodeMap _nodeMap; LayerMap _layerMap; LocatorMap _locatorMap; + VolumeLayerMap _volumeLayerMap; + VolumeLocatorMap _volumeLocatorMap; bool _loadExternalReferenceFiles; diff --git a/src/osgPlugins/ive/DataOutputStream.cpp b/src/osgPlugins/ive/DataOutputStream.cpp index cfeddaf6b..4c0522eee 100644 --- a/src/osgPlugins/ive/DataOutputStream.cpp +++ b/src/osgPlugins/ive/DataOutputStream.cpp @@ -110,6 +110,12 @@ #include "CompositeLayer.h" #include "SwitchLayer.h" +#include "Volume.h" +#include "VolumeTile.h" +#include "VolumeImageLayer.h" +#include "VolumeCompositeLayer.h" +#include "VolumeLocator.h" + #include #include #include @@ -1347,9 +1353,17 @@ void DataOutputStream::writeNode(const osg::Node* node) else if(dynamic_cast(node)){ ((ive::TerrainTile*)(node))->write(this); } + else if(dynamic_cast(node)){ + ((ive::Volume*)(node))->write(this); + } + else if(dynamic_cast(node)){ + ((ive::VolumeTile*)(node))->write(this); + } + else if(dynamic_cast(node)){ ((ive::Group*)(node))->write(this); } + else if(dynamic_cast(node)){ ((ive::Billboard*)(node))->write(this); } @@ -1615,6 +1629,85 @@ void DataOutputStream::writeLocator(const osgTerrain::Locator* locator) } } +void DataOutputStream::writeVolumeLayer(const osgVolume::Layer* layer) +{ + if (layer==0) + { + writeInt(-1); + return; + } + + VolumeLayerMap::iterator itr = _volumeLayerMap.find(layer); + if (itr!=_volumeLayerMap.end()) + { + // Id already exists so just write ID. + writeInt(itr->second); + + if (_verboseOutput) std::cout<<"read/writeLayer() ["<second<<"]"<(layer)) + { + ((ive::VolumeImageLayer*)(layer))->write(this); + } + else if (dynamic_cast(layer)) + { + ((ive::VolumeCompositeLayer*)(layer))->write(this); + } + else + { + throw Exception("Unknown layer in DataOutputStream::writeLayer()"); + } + if (_verboseOutput) std::cout<<"read/writeLayer() ["<second); + + if (_verboseOutput) std::cout<<"read/writeVolumeLocator() ["<second<<"]"<write(this); + + if (_verboseOutput) std::cout<<"read/writeVolumeLocator() ["<(object); diff --git a/src/osgPlugins/ive/DataOutputStream.h b/src/osgPlugins/ive/DataOutputStream.h index df094b4b5..a10265382 100644 --- a/src/osgPlugins/ive/DataOutputStream.h +++ b/src/osgPlugins/ive/DataOutputStream.h @@ -19,6 +19,7 @@ #include #include +#include #include "IveVersion.h" #include "DataTypeSize.h" @@ -102,7 +103,10 @@ public: void writeLayer(const osgTerrain::Layer* layer); void writeLocator(const osgTerrain::Locator* locator); - + + void writeVolumeLayer(const osgVolume::Layer* layer); + void writeVolumeLocator(const osgVolume::Locator* locator); + void writeObject(const osg::Object* object); void setWriteDirectory(const std::string& directoryName) { _writeDirectory = directoryName; } @@ -151,7 +155,9 @@ private: typedef std::map NodeMap; typedef std::map LayerMap; typedef std::map LocatorMap; - + typedef std::map VolumeLayerMap; + typedef std::map VolumeLocatorMap; + StateSetMap _stateSetMap; StateAttributeMap _stateAttributeMap; UniformMap _uniformMap; @@ -161,6 +167,8 @@ private: NodeMap _nodeMap; LayerMap _layerMap; LocatorMap _locatorMap; + VolumeLayerMap _volumeLayerMap; + VolumeLocatorMap _volumeLocatorMap; std::string _writeDirectory; bool _includeExternalReferences; diff --git a/src/osgPlugins/ive/ReadWrite.h b/src/osgPlugins/ive/ReadWrite.h index 44ad38f18..87cdc153d 100644 --- a/src/osgPlugins/ive/ReadWrite.h +++ b/src/osgPlugins/ive/ReadWrite.h @@ -138,7 +138,18 @@ namespace ive { #define IVEVALIDRANGE 0x0020000B #define IVENODATAVALUE 0x0020000C #define IVESWITCHLAYER 0x0020000D -//#define IVETERRAIN 0x0020000A +#define IVETERRAIN 0x0020000A + +// osgVolume classes +#define IVEVOLUMETILE 0x00300001 +#define IVEVOLUMELOCATOR 0x00300002 +#define IVEVOLUMELAYER 0x00300003 +#define IVEVOLUMEIMAGELAYER 0x00300004 +#define IVEVOLUMECOMPOSITELAYER 0x00300005 +#define IVEVOLUMETECHNIQUE 0x00300008 +#define IVEVOLUMERAYTRACEDTECHNIQUE 0x00300009 +#define IVEVOLUMEFIXEDPIPELINETECHNIQUE 0x00300009 +#define IVEVOLUME 0x0030000A // osgFX classes #define IVEMULTITEXTURECONTROL 0x01000001 diff --git a/src/osgPlugins/ive/ReaderWriterIVE.cpp b/src/osgPlugins/ive/ReaderWriterIVE.cpp index cad337d02..f33a50c2b 100644 --- a/src/osgPlugins/ive/ReaderWriterIVE.cpp +++ b/src/osgPlugins/ive/ReaderWriterIVE.cpp @@ -92,6 +92,10 @@ class ReaderWriterIVE : public ReaderWriter virtual ReadResult readNode(std::istream& fin, const Options* options) const { +#if 1 + ive::DataInputStream in(&fin, options); + return in.readNode(); +#else try{ // Create datainputstream. ive::DataInputStream in(&fin, options); @@ -102,6 +106,7 @@ class ReaderWriterIVE : public ReaderWriter { return e.getError(); } +#endif } diff --git a/src/osgPlugins/ive/Volume.cpp b/src/osgPlugins/ive/Volume.cpp new file mode 100644 index 000000000..75599fe7b --- /dev/null +++ b/src/osgPlugins/ive/Volume.cpp @@ -0,0 +1,47 @@ +/* -*-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 "Volume.h" +#include "Group.h" + +using namespace ive; + +void Volume::write(DataOutputStream* out) +{ + // Write Volume's identification. + out->writeInt(IVEVOLUME); + // 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("Volume::write(): Could not cast this osgVolume::Volume to an osg::Group."); +} + +void Volume::read(DataInputStream* in) +{ + // Peek on Volume's identification. + int id = in->peekInt(); + if (id != IVEVOLUME) throw Exception("Volume::read(): Expected Volume identification."); + + // Read Volume'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("Volume::read(): Could not cast this osgVolume::Volume to an osg::Group."); + +} diff --git a/src/osgPlugins/ive/Volume.h b/src/osgPlugins/ive/Volume.h new file mode 100644 index 000000000..c2696d0c0 --- /dev/null +++ b/src/osgPlugins/ive/Volume.h @@ -0,0 +1,34 @@ +/* -*-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_VOLUME +#define IVE_VOLUME 1 + +#include + +#include "ReadWrite.h" + +namespace ive +{ + +class Volume : public osgVolume::Volume, public ReadWrite +{ +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); + +}; + +} + +#endif diff --git a/src/osgPlugins/ive/VolumeCompositeLayer.cpp b/src/osgPlugins/ive/VolumeCompositeLayer.cpp new file mode 100644 index 000000000..6cd76aaeb --- /dev/null +++ b/src/osgPlugins/ive/VolumeCompositeLayer.cpp @@ -0,0 +1,79 @@ +/* -*-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 "VolumeCompositeLayer.h" +#include "VolumeLayer.h" +#include "Layer.h" + +using namespace ive; + +void VolumeCompositeLayer::write(DataOutputStream* out) +{ + // Write Layer's identification. + out->writeInt(IVEVOLUMECOMPOSITELAYER); + + // If the osg class is inherited by any other class we should also write this to file. + osgVolume::Layer* layer = dynamic_cast(this); + if (layer) + ((ive::VolumeLayer*)(layer))->write(out); + else + throw Exception("VolumeCompositeLayer::write(): Could not cast this osgVolume::CompositeLayer to an osgVolume::Layer."); + + out->writeUInt(getNumLayers()); + for(unsigned int i=0; iwriteBool(true); + out->writeVolumeLayer(getLayer(i)); + } + else + { + out->writeBool(false); + out->writeString(getFileName(i)); + } + } +} + +void VolumeCompositeLayer::read(DataInputStream* in) +{ + // Peek on Layer's identification. + int id = in->peekInt(); + if (id != IVEVOLUMECOMPOSITELAYER) + throw Exception("VolumeCompositeLayer::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. + osgVolume::Layer* layer = dynamic_cast(this); + if (layer) + ((ive::VolumeLayer*)(layer))->read(in); + else + throw Exception("VolumeCompositeLayer::read(): Could not cast this osgVolume::Layer to an osg::Group."); + + unsigned int numLayers = in->readUInt(); + for(unsigned int i=0; ireadBool(); + if (readInlineLayer) + { + addLayer(in->readVolumeLayer()); + } + else + { + setFileName(i, in->readString()); + } + } +} diff --git a/src/osgPlugins/ive/VolumeCompositeLayer.h b/src/osgPlugins/ive/VolumeCompositeLayer.h new file mode 100644 index 000000000..567bef11e --- /dev/null +++ b/src/osgPlugins/ive/VolumeCompositeLayer.h @@ -0,0 +1,19 @@ +#ifndef IVE_VOLIMECOMPOSITELAYER +#define IVE_VOLUMECOMPOSITELAYER 1 + +#include +#include "ReadWrite.h" + +namespace ive +{ + +class VolumeCompositeLayer : public osgVolume::CompositeLayer, public ReadWrite +{ +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; + +} + +#endif diff --git a/src/osgPlugins/ive/VolumeImageLayer.cpp b/src/osgPlugins/ive/VolumeImageLayer.cpp new file mode 100644 index 000000000..627c856a6 --- /dev/null +++ b/src/osgPlugins/ive/VolumeImageLayer.cpp @@ -0,0 +1,72 @@ +/* -*-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 "VolumeImageLayer.h" +#include "VolumeLayer.h" + +#include + +using namespace ive; + +void VolumeImageLayer::write(DataOutputStream* out) +{ + // Write Layer's identification. + out->writeInt(IVEVOLUMEIMAGELAYER); + + // If the osg class is inherited by any other class we should also write this to file. + osgVolume::Layer* layer = dynamic_cast(this); + if (layer) + ((ive::VolumeLayer*)(layer))->write(out); + else + throw Exception("VolumeImageLayer::write(): Could not cast this osgVolume::ImageLayer to an osgVolume::Layer."); + + + IncludeImageMode imMode = out->getIncludeImageMode(getImage()); + + if (getFileName().empty() && imMode==IMAGE_REFERENCE_FILE) imMode = IMAGE_INCLUDE_DATA; + + out->writeChar(imMode); + out->writeImage(imMode,getImage()); + +} + +void VolumeImageLayer::read(DataInputStream* in) +{ + // Peek on Layer's identification. + int id = in->peekInt(); + if (id != IVEVOLUMEIMAGELAYER) + throw Exception("VolumeImageLayer::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. + osgVolume::Layer* layer = dynamic_cast(this); + if (layer) + ((ive::VolumeLayer*)(layer))->read(in); + else + throw Exception("ImageLayer::read(): Could not cast this osgVolume::Layer to an osg::Group."); + + // Should we read image data from stream + IncludeImageMode includeImg = (IncludeImageMode)in->readChar(); + + if (includeImg==IMAGE_REFERENCE_FILE) + { + setFileName(in->readString()); + } + else + { + setImage(in->readImage(includeImg)); + } +} diff --git a/src/osgPlugins/ive/VolumeImageLayer.h b/src/osgPlugins/ive/VolumeImageLayer.h new file mode 100644 index 000000000..518686e9e --- /dev/null +++ b/src/osgPlugins/ive/VolumeImageLayer.h @@ -0,0 +1,33 @@ +/* -*-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_VOLUMEIMAGELAYER +#define IVE_VOLUMEIMAGELAYER 1 + +#include + +#include "ReadWrite.h" + +namespace ive +{ + +class VolumeImageLayer : public osgVolume::ImageLayer, public ReadWrite +{ +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; + +} + +#endif diff --git a/src/osgPlugins/ive/VolumeLayer.cpp b/src/osgPlugins/ive/VolumeLayer.cpp new file mode 100644 index 000000000..9d0540b0c --- /dev/null +++ b/src/osgPlugins/ive/VolumeLayer.cpp @@ -0,0 +1,61 @@ +/* -*-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 "VolumeLayer.h" +#include "VolumeLocator.h" +#include "Object.h" + +#include "VolumeImageLayer.h" +#include "VolumeCompositeLayer.h" + +#include + +using namespace ive; + +void VolumeLayer::write(DataOutputStream* out) +{ + // Write Layer's identification. + out->writeInt(IVEVOLUMELAYER); + + // 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("VolumeLayer::write(): Could not cast this osgVolume::Layer to an osg::Object."); + + out->writeVolumeLocator(getLocator()); +} + +void VolumeLayer::read(DataInputStream* in) +{ + // Peek on Layer's identification. + int id = in->peekInt(); + if (id != IVEVOLUMELAYER) + throw Exception("VolumeLayer::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("VolumeLayer::read(): Could not cast this osgVolume::Layer to an osg::Object."); + + setLocator(in->readVolumeLocator()); + +} + diff --git a/src/osgPlugins/ive/VolumeLayer.h b/src/osgPlugins/ive/VolumeLayer.h new file mode 100644 index 000000000..e8db0b8cc --- /dev/null +++ b/src/osgPlugins/ive/VolumeLayer.h @@ -0,0 +1,33 @@ +/* -*-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_VOLUMELAYER +#define IVE_VOLUMELAYER 1 + +#include +#include "ReadWrite.h" + +namespace ive +{ + +class VolumeLayer : public osgVolume::Layer, public ReadWrite +{ + public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; + + +} + +#endif diff --git a/src/osgPlugins/ive/VolumeLocator.cpp b/src/osgPlugins/ive/VolumeLocator.cpp new file mode 100644 index 000000000..4843c17ba --- /dev/null +++ b/src/osgPlugins/ive/VolumeLocator.cpp @@ -0,0 +1,57 @@ +/* -*-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 "VolumeLocator.h" +#include "Object.h" + +using namespace ive; + +void VolumeLocator::write(DataOutputStream* out) +{ + // Write Locator's identification. + out->writeInt(IVEVOLUMELOCATOR); + + // 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("VolumeLocaotr::write(): Could not cast this osgVolume::Locator to an osg::Object."); + + out->writeMatrixd(getTransform()); +} + +void VolumeLocator::read(DataInputStream* in) +{ + // Peek on Locator's identification. + int id = in->peekInt(); + if(id != IVEVOLUMELOCATOR) + { + throw Exception("VolumeLocator::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("VolumeLocator::read(): Could not cast this osgVolume::Locator to an osg::Object."); + + setTransform(in->readMatrixd()); + +} diff --git a/src/osgPlugins/ive/VolumeLocator.h b/src/osgPlugins/ive/VolumeLocator.h new file mode 100644 index 000000000..c94914e49 --- /dev/null +++ b/src/osgPlugins/ive/VolumeLocator.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_VOLUMELOCATOR +#define IVE_VOLUMELOCATOR 1 + +#include +#include "ReadWrite.h" + +namespace ive{ +class VolumeLocator : public osgVolume::Locator, public ReadWrite { +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); +}; +} + +#endif diff --git a/src/osgPlugins/ive/VolumeTile.cpp b/src/osgPlugins/ive/VolumeTile.cpp new file mode 100644 index 000000000..3116cce62 --- /dev/null +++ b/src/osgPlugins/ive/VolumeTile.cpp @@ -0,0 +1,100 @@ +/* -*-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 "VolumeTile.h" +#include "Group.h" +#include "VolumeLayer.h" + +#include +#include + +using namespace ive; + +void VolumeTile::write(DataOutputStream* out) +{ + // Write VolumeTile's identification. + out->writeInt(IVEVOLUMETILE); + // 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("VolumeTile::write(): Could not cast this osgVolume::VolumeTile to an osg::Group."); + + + out->writeVolumeLocator(getLocator()); + out->writeVolumeLayer(getLayer()); + + writeVolumeTechnique(out, getVolumeTechnique()); + +} + +void VolumeTile::read(DataInputStream* in) +{ + // Peek on VolumeTile's identification. + int id = in->peekInt(); + if (id != IVEVOLUMETILE) throw Exception("VolumeTile::read(): Expected Volume identification."); + + // Read VolumeTile'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("VolumeTile::read(): Could not cast this osgVolume::VolumeTile to an osg::Group."); + + setLocator(in->readVolumeLocator()); + setLayer(in->readVolumeLayer()); + + setVolumeTechnique(readVolumeTechnique(in)); +} + +void VolumeTile::writeVolumeTechnique(DataOutputStream* out, osgVolume::VolumeTechnique* technique) +{ + if (dynamic_cast(technique)) + { + out->writeBool(true); + out->writeInt(IVEVOLUMERAYTRACEDTECHNIQUE); + } + if (dynamic_cast(technique)) + { + out->writeBool(true); + out->writeInt(IVEVOLUMEFIXEDPIPELINETECHNIQUE); + } + else + { + out->writeBool(false); + } +} + +osgVolume::VolumeTechnique* VolumeTile::readVolumeTechnique(DataInputStream* in) +{ + bool hasTechnique = in->readBool(); + if (!hasTechnique) return 0; + + int id = in->readInt(); + if (id==IVEVOLUMERAYTRACEDTECHNIQUE) + { + return new osgVolume::RayTracedTechnique; + } + else if (id==IVEVOLUMEFIXEDPIPELINETECHNIQUE) + { + return new osgVolume::FixedFunctionTechnique; + } + else + { + return 0; + } +} diff --git a/src/osgPlugins/ive/VolumeTile.h b/src/osgPlugins/ive/VolumeTile.h new file mode 100644 index 000000000..52cf9e0a5 --- /dev/null +++ b/src/osgPlugins/ive/VolumeTile.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_VOLUMETILE +#define IVE_VOLUMETILE 1 + +#include + +#include "ReadWrite.h" + +namespace ive +{ + +class VolumeTile : public osgVolume::VolumeTile, public ReadWrite +{ +public: + void write(DataOutputStream* out); + void read(DataInputStream* in); + + void writeVolumeTechnique(DataOutputStream* out, osgVolume::VolumeTechnique* technique); + osgVolume::VolumeTechnique* readVolumeTechnique(DataInputStream* out); + +}; + +} + +#endif