Re: [osg-users] How do I Subclass a file loader?

2008-10-04 Thread Robert Osfield
Hi Brett,

You can override the reading and writing at a high level by doing
using a Registry::ReadFileCallback and WriteFileCallback.  You could
use this to intercept all the the write of .ive and adapt them.

Or just disable the change the ProxyNode's filename so that it
includes an extension relating to your encrypted format.

The other approach is to leave all the loaders as is, and just
encrypted the vertex and image data.  This would require an encryption
that doesn't change the data size, but would enable you to use all the
loaders as is, and just run a visitor over the scene grpah and
decrypt/encrypt.

Robert.

On Fri, Oct 3, 2008 at 9:38 PM, brettwiesner <[EMAIL PROTECTED]> wrote:
> OK. I have a workaround for my problem. I'll explain the original problem,
> my solution and make a suggestion.
>
> Requirements:
> A third party we have bought models from does not what their data to be
> shipped unencrypted. So I have to encrypt it.
>
> Initial Solution:
> My thought was that I'd like to just use the IVE loader to write a node to a
> stream, then I'd encrypt that thereby getting an encrypted fast loading
> file. So I tried that. I wrote a loader that use the IVE loader to get a
> stream from a node, then I encrypted the stream and wrote it out. The loader
> would also read in an encrypted file, decrypt it into a stream and pass that
> into the IVE loader. All was well until I came across models with proxy
> nodes (aka models that referenced other models).
>
> It turns out the IVE loader writes out .ive files for all it's proxy nodes.
> There are several options that I can pass to the IVE loader that will make
> it not write out external references, but I want it to. I just don't want
> them to be written out as ".ive's"; I want them to be written out as my
> encrypted file format.
>
> Workaround:
> Because loaders don't have API's they can't be subclassed. Instead, I had to
> do a little trickery. I'll use encryption as an example. When my loader is
> active (ie: writing an encrypted file), I remove the real IVE loader from
> the ReaderWriter list in the registry (but I keep around a pointer to it). I
> register my loader as something that accepts the ".ive" extension. Now when
> anyone tries to write out an ".ive" file, they will be using my loader.
>  Then I use the pointer to the real IVE loader to write the node to a
> stream. When the IVE loader comes across a proxy node and wants to write out
> an ".ive" file, it asks the registry for the IVE loader, which then gives it
> back my loader. My loader gets the stream from the real IVE loader then does
> the encryption and writes it out. At the end, my loader adds the real IVE
> loader back to the reader writer list and then changed itself to no longer
> accept ".ive's" as a valid extension.
>
> My suggestion:
> This trickery could have been avoided if the logic for the IVE loader was in
> a library that could be extended. The IVE loader has a little helper class
> for every kind of node in OSG. These classes should be created with a
> factory. Then I could subclass the IVE loader and replace the ProxyNode
> helper class with my subclass and I'd be able to have an encrypted loader
> that lives alongside the real IVE loader without any weird tricks.
>
> Imagine a library... osgDbIve. This would have headers in the include dir, a
> lib in the lib dir, a dll in the bin dir. Then there would be one other
> library, osgDB_ive which would be very small and only build the plugin.
> Users could then subclass the loader logic since that is all contained in an
> extendable API, and just write the small loader plugin .
>
> Thanks,
> Brett
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] How do I Subclass a file loader?

2008-10-03 Thread brettwiesner
OK. I have a workaround for my problem. I'll explain the original 
problem, my solution and make a suggestion.


Requirements:
A third party we have bought models from does not what their data to be 
shipped unencrypted. So I have to encrypt it.


Initial Solution:
My thought was that I'd like to just use the IVE loader to write a node 
to a stream, then I'd encrypt that thereby getting an encrypted fast 
loading file. So I tried that. I wrote a loader that use the IVE loader 
to get a stream from a node, then I encrypted the stream and wrote it 
out. The loader would also read in an encrypted file, decrypt it into a 
stream and pass that into the IVE loader. All was well until I came 
across models with proxy nodes (aka models that referenced other models).


It turns out the IVE loader writes out .ive files for all it's proxy 
nodes. There are several options that I can pass to the IVE loader that 
will make it not write out external references, but I want it to. I just 
don't want them to be written out as ".ive's"; I want them to be written 
out as my encrypted file format.


Workaround:
Because loaders don't have API's they can't be subclassed. Instead, I 
had to do a little trickery. I'll use encryption as an example. When my 
loader is active (ie: writing an encrypted file), I remove the real IVE 
loader from the ReaderWriter list in the registry (but I keep around a 
pointer to it). I register my loader as something that accepts the 
".ive" extension. Now when anyone tries to write out an ".ive" file, 
they will be using my loader.  Then I use the pointer to the real IVE 
loader to write the node to a stream. When the IVE loader comes across a 
proxy node and wants to write out an ".ive" file, it asks the registry 
for the IVE loader, which then gives it back my loader. My loader gets 
the stream from the real IVE loader then does the encryption and writes 
it out. At the end, my loader adds the real IVE loader back to the 
reader writer list and then changed itself to no longer accept ".ive's" 
as a valid extension.


My suggestion:
This trickery could have been avoided if the logic for the IVE loader 
was in a library that could be extended. The IVE loader has a little 
helper class for every kind of node in OSG. These classes should be 
created with a factory. Then I could subclass the IVE loader and replace 
the ProxyNode helper class with my subclass and I'd be able to have an 
encrypted loader that lives alongside the real IVE loader without any 
weird tricks.


Imagine a library... osgDbIve. This would have headers in the include 
dir, a lib in the lib dir, a dll in the bin dir. Then there would be one 
other library, osgDB_ive which would be very small and only build the 
plugin. Users could then subclass the loader logic since that is all 
contained in an extendable API, and just write the small loader plugin .


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


Re: [osg-users] How do I Subclass a file loader?

2008-10-02 Thread Thrall, Bryan
brettwiesner wrote on Thursday, October 02, 2008 2:22 PM:

> Jean,
> 
> I did try my original solution which is how I know it writes out .ive
> files. I also just implemented the visitor solution to see what happens.
> As expected, the visitor goes and changes the names of all the
> referenced files. Then the top level file is written out. The proxy
> nodes try to write themselves out but since the files they reference
> ("referencedFile.eive") doesn't exist, nothing is written out.
> 
> I would need to be able to change the proxy node ReadWrite class which
> is the part of the IVE loader that says to write out proxy nodes as
> "ive" files. This would require me to derive from ReaderWriterIVE and
> subclass the ProxyNode class so it writes out an "enc" file instead of
> an "ive" file.

Looking at ReaderWriterIVE, it looks like PagedLOD doesn't even try to write 
its children (unless they are already loaded), so if that's what you've got in 
your database, you'll have to manually encrypt its referenced files.

If you've got ProxyNodes, it looks like you can disable automatic writing of 
its referenced files by putting "noWriteExternalReferenceFiles" into the 
Options; then you can manually encrypt the referenced files (you'd still have 
to changed the referenced filenames to "eive"). This would be a workaround to 
subclassing ReaderWriterIVE.

I think the existing mechanisms to do this are not very pretty (and 
inconsistent between ProxyNode and PagedLOD), so if you would like to suggest 
improvements, that would be great!

> Jean-Sébastien Guay wrote:
>> Hi Brett,
>> 
>> I'm wondering, if you suspect that ProxyNodes (and thus PagedLOD nodes
>> as well) would be a problem, why don't you just run a visitor that
>> would find those, and change their extension to eive (or whatever you
>> want)? Then if you write the top-level file, it will write the
>> referenced files with the right writer, and they will be re-read correctly
>> as well... 
>> 
>> Or, try it without and see what happens. If what you suspect turns out
>> to be true, then you have a possible solution above, but if it all
>> works like magic you won't have wasted any time.
>> 
>> Hope this helps,
>> 
>> J-S
> 
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org



-- 
Bryan Thrall
FlightSafety International
[EMAIL PROTECTED]
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] How do I Subclass a file loader?

2008-10-02 Thread brettwiesner

Hi,

I'm going to try one more thing... In my readerWriter, I can unregister 
the real IVE loader, and register my "encrypted ive" loader. This way, 
my loader gets called when a ".ive" is written out/ read in. I'll 
actually call the real IVE loader for all read and writes, but the 
recursive proxy node writer will ask the registry for the readerWriter 
associated with an ".ive" file and it will get give it my EIVE loader. 
When it's all done, I'll re-register the IVE loader with the ".ive" 
extension.


I'll let you know what happens...

Thanks,
Brett



Jean-Sébastien Guay wrote:

Hi Brett,

As expected, the visitor goes and changes the names of all the 
referenced files. Then the top level file is written out. The proxy 
nodes try to write themselves out but since the files they reference 
("referencedFile.eive") doesn't exist, nothing is written out.


I don't quite know what options you have then. In the case of 
ProxyNodes and PagedLOD nodes, you might have to force reading of the 
whole file before you can write it out again anyways... But that may 
exceed the memory in your system (the reason why you use those nodes 
in the first place, most of the time...).


You could catch that error, read the file yourself (original ive 
extension), write it out to eive, and then re-write the parent file. 
(recursively)  That's so ugly I'm almost ashamed I thought of it...


I still don't get why Robert tells you it should work fine, and you 
say it doesn't. Sure, there are any number of things that may go 
wrong, but it should be easier than that.


Sorry I can't help more,

J-S


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


Re: [osg-users] How do I Subclass a file loader?

2008-10-02 Thread Jean-Sébastien Guay

Hi Brett,

As expected, the visitor goes and changes the names of all the 
referenced files. Then the top level file is written out. The proxy 
nodes try to write themselves out but since the files they reference 
("referencedFile.eive") doesn't exist, nothing is written out.


I don't quite know what options you have then. In the case of ProxyNodes 
and PagedLOD nodes, you might have to force reading of the whole file 
before you can write it out again anyways... But that may exceed the 
memory in your system (the reason why you use those nodes in the first 
place, most of the time...).


You could catch that error, read the file yourself (original ive 
extension), write it out to eive, and then re-write the parent file. 
(recursively)  That's so ugly I'm almost ashamed I thought of it...


I still don't get why Robert tells you it should work fine, and you say 
it doesn't. Sure, there are any number of things that may go wrong, but 
it should be easier than that.


Sorry I can't help more,

J-S
--
__
Jean-Sebastien Guay[EMAIL PROTECTED]
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] How do I Subclass a file loader?

2008-10-02 Thread brettwiesner

Jean,

I did try my original solution which is how I know it writes out .ive 
files. I also just implemented the visitor solution to see what happens. 
As expected, the visitor goes and changes the names of all the 
referenced files. Then the top level file is written out. The proxy 
nodes try to write themselves out but since the files they reference 
("referencedFile.eive") doesn't exist, nothing is written out.


I would need to be able to change the proxy node ReadWrite class which 
is the part of the IVE loader that says to write out proxy nodes as 
"ive" files. This would require me to derive from ReaderWriterIVE and 
subclass the ProxyNode class so it writes out an "enc" file instead of 
an "ive" file.


Thanks,
-Brett

Jean-Sébastien Guay wrote:

Hi Brett,

I'm wondering, if you suspect that ProxyNodes (and thus PagedLOD nodes 
as well) would be a problem, why don't you just run a visitor that 
would find those, and change their extension to eive (or whatever you 
want)? Then if you write the top-level file, it will write the 
referenced files with the right writer, and they will be re-read 
correctly as well...


Or, try it without and see what happens. If what you suspect turns out 
to be true, then you have a possible solution above, but if it all 
works like magic you won't have wasted any time.


Hope this helps,

J-S


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


Re: [osg-users] How do I Subclass a file loader?

2008-10-02 Thread Jean-Sébastien Guay

Hi Brett,

I'm wondering, if you suspect that ProxyNodes (and thus PagedLOD nodes 
as well) would be a problem, why don't you just run a visitor that would 
find those, and change their extension to eive (or whatever you want)? 
Then if you write the top-level file, it will write the referenced files 
with the right writer, and they will be re-read correctly as well...


Or, try it without and see what happens. If what you suspect turns out 
to be true, then you have a possible solution above, but if it all works 
like magic you won't have wasted any time.


Hope this helps,

J-S
--
__
Jean-Sebastien Guay[EMAIL PROTECTED]
   http://www.cm-labs.com/
http://whitestar02.webhop.org/
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] How do I Subclass a file loader?

2008-10-02 Thread brettwiesner

Robert,

Maybe some code will help Let's say I write my own ReaderWriter that 
reads and writes encrypted ive files or "eive" files.


class ReaderWriterEive : public osgDB::ReaderWriter
{

public

  virtual bool acceptsExtension(const std::string& extension) const
  {
//  Accepts "eive" as an extension.
  }

  // This takes in a .eive file which is an "encrypted ive file".
  virtual osgDB::ReaderWriter::ReadResult readNode(const std::string& 
file,

 const osgDB::ReaderWriter::Options* options) const
  {
 // basic file checking, etc.

 std::ifstream istream(file.c_str(), std::ios::in | std::ios::binary);
 return readNode(istream, options);
  }

  virtual osgDB::ReaderWriter::ReadResult readNode(std::istream& 
encryptedInput,

 const osgDB::ReaderWriter::Options* options) const
  {
 ReadResult rr;
 //
 // 1. decrypt stream.
 // 2. call the ive readerWriter's readNode() method on the 
decrypted stream.

 //

 // Create an input stream to store the decrypted data in so the 
reader can read it.
 std::istringstream decryptedInputStream(std::ios::in | 
std::ios::binary);


 // Decrypted the encryptedInput into the decryptedInputStream.
 if(decrypt(encryptedInput, decryptedInputStream))
 {
 // Find the correct reader writer.
 osgDB::ReaderWriter* readerWriter =
   
osgDB::Registry::instance()->getReaderWriterForExtension(".ive");


 if(readerWriter)
 {
// Use the reader to read the decrypted data.
rr = readerWriter->readNode(decryptedInputStream, 
options);  
 }

 }
 return rr;
  }

  virtual osgDB::ReaderWriter::WriteResult writeNode(const osg::Node& node,
 const std::string& fileName, const osgDB::ReaderWriter::Options* 
options) const

  {
 // basic file checking...

 std::ofstream fout(fileName.c_str(), std::ios::out | 
std::ios::binary);

 if(!fout)
 {
return osgDB::ReaderWriter::WriteResult::ERROR_IN_WRITING_FILE;
 }

 osgDB::ReaderWriter::WriteResult result = writeNode(node, fout, 
local_opt.get());

 fout.close();
 return result;
  }


  virtual osgDB::ReaderWriter::WriteResult writeNode(const osg::Node& node,
 std::ostream& fout, const osgDB::ReaderWriter::Options* options) const
  {
WriteResult wr;
//
// 1. call the ive readerWriter's writeNode() method on the stream.
// 2. encrypt stream.
//
  
// Find the correct reader writer.

osgDB::ReaderWriter* readerWriter =
   
osgDB::Registry::instance()->getReaderWriterForExtension(".ive");
 
if(readerWriter)

{
 // Create an output stream to store the raw ive data.
 std::ostringstream rawIveData(std::ios::out |std::ios::binary);

 // Use the reader to write the decrypted data.
 // This is where the problem is. The ive's reader writer will 
get called
 // for every proxy node. My reader writer will not get called 
and therefore all

 // referenced files will be written out as unencrypted ive files.
 wr = readerWriter->writeNode(node, rawIveData, options); 
 
 // Encrypt the decrypted data into the file output.

 encrypt(rawIveData, fileOutputStream);
 }

 return wr;
  }

The problem is in the writeNode() method that writes out to an ofstream. 
When I give it a stream to write the data to, it does so, but it also 
writes out all referenced files on its own, as regular .ive's. Perhaps 
my design is flawed and there is a better way but I'm not seeing it in 
the curl or osga loader.


Thanks,
Brett


Robert Osfield wrote:

HI Brett,

Please follow the suggestions already made.  The osga plugin already
implementents a custom std::streambuf, and the curl plugin uses a
stingstream to adapt an external stream into something that the other
OSG plugins can use.

Robert.

On Thu, Oct 2, 2008 at 3:47 PM, brettwiesner <[EMAIL PROTECTED]> wrote:
  

Robert,

OK, I'm reading up on basic_streambuf now. In the meantime, maybe you
can help me understand how I can use a derived streambuf with the existing
IVE loader. Aren't I going to run into the same problem? When the IVE loader
comes across a proxy node, it will write out the node using the IVE loader
and it won't matter that I originally made the call to writeNode() with my
specialized ostream. It's going to create a file stream and write out the
proxy node and there's no way for me to change that.

Thanks,
Brett

Robert Osfield wrote:


Hi Brett,

You need to read up about deriving your own custom std::streambuf,
once you understand this part then adapting existing plugins to use
your encrypted stream will be straightforward.  You could even be lazy
a use a stringstream like the curl plugin does.  Please look into this
stuff - this will answer your need, and there is certainly no need to
subclass from plugins, C++ std::stream streambuf extensibility exist
to help solve problem like yours, and the OS

Re: [osg-users] How do I Subclass a file loader?

2008-10-02 Thread Robert Osfield
HI Brett,

Please follow the suggestions already made.  The osga plugin already
implementents a custom std::streambuf, and the curl plugin uses a
stingstream to adapt an external stream into something that the other
OSG plugins can use.

Robert.

On Thu, Oct 2, 2008 at 3:47 PM, brettwiesner <[EMAIL PROTECTED]> wrote:
> Robert,
>
> OK, I'm reading up on basic_streambuf now. In the meantime, maybe you
> can help me understand how I can use a derived streambuf with the existing
> IVE loader. Aren't I going to run into the same problem? When the IVE loader
> comes across a proxy node, it will write out the node using the IVE loader
> and it won't matter that I originally made the call to writeNode() with my
> specialized ostream. It's going to create a file stream and write out the
> proxy node and there's no way for me to change that.
>
> Thanks,
> Brett
>
> Robert Osfield wrote:
>>
>> Hi Brett,
>>
>> You need to read up about deriving your own custom std::streambuf,
>> once you understand this part then adapting existing plugins to use
>> your encrypted stream will be straightforward.  You could even be lazy
>> a use a stringstream like the curl plugin does.  Please look into this
>> stuff - this will answer your need, and there is certainly no need to
>> subclass from plugins, C++ std::stream streambuf extensibility exist
>> to help solve problem like yours, and the OSG takes advantage of this.
>>
>> Robert.
>>
>> On Wed, Oct 1, 2008 at 9:27 PM, brettwiesner <[EMAIL PROTECTED]>
>> wrote:
>>
>>>
>>> Hey Robert,
>>>
>>> I'm confused about what you mean here. Many plugins have read/ write
>>> methods
>>> that take istreams/ ostreams (ReaderWriterIVE being one of them).
>>> However,
>>> since I can't subclass them I can't attach to the stream. For example, in
>>> ReaderWriterIVE::writeNode() a std::ofstream is created but there's no
>>> way
>>> for me to attach it to a stream buffer.
>>>
>>> It seems like the osga plugin would have the same problem. The doread()/
>>> dowrite() methods call up to whatever ReaderWriter was passed in and I
>>> can't
>>> subclass those.
>>>
>>> Thanks,
>>> Brett
>>>
>>> Robert Osfield wrote:
>>>

 Hi Brett,

 A number of the plugins support reading a writing from istream/ostream
 which means you can implement your std::streambuffer and attach to the
 stream and then pass this to the plugin.  This technique allows you to
 do items like compression/decompression/encription/decription.  Have a
 look at the osga and curl plugins as they provide examples of using
 streams this way.

 Robert.

 On Wed, Oct 1, 2008 at 5:02 PM, brettwiesner <[EMAIL PROTECTED]>
 wrote:


>
> Hi,
>
> I've got a requirement to ship certain 3rd party model data only in an
> encrypted format. So I wrote my own loader that does the encryption/
> decryption but uses the IVE loader for everything. This works except
> for
> files that reference other files. The master file is encrypted, but the
> referenced files are saved out as .ive's.
>
> Ideally all I would have to do is subclass ReaderWriterIVE and override
> the
> following stream methods:
>
>  virtual osgDB::ReaderWriter::ReadResult readObject(std::istream& fin,
>   const osgDB::ReaderWriter::Options* options) const;
>
>  virtual osgDB::ReaderWriter::ReadResult readImage(std::istream& fin,
>   const osgDB::ReaderWriter::Options* options) const;
>
>  virtual osgDB::ReaderWriter::ReadResult readNode(std::istream& fin,
>   const osgDB::ReaderWriter::Options* options) const;
>
>  virtual osgDB::ReaderWriter::WriteResult writeObject(const
> osg::Object&
> object,
>   std::ostream& fout, const osgDB::ReaderWriter::Options* options)
> const;
>
>  virtual osgDB::ReaderWriter::WriteResult writeImage(const osg::Image&
> image,
>   std::ostream& fout, const osgDB::ReaderWriter::Options* options)
> const;
>
>  virtual osgDB::ReaderWriter::WriteResult writeNode(const osg::Node&
> node,
>   std::ostream& fout, const osgDB::ReaderWriter::Options* options)
> const;
>
> For writing I could get the raw data from the ive loader encrypt it and
> write it out. For reading I could decrypt the data, then pass the
> unencrypted data up to the ive loader for use.
>
> There is one fatal flaw... I can't subclass the ReaderWriterIVE plugin.
> :(
>
> 1) Has anyone besides me ever wanted to derive from a file loader?
> Would
> it
> make sense to keep the logic in a lib with headers, then have another
> library that is just the plugin?
>
> 2) Is there some other mechanism in OSG that will let me do this?
>
> Thanks,
> Brett
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
>
> http://lists.openscenegraph.org/listinfo.cgi/osg-

Re: [osg-users] How do I Subclass a file loader?

2008-10-02 Thread brettwiesner

Robert,

OK, I'm reading up on basic_streambuf now. In the meantime, maybe 
you can help me understand how I can use a derived streambuf with the 
existing IVE loader. Aren't I going to run into the same problem? When 
the IVE loader comes across a proxy node, it will write out the node 
using the IVE loader and it won't matter that I originally made the call 
to writeNode() with my specialized ostream. It's going to create a file 
stream and write out the proxy node and there's no way for me to change 
that.


Thanks,
Brett

Robert Osfield wrote:

Hi Brett,

You need to read up about deriving your own custom std::streambuf,
once you understand this part then adapting existing plugins to use
your encrypted stream will be straightforward.  You could even be lazy
a use a stringstream like the curl plugin does.  Please look into this
stuff - this will answer your need, and there is certainly no need to
subclass from plugins, C++ std::stream streambuf extensibility exist
to help solve problem like yours, and the OSG takes advantage of this.

Robert.

On Wed, Oct 1, 2008 at 9:27 PM, brettwiesner <[EMAIL PROTECTED]> wrote:
  

Hey Robert,

I'm confused about what you mean here. Many plugins have read/ write methods
that take istreams/ ostreams (ReaderWriterIVE being one of them). However,
since I can't subclass them I can't attach to the stream. For example, in
ReaderWriterIVE::writeNode() a std::ofstream is created but there's no way
for me to attach it to a stream buffer.

It seems like the osga plugin would have the same problem. The doread()/
dowrite() methods call up to whatever ReaderWriter was passed in and I can't
subclass those.

Thanks,
Brett

Robert Osfield wrote:


Hi Brett,

A number of the plugins support reading a writing from istream/ostream
which means you can implement your std::streambuffer and attach to the
stream and then pass this to the plugin.  This technique allows you to
do items like compression/decompression/encription/decription.  Have a
look at the osga and curl plugins as they provide examples of using
streams this way.

Robert.

On Wed, Oct 1, 2008 at 5:02 PM, brettwiesner <[EMAIL PROTECTED]>
wrote:

  

Hi,

I've got a requirement to ship certain 3rd party model data only in an
encrypted format. So I wrote my own loader that does the encryption/
decryption but uses the IVE loader for everything. This works except for
files that reference other files. The master file is encrypted, but the
referenced files are saved out as .ive's.

Ideally all I would have to do is subclass ReaderWriterIVE and override
the
following stream methods:

 virtual osgDB::ReaderWriter::ReadResult readObject(std::istream& fin,
   const osgDB::ReaderWriter::Options* options) const;

 virtual osgDB::ReaderWriter::ReadResult readImage(std::istream& fin,
   const osgDB::ReaderWriter::Options* options) const;

 virtual osgDB::ReaderWriter::ReadResult readNode(std::istream& fin,
   const osgDB::ReaderWriter::Options* options) const;

 virtual osgDB::ReaderWriter::WriteResult writeObject(const osg::Object&
object,
   std::ostream& fout, const osgDB::ReaderWriter::Options* options)
const;

 virtual osgDB::ReaderWriter::WriteResult writeImage(const osg::Image&
image,
   std::ostream& fout, const osgDB::ReaderWriter::Options* options)
const;

 virtual osgDB::ReaderWriter::WriteResult writeNode(const osg::Node&
node,
   std::ostream& fout, const osgDB::ReaderWriter::Options* options)
const;

For writing I could get the raw data from the ive loader encrypt it and
write it out. For reading I could decrypt the data, then pass the
unencrypted data up to the ive loader for use.

There is one fatal flaw... I can't subclass the ReaderWriterIVE plugin.
:(

1) Has anyone besides me ever wanted to derive from a file loader? Would
it
make sense to keep the logic in a lib with headers, then have another
library that is just the plugin?

2) Is there some other mechanism in OSG that will let me do this?

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




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

  

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



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


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


Re: [osg-users] How do I Subclass a file loader?

2008-10-02 Thread Robert Osfield
Hi Brett,

You need to read up about deriving your own custom std::streambuf,
once you understand this part then adapting existing plugins to use
your encrypted stream will be straightforward.  You could even be lazy
a use a stringstream like the curl plugin does.  Please look into this
stuff - this will answer your need, and there is certainly no need to
subclass from plugins, C++ std::stream streambuf extensibility exist
to help solve problem like yours, and the OSG takes advantage of this.

Robert.

On Wed, Oct 1, 2008 at 9:27 PM, brettwiesner <[EMAIL PROTECTED]> wrote:
> Hey Robert,
>
> I'm confused about what you mean here. Many plugins have read/ write methods
> that take istreams/ ostreams (ReaderWriterIVE being one of them). However,
> since I can't subclass them I can't attach to the stream. For example, in
> ReaderWriterIVE::writeNode() a std::ofstream is created but there's no way
> for me to attach it to a stream buffer.
>
> It seems like the osga plugin would have the same problem. The doread()/
> dowrite() methods call up to whatever ReaderWriter was passed in and I can't
> subclass those.
>
> Thanks,
> Brett
>
> Robert Osfield wrote:
>>
>> Hi Brett,
>>
>> A number of the plugins support reading a writing from istream/ostream
>> which means you can implement your std::streambuffer and attach to the
>> stream and then pass this to the plugin.  This technique allows you to
>> do items like compression/decompression/encription/decription.  Have a
>> look at the osga and curl plugins as they provide examples of using
>> streams this way.
>>
>> Robert.
>>
>> On Wed, Oct 1, 2008 at 5:02 PM, brettwiesner <[EMAIL PROTECTED]>
>> wrote:
>>
>>>
>>> Hi,
>>>
>>> I've got a requirement to ship certain 3rd party model data only in an
>>> encrypted format. So I wrote my own loader that does the encryption/
>>> decryption but uses the IVE loader for everything. This works except for
>>> files that reference other files. The master file is encrypted, but the
>>> referenced files are saved out as .ive's.
>>>
>>> Ideally all I would have to do is subclass ReaderWriterIVE and override
>>> the
>>> following stream methods:
>>>
>>>  virtual osgDB::ReaderWriter::ReadResult readObject(std::istream& fin,
>>>const osgDB::ReaderWriter::Options* options) const;
>>>
>>>  virtual osgDB::ReaderWriter::ReadResult readImage(std::istream& fin,
>>>const osgDB::ReaderWriter::Options* options) const;
>>>
>>>  virtual osgDB::ReaderWriter::ReadResult readNode(std::istream& fin,
>>>const osgDB::ReaderWriter::Options* options) const;
>>>
>>>  virtual osgDB::ReaderWriter::WriteResult writeObject(const osg::Object&
>>> object,
>>>std::ostream& fout, const osgDB::ReaderWriter::Options* options)
>>> const;
>>>
>>>  virtual osgDB::ReaderWriter::WriteResult writeImage(const osg::Image&
>>> image,
>>>std::ostream& fout, const osgDB::ReaderWriter::Options* options)
>>> const;
>>>
>>>  virtual osgDB::ReaderWriter::WriteResult writeNode(const osg::Node&
>>> node,
>>>std::ostream& fout, const osgDB::ReaderWriter::Options* options)
>>> const;
>>>
>>> For writing I could get the raw data from the ive loader encrypt it and
>>> write it out. For reading I could decrypt the data, then pass the
>>> unencrypted data up to the ive loader for use.
>>>
>>> There is one fatal flaw... I can't subclass the ReaderWriterIVE plugin.
>>> :(
>>>
>>> 1) Has anyone besides me ever wanted to derive from a file loader? Would
>>> it
>>> make sense to keep the logic in a lib with headers, then have another
>>> library that is just the plugin?
>>>
>>> 2) Is there some other mechanism in OSG that will let me do this?
>>>
>>> Thanks,
>>> Brett
>>> ___
>>> osg-users mailing list
>>> osg-users@lists.openscenegraph.org
>>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>>
>>>
>>
>> ___
>> osg-users mailing list
>> osg-users@lists.openscenegraph.org
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] How do I Subclass a file loader?

2008-10-01 Thread Thrall, Bryan
brettwiesner wrote on Wednesday, October 01, 2008 3:27 PM:

> Hey Robert,
> 
> I'm confused about what you mean here. Many plugins have read/ write
> methods that take istreams/ ostreams (ReaderWriterIVE being one of
> them). However, since I can't subclass them I can't attach to the
> stream. For example, in ReaderWriterIVE::writeNode() a std::ofstream
is
> created but there's no way for me to attach it to a stream buffer.
> 
> It seems like the osga plugin would have the same problem. The
doread()/
> dowrite() methods call up to whatever ReaderWriter was passed in and I
> can't subclass those.

I think Robert was suggesting implementing your own istream/ostream that
does the encryption internally, then passing that to the read/write
methods that take streams.

> Robert Osfield wrote:
>> Hi Brett,
>> 
>> A number of the plugins support reading a writing from
istream/ostream
>> which means you can implement your std::streambuffer and attach to
the
>> stream and then pass this to the plugin.  This technique allows you
to
>> do items like compression/decompression/encription/decription.  Have
a
>> look at the osga and curl plugins as they provide examples of using
>> streams this way.
>> 
>> Robert.
>> 
>> On Wed, Oct 1, 2008 at 5:02 PM, brettwiesner <[EMAIL PROTECTED]>
wrote:
>> 
>>> Hi,
>>> 
>>> I've got a requirement to ship certain 3rd party model data only in
an
>>> encrypted format. So I wrote my own loader that does the encryption/
>>> decryption but uses the IVE loader for everything. This works except
for
>>> files that reference other files. The master file is encrypted, but
the
>>> referenced files are saved out as .ive's.
>>> 
>>> Ideally all I would have to do is subclass ReaderWriterIVE and
override the
>>> following stream methods: 
>>> 
>>>  virtual osgDB::ReaderWriter::ReadResult readObject(std::istream&
fin,
>>> const osgDB::ReaderWriter::Options* options) const;
>>> 
>>>  virtual osgDB::ReaderWriter::ReadResult readImage(std::istream&
fin,
>>> const osgDB::ReaderWriter::Options* options) const;
>>> 
>>>  virtual osgDB::ReaderWriter::ReadResult readNode(std::istream& fin,
>>> const osgDB::ReaderWriter::Options* options) const;
>>> 
>>>  virtual osgDB::ReaderWriter::WriteResult writeObject(const
osg::Object&
>>> object, std::ostream& fout, const osgDB::ReaderWriter::Options*
>>> options) const; 
>>> 
>>>  virtual osgDB::ReaderWriter::WriteResult writeImage(const
osg::Image&
>>> image, std::ostream& fout, const osgDB::ReaderWriter::Options*
options)
>>> const; 
>>> 
>>>  virtual osgDB::ReaderWriter::WriteResult writeNode(const osg::Node&
node,
>>> std::ostream& fout, const osgDB::ReaderWriter::Options* options)
const;
>>> 
>>> For writing I could get the raw data from the ive loader encrypt it
and
>>> write it out. For reading I could decrypt the data, then pass the
>>> unencrypted data up to the ive loader for use.
>>> 
>>> There is one fatal flaw... I can't subclass the ReaderWriterIVE
plugin. :(
>>> 
>>> 1) Has anyone besides me ever wanted to derive from a file loader?
Would it
>>> make sense to keep the logic in a lib with headers, then have
another
>>> library that is just the plugin?
>>> 
>>> 2) Is there some other mechanism in OSG that will let me do this?
-- 
Bryan Thrall
FlightSafety International
[EMAIL PROTECTED]
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] How do I Subclass a file loader?

2008-10-01 Thread brettwiesner

Hey Robert,

I'm confused about what you mean here. Many plugins have read/ write 
methods that take istreams/ ostreams (ReaderWriterIVE being one of 
them). However, since I can't subclass them I can't attach to the 
stream. For example, in ReaderWriterIVE::writeNode() a std::ofstream is 
created but there's no way for me to attach it to a stream buffer.


It seems like the osga plugin would have the same problem. The doread()/ 
dowrite() methods call up to whatever ReaderWriter was passed in and I 
can't subclass those.


Thanks,
Brett

Robert Osfield wrote:

Hi Brett,

A number of the plugins support reading a writing from istream/ostream
which means you can implement your std::streambuffer and attach to the
stream and then pass this to the plugin.  This technique allows you to
do items like compression/decompression/encription/decription.  Have a
look at the osga and curl plugins as they provide examples of using
streams this way.

Robert.

On Wed, Oct 1, 2008 at 5:02 PM, brettwiesner <[EMAIL PROTECTED]> wrote:
  

Hi,

I've got a requirement to ship certain 3rd party model data only in an
encrypted format. So I wrote my own loader that does the encryption/
decryption but uses the IVE loader for everything. This works except for
files that reference other files. The master file is encrypted, but the
referenced files are saved out as .ive's.

Ideally all I would have to do is subclass ReaderWriterIVE and override the
following stream methods:

 virtual osgDB::ReaderWriter::ReadResult readObject(std::istream& fin,
const osgDB::ReaderWriter::Options* options) const;

 virtual osgDB::ReaderWriter::ReadResult readImage(std::istream& fin,
const osgDB::ReaderWriter::Options* options) const;

 virtual osgDB::ReaderWriter::ReadResult readNode(std::istream& fin,
const osgDB::ReaderWriter::Options* options) const;

 virtual osgDB::ReaderWriter::WriteResult writeObject(const osg::Object&
object,
std::ostream& fout, const osgDB::ReaderWriter::Options* options) const;

 virtual osgDB::ReaderWriter::WriteResult writeImage(const osg::Image&
image,
std::ostream& fout, const osgDB::ReaderWriter::Options* options) const;

 virtual osgDB::ReaderWriter::WriteResult writeNode(const osg::Node& node,
std::ostream& fout, const osgDB::ReaderWriter::Options* options) const;

For writing I could get the raw data from the ive loader encrypt it and
write it out. For reading I could decrypt the data, then pass the
unencrypted data up to the ive loader for use.

There is one fatal flaw... I can't subclass the ReaderWriterIVE plugin. :(

1) Has anyone besides me ever wanted to derive from a file loader? Would it
make sense to keep the logic in a lib with headers, then have another
library that is just the plugin?

2) Is there some other mechanism in OSG that will let me do this?

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



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


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


Re: [osg-users] How do I Subclass a file loader?

2008-10-01 Thread Robert Osfield
Hi Brett,

A number of the plugins support reading a writing from istream/ostream
which means you can implement your std::streambuffer and attach to the
stream and then pass this to the plugin.  This technique allows you to
do items like compression/decompression/encription/decription.  Have a
look at the osga and curl plugins as they provide examples of using
streams this way.

Robert.

On Wed, Oct 1, 2008 at 5:02 PM, brettwiesner <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I've got a requirement to ship certain 3rd party model data only in an
> encrypted format. So I wrote my own loader that does the encryption/
> decryption but uses the IVE loader for everything. This works except for
> files that reference other files. The master file is encrypted, but the
> referenced files are saved out as .ive's.
>
> Ideally all I would have to do is subclass ReaderWriterIVE and override the
> following stream methods:
>
>  virtual osgDB::ReaderWriter::ReadResult readObject(std::istream& fin,
> const osgDB::ReaderWriter::Options* options) const;
>
>  virtual osgDB::ReaderWriter::ReadResult readImage(std::istream& fin,
> const osgDB::ReaderWriter::Options* options) const;
>
>  virtual osgDB::ReaderWriter::ReadResult readNode(std::istream& fin,
> const osgDB::ReaderWriter::Options* options) const;
>
>  virtual osgDB::ReaderWriter::WriteResult writeObject(const osg::Object&
> object,
> std::ostream& fout, const osgDB::ReaderWriter::Options* options) const;
>
>  virtual osgDB::ReaderWriter::WriteResult writeImage(const osg::Image&
> image,
> std::ostream& fout, const osgDB::ReaderWriter::Options* options) const;
>
>  virtual osgDB::ReaderWriter::WriteResult writeNode(const osg::Node& node,
> std::ostream& fout, const osgDB::ReaderWriter::Options* options) const;
>
> For writing I could get the raw data from the ive loader encrypt it and
> write it out. For reading I could decrypt the data, then pass the
> unencrypted data up to the ive loader for use.
>
> There is one fatal flaw... I can't subclass the ReaderWriterIVE plugin. :(
>
> 1) Has anyone besides me ever wanted to derive from a file loader? Would it
> make sense to keep the logic in a lib with headers, then have another
> library that is just the plugin?
>
> 2) Is there some other mechanism in OSG that will let me do this?
>
> Thanks,
> Brett
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] How do I Subclass a file loader?

2008-10-01 Thread Thrall, Bryan
brettwiesner wrote on Wednesday, October 01, 2008 11:54 AM:

> Bryan,
> 
> Thanks for the reply. See inline...
>> You could implement your own loader with a different file extension
>> (say, ".enc") that does the en/decryption and then calls the IVE
loader
>> to load the resulting data. The curl loader does something like this.
>> 
> 
> This is what I did originally. There was a problem with referenced
> files; those wouldn't get encrypted/ decrypted. The IVE loader would
> just process them as .ive's.
> 
>> Or you could use a osgDB::Registry::Read/WriteFileCallback to
de/encrypt
>> the data before it gets read/sent from/to disk.
>> 
>> 
> 
> That is interesting. I didn't know about those before. I think they
will
> have the same problem though. If I write a callback that does
something
> special when it's suppose to write out an encrypted file, and it uses
> the IVE loader to get the data to encrypt, that process will still
cause
> the IVE loader to write out referenced files as .ive's.
> 
> This would be pretty easy if I could derive from ReaderWriterIVE.

It sounds like the problem is the referenced filenames; perhaps a
visitor to change them to have the ".enc" extension so they get written
through your loader rather than the IVE one directly?

For example, a ProxyNode or PagedLOD that refers to "foo.osg" would have
to be changed to refer to "foo.osg.enc" before you do the actual write.

-- 
Bryan Thrall
FlightSafety International
[EMAIL PROTECTED]
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] How do I Subclass a file loader?

2008-10-01 Thread brettwiesner

Bryan,

Thanks for the reply. See inline...

You could implement your own loader with a different file extension
(say, ".enc") that does the en/decryption and then calls the IVE loader
to load the resulting data. The curl loader does something like this.
  


This is what I did originally. There was a problem with referenced 
files; those wouldn't get encrypted/ decrypted. The IVE loader would 
just process them as .ive's.



Or you could use a osgDB::Registry::Read/WriteFileCallback to de/encrypt
the data before it gets read/sent from/to disk.

  


That is interesting. I didn't know about those before. I think they will 
have the same problem though. If I write a callback that does something 
special when it's suppose to write out an encrypted file, and it uses 
the IVE loader to get the data to encrypt, that process will still cause 
the IVE loader to write out referenced files as .ive's.


This would be pretty easy if I could derive from ReaderWriterIVE.

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


Re: [osg-users] How do I Subclass a file loader?

2008-10-01 Thread Thrall, Bryan
brettwiesner wrote on Wednesday, October 01, 2008 11:02 AM:
> I've got a requirement to ship certain 3rd party model data only in an
> encrypted format. So I wrote my own loader that does the encryption/
> decryption but uses the IVE loader for everything. This works except
for
> files that reference other files. The master file is encrypted, but
the
> referenced files are saved out as .ive's.

> 2) Is there some other mechanism in OSG that will let me do this?

You could implement your own loader with a different file extension
(say, ".enc") that does the en/decryption and then calls the IVE loader
to load the resulting data. The curl loader does something like this.

Or you could use a osgDB::Registry::Read/WriteFileCallback to de/encrypt
the data before it gets read/sent from/to disk.

-- 
Bryan Thrall
FlightSafety International
[EMAIL PROTECTED]
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] How do I Subclass a file loader?

2008-10-01 Thread brettwiesner

Hi,

I've got a requirement to ship certain 3rd party model data only in an 
encrypted format. So I wrote my own loader that does the encryption/ 
decryption but uses the IVE loader for everything. This works except for 
files that reference other files. The master file is encrypted, but the 
referenced files are saved out as .ive's.


Ideally all I would have to do is subclass ReaderWriterIVE and override 
the following stream methods:


 virtual osgDB::ReaderWriter::ReadResult readObject(std::istream& fin,
 const osgDB::ReaderWriter::Options* options) const;

  virtual osgDB::ReaderWriter::ReadResult readImage(std::istream& fin,
 const osgDB::ReaderWriter::Options* options) const;

  virtual osgDB::ReaderWriter::ReadResult readNode(std::istream& fin,
 const osgDB::ReaderWriter::Options* options) const;

  virtual osgDB::ReaderWriter::WriteResult writeObject(const 
osg::Object& object,
 std::ostream& fout, const osgDB::ReaderWriter::Options* options) 
const;


  virtual osgDB::ReaderWriter::WriteResult writeImage(const osg::Image& 
image,
 std::ostream& fout, const osgDB::ReaderWriter::Options* options) 
const;


  virtual osgDB::ReaderWriter::WriteResult writeNode(const osg::Node& node,
 std::ostream& fout, const osgDB::ReaderWriter::Options* options) 
const;


For writing I could get the raw data from the ive loader encrypt it and 
write it out. For reading I could decrypt the data, then pass the 
unencrypted data up to the ive loader for use.


There is one fatal flaw... I can't subclass the ReaderWriterIVE plugin. :(

1) Has anyone besides me ever wanted to derive from a file loader? Would 
it make sense to keep the logic in a lib with headers, then have another 
library that is just the plugin?


2) Is there some other mechanism in OSG that will let me do this?

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