Added prelimnary KdTree data structure and automatic kdtree build support
into osgDB::Registry/osgTerrain so that newly created subgraphs can have KdTree built on all osg::Geometry automatically on load/creation.
This commit is contained in:
@@ -72,6 +72,7 @@ SET(LIB_PUBLIC_HEADERS
|
||||
${HEADER_PATH}/Image
|
||||
${HEADER_PATH}/ImageStream
|
||||
${HEADER_PATH}/io_utils
|
||||
${HEADER_PATH}/KdTree
|
||||
${HEADER_PATH}/Light
|
||||
${HEADER_PATH}/LightModel
|
||||
${HEADER_PATH}/LightSource
|
||||
@@ -228,6 +229,7 @@ ADD_LIBRARY(${LIB_NAME}
|
||||
Hint.cpp
|
||||
Image.cpp
|
||||
ImageStream.cpp
|
||||
KdTree.cpp
|
||||
LOD.cpp
|
||||
Light.cpp
|
||||
LightModel.cpp
|
||||
|
||||
67
src/osg/KdTree.cpp
Normal file
67
src/osg/KdTree.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
||||
*
|
||||
* This library is open source and may be redistributed and/or modified under
|
||||
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
||||
* (at your option) any later version. The full license is in LICENSE file
|
||||
* included with this distribution, and on the openscenegraph.org website.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* OpenSceneGraph Public License for more details.
|
||||
*/
|
||||
|
||||
#include <osg/KdTree>
|
||||
#include <osg/Geode>
|
||||
|
||||
using namespace osg;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// KdTree
|
||||
|
||||
bool KdTree::build(osg::Geometry* geometry)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"KdTree::build("<<geometry<<")"<<std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool KdTree::intersect(const osg::Vec3& start, const osg::Vec3& end, LineSegmentIntersections& intersections)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// KdTreeBuilder
|
||||
KdTreeBuilder::KdTreeBuilder():
|
||||
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
|
||||
_maxNumLevels(16),
|
||||
_targetNumTrianglesPerLeaf(4),
|
||||
_numVerticesProcessed(0)
|
||||
{
|
||||
_kdTreePrototype = new osg::KdTree;
|
||||
}
|
||||
|
||||
|
||||
void KdTreeBuilder::apply(osg::Geode& geode)
|
||||
{
|
||||
for(unsigned int i=0; i<geode.getNumDrawables(); ++i)
|
||||
{
|
||||
|
||||
osg::Geometry* geom = geode.getDrawable(i)->asGeometry();
|
||||
if (geom)
|
||||
{
|
||||
osg::KdTree* previous = dynamic_cast<osg::KdTree*>(geom->getShape());
|
||||
if (previous) continue;
|
||||
|
||||
osg::ref_ptr<osg::KdTree> kdTree = dynamic_cast<osg::KdTree*>(_kdTreePrototype->cloneType());
|
||||
|
||||
if (kdTree->build(geom))
|
||||
{
|
||||
geom->setShape(kdTree.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -158,6 +158,17 @@ Registry::Registry()
|
||||
// comment out because it was causing problems under OSX - causing it to crash osgconv when constructing ostream in osg::notify().
|
||||
// notify(INFO) << "Constructing osg::Registry"<<std::endl;
|
||||
|
||||
_buildKdTreesHint = ReaderWriter::Options::NO_PREFERENCE;
|
||||
_kdTreeBuilder = new osg::KdTreeBuilder;
|
||||
|
||||
const char* kdtree_str = getenv("OSG_BUILD_KDTREES");
|
||||
if (kdtree_str)
|
||||
{
|
||||
bool switchOff = (strcmp(kdtree_str, "off")==0 || strcmp(kdtree_str, "OFF")==0 || strcmp(kdtree_str, "Off")==0 );
|
||||
if (switchOff) _buildKdTreesHint = ReaderWriter::Options::DO_NOT_BUILD_KDTREES;
|
||||
else _buildKdTreesHint = ReaderWriter::Options::BUILD_KDTREES;
|
||||
}
|
||||
|
||||
_createNodeFromImage = false;
|
||||
_openingLibrary = false;
|
||||
|
||||
@@ -166,6 +177,8 @@ Registry::Registry()
|
||||
|
||||
initFilePathLists();
|
||||
|
||||
|
||||
|
||||
// register file extension alias.
|
||||
const char* flt_str = getenv("OSG_OPEN_FLIGHT_PLUGIN");
|
||||
if (flt_str)
|
||||
@@ -388,7 +401,7 @@ void Registry::readCommandLine(osg::ArgumentParser& arguments)
|
||||
|
||||
while(arguments.read("-O",value))
|
||||
{
|
||||
setOptions(new osgDB::ReaderWriter::Options(value));
|
||||
setOptions(new ReaderWriter::Options(value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -642,6 +642,15 @@ void GeometryTechnique::generateGeometry(Locator* masterLocator, const osg::Vec3
|
||||
|
||||
//geometry->setUseDisplayList(false);
|
||||
geometry->setUseVertexBufferObjects(true);
|
||||
|
||||
|
||||
if (osgDB::Registry::instance()->getBuildKdTreesHint()==osgDB::ReaderWriter::Options::BUILD_KDTREES &&
|
||||
osgDB::Registry::instance()->getKdTreeBuilder())
|
||||
{
|
||||
//osg::notify(osg::NOTICE)<<"osgTerrain::GeometryTechnique::build kd tree"<<std::endl;
|
||||
buffer._geode->accept(*(osgDB::Registry::instance()->getKdTreeBuilder()));
|
||||
//osg::notify(osg::NOTICE)<<"after"<<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void GeometryTechnique::applyColorLayers()
|
||||
|
||||
Reference in New Issue
Block a user