osgUtil::DelaunayTriangulator 类进行模型有限元三角网格划分

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_35097289/article/details/82387045

osgUtil::DelaunayTriangulator类建立约束的delaunay(德洛内)三角网,delaunay(德洛内)三角网主要用于基于离散点数据构建三维表面。如经常用于构建地形表面。

1、生成离散点数据

2、三角化处理

3、将三角化的图元添加到叶节点中

osg::ref_ptr<osg::Geode> CreateModule_DelaunayTriangulator(osg:;ref_ptr<osg::Vec3Array> Points, osg::ref_ptr<osg::Vec4Array>color)
{
     //DelaunayTriangulator
     osg::ref_ptr<osg::Geode> geode=new osg::Geode;

     osg::ref_ptr<osgUtil::DelaunayTriangulator> trig=new osgUtil::DelaunayTriangulator();
     trig->setInputPointArray(points);
     /** NB you need to supply a vec3 array for the triangulator to calculate normals into */
     osg::ref_ptr<osg::Vec3Array> norms=new osg::Vec3Array;
     trig->setOutputNormalArray(norms);
     trig->triangulate();//it will change the ordinary and maybe change the Size of point
    
     //Add color and Calculate the texture coordinates after triangulation as 
     //the points may get disordered by the triangulate function
     osg::ref_ptr<osg::Geometry> gm=new osg::Geometry;
     gm->setVertexArray(points); // points may have been modified in order by triangulation.
     //add color
     gm->setColorArray(color);//set color
     gm->setColorBinding(osg::Geometry::BIND_OVERALL);

     gm->addPrimitiveSet(trig->getTriangles());
     gm->setNormalArray(trig->getOutputNormalArray());
     gm->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);
     geode->addDrawable(gm.get());

     // use smoothing visitor to set the average normals
     osgUtil::SmoothingVisitor sv;
     sv.apply(*geode);
     return geode;
}

示例:

参考文章:https://www.cnblogs.com/flylong0204/p/4616195.html

                  https://blog.csdn.net/hudfang/article/details/46544453

猜你喜欢

转载自blog.csdn.net/qq_35097289/article/details/82387045