Hi,

I would like to compute a triangle Mesh slice. I create a scene that include 
only on node, my triangular mesh. I create a PlaneIntersector without clipping 
plane. The result is not empty ( if you test Intersection object for empty) but 
the sotfware crash immediately when I acces the Intersection object.



Code:

        btBvhTriangleMeshShape Tmp ( m_mesh, true );
        //m_Root->addChild ( osgbBullet::osgNodeFromBtCollisionShape( &Tmp ) );
        osg::Node *nodeTmp = osgbBullet::osgNodeFromBtCollisionShape( &Tmp );
        //nodeTmp->setNodeMask( 0x1 );
        
        m_Root = new osg::Group;
        m_Root->addChild ( nodeTmp );

        osg::BoundingSphere bSphere;
        bSphere = nodeTmp->getBound();

        // set up the main intersection plane
        osg::Plane intersectionPlane;
        osg::Vec3d planeNormal ( m_planeNormal.x(), m_planeNormal.y(), 
m_planeNormal.z() );
        osg::Vec3d planePoint ( m_planePoint.x(), m_planePoint.y(), 
m_planePoint.z() );
        planeNormal.normalize();        
        intersectionPlane.set( planeNormal, planePoint );
        osgUtil::IntersectionVisitor    intersectionVisitor;

        osg::ref_ptr<osgUtil::PlaneIntersector> intersector = new 
osgUtil::PlaneIntersector( intersectionPlane, boundingPolytope );
        //osgUtil::PlaneIntersector *intersector = new 
osgUtil::PlaneIntersector( intersectionPlane );
        
        std::vector<osg::Vec3d> intersectionPoints;

        intersector->setRecordHeightsAsAttributes(true);
        intersector->setEllipsoidModel(NULL);

        intersectionVisitor.reset();
        intersectionVisitor.setTraversalMask( 0x1 );
        intersectionVisitor.setIntersector( intersector.get() );

        m_Root->accept( intersectionVisitor );

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

        typedef osgUtil::PlaneIntersector::Intersection::Polyline Polyline;
        typedef osgUtil::PlaneIntersector::Intersection::Attributes Attributes;

        if (!intersections.empty())
        {
              // at this step size of intersection is 323361003. It is very 
big!!! ?
             // It crash here

                osgUtil::PlaneIntersector::Intersections::iterator itr;
                for(itr = intersections.begin(); itr != intersections.end(); 
++itr)
                {
                        osgUtil::PlaneIntersector::Intersection& intersection = 
*itr;

                        if (intersection.matrix.valid())
                        {
                                // osg::notify(osg::NOTICE)<<"  transforming 
"<<std::endl;
                                // transform points on polyline 
                                for(Polyline::iterator pitr = 
intersection.polyline.begin(); pitr != intersection.polyline.end(); ++pitr)
                                {
                                        *pitr = (*pitr) * 
(*intersection.matrix);
                                }

                                // matrix no longer needed.
                                intersection.matrix = 0;
                        }
                }

                osg::ref_ptr<osg::Geode> geode = new osg::Geode;
                for(itr = intersections.begin(); itr != intersections.end(); 
++itr)
                {
                        osgUtil::PlaneIntersector::Intersection& intersection = 
*itr;
                        osg::Geometry* geometry = new osg::Geometry;

                        osg::Vec3Array* vertices = new osg::Vec3Array;
                        vertices->reserve(intersection.polyline.size());
                        for(Polyline::iterator pitr = 
intersection.polyline.begin(); pitr != intersection.polyline.end(); ++pitr)
                        {
                                vertices->push_back(*pitr);
                        }
                        geometry->setVertexArray( vertices );
                        geometry->addPrimitiveSet( new 
osg::DrawArrays(GL_LINE_STRIP, 0, vertices->size()) );

                        osg::Vec4Array* colours = new osg::Vec4Array;
                        colours->push_back( osg::Vec4(0.2f,0.2f,0.2f,1.0f) );

                        osg::LineWidth* linewidth = new osg::LineWidth();
                        linewidth->setWidth(4.0f);
                        
geode->getOrCreateStateSet()->setAttributeAndModes(linewidth,osg::StateAttribute::ON);

                        geometry->setColorArray( colours );
                        geometry->setColorBinding(osg::Geometry::BIND_OVERALL);
                        geode->addDrawable( geometry );
                        geode->getOrCreateStateSet()->setMode( GL_LIGHTING, 
osg::StateAttribute::OFF );
                }

                osgDB::writeNodeFile(*geode, "c:\\out\\raw.osg");
        }



Normally my plane intersect the mesh ( intersection is not empty). Where I can 
get exemple of PlaneIntersector. I have looked in OSG exemple but I never found 
an example.

Is some one have a solution

Thank you

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





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to