mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 18:21:59 +00:00
Brep and swept solid working now
This commit is contained in:
@@ -108,6 +108,7 @@ void WaveFrontOBJSerializer::write(const IfcGeom::TriangulationElement<real_t>*
|
|||||||
|
|
||||||
const bool has_uvs = !mesh.uvs().empty();
|
const bool has_uvs = !mesh.uvs().empty();
|
||||||
const bool has_normals = !mesh.normals().empty();
|
const bool has_normals = !mesh.normals().empty();
|
||||||
|
// std::cout << mesh.faces().size() << " vertices in face mesh" << std::endl;
|
||||||
for ( std::vector<int>::const_iterator it = mesh.faces().begin(); it != mesh.faces().end(); ) {
|
for ( std::vector<int>::const_iterator it = mesh.faces().begin(); it != mesh.faces().end(); ) {
|
||||||
|
|
||||||
const int material_id = *(material_it++);
|
const int material_id = *(material_it++);
|
||||||
|
|||||||
@@ -70,10 +70,19 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcExtrudedAreaSolid *l, cgal
|
|||||||
top_face.outer.push_back(*vertex+dir);
|
top_face.outer.push_back(*vertex+dir);
|
||||||
} face_list.push_back(top_face);
|
} face_list.push_back(top_face);
|
||||||
|
|
||||||
|
// Naive creation
|
||||||
cgal_shape_t polyhedron = CGAL::Polyhedron_3<Kernel>();
|
cgal_shape_t polyhedron = CGAL::Polyhedron_3<Kernel>();
|
||||||
PolyhedronBuilder builder(&face_list);
|
PolyhedronBuilder builder(&face_list);
|
||||||
polyhedron.delegate(builder);
|
polyhedron.delegate(builder);
|
||||||
|
|
||||||
|
// Stitch edges
|
||||||
|
// std::cout << "Before: " << polyhedron.size_of_vertices() << " vertices and " << polyhedron.size_of_facets() << " facets" << std::endl;
|
||||||
|
CGAL::Polygon_mesh_processing::stitch_borders(polyhedron);
|
||||||
|
if (!CGAL::Polygon_mesh_processing::is_outward_oriented(polyhedron)) {
|
||||||
|
CGAL::Polygon_mesh_processing::reverse_face_orientations(polyhedron);
|
||||||
|
}
|
||||||
|
// std::cout << "After: " << polyhedron.size_of_vertices() << " vertices and " << polyhedron.size_of_facets() << " facets" << std::endl;
|
||||||
|
|
||||||
shape = polyhedron;
|
shape = polyhedron;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -84,6 +93,7 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcCartesianPoint* l, cgal_po
|
|||||||
point = Kernel::Point_3(xyz.size() ? (xyz[0]*getValue(GV_LENGTH_UNIT)) : 0.0f,
|
point = Kernel::Point_3(xyz.size() ? (xyz[0]*getValue(GV_LENGTH_UNIT)) : 0.0f,
|
||||||
xyz.size() > 1 ? (xyz[1]*getValue(GV_LENGTH_UNIT)) : 0.0f,
|
xyz.size() > 1 ? (xyz[1]*getValue(GV_LENGTH_UNIT)) : 0.0f,
|
||||||
xyz.size() > 2 ? (xyz[2]*getValue(GV_LENGTH_UNIT)) : 0.0f);
|
xyz.size() > 2 ? (xyz[2]*getValue(GV_LENGTH_UNIT)) : 0.0f);
|
||||||
|
// std::cout << "Converted Point(" << point << ")" << std::endl;
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
throw std::runtime_error("Point without 3 coordinates");
|
throw std::runtime_error("Point without 3 coordinates");
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
void IfcGeom::CgalShape::Triangulate(const IfcGeom::IteratorSettings & settings, const IfcGeom::ConversionResultPlacement * place, IfcGeom::Representation::Triangulation<double>* t, int surface_style_id) const {
|
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_;
|
cgal_shape_t s = shape_;
|
||||||
const cgal_placement_t& trsf = dynamic_cast<const CgalPlacement*>(place)->trsf();
|
const cgal_placement_t& trsf = dynamic_cast<const CgalPlacement*>(place)->trsf();
|
||||||
|
// std::cout << "Model: " << s.size_of_facets() << " facets and " << s.size_of_vertices() << " vertices" << std::endl;
|
||||||
|
// std::cout << "Valid: " << s.is_valid() << std::endl;
|
||||||
|
|
||||||
// Apply transformation
|
// Apply transformation
|
||||||
if (place != NULL) for (auto &vertex: vertices(s)) {
|
if (place != NULL) for (auto &vertex: vertices(s)) {
|
||||||
@@ -15,17 +17,15 @@ void IfcGeom::CgalShape::Triangulate(const IfcGeom::IteratorSettings & settings,
|
|||||||
boost::associative_property_map<std::map<cgal_vertex_descriptor_t, Kernel::Vector_3>> vertex_normals_map(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;
|
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);
|
boost::associative_property_map<std::map<cgal_face_descriptor_t, Kernel::Vector_3>> face_normals_map(face_normals);
|
||||||
try {
|
if (CGAL::Polygon_mesh_processing::triangulate_faces(s)) {
|
||||||
CGAL::Polygon_mesh_processing::triangulate_faces(s);
|
// std::cout << "Triangulated model: " << s.size_of_facets() << " facets and " << s.size_of_vertices() << " vertices" << std::endl;
|
||||||
CGAL::Polygon_mesh_processing::compute_normals(s, vertex_normals_map, face_normals_map);
|
} else {
|
||||||
} catch (...) {
|
|
||||||
|
|
||||||
// TODO: Catch outside
|
|
||||||
// Logger::Message(Logger::LOG_ERROR,"Failed to triangulate shape:",ifc_file->entityById(_id)->entity);
|
|
||||||
Logger::Message(Logger::LOG_ERROR, "Failed to triangulate shape");
|
Logger::Message(Logger::LOG_ERROR, "Failed to triangulate shape");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CGAL::Polygon_mesh_processing::compute_normals(s, vertex_normals_map, face_normals_map);
|
||||||
|
|
||||||
// Iterates over the faces of the shape
|
// Iterates over the faces of the shape
|
||||||
int num_faces = 0, num_vertices = 0;
|
int num_faces = 0, num_vertices = 0;
|
||||||
for (auto &face: faces(s)) {
|
for (auto &face: faces(s)) {
|
||||||
@@ -43,4 +43,6 @@ void IfcGeom::CgalShape::Triangulate(const IfcGeom::IteratorSettings & settings,
|
|||||||
t->material_ids().push_back(surface_style_id);
|
t->material_ids().push_back(surface_style_id);
|
||||||
++num_faces;
|
++num_faces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// std::cout << num_faces << " faces" << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,13 +129,27 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcConnectedFaceSet* l, cgal_
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// std::cout << "Face in ConnectedFaceSet: " << std::endl;
|
||||||
|
// for (auto &point: face.outer) {
|
||||||
|
// std::cout << "\tPoint(" << point << ")" << std::endl;
|
||||||
|
// }
|
||||||
|
|
||||||
face_list.push_back(face);
|
face_list.push_back(face);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Naive creation
|
||||||
cgal_shape_t polyhedron = CGAL::Polyhedron_3<Kernel>();
|
cgal_shape_t polyhedron = CGAL::Polyhedron_3<Kernel>();
|
||||||
PolyhedronBuilder builder(&face_list);
|
PolyhedronBuilder builder(&face_list);
|
||||||
polyhedron.delegate(builder);
|
polyhedron.delegate(builder);
|
||||||
|
|
||||||
|
// Stitch edges
|
||||||
|
// std::cout << "Before: " << polyhedron.size_of_vertices() << " vertices and " << polyhedron.size_of_facets() << " facets" << std::endl;
|
||||||
|
CGAL::Polygon_mesh_processing::stitch_borders(polyhedron);
|
||||||
|
if (!CGAL::Polygon_mesh_processing::is_outward_oriented(polyhedron)) {
|
||||||
|
CGAL::Polygon_mesh_processing::reverse_face_orientations(polyhedron);
|
||||||
|
}
|
||||||
|
// std::cout << "After: " << polyhedron.size_of_vertices() << " vertices and " << polyhedron.size_of_facets() << " facets" << std::endl;
|
||||||
|
|
||||||
shape = polyhedron;
|
shape = polyhedron;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -189,6 +203,12 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcFace* l, cgal_face_t& face
|
|||||||
}
|
}
|
||||||
|
|
||||||
face = mf;
|
face = mf;
|
||||||
|
|
||||||
|
// std::cout << "Face: " << std::endl;
|
||||||
|
// for (auto &point: face.outer) {
|
||||||
|
// std::cout << "\tPoint(" << point << ")" << std::endl;
|
||||||
|
// }
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,6 +245,12 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcPolyLoop* l, cgal_wire_t&
|
|||||||
}
|
}
|
||||||
|
|
||||||
result = polygon;
|
result = polygon;
|
||||||
|
|
||||||
|
// std::cout << "PolyLoop: " << std::endl;
|
||||||
|
// for (auto &point: polygon) {
|
||||||
|
// std::cout << "\tPoint(" << point << ")" << std::endl;
|
||||||
|
// }
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,6 +43,8 @@ if ( it != cache.T.end() ) { e = it->second; return true; }
|
|||||||
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
|
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
|
||||||
#include <CGAL/Polyhedron_3.h>
|
#include <CGAL/Polyhedron_3.h>
|
||||||
#include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
|
#include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
|
||||||
|
#include <CGAL/Polygon_mesh_processing/stitch_borders.h>
|
||||||
|
#include <CGAL/Polygon_mesh_processing/orientation.h>
|
||||||
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
|
#include <CGAL/Polygon_mesh_processing/triangulate_faces.h>
|
||||||
#include <CGAL/Polygon_mesh_processing/compute_normal.h>
|
#include <CGAL/Polygon_mesh_processing/compute_normal.h>
|
||||||
|
|
||||||
@@ -72,27 +74,23 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void operator()(CGAL::Polyhedron_3<Kernel>::HalfedgeDS &hds) {
|
void operator()(CGAL::Polyhedron_3<Kernel>::HalfedgeDS &hds) {
|
||||||
std::map<Kernel::Point_3, std::size_t> points_map;
|
std::list<Kernel::Point_3> points;
|
||||||
std::list<std::list<std::size_t>> facet_vertices;
|
std::list<std::list<std::size_t>> facet_vertices;
|
||||||
CGAL::Polyhedron_incremental_builder_3<CGAL::Polyhedron_3<Kernel>::HalfedgeDS> builder(hds, true);
|
CGAL::Polyhedron_incremental_builder_3<CGAL::Polyhedron_3<Kernel>::HalfedgeDS> builder(hds, true);
|
||||||
|
|
||||||
for (auto &face: *face_list) {
|
for (auto &face: *face_list) {
|
||||||
facet_vertices.push_back(std::list<std::size_t>());
|
facet_vertices.push_back(std::list<std::size_t>());
|
||||||
for (auto &point: face.outer) {
|
for (auto &point: face.outer) {
|
||||||
if (points_map.count(point) == 0) {
|
facet_vertices.back().push_back(points.size());
|
||||||
facet_vertices.back().push_back(points_map.size());
|
points.push_back(point);
|
||||||
points_map[point] = points_map.size();
|
|
||||||
} else {
|
|
||||||
facet_vertices.back().push_back(points_map[point]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.begin_surface(points_map.size(), facet_vertices.size());
|
builder.begin_surface(points.size(), facet_vertices.size());
|
||||||
|
|
||||||
for (auto &point: points_map) {
|
for (auto &point: points) {
|
||||||
// std::cout << "Adding point " << point.first << std::endl;
|
// std::cout << "Adding point " << point << std::endl;
|
||||||
builder.add_vertex(point.first);
|
builder.add_vertex(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &facet: facet_vertices) {
|
for (auto &facet: facet_vertices) {
|
||||||
|
|||||||
Reference in New Issue
Block a user