Added --points and --lines command line options that do a very simplistic conversion of geometry primitives to points or lines respectively, used to aid testing of intersectors

This commit is contained in:
Robert Osfield
2017-05-09 11:33:22 +01:00
parent 03f73d3aad
commit 6e1866ac18
5 changed files with 937 additions and 1441 deletions

View File

@@ -408,6 +408,36 @@ protected:
};
class ConvertPrimitives : public osg::NodeVisitor
{
public:
osg::PrimitiveSet::Mode _mode;
ConvertPrimitives(osg::PrimitiveSet::Mode mode):
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
_mode(mode) {}
void apply(osg::Geometry& geometry)
{
if (!geometry.getVertexArray()) return;
unsigned int numVertices = geometry.getVertexArray()->getNumElements();
if (_mode==osg::PrimitiveSet::POINTS)
{
// remove previous primitive sets.
geometry.removePrimitiveSet(0, geometry.getNumPrimitiveSets());
geometry.addPrimitiveSet(new osg::DrawArrays(_mode, 0,numVertices));
}
else if (_mode==osg::PrimitiveSet::LINES)
{
geometry.removePrimitiveSet(0, geometry.getNumPrimitiveSets());
geometry.addPrimitiveSet(new osg::DrawArrays(_mode, 0,numVertices));
}
}
};
int main( int argc, char **argv )
{
osg::ArgumentParser arguments(&argc, argv);
@@ -433,6 +463,9 @@ int main( int argc, char **argv )
return 1;
}
while(arguments.read("--points")) { ConvertPrimitives cp(osg::PrimitiveSet::POINTS); loadedModel->accept(cp); }
while(arguments.read("--lines")) { ConvertPrimitives cp(osg::PrimitiveSet::LINES); loadedModel->accept(cp); }
if (useKdTree)
{
OSG_NOTICE<<"Buildering KdTrees"<<std::endl;
@@ -440,6 +473,7 @@ int main( int argc, char **argv )
loadedModel->accept(*builder);
}
// assign the scene graph to viewer
viewer.setSceneData(loadedModel);