mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-23 08:22:39 +00:00
Restructure cgal shape triangulation
This commit is contained in:
@@ -1,11 +1,14 @@
|
|||||||
#include "CgalConversionResult.h"
|
#include "CgalConversionResult.h"
|
||||||
#include "CgalKernel.h"
|
#include "CgalKernel.h"
|
||||||
|
|
||||||
|
#include <CGAL/Polygon_mesh_processing/repair.h>
|
||||||
|
|
||||||
#include "../../../ifcparse/IfcLogger.h"
|
#include "../../../ifcparse/IfcLogger.h"
|
||||||
#include "../../../ifcgeom/IfcGeomRepresentation.h"
|
#include "../../../ifcgeom/IfcGeomRepresentation.h"
|
||||||
|
|
||||||
void ifcopenshell::geometry::CgalShape::Triangulate(const IfcGeom::IteratorSettings& settings, const ifcopenshell::geometry::taxonomy::matrix4& place, IfcGeom::Representation::Triangulation* t, int surface_style_id) const {
|
void ifcopenshell::geometry::CgalShape::Triangulate(const IfcGeom::IteratorSettings& settings, const ifcopenshell::geometry::taxonomy::matrix4& place, IfcGeom::Representation::Triangulation* t, int surface_style_id) const {
|
||||||
// Copy is made because triangulate_faces() does not accept a const argument
|
// Copy is made because triangulate_faces() obviously does not accept a const argument
|
||||||
|
// ... also becuase of transforming the vertex positions, right?
|
||||||
cgal_shape_t s = shape_;
|
cgal_shape_t s = shape_;
|
||||||
|
|
||||||
if (!place.is_identity()) {
|
if (!place.is_identity()) {
|
||||||
@@ -23,16 +26,16 @@ void ifcopenshell::geometry::CgalShape::Triangulate(const IfcGeom::IteratorSetti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::wcout << "Triangulating " << std::distance(s.facets_begin(), s.facets_end()) << std::endl;
|
||||||
|
|
||||||
|
if (!std::all_of(s.facets_begin(), s.facets_end(), [](auto f) { return f.is_triangle(); })) {
|
||||||
|
|
||||||
if (!s.is_valid()) {
|
if (!s.is_valid()) {
|
||||||
Logger::Message(Logger::LOG_ERROR, "Invalid Polyhedron_3 in object (before triangulation)");
|
Logger::Message(Logger::LOG_ERROR, "Invalid Polyhedron_3 in object (before triangulation)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Triangulate the shape and compute the normals
|
CGAL::Polygon_mesh_processing::remove_degenerate_faces(s);
|
||||||
// std::map<cgal_vertex_descriptor_t, Kernel_::Vector_3> vertex_normals;
|
|
||||||
// boost::associative_property_map<std::map<cgal_vertex_descriptor_t, Kernel_::Vector_3>> vertex_normals_map(vertex_normals);
|
|
||||||
std::map<cgal_face_descriptor_t, Kernel_::Vector_3> face_normals;
|
|
||||||
boost::associative_property_map<std::map<cgal_face_descriptor_t, Kernel_::Vector_3>> face_normals_map(face_normals);
|
|
||||||
|
|
||||||
bool success = false;
|
bool success = false;
|
||||||
try {
|
try {
|
||||||
@@ -53,6 +56,15 @@ void ifcopenshell::geometry::CgalShape::Triangulate(const IfcGeom::IteratorSetti
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// std::map<cgal_vertex_descriptor_t, Kernel_::Vector_3> vertex_normals;
|
||||||
|
// boost::associative_property_map<std::map<cgal_vertex_descriptor_t, Kernel_::Vector_3>> vertex_normals_map(vertex_normals);
|
||||||
|
|
||||||
|
// Triangulate the shape and compute the normals
|
||||||
|
std::map<cgal_face_descriptor_t, Kernel_::Vector_3> face_normals;
|
||||||
|
boost::associative_property_map<std::map<cgal_face_descriptor_t, Kernel_::Vector_3>> face_normals_map(face_normals);
|
||||||
|
|
||||||
// CGAL::Polygon_mesh_processing::compute_normals(s, vertex_normals_map, face_normals_map);
|
// CGAL::Polygon_mesh_processing::compute_normals(s, vertex_normals_map, face_normals_map);
|
||||||
try {
|
try {
|
||||||
CGAL::Polygon_mesh_processing::compute_face_normals(s, face_normals_map);
|
CGAL::Polygon_mesh_processing::compute_face_normals(s, face_normals_map);
|
||||||
@@ -79,16 +91,11 @@ void ifcopenshell::geometry::CgalShape::Triangulate(const IfcGeom::IteratorSetti
|
|||||||
double nx = 0.;
|
double nx = 0.;
|
||||||
double ny = 0.;
|
double ny = 0.;
|
||||||
double nz = 1.;
|
double nz = 1.;
|
||||||
// @todo normal calculation throws divide by zero?
|
|
||||||
// try {
|
|
||||||
if (false) {
|
|
||||||
nx = CGAL::to_double(face_normals_map[face].cartesian(0));
|
nx = CGAL::to_double(face_normals_map[face].cartesian(0));
|
||||||
ny = CGAL::to_double(face_normals_map[face].cartesian(1));
|
ny = CGAL::to_double(face_normals_map[face].cartesian(1));
|
||||||
nz = CGAL::to_double(face_normals_map[face].cartesian(2));
|
nz = CGAL::to_double(face_normals_map[face].cartesian(2));
|
||||||
}
|
|
||||||
// catch (...) {
|
|
||||||
// Logger::Error("Error during normal calculation");
|
|
||||||
// }
|
|
||||||
t->addNormal(nx, ny, nz);
|
t->addNormal(nx, ny, nz);
|
||||||
|
|
||||||
++num_vertices;
|
++num_vertices;
|
||||||
|
|||||||
Reference in New Issue
Block a user