Added initial cut at support for osgVolume in .ive format.

This commit is contained in:
Robert Osfield 2009-05-05 18:34:44 +00:00
parent 1515b8d357
commit 2b09b0dffa
19 changed files with 821 additions and 6 deletions

View File

@ -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)

View File

@ -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() ["<<id<<"]"<<std::endl;
return layer;
}
osgTerrain::Locator* DataInputStream::readLocator()
{
@ -1834,6 +1885,32 @@ osgTerrain::Locator* DataInputStream::readLocator()
return locator;
}
osgVolume::Locator* DataInputStream::readVolumeLocator()
{
// Read statesets unique ID.
int id = readInt();
if (id<0) return 0;
// See if stateset is already in the list.
VolumeLocatorMap::iterator itr= _volumeLocatorMap.find(id);
if (itr!=_volumeLocatorMap.end()) return itr->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() ["<<id<<"]"<<std::endl;
return locator;
}
osg::Object* DataInputStream::readObject()
{
int id = readInt();

View File

@ -22,6 +22,7 @@
#include <osg/ref_ptr>
#include <osgTerrain/TerrainTile>
#include <osgVolume/VolumeTile>
#include <osgDB/ReaderWriter>
@ -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<int,osg::ref_ptr<osg::Node> > NodeMap;
typedef std::map<int,osg::ref_ptr<osgTerrain::Layer> > LayerMap;
typedef std::map<int,osg::ref_ptr<osgTerrain::Locator> > LocatorMap;
typedef std::map<int,osg::ref_ptr<osgVolume::Layer> > VolumeLayerMap;
typedef std::map<int,osg::ref_ptr<osgVolume::Locator> > VolumeLocatorMap;
bool _verboseOutput;
std::istream* _istream;
@ -144,6 +151,8 @@ private:
NodeMap _nodeMap;
LayerMap _layerMap;
LocatorMap _locatorMap;
VolumeLayerMap _volumeLayerMap;
VolumeLocatorMap _volumeLocatorMap;
bool _loadExternalReferenceFiles;

View File

@ -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 <osg/Notify>
#include <osg/io_utils>
#include <osgDB/FileUtils>
@ -1347,9 +1353,17 @@ void DataOutputStream::writeNode(const osg::Node* node)
else if(dynamic_cast<const osgTerrain::TerrainTile*>(node)){
((ive::TerrainTile*)(node))->write(this);
}
else if(dynamic_cast<const osgVolume::Volume*>(node)){
((ive::Volume*)(node))->write(this);
}
else if(dynamic_cast<const osgVolume::VolumeTile*>(node)){
((ive::VolumeTile*)(node))->write(this);
}
else if(dynamic_cast<const osg::Group*>(node)){
((ive::Group*)(node))->write(this);
}
else if(dynamic_cast<const osg::Billboard*>(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() ["<<itr->second<<"]"<<std::endl;
}
else
{
// id doesn't exist so create a new ID and
// register the stateset.
int id = _volumeLayerMap.size();
_volumeLayerMap[layer] = id;
// write the id.
writeInt(id);
if (dynamic_cast<const osgVolume::ImageLayer*>(layer))
{
((ive::VolumeImageLayer*)(layer))->write(this);
}
else if (dynamic_cast<const osgVolume::CompositeLayer*>(layer))
{
((ive::VolumeCompositeLayer*)(layer))->write(this);
}
else
{
throw Exception("Unknown layer in DataOutputStream::writeLayer()");
}
if (_verboseOutput) std::cout<<"read/writeLayer() ["<<id<<"]"<<std::endl;
}
}
void DataOutputStream::writeVolumeLocator(const osgVolume::Locator* locator)
{
if (locator==0)
{
writeInt(-1);
return;
}
VolumeLocatorMap::iterator itr = _volumeLocatorMap.find(locator);
if (itr!=_volumeLocatorMap.end())
{
// Id already exists so just write ID.
writeInt(itr->second);
if (_verboseOutput) std::cout<<"read/writeVolumeLocator() ["<<itr->second<<"]"<<std::endl;
}
else
{
// id doesn't exist so create a new ID and
// register the locator.
int id = _volumeLocatorMap.size();
_volumeLocatorMap[locator] = id;
// write the id.
writeInt(id);
// write the locator.
((ive::VolumeLocator*)(locator))->write(this);
if (_verboseOutput) std::cout<<"read/writeVolumeLocator() ["<<id<<"]"<<std::endl;
}
}
void DataOutputStream::writeObject(const osg::Object* object)
{
const osg::Node* node = dynamic_cast<const osg::Node*>(object);

View File

@ -19,6 +19,7 @@
#include <osgDB/ReaderWriter>
#include <osgTerrain/TerrainTile>
#include <osgVolume/VolumeTile>
#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<const osg::Node*,int> NodeMap;
typedef std::map<const osgTerrain::Layer*,int> LayerMap;
typedef std::map<const osgTerrain::Locator*,int> LocatorMap;
typedef std::map<const osgVolume::Layer*,int> VolumeLayerMap;
typedef std::map<const osgVolume::Locator*,int> 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;

View File

@ -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

View File

@ -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
}

View File

@ -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<osg::Group*>(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<osg::Group*>(this);
if(group)
((ive::Group*)(group))->read(in);
else
throw Exception("Volume::read(): Could not cast this osgVolume::Volume to an osg::Group.");
}

View File

@ -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 <osgVolume/Volume>
#include "ReadWrite.h"
namespace ive
{
class Volume : public osgVolume::Volume, public ReadWrite
{
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
};
}
#endif

View File

@ -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<osgVolume::Layer*>(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; i<getNumLayers(); ++i)
{
if(getLayer(i))
{
out->writeBool(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<osgVolume::Layer*>(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; i<numLayers; ++i)
{
bool readInlineLayer = in->readBool();
if (readInlineLayer)
{
addLayer(in->readVolumeLayer());
}
else
{
setFileName(i, in->readString());
}
}
}

View File

@ -0,0 +1,19 @@
#ifndef IVE_VOLIMECOMPOSITELAYER
#define IVE_VOLUMECOMPOSITELAYER 1
#include <osgVolume/Layer>
#include "ReadWrite.h"
namespace ive
{
class VolumeCompositeLayer : public osgVolume::CompositeLayer, public ReadWrite
{
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
};
}
#endif

View File

@ -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 <osgDB/ReadFile>
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<osgVolume::Layer*>(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<osgVolume::Layer*>(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));
}
}

View File

@ -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 <osgVolume/Layer>
#include "ReadWrite.h"
namespace ive
{
class VolumeImageLayer : public osgVolume::ImageLayer, public ReadWrite
{
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
};
}
#endif

View File

@ -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 <osgDB/ReadFile>
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<osg::Object*>(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<osg::Object*>(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());
}

View File

@ -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 <osgVolume/Layer>
#include "ReadWrite.h"
namespace ive
{
class VolumeLayer : public osgVolume::Layer, public ReadWrite
{
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
};
}
#endif

View File

@ -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<osg::Object*>(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<osg::Object*>(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());
}

View File

@ -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 <osgVolume/Locator>
#include "ReadWrite.h"
namespace ive{
class VolumeLocator : public osgVolume::Locator, public ReadWrite {
public:
void write(DataOutputStream* out);
void read(DataInputStream* in);
};
}
#endif

View File

@ -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 <osgVolume/RayTracedTechnique>
#include <osgVolume/FixedFunctionTechnique>
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<osg::Group*>(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<osg::Group*>(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<osgVolume::RayTracedTechnique*>(technique))
{
out->writeBool(true);
out->writeInt(IVEVOLUMERAYTRACEDTECHNIQUE);
}
if (dynamic_cast<osgVolume::FixedFunctionTechnique*>(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;
}
}

View File

@ -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 <osgVolume/VolumeTile>
#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