diff --git a/src/osgPlugins/ive/DataInputStream.cpp b/src/osgPlugins/ive/DataInputStream.cpp index 1c65bd560..7a34e5d57 100644 --- a/src/osgPlugins/ive/DataInputStream.cpp +++ b/src/osgPlugins/ive/DataInputStream.cpp @@ -115,9 +115,9 @@ using namespace ive; using namespace std; -void DataInputStream::setOptions(const osgDB::ReaderWriter::Options* options) -{ - _options = options; +void DataInputStream::setOptions(const osgDB::ReaderWriter::Options* options) +{ + _options = options; if (_options.get()) { @@ -131,7 +131,7 @@ DataInputStream::DataInputStream(std::istream* istream) unsigned int endianType ; _loadExternalReferenceFiles = false; - + _verboseOutput = false; _istream = istream; @@ -140,11 +140,11 @@ DataInputStream::DataInputStream(std::istream* istream) _byteswap = 0; if(!istream){ - throw Exception("DataInputStream::DataInputStream(): null pointer exception in argument."); + throw Exception("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 ) { @@ -153,14 +153,14 @@ DataInputStream::DataInputStream(std::istream* istream) osg::notify(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){ throw Exception("DataInputStream::DataInputStream(): The version found in the file is newer than this library can handle."); } - + } DataInputStream::~DataInputStream(){} @@ -168,12 +168,12 @@ DataInputStream::~DataInputStream(){} bool DataInputStream::readBool(){ char c; _istream->read(&c, CHARSIZE); - + if (_istream->rdstate() & _istream->failbit) throw Exception("DataInputStream::readBool(): Failed to read boolean value."); if (_verboseOutput) std::cout<<"read/writeBool() ["<<(int)c<<"]"<rdstate() & _istream->failbit) // throw Exception("DataInputStream::readInt(): Failed to read int value."); - + if (_byteswap) osg::swapBytes((char *)&i,INTSIZE) ; - + if (_verboseOutput) std::cout<<"read/writeInt() ["<read((char*)&((*a)[0]), INTSIZE*size); if (_istream->rdstate() & _istream->failbit) throw Exception("DataInputStream::readIntArray(): Failed to read Int array."); - if (_verboseOutput) std::cout<<"read/writeIntArray() ["<read((char*)&((*a)[0]), FLOATSIZE*size); if (_istream->rdstate() & _istream->failbit) throw Exception("DataInputStream::readFloatArray(): Failed to read float array."); if (_verboseOutput) std::cout<<"read/writeFloatArray() ["<read((char*)&((*a)[0]), FLOATSIZE*2*size); if (_istream->rdstate() & _istream->failbit) throw Exception("DataInputStream::readVec2Array(): Failed to read Vec2 array."); if (_verboseOutput) std::cout<<"read/writeVec2Array() ["<read((char*)&((*a)[0]), FLOATSIZE*3*size); - + if (_istream->rdstate() & _istream->failbit) throw Exception("DataInputStream::readVec3Array(): Failed to read Vec3 array."); if (_verboseOutput) std::cout<<"read/writeVec3Array() ["<read((char*)&((*a)[0]), DOUBLESIZE*2*size); if (_istream->rdstate() & _istream->failbit) throw Exception("DataInputStream::readVec2dArray(): Failed to read Vec2d array."); if (_verboseOutput) std::cout<<"read/writeVec2dArray() ["<read((char*)&((*a)[0]), DOUBLESIZE*3*size); - + if (_istream->rdstate() & _istream->failbit) throw Exception("DataInputStream::readVec3dArray(): Failed to read Vec3d array."); if (_verboseOutput) std::cout<<"read/writeVec3dArray() ["<second.get(); - - // Image is not in list. - // Read it from disk, + + // Image is not in list. + // Read it from disk, osg::Image* image = osgDB::readImageFile(filename.c_str(),_options.get()); - + // add it to the imageList, _imageMap[filename] = image; // and return image pointer. if (_verboseOutput) std::cout<<"read/writeImage() ["<read(this); - + // and add it to the stateset map, _statesetMap[id] = stateset; - + if (_verboseOutput) std::cout<<"read/writeStateSet() ["<read(this); - } + } else{ throw Exception("Unknown StateAttribute in StateSet::read()"); } - + // and add it to the stateattribute map, _stateAttributeMap[id] = attribute; - + if (_verboseOutput) std::cout<<"read/writeStateAttribute() ["<read(this); - + // and add it to the uniform map, _uniformMap[id] = uniform; - + if (_verboseOutput) std::cout<<"read/writeUniform() ["<read(this); - + // and add it to the shader map, _shaderMap[id] = shader; - + if (_verboseOutput) std::cout<<"read/writeShader() ["<read(this); } else if(drawableTypeID == IVESHAPEDRAWABLE) { - drawable = new osg::ShapeDrawable(); + drawable = new osg::ShapeDrawable(); ((ShapeDrawable*)(drawable))->read(this); } else if(drawableTypeID == IVETEXT){ drawable = new osgText::Text(); ((Text*)(drawable))->read(this); - } + } else if(drawableTypeID == IVEFADETEXT){ drawable = new osgText::FadeText(); ((FadeText*)(drawable))->read(this); @@ -1330,13 +1330,13 @@ osg::Drawable* DataInputStream::readDrawable() else throw Exception("Unknown drawable drawableTypeIDentification in Geode::read()"); - + // and add it to the stateattribute map, _drawableMap[id] = drawable; - + if (_verboseOutput) std::cout<<"read/writeDrawable() ["<read(this); } else if(shapeTypeID == IVEBOX) @@ -1380,19 +1380,19 @@ osg::Shape* DataInputStream::readShape() } else if(shapeTypeID == IVEHEIGHTFIELD) { - shape = new osg::HeightField(); + shape = new osg::HeightField(); ((HeightField*)(shape))->read(this); } else throw Exception("Unknown shape shapeTypeIDentification in Shape::read()"); - + // and add it to the stateattribute map, _shapeMap[id] = shape; - + if (_verboseOutput) std::cout<<"read/writeShape() ["<read(this); @@ -1524,10 +1524,10 @@ osg::Node* DataInputStream::readNode() // and add it to the node map, _nodeMap[id] = node; - + if (_verboseOutput) std::cout<<"read/writeNode() ["<second.get(); @@ -1546,7 +1546,7 @@ osgTerrain::Layer* DataInputStream::readLayer() osgTerrain::Layer* layer = 0; int layerid = peekInt(); - + if (layerid==IVEHEIGHTFIELDLAYER) { layer = new osgTerrain::HeightFieldLayer; @@ -1567,19 +1567,19 @@ osgTerrain::Layer* DataInputStream::readLayer() 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{ @@ -1588,10 +1588,10 @@ osgTerrain::Layer* DataInputStream::readLayer() // and add it to the node map, _layerMap[id] = layer; - + if (_verboseOutput) std::cout<<"read/writeLayer() ["<second.get(); @@ -1612,12 +1612,12 @@ osgTerrain::Locator* DataInputStream::readLocator() // read its properties from stream ((ive::Locator*)(locator))->read(this); - + // and add it to the locator map, _locatorMap[id] = locator; if (_verboseOutput) std::cout<<"read/writeLocator() ["<write(&c, CHARSIZE); - + if (_verboseOutput) std::cout<<"read/writeBool() ["<<(int)c<<"]"<write(&c, CHARSIZE); - + if (_verboseOutput) std::cout<<"read/writeChar() ["<<(int)c<<"]"<write((char*)&c, CHARSIZE); - + if (_verboseOutput) std::cout<<"read/writeUChar() ["<<(int)c<<"]"<write((char*)&s, SHORTSIZE); - + if (_verboseOutput) std::cout<<"read/writeUShort() ["<write((char*)&s, INTSIZE); - + if (_verboseOutput) std::cout<<"read/writeUInt() ["<write((char*)&i, INTSIZE); - + if (_verboseOutput) std::cout<<"read/writeInt() ["<write((char*)&f, FLOATSIZE); - + if (_verboseOutput) std::cout<<"read/writeFloat() ["<write((char*)&l, LONGSIZE); - + if (_verboseOutput) std::cout<<"read/writeLong() ["<write((char*)&l, LONGSIZE); - + if (_verboseOutput) std::cout<<"read/writeULong() ["<write((char*)&d, DOUBLESIZE); - + if (_verboseOutput) std::cout<<"read/writeDouble() ["<write(s.c_str(), s.size()); - + if (_verboseOutput) std::cout<<"read/writeString() ["<write(data, size); - + if (_verboseOutput) std::cout<<"read/writeCharArray() ["<getType()){ - case osg::Array::IntArrayType: + case osg::Array::IntArrayType: writeChar((char)0); writeIntArray(static_cast(a)); break; @@ -377,15 +377,15 @@ void DataOutputStream::writeArray(const osg::Array* a){ writeChar((char)5); writeFloatArray(static_cast(a)); break; - case osg::Array::Vec2ArrayType: + case osg::Array::Vec2ArrayType: writeChar((char)6); writeVec2Array(static_cast(a)); break; - case osg::Array::Vec3ArrayType: + case osg::Array::Vec3ArrayType: writeChar((char)7); writeVec3Array(static_cast(a)); break; - case osg::Array::Vec4ArrayType: + case osg::Array::Vec4ArrayType: writeChar((char)8); writeVec4Array(static_cast(a)); break; @@ -413,15 +413,15 @@ void DataOutputStream::writeArray(const osg::Array* a){ writeChar((char)14); writeVec4bArray(static_cast(a)); break; - case osg::Array::Vec2dArrayType: + case osg::Array::Vec2dArrayType: writeChar((char)15); writeVec2dArray(static_cast(a)); break; - case osg::Array::Vec3dArrayType: + case osg::Array::Vec3dArrayType: writeChar((char)16); writeVec3dArray(static_cast(a)); break; - case osg::Array::Vec4dArrayType: + case osg::Array::Vec4dArrayType: writeChar((char)17); writeVec4dArray(static_cast(a)); break; @@ -437,62 +437,62 @@ void DataOutputStream::writeIntArray(const osg::IntArray* a) for(int i =0; iindex(i)); } - + if (_verboseOutput) std::cout<<"read/writeIntArray() ["<getNumElements(); + int size = a->getNumElements(); writeInt(size); for(int i =0; igetNumElements(); + int size = a->getNumElements(); writeInt(size); for(int i =0; igetNumElements(); + int size = a->getNumElements(); writeInt(size); for(int i =0; igetNumElements(); + int size = a->getNumElements(); writeInt(size); for(int i =0; igetNumElements(); + int size = a->getNumElements(); writeInt(size); for(int i =0; igetNumElements(); + int size = a->getNumElements(); writeInt(size); for(int i =0; igetNumElements(); + int size = a->getNumElements(); writeInt(size); for(int i =0; igetNumElements(); + int size = a->getNumElements(); writeInt(size); for(int i =0; igetNumElements(); + int size = a->getNumElements(); writeInt(size); for(int i =0; igetNumElements(); + int size = a->getNumElements(); writeInt(size); for(int i =0; igetNumElements(); + int size = a->getNumElements(); writeInt(size); for(int i =0; i(drawable)) ((ive::Geometry*)(drawable))->write(this); else if(dynamic_cast(drawable)) @@ -967,7 +967,7 @@ void DataOutputStream::writeShape(const osg::Shape* shape) // write the id. writeInt(id); - + if(dynamic_cast(shape)) ((ive::Sphere*)(shape))->write(this); else if(dynamic_cast(shape)) @@ -1136,9 +1136,9 @@ void DataOutputStream::writeImage(IncludeImageMode mode, osg::Image *image) if (image && !(image->getFileName().empty())){ writeString(image->getFileName()); } - else{ + else{ writeString(""); - } + } break; case IMAGE_INCLUDE_FILE: // Include image file in stream @@ -1170,25 +1170,25 @@ void DataOutputStream::writeImage(IncludeImageMode mode, osg::Image *image) //Close file infile.close(); - + } else { writeString(""); writeInt(0); } } - else{ + else{ writeString(""); writeInt(0); - } + } break; case IMAGE_COMPRESS_DATA: if(image) { //Get ReaderWriter for jpeg images - + std::string extension = "png"; if (image->getPixelFormat()==GL_RGB) extension = "jpg"; - + osgDB::ReaderWriter* writer = osgDB::Registry::instance()->getReaderWriterForExtension(extension); if(writer) @@ -1207,11 +1207,11 @@ void DataOutputStream::writeImage(IncludeImageMode mode, osg::Image *image) // 1 - Same code can be used to read in as with IMAGE_INCLUDE_FILE mode // 2 - Maybe in future version user can specify which format to use writeString(std::string(".")+extension); //Need to add dot so osgDB::getFileExtension will work - + //Write size of stream int size = outputStream.tellp(); writeInt(size); - + //Write stream writeCharArray(outputStream.str().c_str(),size); @@ -1256,7 +1256,7 @@ void DataOutputStream::writeLayer(const osgTerrain::Layer* layer) // write the id. writeInt(id); - + if (dynamic_cast(layer)) { ((ive::HeightFieldLayer*)(layer))->write(this);