мой подход: < /strong>
Используйте opencv's cv :: oppxpolydp (), чтобы упростить контур. /> Передайте отфильтрованную полилин в CGAL для триангуляции.
Даже с помощью этой стадии фильтрации CGAL все еще обнаруживает пересечения и бросает исключение. Что -то дополнительное, что ожидает CGAL?
Есть ли функции CGAL, которые помогают обрабатывать или удалять пересекающие ограничения автоматически?
Код: Выделить всё
//find contour
contourFinder.findContours(grayscaleImage, *minimumArea, *maximumArea, *considered, false, true);
//find outlines
polylines.clear();
meshes.clear();
for (int i = 0; i < contourFinder.nBlobs; i++) {
ofPolyline polyline;
polyline.clear();
vector contour;
for (const auto& p : contourFinder.blobs.at(i).pts) {
contour.push_back(cv::Point(p.x, p.y));
}
if (contour.size() > 0) {
//reduce points
vector approx;
cv::approxPolyDP(contour, approx, *polygonApproximation, true);
//store end coordinate to check first segment
cv::Point previousPoint = approx.at(approx.size() - 1);
//go through all segments, add only if not causing an intersection
for (int i = 0; i < approx.size(); i++) {
bool wouldIntersect = false;
for (int j = 0; j < polyline.size(); j++) {
if (
doIntersect(
ofPoint(
previousPoint.x,
previousPoint.y
),
ofPoint(
approx.at(i).x,
approx.at(i).y
),
ofPoint(
polyline.getVertices().at((j + 1) % polyline.getVertices().size()).x,
polyline.getVertices().at((j + 1) % polyline.getVertices().size()).y
),
ofPoint(
polyline.getVertices().at(j).x,
polyline.getVertices().at(j).y
)
)
) {
wouldIntersect = true;
}
}
if (wouldIntersect == false) {
cout
Подробнее здесь: [url]https://stackoverflow.com/questions/79477328/handling-intersecting-constraints-in-cgal-constrained-delaunay-triangulation[/url]