Re: [osg-users] Is it possible to redrirct all readimage call to a customed method

2009-04-14 Thread Roger
Thanks,

Problem has been solved, and for others reference, code clue listed below:

class FileReadOnceCallback : public osgDB::Registry::ReadFileCallback
{
private:
typedef mapstring,osg::ref_ptrosg::Object PathPointerMap;
PathPointerMap pathpointermap;

public:

virtual osgDB::ReaderWriter::ReadResult readImage(const std::string 
filename, const osgDB::ReaderWriter::Options* options)
{
PathPointerMap::iterator itr=pathpointermap.find(filename);
if (itr==pathpointermap.end()) //没有找到,读取文件
{
osgDB::ReaderWriter::ReadResult result;

result=osgDB::Registry::instance()-readImageImplementation(filename,options);
osg::ref_ptrosg::Image refobj=result.getImage();
if (result.validImage()) 
pathpointermap[filename]=refobj; //将资源以ref_ptr形式记入map
return result;
}
else //找到,直接返回存贮的指针
{
osgDB::ReaderWriter::ReadResult 
result(itr-second.get(),osgDB::ReaderWriter::ReadResult::FILE_LOADED);
return itr-second.get();
}
}

~FileReadOnceCallback(){std::coutDestruct FileReadOnce CallBack.;}

};

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=10190#10190





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


Re: [osg-users] Is it possible to redrirct all readimage call to a customed method

2009-04-13 Thread Robert Osfield
Hi Roger,

The osgDB::Registry::ReadFileCallback can be used to intercept all readImage
or readNode calls.  Have a search through the archives for disucssion about
it.

Robert.

On Mon, Apr 13, 2009 at 11:27 AM, Roger edl7...@hotmail.com wrote:

 Hi,

 I am a developer of OSG.And I am trying to simulate a stand of a forest. My
 tree model is created in MultiGen Creator. Since there will be many many
 trees in a stand (about 6trees or so),and each trees has it own
 height\under branch height\canopy diameter etc,I develped a method to
 transform the loaded tree model to given parameter restricted model. This
 transformation can't be acomplishied just using transform node, so I just
 change the vertex of each goede.This means that Except the vertex of each
 target model are different, while the texture are the same.

 Now the problem is that I would have to read the origin model many many
 times,and transform it to target model. And in memory there are many many
 textures are the same.

 Is it possible to redrirct all readimage call to a customed method, which I
 could apply sigleton pattern and assure the same image file only read once
 in a application instance? Since flt file are readed with plugin, so I just
 don't know how to realize it in a nice and neat way.

 I will be very appreciated if you can give me some clue.
 Thank you.

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=10155#10155





 ___
 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