Ich habe folgende, es ist langwierig und baut gerade die Oberfläche des Würfels, einige Optimierungen und Sie bekommen, was Sie wollen:
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;
}
Was meinst du mit „rekonstruieren“? Möchten Sie sie verbinden und dann den Würfel mit zufälligen Punkten füllen? Könntest du dich besser erklären? – Finfa811