MCPcopy Create free account
hub / github.com/IfcOpenShell/IfcOpenShell / CgalShape

Method CgalShape

src/ifcgeom/kernels/cgal/CgalConversionResult.cpp:102–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102ifcopenshell::geometry::CgalShape::CgalShape(const cgal_shape_t& shape, bool convex) {
103 shape_ = shape;
104 convex_tag_ = convex;
105
106 std::set<cgal_shape_t::Facet_handle> faces_to_remove;
107
108 for (const auto& face : CGAL::faces(*shape_)) {
109 auto V = newell(*face).to_vector();
110 CGAL::Plane_3<Kernel_> plane(CGAL::Point_3<Kernel_>(), V);
111 auto b1 = plane.base1();
112 auto b2 = plane.base2();
113
114 if (V.squared_length() == 0) {
115 Logger::Warning("Removed face due to self-intersections");
116 faces_to_remove.insert(face);
117 continue;
118 }
119 auto C = face->halfedge()->vertex()->point();
120 auto transform_point = [&V, &C, &b1, &b2](const auto& p) {
121 auto dv = p - C;
122 return CGAL::Point_2<Kernel_>(
123 dv * b1,
124 dv * b2
125 );
126 };
127
128 std::vector<CGAL::Point_2<Kernel_>> ps;
129
130 for (auto& he1 : CGAL::halfedges_around_face(face->halfedge(), *shape_)) {
131 const auto& source = he1->vertex()->point();
132 ps.push_back(transform_point(source));
133 }
134
135 if (!CGAL::Polygon_2<Kernel_>(ps.begin(), ps.end()).is_simple()) {
136 Logger::Warning("Removed face due to self-intersections");
137 faces_to_remove.insert(face);
138 }
139 }
140
141 {
142 for (auto& face : faces_to_remove) {
143 CGAL::Euler::remove_face(face->halfedge(), *shape_);
144 }
145 }
146
147 if (shape.size_of_facets() != 1) {
148 // the size_of_facets() == 1 check is for handling the specical case of
149 // storing a single point in a polyhedron as a degenerate triangle
150 //
151 // @todo come up with a proper variant for storing lower dimensional entities
152
153 // @todo we don't have access to settings here so we don't know whether we should triangulate
154 // remove_degenerate_faces() is also called in the triangulate() call below though...
155 // CGAL::Polygon_mesh_processing::triangulate_faces(*shape_);
156 // CGAL::Polygon_mesh_processing::remove_degenerate_faces(*shape_);
157 }
158}
159

Callers

nothing calls this directly

Calls 7

WarningFunction · 0.85
vertexMethod · 0.80
push_backMethod · 0.80
newellFunction · 0.70
insertMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected