Re: [osg-users] LineSegmentIntersector bug?

2014-10-06 Thread Robert Osfield
HI ? Could you sign your post so we know how to address you :-)

From the description of the problem it looks likely to be a precision issue
where the line segment aligns right along the edge between two triangles
with neither triangle passing the test.

In the svn/trunk version of the OSG there is a
IntersectionVisitor::setPrecisionHint(PrecisionHint hint) method that you
can use to hint to the intersectors to use double maths.  The
LineSegmentIntersector supports this.

Could you try this out to see if it helps?
Robert.

On 5 October 2014 09:51, weijianggood weijiangg...@163.com wrote:


 Hi,
 When i use LineSegmentIntersector in the following code.
 there must be 8 lines. but after I run the code, only 7 lines exist.

 [image: Lines.png]

  int main( int argc, char** argv ){

 float height = 5.f;

 osg::ref_ptrosg::TessellationHints hints;
 hints = new osg::TessellationHints;
 hints-setDetailRatio(0.5f);
 hints-setCreateBody(true);
 hints-setCreateBottom(false);
 hints-setCreateTop(false);
 osg::ref_ptrosg::Geode mynode = new osg::Geode;

 osg::ref_ptrosg::ShapeDrawable drawable = new 
 osg::ShapeDrawable(new 
 osg::Cylinder(osg::Vec3(0.0f,0.0f,0.0f),1.0f,height),hints);

 osg::ref_ptrosg::ShapeDrawable drawable2 = new 
 osg::ShapeDrawable(new 
 osg::Cylinder(osg::Vec3(0.0f,0.0f,0.0f),4.0f,height),hints);

 mynode-addDrawable(drawable.get());// geom.get() or gemo. 
 both are ok.
 mynode-addDrawable(drawable2.get());

 osg::ref_ptrosg::Group root = new osg::Group;
 root-addChild(mynode.get() );
 float angle = 0.0;
 float angleDelta = 2.0f*osg::PI/8;

 for(int i=0; i8;i++){
 float c = cosf(angle);
 float s = sinf(angle);

 osg::ref_ptrosgUtil::LineSegmentIntersector intersector = 
 new osgUtil::LineSegmentIntersector( osg::Vec3(0.0f,0.0f,0.0f),  
 osg::Vec3(10.0f*c,10.0f*s,0.0f) );

 osgUtil::IntersectionVisitor iv( intersector.get() );
 mynode-accept( iv );

 if ( intersector-containsIntersections() )
 {
 osgUtil::LineSegmentIntersector::Intersections

 intersections = 
 intersector-getIntersections();

 std::cout intersection size 
 intersections.size()std::endl;

 osg::ref_ptrosg::Geode  geode=new osg::Geode;
 osg::ref_ptrosg::Geometry geom=new osg::Geometry;

 osg::ref_ptrosg::Vec3Array v3a=new osg::Vec3Array;

 osg::ref_ptrosg::Vec4Array colors = new 
 osg::Vec4Array;
 colors-push_back( osg::Vec4(1.0, 0.0, 0.0, 1.0) );


 
 osgUtil::LineSegmentIntersector::Intersections::iterator itr;

 for ( itr = intersections.begin(); itr != 
 intersections.end(); ++itr ) {

 std::cout  X  
 itr-getWorldIntersectPoint().x()

   Y   
 itr-getWorldIntersectPoint().y()

   Z  
 itr-getWorldIntersectPoint().z();
 if(itr == intersections.begin())

 v3a-push_back( 
 itr-getWorldIntersectPoint());

 }
 itr--;

 v3a-push_back( 
 itr-getWorldIntersectPoint());
 std::coutstd::endl;
 geom-setVertexArray(v3a);
 geom-setColorArray(colors.get() );
 geom-setColorBinding(osg::Geometry::BIND_OVERALL);
 for(int k=0; kv3a-size(); k++){

 std::coutvectex: v3a-at(k).x() 
 v3a-at(k).y() v3a-at(k).z();
 }
 std::coutstd::endl;

 geom-addPrimitiveSet(new 
 osg::DrawArrays(osg::PrimitiveSet::LINES,0,v3a-size()));
 geode-addDrawable(geom);
 root-addChild(geode);
 }else{
 std::coutno intersection for i=istd::endl;

 std::coutx intersector-getStart().x() y 
 intersector-getStart().y() z intersector-getStart().z()std::endl;

 std::coutx intersector-getEnd().x() y 
 intersector-getEnd().y() z intersector-getEnd().z()std::endl;
 }
 angle+=angleDelta;
 }
 osgViewer::Viewer viewer;
 viewer.setSceneData(root.get());
 viewer.addEventHandler(new osgViewer::WindowSizeHandler);
 return viewer.run();

 }

 Thanks.

 --


 ___
 osg-users mailing list
 

Re: [osg-users] LineSegmentIntersector bug?

2014-10-06 Thread weijianggood
Hello, Robert,

Thank you for the suggestion.
Currently, I am using osg3.0.1, intersector does not have the function 
setPrecisionHint.
So I download the newest  version of osg from svn, then compile it.

Finally,
I add  the following line into my test code:
intersector-setPrecisionHint(osgUtil::Intersector::PrecisionHint::USE_DOUBLE_CALCULATIONS);
 
It worked. Woo!  
Thanks again.

Rubby








From: Robert Osfield
Date: 2014-10-06 16:22
To: OpenSceneGraph Users
Subject: Re: [osg-users] LineSegmentIntersector bug?
HI ? Could you sign your post so we know how to address you :-)


From the description of the problem it looks likely to be a precision issue 
where the line segment aligns right along the edge between two triangles with 
neither triangle passing the test.


In the svn/trunk version of the OSG there is a 
IntersectionVisitor::setPrecisionHint(PrecisionHint hint) method that you can 
use to hint to the intersectors to use double maths.  The 
LineSegmentIntersector supports this.


Could you try this out to see if it helps?

Robert.



On 5 October 2014 09:51, weijianggood weijiangg...@163.com wrote:


Hi,
When i use LineSegmentIntersector in the following code.
there must be 8 lines. but after I run the code, only 7 lines exist.



int main( int argc, char** argv ){

float height = 5.f;

osg::ref_ptrosg::TessellationHints hints;
hints = new osg::TessellationHints;
hints-setDetailRatio(0.5f);
hints-setCreateBody(true);
hints-setCreateBottom(false);
hints-setCreateTop(false);
osg::ref_ptrosg::Geode mynode = new osg::Geode;
osg::ref_ptrosg::ShapeDrawable drawable = new osg::ShapeDrawable(new 
osg::Cylinder(osg::Vec3(0.0f,0.0f,0.0f),1.0f,height),hints);
osg::ref_ptrosg::ShapeDrawable drawable2 = new osg::ShapeDrawable(new 
osg::Cylinder(osg::Vec3(0.0f,0.0f,0.0f),4.0f,height),hints);
mynode-addDrawable(drawable.get());// geom.get() or gemo. both 
are ok. 
mynode-addDrawable(drawable2.get());

osg::ref_ptrosg::Group root = new osg::Group;
root-addChild(mynode.get() );
float angle = 0.0;
float angleDelta = 2.0f*osg::PI/8;

for(int i=0; i8;i++){  
float c = cosf(angle);
float s = sinf(angle);
osg::ref_ptrosgUtil::LineSegmentIntersector intersector = new 
osgUtil::LineSegmentIntersector( osg::Vec3(0.0f,0.0f,0.0f),  
osg::Vec3(10.0f*c,10.0f*s,0.0f) );

osgUtil::IntersectionVisitor iv( intersector.get() );
mynode-accept( iv );

if ( intersector-containsIntersections() )
{
osgUtil::LineSegmentIntersector::Intersections
intersections = 
intersector-getIntersections();
std::cout intersection size 
intersections.size()std::endl;

osg::ref_ptrosg::Geode  geode=new osg::Geode;
osg::ref_ptrosg::Geometry geom=new osg::Geometry;
osg::ref_ptrosg::Vec3Array v3a=new osg::Vec3Array;
osg::ref_ptrosg::Vec4Array colors = new 
osg::Vec4Array;
colors-push_back( osg::Vec4(1.0, 0.0, 0.0, 1.0) );


osgUtil::LineSegmentIntersector::Intersections::iterator itr;
for ( itr = intersections.begin(); itr != 
intersections.end(); ++itr ) {
std::cout  X  
itr-getWorldIntersectPoint().x()
  Y   
itr-getWorldIntersectPoint().y()
  Z  
itr-getWorldIntersectPoint().z();
if(itr == intersections.begin())
v3a-push_back( 
itr-getWorldIntersectPoint());

}
itr--;
v3a-push_back( itr-getWorldIntersectPoint());
std::coutstd::endl;
geom-setVertexArray(v3a);
geom-setColorArray(colors.get() );
geom-setColorBinding(osg::Geometry::BIND_OVERALL);
for(int k=0; kv3a-size(); k++){
std::coutvectex: v3a-at(k).x() 
v3a-at(k).y() v3a-at(k).z();
}
std::coutstd::endl;
geom-addPrimitiveSet(new 
osg::DrawArrays(osg::PrimitiveSet::LINES,0,v3a-size()));
geode-addDrawable(geom);
root-addChild(geode);
}else{
std::coutno intersection for i=istd::endl;
std::coutx intersector-getStart().x() y 
intersector-getStart().y() z intersector-getStart().z()std::endl;
std::coutx intersector

[osg-users] LineSegmentIntersector bug?

2014-10-05 Thread weijianggood

Hi,
When i use LineSegmentIntersector in the following code.
there must be 8 lines. but after I run the code, only 7 lines exist.



int main( int argc, char** argv ){

float height = 5.f;

osg::ref_ptrosg::TessellationHints hints;
hints = new osg::TessellationHints;
hints-setDetailRatio(0.5f);
hints-setCreateBody(true);
hints-setCreateBottom(false);
hints-setCreateTop(false);
osg::ref_ptrosg::Geode mynode = new osg::Geode;
osg::ref_ptrosg::ShapeDrawable drawable = new osg::ShapeDrawable(new 
osg::Cylinder(osg::Vec3(0.0f,0.0f,0.0f),1.0f,height),hints);
osg::ref_ptrosg::ShapeDrawable drawable2 = new osg::ShapeDrawable(new 
osg::Cylinder(osg::Vec3(0.0f,0.0f,0.0f),4.0f,height),hints);
mynode-addDrawable(drawable.get());// geom.get() or gemo. both 
are ok. 
mynode-addDrawable(drawable2.get());

osg::ref_ptrosg::Group root = new osg::Group;
root-addChild(mynode.get() );
float angle = 0.0;
float angleDelta = 2.0f*osg::PI/8;

for(int i=0; i8;i++){  
float c = cosf(angle);
float s = sinf(angle);
osg::ref_ptrosgUtil::LineSegmentIntersector intersector = new 
osgUtil::LineSegmentIntersector( osg::Vec3(0.0f,0.0f,0.0f),  
osg::Vec3(10.0f*c,10.0f*s,0.0f) );

osgUtil::IntersectionVisitor iv( intersector.get() );
mynode-accept( iv );

if ( intersector-containsIntersections() )
{
osgUtil::LineSegmentIntersector::Intersections
intersections = 
intersector-getIntersections();
std::cout intersection size 
intersections.size()std::endl;

osg::ref_ptrosg::Geode  geode=new osg::Geode;
osg::ref_ptrosg::Geometry geom=new osg::Geometry;
osg::ref_ptrosg::Vec3Array v3a=new osg::Vec3Array;
osg::ref_ptrosg::Vec4Array colors = new 
osg::Vec4Array;
colors-push_back( osg::Vec4(1.0, 0.0, 0.0, 1.0) );


osgUtil::LineSegmentIntersector::Intersections::iterator itr;
for ( itr = intersections.begin(); itr != 
intersections.end(); ++itr ) {
std::cout  X  
itr-getWorldIntersectPoint().x()
  Y   
itr-getWorldIntersectPoint().y()
  Z  
itr-getWorldIntersectPoint().z();
if(itr == intersections.begin())
v3a-push_back( 
itr-getWorldIntersectPoint());

}
itr--;
v3a-push_back( itr-getWorldIntersectPoint());
std::coutstd::endl;
geom-setVertexArray(v3a);
geom-setColorArray(colors.get() );
geom-setColorBinding(osg::Geometry::BIND_OVERALL);
for(int k=0; kv3a-size(); k++){
std::coutvectex: v3a-at(k).x() 
v3a-at(k).y() v3a-at(k).z();
}
std::coutstd::endl;
geom-addPrimitiveSet(new 
osg::DrawArrays(osg::PrimitiveSet::LINES,0,v3a-size()));
geode-addDrawable(geom);
root-addChild(geode);
}else{
std::coutno intersection for i=istd::endl;
std::coutx intersector-getStart().x() y 
intersector-getStart().y() z intersector-getStart().z()std::endl;
std::coutx intersector-getEnd().x() y 
intersector-getEnd().y() z intersector-getEnd().z()std::endl;
}
angle+=angleDelta;
}
osgViewer::Viewer viewer;
viewer.setSceneData(root.get());
viewer.addEventHandler(new osgViewer::WindowSizeHandler);
return viewer.run();

}

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