- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/osg/ReaderWriterOSG2.cpp
r13005 r13041 38 38 else if ( optionString.find("XML")!=std::string::npos ) extensionIsXML = true; 39 39 } 40 40 41 41 if ( !extensionIsAscii && !extensionIsXML ) 42 42 { … … 54 54 return new BinaryInputIterator(&fin, 1); // endian different so byte swap required 55 55 } 56 56 57 57 fin.seekg( 0, std::ios::beg ); 58 58 } 59 59 60 60 if ( !extensionIsXML ) 61 61 { … … 67 67 fin.seekg( 0, std::ios::beg ); 68 68 } 69 69 70 70 if ( 1 ) 71 71 { … … 89 89 while (iss >> opt) 90 90 { 91 if(opt=="PRECISION" || opt=="precision") 91 if(opt=="PRECISION" || opt=="precision") 92 92 { 93 93 iss >> precision; … … 124 124 supportsExtension( "osgb", "OpenSceneGraph extendable binary format" ); 125 125 supportsExtension( "osgx", "OpenSceneGraph extendable XML format" ); 126 126 127 127 supportsOption( "Ascii", "Import/Export option: Force reading/writing ascii file" ); 128 128 supportsOption( "XML", "Import/Export option: Force reading/writing XML file" ); … … 162 162 else if ( ext=="osgx" ) local_opt->setOptionString( local_opt->getOptionString() + " XML" ); 163 163 else mode |= std::ios::binary; 164 164 165 165 return local_opt.release(); 166 166 } 167 167 168 168 virtual ReadResult readObject( const std::string& file, const Options* options ) const 169 169 { … … 177 177 return readObject( istream, local_opt ); 178 178 } 179 179 180 180 virtual ReadResult readObject( std::istream& fin, const Options* options ) const 181 181 { … … 196 196 return obj; 197 197 } 198 198 199 199 virtual ReadResult readImage( const std::string& file, const Options* options ) const 200 200 { … … 204 204 Options* local_opt = prepareReading( result, fileName, mode, options ); 205 205 if ( !result.success() ) return result; 206 206 207 207 osgDB::ifstream istream( fileName.c_str(), mode ); 208 208 return readImage( istream, local_opt ); 209 209 } 210 210 211 211 virtual ReadResult readImage( std::istream& fin, const Options* options ) const 212 212 { 213 213 osg::ref_ptr<InputIterator> ii = readInputIterator(fin, options); 214 214 if ( !ii ) return ReadResult::FILE_NOT_HANDLED; 215 215 216 216 InputStream is( options ); 217 217 if ( is.start(ii.get())!=InputStream::READ_IMAGE ) … … 224 224 return image; 225 225 } 226 226 227 227 virtual ReadResult readNode( const std::string& file, const Options* options ) const 228 228 { … … 232 232 Options* local_opt = prepareReading( result, fileName, mode, options ); 233 233 if ( !result.success() ) return result; 234 234 235 235 osgDB::ifstream istream( fileName.c_str(), mode ); 236 236 return readNode( istream, local_opt ); 237 237 } 238 238 239 239 virtual ReadResult readNode( std::istream& fin, const Options* options ) const 240 240 { 241 241 osg::ref_ptr<InputIterator> ii = readInputIterator(fin, options); 242 242 if ( !ii ) return ReadResult::FILE_NOT_HANDLED; 243 243 244 244 InputStream is( options ); 245 245 if ( is.start(ii.get())!=InputStream::READ_SCENE ) … … 248 248 return ReadResult::FILE_NOT_HANDLED; 249 249 } 250 250 251 251 is.decompress(); CATCH_EXCEPTION(is); 252 252 osg::Node* node = dynamic_cast<osg::Node*>(is.readObject()); CATCH_EXCEPTION(is); 253 253 return node; 254 254 } 255 255 256 256 Options* prepareWriting( WriteResult& result, const std::string& fileName, std::ios::openmode& mode, const Options* options ) const 257 257 { 258 258 std::string ext = osgDB::getFileExtension( fileName ); 259 259 if ( !acceptsExtension(ext) ) result = WriteResult::FILE_NOT_HANDLED; 260 260 261 261 osg::ref_ptr<Options> local_opt = options ? 262 262 static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; … … 265 265 else if ( ext=="osgx" ) local_opt->setOptionString( local_opt->getOptionString() + " XML" ); 266 266 else mode |= std::ios::binary; 267 267 268 268 return local_opt.release(); 269 269 } 270 270 271 271 virtual WriteResult writeObject( const osg::Object& object, const std::string& fileName, const Options* options ) const 272 272 { … … 275 275 osg::ref_ptr<Options> local_opt = prepareWriting( result, fileName, mode, options ); 276 276 if ( !result.success() ) return result; 277 277 278 278 osgDB::ofstream fout( fileName.c_str(), mode ); 279 279 if ( !fout ) return WriteResult::ERROR_IN_WRITING_FILE; 280 280 281 281 result = writeObject( object, fout, local_opt.get() ); 282 282 fout.close(); 283 283 return result; 284 284 } 285 285 286 286 virtual WriteResult writeObject( const osg::Object& object, std::ostream& fout, const Options* options ) const 287 287 { 288 288 osg::ref_ptr<OutputIterator> oi = writeOutputIterator(fout, options); 289 289 290 290 OutputStream os( options ); 291 291 os.start( oi.get(), OutputStream::WRITE_OBJECT ); CATCH_EXCEPTION(os); 292 292 os.writeObject( &object ); CATCH_EXCEPTION(os); 293 293 os.compress( &fout ); CATCH_EXCEPTION(os); 294 294 295 295 oi->flush(); 296 296 if ( !os.getSchemaName().empty() ) … … 300 300 schemaStream.close(); 301 301 } 302 302 303 303 if ( fout.fail() ) return WriteResult::ERROR_IN_WRITING_FILE; 304 304 return WriteResult::FILE_SAVED; 305 305 } 306 306 307 307 virtual WriteResult writeImage( const osg::Image& image, const std::string& fileName, const Options* options ) const 308 308 { … … 311 311 osg::ref_ptr<Options> local_opt = prepareWriting( result, fileName, mode, options ); 312 312 if ( !result.success() ) return result; 313 313 314 314 osgDB::ofstream fout( fileName.c_str(), mode ); 315 315 if ( !fout ) return WriteResult::ERROR_IN_WRITING_FILE; 316 316 317 317 result = writeImage( image, fout, local_opt.get() ); 318 318 fout.close(); 319 319 return result; 320 320 } 321 321 322 322 virtual WriteResult writeImage( const osg::Image& image, std::ostream& fout, const Options* options ) const 323 323 { 324 324 osg::ref_ptr<OutputIterator> oi = writeOutputIterator(fout, options); 325 325 326 326 OutputStream os( options ); 327 327 os.start( oi.get(), OutputStream::WRITE_IMAGE ); CATCH_EXCEPTION(os); 328 328 os.writeImage( &image ); CATCH_EXCEPTION(os); 329 329 os.compress( &fout ); CATCH_EXCEPTION(os); 330 330 331 331 oi->flush(); 332 332 if ( !os.getSchemaName().empty() ) … … 336 336 schemaStream.close(); 337 337 } 338 338 339 339 if ( fout.fail() ) return WriteResult::ERROR_IN_WRITING_FILE; 340 340 return WriteResult::FILE_SAVED; 341 341 } 342 342 343 343 virtual WriteResult writeNode( const osg::Node& node, const std::string& fileName, const Options* options ) const 344 344 { … … 347 347 osg::ref_ptr<Options> local_opt = prepareWriting( result, fileName, mode, options ); 348 348 if ( !result.success() ) return result; 349 349 350 350 osgDB::ofstream fout( fileName.c_str(), mode ); 351 351 if ( !fout ) return WriteResult::ERROR_IN_WRITING_FILE; 352 352 353 353 result = writeNode( node, fout, local_opt.get() ); 354 354 fout.close(); 355 355 return result; 356 356 } 357 357 358 358 virtual WriteResult writeNode( const osg::Node& node, std::ostream& fout, const Options* options ) const 359 359 { 360 360 osg::ref_ptr<OutputIterator> oi = writeOutputIterator(fout, options); 361 361 362 362 OutputStream os( options ); 363 363 os.start( oi.get(), OutputStream::WRITE_SCENE ); CATCH_EXCEPTION(os); 364 364 os.writeObject( &node ); CATCH_EXCEPTION(os); 365 365 os.compress( &fout ); CATCH_EXCEPTION(os); 366 366 367 367 oi->flush(); 368 368 if ( !os.getSchemaName().empty() ) … … 372 372 schemaStream.close(); 373 373 } 374 374 375 375 if ( fout.fail() ) return WriteResult::ERROR_IN_WRITING_FILE; 376 376 return WriteResult::FILE_SAVED;
