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;
}