mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-10-03 21:38:12 +00:00
Switched to Nef_polyhedron_3. Some problems...
This commit is contained in:
@@ -7,8 +7,11 @@ void IfcGeom::CgalShape::Triangulate(const IfcGeom::IteratorSettings & settings,
|
|||||||
// std::cout << "Model: " << s.size_of_facets() << " facets and " << s.size_of_vertices() << " vertices" << std::endl;
|
// std::cout << "Model: " << s.size_of_facets() << " facets and " << s.size_of_vertices() << " vertices" << std::endl;
|
||||||
// std::cout << "Valid: " << s.is_valid() << std::endl;
|
// std::cout << "Valid: " << s.is_valid() << std::endl;
|
||||||
|
|
||||||
|
CGAL::Polyhedron_3<Kernel> polyhedron;
|
||||||
|
s.convert_to_polyhedron(polyhedron);
|
||||||
|
|
||||||
// Apply transformation
|
// Apply transformation
|
||||||
if (place != NULL) for (auto &vertex: vertices(s)) {
|
if (place != NULL) for (auto &vertex: vertices(polyhedron)) {
|
||||||
vertex->point() = vertex->point().transform(trsf);
|
vertex->point() = vertex->point().transform(trsf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,7 +25,7 @@ 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);
|
||||||
if (CGAL::Polygon_mesh_processing::triangulate_faces(s)) {
|
if (CGAL::Polygon_mesh_processing::triangulate_faces(polyhedron)) {
|
||||||
// std::cout << "Triangulated model: " << s.size_of_facets() << " facets and " << s.size_of_vertices() << " vertices" << std::endl;
|
// std::cout << "Triangulated model: " << s.size_of_facets() << " facets and " << s.size_of_vertices() << " vertices" << std::endl;
|
||||||
} else {
|
} else {
|
||||||
Logger::Message(Logger::LOG_ERROR, "Failed to triangulate shape");
|
Logger::Message(Logger::LOG_ERROR, "Failed to triangulate shape");
|
||||||
@@ -34,10 +37,10 @@ void IfcGeom::CgalShape::Triangulate(const IfcGeom::IteratorSettings & settings,
|
|||||||
// fafter << s << std::endl;
|
// fafter << s << std::endl;
|
||||||
// fafter.close();
|
// fafter.close();
|
||||||
|
|
||||||
CGAL::Polygon_mesh_processing::compute_normals(s, vertex_normals_map, face_normals_map);
|
CGAL::Polygon_mesh_processing::compute_normals(polyhedron, vertex_normals_map, face_normals_map);
|
||||||
std::map<CGAL::Polyhedron_3<Kernel>::Vertex_const_handle, int> vertices_map;
|
std::map<CGAL::Polyhedron_3<Kernel>::Vertex_const_handle, int> vertices_map;
|
||||||
std::size_t initial_size = t->verts().size()/3;
|
std::size_t initial_size = t->verts().size()/3;
|
||||||
for (auto &vertex: vertices(s)) {
|
for (auto &vertex: vertices(polyhedron)) {
|
||||||
if (vertices_map.count(vertex) == 0) {
|
if (vertices_map.count(vertex) == 0) {
|
||||||
vertices_map[vertex] = (int)(vertices_map.size()+initial_size);
|
vertices_map[vertex] = (int)(vertices_map.size()+initial_size);
|
||||||
t->addVertex(surface_style_id,
|
t->addVertex(surface_style_id,
|
||||||
@@ -49,7 +52,7 @@ void IfcGeom::CgalShape::Triangulate(const IfcGeom::IteratorSettings & settings,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto &face: faces(s)) {
|
for (auto &face: faces(polyhedron)) {
|
||||||
if (!face->is_triangle()) {
|
if (!face->is_triangle()) {
|
||||||
std::cout << "Warning: non-triangular face!" << std::endl;
|
std::cout << "Warning: non-triangular face!" << std::endl;
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcExtrudedAreaSolid *l, cgal
|
|||||||
} face_list.push_back(top_face);
|
} face_list.push_back(top_face);
|
||||||
|
|
||||||
// Naive creation
|
// Naive creation
|
||||||
cgal_shape_t polyhedron = CGAL::Polyhedron_3<Kernel>();
|
CGAL::Polyhedron_3<Kernel> polyhedron = CGAL::Polyhedron_3<Kernel>();
|
||||||
PolyhedronBuilder builder(&face_list);
|
PolyhedronBuilder builder(&face_list);
|
||||||
polyhedron.delegate(builder);
|
polyhedron.delegate(builder);
|
||||||
|
|
||||||
@@ -179,7 +179,7 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcExtrudedAreaSolid *l, cgal
|
|||||||
} CGAL_postcondition(polyhedron.is_valid() && polyhedron.is_closed());
|
} CGAL_postcondition(polyhedron.is_valid() && polyhedron.is_closed());
|
||||||
// std::cout << "After: " << polyhedron.size_of_vertices() << " vertices and " << polyhedron.size_of_facets() << " facets" << std::endl;
|
// std::cout << "After: " << polyhedron.size_of_vertices() << " vertices and " << polyhedron.size_of_facets() << " facets" << std::endl;
|
||||||
|
|
||||||
shape = polyhedron;
|
shape = CGAL::Nef_polyhedron_3<Kernel>(polyhedron);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,7 +209,7 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcConnectedFaceSet* l, cgal_
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Naive creation
|
// Naive creation
|
||||||
cgal_shape_t polyhedron = CGAL::Polyhedron_3<Kernel>();
|
CGAL::Polyhedron_3<Kernel> polyhedron = CGAL::Polyhedron_3<Kernel>();
|
||||||
PolyhedronBuilder builder(&face_list);
|
PolyhedronBuilder builder(&face_list);
|
||||||
polyhedron.delegate(builder);
|
polyhedron.delegate(builder);
|
||||||
|
|
||||||
@@ -221,7 +221,7 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcConnectedFaceSet* l, cgal_
|
|||||||
}
|
}
|
||||||
// std::cout << "After: " << polyhedron.size_of_vertices() << " vertices and " << polyhedron.size_of_facets() << " facets" << std::endl;
|
// std::cout << "After: " << polyhedron.size_of_vertices() << " vertices and " << polyhedron.size_of_facets() << " facets" << std::endl;
|
||||||
|
|
||||||
shape = polyhedron;
|
shape = CGAL::Nef_polyhedron_3<Kernel>(polyhedron);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -279,7 +279,7 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcBlock* l, cgal_shape_t& sh
|
|||||||
face_list.back().outer.push_back(Kernel::Point_3(dx, 0, dz));
|
face_list.back().outer.push_back(Kernel::Point_3(dx, 0, dz));
|
||||||
|
|
||||||
// Naive creation
|
// Naive creation
|
||||||
cgal_shape_t polyhedron = CGAL::Polyhedron_3<Kernel>();
|
CGAL::Polyhedron_3<Kernel> polyhedron = CGAL::Polyhedron_3<Kernel>();
|
||||||
PolyhedronBuilder builder(&face_list);
|
PolyhedronBuilder builder(&face_list);
|
||||||
polyhedron.delegate(builder);
|
polyhedron.delegate(builder);
|
||||||
|
|
||||||
@@ -298,7 +298,7 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcBlock* l, cgal_shape_t& sh
|
|||||||
vertex->point() = vertex->point().transform(trsf);
|
vertex->point() = vertex->point().transform(trsf);
|
||||||
}
|
}
|
||||||
|
|
||||||
shape = polyhedron;
|
shape = CGAL::Nef_polyhedron_3<Kernel>(polyhedron);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,16 +359,12 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcBooleanResult* l, cgal_sha
|
|||||||
|
|
||||||
const IfcSchema::IfcBooleanOperator::IfcBooleanOperator op = l->Operator();
|
const IfcSchema::IfcBooleanOperator::IfcBooleanOperator op = l->Operator();
|
||||||
|
|
||||||
CGAL_precondition(s1.is_valid() && s1.is_closed());
|
if (!s1.is_simple()) {
|
||||||
CGAL::Nef_polyhedron_3<Kernel> nef1(s1);
|
|
||||||
if (!nef1.is_simple()) {
|
|
||||||
Logger::Message(Logger::LOG_ERROR, "s1: Not simple Nef?", operand1->entity);
|
Logger::Message(Logger::LOG_ERROR, "s1: Not simple Nef?", operand1->entity);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGAL_precondition(s2.is_valid() && s2.is_closed());
|
if (!s2.is_simple()) {
|
||||||
CGAL::Nef_polyhedron_3<Kernel> nef2(s2);
|
|
||||||
if (!nef2.is_simple()) {
|
|
||||||
Logger::Message(Logger::LOG_ERROR, "s2: Not simple Nef?", operand2->entity);
|
Logger::Message(Logger::LOG_ERROR, "s2: Not simple Nef?", operand2->entity);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -385,52 +381,52 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcBooleanResult* l, cgal_sha
|
|||||||
if (op == IfcSchema::IfcBooleanOperator::IfcBooleanOperator_DIFFERENCE) {
|
if (op == IfcSchema::IfcBooleanOperator::IfcBooleanOperator_DIFFERENCE) {
|
||||||
|
|
||||||
// std::cout << "Difference" << std::endl;
|
// std::cout << "Difference" << std::endl;
|
||||||
CGAL::Nef_polyhedron_3<Kernel> nef_result = nef1-nef2;
|
CGAL::Nef_polyhedron_3<Kernel> nef_result = s1-s2;
|
||||||
if (!nef_result.is_simple()) {
|
if (!nef_result.is_simple()) {
|
||||||
std::cout << "Not simple: " << nef_result.number_of_volumes() << " volumes" << std::endl;
|
std::cout << "Not simple: " << nef_result.number_of_volumes() << " volumes" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cgal_shape_t result;
|
// cgal_shape_t result;
|
||||||
nef_result.convert_to_polyhedron(result);
|
// nef_result.convert_to_polyhedron(result);
|
||||||
// std::ofstream fresult;
|
// std::ofstream fresult;
|
||||||
// fresult.open("/Users/ken/Desktop/result.off");
|
// fresult.open("/Users/ken/Desktop/result.off");
|
||||||
// fresult << result << std::endl;
|
// fresult << result << std::endl;
|
||||||
// fresult.close();
|
// fresult.close();
|
||||||
shape = result;
|
shape = nef_result;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else if (op == IfcSchema::IfcBooleanOperator::IfcBooleanOperator_UNION) {
|
} else if (op == IfcSchema::IfcBooleanOperator::IfcBooleanOperator_UNION) {
|
||||||
|
|
||||||
// std::cout << "Union" << std::endl;
|
// std::cout << "Union" << std::endl;
|
||||||
CGAL::Nef_polyhedron_3<Kernel> nef_result = nef1+nef2;
|
CGAL::Nef_polyhedron_3<Kernel> nef_result = s1+s2;
|
||||||
if (!nef_result.is_simple()) {
|
if (!nef_result.is_simple()) {
|
||||||
std::cout << "Not simple: " << nef_result.number_of_volumes() << " volumes" << std::endl;
|
std::cout << "Not simple: " << nef_result.number_of_volumes() << " volumes" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cgal_shape_t result;
|
// cgal_shape_t result;
|
||||||
nef_result.convert_to_polyhedron(result);
|
// nef_result.convert_to_polyhedron(result);
|
||||||
// std::ofstream fresult;
|
// std::ofstream fresult;
|
||||||
// fresult.open("/Users/ken/Desktop/result.off");
|
// fresult.open("/Users/ken/Desktop/result.off");
|
||||||
// fresult << result << std::endl;
|
// fresult << result << std::endl;
|
||||||
// fresult.close();
|
// fresult.close();
|
||||||
shape = result;
|
shape = nef_result;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else if (op == IfcSchema::IfcBooleanOperator::IfcBooleanOperator_INTERSECTION) {
|
} else if (op == IfcSchema::IfcBooleanOperator::IfcBooleanOperator_INTERSECTION) {
|
||||||
|
|
||||||
// std::cout << "Intersection" << std::endl;
|
// std::cout << "Intersection" << std::endl;
|
||||||
CGAL::Nef_polyhedron_3<Kernel> nef_result = nef1*nef2;
|
CGAL::Nef_polyhedron_3<Kernel> nef_result = s1*s2;
|
||||||
if (!nef_result.is_simple()) {
|
if (!nef_result.is_simple()) {
|
||||||
std::cout << "Not simple: " << nef_result.number_of_volumes() << " volumes" << std::endl;
|
std::cout << "Not simple: " << nef_result.number_of_volumes() << " volumes" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cgal_shape_t result;
|
// cgal_shape_t result;
|
||||||
nef_result.convert_to_polyhedron(result);
|
// nef_result.convert_to_polyhedron(result);
|
||||||
// std::ofstream fresult;
|
// std::ofstream fresult;
|
||||||
// fresult.open("/Users/ken/Desktop/result.off");
|
// fresult.open("/Users/ken/Desktop/result.off");
|
||||||
// fresult << result << std::endl;
|
// fresult << result << std::endl;
|
||||||
// fresult.close();
|
// fresult.close();
|
||||||
shape = result;
|
shape = nef_result;
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -608,7 +604,7 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcSphere* l, cgal_shape_t& s
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Naive creation
|
// Naive creation
|
||||||
cgal_shape_t polyhedron = CGAL::Polyhedron_3<Kernel>();
|
CGAL::Polyhedron_3<Kernel> polyhedron = CGAL::Polyhedron_3<Kernel>();
|
||||||
PolyhedronBuilder builder(&face_list);
|
PolyhedronBuilder builder(&face_list);
|
||||||
polyhedron.delegate(builder);
|
polyhedron.delegate(builder);
|
||||||
|
|
||||||
@@ -639,7 +635,7 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcSphere* l, cgal_shape_t& s
|
|||||||
// fresult << polyhedron << std::endl;
|
// fresult << polyhedron << std::endl;
|
||||||
// fresult.close();
|
// fresult.close();
|
||||||
|
|
||||||
shape = polyhedron;
|
shape = CGAL::Nef_polyhedron_3<Kernel>(polyhedron);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -679,7 +675,7 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcRectangularPyramid* l, cga
|
|||||||
face_list.back().outer.push_back(Kernel::Point_3(0.5*dx, 0.5*dy, dz));
|
face_list.back().outer.push_back(Kernel::Point_3(0.5*dx, 0.5*dy, dz));
|
||||||
|
|
||||||
// Naive creation
|
// Naive creation
|
||||||
cgal_shape_t polyhedron = CGAL::Polyhedron_3<Kernel>();
|
CGAL::Polyhedron_3<Kernel> polyhedron = CGAL::Polyhedron_3<Kernel>();
|
||||||
PolyhedronBuilder builder(&face_list);
|
PolyhedronBuilder builder(&face_list);
|
||||||
polyhedron.delegate(builder);
|
polyhedron.delegate(builder);
|
||||||
|
|
||||||
@@ -698,7 +694,7 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcRectangularPyramid* l, cga
|
|||||||
vertex->point() = vertex->point().transform(trsf);
|
vertex->point() = vertex->point().transform(trsf);
|
||||||
}
|
}
|
||||||
|
|
||||||
shape = polyhedron;
|
shape = CGAL::Nef_polyhedron_3<Kernel>(polyhedron);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -737,7 +733,7 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcRightCircularCylinder* l,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Naive creation
|
// Naive creation
|
||||||
cgal_shape_t polyhedron = CGAL::Polyhedron_3<Kernel>();
|
CGAL::Polyhedron_3<Kernel> polyhedron = CGAL::Polyhedron_3<Kernel>();
|
||||||
PolyhedronBuilder builder(&face_list);
|
PolyhedronBuilder builder(&face_list);
|
||||||
polyhedron.delegate(builder);
|
polyhedron.delegate(builder);
|
||||||
|
|
||||||
@@ -756,7 +752,7 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcRightCircularCylinder* l,
|
|||||||
vertex->point() = vertex->point().transform(trsf);
|
vertex->point() = vertex->point().transform(trsf);
|
||||||
}
|
}
|
||||||
|
|
||||||
shape = polyhedron;
|
shape = CGAL::Nef_polyhedron_3<Kernel>(polyhedron);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -787,7 +783,7 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcRightCircularCone* l, cgal
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Naive creation
|
// Naive creation
|
||||||
cgal_shape_t polyhedron = CGAL::Polyhedron_3<Kernel>();
|
CGAL::Polyhedron_3<Kernel> polyhedron = CGAL::Polyhedron_3<Kernel>();
|
||||||
PolyhedronBuilder builder(&face_list);
|
PolyhedronBuilder builder(&face_list);
|
||||||
polyhedron.delegate(builder);
|
polyhedron.delegate(builder);
|
||||||
|
|
||||||
@@ -806,7 +802,7 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcRightCircularCone* l, cgal
|
|||||||
vertex->point() = vertex->point().transform(trsf);
|
vertex->point() = vertex->point().transform(trsf);
|
||||||
}
|
}
|
||||||
|
|
||||||
shape = polyhedron;
|
shape = CGAL::Nef_polyhedron_3<Kernel>(polyhedron);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -856,7 +852,7 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcTriangulatedFaceSet* l, cg
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Naive creation
|
// Naive creation
|
||||||
cgal_shape_t polyhedron = CGAL::Polyhedron_3<Kernel>();
|
CGAL::Polyhedron_3<Kernel> polyhedron = CGAL::Polyhedron_3<Kernel>();
|
||||||
PolyhedronBuilder builder(&face_list);
|
PolyhedronBuilder builder(&face_list);
|
||||||
polyhedron.delegate(builder);
|
polyhedron.delegate(builder);
|
||||||
|
|
||||||
@@ -868,6 +864,6 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcTriangulatedFaceSet* l, cg
|
|||||||
} CGAL_postcondition(polyhedron.is_valid() && polyhedron.is_closed());
|
} CGAL_postcondition(polyhedron.is_valid() && polyhedron.is_closed());
|
||||||
// std::cout << "After: " << polyhedron.size_of_vertices() << " vertices and " << polyhedron.size_of_facets() << " facets" << std::endl;
|
// std::cout << "After: " << polyhedron.size_of_vertices() << " vertices and " << polyhedron.size_of_facets() << " facets" << std::endl;
|
||||||
|
|
||||||
shape = polyhedron;
|
shape = CGAL::Nef_polyhedron_3<Kernel>(polyhedron);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcEdgeLoop* l, cgal_wire_t&
|
|||||||
for (IfcSchema::IfcOrientedEdge::list::it it = li->begin(); it != li->end(); ++it) {
|
for (IfcSchema::IfcOrientedEdge::list::it it = li->begin(); it != li->end(); ++it) {
|
||||||
cgal_wire_t w;
|
cgal_wire_t w;
|
||||||
if (convert_wire(*it, w)) {
|
if (convert_wire(*it, w)) {
|
||||||
// TODO: What to do here?
|
// TODO: What to do here? Add some points only?
|
||||||
// mw.Add(TopoDS::Edge(TopoDS_Iterator(w).Value()));
|
// mw.Add(TopoDS::Edge(TopoDS_Iterator(w).Value()));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ struct cgal_face_t {
|
|||||||
std::vector<cgal_wire_t> inner;
|
std::vector<cgal_wire_t> inner;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef CGAL::Polyhedron_3<Kernel> cgal_shape_t;
|
typedef CGAL::Nef_polyhedron_3<Kernel> cgal_shape_t;
|
||||||
typedef boost::graph_traits<CGAL::Polyhedron_3<Kernel>>::vertex_descriptor cgal_vertex_descriptor_t;
|
typedef boost::graph_traits<CGAL::Polyhedron_3<Kernel>>::vertex_descriptor cgal_vertex_descriptor_t;
|
||||||
typedef boost::graph_traits<CGAL::Polyhedron_3<Kernel>>::face_descriptor cgal_face_descriptor_t;
|
typedef boost::graph_traits<CGAL::Polyhedron_3<Kernel>>::face_descriptor cgal_face_descriptor_t;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user