diff --git a/EgtGeomKernel.rc b/EgtGeomKernel.rc index f84e231..4fd7082 100644 Binary files a/EgtGeomKernel.rc and b/EgtGeomKernel.rc differ diff --git a/PolyLine.cpp b/PolyLine.cpp index 9357389..466f77f 100644 --- a/PolyLine.cpp +++ b/PolyLine.cpp @@ -1513,3 +1513,82 @@ SplitPolyLineAtPoint( const PolyLine& plPoly, const Point3d& ptP, double dToler, plPoly2.AddUPoint( 0, ptP, false) ; return true ; } + +//---------------------------------------------------------------------------- +bool +AssociatePolyLinesMinDistPoints( const PolyLine& PL1, const PolyLine& PL2, PNTIVECTOR& vPnt1, PNTIVECTOR& vPnt2, bool& bCommonInternalPoints) +{ + // controllo che le polyline abbiano almeno un punto + int nPnt1 = PL1.GetPointNbr() ; + int nPnt2 = PL2.GetPointNbr() ; + if ( nPnt1 == 0 || nPnt2 == 0) + return false ; + + bCommonInternalPoints = false ; // indica la presenza di punti interni in comune tra le due polylines + + vPnt1.reserve( PL1.GetPointNbr()) ; + Point3d ptP1 ; + bool bF1 = PL1.GetFirstPoint( ptP1) ; + while ( bF1) { + vPnt1.emplace_back( ptP1, -1) ; + bF1 = PL1.GetNextPoint( ptP1) ; + } + int nTotP1 = int( vPnt1.size()) ; + + vPnt2.reserve( PL2.GetPointNbr()) ; + Point3d ptP2 ; + bool bF2 = PL2.GetFirstPoint( ptP2) ; + while ( bF2) { + vPnt2.emplace_back( ptP2, -1) ; + bF2 = PL2.GetNextPoint( ptP2) ; + } + int nTotP2 = int( vPnt2.size()) ; + + // calcoli per prima curva + int LastJ = 0 ; + vPnt1[0].second = 0 ; + for ( int i = 1 ; i < nTotP1 ; ++ i) { + double dSqDistMin = SqDist( vPnt1[i].first, vPnt2[LastJ].first) ; + double dApprDistMin = ApproxDist( vPnt1[i].first, vPnt2[LastJ].first) ; + int MinJ = LastJ ; + for ( int j = LastJ + 1 ; j < nTotP2 ; ++ j) { + double dSqDist = SqDist( vPnt1[i].first, vPnt2[j].first) ; + if ( dSqDist < dSqDistMin - 2 * dApprDistMin * EPS_SMALL) { + dSqDistMin = dSqDist ; + dApprDistMin = ApproxDist( vPnt1[i].first, vPnt2[j].first) ; + MinJ = j ; + } + else if ( dSqDist > 16 * dSqDistMin) + break ; + } + if ( i < nTotP1 - 1 && dSqDistMin < EPS_SMALL) + bCommonInternalPoints = true ; + vPnt1[i].second = MinJ ; + LastJ = MinJ ; + } + + // calcoli per seconda curva + int LastI = 0 ; + vPnt2[0].second = 0 ; + for ( int j = 1 ; j < nTotP2 ; ++ j) { + double dSqDistMin = SqDist( vPnt2[j].first, vPnt1[LastI].first) ; + double dApprDistMin = ApproxDist( vPnt2[j].first, vPnt1[LastI].first) ; + int MinI = LastI ; + for ( int i = LastI + 1 ; i < nTotP1 ; ++ i) { + double dSqDist = SqDist( vPnt2[j].first, vPnt1[i].first) ; + if ( dSqDist < dSqDistMin - 2 * dApprDistMin * EPS_SMALL) { + dSqDistMin = dSqDist ; + dApprDistMin = ApproxDist( vPnt2[j].first, vPnt1[i].first) ; + MinI = i ; + } + else if ( dSqDist > 16 * dSqDistMin) + break ; + } + if ( j < nTotP2 - 1 && dSqDistMin < EPS_SMALL) + bCommonInternalPoints = true ; + vPnt2[j].second = MinI ; + LastI = MinI ; + } + + return true ; +} \ No newline at end of file diff --git a/SurfTriMesh.cpp b/SurfTriMesh.cpp index aa72184..2acf8db 100644 --- a/SurfTriMesh.cpp +++ b/SurfTriMesh.cpp @@ -2141,79 +2141,26 @@ SurfTriMesh::CreateByTwoCurves( const PolyLine& PL1, const PolyLine& PL2, int nR ResetHashGrids3d() ; // se rigata a minima distanza tra le due curve - if ( nRuledType == RLT_MINDIST) { + if ( nRuledType == RLT_MINDIST) { // verifico ci siano almeno due punti diversi per curva if ( ( PL1.IsClosed() && PL1.GetPointNbr() < 3) || PL1.GetPointNbr() < 2) return false ; if ( ( PL2.IsClosed() && PL2.GetPointNbr() < 3) || PL2.GetPointNbr() < 2) - return false ; - + return false ; + // flag di curve entrambe chiuse e correzione conseguente a numero totale punti differenti bool bClosed = PL1.IsClosed() && PL2.IsClosed() ; - // vettori punti con primo punto dell'altra curva a distanza minima - PNTUVECTOR vPnt1 ; - vPnt1.reserve( PL1.GetPointNbr()) ; - Point3d ptP1 ; - bool bF1 = PL1.GetFirstPoint( ptP1) ; - while ( bF1) { - vPnt1.emplace_back( ptP1, -1) ; - bF1 = PL1.GetNextPoint( ptP1) ; - } - int nTotP1 = int( vPnt1.size()) ; - PNTUVECTOR vPnt2 ; - vPnt2.reserve( PL2.GetPointNbr()) ; - Point3d ptP2 ; - bool bF2 = PL2.GetFirstPoint( ptP2) ; - while ( bF2) { - vPnt2.emplace_back( ptP2, -1) ; - bF2 = PL2.GetNextPoint( ptP2) ; - } + // vettori punti con indice del primo punto dell'altra curva a distanza minima + PNTIVECTOR vPnt1, vPnt2 ; + bool bCommonInternalPoints ; + if ( ! AssociatePolyLinesMinDistPoints( PL1, PL2, vPnt1, vPnt2, bCommonInternalPoints)) + return false ; + // verifico che non ci siano punti interni in comune + if ( bCommonInternalPoints) + return false ; + int nTotP1 = int( vPnt1.size()) ; int nTotP2 = int( vPnt2.size()) ; - // calcoli per prima curva - int LastJ = 0 ; - vPnt1[0].second = 0 ; - for ( int i = 1 ; i < nTotP1 ; ++ i) { - double dSqDistMin = SqDist( vPnt1[i].first, vPnt2[LastJ].first) ; - double dApprDistMin = ApproxDist( vPnt1[i].first, vPnt2[LastJ].first) ; - int MinJ = LastJ ; - for ( int j = LastJ + 1 ; j < nTotP2 ; ++ j) { - double dSqDist = SqDist( vPnt1[i].first, vPnt2[j].first) ; - if ( dSqDist < dSqDistMin - 2 * dApprDistMin * EPS_SMALL) { - dSqDistMin = dSqDist ; - dApprDistMin = ApproxDist( vPnt1[i].first, vPnt2[j].first) ; - MinJ = j ; - } - else if ( dSqDist > 16 * dSqDistMin) - break ; - } - if ( i < nTotP1 - 1 && dSqDistMin < EPS_SMALL) - return false ; - vPnt1[i].second = MinJ ; - LastJ = MinJ ; - } - // calcoli per seconda curva - int LastI = 0 ; - vPnt2[0].second = 0 ; - for ( int j = 1 ; j < nTotP2 ; ++ j) { - double dSqDistMin = SqDist( vPnt2[j].first, vPnt1[LastI].first) ; - double dApprDistMin = ApproxDist( vPnt2[j].first, vPnt1[LastI].first) ; - int MinI = LastI ; - for ( int i = LastI + 1 ; i < nTotP1 ; ++ i) { - double dSqDist = SqDist( vPnt2[j].first, vPnt1[i].first) ; - if ( dSqDist < dSqDistMin - 2 * dApprDistMin * EPS_SMALL) { - dSqDistMin = dSqDist ; - dApprDistMin = ApproxDist( vPnt2[j].first, vPnt1[i].first) ; - MinI = i ; - } - else if ( dSqDist > 16 * dSqDistMin) - break ; - } - if ( j < nTotP2 - 1 && dSqDistMin < EPS_SMALL) - return false ; - vPnt2[j].second = MinI ; - LastI = MinI ; - } // Costruisco la mesh int nVertNbr = nTotP1 + nTotP2 ; @@ -2317,7 +2264,7 @@ SurfTriMesh::CreateByTwoCurves( const PolyLine& PL1, const PolyLine& PL2, int nR if ( ! VerifyPolylinesForTwoCurves( PL1, PL2)) return false ; - // flag di curve chiuse + // flag di curve chiuse bool bClosed = PL1.IsClosed() && PL2.IsClosed() ; // recupero i parametri delle due polilinee double dU1F ; PL1.GetFirstU( dU1F) ;