Files
IfcOpenShell/src/ifcgeom/kernels/cgal/CgalConversionResult.cpp
T

55 lines
2.4 KiB
C++
Raw Normal View History

2017-01-16 14:04:31 +01:00
#include "CgalKernel.h"
#include "CgalConversionResult.h"
void IfcGeom::CgalShape::Triangulate(const IfcGeom::IteratorSettings & settings, const IfcGeom::ConversionResultPlacement * place, IfcGeom::Representation::Triangulation<double>* t, int surface_style_id) const {
cgal_shape_t s = shape_;
const cgal_placement_t& trsf = dynamic_cast<const CgalPlacement*>(place)->trsf();
2017-03-20 20:57:17 -06:00
2017-02-08 16:56:59 -06:00
// Apply transformation
if (place != NULL) for (auto &vertex: vertices(s)) {
2017-02-13 15:26:06 -06:00
vertex->point() = vertex->point().transform(trsf);
}
2017-02-08 16:56:59 -06:00
2017-03-03 15:25:45 -06:00
// std::ofstream fbefore;
// fbefore.open("/Users/ken/Desktop/before.off");
// fbefore << s << std::endl;
// fbefore.close();
// Triangulate the shape and compute the normals
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);
if (CGAL::Polygon_mesh_processing::triangulate_faces(s)) {
2017-02-20 20:14:49 -06:00
// std::cout << "Triangulated model: " << s.size_of_facets() << " facets and " << s.size_of_vertices() << " vertices" << std::endl;
} else {
Logger::Message(Logger::LOG_ERROR, "Failed to triangulate shape");
return;
}
2017-03-03 15:25:45 -06:00
// std::ofstream fafter;
// fafter.open("/Users/ken/Desktop/after.off");
// fafter << s << std::endl;
// fafter.close();
CGAL::Polygon_mesh_processing::compute_normals(s, vertex_normals_map, face_normals_map);
2017-03-03 15:25:45 -06:00
for (auto &face: faces(s)) {
2017-03-03 15:25:45 -06:00
if (!face->is_triangle()) {
std::cout << "Warning: non-triangular face!" << std::endl;
continue;
}
CGAL::Polyhedron_3<Kernel>::Halfedge_around_facet_const_circulator current_halfedge = face->facet_begin();
do {
2017-03-07 12:50:06 -06:00
t->faces().push_back((int)t->verts().size()/3);
t->addVertex(surface_style_id,
CGAL::to_double(current_halfedge->vertex()->point().cartesian(0)),
CGAL::to_double(current_halfedge->vertex()->point().cartesian(1)),
CGAL::to_double(current_halfedge->vertex()->point().cartesian(2)));
for (int i = 0; i < 3; ++i) t->normals().push_back(CGAL::to_double(face_normals_map[face].cartesian(i)));
++current_halfedge;
} while (current_halfedge != face->facet_begin());
t->material_ids().push_back(surface_style_id);
}
2017-01-16 14:04:31 +01:00
}