Added support for reading and writing osgTerrain objects
This commit is contained in:
@@ -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)
|
||||
|
||||
82
src/osgPlugins/ive/CompositeLayer.cpp
Normal file
82
src/osgPlugins/ive/CompositeLayer.cpp
Normal file
@@ -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<osgTerrain::Layer*>(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; i<getNumLayers(); ++i)
|
||||
{
|
||||
if(getLayer(i))
|
||||
{
|
||||
out->writeBool(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<osgTerrain::Layer*>(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; i<numLayers; ++i)
|
||||
{
|
||||
bool readInlineLayer = in->readBool();
|
||||
if (readInlineLayer)
|
||||
{
|
||||
addLayer(helper.readLayer(in));
|
||||
}
|
||||
else
|
||||
{
|
||||
addLayer(in->readString());
|
||||
}
|
||||
}
|
||||
}
|
||||
19
src/osgPlugins/ive/CompositeLayer.h
Normal file
19
src/osgPlugins/ive/CompositeLayer.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef IVE_COMPOSITELAYER
|
||||
#define IVE_COMPOSITELAYER 1
|
||||
|
||||
#include <osgTerrain/Terrain>
|
||||
#include "ReadWrite.h"
|
||||
|
||||
namespace ive
|
||||
{
|
||||
|
||||
class CompositeLayer : public osgTerrain::CompositeLayer, public ReadWrite
|
||||
{
|
||||
public:
|
||||
void write(DataOutputStream* out);
|
||||
void read(DataInputStream* in);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -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);
|
||||
|
||||
@@ -89,6 +89,8 @@
|
||||
|
||||
#include "Text.h"
|
||||
|
||||
#include "Terrain.h"
|
||||
|
||||
#include <osg/Endian>
|
||||
#include <osg/Notify>
|
||||
#include <osg/io_utils>
|
||||
@@ -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()");
|
||||
}
|
||||
|
||||
@@ -90,6 +90,8 @@
|
||||
|
||||
#include "Text.h"
|
||||
|
||||
#include "Terrain.h"
|
||||
|
||||
#include <osg/Notify>
|
||||
#include <osg/io_utils>
|
||||
#include <osgDB/FileUtils>
|
||||
@@ -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<const osgFX::MultiTextureControl*>(node)){
|
||||
((ive::MultiTextureControl*)(node))->write(this);
|
||||
}
|
||||
else if(dynamic_cast<const osgTerrain::Terrain*>(node)){
|
||||
((ive::Terrain*)(node))->write(this);
|
||||
}
|
||||
else if(dynamic_cast<const osg::Group*>(node)){
|
||||
((ive::Group*)(node))->write(this);
|
||||
}
|
||||
|
||||
86
src/osgPlugins/ive/ImageLayer.cpp
Normal file
86
src/osgPlugins/ive/ImageLayer.cpp
Normal file
@@ -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 <osgDB/ReadFile>
|
||||
|
||||
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<osgTerrain::Layer*>(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<osgTerrain::Layer*>(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()));
|
||||
}
|
||||
|
||||
}
|
||||
32
src/osgPlugins/ive/ImageLayer.h
Normal file
32
src/osgPlugins/ive/ImageLayer.h
Normal file
@@ -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 <osgTerrain/Terrain>
|
||||
#include "ReadWrite.h"
|
||||
|
||||
namespace ive
|
||||
{
|
||||
|
||||
class ImageLayer : public osgTerrain::ImageLayer, public ReadWrite
|
||||
{
|
||||
public:
|
||||
void write(DataOutputStream* out);
|
||||
void read(DataInputStream* in);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
181
src/osgPlugins/ive/Layer.cpp
Normal file
181
src/osgPlugins/ive/Layer.cpp
Normal file
@@ -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 <osgDB/ReadFile>
|
||||
|
||||
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<osg::Object*>(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<osg::Object*>(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<osgTerrain::HeightFieldLayer*>(layer))
|
||||
{
|
||||
((ive::HeightFieldLayer*)(layer))->write(out);
|
||||
}
|
||||
else if (dynamic_cast<osgTerrain::ImageLayer*>(layer))
|
||||
{
|
||||
((ive::ImageLayer*)(layer))->write(out);
|
||||
}
|
||||
else if (dynamic_cast<osgTerrain::CompositeLayer*>(layer))
|
||||
{
|
||||
((ive::CompositeLayer*)(layer))->write(out);
|
||||
}
|
||||
else if (dynamic_cast<osgTerrain::ProxyLayer*>(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<osg::Object> object = osgDB::readObjectFile(filename+".gdal");
|
||||
osgTerrain::ProxyLayer* proxyLayer = dynamic_cast<osgTerrain::ProxyLayer*>(object.get());
|
||||
|
||||
osg::ref_ptr<osgTerrain::Locator> 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;
|
||||
}
|
||||
45
src/osgPlugins/ive/Layer.h
Normal file
45
src/osgPlugins/ive/Layer.h
Normal file
@@ -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 <osgTerrain/Terrain>
|
||||
#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
|
||||
84
src/osgPlugins/ive/Locator.cpp
Normal file
84
src/osgPlugins/ive/Locator.cpp
Normal file
@@ -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<osg::Object*>(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<osg::Object*>(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<osgTerrain::Locator::CoordinateSystemType>(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());
|
||||
|
||||
}
|
||||
28
src/osgPlugins/ive/Locator.h
Normal file
28
src/osgPlugins/ive/Locator.h
Normal 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_LOCATOR
|
||||
#define IVE_LOCATOR 1
|
||||
|
||||
#include <osgTerrain/Locator>
|
||||
#include "ReadWrite.h"
|
||||
|
||||
namespace ive{
|
||||
class Locator : public osgTerrain::Locator, public ReadWrite {
|
||||
public:
|
||||
void write(DataOutputStream* out);
|
||||
void read(DataInputStream* in);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -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
|
||||
|
||||
|
||||
109
src/osgPlugins/ive/Terrain.cpp
Normal file
109
src/osgPlugins/ive/Terrain.cpp
Normal file
@@ -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 <osgTerrain/GeometryTechnique>
|
||||
|
||||
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<osg::Group*>(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; i<getNumColorLayers(); ++i)
|
||||
{
|
||||
helper.writeLayer(out, getColorLayer(i));
|
||||
}
|
||||
|
||||
writeTerrainTechnique(out, getTerrainTechnique());
|
||||
|
||||
}
|
||||
|
||||
void Terrain::read(DataInputStream* in)
|
||||
{
|
||||
// Peek on Terrain's identification.
|
||||
int id = in->peekInt();
|
||||
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<osg::Group*>(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<numColorLayers; ++i)
|
||||
{
|
||||
setColorLayer(i, helper.readLayer(in));
|
||||
}
|
||||
|
||||
setTerrainTechnique(readTerrainTechnique(in));
|
||||
|
||||
}
|
||||
|
||||
void Terrain::writeTerrainTechnique(DataOutputStream* out, osgTerrain::TerrainTechnique* technique)
|
||||
{
|
||||
if (dynamic_cast<osgTerrain::GeometryTechnique*>(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;
|
||||
}
|
||||
}
|
||||
37
src/osgPlugins/ive/Terrain.h
Normal file
37
src/osgPlugins/ive/Terrain.h
Normal 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_TERRAIN
|
||||
#define IVE_TERRAIN 1
|
||||
|
||||
#include <osgTerrain/Terrain>
|
||||
|
||||
#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
|
||||
Reference in New Issue
Block a user