Hi Robert,
thanks for your reply. :)
The stats of my scene are as follows:
Stateset: 17
Group: 7
Transform: 5
LOD: 0
Switch: 0
Geode: 57
Drawable: 175
Geometry: 175
Vertices: 10508
Primitives: 3993
I guess the model isn't as simple as described it. ;)
However, I really thinks it still isn't a very complex model, compared to 3D
buildings or industrial gadgets.
I tested it also with the dumptruck and cow osg files and the speed outcome is
quite similiar.
I made an example programm using the cow:
Code:
#include <windows.h>
#include <iostream>
#include <vector>
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osg/io_utils>
#include <osg/MatrixTransform>
#include <osg/Geode>
#include <osg/Group>
#include <osgDB/ReadFile>
int width = 640;
int height = 480;
std::string modelFile = "cow.osg";
int main(int , char **){
//KD-Tree usage
osgDB::Registry::instance()->setBuildKdTreesHint(osgDB::ReaderWriter::Options::BUILD_KDTREES);
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer();
osg::ref_ptr<osg::Group> root = new osg::Group;
osg::ref_ptr<osg::Node> loadedModel =
osgDB::readNodeFile(modelFile.c_str());
osg::ref_ptr<osg::MatrixTransform> arTransform = new
osg::MatrixTransform();
arTransform->getOrCreateStateSet()->setRenderBinDetails(100,
"RenderBin");
arTransform->addChild(loadedModel);
root->addChild(arTransform.get());
viewer->setSceneData(root.get());
viewer->addEventHandler(new osgViewer::StatsHandler);
viewer->setUpViewInWindow(200, 200, width, height);
osg::Matrix trans;
trans.makeTranslate( 0., 0., -12. );
osg::Matrix rot;
rot.makeRotate(
osg::DegreesToRadians(-90.0), osg::Vec3(1,0,0),
osg::DegreesToRadians(0.0), osg::Vec3(0,1,0) ,
osg::DegreesToRadians(0.0), osg::Vec3(0,0,1) );
viewer->getCamera()->setViewMatrix(rot * trans);
// -------- generate random image points ---------
struct ImgPoint{
double x;
double y;
};
int numImagePoints = 800;
srand((unsigned)time(0));
std::vector<ImgPoint> points;
for (int i = 0; i < numImagePoints; i++) {
ImgPoint p = {(rand()/(double)RAND_MAX)*width,
(rand()/(double)RAND_MAX)*height };
points.push_back(p);
}
// -------- intersections ---------
std::vector<ImgPoint> intersectionPoints;
std::vector<osg::Vec3d> modelPoints;
//necessary so that Y values won't be inverted if there hasn't been
mouse interaction yet
viewer->getEventQueue()->getCurrentEventState()->setMouseYOrientation(
osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS );
//time start
LONGLONG g_Frequency, g_CurentCount, g_LastCount;
if (!QueryPerformanceFrequency((LARGE_INTEGER*)&g_Frequency))
printf("%s\n", "Performance Counter nicht vorhanden");
QueryPerformanceCounter((LARGE_INTEGER*)&g_CurentCount);
osgUtil::LineSegmentIntersector::Intersections intersections;
std::vector<ImgPoint>::iterator myPointVectorIterator;
for(myPointVectorIterator = points.begin(); myPointVectorIterator !=
points.end(); myPointVectorIterator++){
if(viewer->computeIntersections(myPointVectorIterator->x,
myPointVectorIterator->y, intersections)){
intersectionPoints.push_back(*myPointVectorIterator);
osgUtil::LineSegmentIntersector::Intersection
first = *(intersections.begin());
modelPoints.push_back(first.getWorldIntersectPoint());
}
}
//time stop
QueryPerformanceCounter((LARGE_INTEGER*)&g_LastCount);
double dTimeDiff =
(((double)(g_LastCount-g_CurentCount))/((double)g_Frequency));
dTimeDiff = dTimeDiff * 1000;
printf("%s %s %f \n", "Intersection:", "(ms): \n", dTimeDiff);
std::cout<<"Number Image Points: "<< points.size()<<std::endl;
std::cout<<"Number Model Points intersected : "<<
modelPoints.size()<<std::endl;
while (!viewer->done()){
viewer->frame();
}
}
Maybe I do something wrong. The only line I use for KD Tree usage is the first
line in main. Is that correct?
Or is geometry like the model I have or cow or dumptruck already to complex too
use for realtime intersection testing with ~800 points?
Thanks!
Cheers,
Jen
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=44668#44668
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org