list<TPPLPoly> NavMesh::_processNavigationConvexTesselation(list<TPPLPoly> &polygons) { TPPLPartition partition; list<TPPLPoly> navigationMeshPolygons; // convex tesselation with minimal convex elements int res = partition.ConvexPartition_HM(&polygons, &navigationMeshPolygons); if( res == 0 ) std::cerr<< "NavMesh::processNavigationTesselation -> Error in the ConvexPartition_HM method"<<std::endl; return navigationMeshPolygons; }
void GeneralPolygon::_updateOptimalConvexTesselation() { TPPLPartition partition; _optimalConvexTesselation.clear(); list<TPPLPoly> polys = (list<TPPLPoly>)*this; // convex tesselation with minimal convex elements int res = partition.ConvexPartition_HM(&polys, &_optimalConvexTesselation); // _optimalConvexTesselation will be in local space if( res == 0 ) std::cerr<< "GeneralPolygon::_updateOptimalConvexTesselation -> Error in the ConvexPartition_HM method"<<std::endl; polys.clear(); }
static std::vector<Polygon> decompose(const Polygon& polygons) { TPPLPartition pp; TPPLPoly tp_poly; TPPLPolyList tp_parts; tp_poly.Init(polygons.size()); for (size_t i = 0; i < polygons.size(); i++) { tp_poly[i] = {polygons[i].x, polygons[i].y, i}; } pp.ConvexPartition_HM(&tp_poly, &tp_parts); std::vector<Polygon> ret; for (TPPLPoly& tp_poly : tp_parts) { Polygon polygon; for (size_t i = 0; i < tp_poly.GetNumPoints(); i++) { auto point = tp_poly.GetPoint(i); polygon.push_back({point.x, point.y}); } ret.push_back(polygon); } return ret; }
void GenerateTestData() { TPPLPartition pp; list<TPPLPoly> testpolys,result,expectedResult; ReadPolyList("test_input.txt",&testpolys); DrawPolyList("test_input.bmp",&testpolys); pp.Triangulate_EC(&testpolys,&result); //pp.Triangulate_EC(&(*testpolys.begin()),&result); DrawPolyList("test_triangulate_EC.bmp",&result); WritePolyList("test_triangulate_EC.txt",&result); result.clear(); expectedResult.clear(); pp.Triangulate_OPT(&(*testpolys.begin()),&result); DrawPolyList("test_triangulate_OPT.bmp",&result); WritePolyList("test_triangulate_OPT.txt",&result); result.clear(); expectedResult.clear(); pp.Triangulate_MONO(&testpolys,&result); //pp.Triangulate_MONO(&(*testpolys.begin()),&result); DrawPolyList("test_triangulate_MONO.bmp",&result); WritePolyList("test_triangulate_MONO.txt",&result); result.clear(); expectedResult.clear(); pp.ConvexPartition_HM(&testpolys,&result); //pp.ConvexPartition_HM(&(*testpolys.begin()),&result); DrawPolyList("test_convexpartition_HM.bmp",&result); WritePolyList("test_convexpartition_HM.txt",&result); result.clear(); expectedResult.clear(); pp.ConvexPartition_OPT(&(*testpolys.begin()),&result); DrawPolyList("test_convexpartition_OPT.bmp",&result); WritePolyList("test_convexpartition_OPT.txt",&result); }