Re: [osg-users] osgUtil::IntersectionVisitor slow with huge geometry

2017-07-18 Thread Gianni Ambrosio
Debugging the OSG code it seems most of time spent before seeing the picked 
triangle with adifferent color is inside "ViewerBase::renderingTraversals()", 
and exactly in the following line:

if (_endDynamicDrawBlock.valid())
{
_endDynamicDrawBlock->block(); // <-- HERE!
}

Any idea?

Regards,
Gianni

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





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


Re: [osg-users] osgUtil::IntersectionVisitor slow with huge geometry

2017-07-18 Thread Gianni Ambrosio
Just an update.
OSG KdTree works great!

Computational time for "camera->accept(intersectionVisitor)":
before it was about 10M microseconds
with KdTree it is about 25 microseconds!

This is the code I modified in my example:

Code:

osg::Node* createScene() {
osg::Geode* geode = new osg::Geode;
   osg::KdTree* kdtree = new osg::KdTree;
   osg::Geometry* geometry = buildGeometry();
   osg::KdTree::BuildOptions buildOptions;
   kdtree->build(buildOptions, geometry);
   geometry->setShape(kdtree);
geode->addDrawable(geometry);
return geode;
}




Gianni

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





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


Re: [osg-users] osgUtil::IntersectionVisitor slow with huge geometry

2017-07-18 Thread Gianni Ambrosio
Thanks Jordi for the fast reply.
I will try with Kdtrees. In fact USE_FLOAT_CALCULATIONS does not help much.

I have one more issue.
As you can see in my previously attached example, after mouse picking, I 
basically set:

geometry->dirtyDisplayList();
geometry->getColorArray()->dirty();

Those methods are pretty fast but in fact I have a delay of about one second on 
my PC (some seconds on other PCs) before seeing the picked triangle with a 
different color. Is there an obvious reason for that delay?


Regards,
Gianni

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





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


Re: [osg-users] osgUtil::IntersectionVisitor slow with huge geometry

2017-07-18 Thread Jordi Torres
HI Gianni,

For faster intersections it is far better to build the kdtree first. Also
splitting your huge geometry in several could help to traverse the graph in
case you don't want to use kdtrees.

Cheers.

2017-07-18 12:17 GMT+02:00 Gianni Ambrosio :

> Hi All,
> I built a test geometry with about 9M triangles and 27M vertices. The
> intent of my spike solution (attached) is to select a triangle with mouse
> to change its color. I realized that the bottleneck of that code is the
> line where the camera accepts the "osgUtil::IntersectionVisitor" (line 51:
> camera->accept(iv)). That call takes most of the computation time.
> Debugging the OSG code I fall into:
>
> void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv,
> osg::Drawable* drawable, const osg::Vec3d& s, const osg::Vec3d& e)
>
> In that code there are different methods to be used: KdTree,
> USE_DOUBLE_CALCULATIONS or USE_FLOAT_CALCULATIONS.
> On the basis of your experience, is one of the previous method ideal to
> solve my performance issue or something else must be done?
>
> Best regards,
> Gianni
>
> --
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=71281#71281
>
>
>
>
> ___
> osg-users mailing list
> osg-users@lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>


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


[osg-users] osgUtil::IntersectionVisitor slow with huge geometry

2017-07-18 Thread Gianni Ambrosio
Hi All,
I built a test geometry with about 9M triangles and 27M vertices. The intent of 
my spike solution (attached) is to select a triangle with mouse to change its 
color. I realized that the bottleneck of that code is the line where the camera 
accepts the "osgUtil::IntersectionVisitor" (line 51: camera->accept(iv)). That 
call takes most of the computation time.
Debugging the OSG code I fall into:

void LineSegmentIntersector::intersect(osgUtil::IntersectionVisitor& iv, 
osg::Drawable* drawable, const osg::Vec3d& s, const osg::Vec3d& e)

In that code there are different methods to be used: KdTree, 
USE_DOUBLE_CALCULATIONS or USE_FLOAT_CALCULATIONS.
On the basis of your experience, is one of the previous method ideal to solve 
my performance issue or something else must be done?

Best regards,
Gianni

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



// materials.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include 

#include 

#include 
#include 
#include 
#include 

#include 
#include 

#include 
#include 
#include 
#include 
#include 
#include 

#include 
#include 

#include 

class SelectModelHandler : public osgGA::GUIEventHandler
{
public:
SelectModelHandler()
: selectedColor(0.5f, 0.5f, 0.5f, 1.0f)
{}

virtual bool handle(const osgGA::GUIEventAdapter& ea, 
osgGA::GUIActionAdapter& aa)
{
if (ea.getEventType() == osgGA::GUIEventAdapter::MOVE &&
ea.getModKeyMask() & 
osgGA::GUIEventAdapter::MODKEY_CTRL)
{
osgViewer::View* viewer = 
dynamic_cast();
if (viewer)
{
std::chrono::steady_clock::time_point start1 = 
std::chrono::steady_clock::now();
osg::ref_ptr intersector = new 
osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, ea.getX(), 
ea.getY());
osgUtil::IntersectionVisitor 
iv(intersector.get());
osg::Camera* camera = viewer->getCamera();
std::chrono::steady_clock::time_point end1 = 
std::chrono::steady_clock::now();
std::cout << "Intersector creation took " << 
std::chrono::duration_cast(end1 - start1).count() << 
" us.\n";
std::chrono::steady_clock::time_point  start2 = 
std::chrono::steady_clock::now();
camera->accept(iv);
std::chrono::steady_clock::time_point  end2 = 
std::chrono::steady_clock::now();
std::cout << "Camera accept took " << 
std::chrono::duration_cast(end2 - start2).count() << 
" us.\n";
std::chrono::steady_clock::time_point start3 = 
std::chrono::steady_clock::now();
if (intersector->containsIntersections())
{

osgUtil::LineSegmentIntersector::Intersections& intersections = 
intersector->getIntersections();

osgUtil::LineSegmentIntersector::Intersection result = *(intersections.begin());
doUserOperationsColor(result);
}
std::chrono::steady_clock::time_point  end3 = 
std::chrono::steady_clock::now();
std::cout << "Apply color to geometry took " << 
std::chrono::duration_cast(end3 - start3).count() << 
" us.\n";
 }
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_0) {
selectedColor.set(0.5f, 0.5f, 0.5f, 1.0f);
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_1) {
selectedColor.set(1.0f, 0.0f, 0.0f, 1.0f);
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_2) {
selectedColor.set(0.0f, 1.0f, 0.0f, 1.0f);
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_3) {
selectedColor.set(0.0f, 0.0f, 1.0f, 1.0f);
}
if (ea.getKey() == osgGA::GUIEventAdapter::KEY_4) {
selectedColor.set(1.0f, 0.0f, 1.0f, 1.0f);
}
return false;
}

virtual void 
doUserOperationsColor(osgUtil::LineSegmentIntersector::Intersection& result)
{
osg::Geometry* geom = 
dynamic_cast(result.drawable.get());
osg::Vec4Array& color = 
dynamic_cast(*geom->getColorArray());
color[result.indexList[0]] = selectedColor;
color[result.indexList[1]] = selectedColor;
color[result.indexList[2]] = selectedColor;
geom->dirtyDisplayList();
color.dirty();
}

protected:
osg::Vec4 selectedColor;
};

osg::Vec3Array*