|
本帖最后由 just_rookie 于 2013-12-1 21:44 编辑
如题!
下面是我自己写的一段代码,但是错误提示说有逻辑错误,求指教!
//greedy projection;
pcl::GreedyProjectionTriangulation<pcl::PointNormal> gp;
pcl::PolygonMesh mesh;
gp.setInputCloud(pointWithNormal);
gp.setSearchMethod(tree1);
gp.setMu(3.20);
gp.setSearchRadius(20.0);
gp.setMaximumNearestNeighbors(200);
gp.setMaximumSurfaceAngle(M_PI);
gp.setMaximumAngle(3*M_PI/3);
gp.setMinimumAngle(M_PI/180);
gp.setNormalConsistency(false);
gp.reconstruct(mesh);
//cout<<"The size of polygons is "<<mesh.polygons.size()<<endl;
//pcl::io::saveVTKFile("potting-reconstruction.vtk",mesh);
//pcl::io::savePLYFile("potting-reconstruction.ply",mesh);
//calculate area;
pcl::PointCloud<pcl::PointXYZ> cloud1;
cloud1=*cloud;
int index_p1,index_p2,index_p3;
float x1,x2,x3,y1,y2,y3,z1,z2,z3,a,b,c,q;
float area=0;
for(int i=0;i<mesh.polygons.size();++i)
{
index_p1=mesh.polygons.vertices[0];
index_p2=mesh.polygons.vertices[1];
index_p3=mesh.polygons.vertices[2];
x1=cloud1.points[index_p1].x;
y1=cloud1.points[index_p1].y;
z1=cloud1.points[index_p1].z;
x2=cloud1.points[index_p2].x;
y2=cloud1.points[index_p2].y;
z2=cloud1.points[index_p2].z;
x3=cloud1.points[index_p3].x;
y3=cloud1.points[index_p3].y;
z3=cloud1.points[index_p3].z;
a=sqrt(pow((x1-x2),2)+pow((y1-y2),2)+pow((z1-z2),2));
b=sqrt(pow((x1-x3),2)+pow((y1-y3),2)+pow((z1-z3),2));
c=sqrt(pow((x3-x2),2)+pow((y3-y2),2)+pow((z3-z2),2));
q=(a+b+c)/2;
area=area+sqrt(q*(q-a)*(q-b)*(q-c));//Heron's formula;
}
cout<<area<<endl; |
|