Hi, I have found the problem that is causing me trouble. The code I posted is writing two 'end brackets':
os << osgDB::BEGIN_BRACKET << std::endl; os.writeImage( value ); os << osgDB::END_BRACKET; If I don't write the an end bracket explicity then everything seems to work ok. I am guessing that the writeImage call is adding the end bracket for me. Is this expected behaviour? The code looks incorrect without it: os << osgDB::BEGIN_BRACKET << std::endl; os.writeImage( value ); Cheers, Brad -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Christiansen, Brad Sent: Wednesday, 5 January 2011 3:51 PM To: OpenSceneGraph Users Subject: Re: [osg-users] Limitation in current ImageLayer serializer Hi, I have found a little more time to work on this issue but have become stuck. Using a user serializer I have managed to read and write the image sucsessfully in the case that the image is loaded, but cant get it to work in the case the image should not be loaded. I think the issue is that, when I don't want want to read the image (i.e. deffered loading is enabled), then I still need to read the image 'header' from the stream. If the image is embedded in the file then I think I will need to read the entire image regardless of wether deffered loading is enabled or not (I haven't looked at this case yet). The code I am using is (I am testing with .osgt files so far): static bool readImage( osgDB::InputStream& is, osgTerrain::ImageLayer& im ) { std::string filename = im.getFileName(); if (!filename.empty()) { bool hasImage; is >> hasImage; if(hasImage) { is >> osgDB::BEGIN_BRACKET; bool deferExternalLayerLoading = osgTerrain::TerrainTile::getTileLoadedCallback().valid() ? osgTerrain::TerrainTile::getTileLoadedCallback()->deferExternalLayerLoading() : false; if (!deferExternalLayerLoading) { osg::ref_ptr<osg::Image> image = is.readImage(); if (image.valid()) { im.setImage(image.get()); } } else { //I think this is where I need to read of the image 'header' } is >> osgDB::END_BRACKET; } } return true; } static bool writeImage( osgDB::OutputStream& os, const osgTerrain::ImageLayer& im ) { const osg::Image* value = im.getImage(); bool hasObject = (value!=NULL); os << hasObject; if ( hasObject ) { os << osgDB::BEGIN_BRACKET << std::endl; os.writeImage( value ); os << osgDB::END_BRACKET; } return true; } The relevenat section of the osgt file that is created is: Layers 1 { Object osgTerrain::ImageLayer { UniqueID 9 Name "kljhjkl" FileName "earth_L1_X0_Y0_kljhjkl.dds" Locator TRUE { osgTerrain::Locator { UniqueID 4 } } Image TRUE { UniqueID 10 FileName "earth_L1_X0_Y0_kljhjkl.dds" WriteHint 2 2 DataVariance STATIC }} } And the error I get when loading the file with deffered loading enabled is a bad allocation error. Any suggestions would be greatly appreciated! Cheers, Brad -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Wang Rui Sent: Tuesday, 30 November 2010 1:47 PM To: [email protected] Subject: Re: [osg-users] Limitation in current ImageLayer serializer Hi Brad, In fact when I'm working on the osgTerrain serializers, I don't pay much attention to the special mechanism that may be required when loading terrain tile and layer classes. For the case that the image layer may be loaded inactive according to an additional flag, I suggest that we should handle all of these with a user serializer instead, that is, REGISTER_OBJECT_WRAPPER( osgTerrain_ImageLayer, new osgTerrain::ImageLayer, osgTerrain::ImageLayer, "osg::Object osgTerrain::Layer osgTerrain::ImageLayer" ) { ADD_USER_SERIALIZER( Image ); // _image } And write/read images and activate them by ourselves. Here we can read out an image object from the input stream using is.readImage(), and write image to disk files with the << operator. Hope this can help if you would like to help fix the problem. :-) Cheers, Wang Rui 2010/11/30 Brad Christiansen <[email protected]>: > Hi, > > I have discovered a piece of missing functionality in the new serializer for > osgTerrain::ImageLayers. The issue is that all optional layers are loaded > when an osgb file is loaded regardless of weather they should be or not. > > The relevant piece of code for the the .ive format is in (in osgDB_ive) > "void ImageLayer::read(DataInputStream* in)" at line 64: > > bool deferExternalLayerLoading = > osgTerrain::TerrainTile::getTileLoadedCallback().valid() ? > > osgTerrain::TerrainTile::getTileLoadedCallback()->deferExternalLayerLoading() > : false; > // Should we read image data from stream > IncludeImageMode includeImg = (IncludeImageMode)in->readChar(); > > if (includeImg==IMAGE_REFERENCE_FILE && deferExternalLayerLoading) > { > setFileName(in->readString()); > } > else > { > setImage(in->readImage(includeImg)); > } > > The new serializer simple adds an image serializer for an ImageLayer with no > similar checks. > > I have had a quick look at coding a fix but have to admit I still dont fully > understand how the new system works in such cases. If anyone can give me some > pointers on how to go about adding this functionality that would be greatly > apprecaited as at the momment I am having to covert my terrain databases back > to .ive. > > For reference, I discovered the issue as my osgb databses where laoding alot > slower than my ive based ones. The reason was that all optional layers were > being loaded even if they weren't active. > > > Cheers, > Brad > > ------------------ > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=34231#34231 > > > > > > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org DISCLAIMER:--------------------------------------------------------------------------- This e-mail transmission and any documents, files and previous e-mail messages attached to it are private and confidential. They may contain proprietary or copyright material or information that is subject to legal professional privilege. They are for the use of the intended recipient only. Any unauthorised viewing, use, disclosure, copying, alteration, storage or distribution of, or reliance on, this message is strictly prohibited. No part may be reproduced, adapted or transmitted without the written permission of the owner. If you have received this transmission in error, or are not an authorised recipient, please immediately notify the sender by return email, delete this message and all copies from your e-mail system, and destroy any printed copies. Receipt by anyone other than the intended recipient should not be deemed a waiver of any privilege or protection. Thales Australia does not warrant or represent that this e-mail or any documents, files and previous e-mail messages attached are error or virus free. -------------------------------------------------------------------------------------- _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org DISCLAIMER:--------------------------------------------------------------------------- This e-mail transmission and any documents, files and previous e-mail messages attached to it are private and confidential. They may contain proprietary or copyright material or information that is subject to legal professional privilege. They are for the use of the intended recipient only. Any unauthorised viewing, use, disclosure, copying, alteration, storage or distribution of, or reliance on, this message is strictly prohibited. No part may be reproduced, adapted or transmitted without the written permission of the owner. If you have received this transmission in error, or are not an authorised recipient, please immediately notify the sender by return email, delete this message and all copies from your e-mail system, and destroy any printed copies. Receipt by anyone other than the intended recipient should not be deemed a waiver of any privilege or protection. Thales Australia does not warrant or represent that this e-mail or any documents, files and previous e-mail messages attached are error or virus free. -------------------------------------------------------------------------------------- _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

