面对最原始的三维数据(x,y,z),怎么用OSG显示出其模型呢?
用osg的Geometry类去实现,通过将一系列的三维数据点压入容器中,让后调用Geometry的setVertexArray方法去实现点云图的绘制:
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osg/Node>
#include <osg/Geode>
#include <osg/Geometry>
#include <osgViewer/ViewerEventHandlers>
#include <iostream>
#include <cstring>
#include <windows.h>
using namespace std;
//绘制点云图
osg::ref_ptr<osg::Node> creatPoints(string dataFile)
{
//首先定义点
osg::ref_ptr<osg::Vec3Array> v = new osg::Vec3Array;
//定义颜色数组
osg::ref_ptr<osg::Vec4Array> c = new osg::Vec4Array;
int count = 0;
FILE* pfData = fopen(dataFile.c_str(), "r");
if (pfData == NULL)
{
cout<<"DataFile does not exist!!!"<<endl;
return NULL;
}
else