From 736e20e599bf0f54773c69e03fc0759a38eb4cd4 Mon Sep 17 00:00:00 2001 From: SaraP Date: Mon, 8 Sep 2025 15:21:27 +0200 Subject: [PATCH] EgtGeomKernel : - nell'associare i punti a minima distanza delle polylines aggiuta gestione speciale per gli spigoli. --- PolyLine.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/PolyLine.cpp b/PolyLine.cpp index d9cd847..ca205e6 100644 --- a/PolyLine.cpp +++ b/PolyLine.cpp @@ -1607,6 +1607,8 @@ SplitPolyLineAtPoint( const PolyLine& plPoly, const Point3d& ptP, double dToler, bool AssociatePolyLinesMinDistPoints( const PolyLine& PL1, const PolyLine& PL2, PNTIVECTOR& vPnt1, PNTIVECTOR& vPnt2, bool& bCommonInternalPoints) { + const double CORNER_COS = 0.96 ; + // controllo che le polyline abbiano almeno un punto int nPnt1 = PL1.GetPointNbr() ; int nPnt2 = PL2.GetPointNbr() ; @@ -1633,6 +1635,36 @@ AssociatePolyLinesMinDistPoints( const PolyLine& PL1, const PolyLine& PL2, PNTIV } int nTotP2 = int( vPnt2.size()) ; + // individuo gli spigoli + BOOLVECTOR vSharpCorner1( nTotP1, false), vSharpCorner2( nTotP2, false) ; + for ( int i = 0 ; i < nTotP1 - 1 ; i ++) { + // se estremo di curva aperta non è spigolo + if ( i == 0 && ! PL1.IsClosed()) + continue ; + // recupero direzioni precedente e successiva + int nPrevI = ( i == 0 ? nTotP1 - 2 : i - 1) ; + int nNextI = i + 1 ; + Vector3d vtPrev = vPnt1[i].first - vPnt1[nPrevI].first ; + vtPrev.Normalize() ; + Vector3d vtNext = vPnt1[nNextI].first - vPnt1[i].first ; + vtNext.Normalize() ; + vSharpCorner1[i] = ( vtPrev * vtNext < CORNER_COS) ; + } + vSharpCorner1.back() = vSharpCorner1.front() ; + + for ( int i = 0 ; i < nTotP2 - 1 ; i ++) { + if ( i == 0 && ! PL2.IsClosed()) + continue ; + int nPrevI = ( i == 0 ? nTotP2 - 2 : i - 1) ; + int nNextI = i + 1 ; + Vector3d vtPrev = vPnt2[i].first - vPnt2[nPrevI].first ; + vtPrev.Normalize() ; + Vector3d vtNext = vPnt2[nNextI].first - vPnt2[i].first ; + vtNext.Normalize() ; + vSharpCorner2[i] = ( vtPrev * vtNext < CORNER_COS) ; + } + vSharpCorner2.back() = vSharpCorner2.front() ; + // calcoli per prima curva int nLastJ = 0 ; vPnt1[0].second = 0 ; @@ -1664,6 +1696,28 @@ AssociatePolyLinesMinDistPoints( const PolyLine& PL1, const PolyLine& PL2, PNTIV nLastJ = nMinJ ; } + // correzione per associare spigoli : se spigolo non associato ad altro spigolo, verifico se esiste un possibile + // spigolo da associare + for ( int i = 0 ; i < nTotP1 ; i ++) { + if ( vSharpCorner1[i] && ! vSharpCorner2[vPnt1[i].second]) { + // individuo i limiti per la ricerca dello spigolo + int nPrevI = ( i == 0 ? 0 : i - 1) ; + int nNextI = ( i == nTotP1 - 1 ? i : i + 1) ; + int nPrevJ = vPnt1[nPrevI].second ; + int nNextJ = vPnt1[nNextI].second ; + int nStart = ( vSharpCorner2[nPrevJ] ? nPrevJ + 1 : nPrevJ) ; + int nEnd = ( vSharpCorner2[nNextJ] ? nNextJ - 1 : nNextJ) ; + double dMinDist = INFINITO ; + int nCorner = vPnt1[i].second ; + // cerco lo spigolo più vicino nel range fissato + for ( int j = nStart ; j <= nEnd ; j ++) { + if ( vSharpCorner2[j] && Dist( vPnt1[i].first, vPnt2[j].first) < dMinDist) + nCorner = j ; + } + vPnt1[i].second = nCorner ; + } + } + // calcoli per seconda curva int nLastI = 0 ; vPnt2[0].second = 0 ; @@ -1694,5 +1748,24 @@ AssociatePolyLinesMinDistPoints( const PolyLine& PL1, const PolyLine& PL2, PNTIV nLastI = nMinI ; } + // correzione per associare spigoli + for ( int i = 0 ; i < nTotP2 ; i ++) { + if ( vSharpCorner2[i] && ! vSharpCorner1[vPnt2[i].second]) { + int nPrevI = ( i == 0 ? 0 : i - 1) ; + int nNextI = ( i == nTotP2 - 1 ? i : i + 1) ; + int nPrevJ = vPnt2[nPrevI].second ; + int nNextJ = vPnt2[nNextI].second ; + int nStart = ( vSharpCorner1[nPrevJ] ? nPrevJ + 1 : nPrevJ) ; + int nEnd = ( vSharpCorner1[nNextJ] ? nNextJ - 1 : nNextJ) ; + double dMinDist = INFINITO ; + int nCorner = vPnt2[i].second ; + for ( int j = nStart ; j <= nEnd ; j ++) { + if ( vSharpCorner1[j] && Dist( vPnt2[i].first, vPnt1[j].first) < dMinDist) + nCorner = j ; + } + vPnt2[i].second = nCorner ; + } + } + return true ; } \ No newline at end of file