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_cast<osgViewer::Viewer*>(&aa);
        if ( viewer ){
            osg::ref_ptr<osgUtil::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_ptr<osg::Node> model1 = osgDB::readNodeFile( "STLFILE.stl" );
        osg::ref_ptr<osg::Group> root = new osg::Group;
    root->addChild( model1.get() );
        osg::ref_ptr<PickHandler> 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

Reply via email to