Skip to Content.
Sympa Menu

cgal-discuss - Re: [cgal-discuss] CGAL::difference for 2d polygon return a incorrect result polygon

Subject: CGAL users discussion list

List archive

Re: [cgal-discuss] CGAL::difference for 2d polygon return a incorrect result polygon


Chronological Thread 
  • From: Efi Fogel <>
  • To:
  • Subject: Re: [cgal-discuss] CGAL::difference for 2d polygon return a incorrect result polygon
  • Date: Sun, 26 Apr 2020 14:00:12 +0300
  • Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None ; spf=Pass ; spf=None
  • Ironport-phdr: 9a23:43oGQRP+TqtiyGJbTxYl6mtUPXoX/o7sNwtQ0KIMzox0I/7/rarrMEGX3/hxlliBBdydt6sZzbeJ+Pu8EUU7or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6arXK99yMdFQviPgRpOOv1BpTSj8Oq3Oyu5pHfeQpFiCe9bL9oLBi7rwrdu8cZjIB/Nqs/1xzFr2dSde9L321oP1WTnxj95se04pFu9jlbtuwi+cBdT6j0Zrw0QrNEAjsoNWA1/9DrugLYTQST/HscU34ZnQRODgPY8Rz1RJbxsi/9tupgxCmXOND9QL4oVTi+6apgVRnlgzoFOTEk6mHaksN/jKxZrxyhqRJxwJPabp+JO/dlZKzRYckXSHBdUspNVSFMBJ63YYsVD+oGOOZVt4bzp1UPrRCjBQesA+zvxSFMhnTr2qA1zeohEQDI3AwnENIBrnDUoc76NKcXS++1za3IwS/fYPNR3Dfw8Y7FeQ0vr/GLWLJ/a8vRyU83GgPDlFqfspfqPzeL2egXr2eb6O9gWfqui24hsQFxoyKgyt0iionTgI8e11PK9T1hzYorOdG1TFR3bN2kHZdKqi2XNop7Ttk/T2xsuCs3zKANt4ShcygQ0psnwgbSa/yZfIiM5RLuTOORLi15hHJhYb6/hhKy/VW5xu3yS8W51FZHojBKktnLsXAN2BjT5dadRvRh+Ueh3C6D1wHV6u5aPUA5jbTXJ4Ilz7IqlZcesV7PEjL3lUj3lqOaa0Ep9+iw5+TieLrmp5ucN4FuigH5N6QjgtKwAeo5MggAWGib9vqz1Ln48E32RbVFlPw2kq3DvJ/GIsQbo7a1AxVJ3YY79xa/EzCm3cwEknkINl1FfAuLgJXoO1HVPP/4EOy/g0+3nTdwx/HGO6XhDY/XInjClrfhZ7d95FRGxAo919AMr69SEawLdfLvRlfq5pufFQ48KwXywuD9Cdw72JlZQnOKGqbeMaXcthiD6esrZuWNf4QIoy2uFv4++vTOkXo9zF8BYbGyj9xQc2G9Bv0gIkODYHOqjM1GCnYPpgN5TerkjxqJXjdXInqzRKkh/SpoNYS9EI3/S5Cx1bydwD+gTNoRfXFDElnKEHHydozCVe1LczOXOsYmkzoKUv+qRIYlkB2vrwTn0KE0Eu2B8SIRsdfv1cN++vbIvRA07z19ScqHgE+XSGQhs20JDxEx06176RhwxFaN1qd1h9RXENVS47VCVQJsZs2U9PBzF92nAlGJRdyOUlvzGoz7UwF0dco4xpo1W2g4G9imiUqdjS+jArtQlrjSQZJto/+a0H/2KMJwjX3B0ft51gV0co50LWSjw5VH2U3LHYeQyheWkq+rceIX2yufrD7Sn1rLh1lRVUtLaYuAWHkeYkXMqtGgvxHNSravDfIsNQ4TkMM=

Please provide a simple test case, nicely indented, using only point type from EPEC (exact predicates exact constructions),  that can be used to reproduce the problem.

   ____  _        ____             _
  /_____/_) o    /__________  __  //
 (____ (   (    (    (_/ (_/-(-'_(/
                         _/




On Sun, 26 Apr 2020 at 13:14, Luoyu <> wrote:
Hi,
    I'm newer to use cgal, I want to split the given polygon by another
polygon. Then I choose the CGAL::difference function. But in some cases,
it's function return incorrect result polygon for me.

Here is my code:

// TArray is a template for an array, FVector2D is a struct for a 2d point,
use float number type.

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Boolean_set_operations_2.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/Polygon_with_holes_2.h>
#include <CGAL/Polygon_set_2.h>

#include <list>

typedef CGAL::Exact_predicates_exact_constructions_kernel exactKernel;
typedef exactKernel::Point_2                              exactPoint_2;
typedef CGAL::Polygon_2<exactKernel>                      exactPolygon_2;
typedef CGAL::Polygon_with_holes_2<exactKernel>         
exactPolygon_with_holes_2;
typedef CGAL::Polygon_set_2<exactKernel>                 
exactPolygon_set_2;
typedef exactKernel::Segment_2                            exactSegment_2;
typedef exactKernel::Point_2                                                      exactPoint_2;
typedef exactKernel::Vector_2                                                     exactVector_2;

void UPaveMethodFunctionLibrary::FiltrationPolygon(const
TArray<FPolygonData>& InHolesPolygon, TArray<FVector2D>&
OutFiltrationPolygon)
{
        if (OutFiltrationPolygon.Num() < 3 || InHolesPolygon.Num() == 0){
                return;
        }

        exactPolygon_2 targetPolygon;
        std::list<exactPolygon_2> holesPolygon;

        for (int32 filtrationPolygonIndex = 0; filtrationPolygonIndex <
OutFiltrationPolygon.Num(); ++filtrationPolygonIndex)
        {

targetPolygon.push_back(exactPoint_2(OutFiltrationPolygon[filtrationPolygonIndex].X,
OutFiltrationPolygon[filtrationPolygonIndex].Y));
        }

        if (targetPolygon.is_clockwise_oriented()) {
                targetPolygon.reverse_orientation();
        }

        for (int32 holePolygonIndex = 0; holePolygonIndex < InHolesPolygon.Num();
++holePolygonIndex)
        {
                exactPolygon_2 currentHolePolygon;

                for (int32 holePointIndex = 0; holePointIndex <
InHolesPolygon[holePolygonIndex].Polygon.Num(); ++holePointIndex)
                {

currentHolePolygon.push_back(exactPoint_2(InHolesPolygon[holePolygonIndex].Polygon[holePointIndex].X,
InHolesPolygon[holePolygonIndex].Polygon[holePointIndex].Y));
                }

                if (currentHolePolygon.is_clockwise_oriented()) {
                        currentHolePolygon.reverse_orientation();
                }

                holesPolygon.push_back(currentHolePolygon);
        }

        bool IsExistInList = false;

        std::list<exactPolygon_2> tempholesPolygon;

        for (std::list<exactPolygon_2>::const_iterator holePolygonListIt =
holesPolygon.cbegin(); holePolygonListIt != holesPolygon.cend();
++holePolygonListIt)
        {
                for (exactPolygon_2::Edge_const_iterator holePolygonIt =
holePolygonListIt->edges_begin(); holePolygonIt !=
holePolygonListIt->edges_end(); ++holePolygonIt)
                {
                        for (exactPolygon_2::Edge_const_iterator targetPolygonIt =
targetPolygon.edges_begin(); targetPolygonIt != targetPolygon.edges_end();
++targetPolygonIt)
                        {
                                if (targetPolygonIt->collinear_has_on(holePolygonIt->start()) &&
targetPolygonIt->collinear_has_on(holePolygonIt->end()))
                                {
                                        IsExistInList = true;
                                        tempholesPolygon.push_back(*holePolygonListIt);
                                        break;
                                }
                        }
                        if (IsExistInList){
                                break;
                        }
                }
                IsExistInList = false;
        }

        if (tempholesPolygon.size() == 0){
                return;
        }

        for (exactPolygon_2 currentHolePolygon : tempholesPolygon)
        {
                std::list<exactPolygon_with_holes_2> differencePolygons;

                CGAL::difference(targetPolygon, currentHolePolygon,
std::back_inserter(differencePolygons));

                if (differencePolygons.size() != 1) {
                        return;
                }

                targetPolygon = differencePolygons.front().outer_boundary();
                if (targetPolygon.is_clockwise_oriented()) {
                        targetPolygon.reverse_orientation();
                }
        }

        if (targetPolygon.size() < 3 || !targetPolygon.is_simple()){
                return;
        }

        OutFiltrationPolygon.Empty();

        for (exactPolygon_2::Vertex_const_iterator it =
targetPolygon.vertices_begin(); it != targetPolygon.vertices_end(); it++)
        {
                double pointX = CGAL::to_double(it->x());
                double pointY = CGAL::to_double(it->y());
                OutFiltrationPolygon.AddUnique(FVector2D(pointX, pointY));
        }
}



--
Sent from: http://cgal-discuss.949826.n4.nabble.com/

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss





Archive powered by MHonArc 2.6.18.

Top of Page