diff --git a/include/osg/KdTree b/include/osg/KdTree index eaff4c808..1b521419f 100644 --- a/include/osg/KdTree +++ b/include/osg/KdTree @@ -227,6 +227,10 @@ class OSG_EXPORT KdTreeBuilder : public osg::NodeVisitor KdTreeBuilder(); + KdTreeBuilder(const KdTreeBuilder& rhs); + + virtual KdTreeBuilder* clone() { return new KdTreeBuilder(*this); } + void apply(osg::Geode& geode); KdTree::BuildOptions _buildOptions; diff --git a/include/osgDB/DatabasePager b/include/osgDB/DatabasePager index 43eb86d2b..bf31cef9e 100644 --- a/include/osgDB/DatabasePager +++ b/include/osgDB/DatabasePager @@ -104,6 +104,8 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl virtual void run(); + osg::ref_ptr dpReadRefNodeFile(const std::string& fileName,const ReaderWriter::Options* options); + protected: virtual ~DatabaseThread(); diff --git a/include/osgDB/Registry b/include/osgDB/Registry index 92f454b7a..98dc9607c 100644 --- a/include/osgDB/Registry +++ b/include/osgDB/Registry @@ -320,7 +320,8 @@ class OSGDB_EXPORT Registry : public osg::Referenced if (doKdTreeBuilder && _kdTreeBuilder.valid() && result.validNode()) { - result.getNode()->accept(*_kdTreeBuilder); + osg::ref_ptr builder = _kdTreeBuilder->clone(); + result.getNode()->accept(*builder); } } diff --git a/src/osg/KdTree.cpp b/src/osg/KdTree.cpp index e0f2e1b14..77d7b490d 100644 --- a/src/osg/KdTree.cpp +++ b/src/osg/KdTree.cpp @@ -67,8 +67,6 @@ KdTree::KdTree(const KdTree& rhs, const osg::CopyOp& copyop): bool KdTree::build(BuildOptions& options, osg::Geometry* geometry) { - osg::notify(osg::NOTICE)<<"KdTree::build("< -#include #include #include #include +#include #include #include @@ -367,6 +367,17 @@ int DatabasePager::DatabaseThread::cancel() } +osg::ref_ptr DatabasePager::DatabaseThread::dpReadRefNodeFile(const std::string& fileName,const ReaderWriter::Options* options) +{ + ReaderWriter::ReadResult rr = Registry::instance()->getReadFileCallback() ? + Registry::instance()->getReadFileCallback()->readNode(fileName,options) : + Registry::instance()->readNodeImplementation(fileName,options); + + if (rr.validNode()) return rr.getNode(); + if (rr.error()) osg::notify(osg::WARN) << rr.message() << std::endl; + return 0; +} + void DatabasePager::DatabaseThread::run() { osg::notify(osg::INFO)<<_name<<": DatabasePager::DatabaseThread::run"< lock(s_serialize_readNodeFile_mutex); - databaseRequest->_loadedModel = osgDB::readRefNodeFile(databaseRequest->_fileName, + databaseRequest->_loadedModel = dpReadRefNodeFile(databaseRequest->_fileName, databaseRequest->_loadOptions.get()); } else { // assume that we only have one DatabasePager, or that readNodeFile is thread safe... - databaseRequest->_loadedModel = osgDB::readRefNodeFile(databaseRequest->_fileName, + databaseRequest->_loadedModel = dpReadRefNodeFile(databaseRequest->_fileName, databaseRequest->_loadOptions.get()); } diff --git a/src/osgDB/Registry.cpp b/src/osgDB/Registry.cpp index 79c3b121e..2bc8263af 100644 --- a/src/osgDB/Registry.cpp +++ b/src/osgDB/Registry.cpp @@ -54,6 +54,8 @@ static osg::ApplicationUsageProxy Registry_e0(osg::ApplicationUsage::ENVIRONMENT static osg::ApplicationUsageProxy Registry_e1(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_LIBRARY_PATH [;path]..","Paths for locating libraries/ plugins"); #endif +static osg::ApplicationUsageProxy Registry_e2(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_BUILD_KDTREES on/off","Enable/disable the automatic building of KdTrees for each loaded Geometry."); + class Registry::AvailableReaderWriterIterator { diff --git a/src/osgTerrain/GeometryTechnique.cpp b/src/osgTerrain/GeometryTechnique.cpp index b40fa82fa..e5818fb6c 100644 --- a/src/osgTerrain/GeometryTechnique.cpp +++ b/src/osgTerrain/GeometryTechnique.cpp @@ -25,6 +25,7 @@ #include #include #include +#include using namespace osgTerrain; @@ -232,6 +233,8 @@ void GeometryTechnique::generateGeometry(Locator* masterLocator, const osg::Vec3 double i_sampleFactor = 1.0; double j_sampleFactor = 1.0; + osg::notify(osg::NOTICE)<<"Sample ratio="<getBuildKdTreesHint()==osgDB::ReaderWriter::Options::BUILD_KDTREES && osgDB::Registry::instance()->getKdTreeBuilder()) { + + + osg::Timer_t before = osg::Timer::instance()->tick(); //osg::notify(osg::NOTICE)<<"osgTerrain::GeometryTechnique::build kd tree"<accept(*(osgDB::Registry::instance()->getKdTreeBuilder())); - //osg::notify(osg::NOTICE)<<"after"< builder = osgDB::Registry::instance()->getKdTreeBuilder()->clone(); + buffer._geode->accept(*builder); + osg::Timer_t after = osg::Timer::instance()->tick(); + osg::notify(osg::NOTICE)<<"KdTree build time "<delta_m(before, after)<getPrimitiveSetIndex(primitive))!=geometry.getNumPrimitiveSet()) "); + I_Method1(void, setVertexIndices, IN, osg::IndexArray *, array, + Properties::NON_VIRTUAL, + __void__setVertexIndices__IndexArray_P1, + "deprecated - forces OpenGL slow path, just kept for backwards compatibility. ", + ""); + I_Method0(osg::IndexArray *, getVertexIndices, + Properties::NON_VIRTUAL, + __IndexArray_P1__getVertexIndices, + "", + ""); + I_Method0(const osg::IndexArray *, getVertexIndices, + Properties::NON_VIRTUAL, + __C5_IndexArray_P1__getVertexIndices, + "", + ""); + I_Method1(void, setNormalIndices, IN, osg::IndexArray *, array, + Properties::NON_VIRTUAL, + __void__setNormalIndices__IndexArray_P1, + "deprecated - forces OpenGL slow path, just kept for backwards compatibility. ", + ""); + I_Method0(osg::IndexArray *, getNormalIndices, + Properties::NON_VIRTUAL, + __IndexArray_P1__getNormalIndices, + "", + ""); + I_Method0(const osg::IndexArray *, getNormalIndices, + Properties::NON_VIRTUAL, + __C5_IndexArray_P1__getNormalIndices, + "", + ""); + I_Method1(void, setColorIndices, IN, osg::IndexArray *, array, + Properties::NON_VIRTUAL, + __void__setColorIndices__IndexArray_P1, + "deprecated - forces OpenGL slow path, just kept for backwards compatibility. ", + ""); + I_Method0(osg::IndexArray *, getColorIndices, + Properties::NON_VIRTUAL, + __IndexArray_P1__getColorIndices, + "", + ""); + I_Method0(const osg::IndexArray *, getColorIndices, + Properties::NON_VIRTUAL, + __C5_IndexArray_P1__getColorIndices, + "", + ""); + I_Method1(void, setSecondaryColorIndices, IN, osg::IndexArray *, array, + Properties::NON_VIRTUAL, + __void__setSecondaryColorIndices__IndexArray_P1, + "deprecated - forces OpenGL slow path, just kept for backwards compatibility. ", + ""); + I_Method0(osg::IndexArray *, getSecondaryColorIndices, + Properties::NON_VIRTUAL, + __IndexArray_P1__getSecondaryColorIndices, + "", + ""); + I_Method0(const osg::IndexArray *, getSecondaryColorIndices, + Properties::NON_VIRTUAL, + __C5_IndexArray_P1__getSecondaryColorIndices, + "", + ""); + I_Method1(void, setFogCoordIndices, IN, osg::IndexArray *, array, + Properties::NON_VIRTUAL, + __void__setFogCoordIndices__IndexArray_P1, + "deprecated - forces OpenGL slow path, just kept for backwards compatibility. ", + ""); + I_Method0(osg::IndexArray *, getFogCoordIndices, + Properties::NON_VIRTUAL, + __IndexArray_P1__getFogCoordIndices, + "", + ""); + I_Method0(const osg::IndexArray *, getFogCoordIndices, + Properties::NON_VIRTUAL, + __C5_IndexArray_P1__getFogCoordIndices, + "", + ""); + I_Method2(void, setTexCoordIndices, IN, unsigned int, unit, IN, osg::IndexArray *, x, + Properties::NON_VIRTUAL, + __void__setTexCoordIndices__unsigned_int__IndexArray_P1, + "deprecated - forces OpenGL slow path, just kept for backwards compatibility. ", + ""); + I_Method1(osg::IndexArray *, getTexCoordIndices, IN, unsigned int, unit, + Properties::NON_VIRTUAL, + __IndexArray_P1__getTexCoordIndices__unsigned_int, + "", + ""); + I_Method1(const osg::IndexArray *, getTexCoordIndices, IN, unsigned int, unit, + Properties::NON_VIRTUAL, + __C5_IndexArray_P1__getTexCoordIndices__unsigned_int, + "", + ""); + I_Method2(void, setVertexAttribIndices, IN, unsigned int, index, IN, osg::IndexArray *, array, + Properties::NON_VIRTUAL, + __void__setVertexAttribIndices__unsigned_int__IndexArray_P1, + "deprecated - forces OpenGL slow path, just kept for backwards compatibility. ", + ""); + I_Method1(osg::IndexArray *, getVertexAttribIndices, IN, unsigned int, index, + Properties::NON_VIRTUAL, + __IndexArray_P1__getVertexAttribIndices__unsigned_int, + "", + ""); + I_Method1(const osg::IndexArray *, getVertexAttribIndices, IN, unsigned int, index, + Properties::NON_VIRTUAL, + __C5_IndexArray_P1__getVertexAttribIndices__unsigned_int, + "", + ""); I_Method1(void, setUseVertexBufferObjects, IN, bool, flag, Properties::VIRTUAL, __void__setUseVertexBufferObjects__bool, diff --git a/src/osgWrappers/osgDB/DatabasePager.cpp b/src/osgWrappers/osgDB/DatabasePager.cpp index 9d0bb9859..2c7c38ee6 100644 --- a/src/osgWrappers/osgDB/DatabasePager.cpp +++ b/src/osgWrappers/osgDB/DatabasePager.cpp @@ -449,6 +449,11 @@ BEGIN_OBJECT_REFLECTOR(osgDB::DatabasePager::DatabaseThread) __void__run, "Thread's run method. ", "Must be implemented by derived classes. This is where the action happens. "); + I_Method2(osg::ref_ptr< osg::Node >, dpReadRefNodeFile, IN, const std::string &, fileName, IN, const osgDB::ReaderWriter::Options *, options, + Properties::NON_VIRTUAL, + __osg_ref_ptrT1_osg_Node___dpReadRefNodeFile__C5_std_string_R1__C5_ReaderWriter_Options_P1, + "", + ""); I_SimpleProperty(bool, Done, __bool__getDone, __void__setDone__bool); diff --git a/src/osgWrappers/osgDB/ReaderWriter.cpp b/src/osgWrappers/osgDB/ReaderWriter.cpp index a1dca549b..b75c29515 100644 --- a/src/osgWrappers/osgDB/ReaderWriter.cpp +++ b/src/osgWrappers/osgDB/ReaderWriter.cpp @@ -198,6 +198,13 @@ BEGIN_ENUM_REFLECTOR(osgDB::ReaderWriter::Options::CacheHintOptions) I_EnumLabel(osgDB::ReaderWriter::Options::CACHE_ALL); END_REFLECTOR +BEGIN_ENUM_REFLECTOR(osgDB::ReaderWriter::Options::BuildKdTreesHint) + I_DeclaringFile("osgDB/ReaderWriter"); + I_EnumLabel(osgDB::ReaderWriter::Options::NO_PREFERENCE); + I_EnumLabel(osgDB::ReaderWriter::Options::DO_NOT_BUILD_KDTREES); + I_EnumLabel(osgDB::ReaderWriter::Options::BUILD_KDTREES); +END_REFLECTOR + BEGIN_OBJECT_REFLECTOR(osgDB::ReaderWriter::Options) I_DeclaringFile("osgDB/ReaderWriter"); I_BaseType(osg::Object); @@ -273,6 +280,16 @@ BEGIN_OBJECT_REFLECTOR(osgDB::ReaderWriter::Options) __CacheHintOptions__getObjectCacheHint, "Get whether the Registry::ObjectCache should be used by default. ", ""); + I_Method1(void, setBuildKdTreesHint, IN, osgDB::ReaderWriter::Options::BuildKdTreesHint, hint, + Properties::NON_VIRTUAL, + __void__setBuildKdTreesHint__BuildKdTreesHint, + "Set whether the KdTrees should be built for geometry in the loader model. ", + ""); + I_Method0(osgDB::ReaderWriter::Options::BuildKdTreesHint, getBuildKdTreesHint, + Properties::NON_VIRTUAL, + __BuildKdTreesHint__getBuildKdTreesHint, + "Get whether the KdTrees should be built for geometry in the loader model. ", + ""); I_Method2(void, setPluginData, IN, const std::string &, s, IN, void *, v, Properties::NON_VIRTUAL, __void__setPluginData__C5_std_string_R1__void_P1, @@ -293,6 +310,9 @@ BEGIN_OBJECT_REFLECTOR(osgDB::ReaderWriter::Options) __void__removePluginData__C5_std_string_R1, "Remove a value from the PluginData. ", ""); + I_SimpleProperty(osgDB::ReaderWriter::Options::BuildKdTreesHint, BuildKdTreesHint, + __BuildKdTreesHint__getBuildKdTreesHint, + __void__setBuildKdTreesHint__BuildKdTreesHint); I_SimpleProperty(const std::string &, DatabasePath, 0, __void__setDatabasePath__C5_std_string_R1); diff --git a/src/osgWrappers/osgDB/Registry.cpp b/src/osgWrappers/osgDB/Registry.cpp index bae7d2af8..d516068c1 100644 --- a/src/osgWrappers/osgDB/Registry.cpp +++ b/src/osgWrappers/osgDB/Registry.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -330,6 +331,31 @@ BEGIN_OBJECT_REFLECTOR(osgDB::Registry) __ReaderWriter_WriteResult__writeShaderImplementation__C5_osg_Shader_R1__C5_std_string_R1__C5_ReaderWriter_Options_P1, "", ""); + I_Method2(void, buildKdTreeIfRequired, IN, osgDB::ReaderWriter::ReadResult &, result, IN, const osgDB::ReaderWriter::Options *, options, + Properties::NON_VIRTUAL, + __void__buildKdTreeIfRequired__ReaderWriter_ReadResult_R1__C5_ReaderWriter_Options_P1, + "", + ""); + I_Method1(void, setBuildKdTreesHint, IN, osgDB::ReaderWriter::Options::BuildKdTreesHint, hint, + Properties::NON_VIRTUAL, + __void__setBuildKdTreesHint__ReaderWriter_Options_BuildKdTreesHint, + "", + ""); + I_Method0(osgDB::ReaderWriter::Options::BuildKdTreesHint, getBuildKdTreesHint, + Properties::NON_VIRTUAL, + __ReaderWriter_Options_BuildKdTreesHint__getBuildKdTreesHint, + "", + ""); + I_Method1(void, setKdTreeBuilder, IN, osg::KdTreeBuilder *, builder, + Properties::NON_VIRTUAL, + __void__setKdTreeBuilder__osg_KdTreeBuilder_P1, + "", + ""); + I_Method0(osg::KdTreeBuilder *, getKdTreeBuilder, + Properties::NON_VIRTUAL, + __osg_KdTreeBuilder_P1__getKdTreeBuilder, + "", + ""); I_Method1(void, setCreateNodeFromImage, IN, bool, flag, Properties::NON_VIRTUAL, __void__setCreateNodeFromImage__bool, @@ -528,6 +554,9 @@ BEGIN_OBJECT_REFLECTOR(osgDB::Registry) __ReaderWriter_ReadResult__readImplementation__C5_ReadFunctor_R1__bool, "", ""); + I_SimpleProperty(osgDB::ReaderWriter::Options::BuildKdTreesHint, BuildKdTreesHint, + __ReaderWriter_Options_BuildKdTreesHint__getBuildKdTreesHint, + __void__setBuildKdTreesHint__ReaderWriter_Options_BuildKdTreesHint); I_SimpleProperty(bool, CreateNodeFromImage, __bool__getCreateNodeFromImage, __void__setCreateNodeFromImage__bool); @@ -537,6 +566,9 @@ BEGIN_OBJECT_REFLECTOR(osgDB::Registry) I_SimpleProperty(osgDB::DatabasePager *, DatabasePager, __DatabasePager_P1__getDatabasePager, __void__setDatabasePager__DatabasePager_P1); + I_SimpleProperty(osg::KdTreeBuilder *, KdTreeBuilder, + __osg_KdTreeBuilder_P1__getKdTreeBuilder, + __void__setKdTreeBuilder__osg_KdTreeBuilder_P1); I_SimpleProperty(const osgDB::FilePathList &, LibraryFilePathList, __C5_FilePathList_R1__getLibraryFilePathList, __void__setLibraryFilePathList__C5_FilePathList_R1); diff --git a/src/osgWrappers/osgGA/DriveManipulator.cpp b/src/osgWrappers/osgGA/DriveManipulator.cpp index 463770b03..83aba6e55 100644 --- a/src/osgWrappers/osgGA/DriveManipulator.cpp +++ b/src/osgWrappers/osgGA/DriveManipulator.cpp @@ -126,6 +126,12 @@ BEGIN_OBJECT_REFLECTOR(osgGA::DriveManipulator) __double__getHeight, "", ""); + I_ProtectedMethod4(bool, intersect, IN, const osg::Vec3d &, start, IN, const osg::Vec3d &, end, IN, osg::Vec3d &, intersection, IN, osg::Vec3d &, normal, + Properties::NON_VIRTUAL, + Properties::CONST, + __bool__intersect__C5_osg_Vec3d_R1__C5_osg_Vec3d_R1__osg_Vec3d_R1__osg_Vec3d_R1, + "", + ""); I_ProtectedMethod0(void, flushMouseEventStack, Properties::NON_VIRTUAL, Properties::NON_CONST, diff --git a/src/osgWrappers/osgGA/TerrainManipulator.cpp b/src/osgWrappers/osgGA/TerrainManipulator.cpp index 7aca1e0cb..063631bd9 100644 --- a/src/osgWrappers/osgGA/TerrainManipulator.cpp +++ b/src/osgWrappers/osgGA/TerrainManipulator.cpp @@ -118,6 +118,12 @@ BEGIN_OBJECT_REFLECTOR(osgGA::TerrainManipulator) __void__getUsage__osg_ApplicationUsage_R1, "Get the keyboard and mouse usage of this manipulator. ", ""); + I_ProtectedMethod3(bool, intersect, IN, const osg::Vec3d &, start, IN, const osg::Vec3d &, end, IN, osg::Vec3d &, intersection, + Properties::NON_VIRTUAL, + Properties::CONST, + __bool__intersect__C5_osg_Vec3d_R1__C5_osg_Vec3d_R1__osg_Vec3d_R1, + "", + ""); I_ProtectedMethod0(void, flushMouseEventStack, Properties::NON_VIRTUAL, Properties::NON_CONST, diff --git a/src/osgWrappers/osgUtil/LineSegmentIntersector.cpp b/src/osgWrappers/osgUtil/LineSegmentIntersector.cpp index ff14ad4aa..cc5558765 100644 --- a/src/osgWrappers/osgUtil/LineSegmentIntersector.cpp +++ b/src/osgWrappers/osgUtil/LineSegmentIntersector.cpp @@ -187,5 +187,3 @@ END_REFLECTOR STD_SET_REFLECTOR(std::multiset< osgUtil::LineSegmentIntersector::Intersection >) -STD_VECTOR_REFLECTOR(std::vector< double >) -