コード例 #1
0
ファイル: NavMesh.cpp プロジェクト: keekekx/NavMesh
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;
}
コード例 #2
0
ファイル: GeneralPolygon.cpp プロジェクト: 675492062/NavMesh
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();
}
コード例 #3
0
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;
}
コード例 #4
0
ファイル: test.cpp プロジェクト: BackupGGCode/polypartition
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);
}