I am struggling to compute the projection of a polyhedron onto the xy plane. Currently I use the following code:
vector<Polygon_2> ii;
vector<Polygon_with_holes_2> oi;
for (Facet_iterator s = polyhedron.facets_begin();
s != polyhedron.facets_end(); ++s) {
Halfedge_facet_circulator h = s->facet_begin(), he(h);
Polygon_2 polygon;
do {
Point p1 = h->vertex()->point();
polygon.insert(polygon.vertices_end(), Point_2(p1.x(), p1.y()));
} while (++h != he);
if (polygon.orientation() == CGAL::NEGATIVE)
polygon.reverse_orientation();
ii.push_back(polygon);
}
CGAL::join(ii.begin(), ii.end(), std::back_inserter(oi));
This iterates over the polyhedron surfaces and for each surface performs the 2d projection manually. The resulting polygons are then joined together.
However, from the manual I feel that this is not the intended way to use the library for such a task. The class Project_traits_xy_3
hints, that there is a regular way to achieve the projection with CGAL. However, I could not find a proper documentation or examples for this.
Can anyone point me into the right direction here? I feel, that this should be a standard task with an elegant way.
what you are looking for is the computation of a silhouette, and we don't have that in CGAL as a high level function. Your code does the job.
If your object is watertight, you could take only the faces which have a normal pointing upwards. You could also compute connected components of faces with normls pointing upwards, and then create polygons for the boundary of such components.
The projection traits class is used to interpret 3D points as 2D points, for example to construct a 2D Constrained Delaunay triangulation, but I don't see where it could come in handy here.