3

我收到了来自 Cinema 4D 的 STL 格式的 3D 模型。我的目标是使用 CGAL 来操纵它们。目前,我只是尝试使用以下代码将模型加载为 Polyhedron_3:

using namespace std;

typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron_3;
typedef CGAL::Simple_cartesian<double> K;
typedef K::Point_2                 Point_2;
typedef K::Point_3                 Point_3;

int main()
{
std::string stl_file_name;

cout << "opening file\n";
stl_file_name = "D:\\Julien\\Edit3D_I5_STImier.stl";

Polyhedron_3 poly_Partition;

std::ifstream stl_file(stl_file_name, std::ifstream::in);
std::vector<CGAL::cpp11::array<double, 3> > points;
std::vector<CGAL::cpp11::array<int, 3> > triangles;

cout << "reading file\n";
CGAL::read_STL(stl_file, points, triangles);

cout << "closing file \n";
stl_file.close();

cout << "processing mesh\n";
int spoints_nb = points.size();
cout << "number of points in soup : " << spoints_nb << "\n";
int poly_nb = triangles.size();
cout << "number of polys in soup : " << poly_nb << "\n";
CGAL::Polygon_mesh_processing::orient_polygon_soup(points, triangles);
CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh(points, triangles, poly_Partition);

int vertices_nb = poly_Partition.size_of_facets();
cout << "number of facets : " << vertices_nb << "\n";

int points_nb = points.size();
cout << "number of points : " << points_nb << "\n";

int triangles_nb = triangles.size();
cout << "number of triangles : " << triangles_nb << "\n";

std::vector<Point_3> points_3;
std::vector<CGAL::cpp11::array<double, 3>>::iterator it;
for (it = points.begin() ; it != points.end(); ++it) {
    CGAL::cpp11::array<double, 3> a = *it;
    Point_3 point = Point_3(a[0], a[1], a[2]);
    points_3.push_back(point);
}

K::Iso_cuboid_3 c3 = CGAL::bounding_box(points_3.begin(), points_3.end());

for (int i = 0; i < 8; i++) {
    Point_3 vert = c3.vertex(i);
    cout << vert.hx() << ", " << vert.hy() << ", " << vert.hz() << "\n";
}

return 0;
}

问题是我只得到 19 个点和 24 个三角形。当我打开详细信息时,我会在控制台中read_STL收到很多消息。ignore degenerate face

我的问题是:如何让脸不退化?是否有更宽容的(关于“退化”)方式来读取 STL 文件?

我是 C++ 和 CGAL 的新手,所以如果我的代码伤害了你的眼睛,请原谅我。

4

0 回答 0