Re: [osg-users] Limitation in current ImageLayer serializer

2011-01-05 Thread Christiansen, Brad
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: osg-users-boun...@lists.openscenegraph.org 
[mailto:osg-users-boun...@lists.openscenegraph.org] 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_ptrosg::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: osg-users-boun...@lists.openscenegraph.org 
[mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Wang Rui
Sent: Tuesday, 30 November 2010 1:47 PM
To: osg-users@lists.openscenegraph.org
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 brad.christian...@thalesgroup.com.au:
 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

Re: [osg-users] Limitation in current ImageLayer serializer

2011-01-04 Thread Christiansen, Brad
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_ptrosg::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: osg-users-boun...@lists.openscenegraph.org 
[mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Wang Rui
Sent: Tuesday, 30 November 2010 1:47 PM
To: osg-users@lists.openscenegraph.org
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 brad.christian...@thalesgroup.com.au:
 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

Re: [osg-users] Limitation in current ImageLayer serializer

2010-12-15 Thread Wang Rui
Hi Brad,

In your compile error reports:

cannot convert parameter 3 from 'bool (__cdecl *)(osgDB::InputStream
,const osgTerrain::ImageLayer )

Shouldn't it be:

bool readFunction(osgDB::InputStream, osgTerrain::ImageLayer)

'const' may not be used here. :-)

Wang Rui


2010/12/16 Christiansen, Brad brad.christian...@thalesgroup.com.au:
 Hi Rui,

 I have finally found some time to have a look at this issue, and would love 
 to get a fix implemented before 3.0, but I am not having much luck.
 I have previously managed to add a user serializer to VirtualPlanetBuilder 
 without issue to add support for some extra options, but am getting nowhere 
 with the ImageLyer serializer.

 I changed the code exactly as you suggested and have added the required check 
 / read and write functions. I am pretty sure I can implement these ok but I 
 cant get things compiling with simple stub implementations that simply return 
 true.

 The compile error I am getting is:

 2  ImageLayer.cpp
 2..\..\..\..\..\..\..\Source\src-osg\src\osgWrappers\serializers\osgTerrain\ImageLayer.cpp(52):
  error C2664: 'osgDB::UserSerializerC::UserSerializer(const char *,bool 
 (__cdecl *)(const C ),bool (__cdecl *)(osgDB::InputStream ,C ),bool 
 (__cdecl *)(osgDB::OutputStream ,const C ))' : cannot convert parameter 3 
 from 'bool (__cdecl *)(osgDB::InputStream ,const osgTerrain::ImageLayer )' 
 to 'bool (__cdecl *)(osgDB::InputStream ,C )'
 2          with
 2          [
 2              C=MyClass
 2          ]
 2          This conversion requires a reinterpret_cast, a C-style cast or 
 function-style cast

 After examing the the VirtualPlanetBuilder code I modified for an earlier 
 submission, I think I need to register a lookup (or something like that) to 
 solve the issue but my C++ skills just arnt up to the job of figuring out 
 exactly what it is I need to do. Any suggestions or simple examples I could 
 look at would be greatly appreciated.

 Cheers,
 Brad


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Limitation in current ImageLayer serializer

2010-12-15 Thread Wang Rui
Hi Brad,

2010/12/16 Christiansen, Brad brad.christian...@thalesgroup.com.au:
 ps- I am not used to such quick resposes. Geat having someone in the same 
 time zone for a change!


I'm in China and its afternoon here. I'm just in my best shape after a
rest at midnood. ;-)

Wang Rui
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Limitation in current ImageLayer serializer

2010-11-29 Thread Brad Christiansen
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
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org