Polyhedra built with the incremental builder, IfcConvert crashes

This commit is contained in:
Ken Arroyo Ohori
2017-02-02 14:29:26 -06:00
parent 5724e1ac34
commit 1525cf6bfc
2 changed files with 69 additions and 23 deletions
+22 -23
View File
@@ -115,7 +115,7 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcManifoldSolidBrep* l, Conv
bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcConnectedFaceSet* l, cgal_shape_t& shape) {
IfcSchema::IfcFace::list::ptr faces = l->CfsFaces();
// TopTools_ListOfShape face_list;
std::list<cgal_face_t> face_list;
for (IfcSchema::IfcFace::list::it it = faces->begin(); it != faces->end(); ++it) {
bool success = false;
cgal_face_t face;
@@ -128,30 +128,29 @@ bool IfcGeom::CgalKernel::convert(const IfcSchema::IfcConnectedFaceSet* l, cgal_
Logger::Message(Logger::LOG_WARNING, "Failed to convert face:", (*it)->entity);
continue;
}
// if (face_area(face) > getValue(GV_MINIMAL_FACE_AREA)) {
// face_list.Append(face);
// } else {
// Logger::Message(Logger::LOG_WARNING, "Invalid face:", (*it)->entity);
// }
face_list.push_back(face);
}
//
// if (face_list.Extent() == 0) {
// return false;
// }
//
// if (face_list.Extent() > getValue(GV_MAX_FACES_TO_SEW) || !create_solid_from_faces(face_list, shape)) {
// TopoDS_Compound compound;
// BRep_Builder builder;
// builder.MakeCompound(compound);
//
// TopTools_ListIteratorOfListOfShape face_iterator;
// for (face_iterator.Initialize(face_list); face_iterator.More(); face_iterator.Next()) {
// builder.Add(compound, face_iterator.Value());
// }
// shape = compound;
// }
for (auto const &face : face_list) {
std::cout << "Face" << std::endl;
std::cout << "\touter: ";
for (auto const &point: *face->outer) {
std::cout << "(" << point << ") ";
} std::cout << std::endl;
for (auto const &inner: face->inner) {
std::cout << "\tinner: ";
for (auto const &point: *inner) {
std::cout << "(" << point << ") ";
} std::cout << std::endl;
}
}
cgal_shape_t polyhedron = new CGAL::Polyhedron_3<Kernel>();
PolyhedronBuilder builder(&face_list);
polyhedron->delegate(builder);
shape = polyhedron;
return true;
}
+47
View File
@@ -57,6 +57,53 @@ struct CgalFace {
typedef CgalFace *cgal_face_t;
typedef CGAL::Polyhedron_3<Kernel> *cgal_shape_t;
struct PolyhedronBuilder : public CGAL::Modifier_base<CGAL::Polyhedron_3<Kernel>::HalfedgeDS> {
private:
std::list<cgal_face_t> *face_list;
public:
PolyhedronBuilder(std::list<cgal_face_t> *face_list) {
this->face_list = face_list;
}
void operator()(CGAL::Polyhedron_3<Kernel>::HalfedgeDS &hds) {
std::map<Kernel::Point_3, std::size_t> points_map;
std::list<std::list<std::size_t>> facet_vertices;
CGAL::Polyhedron_incremental_builder_3<CGAL::Polyhedron_3<Kernel>::HalfedgeDS> builder(hds, true);
for (auto const &face: *face_list) {
facet_vertices.push_back(std::list<std::size_t>());
for (auto const &point: *face->outer) {
if (points_map.count(point) == 0) {
facet_vertices.back().push_back(points_map.size());
points_map[point] = points_map.size();
} else {
facet_vertices.back().push_back(points_map[point]);
}
}
}
builder.begin_surface(points_map.size(), facet_vertices.size());
for (auto const &point: points_map) {
std::cout << "Adding point " << point.first << std::endl;
builder.add_vertex(point.first);
}
for (auto const &facet: facet_vertices) {
builder.begin_facet();
std::cout << "Adding facet ";
for (auto const &vertex: facet) {
std::cout << vertex << " ";
builder.add_vertex_to_facet(vertex);
}
std::cout << std::endl;
builder.end_facet();
}
builder.end_surface();
}
};
namespace IfcGeom {
class IFC_GEOM_API CgalCache {