Surface* Surface::createSurface(const Polyline &ply) { if (!ply.isClosed()) { std::cout << "Error in Surface::createSurface() - Polyline is not closed..." << "\n"; return NULL; } if (ply.getNumberOfPoints() > 2) { // create empty surface Surface* sfc(new Surface(ply.getPointsVec())); Polygon* polygon (new Polygon (ply)); polygon->computeListOfSimplePolygons (); // create surfaces from simple polygons const std::list<GEOLIB::Polygon*>& list_of_simple_polygons ( polygon->getListOfSimplePolygons()); for (std::list<GEOLIB::Polygon*>::const_iterator simple_polygon_it ( list_of_simple_polygons.begin()); simple_polygon_it != list_of_simple_polygons.end(); ++simple_polygon_it) { std::list<GEOLIB::Triangle> triangles; std::cout << "triangulation of surface: ... " << std::flush; MathLib::EarClippingTriangulation(*simple_polygon_it, triangles); std::cout << "done - " << triangles.size () << " triangles " << "\n"; // add Triangles to Surface std::list<GEOLIB::Triangle>::const_iterator it (triangles.begin()); while (it != triangles.end()) { sfc->addTriangle ((*it)[0], (*it)[1], (*it)[2]); it++; } } delete polygon; return sfc; } else { std::cout << "Error in Surface::createSurface() - Polyline consists of less than three points and therefore cannot be triangulated..." << "\n"; return NULL; } }
Surface* Surface::createSurface(const Polyline &ply) { if (!ply.isClosed()) { WARN("Error in Surface::createSurface() - Polyline is not closed."); return NULL; } if (ply.getNumberOfPoints() > 2) { // create empty surface Surface *sfc(new Surface(ply.getPointsVec())); Polygon* polygon (new Polygon (ply)); polygon->computeListOfSimplePolygons (); // create surfaces from simple polygons const std::list<GeoLib::Polygon*>& list_of_simple_polygons (polygon->getListOfSimplePolygons()); for (std::list<GeoLib::Polygon*>::const_iterator simple_polygon_it (list_of_simple_polygons.begin()); simple_polygon_it != list_of_simple_polygons.end(); ++simple_polygon_it) { std::list<GeoLib::Triangle> triangles; GeoLib::EarClippingTriangulation(*simple_polygon_it, triangles); // add Triangles to Surface std::list<GeoLib::Triangle>::const_iterator it (triangles.begin()); while (it != triangles.end()) { sfc->addTriangle ((*it)[0], (*it)[1], (*it)[2]); it++; } } delete polygon; if (sfc->getNTriangles() == 0) { WARN("Surface::createSurface(): Triangulation does not contain any triangle."); delete sfc; return nullptr; } return sfc; } else { WARN("Error in Surface::createSurface() - Polyline consists of less than three points and therefore cannot be triangulated."); return nullptr; } }