From 41924dfc14a154a60c88618064137b2c409a4268 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 13 Sep 2011 11:48:06 +0000 Subject: [PATCH] From Sukender, "I just fount that writing double precision values (eg. Vec3dArray for vertices) works with .osg but not .osgt/.osgx. So here is the fix (SVN trunk r12712). I suppose .osgb works as expected on this point and did not change anything. So, as for .osg, if you add "precision 16" (for instance) to the optionString, then you'll get double precision vertices written correctly. " --- src/osgPlugins/osg/AsciiStreamOperator.h | 8 ++++++-- src/osgPlugins/osg/ReaderWriterOSG2.cpp | 18 ++++++++++++++++-- src/osgPlugins/osg/XmlStreamOperator.h | 3 ++- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/osgPlugins/osg/AsciiStreamOperator.h b/src/osgPlugins/osg/AsciiStreamOperator.h index 091d497ae..9fca5768b 100644 --- a/src/osgPlugins/osg/AsciiStreamOperator.h +++ b/src/osgPlugins/osg/AsciiStreamOperator.h @@ -7,8 +7,12 @@ class AsciiOutputIterator : public osgDB::OutputIterator { public: - AsciiOutputIterator( std::ostream* ostream ) - : _readyForIndent(false), _indent(0) { _out = ostream; } + AsciiOutputIterator( std::ostream* ostream, int precision ) + : _readyForIndent(false), _indent(0) + { + _out = ostream; + if (precision>0) _out->precision(precision); + } virtual ~AsciiOutputIterator() {} diff --git a/src/osgPlugins/osg/ReaderWriterOSG2.cpp b/src/osgPlugins/osg/ReaderWriterOSG2.cpp index 41eb55cc8..9f20d07f3 100644 --- a/src/osgPlugins/osg/ReaderWriterOSG2.cpp +++ b/src/osgPlugins/osg/ReaderWriterOSG2.cpp @@ -71,15 +71,29 @@ InputIterator* readInputIterator( std::istream& fin, const Options* options ) OutputIterator* writeOutputIterator( std::ostream& fout, const Options* options ) { + // Read precision parameter, for text & XML formats + int precision(-1); + if ( options ) { + std::istringstream iss(options->getOptionString()); + std::string opt; + while (iss >> opt) + { + if(opt=="PRECISION" || opt=="precision") + { + iss >> precision; + } + } + } + if ( options && options->getOptionString().find("Ascii")!=std::string::npos ) { fout << std::string("#Ascii") << ' '; - return new AsciiOutputIterator(&fout); + return new AsciiOutputIterator(&fout, precision); } else if ( options && options->getOptionString().find("XML")!=std::string::npos ) { fout << std::string("") << std::endl; - return new XmlOutputIterator(&fout); + return new XmlOutputIterator(&fout, precision); } else { diff --git a/src/osgPlugins/osg/XmlStreamOperator.h b/src/osgPlugins/osg/XmlStreamOperator.h index c85d0a767..16fc4fe41 100644 --- a/src/osgPlugins/osg/XmlStreamOperator.h +++ b/src/osgPlugins/osg/XmlStreamOperator.h @@ -19,10 +19,11 @@ public: TEXT_LINE // A text line, e.g. recording array elements }; - XmlOutputIterator( std::ostream* ostream ) + XmlOutputIterator( std::ostream* ostream, int precision ) : _readLineType(FIRST_LINE), _prevReadLineType(FIRST_LINE), _hasSubProperty(false) { _out = ostream; + if (precision>0) _sstream.precision(precision); _root = new osgDB::XmlNode; _root->type = osgDB::XmlNode::GROUP; }