使用PCL(点云库)获取一个对象信息数组
Using PCL(point cloud library) to obtain an array of an object information
例如,在二维space中,正方形的位置由'1'的集合表示,空space的位置由'0'的集合表示
00000000000000
00000111000000
00000111000000
00000111000000
00000000000000
发现pcl::OrganizedFastMeshclass是做这个任务的方法。 http://docs.pointclouds.org/trunk/classpcl_1_1_organized_fast_mesh.html 的网站显示了 class 的详细信息,但是对我来说很难理解。比如输入的文件名是'example.stl',如何获取上面的'0'和'1'的信息到一个数组'siteInfo[][]'?
为了从 stl 导入,您需要从顶点生成点。这是我将 stl 导入 pcl 点云的函数:
//generates an evenly distributed point cloud from stl file (assumed to be scaled in mm)
//maxPPDist: desired max distance between points (all surfaces will be upsampled until this density is reached)
//normalNeighborCount: how many points to include in NN normal resampling. (should match what is used on camera cloud)
bool PCL_Util::importCAD_STL(pcl::PointCloud<pcl::PointNormal>::Ptr &objectCloud,
std::string fileName,
double maxPPDist,
bool normResample,
int normalNeighborCount,
bool fastNormRecombination)
{
pcl::PolygonMesh mesh;
int fileReadVal;
try
{
fileReadVal = pcl::io::loadPolygonFileSTL(fileName, mesh);
}
catch (...)
{
return false;
}
if (fileReadVal == 0)
{
PCL_ERROR("Failed to load STL file\n");
return false;
}
else
{
pcl::PointCloud<pcl::PointNormal>::Ptr outputCloud(new pcl::PointCloud<pcl::PointNormal>);
pcl::PointCloud<pcl::PointXYZ> objCloud;
pcl::PCLPointCloud2 ptCloud2 = mesh.cloud;
pcl::fromPCLPointCloud2(ptCloud2, objCloud);
for (int i = 0; i < mesh.polygons.size(); i++)
{
pcl::Vertices currentPoly = mesh.polygons[i];
for (int ii = 0; ii < currentPoly.vertices.size(); ii++)
{
pcl::PointNormal currentPt = pcl::PointNormal();
currentPt.x = objCloud[currentPoly.vertices[ii]].x;
currentPt.y = objCloud[currentPoly.vertices[ii]].y;
currentPt.z = objCloud[currentPoly.vertices[ii]].z;
outputCloud->points.push_back(currentPt);//push in points without normals
}
//make the assumption that at least 3 verticies for last poly (standard stl... not sure how dirty this is)
int index = outputCloud->points.size() - 1;
pcl::PointXYZ pt3(outputCloud->points[index].x, outputCloud->points[index].y, outputCloud->points[index].z);
pcl::PointXYZ pt2(outputCloud->points[index - 1].x, outputCloud->points[index - 1].y, outputCloud->points[index - 1].z);
pcl::PointXYZ pt1(outputCloud->points[index - 2].x, outputCloud->points[index - 2].y, outputCloud->points[index - 2].z);
Eigen::Vector3f vec12(pt2.x - pt1.x, pt2.y - pt1.y, pt2.z - pt1.z);
Eigen::Vector3f vec23(pt3.x - pt2.x, pt3.y - pt2.y, pt3.z - pt2.z);
Eigen::Vector3f vecNorm = vec12.cross(vec23);
vecNorm.normalize();
for (int ii = 0; ii < 3; ii++)
{
outputCloud->points[index - ii].normal_x = vecNorm[0];
outputCloud->points[index - ii].normal_y = vecNorm[1];
outputCloud->points[index - ii].normal_z = vecNorm[2];
}
//interpolate each triangular surface to fit desired resolution
if (maxPPDist != -1)
{
interpolateTriangle(outputCloud, maxPPDist);
}
}
if (fastNormRecombination)//faster by an order of magnitude, but less accurate normals stl surface join points
{
voxelPruneCloud<pcl::PointNormal>(outputCloud, maxPPDist / 2.0f, maxPPDist / 2.0f, maxPPDist / 2.0f);
}
else//very slow, but generates more accurate normals at joint points
{
combineColocatedPoints(outputCloud, maxPPDist / 2.0f);
}
if (normResample)//uses the current normals as hemisphere guides for newly calculated normals
{
resampleNormalCloud(outputCloud, normalNeighborCount);
}
copyPointCloud(*outputCloud, *objectCloud);
printf("File imported successfully?!\n");
return true;
}
}
就生成二维数组而言...我会研究光线投射以生成结构化点云/表面。 (http://www.pcl-users.org/From-3D-point-cloud-to-depth-map-td4027567.html) 我个人编写了自己的实现以允许线程化,但我确信 pcl 有一些内置函数。
例如,在二维space中,正方形的位置由'1'的集合表示,空space的位置由'0'的集合表示
00000000000000
00000111000000
00000111000000
00000111000000
00000000000000
发现pcl::OrganizedFastMeshclass是做这个任务的方法。 http://docs.pointclouds.org/trunk/classpcl_1_1_organized_fast_mesh.html 的网站显示了 class 的详细信息,但是对我来说很难理解。比如输入的文件名是'example.stl',如何获取上面的'0'和'1'的信息到一个数组'siteInfo[][]'?
为了从 stl 导入,您需要从顶点生成点。这是我将 stl 导入 pcl 点云的函数:
//generates an evenly distributed point cloud from stl file (assumed to be scaled in mm)
//maxPPDist: desired max distance between points (all surfaces will be upsampled until this density is reached)
//normalNeighborCount: how many points to include in NN normal resampling. (should match what is used on camera cloud)
bool PCL_Util::importCAD_STL(pcl::PointCloud<pcl::PointNormal>::Ptr &objectCloud,
std::string fileName,
double maxPPDist,
bool normResample,
int normalNeighborCount,
bool fastNormRecombination)
{
pcl::PolygonMesh mesh;
int fileReadVal;
try
{
fileReadVal = pcl::io::loadPolygonFileSTL(fileName, mesh);
}
catch (...)
{
return false;
}
if (fileReadVal == 0)
{
PCL_ERROR("Failed to load STL file\n");
return false;
}
else
{
pcl::PointCloud<pcl::PointNormal>::Ptr outputCloud(new pcl::PointCloud<pcl::PointNormal>);
pcl::PointCloud<pcl::PointXYZ> objCloud;
pcl::PCLPointCloud2 ptCloud2 = mesh.cloud;
pcl::fromPCLPointCloud2(ptCloud2, objCloud);
for (int i = 0; i < mesh.polygons.size(); i++)
{
pcl::Vertices currentPoly = mesh.polygons[i];
for (int ii = 0; ii < currentPoly.vertices.size(); ii++)
{
pcl::PointNormal currentPt = pcl::PointNormal();
currentPt.x = objCloud[currentPoly.vertices[ii]].x;
currentPt.y = objCloud[currentPoly.vertices[ii]].y;
currentPt.z = objCloud[currentPoly.vertices[ii]].z;
outputCloud->points.push_back(currentPt);//push in points without normals
}
//make the assumption that at least 3 verticies for last poly (standard stl... not sure how dirty this is)
int index = outputCloud->points.size() - 1;
pcl::PointXYZ pt3(outputCloud->points[index].x, outputCloud->points[index].y, outputCloud->points[index].z);
pcl::PointXYZ pt2(outputCloud->points[index - 1].x, outputCloud->points[index - 1].y, outputCloud->points[index - 1].z);
pcl::PointXYZ pt1(outputCloud->points[index - 2].x, outputCloud->points[index - 2].y, outputCloud->points[index - 2].z);
Eigen::Vector3f vec12(pt2.x - pt1.x, pt2.y - pt1.y, pt2.z - pt1.z);
Eigen::Vector3f vec23(pt3.x - pt2.x, pt3.y - pt2.y, pt3.z - pt2.z);
Eigen::Vector3f vecNorm = vec12.cross(vec23);
vecNorm.normalize();
for (int ii = 0; ii < 3; ii++)
{
outputCloud->points[index - ii].normal_x = vecNorm[0];
outputCloud->points[index - ii].normal_y = vecNorm[1];
outputCloud->points[index - ii].normal_z = vecNorm[2];
}
//interpolate each triangular surface to fit desired resolution
if (maxPPDist != -1)
{
interpolateTriangle(outputCloud, maxPPDist);
}
}
if (fastNormRecombination)//faster by an order of magnitude, but less accurate normals stl surface join points
{
voxelPruneCloud<pcl::PointNormal>(outputCloud, maxPPDist / 2.0f, maxPPDist / 2.0f, maxPPDist / 2.0f);
}
else//very slow, but generates more accurate normals at joint points
{
combineColocatedPoints(outputCloud, maxPPDist / 2.0f);
}
if (normResample)//uses the current normals as hemisphere guides for newly calculated normals
{
resampleNormalCloud(outputCloud, normalNeighborCount);
}
copyPointCloud(*outputCloud, *objectCloud);
printf("File imported successfully?!\n");
return true;
}
}
就生成二维数组而言...我会研究光线投射以生成结构化点云/表面。 (http://www.pcl-users.org/From-3D-point-cloud-to-depth-map-td4027567.html) 我个人编写了自己的实现以允许线程化,但我确信 pcl 有一些内置函数。