/********************************************************************** * * FILE: DataInputStream.cpp * * DESCRIPTION: Implements methods to read simple datatypes from an * input stream. * * CREATED BY: Rune Schmidt Jensen * * HISTORY: Created 11.03.2003 * Updated for texture1D by Don Burns, 27.1.2004 * Updated for light model - Stan Blinov at 25 august 7512 from World Creation (7.09.2004) * * * Copyright 2003 VR-C **********************************************************************/ #include "DataInputStream.h" #include "StateSet.h" #include "AlphaFunc.h" #include "BlendColor.h" #include "Stencil.h" #include "BlendFunc.h" #include "BlendEquation.h" #include "Depth.h" #include "Material.h" #include "CullFace.h" #include "ColorMask.h" #include "ClipPlane.h" #include "PolygonOffset.h" #include "PolygonMode.h" #include "ShadeModel.h" #include "Point.h" #include "LineWidth.h" #include "LineStipple.h" #include "Texture1D.h" #include "Texture2D.h" #include "Texture2DArray.h" #include "Texture3D.h" #include "TextureCubeMap.h" #include "TextureRectangle.h" #include "TexEnv.h" #include "TexEnvCombine.h" #include "TexGen.h" #include "TexMat.h" #include "FragmentProgram.h" #include "VertexProgram.h" #include "LightModel.h" #include "ProxyNode.h" #include "FrontFace.h" #include "Program.h" #include "Viewport.h" #include "Scissor.h" #include "Image.h" #include "ImageSequence.h" #include "PointSprite.h" #include "Multisample.h" #include "Fog.h" #include "Light.h" #include "PolygonStipple.h" #include "Node.h" #include "Group.h" #include "MatrixTransform.h" #include "Camera.h" #include "CameraView.h" #include "Geode.h" #include "LightSource.h" #include "TexGenNode.h" #include "ClipNode.h" #include "Billboard.h" #include "Sequence.h" #include "LOD.h" #include "PagedLOD.h" #include "PositionAttitudeTransform.h" #include "AutoTransform.h" #include "DOFTransform.h" #include "Transform.h" #include "Switch.h" #include "OccluderNode.h" #include "OcclusionQueryNode.h" #include "Impostor.h" #include "CoordinateSystemNode.h" #include "Uniform.h" #include "Shader.h" #include "LightPointNode.h" #include "MultiSwitch.h" #include "VisibilityGroup.h" #include "MultiTextureControl.h" #include "ShapeAttributeList.h" #include "Effect.h" #include "AnisotropicLighting.h" #include "BumpMapping.h" #include "Cartoon.h" #include "Scribe.h" #include "SpecularHighlights.h" #include "Volume.h" #include "VolumeTile.h" #include "VolumeImageLayer.h" #include "VolumeCompositeLayer.h" #include "VolumeLocator.h" #include "VolumeCompositeProperty.h" #include "VolumeSwitchProperty.h" #include "VolumeScalarProperty.h" #include "VolumeTransferFunctionProperty.h" #include "Geometry.h" #include "ShapeDrawable.h" #include "Shape.h" #include "Text.h" #include "Terrain.h" #include "TerrainTile.h" #include "Locator.h" #include "ImageLayer.h" #include "HeightFieldLayer.h" #include "CompositeLayer.h" #include "SwitchLayer.h" #include "FadeText.h" #include "Text3D.h" #include #include #include #include #include #include #include using namespace ive; using namespace std; DataInputStream::DataInputStream(std::istream* istream, const osgDB::ReaderWriter::Options* options) { unsigned int endianType ; _loadExternalReferenceFiles = false; _verboseOutput = false; _istream = istream; _owns_istream = false; _peeking = false; _peekValue = 0; _byteswap = 0; _options = options; if (_options.get()) { setLoadExternalReferenceFiles(_options->getOptionString().find("noLoadExternalReferenceFiles")==std::string::npos); OSG_DEBUG << "ive::DataInputStream.setLoadExternalReferenceFiles()=" << getLoadExternalReferenceFiles() << std::endl; } if(!istream){ throwException("DataInputStream::DataInputStream(): null pointer exception in argument."); } endianType = readUInt() ; if ( endianType != ENDIAN_TYPE) { // Make sure the file is simply swapped if ( endianType != OPPOSITE_ENDIAN_TYPE ) { throwException("DataInputStream::DataInputStream(): This file has an unreadable endian type.") ; } OSG_INFO<<"DataInputStream::DataInputStream: Reading a byteswapped file" << std::endl ; _byteswap = 1 ; } _version = readUInt(); // Are we trying to open a binary .ive file which version are newer than this library. if(_version>VERSION){ throwException("DataInputStream::DataInputStream(): The version found in the file is newer than this library can handle."); } if (_version>=VERSION_0033) { int compressionLevel = readInt(); if (compressionLevel>0) { OSG_INFO<<"compressed ive stream"< bool DataInputStream::uncompress(std::istream& fin, std::string& destination) const { //#define CHUNK 16384 #define CHUNK 32768 int ret; unsigned have; z_stream strm; unsigned char in[CHUNK]; unsigned char out[CHUNK]; /* allocate inflate state */ strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; strm.avail_in = 0; strm.next_in = Z_NULL; ret = inflateInit2(&strm, 15 + 32 // autodected zlib or gzip header ); if (ret != Z_OK) { OSG_INFO<<"failed to init"<read(&c, CHARSIZE); if (_istream->rdstate() & _istream->failbit) throwException("DataInputStream::readBool(): Failed to read boolean value."); if (_verboseOutput) std::cout<<"read/writeBool() ["<<(int)c<<"]"<read(&c, CHARSIZE); if (_istream->rdstate() & _istream->failbit) throwException("DataInputStream::readChar(): Failed to read char value."); if (_verboseOutput) std::cout<<"read/writeChar() ["<<(int)c<<"]"<read((char*)&c, CHARSIZE); if (_istream->rdstate() & _istream->failbit) throwException("DataInputStream::readUChar(): Failed to read unsigned char value."); if (_verboseOutput) std::cout<<"read/writeUChar() ["<<(int)c<<"]"<read((char*)&s, SHORTSIZE); if (_istream->rdstate() & _istream->failbit) throwException("DataInputStream::readUShort(): Failed to read unsigned short value."); if (_verboseOutput) std::cout<<"read/writeUShort() ["<read((char*)&s, INTSIZE); if (_istream->rdstate() & _istream->failbit) throwException("DataInputStream::readUInt(): Failed to read unsigned int value."); if (_byteswap) osg::swapBytes((char *)&s,INTSIZE) ; if (_verboseOutput) std::cout<<"read/writeUInt() ["<read((char*)&i, INTSIZE); // comment out for time being as this check seems to eroneously cause a // premature exit when reading .ive files under OSX!#?:! // Robet Osfield, September 12th 2003. // if (_istream->rdstate() & _istream->failbit) // throwException("DataInputStream::readInt(): Failed to read int value."); if (_byteswap) osg::swapBytes((char *)&i,INTSIZE) ; if (_verboseOutput) std::cout<<"read/writeInt() ["<read((char*)&f, FLOATSIZE); if (_istream->rdstate() & _istream->failbit) throwException("DataInputStream::readFloat(): Failed to read float value."); if (_byteswap) osg::swapBytes((char *)&f,FLOATSIZE) ; if (_verboseOutput) std::cout<<"read/writeFloat() ["<read((char*)&l, LONGSIZE); if (_istream->rdstate() & _istream->failbit) throwException("DataInputStream::readLong(): Failed to read long value."); if (_byteswap) osg::swapBytes((char *)&l,LONGSIZE) ; if (_verboseOutput) std::cout<<"read/writeLong() ["<read((char*)&l, LONGSIZE); if (_istream->rdstate() & _istream->failbit) throwException("DataInputStream::readULong(): Failed to read unsigned long value."); if (_byteswap) osg::swapBytes((char *)&l,LONGSIZE) ; if (_verboseOutput) std::cout<<"read/writeULong() ["<read((char*)&d, DOUBLESIZE); if (_istream->rdstate() & _istream->failbit) throwException("DataInputStream::readDouble(): Failed to read double value."); if (_byteswap) osg::swapBytes((char *)&d,DOUBLESIZE) ; if (_verboseOutput) std::cout<<"read/writeDouble() ["<read((char*)s.c_str(), size); //if (_istream->rdstate() & _istream->failbit) // throwException("DataInputStream::readString(): Failed to read string value."); if (_verboseOutput) std::cout<<"read/writeString() ["<read(data, size); if (_istream->rdstate() & _istream->failbit) throwException("DataInputStream::readCharArray(): Failed to read char value."); if (_verboseOutput) std::cout<<"read/writeCharArray() ["< a = new osg::IntArray(size); _istream->read((char*)&((*a)[0]), INTSIZE*size); if (_istream->rdstate() & _istream->failbit) { throwException("DataInputStream::readIntArray(): Failed to read Int array."); return 0; } if (_verboseOutput) std::cout<<"read/writeIntArray() ["< a = new osg::UByteArray(size); _istream->read((char*)&((*a)[0]), CHARSIZE*size); if (_istream->rdstate() & _istream->failbit) { throwException("DataInputStream::readUByteArray(): Failed to read UByte array."); return 0; } if (_verboseOutput) std::cout<<"read/writeUByteArray() ["< a = new osg::UShortArray(size); _istream->read((char*)&((*a)[0]), SHORTSIZE*size); if (_istream->rdstate() & _istream->failbit) { throwException("DataInputStream::readUShortArray(): Failed to read UShort array."); return 0; } if (_verboseOutput) std::cout<<"read/writeUShortArray() ["< a = new osg::UIntArray(size); _istream->read((char*)&((*a)[0]), INTSIZE*size); if (_istream->rdstate() & _istream->failbit) { throwException("DataInputStream::readUIntArray(): Failed to read UInt array."); return 0; } if (_verboseOutput) std::cout<<"read/writeUIntArray() ["< a = new osg::Vec4ubArray(size); _istream->read((char*)&((*a)[0]), INTSIZE*size); if (_istream->rdstate() & _istream->failbit) { throwException("DataInputStream::readVec4ubArray(): Failed to read Vec4ub array."); return 0; } if (_verboseOutput) std::cout<<"read/writeVec4ubArray() ["<resize(size); if (size == 0) return true; if (readBool()) { float value = readFloat(); for(int i=0; irdstate() & _istream->failbit) { throwException("DataInputStream::readFloatArray(): Failed to read float array."); return false; } if (_verboseOutput) std::cout<<"read/writeFloatArray() ["< a = new osg::FloatArray(size); _istream->read((char*)&((*a)[0]), FLOATSIZE*size); if (_istream->rdstate() & _istream->failbit) { throwException("DataInputStream::readFloatArray(): Failed to read float array."); return 0; } if (_verboseOutput) std::cout<<"read/writeFloatArray() ["< a = new osg::Vec2Array(size); _istream->read((char*)&((*a)[0]), FLOATSIZE*2*size); if (_istream->rdstate() & _istream->failbit) { throwException("DataInputStream::readVec2Array(): Failed to read Vec2 array."); return 0; } if (_verboseOutput) std::cout<<"read/writeVec2Array() ["< a = new osg::Vec3Array(size); _istream->read((char*)&((*a)[0]), FLOATSIZE*3*size); if (_istream->rdstate() & _istream->failbit) { throwException("DataInputStream::readVec3Array(): Failed to read Vec3 array."); return 0; } if (_verboseOutput) std::cout<<"read/writeVec3Array() ["< a = new osg::Vec4Array(size); _istream->read((char*)&((*a)[0]), FLOATSIZE*4*size); if (_istream->rdstate() & _istream->failbit) { throwException("DataInputStream::readVec4Array(): Failed to read Vec4 array."); return 0; } if (_verboseOutput) std::cout<<"read/writeVec4Array() ["< a = new osg::Vec2bArray(size); _istream->read((char*)&((*a)[0]), CHARSIZE * 2 * size); if (_istream->rdstate() & _istream->failbit) { throwException("DataInputStream::readVec2bArray(): Failed to read Vec2b array."); return 0; } if (_verboseOutput) std::cout<<"read/writeVec2bArray() ["< a = new osg::Vec3bArray(size); _istream->read((char*)&((*a)[0]), CHARSIZE * 3 * size); if (_istream->rdstate() & _istream->failbit) { throwException("DataInputStream::readVec3bArray(): Failed to read Vec3b array."); return 0; } if (_verboseOutput) std::cout<<"read/writeVec3bArray() ["< a = new osg::Vec4bArray(size); _istream->read((char*)&((*a)[0]), CHARSIZE * 4 * size); if (_istream->rdstate() & _istream->failbit) { throwException("DataInputStream::readVec4bArray(): Failed to read Vec4b array."); return 0; } if (_verboseOutput) std::cout<<"read/writeVec4bArray() ["< a = new osg::Vec2sArray(size); _istream->read((char*)&((*a)[0]), SHORTSIZE * 2 * size); if (_istream->rdstate() & _istream->failbit) { throwException("DataInputStream::readVec2sArray(): Failed to read Vec2s array."); return 0; } if (_verboseOutput) std::cout<<"read/writeVec2sArray() ["< a = new osg::Vec3sArray(size); _istream->read((char*)&((*a)[0]), SHORTSIZE * 3 * size); if (_istream->rdstate() & _istream->failbit) { throwException("DataInputStream::readVec3sArray(): Failed to read Vec3s array."); return 0; } if (_verboseOutput) std::cout<<"read/writeVec3sArray() ["< a = new osg::Vec4sArray(size); _istream->read((char*)&((*a)[0]), SHORTSIZE * 4 * size); if (_istream->rdstate() & _istream->failbit) { throwException("DataInputStream::readVec4sArray(): Failed to read Vec4s array."); return 0; } if (_verboseOutput) std::cout<<"read/writeVec4sArray() ["< a = new osg::Vec2dArray(size); _istream->read((char*)&((*a)[0]), DOUBLESIZE*2*size); if (_istream->rdstate() & _istream->failbit) { throwException("DataInputStream::readVec2dArray(): Failed to read Vec2d array."); return 0; } if (_verboseOutput) std::cout<<"read/writeVec2dArray() ["< a = new osg::Vec3dArray(size); _istream->read((char*)&((*a)[0]), DOUBLESIZE*3*size); if (_istream->rdstate() & _istream->failbit) { throwException("DataInputStream::readVec3dArray(): Failed to read Vec3d array."); return 0; } if (_verboseOutput) std::cout<<"read/writeVec3dArray() ["< a = new osg::Vec4dArray(size); _istream->read((char*)&((*a)[0]), DOUBLESIZE*4*size); if (_istream->rdstate() & _istream->failbit) { throwException("DataInputStream::readVec4dArray(): Failed to read Vec4d array."); return 0; } if (_verboseOutput) std::cout<<"read/writeVec4dArray() ["<rdstate() & _istream->failbit) { throwException("DataInputStream::readMatrix(): Failed to read Matrix array."); return osg::Matrixf(); } if (_verboseOutput) std::cout<<"read/writeMatrix() ["<rdstate() & _istream->failbit) { throwException("DataInputStream::readMatrix(): Failed to read Matrix array."); return osg::Matrixd(); } if (_verboseOutput) std::cout<<"read/writeMatrix() ["<second.get(); // Image is not in list. // Read it from disk, osg::ref_ptr image = osgDB::readRefImageFile(filename.c_str(),_options.get()); // add it to the imageList, _imageMap[filename] = image; // and return image pointer. if (_verboseOutput) std::cout<<"read/writeImage() ["<= VERSION_0029 ) { int id = peekInt(); if(id == IVEIMAGESEQUENCE) { osg::ImageSequence* image = new osg::ImageSequence(); ((ive::ImageSequence*)image)->read(this); return image; } else { readInt(); IncludeImageMode includeImg = (IncludeImageMode)readChar(); return readImage(includeImg); } } else { IncludeImageMode includeImg = (IncludeImageMode)readChar(); return readImage(includeImg); } } osg::Image* DataInputStream::readImage(IncludeImageMode mode) { switch(mode) { case IMAGE_INCLUDE_DATA: // Read image data from stream if(readBool()) { osg::Image* image = new osg::Image(); ((ive::Image*)image)->read(this); return image; } break; case IMAGE_REFERENCE_FILE: // Only read image name from stream. { std::string filename = readString(); if(!filename.empty()){ return readImage(filename); } } break; case IMAGE_INCLUDE_FILE: case IMAGE_COMPRESS_DATA: // Read image file from stream { std::string filename = readString(); int size = readInt(); if(filename.compare("")!=0 && size > 0){ //Read in file char *buffer = new char[size]; readCharArray(buffer,size); //Get ReaderWriter from file extension std::string ext = osgDB::getFileExtension(filename); osgDB::ReaderWriter *reader = osgDB::Registry::instance()->getReaderWriterForExtension(ext); osgDB::ReaderWriter::ReadResult rr; if(reader) { //Convert data to istream std::stringstream inputStream; inputStream.write(buffer,size); //Attempt to read the image rr = reader->readImage(inputStream,_options.get()); } //Delete buffer delete [] buffer; //Return result if(rr.validImage()) { return rr.takeImage(); } } } break; default: throwException("DataInputStream::readImage(): Invalid IncludeImageMode value."); break; } return 0; } osg::StateSet* DataInputStream::readStateSet() { // Read statesets unique ID. int id = readInt(); // See if stateset is already in the list. StateSetMap::iterator itr= _statesetMap.find(id); if (itr!=_statesetMap.end()) return itr->second.get(); // StateSet is not in list. // Create a new stateset, osg::ref_ptr stateset = new osg::StateSet(); // read its properties from stream ((ive::StateSet*)(stateset.get()))->read(this); // exit early if an exception has been set. if (getException()) return 0; // and add it to the stateset map, _statesetMap[id] = stateset; if (_verboseOutput) std::cout<<"read/writeStateSet() ["<second.get(); // stateattribute is not in list. // Create a new stateattribute, osg::ref_ptr attribute; int attributeID = peekInt(); if(attributeID == IVEALPHAFUNC){ attribute = new osg::AlphaFunc(); ((ive::AlphaFunc*)(attribute.get()))->read(this); } else if(attributeID == IVEBLENDCOLOR){ attribute = new osg::BlendColor(); ((ive::BlendColor*)(attribute.get()))->read(this); } else if(attributeID == IVEBLENDFUNC || attributeID == IVEBLENDFUNCSEPARATE){ attribute = new osg::BlendFunc(); ((ive::BlendFunc*)(attribute.get()))->read(this); } else if(attributeID == IVEBLENDEQUATION){ attribute = new osg::BlendEquation(); ((ive::BlendEquation*)(attribute.get()))->read(this); } else if(attributeID == IVEDEPTH){ attribute = new osg::Depth(); ((ive::Depth*)(attribute.get()))->read(this); } else if(attributeID == IVEVIEWPORT){ attribute = new osg::Viewport(); ((ive::Viewport*)(attribute.get()))->read(this); } else if(attributeID == IVESCISSOR){ attribute = new osg::Scissor(); ((ive::Scissor*)(attribute.get()))->read(this); } else if(attributeID == IVEMATERIAL){ attribute = new osg::Material(); ((ive::Material*)(attribute.get()))->read(this); } else if(attributeID == IVECULLFACE){ attribute = new osg::CullFace(); ((ive::CullFace*)(attribute.get()))->read(this); } else if(attributeID == IVECOLORMASK){ attribute = new osg::ColorMask(); ((ive::ColorMask*)(attribute.get()))->read(this); } else if(attributeID == IVECLIPPLANE){ attribute = new osg::ClipPlane(); ((ive::ClipPlane*)(attribute.get()))->read(this); } else if(attributeID == IVEPOLYGONOFFSET){ attribute = new osg::PolygonOffset(); ((ive::PolygonOffset*)(attribute.get()))->read(this); } else if(attributeID == IVEPOLYGONMODE){ attribute = new osg::PolygonMode(); ((ive::PolygonMode*)(attribute.get()))->read(this); } else if(attributeID == IVESHADEMODEL){ attribute = new osg::ShadeModel(); ((ive::ShadeModel*)(attribute.get()))->read(this); } else if(attributeID == IVEPOINT){ attribute = new osg::Point(); ((ive::Point*)(attribute.get()))->read(this); } else if(attributeID == IVELINEWIDTH){ attribute = new osg::LineWidth(); ((ive::LineWidth*)(attribute.get()))->read(this); } else if(attributeID == IVETEXTURE1D){ attribute = new osg::Texture1D(); ((ive::Texture1D*)(attribute.get()))->read(this); } else if(attributeID == IVETEXTURE2D){ attribute = new osg::Texture2D(); ((ive::Texture2D*)(attribute.get()))->read(this); } else if(attributeID == IVETEXTURE2DARRAY){ attribute = new osg::Texture2DArray(); ((ive::Texture2DArray*)(attribute.get()))->read(this); } else if(attributeID == IVETEXTURE3D){ attribute = new osg::Texture3D(); ((ive::Texture3D*)(attribute.get()))->read(this); } else if(attributeID == IVETEXTURECUBEMAP){ attribute = new osg::TextureCubeMap(); ((ive::TextureCubeMap*)(attribute.get()))->read(this); } else if(attributeID == IVETEXTURERECTANGLE){ attribute = new osg::TextureRectangle(); ((ive::TextureRectangle*)(attribute.get()))->read(this); } else if(attributeID == IVETEXENV){ attribute = new osg::TexEnv(); ((ive::TexEnv*)(attribute.get()))->read(this); } else if(attributeID == IVETEXENVCOMBINE){ attribute = new osg::TexEnvCombine(); ((ive::TexEnvCombine*)(attribute.get()))->read(this); } else if(attributeID == IVETEXGEN){ attribute = new osg::TexGen(); ((ive::TexGen*)(attribute.get()))->read(this); } else if(attributeID == IVETEXMAT){ attribute = new osg::TexMat(); ((ive::TexMat*)(attribute.get()))->read(this); } else if(attributeID == IVEFRAGMENTPROGRAM){ attribute = new osg::FragmentProgram(); ((ive::FragmentProgram*)(attribute.get()))->read(this); } else if(attributeID == IVEVERTEXPROGRAM){ attribute = new osg::VertexProgram(); ((ive::VertexProgram*)(attribute.get()))->read(this); } else if(attributeID == IVELIGHTMODEL){ attribute = new osg::LightModel(); ((ive::LightModel*)(attribute.get()))->read(this); } else if(attributeID == IVEFRONTFACE){ attribute = new osg::FrontFace(); ((ive::FrontFace*)(attribute.get()))->read(this); } else if(attributeID == IVEPROGRAM){ attribute = new osg::Program(); ((ive::Program*)(attribute.get()))->read(this); } else if(attributeID == IVEPOINTSPRITE){ attribute = new osg::PointSprite(); ((ive::PointSprite*)(attribute.get()))->read(this); } else if(attributeID == IVEMULTISAMPLE){ attribute = new osg::Multisample(); ((ive::Multisample*)(attribute.get()))->read(this); } else if(attributeID == IVELINESTIPPLE){ attribute = new osg::LineStipple(); ((ive::LineStipple*)(attribute.get()))->read(this); } else if(attributeID == IVESTENCIL){ attribute = new osg::Stencil(); ((ive::Stencil*)(attribute.get()))->read(this); } else if(attributeID == IVEFOG){ attribute = new osg::Fog(); ((ive::Fog*)(attribute.get()))->read(this); } else if(attributeID == IVELIGHT){ attribute = new osg::Light(); ((ive::Light*)(attribute.get()))->read(this); } else if(attributeID == IVEPOLYGONSTIPPLE){ attribute = new osg::PolygonStipple(); ((ive::PolygonStipple*)(attribute.get()))->read(this); } else{ throwException("Unknown StateAttribute in StateSet::read()"); return 0; } // exit early if an exception has been set. if (getException()) return 0; // and add it to the stateattribute map, _stateAttributeMap[id] = attribute; if (_verboseOutput) std::cout<<"read/writeStateAttribute() ["<second.get(); // Uniform is not in list. // Create a new uniform, osg::ref_ptr uniform = new osg::Uniform(); // read its properties from stream ((ive::Uniform*)(uniform.get()))->read(this); // exit early if an exception has been set. if (getException()) return 0; // and add it to the uniform map, _uniformMap[id] = uniform; if (_verboseOutput) std::cout<<"read/writeUniform() ["<second.get(); // Shader is not in list. // Create a new shader, osg::ref_ptr shader = new osg::Shader(); // read its properties from stream ((ive::Shader*)(shader.get()))->read(this); // exit early if an exception has been set. if (getException()) return 0; // and add it to the shader map, _shaderMap[id] = shader; if (_verboseOutput) std::cout<<"read/writeShader() ["<second.get(); // stateattribute is not in list. // Create a new stateattribute, int drawableTypeID = peekInt(); osg::ref_ptr drawable; if(drawableTypeID == IVEGEOMETRY) { drawable = new osg::Geometry(); ((Geometry*)(drawable.get()))->read(this); } else if(drawableTypeID == IVESHAPEDRAWABLE) { drawable = new osg::ShapeDrawable(); ((ShapeDrawable*)(drawable.get()))->read(this); } else if(drawableTypeID == IVETEXT){ drawable = new osgText::Text(); ((Text*)(drawable.get()))->read(this); } else if(drawableTypeID == IVEFADETEXT){ drawable = new osgText::FadeText(); ((FadeText*)(drawable.get()))->read(this); } else if(drawableTypeID == IVETEXT3D){ drawable = new osgText::Text3D(); ((Text3D*)(drawable.get()))->read(this); } else throwException("Unknown drawable drawableTypeIDentification in Geode::read()"); // exit early if an exception has been set. if (getException()) return 0; // and add it to the stateattribute map, _drawableMap[id] = drawable; if (_verboseOutput) std::cout<<"read/writeDrawable() ["<second.get(); // stateattribute is not in list. // Create a new stateattribute, int shapeTypeID = peekInt(); osg::ref_ptr shape; if(shapeTypeID == IVESPHERE) { shape = new osg::Sphere(); ((Sphere*)(shape.get()))->read(this); } else if(shapeTypeID == IVEBOX) { shape = new osg::Box(); ((Box*)(shape.get()))->read(this); } else if(shapeTypeID == IVECONE) { shape = new osg::Cone(); ((Cone*)(shape.get()))->read(this); } else if(shapeTypeID == IVECYLINDER) { shape = new osg::Cylinder(); ((Cylinder*)(shape.get()))->read(this); } else if(shapeTypeID == IVECAPSULE) { shape = new osg::Capsule(); ((Capsule*)(shape.get()))->read(this); } else if(shapeTypeID == IVEHEIGHTFIELD) { shape = new osg::HeightField(); ((HeightField*)(shape.get()))->read(this); } else throwException("Unknown shape shapeTypeIDentification in Shape::read()"); // exit early if an exception has been set. if (getException()) return 0; // and add it to the stateattribute map, _shapeMap[id] = shape; if (_verboseOutput) std::cout<<"read/writeShape() ["<second.get(); // stateattribute is not in list. // Create a new node, osg::ref_ptr node; int nodeTypeID= peekInt(); if(nodeTypeID== IVEMATRIXTRANSFORM){ node = new osg::MatrixTransform(); ((ive::MatrixTransform*)(node.get()))->read(this); } else if(nodeTypeID== IVECAMERA){ node = new osg::Camera(); ((ive::Camera*)(node.get()))->read(this); } else if(nodeTypeID== IVECAMERAVIEW){ node = new osg::CameraView(); ((ive::CameraView*)(node.get()))->read(this); } else if(nodeTypeID== IVEPOSITIONATTITUDETRANSFORM){ node = new osg::PositionAttitudeTransform(); ((ive::PositionAttitudeTransform*)(node.get()))->read(this); } else if(nodeTypeID== IVEAUTOTRANSFORM){ node = new osg::AutoTransform(); ((ive::AutoTransform*)(node.get()))->read(this); } else if(nodeTypeID== IVEDOFTRANSFORM){ node = new osgSim::DOFTransform(); ((ive::DOFTransform*)(node.get()))->read(this); } else if(nodeTypeID== IVETRANSFORM){ node = new osg::Transform(); ((ive::Transform*)(node.get()))->read(this); } else if(nodeTypeID== IVELIGHTSOURCE){ node = new osg::LightSource(); ((ive::LightSource*)(node.get()))->read(this); } else if(nodeTypeID== IVETEXGENNODE){ node = new osg::TexGenNode(); ((ive::TexGenNode*)(node.get()))->read(this); } else if(nodeTypeID== IVECLIPNODE){ node = new osg::ClipNode(); ((ive::ClipNode*)(node.get()))->read(this); } else if(nodeTypeID== IVESEQUENCE){ node = new osg::Sequence(); ((ive::Sequence*)(node.get()))->read(this); } else if(nodeTypeID== IVELOD){ node = new osg::LOD(); ((ive::LOD*)(node.get()))->read(this); } else if(nodeTypeID== IVEPAGEDLOD){ node = new osg::PagedLOD(); ((ive::PagedLOD*)(node.get()))->read(this); } else if(nodeTypeID== IVECOORDINATESYSTEMNODE){ node = new osg::CoordinateSystemNode(); ((ive::CoordinateSystemNode*)(node.get()))->read(this); } else if(nodeTypeID== IVESWITCH){ node = new osg::Switch(); ((ive::Switch*)(node.get()))->read(this); } else if(nodeTypeID== IVEMULTISWITCH){ node = new osgSim::MultiSwitch(); ((ive::MultiSwitch*)(node.get()))->read(this); } else if(nodeTypeID== IVEIMPOSTOR){ node = new osgSim::Impostor(); ((ive::Impostor*)(node.get()))->read(this); } else if(nodeTypeID== IVEOCCLUDERNODE){ node = new osg::OccluderNode(); ((ive::OccluderNode*)(node.get()))->read(this); } else if(nodeTypeID== IVEOCCLUSIONQUERYNODE){ node = new osg::OcclusionQueryNode(); ((ive::OcclusionQueryNode*)(node.get()))->read(this); } else if(nodeTypeID== IVEVISIBILITYGROUP){ node = new osgSim::VisibilityGroup(); ((ive::VisibilityGroup*)(node.get()))->read(this); } else if(nodeTypeID== IVEPROXYNODE){ node = new osg::ProxyNode(); ((ive::ProxyNode*)(node.get()))->read(this); } else if(nodeTypeID== IVEGROUP){ node = new osg::Group(); ((ive::Group*)(node.get()))->read(this); } else if(nodeTypeID== IVEBILLBOARD){ node = new osg::Billboard(); ((ive::Billboard*)(node.get()))->read(this); } else if(nodeTypeID== IVEGEODE){ node = new osg::Geode(); ((ive::Geode*)(node.get()))->read(this); } else if(nodeTypeID== IVELIGHTPOINTNODE){ node = new osgSim::LightPointNode(); ((ive::LightPointNode*)(node.get()))->read(this); } else if(nodeTypeID== IVEMULTITEXTURECONTROL){ node = new osgFX::MultiTextureControl(); ((ive::MultiTextureControl*)(node.get()))->read(this); } else if(nodeTypeID== IVEANISOTROPICLIGHTING){ node = new osgFX::AnisotropicLighting(); ((ive::AnisotropicLighting*)(node.get()))->read(this); } else if(nodeTypeID== IVEBUMPMAPPING){ node = new osgFX::BumpMapping(); ((ive::BumpMapping*)(node.get()))->read(this); } else if(nodeTypeID== IVECARTOON){ node = new osgFX::Cartoon(); ((ive::Cartoon*)(node.get()))->read(this); } else if(nodeTypeID== IVESCRIBE){ node = new osgFX::Scribe(); ((ive::Scribe*)(node.get()))->read(this); } else if(nodeTypeID== IVESPECULARHIGHLIGHTS){ node = new osgFX::SpecularHighlights(); ((ive::SpecularHighlights*)(node.get()))->read(this); } else if(nodeTypeID== IVETERRAINTILE){ node = new osgTerrain::TerrainTile(); ((ive::TerrainTile*)(node.get()))->read(this); } else if(nodeTypeID== IVETERRAIN){ node = new osgTerrain::Terrain(); ((ive::Terrain*)(node.get()))->read(this); } else if(nodeTypeID== IVEVOLUME){ node = new osgVolume::Volume(); ((ive::Volume*)(node.get()))->read(this); } else if(nodeTypeID== IVEVOLUMETILE){ node = new osgVolume::VolumeTile(); ((ive::VolumeTile*)(node.get()))->read(this); } else if(nodeTypeID== IVENODE){ node = new osg::Node(); ((ive::Node*)(node.get()))->read(this); } else{ throwException("Unknown node identification in DataInputStream::readNode()"); } // exit early if an exception has been set. if (getException()) return 0; // and add it to the node map, _nodeMap[id] = node; if (_verboseOutput) std::cout<<"read/writeNode() ["<second.get(); // Layer is not in list. // Create a new Layer, osg::ref_ptr layer = 0; int layerid = peekInt(); if (layerid==IVEHEIGHTFIELDLAYER) { layer = new osgTerrain::HeightFieldLayer; ((ive::HeightFieldLayer*)(layer.get()))->read(this); } else if (layerid==IVEIMAGELAYER) { layer = new osgTerrain::ImageLayer; ((ive::ImageLayer*)(layer.get()))->read(this); } else if (layerid==IVESWITCHLAYER) { layer = new osgTerrain::SwitchLayer; ((ive::SwitchLayer*)(layer.get()))->read(this); } else if (layerid==IVECOMPOSITELAYER) { layer = new osgTerrain::CompositeLayer; ((ive::CompositeLayer*)(layer.get()))->read(this); } else if (layerid==IVEPROXYLAYER) { std::string filename = readString(); osg::ref_ptr object = osgDB::readObjectFile(filename+".gdal"); osgTerrain::ProxyLayer* proxyLayer = dynamic_cast(object.get()); osg::ref_ptr locator = readLocator(); unsigned int minLevel = readUInt(); unsigned int maxLevel = readUInt(); if (proxyLayer) { if (locator.valid()) proxyLayer->setLocator(locator.get()); proxyLayer->setMinLevel(minLevel); proxyLayer->setMaxLevel(maxLevel); } layer = proxyLayer; } else{ throwException("Unknown layer identification in DataInputStream::readLayer()"); } // exit early if an exception has been set. if (getException()) return 0; // and add it to the node map, _layerMap[id] = layer; if (_verboseOutput) std::cout<<"read/writeLayer() ["<second.get(); // Locator is not in list. // Create a new locator, osg::ref_ptr locator = new osgTerrain::Locator(); // read its properties from stream ((ive::Locator*)(locator.get()))->read(this); // exit early if an exception has been set. if (getException()) return 0; // and add it to the locator map, _locatorMap[id] = locator; if (_verboseOutput) std::cout<<"read/writeLocator() ["<second.get(); // Layer is not in list. // Create a new Layer, osg::ref_ptr layer = 0; int layerid = peekInt(); if (layerid==IVEVOLUMEIMAGELAYER) { layer = new osgVolume::ImageLayer; ((ive::VolumeImageLayer*)(layer.get()))->read(this); } else if (layerid==IVEVOLUMECOMPOSITELAYER) { layer = new osgVolume::CompositeLayer; ((ive::VolumeCompositeLayer*)(layer.get()))->read(this); } else{ throwException("Unknown layer identification in DataInputStream::readLayer()"); } // exit early if an exception has been set. if (getException()) return 0; // 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, osg::ref_ptr locator = new osgVolume::Locator(); // read its properties from stream ((ive::VolumeLocator*)(locator.get()))->read(this); // exit early if an exception has been set. if (getException()) return 0; // and add it to the locator map, _volumeLocatorMap[id] = locator; if (_verboseOutput) std::cout<<"read/writeVolumeLocator() ["<second.get(); int layerid = peekInt(); osg::ref_ptr property = 0; if (layerid==IVEVOLUMECOMPOSITEPROPERTY) { property = new osgVolume::CompositeProperty; ((ive::VolumeCompositeProperty*)(property.get()))->read(this); } else if (layerid==IVEVOLUMESWITCHPROPERTY) { property = new osgVolume::SwitchProperty; ((ive::VolumeSwitchProperty*)(property.get()))->read(this); } else if (layerid==IVEVOLUMETRANSFERFUNCTIONPROPERTY) { property = new osgVolume::TransferFunctionProperty; ((ive::VolumeTransferFunctionProperty*)(property.get()))->read(this); } else if (layerid==IVEVOLUMEMAXIMUMINTENSITYPROPERTY) { property = new osgVolume::MaximumIntensityProjectionProperty; readInt(); } else if (layerid==IVEVOLUMELIGHTINGPROPERTY) { property = new osgVolume::LightingProperty; readInt(); } else if (layerid==IVEVOLUMEISOSURFACEPROPERTY) { property = new osgVolume::IsoSurfaceProperty; readInt(); ((ive::VolumeScalarProperty*)(property.get()))->read(this); } else if (layerid==IVEVOLUMEALPHAFUNCPROPERTY) { property = new osgVolume::AlphaFuncProperty; readInt(); ((ive::VolumeScalarProperty*)(property.get()))->read(this); } else if (layerid==IVEVOLUMESAMPLEDENSITYPROPERTY) { property = new osgVolume::SampleDensityProperty; readInt(); ((ive::VolumeScalarProperty*)(property.get()))->read(this); } else if (layerid==IVEVOLUMETRANSPARENCYPROPERTY) { property = new osgVolume::TransparencyProperty; readInt(); ((ive::VolumeScalarProperty*)(property.get()))->read(this); } else{ throwException("Unknown layer identification in DataInputStream::readVolumeProperty()"); } // exit early if an exception has been set. if (getException()) return 0; // and add it to the locator map, _volumePropertyMap[id] = property; if (_verboseOutput) std::cout<<"read/writeVolumeProperty() ["< sal = new osgSim::ShapeAttributeList; ((ive::ShapeAttributeList*)sal.get())->read(this); // exit early if an exception has been set. if (getException()) return 0; return sal.release(); } return 0; }