Hi Miha,
I have attempted to merge your submission but on testing found that it
breaks the osg plugin ability to load .osgt files, it only is able to
load .osgb files successfully. This is a very serious bug. The
original code itself wasn't a bug, rather it just didn't do what you
wanted it to. If your changes had not broken the existing plugin then
I would have merged it.
When merging I had to amend some of the formatting and line spacing
that you used to make the code more readable, the attached file is the
result of an svn diff against svn trunk so you can use this as a basis
for any future submission if you wish to re-submit once you have fixed
the bugs. Please in future actually test your code properly before
submitting, I have many submissions to get through and having to
merge, test and then revert broken submissions waste alot of me time.
Robert.
On 11 February 2013 21:34, Miha Ravšelj <[email protected]> wrote:
> During development I discovered some issues in file extension mapping.
>
> My goal was to map user-defined extension to new osg format but i ran into
> some problems.
>
> The code that recreates the problem:
>
> //we read sample geometry from file
> osg::Geode* geode = osgDB::readNodeFile("geode.osgb");
>
> //now we want to globally map xyz extension to be opened the same way as
> osgt
> osgDB::Registry::instance()->addFileExtensionAlias("xyz","osgt");
>
> //however this line does not work since ReaderWriterOSG2 rejects extension
> 'xyz'
> bool b = osgDB::writeNodeFile(*geode,"geode.xyz");
>
> Solution:
> I added some code to ReaderWriter.cpp acceptsExtensiont() to check also for
> registry alias and if alias is supported. Since there was no
> getFileExtensionAlias method I also implemented it in Registry class.
> ReaderWriterOSG2 is extended with code that make mapping to osgt and osgx
> possible. Without it mapping of xywz->osgt would produce always default
> osgb(binary) output.
>
> Greetings,
> Miha
>
>
>
>
> _______________________________________________
> osg-submissions mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
>
Index: src/osgDB/Registry.cpp
===================================================================
--- src/osgDB/Registry.cpp (revision 13338)
+++ src/osgDB/Registry.cpp (working copy)
@@ -674,6 +674,12 @@
_extAliasMap[mapExt] = toExt;
}
+std::string Registry::getFileExtensionAlias(const std::string& mapExt) const
+{
+ ExtensionAliasMap::const_iterator itr = _extAliasMap.find(mapExt);
+ return ( itr != _extAliasMap.end() ) ? itr->second : std::string();
+}
+
void Registry::addMimeTypeExtensionMapping(const std::string fromMimeType,
const std::string toExt)
{
_mimeTypeExtMap[fromMimeType] = toExt;
Index: src/osgDB/ReaderWriter.cpp
===================================================================
--- src/osgDB/ReaderWriter.cpp (revision 13338)
+++ src/osgDB/ReaderWriter.cpp (working copy)
@@ -41,7 +41,11 @@
{
// check for an exact match
std::string lowercase_ext = convertToLowerCase(extension);
- return (_supportedExtensions.count(lowercase_ext)!=0);
+ if( _supportedExtensions.count(lowercase_ext)!=0) return true;
+
+ //check for alias extension
+ std::string mappedExt =
osgDB::Registry::instance()->getFileExtensionAlias(extension);
+ return _supportedExtensions.count(mappedExt) != 0;
}
bool ReaderWriter::acceptsProtocol(const std::string& protocol) const
Index: src/osgPlugins/osg/ReaderWriterOSG2.cpp
===================================================================
--- src/osgPlugins/osg/ReaderWriterOSG2.cpp (revision 13338)
+++ src/osgPlugins/osg/ReaderWriterOSG2.cpp (working copy)
@@ -158,8 +158,12 @@
osg::ref_ptr<Options> local_opt = options ?
static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) :
new Options;
local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName));
- if ( ext=="osgt" ) local_opt->setOptionString(
local_opt->getOptionString() + " Ascii" );
- else if ( ext=="osgx" ) local_opt->setOptionString(
local_opt->getOptionString() + " XML" );
+
+ std::string mappedExt =
osgDB::Registry::instance()->getFileExtensionAlias(ext);
+ if( mappedExt.empty() ) mappedExt = ext;
+
+ if ( mappedExt=="osgt" ) local_opt->setOptionString(
local_opt->getOptionString() + " Ascii" );
+ else if ( mappedExt=="osgx" ) local_opt->setOptionString(
local_opt->getOptionString() + " XML" );
else mode |= std::ios::binary;
return local_opt.release();
@@ -261,8 +265,12 @@
osg::ref_ptr<Options> local_opt = options ?
static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) :
new Options;
local_opt->getDatabasePathList().push_front(osgDB::getFilePath(fileName));
- if ( ext=="osgt" ) local_opt->setOptionString(
local_opt->getOptionString() + " Ascii" );
- else if ( ext=="osgx" ) local_opt->setOptionString(
local_opt->getOptionString() + " XML" );
+
+ std::string mappedExt =
osgDB::Registry::instance()->getFileExtensionAlias(ext);
+ if( mappedExt.empty() ) mappedExt = ext;
+
+ if ( mappedExt=="osgt" ) local_opt->setOptionString(
local_opt->getOptionString() + " Ascii" );
+ else if ( mappedExt=="osgx" ) local_opt->setOptionString(
local_opt->getOptionString() + " XML" );
else mode |= std::ios::binary;
return local_opt.release();
Index: include/osgDB/Registry
===================================================================
--- include/osgDB/Registry (revision 13338)
+++ include/osgDB/Registry (working copy)
@@ -68,6 +68,9 @@
* by the libdb_tiff readerwriter plugin.*/
void addFileExtensionAlias(const std::string mapExt, const std::string
toExt);
+ /** returns mapExt registered mapped alias or empty string. */
+ std::string getFileExtensionAlias(const std::string& mapExt) const;
+
/** Reads a file that configures extension mappings. File is ASCII text
* and each line contains the parameters to the addFileExtensionAlias
* method. Lines can be commented out with an initial '#' character.*/
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org