From 4aa7afedf36130898eab26742e8273735f1121fe Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 3 Mar 2004 13:27:21 +0000 Subject: [PATCH] Removed include where possible, replacing with istream or ostream and changing std::cout/cerr to osg::notify(). --- examples/osgconv/osgconv.cpp | 4 +- examples/osgpagedlod/osgpagedlod.cpp | 2 + examples/osgunittests/osgunittests.cpp | 1 + include/osg/AnimationPath | 1 + include/osg/ApplicationUsage | 2 +- include/osg/ArgumentParser | 2 +- include/osg/Math | 4 - include/osg/Matrixd | 2 +- include/osg/Matrixf | 2 +- include/osg/Notify | 2 +- include/osg/UByte4 | 2 +- include/osg/UnitTestFramework | 411 ++++++++--------- include/osg/Vec2 | 2 +- include/osg/Vec3 | 2 +- include/osg/Vec4 | 2 +- include/osgDB/FieldReader | 2 +- src/osg/CullingSet.cpp | 12 - src/osg/Image.cpp | 2 - src/osg/Notify.cpp | 1 + src/osg/PagedLOD.cpp | 9 +- src/osg/ShapeDrawable.cpp | 8 +- src/osg/UnitTestFramework.cpp | 2 +- src/osgGL2/UniformValue.cpp | 15 + src/osgPlugins/3dc/ReaderWriter3DC.cpp | 5 +- src/osgPlugins/ac3d/ac3d.cpp | 2 +- src/osgPlugins/freetype/FreeTypeFont.cpp | 2 +- src/osgPlugins/freetype/FreeTypeLibrary.cpp | 12 +- src/osgPlugins/geo/ReaderWriterGEO.cpp | 486 ++++++++++---------- src/osgPlugins/lib3ds/ReaderWriter3DS.cpp | 16 +- src/osgPlugins/logo/ReaderWriterLOGO.cpp | 2 +- src/osgPlugins/txp/TXPParser.cpp | 371 ++++++++------- src/osgText/Font.cpp | 12 +- src/osgUtil/CullVisitor.cpp | 9 +- 33 files changed, 705 insertions(+), 704 deletions(-) diff --git a/examples/osgconv/osgconv.cpp b/examples/osgconv/osgconv.cpp index 9a73dbda7..d0e8b5306 100644 --- a/examples/osgconv/osgconv.cpp +++ b/examples/osgconv/osgconv.cpp @@ -39,12 +39,12 @@ public: osg::Geometry* geom = geoset->convertToGeometry(); if (geom) { - std::cout<<"Successfully converted GeoSet to Geometry"< +#include + osg::Geode* createTile(const osg::Vec3& lb, const osg::Vec3& rb, const osg::Vec3& lt, const osg::Vec3& rt, const std::string& imageFile) diff --git a/examples/osgunittests/osgunittests.cpp b/examples/osgunittests/osgunittests.cpp index d7ad5886d..61b6065dd 100644 --- a/examples/osgunittests/osgunittests.cpp +++ b/examples/osgunittests/osgunittests.cpp @@ -4,6 +4,7 @@ #include +#include void testFrustum(double left,double right,double bottom,double top,double zNear,double zFar) { diff --git a/include/osg/AnimationPath b/include/osg/AnimationPath index 24e21d24f..537a2da14 100644 --- a/include/osg/AnimationPath +++ b/include/osg/AnimationPath @@ -20,6 +20,7 @@ #include #include +#include #include namespace osg { diff --git a/include/osg/ApplicationUsage b/include/osg/ApplicationUsage index a6dd48f7c..65fb6b46d 100644 --- a/include/osg/ApplicationUsage +++ b/include/osg/ApplicationUsage @@ -18,7 +18,7 @@ #include #include -#include +#include namespace osg { diff --git a/include/osg/ArgumentParser b/include/osg/ArgumentParser index 548395a77..4aba26e7c 100644 --- a/include/osg/ArgumentParser +++ b/include/osg/ArgumentParser @@ -18,7 +18,7 @@ #include #include -#include +#include namespace osg { diff --git a/include/osg/Math b/include/osg/Math index 60f74907f..0252b6cd2 100644 --- a/include/osg/Math +++ b/include/osg/Math @@ -16,10 +16,6 @@ #include -#if defined(__GNUC__) && defined(WIN32) -# include -#endif - // for OSX users : // comment in if you want backwards compatibility with 10.1.x versions // otherwise you'll have problems with missing floorf and __isnan*() diff --git a/include/osg/Matrixd b/include/osg/Matrixd index 5d059826a..d1c099acf 100644 --- a/include/osg/Matrixd +++ b/include/osg/Matrixd @@ -21,7 +21,7 @@ #include -#include +#include #include namespace osg { diff --git a/include/osg/Matrixf b/include/osg/Matrixf index 370b98ede..5796f3323 100644 --- a/include/osg/Matrixf +++ b/include/osg/Matrixf @@ -21,7 +21,7 @@ #include -#include +#include #include namespace osg { diff --git a/include/osg/Notify b/include/osg/Notify index b1dc44df3..d86475288 100644 --- a/include/osg/Notify +++ b/include/osg/Notify @@ -16,7 +16,7 @@ #include -#include +#include #include #include diff --git a/include/osg/UByte4 b/include/osg/UByte4 index 9cb953529..a93f015dd 100644 --- a/include/osg/UByte4 +++ b/include/osg/UByte4 @@ -16,7 +16,7 @@ #include -#include +#include namespace osg { diff --git a/include/osg/UnitTestFramework b/include/osg/UnitTestFramework index de3615e30..44bcdd6b4 100644 --- a/include/osg/UnitTestFramework +++ b/include/osg/UnitTestFramework @@ -18,12 +18,13 @@ #include #include #include +#include #include #include #include #include -#include +#include namespace osgUtx{ @@ -39,19 +40,19 @@ class SG_EXPORT Test: public osg::Referenced { public: - typedef TestVisitor Visitor; // Test is redundant + typedef TestVisitor Visitor; // Test is redundant - Test( const std::string& sName ) : _name( sName ) {} + Test( const std::string& sName ) : _name( sName ) {} - const std::string& name() const { return _name; } + const std::string& name() const { return _name; } - virtual bool accept( Visitor& ) = 0; + virtual bool accept( Visitor& ) = 0; protected: virtual ~Test() {} - std::string _name; + std::string _name; }; @@ -66,50 +67,50 @@ class SG_EXPORT TestContext { public: - TestContext(); + TestContext(); - bool shouldStop() { return false; } - bool isVerbose() { return true; } + bool shouldStop() { return false; } + bool isVerbose() { return true; } - enum TraceLevel{ - Off, ///< All tracing turned off - Results, ///< Output results only - Full ///< Full test diagnostic output - }; + enum TraceLevel{ + Off, ///< All tracing turned off + Results, ///< Output results only + Full ///< Full test diagnostic output + }; - void setTraceLevel(TraceLevel tl); - TraceLevel getTraceLevel() const; + void setTraceLevel(TraceLevel tl); + TraceLevel getTraceLevel() const; - std::ostream& tout(TraceLevel tl=Full) const; + std::ostream& tout(TraceLevel tl=Full) const; private: - TestContext(const TestContext&); - TestContext operator=(const TestContext&); + TestContext(const TestContext&); + TestContext operator=(const TestContext&); #ifndef DOXYGEN_SHOULD_SKIP_THIS - class SG_EXPORT TraceStream{ + class SG_EXPORT TraceStream{ - public: - TraceStream(std::ostream& o=std::cout, TraceLevel tl=Results); - ~TraceStream(); + public: + TraceStream(std::ostream& o=osg::notify(osg::NOTICE), TraceLevel tl=Results); + ~TraceStream(); - void setTraceLevel(TraceLevel tl); - TraceLevel getTraceLevel() const; + void setTraceLevel(TraceLevel tl); + TraceLevel getTraceLevel() const; - std::ostream& stream(TraceLevel tl); + std::ostream& stream(TraceLevel tl); - private: + private: - TraceLevel _traceLevel; - std::ostream* _outputStreamPtr; - std::ofstream _nullStream; - }; + TraceLevel _traceLevel; + std::ostream* _outputStreamPtr; + std::ofstream _nullStream; + }; #endif /* DOXYGEN_SHOULD_SKIP_THIS */ - mutable TraceStream _tout; + mutable TraceStream _tout; }; @@ -125,20 +126,20 @@ class TestVisitor { public: - //..Should we enter this node and its children? - virtual bool visitEnter( TestSuite* ) { return true; } + //..Should we enter this node and its children? + virtual bool visitEnter( TestSuite* ) { return true; } - //..Returns true to continue to next Leaf - virtual bool visit( TestCase* ) = 0; + //..Returns true to continue to next Leaf + virtual bool visit( TestCase* ) = 0; - //..Returns true to continue to next Composite - virtual bool visitLeave( TestSuite* ) { return true; } + //..Returns true to continue to next Composite + virtual bool visitLeave( TestSuite* ) { return true; } protected: - TestVisitor() {} - TestVisitor( const TestVisitor& ) {} - virtual ~TestVisitor() {} + TestVisitor() {} + TestVisitor( const TestVisitor& ) {} + virtual ~TestVisitor() {} }; /** @@ -149,13 +150,13 @@ class TestCase : public Test { public: - typedef TestContext Context; // Test in TestContext? is redundant + typedef TestContext Context; // Test in TestContext? is redundant - TestCase( const std::string& sName ) : Test( sName ) {} + TestCase( const std::string& sName ) : Test( sName ) {} - virtual bool accept( Visitor& v ) { return v.visit( this ); } + virtual bool accept( Visitor& v ) { return v.visit( this ); } - virtual void run( const Context& ) = 0; // Subclass OSGUTX_EXPORT Responsibility + virtual void run( const Context& ) = 0; // Subclass OSGUTX_EXPORT Responsibility protected: @@ -170,13 +171,13 @@ class TestX { public: - TestX(const std::string& s):_what(s) {} - virtual ~TestX() {} + TestX(const std::string& s):_what(s) {} + virtual ~TestX() {} - const std::string& what() const { return _what; } + const std::string& what() const { return _what; } private: - std::string _what; + std::string _what; }; /** @@ -185,7 +186,7 @@ A TestFailureX indicates a failure in the tested component. class TestFailureX: public TestX { public: - TestFailureX(const std::string& s):TestX(s) {} + TestFailureX(const std::string& s):TestX(s) {} }; /** @@ -197,7 +198,7 @@ run which prevents the component from being tested. class TestErrorX: public TestX { public: - TestErrorX(const std::string& s):TestX(s) {} + TestErrorX(const std::string& s):TestX(s) {} }; /** @@ -211,28 +212,28 @@ of information from one test case to the next. template< typename FixtureT > class TestCase_ : public TestCase { - typedef void (FixtureT::*TestMethodPtr)( const Context& ); + typedef void (FixtureT::*TestMethodPtr)( const Context& ); public: - // Constructor adds the TestMethod pointer - TestCase_( const std::string& sName, TestMethodPtr pTestMethod ) : - TestCase( sName ), - _pTestMethod( pTestMethod ) - { - } + // Constructor adds the TestMethod pointer + TestCase_( const std::string& sName, TestMethodPtr pTestMethod ) : + TestCase( sName ), + _pTestMethod( pTestMethod ) + { + } - // Create a TestFixture instance and invoke TestMethod? - virtual void run( const Context& ctx ) - { - ( FixtureT().*_pTestMethod )( ctx ); - } + // Create a TestFixture instance and invoke TestMethod? + virtual void run( const Context& ctx ) + { + ( FixtureT().*_pTestMethod )( ctx ); + } protected: virtual ~TestCase_() {} - TestMethodPtr _pTestMethod; + TestMethodPtr _pTestMethod; }; /** @@ -243,24 +244,24 @@ class SG_EXPORT TestSuite : public Test { public: - TestSuite( const std::string& name ); + TestSuite( const std::string& name ); - /** Adds a Test to the suite. */ - void add( Test* pTest ); + /** Adds a Test to the suite. */ + void add( Test* pTest ); - /** - @returns The immediate child denoted by name, or 0 if not found. - */ - Test* findChild(const std::string& name); + /** + @returns The immediate child denoted by name, or 0 if not found. + */ + Test* findChild(const std::string& name); - virtual bool accept( Test::Visitor& v ); + virtual bool accept( Test::Visitor& v ); protected: virtual ~TestSuite() {} - typedef std::vector< osg::ref_ptr > Tests; - Tests _tests; // Collection of Suites and/or Cases + typedef std::vector< osg::ref_ptr > Tests; + Tests _tests; // Collection of Suites and/or Cases }; /** @@ -272,54 +273,54 @@ class SG_EXPORT TestGraph public: - static TestGraph& instance(); + static TestGraph& instance(); - /** - @return a pointer to the root TestSuite. - */ - TestSuite* root(); + /** + @return a pointer to the root TestSuite. + */ + TestSuite* root(); - /** - A utility function for accessing an arbitrary quite by pathname, relative to - the suite 'tsuite' (defaults to root if null), and with the option of creating - the \em TestSuite designated by \em path, if it does not already exist. + /** + A utility function for accessing an arbitrary quite by pathname, relative to + the suite 'tsuite' (defaults to root if null), and with the option of creating + the \em TestSuite designated by \em path, if it does not already exist. - This method may return 0 if the suite either cannot be found (and createIfNecssary - is 0), or the first component of \em path is not the same as the name of the - TestSuite \em tsuite. + This method may return 0 if the suite either cannot be found (and createIfNecssary + is 0), or the first component of \em path is not the same as the name of the + TestSuite \em tsuite. - This was written to aid the auto-registration of tests at specific points in - the test tree, where the tests' AutoRegistrationAgents may be distributed across - several files, and cannot be guaranteed to run in a given order. E.g. You cannot - register a test "root.osg.MyTest" unless you know that the the suite "root.osg" - already exists. - + This was written to aid the auto-registration of tests at specific points in + the test tree, where the tests' AutoRegistrationAgents may be distributed across + several files, and cannot be guaranteed to run in a given order. E.g. You cannot + register a test "root.osg.MyTest" unless you know that the the suite "root.osg" + already exists. + - @param path The name of the TestSuite to return. - @param tsuite The suite to 'start from'. Path is relative to this - suite (defaults to root suite). - @param createIfNecessary Optionally create the TestSuite(s) denoted by path if - they do not exist. - */ - TestSuite* suite(const std::string& path, TestSuite* tsuite = 0,bool createIfNecessary = false); + @param path The name of the TestSuite to return. + @param tsuite The suite to 'start from'. Path is relative to this + suite (defaults to root suite). + @param createIfNecessary Optionally create the TestSuite(s) denoted by path if + they do not exist. + */ + TestSuite* suite(const std::string& path, TestSuite* tsuite = 0,bool createIfNecessary = false); private: - /** - Does the same job as the version of suite listed above, but the path - is passed in as components in a list, represented by the iterator parameters. - */ - TestSuite* suite( - std::list::iterator it, - std::list::iterator end, - TestSuite* tsuite, bool createIfNecessary); + /** + Does the same job as the version of suite listed above, but the path + is passed in as components in a list, represented by the iterator parameters. + */ + TestSuite* suite( + std::list::iterator it, + std::list::iterator end, + TestSuite* tsuite, bool createIfNecessary); - TestGraph(); + TestGraph(); - TestGraph(const TestGraph&); - TestGraph& operator=(const TestGraph&); + TestGraph(const TestGraph&); + TestGraph& operator=(const TestGraph&); - osg::ref_ptr root_; + osg::ref_ptr root_; }; @@ -330,22 +331,22 @@ current qualified TestSuite path. */ class SG_EXPORT TestQualifier : public TestVisitor { - enum { SEPCHAR = '.' }; + enum { SEPCHAR = '.' }; public: - // Entering a composite: Push its name on the Path - virtual bool visitEnter( TestSuite* pSuite ); + // Entering a composite: Push its name on the Path + virtual bool visitEnter( TestSuite* pSuite ); - // Leaving a composite: Pop its name from the Path - virtual bool visitLeave( TestSuite* pSuite ); + // Leaving a composite: Pop its name from the Path + virtual bool visitLeave( TestSuite* pSuite ); - // Provide read-only access to the current qualifier - const std::string& currentPath() const; + // Provide read-only access to the current qualifier + const std::string& currentPath() const; private: - std::string _path; // Current qualifier + std::string _path; // Current qualifier }; /** @@ -357,50 +358,50 @@ class SG_EXPORT QualifiedTestPrinter : public TestQualifier public: - virtual bool visit( TestCase* pTest ); + virtual bool visit( TestCase* pTest ); }; /** A TestRecord records the output of a given test case, i.e. its start/stop time, its result, and a textual description of any problems. -\todo Consider adding accessor methods if necessary, to get the details - stored in the TestRecord. +\todo Consider adding accessor methods if necessary, to get the details + stored in the TestRecord. */ class SG_EXPORT TestRecord { - public: + public: - void start(); - void stop(); - void log(const TestFailureX& e); - void log(const TestErrorX& e); - void log(const std::exception& e); - void log(const std::string& s); + void start(); + void stop(); + void log(const TestFailureX& e); + void log(const TestErrorX& e); + void log(const std::exception& e); + void log(const std::string& s); - // Default copy construction and assignment are OK + // Default copy construction and assignment are OK - // FIXME: Add accessors? + // FIXME: Add accessors? - private: + private: - // Onlye a TestReport can create a TestRecord - friend class TestReport; - TestRecord(const std::string& name); + // Onlye a TestReport can create a TestRecord + friend class TestReport; + TestRecord(const std::string& name); - enum Result{ - Success,Failure,Error - }; + enum Result{ + Success,Failure,Error + }; - friend std::ostream& operator<<(std::ostream& o,const TestRecord& tr); + friend std::ostream& operator<<(std::ostream& o,const TestRecord& tr); - static osg::Timer timer_; // To time tests + static osg::Timer timer_; // To time tests - std::string name_; - osg::Timer_t start_; - osg::Timer_t stop_; - Result result_; - std::string problem_; + std::string name_; + osg::Timer_t start_; + osg::Timer_t stop_; + Result result_; + std::string problem_; }; @@ -408,20 +409,20 @@ class SG_EXPORT TestRecord A TestReport represents the complete set of results (TestRecords) for a given test run. -\todo Add support for printing the test report in various formats: - e.g. text, XML, CSV +\todo Add support for printing the test report in various formats: + e.g. text, XML, CSV */ class SG_EXPORT TestReport { public: - TestRecord& createRecord(const std::string& s){ - _records.push_back(TestRecord(s)); - return _records.back(); - } + TestRecord& createRecord(const std::string& s){ + _records.push_back(TestRecord(s)); + return _records.back(); + } private: - std::list _records; + std::list _records; }; @@ -435,37 +436,37 @@ private: A TestRunner is a visitor which will run specified tests as it traverses the test graph. -\todo Consider an accessor method to get at the TestReport if necessary. +\todo Consider an accessor method to get at the TestReport if necessary. */ class SG_EXPORT TestRunner : public TestQualifier { public: - TestRunner( TestContext& ctx ); + TestRunner( TestContext& ctx ); - /** - Tests may be specified by partial names. E.g. specifiying "root" - will run all tests below root, i.e. all tests. - Specifiying "root.osg" will run all tests below \em root.osg. - Specifying "root.osg.de" will run all tests (and suites) below - \em root.osg with names beginning with the \em de. - */ - void specify( const std::string& sQualifiedName ); + /** + Tests may be specified by partial names. E.g. specifiying "root" + will run all tests below root, i.e. all tests. + Specifiying "root.osg" will run all tests below \em root.osg. + Specifying "root.osg.de" will run all tests (and suites) below + \em root.osg with names beginning with the \em de. + */ + void specify( const std::string& sQualifiedName ); - bool visitEnter( TestSuite* pSuite ); - bool visit( TestCase* pTest ); - bool visitLeave( TestSuite* pSuite ); + bool visitEnter( TestSuite* pSuite ); + bool visit( TestCase* pTest ); + bool visitLeave( TestSuite* pSuite ); protected: - void perform( TestCase* pTest ); + void perform( TestCase* pTest ); private: - TestReport _db; // Results - TestContext& _ctx; // The Global Testing Context - std::vector _tests; // Specified Tests + TestReport _db; // Results + TestContext& _ctx; // The Global Testing Context + std::vector _tests; // Specified Tests }; } @@ -475,11 +476,11 @@ Starts a TestSuite singleton function @see OSGUTX_ADD_TESTCASE, OSGUTX_END_TESTSUITE */ #define OSGUTX_BEGIN_TESTSUITE( tsuite ) \ - osgUtx::TestSuite* tsuite##_TestSuite() \ - { \ - static osg::ref_ptr s_suite = 0; \ - if ( s_suite == 0 ) { \ - s_suite = new osgUtx::TestSuite( #tsuite ); + osgUtx::TestSuite* tsuite##_TestSuite() \ + { \ + static osg::ref_ptr s_suite = 0; \ + if ( s_suite == 0 ) { \ + s_suite = new osgUtx::TestSuite( #tsuite ); @@ -488,21 +489,21 @@ Adds a test case to a suite object being created in a TestSuite singleton functi @see OSGUTX_BEGIN_TESTSUITE, OSGUTX_END_TESTSUITE */ #define OSGUTX_ADD_TESTCASE( tfixture, tmethod ) \ - s_suite->add( new osgUtx::TestCase_( \ - #tmethod, &tfixture::tmethod ) ); + s_suite->add( new osgUtx::TestCase_( \ + #tmethod, &tfixture::tmethod ) ); /** Ends a TestSuite singleton function @see OSGUTX_BEGIN_TESTSUITE, OSGUTX_ADD_TESTCASE */ #define OSGUTX_END_TESTSUITE \ - } \ - return s_suite.get(); \ - } + } \ + return s_suite.get(); \ + } /** Define a TestSuite accessor */ #define OSGUTX_TESTSUITE( tsuite ) \ - tsuite##_TestSuite() + tsuite##_TestSuite() /** @@ -510,16 +511,16 @@ Adds a suite to a suite - allows composition of test suites. @see OSGUTX_BEGIN_TESTSUITE, OSGUTX_END_TESTSUITE */ #define OSGUTX_ADD_TESTSUITE( childSuite ) \ - s_suite->add( childSuite##_TestSuite() ); + s_suite->add( childSuite##_TestSuite() ); /** Autoregister a testsuite with the root suite at startup */ #define OSGUTX_AUTOREGISTER_TESTSUITE( tsuite ) \ - static osgUtx::TestSuiteAutoRegistrationAgent tsuite##_autoRegistrationObj__( tsuite##_TestSuite() ); + static osgUtx::TestSuiteAutoRegistrationAgent tsuite##_autoRegistrationObj__( tsuite##_TestSuite() ); /** Auto register a testsuite with at designated point in the suite graph at startup */ #define OSGUTX_AUTOREGISTER_TESTSUITE_AT( tsuite , path ) \ - static osgUtx::TestSuiteAutoRegistrationAgent tsuite##_autoRegistrationObj__( tsuite##_TestSuite(), #path ); + static osgUtx::TestSuiteAutoRegistrationAgent tsuite##_autoRegistrationObj__( tsuite##_TestSuite(), #path ); namespace osgUtx{ @@ -531,21 +532,21 @@ direct use, it should be used via the following macros. (It's a secret agent :-) */ struct TestSuiteAutoRegistrationAgent { - TestSuiteAutoRegistrationAgent(TestSuite* tsuite, const char* path = 0) - { - if( ! path ) path = "root"; + TestSuiteAutoRegistrationAgent(TestSuite* tsuite, const char* path = 0) + { + if( ! path ) path = "root"; - // Find the suite named in 'path', create it if necessary - TestSuite *regSuite = osgUtx::TestGraph::instance().suite( path, 0, true ); + // Find the suite named in 'path', create it if necessary + TestSuite *regSuite = osgUtx::TestGraph::instance().suite( path, 0, true ); - if(!regSuite){ - std::cerr<<"Warning, unable to register test suite named \""<name()<<"\" at " - <name()<<"\" at " + <add(tsuite); - } + regSuite->add(tsuite); + } }; } @@ -560,11 +561,11 @@ The exception will indicate the file and line number of the failed expression, along with expression itself. */ #define OSGUTX_TEST_F( expr ) \ - if( !(expr) ){ \ - std::stringstream ss; \ - ss<< #expr <<" failure: "<<__FILE__<<", line "<<__LINE__< -#include +#include namespace osg { diff --git a/include/osg/Vec3 b/include/osg/Vec3 index 6d6701b9f..79bdc914d 100644 --- a/include/osg/Vec3 +++ b/include/osg/Vec3 @@ -16,7 +16,7 @@ #include -#include +#include namespace osg { diff --git a/include/osg/Vec4 b/include/osg/Vec4 index ea37ebb3a..70f4e40fb 100644 --- a/include/osg/Vec4 +++ b/include/osg/Vec4 @@ -16,7 +16,7 @@ #include -#include +#include namespace osg { diff --git a/include/osgDB/FieldReader b/include/osgDB/FieldReader index dfffe8551..8769dd5d2 100644 --- a/include/osgDB/FieldReader +++ b/include/osgDB/FieldReader @@ -19,7 +19,7 @@ #include #include -#include +#include namespace osgDB { diff --git a/src/osg/CullingSet.cpp b/src/osg/CullingSet.cpp index 677a28964..44ca9599f 100644 --- a/src/osg/CullingSet.cpp +++ b/src/osg/CullingSet.cpp @@ -25,20 +25,8 @@ CullingSet::~CullingSet() { } -void PrintNodePath(const NodePath& nodePath) -{ - for(NodePath::const_iterator itr=nodePath.begin(); - itr!=nodePath.end(); - ++itr) - { - std::cout<<*itr<<" "; - } -} - - void CullingSet::disableAndPushOccludersCurrentMask(NodePath& nodePath) { - //std::cout<<" trying to disable occluder ";PrintNodePath(nodePath);std::cout<accept(nv); lastChildTraversed = (int)i; } @@ -79,11 +78,9 @@ void PagedLOD::traverse(NodeVisitor& nv) { unsigned int numChildren = _children.size(); - //std::cout<<"PagedLOD::traverse() - falling back "<0 && ((int)numChildren-1)!=lastChildTraversed) { - //std::cout<<" to child "<accept(nv); } @@ -97,7 +94,6 @@ void PagedLOD::traverse(NodeVisitor& nv) // modify the priority according to the child's priority offset and scale. priority = _perRangeDataList[numChildren]._priorityOffset + priority * _perRangeDataList[numChildren]._priorityScale; - //std::cout<<" requesting child "<<_fileNameList[numChildren]<<" priotity = "<requestNodeFile(_perRangeDataList[numChildren]._filename,this,priority,nv.getFrameStamp()); } @@ -131,25 +127,21 @@ bool PagedLOD::computeBound() const void PagedLOD::childRemoved(unsigned int pos, unsigned int numChildrenToRemove) { LOD::childRemoved(pos, numChildrenToRemove); - //std::cout<<"PagedLOD::childRemoved("<name() << std::endl; + osg::notify(osg::NOTICE) << currentPath() + pTest->name() << std::endl; return true; } diff --git a/src/osgGL2/UniformValue.cpp b/src/osgGL2/UniformValue.cpp index c1bde3f7d..ef72c6da0 100644 --- a/src/osgGL2/UniformValue.cpp +++ b/src/osgGL2/UniformValue.cpp @@ -38,6 +38,9 @@ int UniformValue::getLocation( Extensions *ext, const GLhandleARB progObj ) cons /////////////////////////////////////////////////////////////////////////// +#ifdef sgi +template <> +#endif void UniformValue_int::apply( Extensions *ext, const GLhandleARB progObj ) const { int loc = getLocation( ext, progObj ); @@ -47,6 +50,9 @@ void UniformValue_int::apply( Extensions *ext, const GLhandleARB progObj ) const } } +#ifdef sgi +template <> +#endif void UniformValue_float::apply( Extensions *ext, const GLhandleARB progObj ) const { int loc = getLocation( ext, progObj ); @@ -56,6 +62,9 @@ void UniformValue_float::apply( Extensions *ext, const GLhandleARB progObj ) con } } +#ifdef sgi +template <> +#endif void UniformValue_Vec2::apply( Extensions *ext, const GLhandleARB progObj ) const { int loc = getLocation( ext, progObj ); @@ -65,6 +74,9 @@ void UniformValue_Vec2::apply( Extensions *ext, const GLhandleARB progObj ) cons } } +#ifdef sgi +template <> +#endif void UniformValue_Vec3::apply( Extensions *ext, const GLhandleARB progObj ) const { int loc = getLocation( ext, progObj ); @@ -74,6 +86,9 @@ void UniformValue_Vec3::apply( Extensions *ext, const GLhandleARB progObj ) cons } } +#ifdef sgi +template <> +#endif void UniformValue_Vec4::apply( Extensions *ext, const GLhandleARB progObj ) const { int loc = getLocation( ext, progObj ); diff --git a/src/osgPlugins/3dc/ReaderWriter3DC.cpp b/src/osgPlugins/3dc/ReaderWriter3DC.cpp index f409b395e..b19d005f6 100644 --- a/src/osgPlugins/3dc/ReaderWriter3DC.cpp +++ b/src/osgPlugins/3dc/ReaderWriter3DC.cpp @@ -45,15 +45,12 @@ class ReaderWriter3DC : public osgDB::ReaderWriter if (line[0]=='#') { // comment line - std::cout <<"Comment: "<(&node)) // const_cast(static_cast(&node))->Process(fout); else - std::cout<<"File must start with a geode "< FreeTypeLibrary::FreeTypeLibrary() { FT_Error error = FT_Init_FreeType( &_ftlibrary ); if (error) { - std::cout<<"Warning: an error occured during FT_Init_FreeType(..) initialisation .. "<getField(GEO_DB_POLY_SHADEMODEL); // shaded gouraud, flat... - int shademodel=gfshade ? gfshade->getInt() : -1; - if (shademodel==GEO_POLY_SHADEMODEL_LIT) { // flat shaded - need the index - const geoField *gfd=gface->getField(GEO_DB_POLY_NORMAL); - if (gfd) { - float *normal= (gfd) ? (gfd->getVec3Arr()):NULL; - osg::Vec3 nrm(normal[0], normal[1], normal[2]); - norms->push_back(nrm); - isflat=true; - } - } - return isflat; + int shademodel=gfshade ? gfshade->getInt() : -1; + if (shademodel==GEO_POLY_SHADEMODEL_LIT) { // flat shaded - need the index + const geoField *gfd=gface->getField(GEO_DB_POLY_NORMAL); + if (gfd) { + float *normal= (gfd) ? (gfd->getVec3Arr()):NULL; + osg::Vec3 nrm(normal[0], normal[1], normal[2]); + norms->push_back(nrm); + isflat=true; + } + } + return isflat; } bool addIndices(georecord *gr, const geoHeaderGeo *ghdr, const float cdef[4], const georecord *gface) { // this must only be called with a vertex georecord. @@ -203,38 +203,38 @@ public: const geoField *gfshade=gface->getField(GEO_DB_POLY_SHADEMODEL); // shaded gouraud, flat... int shademodel=gfshade ? gfshade->getInt() : -1; if (shademodel!=GEO_POLY_SHADEMODEL_LIT && shademodel!=GEO_POLY_SHADEMODEL_FLAT) { - const geoField *gfd=gr->getField(GEO_DB_VRTX_NORMAL); - if (gfd->getType()==DB_UINT) { - if (gfd) { + const geoField *gfd=gr->getField(GEO_DB_VRTX_NORMAL); + if (gfd->getType()==DB_UINT) { + if (gfd) { unsigned int idx=gfd->getUInt(); - normindices->push_back(idx); - norms->push_back((*npool)[idx]); - } else { - osg::notify(osg::WARN) << "No valid vertex index" << std::endl; - } - } else if (gfd->getType()==DB_VEC3F) { - float *p=gfd->getVec3Arr(); - osg::Vec3 nrm; - nrm.set(p[0],p[1],p[2]); - norms->push_back(nrm); - } - } + normindices->push_back(idx); + norms->push_back((*npool)[idx]); + } else { + osg::notify(osg::WARN) << "No valid vertex index" << std::endl; + } + } else if (gfd->getType()==DB_VEC3F) { + float *p=gfd->getVec3Arr(); + osg::Vec3 nrm; + nrm.set(p[0],p[1],p[2]); + norms->push_back(nrm); + } + } const geoField *gfd=gr->getField(GEO_DB_VRTX_COORD); - osg::Vec3 pos; - if (gfd->getType()==DB_INT) { - if (gfd) { + osg::Vec3 pos; + if (gfd->getType()==DB_INT) { + if (gfd) { int idx=gfd->getInt(); - pos=(*cpool)[idx]; - coords->push_back((*cpool)[idx]); //osg::Vec3(cpool[3*idx],cpool[3*idx+1],cpool[3*idx+2])); - coordindices->push_back(coords->size()); - } else { - osg::notify(osg::WARN) << "No valid vertex index" << std::endl; - } - } else if (gfd->getType()==DB_VEC3F) { - float *p=gfd->getVec3Arr(); - pos.set(p[0],p[1],p[2]); - coords->push_back(pos); //osg::Vec3(cpool[3*idx],cpool[3*idx+1],cpool[3*idx+2])); - } + pos=(*cpool)[idx]; + coords->push_back((*cpool)[idx]); //osg::Vec3(cpool[3*idx],cpool[3*idx+1],cpool[3*idx+2])); + coordindices->push_back(coords->size()); + } else { + osg::notify(osg::WARN) << "No valid vertex index" << std::endl; + } + } else if (gfd->getType()==DB_VEC3F) { + float *p=gfd->getVec3Arr(); + pos.set(p[0],p[1],p[2]); + coords->push_back(pos); //osg::Vec3(cpool[3*idx],cpool[3*idx+1],cpool[3*idx+2])); + } std::vector< georecord *>bhv=gr->getBehaviour(); // behaviours for vertices, eg tranlate, colour! if (!bhv.empty()) { int ncoord=coords->size(); @@ -281,15 +281,15 @@ public: gfd=gr->getField(GEO_DB_VRTX_UV_SET_0); if (gfd) { uvc=(float *)gfd->getstore(0); - - if (uvc) { // then there are tx coords - osg::Vec2 uv(uvc[0], uvc[1]); - txcoords->push_back(uv); - } else { - txcoords->push_back(osg::Vec2(0,0)); - } - } else { - txcoords->push_back(osg::Vec2(0,0)); + + if (uvc) { // then there are tx coords + osg::Vec2 uv(uvc[0], uvc[1]); + txcoords->push_back(uv); + } else { + txcoords->push_back(osg::Vec2(0,0)); + } + } else { + txcoords->push_back(osg::Vec2(0,0)); } gfd=gr->getField(GEO_DB_VRTX_PACKED_COLOR); if (gfd) { @@ -365,8 +365,8 @@ public: void setPools(const std::vector *coord_pool, const std::vector *normal_pool) { vinf.setPools(coord_pool,normal_pool); } - float getlinewidth(void) const { return linewidth;} - void setlineWidth(const int w) { linewidth=w;} + float getlinewidth(void) const { return linewidth;} + void setlineWidth(const int w) { linewidth=w;} void setGeom(osg::Geometry *nugeom) { geom=nugeom;} osg::Geometry *getGeom() { return geom.get();} uint getStart(uint nv) { uint ns=nstart; nstart+=nv; return ns; } @@ -381,10 +381,10 @@ private: int texture; // texture index int bothsides; // none, back,front int shademodel; - int linewidth; + int linewidth; vertexInfo vinf; uint nstart; // start vertex for a primitive - osg::ref_ptr geom; // the geometry created for this vinf and texture + osg::ref_ptr geom; // the geometry created for this vinf and texture }; @@ -422,7 +422,7 @@ class ReaderWriterGEO : public osgDB::ReaderWriter { georecord gr; gr.readfile(fin); -// osg::notify(osg::WARN) << "end of record " << (int)gr.getType() << std::endl; +// osg::notify(osg::WARN) << "end of record " << (int)gr.getType() << std::endl; if (gr.getType() == DB_DSK_NORMAL_POOL) { geoField *gfff=gr.getModField(GEO_DB_NORMAL_POOL_VALUES); gfff->uncompress();// uncompress the normals @@ -440,7 +440,7 @@ class ReaderWriterGEO : public osgDB::ReaderWriter output(fout,sorted); fout.close(); #endif /**/ - makeHeader(*(sorted.begin())); + makeHeader(*(sorted.begin())); nodeList=makeosg(sorted); // make a list of osg nodes geotxlist.clear(); @@ -450,7 +450,7 @@ class ReaderWriterGEO : public osgDB::ReaderWriter matlist.clear();/* */ coord_pool.clear(); normal_pool.clear(); - osg::Node * groupnode = NULL; + osg::Node * groupnode = NULL; if (nodeList.empty()) { return ReadResult("No data loaded from "+fileName); @@ -461,7 +461,7 @@ class ReaderWriterGEO : public osgDB::ReaderWriter } else { - osg::Group *group = new Group; + osg::Group *group = new Group; group->setName("import group"); for(NodeList::iterator itr=nodeList.begin(); itr!=nodeList.end(); @@ -469,12 +469,12 @@ class ReaderWriterGEO : public osgDB::ReaderWriter { group->addChild(*itr); } - groupnode=group; + groupnode=group; } - (theHeader.get())->addChild(groupnode); - groupnode=theHeader.get(); + (theHeader.get())->addChild(groupnode); + groupnode=theHeader.get(); #ifdef _DEBUG // output a .osg version - osgDB::writeNodeFile(*groupnode,"geoosg.osg"); + osgDB::writeNodeFile(*groupnode,"geoosg.osg"); #endif /**/ recs.clear(); return groupnode; @@ -496,8 +496,8 @@ class ReaderWriterGEO : public osgDB::ReaderWriter case 101: // old header - not appropriate! curparent= &(*itr); sorted.push_back(&(*itr)); - osg::notify(osg::WARN) << "Old version 2 header block found - possible error!" << std::endl; - break; + osg::notify(osg::WARN) << "Old version 2 header block found - possible error!" << std::endl; + break; case DB_DSK_PUSH: if (!(curparent->getchildren().empty())) { curparent= curparent->getLastChild(); // itr-1; @@ -511,7 +511,7 @@ class ReaderWriterGEO : public osgDB::ReaderWriter case DB_DSK_HEADER: // attach to previous curparent= &(*itr); sorted.push_back(&(*itr)); - cpalrec=NULL; + cpalrec=NULL; break; case DB_DSK_INTERNAL_VARS: // attach to parent case DB_DSK_LOCAL_VARS: @@ -586,12 +586,12 @@ class ReaderWriterGEO : public osgDB::ReaderWriter case DB_DSK_IF_THEN_ELSE_ACTION: case DB_DSK_DCS_ACTION: case DB_DSK_SQRT_ACTION: // an action - if (curparent->getType()==DB_DSK_HEADER) - curparent->addBehaviourRecord(&(*itr)); - else { - class georecord *cp=curparent->getLastChild(); - if (cp) cp->addBehaviourRecord(&(*itr)); - } + if (curparent->getType()==DB_DSK_HEADER) + curparent->addBehaviourRecord(&(*itr)); + else { + class georecord *cp=curparent->getLastChild(); + if (cp) cp->addBehaviourRecord(&(*itr)); + } break; case DB_DSK_PERSPECTIVE_GRID_INFO: // Feb 2003 not sure what this is yet! (curparent)->addchild(&(*itr)); @@ -649,7 +649,7 @@ class ReaderWriterGEO : public osgDB::ReaderWriter const vertexInfo *vinf=ginf.getVinf(); nug->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); nug->setVertexArray(vinf->getCoords()); - StateSet *dstate=new StateSet; + StateSet *dstate=new StateSet; if (bothsides==0) { osg::CullFace *cf = new osg::CullFace; // to define non-default culling cf->setMode(osg::CullFace::BACK); @@ -710,20 +710,20 @@ class ReaderWriterGEO : public osgDB::ReaderWriter nug->setColorBinding(osg::Geometry::BIND_PER_VERTEX); } } else { - if (shademodel==GEO_POLY_SHADEMODEL_LIT_GOURAUD) { - nug->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); - } else if (shademodel==GEO_POLY_SHADEMODEL_LIT) { - nug->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE); - } - osg::Vec4Array *polycols=vinf->getPolcolours(); + if (shademodel==GEO_POLY_SHADEMODEL_LIT_GOURAUD) { + nug->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); + } else if (shademodel==GEO_POLY_SHADEMODEL_LIT) { + nug->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE); + } + osg::Vec4Array *polycols=vinf->getPolcolours(); nug->setColorArray(polycols); nug->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE); } } } - osg::LineWidth *lw=new osg::LineWidth; - lw->setWidth(ginf.getlinewidth()); - dstate->setAttributeAndModes(lw,osg::StateAttribute::ON); + osg::LineWidth *lw=new osg::LineWidth; + lw->setWidth(ginf.getlinewidth()); + dstate->setAttributeAndModes(lw,osg::StateAttribute::ON); nug->setStateSet( dstate ); ginf.setGeom(nug); return nug; @@ -754,11 +754,11 @@ class ReaderWriterGEO : public osgDB::ReaderWriter } if (gr.size()>0) { - vinf->addFlat(grec); // for flat normal shading + vinf->addFlat(grec); // for flat normal shading for (std::vector::const_iterator itr=gr.begin(); itr!=gr.end(); ++itr) { - vinf->addIndices((*itr), theHeader.get(), defcol, grec); + vinf->addIndices((*itr), theHeader.get(), defcol, grec); nv++; } } @@ -782,7 +782,7 @@ class ReaderWriterGEO : public osgDB::ReaderWriter osg::MatrixTransform *makeText(georecord *gr) { // make transform, geode & text osg::MatrixTransform *numt=NULL; std::string ttfPath("fonts/times.ttf"); - // unused + // unused //int gFontSize1=2; osgText::Text *text= new osgText::Text; text->setFont(ttfPath); @@ -823,7 +823,7 @@ class ReaderWriterGEO : public osgDB::ReaderWriter textState->setMode(GL_LIGHTING, osg::StateAttribute::OFF); geod->setStateSet( textState ); numt=new osg::MatrixTransform; - numt->setName(name); + numt->setName(name); gfd=gr->getField(GEO_DB_TEXT_MATRIX); if (gfd) { float *fmat=gfd->getMat44Arr(); @@ -899,18 +899,18 @@ class ReaderWriterGEO : public osgDB::ReaderWriter if ((*itr)->getType()==DB_DSK_VERTEX) { // light point vertices const geoField *gfd=(*itr)->getField(GEO_DB_VRTX_COORD); - osg::Vec3 pos; - if (gfd->getType()==DB_INT) { - if (gfd) { + osg::Vec3 pos; + if (gfd->getType()==DB_INT) { + if (gfd) { int idx=gfd->getInt(); - pos=coord_pool[idx]; - } else { - osg::notify(osg::WARN) << "No valid vertex index" << std::endl; - } - } else if (gfd->getType()==DB_VEC3F) { - float *p=gfd->getVec3Arr(); - pos.set(p[0],p[1],p[2]); - } + pos=coord_pool[idx]; + } else { + osg::notify(osg::WARN) << "No valid vertex index" << std::endl; + } + } else if (gfd->getType()==DB_VEC3F) { + float *p=gfd->getVec3Arr(); + pos.set(p[0],p[1],p[2]); + } gfd=(*itr)->getField(GEO_DB_VRTX_PACKED_COLOR); if (gfd) { unsigned char *cls=gfd->getUCh4Arr(); @@ -949,16 +949,16 @@ class ReaderWriterGEO : public osgDB::ReaderWriter int makeAnimatedGeometry(const georecord grec, const int imat,Group *nug) { // animated polygons - create a matrix & geode & poly & add to group nug const std::vector gr=grec.getchildren(); - int nanimations=0; + int nanimations=0; const geoField *gfd=grec.getField(GEO_DB_RENDERGROUP_CULLING); // back, front, none - unsigned int bothsides=gfd ? gfd->getUInt() : 0; + unsigned int bothsides=gfd ? gfd->getUInt() : 0; // int bothsides =allOneSided(&grec); for (std::vector::const_iterator itr=gr.begin(); itr!=gr.end(); ++itr) { std::vector< georecord *>bhv=(*itr)->getBehaviour(); // behaviours attached to facets, eg colour! if ((*itr)->getType()==DB_DSK_POLYGON && !bhv.empty()) { // animated facets go here - nanimations++; + nanimations++; if (hasMotionAction(bhv)) { // make matrix if motion needed. const geoField *gfd=(*itr)->getField(GEO_DB_POLY_TEX0); int txidx= gfd ? gfd->getInt() : -1; @@ -1064,11 +1064,11 @@ class ReaderWriterGEO : public osgDB::ReaderWriter int shademodel=gfd ? gfd->getInt() : GEO_POLY_SHADEMODEL_LIT_GOURAUD; geoInfo gi(txidx,shademodel, bothsides); gi.setPools(&coord_pool, &normal_pool); - gfd=grec->getField(GEO_DB_POLY_LINE_WIDTH); // integer line width... - if (gfd) { - int w=gfd->getInt(); - gi.setlineWidth(w); - } + gfd=grec->getField(GEO_DB_POLY_LINE_WIDTH); // integer line width... + if (gfd) { + int w=gfd->getInt(); + gi.setlineWidth(w); + } osg::Geometry *nugeom=makeNewGeometry(grec, gi, imat); nug->addDrawable(nugeom); igeom=ia->size(); @@ -1083,7 +1083,7 @@ class ReaderWriterGEO : public osgDB::ReaderWriter if (gr.size()>0) { std::vector ia; // list of texture indices & vinfo found in this geode; sort into new const geoField *gfd=grec.getField(GEO_DB_RENDERGROUP_CULLING); // back, front, none - unsigned int bothsides=gfd ? gfd->getUInt() : 0; + unsigned int bothsides=gfd ? gfd->getUInt() : 0; // vertexInfo vinf(&coord_pool, &normal_pool); // holds all types of coords, indices etc // bool bothsides=allOneSided(&grec); for (std::vector::const_iterator itr=gr.begin(); @@ -1121,15 +1121,15 @@ class ReaderWriterGEO : public osgDB::ReaderWriter } } int nv=getprim((*itr), *gi); - { - const vertexInfo *vinf=gi->getVinf(); - if (vinf->getNorms() && vinf->getNorms()->size()>0) { - gi->getGeom()->setNormalArray(vinf->getNorms()); - gi->getGeom()->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); - } else { - gi->getGeom()->setNormalBinding(osg::Geometry::BIND_OFF); - } - } + { + const vertexInfo *vinf=gi->getVinf(); + if (vinf->getNorms() && vinf->getNorms()->size()>0) { + gi->getGeom()->setNormalArray(vinf->getNorms()); + gi->getGeom()->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); + } else { + gi->getGeom()->setNormalBinding(osg::Geometry::BIND_OFF); + } + } if (hasColorAction(bhv)) addPolyActions(bhv, *gi, nv); if (dstyle==GEO_POLY_DSTYLE_SOLID_BOTH_SIDES || dstyle == GEO_POLY_DSTYLE_SOLID) { @@ -1189,7 +1189,7 @@ class ReaderWriterGEO : public osgDB::ReaderWriter Group *makeTextGeode(const georecord *gr) { // in geo text is defined with a matrix included in the geo.geode (gr is this geo.geode) // - we need to create this tree to render text - return NULL; // temporary disable april 2003 + return NULL; // temporary disable april 2003 Group *nug=new Group; const geoField *gfd=gr->getField(GEO_DB_RENDERGROUP_MAT); // may be used in future const unsigned int imat=gfd ? gfd->getInt():0; @@ -1251,7 +1251,7 @@ class ReaderWriterGEO : public osgDB::ReaderWriter const unsigned int imat=gfd ? gfd->getInt():0; gfd=gr.getField(GEO_DB_RENDERGROUP_BILLBOARD); bool isbillb = gfd ? gfd->getBool() : false; - osg::Geode *nug; + osg::Geode *nug; if (isbillb) { Billboard *bilb= new Billboard ; bilb->setAxis(Vec3(0,0,1)); @@ -1261,15 +1261,15 @@ class ReaderWriterGEO : public osgDB::ReaderWriter nug=new Geode; } int nchild=makeGeometry(gr,imat,nug); - if (nchild>0) { // complete the geode - gfd=gr.getField(GEO_DB_NODE_NAME); - if (gfd) { - nug->setName(gfd->getChar()); - } - return nug; - } else { - return NULL; - } + if (nchild>0) { // complete the geode + gfd=gr.getField(GEO_DB_NODE_NAME); + if (gfd) { + nug->setName(gfd->getChar()); + } + return nug; + } else { + return NULL; + } } osg::Group *makePage(const georecord *gr) { @@ -1280,11 +1280,11 @@ class ReaderWriterGEO : public osgDB::ReaderWriter } return gp; } - osg::Group *setmatrix(const georecord *gr) { // find one of the types of matrix supported + osg::Group *setmatrix(const georecord *gr) { // find one of the types of matrix supported const geoField *gfd=gr->getField(GEO_DB_GRP_MATRIX_TRANSFORM); - if (!gfd) gfd=gr->getField(GEO_DB_GRP_TRANSLATE_TRANSFORM); - if (!gfd) gfd=gr->getField(GEO_DB_GRP_ROTATE_TRANSFORM); - if (!gfd) gfd=gr->getField(GEO_DB_GRP_SCALE_TRANSFORM); + if (!gfd) gfd=gr->getField(GEO_DB_GRP_TRANSLATE_TRANSFORM); + if (!gfd) gfd=gr->getField(GEO_DB_GRP_ROTATE_TRANSFORM); + if (!gfd) gfd=gr->getField(GEO_DB_GRP_SCALE_TRANSFORM); if (gfd) { MatrixTransform *tr=new MatrixTransform; osg::Matrix mx; @@ -1295,7 +1295,7 @@ class ReaderWriterGEO : public osgDB::ReaderWriter } else { return NULL; } - } + } osg::Group *makeGroup(const georecord *gr) { // group or Static transform osg::Group *gp=setmatrix(gr); if (!gp) { @@ -1359,41 +1359,41 @@ class ReaderWriterGEO : public osgDB::ReaderWriter } return gp; } - osg::Drawable* createClipSurface(float xMin,float xMax,float yMin,float yMax,float z) - { // set up the Geometry that defines the clipped region. - osg::Geometry* geom = new osg::Geometry; - - osg::Vec3Array* coords = new osg::Vec3Array(4); - (*coords)[0].set(xMin,yMax,z); - (*coords)[1].set(xMin,yMin,z); - (*coords)[2].set(xMax,yMin,z); - (*coords)[3].set(xMax,yMax,z); - geom->setVertexArray(coords); - - geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); - - return geom; - } + osg::Drawable* createClipSurface(float xMin,float xMax,float yMin,float yMax,float z) + { // set up the Geometry that defines the clipped region. + osg::Geometry* geom = new osg::Geometry; + + osg::Vec3Array* coords = new osg::Vec3Array(4); + (*coords)[0].set(xMin,yMax,z); + (*coords)[1].set(xMin,yMin,z); + (*coords)[2].set(xMax,yMin,z); + (*coords)[3].set(xMax,yMax,z); + geom->setVertexArray(coords); + + geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); + + return geom; + } Group *makeClipRegion(const georecord *gr) { - GeoClipRegion *clp=new GeoClipRegion; + GeoClipRegion *clp=new GeoClipRegion; const geoField *gfd=gr->getField(GEO_DB_NODE_NAME); if (gfd) { clp->setName(gfd->getChar()); } gfd=gr->getField(140); - float *lleft = (gfd) ? (gfd->getVec3Arr()):NULL; + float *lleft = (gfd) ? (gfd->getVec3Arr()):NULL; gfd=gr->getField(141); - float *uright= (gfd) ? (gfd->getVec3Arr()):NULL; - if (uright && lleft) { - Geode *geod=new Geode; - Drawable *drw=createClipSurface(lleft[0],uright[0],lleft[1],uright[1],lleft[2]); - geod->addDrawable(drw); - clp->addClipNode(geod); - } - return clp; + float *uright= (gfd) ? (gfd->getVec3Arr()):NULL; + if (uright && lleft) { + Geode *geod=new Geode; + Drawable *drw=createClipSurface(lleft[0],uright[0],lleft[1],uright[1],lleft[2]); + geod->addDrawable(drw); + clp->addClipNode(geod); + } + return clp; } geoHeader *makeHeader(const georecord *gr) { - if (!theHeader.valid()) theHeader=new geoHeaderGeo(); + if (!theHeader.valid()) theHeader=new geoHeaderGeo(); // the header contains variables as well as a transform for the XYZup cases const geoField *gfd; if (cpalrec) { // global - attach to geoheader @@ -1709,23 +1709,23 @@ class ReaderWriterGEO : public osgDB::ReaderWriter Group *animatedGeodes= makeAnimatedGeodes(gr); Group *lightptGeodes= makeLightPointGeodes(gr); Group *textgeode=makeTextGeode(gr); // group of matrices & texts - const geoField *gfd=gr->getField(GEO_DB_GRP_ZBUFFER); - if (gfd) { - bool onoff=gfd->getBool(); - if (!onoff) { // no z buffer - force to use unsorted renderBin - StateSet *dstate=new StateSet; - osg::Depth* depth = new osg::Depth; - depth->setFunction(osg::Depth::ALWAYS); - dstate->setAttribute(depth); - dstate->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); - dstate->setRenderBinDetails(osg::StateSet::TRANSPARENT_BIN + 1,"RenderBin"); - // dstate->setRenderBinDetails(osg::StateSet::TRANSPARENT_BIN + 12, "UnSortedBin"); - if (geode) geode->setStateSet( dstate ); - if (animatedGeodes) animatedGeodes->setStateSet( dstate ); - if (lightptGeodes) lightptGeodes->setStateSet( dstate ); - if (textgeode) textgeode->setStateSet( dstate ); - } - } + const geoField *gfd=gr->getField(GEO_DB_GRP_ZBUFFER); + if (gfd) { + bool onoff=gfd->getBool(); + if (!onoff) { // no z buffer - force to use unsorted renderBin + StateSet *dstate=new StateSet; + osg::Depth* depth = new osg::Depth; + depth->setFunction(osg::Depth::ALWAYS); + dstate->setAttribute(depth); + dstate->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); + dstate->setRenderBinDetails(osg::StateSet::TRANSPARENT_BIN + 1,"RenderBin"); + // dstate->setRenderBinDetails(osg::StateSet::TRANSPARENT_BIN + 12, "UnSortedBin"); + if (geode) geode->setStateSet( dstate ); + if (animatedGeodes) animatedGeodes->setStateSet( dstate ); + if (lightptGeodes) lightptGeodes->setStateSet( dstate ); + if (textgeode) textgeode->setStateSet( dstate ); + } + } if (mtr) { if (geode) mtr->addChild(geode); @@ -1737,7 +1737,7 @@ class ReaderWriterGEO : public osgDB::ReaderWriter } else { if (!geodeholder && (geode || textgeode)) { geodeholder=new osg::Group; - geodeholder->setName("geodeHolder"); + geodeholder->setName("geodeHolder"); } if (geode) geodeholder->addChild(geode); if (animatedGeodes) geodeholder->addChild(animatedGeodes); @@ -1756,12 +1756,12 @@ class ReaderWriterGEO : public osgDB::ReaderWriter holder=mtr; } (*itr)->setNode(holder); - break; + break; /* holder= theHeader.get(); // makeHeader(gr);// (*itr)->setNode(holder); if (mtr) { holder->addChild(mtr); - osg::Group *grp=makeGroup(gr); + osg::Group *grp=makeGroup(gr); mtr->addChild(grp); holder=mtr; } @@ -1770,7 +1770,7 @@ class ReaderWriterGEO : public osgDB::ReaderWriter makeTexture(gr); break; case DB_DSK_BASE_GROUP: // start of a group plus extra features - holder=makeClipRegion(gr); + holder=makeClipRegion(gr); if (mtr) { mtr->addChild(holder); holder=mtr; @@ -1862,9 +1862,9 @@ class ReaderWriterGEO : public osgDB::ReaderWriter (*itr)->setNode(holder); break; case DB_DSK_PERSPECTIVE_GRID_INFO: - { // relates to how model is viewed in Geo modeller - osg::Group *gp=new Group; - holder=gp; + { // relates to how model is viewed in Geo modeller + osg::Group *gp=new Group; + holder=gp; } break; case DB_DSK_FLOAT_VAR: @@ -1892,8 +1892,8 @@ class ReaderWriterGEO : public osgDB::ReaderWriter case DB_DSK_STRING_CONTENT_ACTION: default: { osg::Group *gp=new Group; - std::cout << "Unhandled item " << gr->getType() << - "address " << (*itr) << std::endl; + osg::notify(osg::WARN) << "Unhandled item " << gr->getType() << + "address " << (*itr) << std::endl; holder=gp; } break; @@ -1901,11 +1901,11 @@ class ReaderWriterGEO : public osgDB::ReaderWriter if (holder) nodelist.push_back(holder); std::vector child=makeosg((*itr)->getchildren()); - GeoClipRegion *clip=dynamic_cast(holder); + GeoClipRegion *clip=dynamic_cast(holder); for (std::vector::iterator itr=child.begin(); itr!=child.end(); ++itr) { - if (clip) clip->addClippedChild(*itr); + if (clip) clip->addClippedChild(*itr); else holder->addChild(*itr); } } @@ -1998,12 +1998,12 @@ class ReaderWriterGEO : public osgDB::ReaderWriter } return NULL; } - + private: geoRecordList recs; // the records read from file std::vector coord_pool; // current vertex ooords std::vector normal_pool; // current pool of normal vectors - osg::ref_ptr theHeader; // an OSG class - has animation vars etc + osg::ref_ptr theHeader; // an OSG class - has animation vars etc std::vector geotxlist; // list of geo::textures for this model std::vector geomatlist; // list of geo::materials for this model std::vector txlist; // list of osg::textures for this model @@ -2135,65 +2135,65 @@ void internalVars::update(const osg::FrameStamp *_frameStamp) { } void geoField::parseExt(std::ifstream &fin) const { // Feb 2003 parse onme extension fields - static int nread=0; // debug only - // unused - //geoExtensionDefRec *geoExt=(geoExtensionDefRec *)storage; - for (uint i=0; i0) { - storageRead(fin); // allocate & fill the storage - if (tokenId == GEO_DB_NODE_EXT) { // added Nov 2003 to parse extension nodes - if (TypeId == DB_SHORT ||TypeId == DB_USHORT) fin.ignore(2); // skip padding - // if (TypeId == DB_CHAR ||TypeId == DB_UCHAR) fin.ignore(3); // skip padding - } - if (tokenId == GEO_DB_NODE_EXTENDED) { - if (id==DB_DSK_POLYGON || id==DB_DSK_RENDERGROUP || id==DB_DSK_GROUP - || id==DB_DSK_LOD || id==DB_DSK_MESH || id==DB_DSK_CUBE - || id==DB_DSK_SPHERE || id==DB_DSK_CONE || id==DB_DSK_CYLINDER - || id==DB_DSK_TEXTURE || id==DB_DSK_MATERIAL || id==DB_DSK_VIEW) { - if (TypeId == DB_SHORT ||TypeId == DB_USHORT) fin.ignore(2); // skip padding - } - } - } - } - } + unsigned char tokid, type; + unsigned short nits; + if (!fin.eof()) { + fin.read((char *)&tokid,1);fin.read((char *)&type,1); + fin.read((char *)&nits,sizeof(unsigned short)); + // osg::notify(osg::WARN) << "geoField " << (int)tokid << " type " << (int)type << " nit " << (int)nits << std::endl; + if (type == DB_EXTENDED_FIELD_STRUCT) { // change for true extended type + fin.read((char *)&tokenId,sizeof(tokenId));fin.read((char *)&TypeId,sizeof(TypeId)); + fin.read((char *)&numItems,sizeof(unsigned int)); + } else { + tokenId=tokid; TypeId=type; + numItems=nits; + } + if (id== 0 && tokenId == GEO_DB_NODE_EXTENDED && numItems==1) { // Feb 2003 parse extension template records + if (TypeId == DB_SHORT || + TypeId == DB_USHORT) { + short upad; + fin.read((char *)&upad,SIZEOF_SHORT); // skip the padding on extension template + upad=1; + } else if (TypeId == DB_CHAR || + TypeId == DB_UCHAR) { + char cpad[4]; + fin.read(cpad,SIZEOF_CHAR); // skip the padding + } else { + } + } + if (id== DB_DSK_HEADER && tokenId == GEO_DB_HDR_EXT_TEMPLATE) { // Feb 2003 parse extension records + // osg::notify(osg::WARN) << "header extension template " << (int)getType() << std::endl; + parseExt(fin); // multiple structs occur here + } else { + if (numItems>0) { + storageRead(fin); // allocate & fill the storage + if (tokenId == GEO_DB_NODE_EXT) { // added Nov 2003 to parse extension nodes + if (TypeId == DB_SHORT ||TypeId == DB_USHORT) fin.ignore(2); // skip padding + // if (TypeId == DB_CHAR ||TypeId == DB_UCHAR) fin.ignore(3); // skip padding + } + if (tokenId == GEO_DB_NODE_EXTENDED) { + if (id==DB_DSK_POLYGON || id==DB_DSK_RENDERGROUP || id==DB_DSK_GROUP + || id==DB_DSK_LOD || id==DB_DSK_MESH || id==DB_DSK_CUBE + || id==DB_DSK_SPHERE || id==DB_DSK_CONE || id==DB_DSK_CYLINDER + || id==DB_DSK_TEXTURE || id==DB_DSK_MATERIAL || id==DB_DSK_VIEW) { + if (TypeId == DB_SHORT ||TypeId == DB_USHORT) fin.ignore(2); // skip padding + } + } + } + } + } } diff --git a/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp b/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp index 15199408d..e23dedc4d 100644 --- a/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp +++ b/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp @@ -32,6 +32,7 @@ #include #include +#include using namespace std; using namespace osg; @@ -41,7 +42,9 @@ class PrintVisitor : public NodeVisitor public: - PrintVisitor():NodeVisitor(NodeVisitor::TRAVERSE_ALL_CHILDREN) + PrintVisitor(std::ostream& out): + NodeVisitor(NodeVisitor::TRAVERSE_ALL_CHILDREN), + _out(out) { _indent = 0; _step = 4; @@ -51,29 +54,32 @@ class PrintVisitor : public NodeVisitor inline void moveOut() { _indent -= _step; } inline void writeIndent() { - for(int i=0;i<_indent;++i) std::cout << " "; + for(int i=0;i<_indent;++i) _out << " "; } virtual void apply(Node& node) { moveIn(); - writeIndent(); std::cout << node.className() << " name=" << node.getName() << std::endl; + writeIndent(); _out << node.className() < text = new osgText::Text; // Text - std::ostringstream os; - int nl; - std::string lb = *labelText; - while ( (nl=lb.find_first_of('\\')) != std::string::npos) - { - std::string sub = lb.substr(0,nl); - switch (lb[nl+1]) - { - case 'n': - lb.erase(0,nl+2); - if (sub.length()) os << sub << std::endl; - break; - case 't': - lb.erase(0,nl+2); - os << sub << " ";//'\t'; - break; - default: - lb.erase(0,nl+1); - os << '\\' << sub; - break; - } - - } - if (lb.length()) os << lb; + std::ostringstream os; + unsigned int nl; + std::string lb = *labelText; + while ( (nl=lb.find_first_of('\\')) != std::string::npos) + { + std::string sub = lb.substr(0,nl); + switch (lb[nl+1]) + { + case 'n': + lb.erase(0,nl+2); + if (sub.length()) os << sub << std::endl; + break; + case 't': + lb.erase(0,nl+2); + os << sub << " ";//'\t'; + break; + default: + lb.erase(0,nl+1); + os << '\\' << sub; + break; + } + + } + if (lb.length()) os << lb; text->setText(os.str()); // Position @@ -811,13 +810,13 @@ void* labelRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf) text->setAlignment(osgText::Text::CENTER_BOTTOM); } // Axis alignment - text->setAxisAlignment(osgText::Text::XZ_PLANE); + text->setAxisAlignment(osgText::Text::XZ_PLANE); const trpgLabelPropertyTable *labelPropertyTable = _parse->getArchive()->GetLabelPropertyTable(); const trpgLabelProperty *labelProperty = labelPropertyTable ? labelPropertyTable->GetPropertyRef(label.GetProperty()) : 0; - bool addTextGeodeIntoSceneGraph = true; + bool addTextGeodeIntoSceneGraph = true; if (labelProperty) { const trpgTextStyleTable *textStyleTable = _parse->getArchive()->GetTextStyleTable(); @@ -833,213 +832,213 @@ void* labelRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf) // Font text->setFont(_parse->getArchive()->getStyles()[labelProperty->GetFontStyle()].get()); - // Color - text->setColor(_parse->getArchive()->getTextColors()[labelProperty->GetFontStyle()]); + // Color + text->setColor(_parse->getArchive()->getTextColors()[labelProperty->GetFontStyle()]); - // Cube - osg::ref_ptr cube = 0; + // Cube + osg::ref_ptr cube = 0; // Type switch (labelProperty->GetType()) { case trpgLabelProperty::Billboard: - text->setAxisAlignment(osgText::Text::XY_PLANE); + text->setAxisAlignment(osgText::Text::XY_PLANE); text->setAutoRotateToScreen(true); break; case trpgLabelProperty::VertBillboard: - addTextGeodeIntoSceneGraph = false; - { - osg::ref_ptr< osg::Billboard > billboard = new osg::Billboard; - text->setPosition(osg::Vec3(0.f,0.f,0.f)); - billboard->addDrawable(text.get()); - billboard->setAxis(osg::Vec3(0.0f,0.0,1.0f) ); - billboard->setNormal(osg::Vec3(0.0f,-1.0,0.0f)); - billboard->setMode(osg::Billboard::AXIAL_ROT); - billboard->setPos(0,pos); + addTextGeodeIntoSceneGraph = false; + { + osg::ref_ptr< osg::Billboard > billboard = new osg::Billboard; + text->setPosition(osg::Vec3(0.f,0.f,0.f)); + billboard->addDrawable(text.get()); + billboard->setAxis(osg::Vec3(0.0f,0.0,1.0f) ); + billboard->setNormal(osg::Vec3(0.0f,-1.0,0.0f)); + billboard->setMode(osg::Billboard::AXIAL_ROT); + billboard->setPos(0,pos); - _parse->getCurrTop()->addChild(billboard.get()); - } + _parse->getCurrTop()->addChild(billboard.get()); + } break; case trpgLabelProperty::Cube: - addTextGeodeIntoSceneGraph = false; - { - osg::Group* group = new osg::Group; + addTextGeodeIntoSceneGraph = false; + { + osg::Group* group = new osg::Group; - osg::BoundingBox box = text->getBound(); - float shift = box.radius()+1.f; + osg::BoundingBox box = text->getBound(); + float shift = box.radius()+1.f; - // front - text->setAlignment(osgText::Text::CENTER_CENTER); + // front + text->setAlignment(osgText::Text::CENTER_CENTER); - // back - osg::ref_ptr backText = new osgText::Text(*text); - backText->setPosition(osg::Vec3(pos.x(),pos.y()+shift,pos.z())); - backText->setAxisAlignment(osgText::Text::REVERSED_XZ_PLANE); + // back + osg::ref_ptr backText = new osgText::Text(*text); + backText->setPosition(osg::Vec3(pos.x(),pos.y()+shift,pos.z())); + backText->setAxisAlignment(osgText::Text::REVERSED_XZ_PLANE); - // top - osg::ref_ptr topText = new osgText::Text(*text); - topText->setPosition(osg::Vec3(pos.x(),pos.y(),pos.z()+shift)); - topText->setAxisAlignment(osgText::Text::XY_PLANE); + // top + osg::ref_ptr topText = new osgText::Text(*text); + topText->setPosition(osg::Vec3(pos.x(),pos.y(),pos.z()+shift)); + topText->setAxisAlignment(osgText::Text::XY_PLANE); - // bottom - osg::ref_ptr bottomText = new osgText::Text(*text); - bottomText->setPosition(osg::Vec3(pos.x(),pos.y(),pos.z()-shift)); - bottomText->setAxisAlignment(osgText::Text::REVERSED_XY_PLANE); + // bottom + osg::ref_ptr bottomText = new osgText::Text(*text); + bottomText->setPosition(osg::Vec3(pos.x(),pos.y(),pos.z()-shift)); + bottomText->setAxisAlignment(osgText::Text::REVERSED_XY_PLANE); - // left - osg::ref_ptr leftText = new osgText::Text(*text); - leftText->setPosition(osg::Vec3(pos.x()-shift,pos.y(),pos.z())); - leftText->setAxisAlignment(osgText::Text::REVERSED_YZ_PLANE); + // left + osg::ref_ptr leftText = new osgText::Text(*text); + leftText->setPosition(osg::Vec3(pos.x()-shift,pos.y(),pos.z())); + leftText->setAxisAlignment(osgText::Text::REVERSED_YZ_PLANE); - // right - osg::ref_ptr rightText = new osgText::Text(*text); - rightText->setPosition(osg::Vec3(pos.x()+shift,pos.y(),pos.z())); - rightText->setAxisAlignment(osgText::Text::YZ_PLANE); + // right + osg::ref_ptr rightText = new osgText::Text(*text); + rightText->setPosition(osg::Vec3(pos.x()+shift,pos.y(),pos.z())); + rightText->setAxisAlignment(osgText::Text::YZ_PLANE); - text->setPosition(osg::Vec3(pos.x(),pos.y()-shift,pos.z())); + text->setPosition(osg::Vec3(pos.x(),pos.y()-shift,pos.z())); - osg::TessellationHints* hints = new osg::TessellationHints; - hints->setDetailRatio(0.5f); - cube = new osg::ShapeDrawable(new osg::Box(pos,2*shift),hints); + osg::TessellationHints* hints = new osg::TessellationHints; + hints->setDetailRatio(0.5f); + cube = new osg::ShapeDrawable(new osg::Box(pos,2*shift),hints); - osg::ref_ptr polyoffset = new osg::PolygonOffset; + osg::ref_ptr polyoffset = new osg::PolygonOffset; polyoffset->setFactor(10.0f); polyoffset->setUnits(10.0f); - osg::ref_ptr ss = cube->getOrCreateStateSet(); - ss->setAttributeAndModes(polyoffset.get(),osg::StateAttribute::ON); - cube->setStateSet(ss.get()); + osg::ref_ptr ss = cube->getOrCreateStateSet(); + ss->setAttributeAndModes(polyoffset.get(),osg::StateAttribute::ON); + cube->setStateSet(ss.get()); - textGeode->addDrawable(cube.get()); - textGeode->addDrawable(text.get()); - textGeode->addDrawable(backText.get()); - textGeode->addDrawable(topText.get()); - textGeode->addDrawable(bottomText.get()); - textGeode->addDrawable(leftText.get()); - textGeode->addDrawable(rightText.get()); + textGeode->addDrawable(cube.get()); + textGeode->addDrawable(text.get()); + textGeode->addDrawable(backText.get()); + textGeode->addDrawable(topText.get()); + textGeode->addDrawable(bottomText.get()); + textGeode->addDrawable(leftText.get()); + textGeode->addDrawable(rightText.get()); - group->addChild(textGeode.get()); + group->addChild(textGeode.get()); - _parse->getCurrTop()->addChild(group); - } + _parse->getCurrTop()->addChild(group); + } break; } - const std::vector *supports = label.GetSupports(); - if (supports && supports->size()) - { - osg::ref_ptr supGeode = new osg::Geode; + const std::vector *supports = label.GetSupports(); + if (supports && supports->size()) + { + osg::ref_ptr supGeode = new osg::Geode; - int supId = labelProperty->GetSupport(); - const trpgSupportStyleTable *supTable = _parse->getArchive()->GetSupportStyleTable(); - const trpgSupportStyle *supStyle = supTable ? supTable->GetStyleRef(supId) : 0; - if (supStyle) - { - int matId = supStyle->GetMaterial(); + int supId = labelProperty->GetSupport(); + const trpgSupportStyleTable *supTable = _parse->getArchive()->GetSupportStyleTable(); + const trpgSupportStyle *supStyle = supTable ? supTable->GetStyleRef(supId) : 0; + if (supStyle) + { + int matId = supStyle->GetMaterial(); - osg::Vec4 supLineColor(1.f,1.f,1.f,1.f); - _parse->loadMaterial(matId); - osg::ref_ptr sset = (*_parse->getMaterials())[matId]; + osg::Vec4 supLineColor(1.f,1.f,1.f,1.f); + _parse->loadMaterial(matId); + osg::ref_ptr sset = (*_parse->getMaterials())[matId]; - if (cube.get()) - { - osg::StateSet* ss = cube->getOrCreateStateSet(); - ss->merge(*sset); - } + if (cube.get()) + { + osg::StateSet* ss = cube->getOrCreateStateSet(); + ss->merge(*sset); + } - const trpgMatTable* matTable = _parse->getArchive()->GetMaterialTable(); - if (matTable) - { - const trpgMaterial* mat = matTable->GetMaterialRef(0,matId); - if (mat) - { - trpgColor faceColor; - mat->GetColor(faceColor); + const trpgMatTable* matTable = _parse->getArchive()->GetMaterialTable(); + if (matTable) + { + const trpgMaterial* mat = matTable->GetMaterialRef(0,matId); + if (mat) + { + trpgColor faceColor; + mat->GetColor(faceColor); - float64 alpha; - mat->GetAlpha(alpha); + float64 alpha; + mat->GetAlpha(alpha); - supLineColor = osg::Vec4(faceColor.red, faceColor.green, faceColor.blue, alpha ); - } - } - - switch (supStyle->GetType()) - { - case trpgSupportStyle::Line: - { - osg::Geometry* linesGeom = new osg::Geometry(); - osg::Vec3Array* vertices = new osg::Vec3Array(supports->size()*2); + supLineColor = osg::Vec4(faceColor.red, faceColor.green, faceColor.blue, alpha ); + } + } + + switch (supStyle->GetType()) + { + case trpgSupportStyle::Line: + { + osg::Geometry* linesGeom = new osg::Geometry(); + osg::Vec3Array* vertices = new osg::Vec3Array(supports->size()*2); - int cnt = 0; - for (unsigned int i = 0; i < supports->size(); i++) - { - const trpg3dPoint& supPt = (*supports)[i]; - (*vertices)[cnt++].set(pos); - (*vertices)[cnt++].set(osg::Vec3(supPt.x,supPt.y,supPt.z)); - } + int cnt = 0; + for (unsigned int i = 0; i < supports->size(); i++) + { + const trpg3dPoint& supPt = (*supports)[i]; + (*vertices)[cnt++].set(pos); + (*vertices)[cnt++].set(osg::Vec3(supPt.x,supPt.y,supPt.z)); + } - linesGeom->setVertexArray(vertices); + linesGeom->setVertexArray(vertices); - osg::Vec4Array* colors = new osg::Vec4Array; - colors->push_back(supLineColor); - linesGeom->setColorArray(colors); - linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL); - - osg::Vec3Array* normals = new osg::Vec3Array; - normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); - linesGeom->setNormalArray(normals); - linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); + osg::Vec4Array* colors = new osg::Vec4Array; + colors->push_back(supLineColor); + linesGeom->setColorArray(colors); + linesGeom->setColorBinding(osg::Geometry::BIND_OVERALL); + + osg::Vec3Array* normals = new osg::Vec3Array; + normals->push_back(osg::Vec3(0.0f,-1.0f,0.0f)); + linesGeom->setNormalArray(normals); + linesGeom->setNormalBinding(osg::Geometry::BIND_OVERALL); - linesGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,supports->size()*2)); - supGeode->addDrawable(linesGeom); - } + linesGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,supports->size()*2)); + supGeode->addDrawable(linesGeom); + } - _parse->getCurrTop()->addChild(supGeode.get()); - break; - case trpgSupportStyle::Cylinder: - { - osg::ref_ptr hints = new osg::TessellationHints; - hints->setDetailRatio(0.5f); + _parse->getCurrTop()->addChild(supGeode.get()); + break; + case trpgSupportStyle::Cylinder: + { + osg::ref_ptr hints = new osg::TessellationHints; + hints->setDetailRatio(0.5f); - for (unsigned int i = 0; i < supports->size(); i++) - { - const trpg3dPoint& supPt = (*supports)[i]; - - osg::Vec3 supPos(supPt.x,supPt.y,supPt.z); - osg::Vec3 supCenter = (supPos+pos)/2.f; - float supHeight = (supPos-pos).length(); + for (unsigned int i = 0; i < supports->size(); i++) + { + const trpg3dPoint& supPt = (*supports)[i]; + + osg::Vec3 supPos(supPt.x,supPt.y,supPt.z); + osg::Vec3 supCenter = (supPos+pos)/2.f; + float supHeight = (supPos-pos).length(); - osg::Vec3 d = pos-supPos; - d.normalize(); - osg::Quat r; + osg::Vec3 d = pos-supPos; + d.normalize(); + osg::Quat r; - r.makeRotate(osg::Vec3(0.f,0.f,1.f),d); + r.makeRotate(osg::Vec3(0.f,0.f,1.f),d); - osg::Cylinder* cylinder = new osg::Cylinder(supCenter,10.f,supHeight); - cylinder->setRotation(r); + osg::Cylinder* cylinder = new osg::Cylinder(supCenter,10.f,supHeight); + cylinder->setRotation(r); - osg::ShapeDrawable* cylinderDrawable = new osg::ShapeDrawable(cylinder,hints.get()); - osg::StateSet* ss = cylinderDrawable->getOrCreateStateSet(); - ss->merge(*sset); + osg::ShapeDrawable* cylinderDrawable = new osg::ShapeDrawable(cylinder,hints.get()); + osg::StateSet* ss = cylinderDrawable->getOrCreateStateSet(); + ss->merge(*sset); - supGeode->addDrawable(cylinderDrawable); + supGeode->addDrawable(cylinderDrawable); - } - - _parse->getCurrTop()->addChild(supGeode.get()); - } - break; - } + } + + _parse->getCurrTop()->addChild(supGeode.get()); + } + break; + } - - } - } + + } + } + } + if (addTextGeodeIntoSceneGraph) + { + _parse->getCurrTop()->addChild(textGeode.get()); + textGeode->addDrawable(text.get()); } - if (addTextGeodeIntoSceneGraph) - { - _parse->getCurrTop()->addChild(textGeode.get()); - textGeode->addDrawable(text.get()); - } return (void*)1; } @@ -1388,7 +1387,7 @@ void* geomRead::Parse(trpgToken /*tok*/,trpgReadBuffer &buf) } else { - std::cout<<"Detected potential memory leak in TXPParerse.cpp"<CalcTotalSize(); + int32 size = tex->CalcTotalSize(); data = new char [size]; image_helper.GetLocalGL(tex,data,size); image->setImage(s.x,s.y,1,internalFormat, pixelFormat, dataType, @@ -1570,7 +1569,7 @@ osg::Texture2D* txp::getTemplateTexture(trpgrImageHelper& image_helper, trpgLoca // osg::Image do their own mipmaps if(num_mipmaps <= 1) { - int32 size = tex->CalcTotalSize(); + int32 size = tex->CalcTotalSize(); data = new char [size]; image_helper.GetNthImageForLocalMat(locmat,index, data,size); diff --git a/src/osgText/Font.cpp b/src/osgText/Font.cpp index bc732ec24..958bd413b 100644 --- a/src/osgText/Font.cpp +++ b/src/osgText/Font.cpp @@ -691,12 +691,12 @@ void Font::Glyph::subload() const { osg::notify(osg::WARN)<<"after Font::Glyph::subload() : detected OpenGL error '"<