Re: [osg-users] LineSegmentIntersector gives incorrect results (intersections missing)

2013-08-01 Thread Robert Osfield
Hi Jaap,

In svn/trunk I've introduced the ability to set the Eplsion value to a
user specified value rather than the default of 1e-4, this may not be
an ideal solution though, I'd much rather have the code work with
defaults correctly.

The clipping of the line length to the bounding box is done to make it
more likely that intersection tests will be more rejected more quickly
so speeding up the intersections.  We could add an option to disable
this clipping and explore just much of an impact it has.

Scaling the epsilion by the size of the bounding box is a possibility,
but this would cause problems with small objects but with relatively
large xyz values.  One could possible have a constant and scaled
epsilon term to get round this.

A double version of the intersection functions wold be another possibility.

Robert.

On 16 May 2013 09:07, Jaap Glas jaap.g...@dgbes.com wrote:
 Dear Peter, Robert, and all.

 I would like to endorse Peter's remarks on the current implementation of
 the LineSegmentIntersector. We experience precisely the same problems when
 trying to pick on plane faces that coincide with the bounding box of the
 Drawable to which they belong. The simplest example is a drawable consisting
 of one triangle or quad aligning with the axes of the local coordinate frame.

 Like Peter, we are also dealing with co-ordinate values running into the
 thousands. The applied epsilon of 1e-4 in the intersectAndClip() function
 is too small in suchlike cases, especially if the TriangleIntersector keeps
 using floats at some places.

 For the moment, we circumvent the problem by overloading the computeBound()
 function of the Drawable and return a slightly bigger bounding box ourselves,
 but a more general solution would be better in the end.

 Like Peter, I also do not see why the intersectAndClip() function should
 cut off those parts of the line segment that are outside the bounding box.
 What is the computational benefit of this later on? I would expect it is
 sufficient to check whether the line segment is crossing the box or not,
 and neglect Drawables for which the answer is false.

 However, assuming that this clipping does serve a goal, then my choice
 would be not to assign the epsilon in the intersectAndClip() function
 an absolute value, but to make it relative to the bounding box size,
 for example by multiplying the current epsilon of 1e-4 with the diagonal
 length of the bounding box.


 Best regards,

 Jaap Glas

 dGB Earth Sciences
 Enschede, The Netherlands

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





 ___
 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] LineSegmentIntersector gives incorrect results (intersections missing)

2013-07-31 Thread Jaap Glas
Dear Peter, Robert, and all.

I would like to endorse Peter's remarks on the current implementation of
the LineSegmentIntersector. We experience precisely the same problems when  
trying to pick on plane faces that coincide with the bounding box of the
Drawable to which they belong. The simplest example is a drawable consisting
of one triangle or quad aligning with the axes of the local coordinate frame.   

Like Peter, we are also dealing with co-ordinate values running into the
thousands. The applied epsilon of 1e-4 in the intersectAndClip() function   
is too small in suchlike cases, especially if the TriangleIntersector keeps 
using floats at some places.

For the moment, we circumvent the problem by overloading the computeBound() 
function of the Drawable and return a slightly bigger bounding box ourselves,   
but a more general solution would be better in the end. 

Like Peter, I also do not see why the intersectAndClip() function should
cut off those parts of the line segment that are outside the bounding box.  
What is the computational benefit of this later on? I would expect it is
sufficient to check whether the line segment is crossing the box or not,
and neglect Drawables for which the answer is false.

However, assuming that this clipping does serve a goal, then my choice  
would be not to assign the epsilon in the intersectAndClip() function   
an absolute value, but to make it relative to the bounding box size,
for example by multiplying the current epsilon of 1e-4 with the diagonal
length of the bounding box. 


Best regards,   

Jaap Glas   

dGB Earth Sciences  
Enschede, The Netherlands

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





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


Re: [osg-users] LineSegmentIntersector gives incorrect results (intersections missing)

2012-11-16 Thread Peter Bako
Hello Robert.

I digged a bit into the OSG source code and I found out that its a precision 
problem. I use big models where the vertex coordinate values are 1000.
I don't know the exact process of the intersection search, but I assume that 
the lineSegment is clipped in the  

lineSegmentIntersector.cpp

Code:
bool LineSegmentIntersector::intersectAndClip(osg::Vec3d s, osg::Vec3d 
e,const osg::BoundingBox bbInput)

 
function to the values, where the lineSegment is slightly longer, than the 
bounding sphere of the geometry. 

Code:
 osg::Vec3d bb_min(bbInput._min);
osg::Vec3d bb_max(bbInput._max);

#if 1
double epsilon = 1e-4;
bb_min.x() -= epsilon;
bb_min.y() -= epsilon;
bb_min.z() -= epsilon;
bb_max.x() += epsilon;
bb_max.y() += epsilon;
bb_max.z() += epsilon;
#endif



There is an epsilon value, which is currently set to 1e-4. I would suggest to 
set it bigger (1e-2 f. ex.). If I change it to 1e-2, I don't get this problem 
anymore.

What is the exact reason of lineSegment clipping?

Thank you!

Cheers,
Peter
Code:




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





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


Re: [osg-users] LineSegmentIntersector gives incorrect results (intersections missing)

2012-10-25 Thread Robert Osfield
HI Peter,

I'm afraid I've not got enough time available to look into this
problem right now, hopefully others can dive in.  My suspicision is
that due to nuermical precision issues on constructing the linesegment
and/or intersecting this with the bonding volumes or meshes you aren't
always getting the intersections you expect.  A quick hack to test
this would be to rotate the mesh slightly so nothing is axis aligned -
this way the mesh won't be setting on the face of the bounding volume.
 If this hack does prove to address the problem then it points the
need of doing interesection testing with error bars that are larger
than the numberic precision errors.

Robert.

On 23 October 2012 09:21, Peter Bako osgfo...@tevs.eu wrote:
 I use the LineSegmentIntersector in my application to select planar faces. 
 The problem is that sometimes when I click on the face facing to you (check 
 the red Xes on the picture), I get no intersection of this face. I get only 
 an intersection on the face which is not visible from this view - the 
 bottom face.
 Then sometimes it happens, that the user wants to select a face, but an 
 invisible face is selected instead, but he doesn't know it because he 
 doesn't see it, even if its highlighted.

 i made this sample application to simulate my problem - when I click on the 
 positions where the red crosses are, normally I should get 2 intersections - 
 first the face where I drew the red crosses and then to bottom face which we 
 don't see. Sometimes, I get only the second (see the debug output on the 
 picture).

 I think this is a problem.

 Thank you!

 Cheers,
 Peter

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





 ___
 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] LineSegmentIntersector gives incorrect results (intersections missing)

2012-10-23 Thread Peter Bako
I use the LineSegmentIntersector in my application to select planar faces. The 
problem is that sometimes when I click on the face facing to you (check the 
red Xes on the picture), I get no intersection of this face. I get only an 
intersection on the face which is not visible from this view - the bottom 
face. 
Then sometimes it happens, that the user wants to select a face, but an 
invisible face is selected instead, but he doesn't know it because he doesn't 
see it, even if its highlighted.

i made this sample application to simulate my problem - when I click on the 
positions where the red crosses are, normally I should get 2 intersections - 
first the face where I drew the red crosses and then to bottom face which we 
don't see. Sometimes, I get only the second (see the debug output on the 
picture).

I think this is a problem.

Thank you!

Cheers,
Peter

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





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


Re: [osg-users] LineSegmentIntersector gives incorrect results (intersections missing)

2012-10-22 Thread Robert Osfield
Hi Peter,

I can't specifically say what you are seeing a problem, but it does
rather sound like a precision issue with projecting the mouse poistion
into clip space and then to world and final object coordinates.

Robert.

On 17 October 2012 14:19, Peter Bako osgfo...@tevs.eu wrote:
 Hi,

 I've got a problem with line segment intersector. Sometimes I get only one 
 intersection (on the bootom side of the table), while I should get two.
 Please check the screenshot.

 Do you have any idea why this happens? What should I do?
 STLFILE.stl (ZIPPED) is attached
 Thank you!

 Cheers,
 Peter

 Hold CTRL key to activate intersection output.
 This is the code I use:

 Code:
 #include stdafx.h
 #include osgViewer/Viewer
 #include osgDB/ReadFile
 #include osgUtil/LineSegmentIntersector


 class PickHandler : public osgGA::GUIEventHandler
 {
 public:

 virtual bool handle( const osgGA::GUIEventAdapter ea, 
 osgGA::GUIActionAdapter aa )
 {
 if ( ea.getEventType()!=osgGA::GUIEventAdapter::RELEASE ||
  ea.getButton()!=osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON ||
  !(ea.getModKeyMask()osgGA::GUIEventAdapter::MODKEY_CTRL) )
 return false;

 osgViewer::Viewer* viewer = dynamic_castosgViewer::Viewer*(aa);
 if ( viewer ){
 osg::ref_ptrosgUtil::LineSegmentIntersector intersector =
 new 
 osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, ea.getX(), 
 ea.getY());
 osgUtil::IntersectionVisitor iv( intersector.get() );
 iv.setTraversalMask( ~0x1 );
 viewer-getCamera()-accept( iv );

 if ( intersector-containsIntersections() ){
 const 
 osgUtil::LineSegmentIntersector::Intersection result =
 *(intersector-getIntersections().begin());
 printf(Intersection count:%d. Coordinates: %.2f, %.2f, 
 %.2f\n,
 
 intersector-getIntersections().size(), 
 result.getWorldIntersectPoint().x(),result.getWorldIntersectPoint().y(),result.getWorldIntersectPoint().z());

 }
 }
 return false;
 }

 };

 int main( int argc, char** argv )
 {
 osg::ref_ptrosg::Node model1 = osgDB::readNodeFile( STLFILE.stl );
 osg::ref_ptrosg::Group root = new osg::Group;
 root-addChild( model1.get() );
 osg::ref_ptrPickHandler picker = new PickHandler;
 osgViewer::Viewer viewer;
 viewer.setSceneData( root.get() );
 viewer.addEventHandler( picker.get() );
 return viewer.run();
 }




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




 Attachments:
 http://forum.openscenegraph.org//files/intersection_errors_639.png
 http://forum.openscenegraph.org//files/stlfile_974.zip


 ___
 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


[osg-users] LineSegmentIntersector gives incorrect results (intersections missing)

2012-10-17 Thread Peter Bako
Hi,

I've got a problem with line segment intersector. Sometimes I get only one 
intersection (on the bootom side of the table), while I should get two. 
Please check the screenshot.

Do you have any idea why this happens? What should I do?
STLFILE.stl (ZIPPED) is attached
Thank you!

Cheers,
Peter

Hold CTRL key to activate intersection output.
This is the code I use:

Code:
#include stdafx.h
#include osgViewer/Viewer
#include osgDB/ReadFile
#include osgUtil/LineSegmentIntersector


class PickHandler : public osgGA::GUIEventHandler
{
public:
  
virtual bool handle( const osgGA::GUIEventAdapter ea, 
osgGA::GUIActionAdapter aa )
{
if ( ea.getEventType()!=osgGA::GUIEventAdapter::RELEASE ||
 ea.getButton()!=osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON ||
 !(ea.getModKeyMask()osgGA::GUIEventAdapter::MODKEY_CTRL) )
return false;

osgViewer::Viewer* viewer = dynamic_castosgViewer::Viewer*(aa);
if ( viewer ){
osg::ref_ptrosgUtil::LineSegmentIntersector intersector =
new 
osgUtil::LineSegmentIntersector(osgUtil::Intersector::WINDOW, ea.getX(), 
ea.getY());
osgUtil::IntersectionVisitor iv( intersector.get() );
iv.setTraversalMask( ~0x1 );
viewer-getCamera()-accept( iv );

if ( intersector-containsIntersections() ){
const 
osgUtil::LineSegmentIntersector::Intersection result =
*(intersector-getIntersections().begin());
printf(Intersection count:%d. Coordinates: %.2f, %.2f, 
%.2f\n, 
intersector-getIntersections().size(), 
result.getWorldIntersectPoint().x(),result.getWorldIntersectPoint().y(),result.getWorldIntersectPoint().z());

}
}
return false;
}

};

int main( int argc, char** argv )
{
osg::ref_ptrosg::Node model1 = osgDB::readNodeFile( STLFILE.stl );
osg::ref_ptrosg::Group root = new osg::Group;
root-addChild( model1.get() );
osg::ref_ptrPickHandler picker = new PickHandler;
osgViewer::Viewer viewer;
viewer.setSceneData( root.get() );
viewer.addEventHandler( picker.get() );
return viewer.run();
}




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




Attachments: 
http://forum.openscenegraph.org//files/intersection_errors_639.png
http://forum.openscenegraph.org//files/stlfile_974.zip


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