Re: [osg-users] computeIntersections performance

2012-01-06 Thread Jen Hunter
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_ptrosgViewer::Viewer viewer = new osgViewer::Viewer();
osg::ref_ptrosg::Group root = new osg::Group;
osg::ref_ptrosg::Node loadedModel = 
osgDB::readNodeFile(modelFile.c_str());
osg::ref_ptrosg::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::vectorImgPoint 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::vectorImgPoint intersectionPoints;
std::vectorosg::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::vectorImgPoint::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::coutNumber Image Points:  points.size()std::endl;
std::coutNumber 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
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] computeIntersections performance

2012-01-05 Thread Robert Osfield
Hi Dakota,

Without knowing more about your model we can't say too much about what
is actually causing the performance to be so poor.  KdTree normally
help with intersection performance in a massive way, and will
typically be hundreds or even thousands of times faster depending on
the nature of the model.

Since you aren't getting speed and slow in the first place I can't
help wonder if there isn't something particular about your model that
is causing problem.  Could it be that you have many long thin
triangles in your scene?

Run you model with osgviewer and bring up the on screen stats by
pressing 's' three times - the will list the scene stats.  How many
geometry, primitives and vertices do you have in the scene?

Robert.

On 14 December 2011 09:40, Jen Hunter jenr...@web.de wrote:
 Hi,

 I'm curious about the time it takes to do intersection testing.

 I have roughly 800 Image points that I need to check for intersection with my 
 model.
 My model isn't really complicated, it's basically just a huge box with a few 
 rectangular elements that stand out a bit.
 It was created using Sketchup and is in Collada file format. I use the method 
 computeIntersections. I'm working with OSG 2.8.2.

 However, even with kdtree support it takes about 120 to 190 ms to test for 
 the 800 intersections.
 Without kdtrees it takes up to above 400 ms. I'm confused that it varies so 
 much when the setup of the scene I tested was always the same.

 I am by no means an expert in computer graphics, so I ask you.
 Is it normal that it takes so long even for kdtrees, or is it likely that I 
 do something terribly wrong?

 Thank you!

 Cheers,
 Dakota

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=44379#44379





 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org
 http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] computeIntersections performance

2012-01-05 Thread Tueller, Shayne R Civ USAF AFMC 519 SMXS/MXDEC
Robert,

I've also seen minimal speedup with KdTree usage (in my case with
terrain). Is there an example where this feature (KdTree usage) is
employed? Perhaps the way it's being used (at least by me) isn't
correct...

-Shayne

-Original Message-
From: osg-users-boun...@lists.openscenegraph.org
[mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Robert
Osfield
Sent: Thursday, January 05, 2012 1:14 PM
To: osg-users@lists.openscenegraph.org
Subject: Re: [osg-users] computeIntersections performance

Hi Dakota,

Without knowing more about your model we can't say too much about what
is actually causing the performance to be so poor.  KdTree normally
help with intersection performance in a massive way, and will
typically be hundreds or even thousands of times faster depending on
the nature of the model.

Since you aren't getting speed and slow in the first place I can't
help wonder if there isn't something particular about your model that
is causing problem.  Could it be that you have many long thin
triangles in your scene?

Run you model with osgviewer and bring up the on screen stats by
pressing 's' three times - the will list the scene stats.  How many
geometry, primitives and vertices do you have in the scene?

Robert.

On 14 December 2011 09:40, Jen Hunter jenr...@web.de wrote:
 Hi,

 I'm curious about the time it takes to do intersection testing.

 I have roughly 800 Image points that I need to check for intersection
with my model.
 My model isn't really complicated, it's basically just a huge box with
a few rectangular elements that stand out a bit.
 It was created using Sketchup and is in Collada file format. I use the
method computeIntersections. I'm working with OSG 2.8.2.

 However, even with kdtree support it takes about 120 to 190 ms to test
for the 800 intersections.
 Without kdtrees it takes up to above 400 ms. I'm confused that it
varies so much when the setup of the scene I tested was always the same.

 I am by no means an expert in computer graphics, so I ask you.
 Is it normal that it takes so long even for kdtrees, or is it likely
that I do something terribly wrong?

 Thank you!

 Cheers,
 Dakota

 --
 Read this topic online here:
 http://forum.openscenegraph.org/viewtopic.php?p=44379#44379





 ___
 osg-users mailing list
 osg-users@lists.openscenegraph.org

http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or
g
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.or
g
___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] computeIntersections performance

2011-12-14 Thread Jen Hunter
Hi,

I'm curious about the time it takes to do intersection testing.

I have roughly 800 Image points that I need to check for intersection with my 
model.
My model isn't really complicated, it's basically just a huge box with a few 
rectangular elements that stand out a bit.
It was created using Sketchup and is in Collada file format. I use the method 
computeIntersections. I'm working with OSG 2.8.2.

However, even with kdtree support it takes about 120 to 190 ms to test for the 
800 intersections.
Without kdtrees it takes up to above 400 ms. I'm confused that it varies so 
much when the setup of the scene I tested was always the same.

I am by no means an expert in computer graphics, so I ask you. 
Is it normal that it takes so long even for kdtrees, or is it likely that I do 
something terribly wrong?

Thank you!

Cheers,
Dakota

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=44379#44379





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org