考虑到8个角点,我想重建它们并填满点云数据的立方体。使用Point Cloud Library,我该怎么做?
答案 0 :(得分:0)
我有以下内容,它很长,只是构建了立方体的表面,一些调整,你会得到你想要的东西:
struct Dimensions // min and max points of cube
{
float min_x, min_y, min_z, max_x, max_y, max_z;
}
PointCloudColoredPtr draw_box(Dimensions& dim, uint32_t rgb)
{
float step = 0.4;
PointCloudColoredPtr box(new PointCloudColored);
PointTColored point_min, point_max;
point_min.rgb = *reinterpret_cast<float*>(&rgb);
point_max.rgb = *reinterpret_cast<float*>(&rgb);
// add points according to X
point_min.x = dim.min_x;
point_max.x = dim.max_x;
float b1, b2;
for (b1 = dim.min_y; b1 < dim.max_y; b1 += step)
{
for (b2 = dim.min_z; b2 < dim.max_z; b2 += step)
{
point_min.y = b1; point_max.y = b1;
point_min.z = b2; point_max.z = b2;
box->points.push_back(point_min);
box->points.push_back(point_max);
}
}
// add points according to Y
point_min.y = dim.min_y;
point_max.y = dim.max_y;
for (b1 = dim.min_x; b1 < dim.max_x; b1 += step)
{
for (b2 = dim.min_z; b2 < dim.max_z; b2 += step)
{
point_min.x = b1; point_max.x = b1;
point_min.z = b2; point_max.z = b2;
box->points.push_back(point_min);
box->points.push_back(point_max);
}
}
// add points according to Z
point_min.z = dim.min_z;
point_max.z = dim.max_z;
for (b1 = dim.min_x; b1 < dim.max_x; b1 += step)
{
for (b2 = dim.min_y; b2 < dim.max_y; b2 += step)
{
point_min.x = b1; point_max.x = b1;
point_min.y = b2; point_max.y = b2;
box->points.push_back(point_min);
box->points.push_back(point_max);
}
}
return box;
}