From dd3091fc13769fb730ba952951ffd05bdbb54831 Mon Sep 17 00:00:00 2001 From: Daniele Bariletti Date: Fri, 3 Apr 2026 17:27:13 +0200 Subject: [PATCH 1/2] EgtGeomKernel : - miglioramento delle rigate con bezier. --- SurfBezier.cpp | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/SurfBezier.cpp b/SurfBezier.cpp index 851ec1a..7da5111 100644 --- a/SurfBezier.cpp +++ b/SurfBezier.cpp @@ -5054,6 +5054,8 @@ SurfBezier::CreateByTwoCurves( const ICurve* pCurve0, const ICurve* pCurve1, int PNTUVECTOR vMatch1 ; PNTUVECTOR vMatch1b ; PNTVECTOR vPnt1 ; vPnt1.emplace_back( ptP1) ; + BOOLVECTOR vbMismatch1( plU1.GetPointNbr() - 1) ; + fill( vbMismatch1.begin(), vbMismatch1.end(), false) ; while ( plU1.GetNextPoint( ptP1, true)) { Vector3d vtDirPrev ; CrvU1.GetCurve( vPnt1.size() - 1)->GetEndDir( vtDirPrev) ; Vector3d vtDirCurr ; CrvU1.GetCurve( vPnt1.size())->GetStartDir( vtDirCurr) ; @@ -5072,9 +5074,10 @@ SurfBezier::CreateByTwoCurves( const ICurve* pCurve0, const ICurve* pCurve1, int if ( icp.GetIntersCount() > 0) { icp.GetIntersPointNearTo( ptP1, ptJoint, dParam) ; AdjustParamFromApprox( plApproxU0, dParam) ; - if ( Dist( ptP1, ptJoint) > 2 * Dist( ptP1, ptMinDist)) { + if ( Dist( ptP1, ptJoint) > 1.5 * Dist( ptP1, ptMinDist)) { ptJoint = ptMinDist ; dParam = dParamMinDist ; + vbMismatch1[ssize(vMatch1b) - 1] = true ; } } else { @@ -5113,6 +5116,8 @@ SurfBezier::CreateByTwoCurves( const ICurve* pCurve0, const ICurve* pCurve1, int PNTUVECTOR vMatch0 ; PNTUVECTOR vMatch0b ; PNTVECTOR vPnt0 ; vPnt0.emplace_back( ptP0) ; + BOOLVECTOR vbMismatch0( plU0.GetPointNbr() - 1) ; + fill( vbMismatch0.begin(), vbMismatch0.end(), false) ; while ( plU0.GetNextPoint( ptP0, true)) { Vector3d vtDirPrev ; CrvU0.GetCurve( vPnt0.size() - 1)->GetEndDir( vtDirPrev) ; Vector3d vtDirCurr ; CrvU0.GetCurve( vPnt0.size())->GetStartDir( vtDirCurr) ; @@ -5131,9 +5136,10 @@ SurfBezier::CreateByTwoCurves( const ICurve* pCurve0, const ICurve* pCurve1, int if ( icp.GetIntersCount() > 0) { icp.GetIntersPointNearTo( ptP0, ptJoint, dParam) ; AdjustParamFromApprox( plApproxU1, dParam) ; - if ( Dist( ptP0, ptJoint) > 2 * Dist( ptP0, ptMinDist)) { + if ( Dist( ptP0, ptJoint) > 1.5 * Dist( ptP0, ptMinDist)) { ptJoint = ptMinDist ; dParam = dParamMinDist ; + vbMismatch0[ssize(vMatch0b) - 1] = true ; } } else { @@ -5184,14 +5190,25 @@ SurfBezier::CreateByTwoCurves( const ICurve* pCurve0, const ICurve* pCurve1, int // tramite due misure diverse della distanza INTINTVECTOR vMismatch0 ; INTINTVECTOR vMismatch1 ; - //double dMaxDist = Dist( vPnt0[0], vPnt1[0]) / 20 ; + DBLVECTOR vdDistMismatch0 ; double dMaxDist = Dist( vPnt0[0], vPnt1[0]) / 3 ; + double dMinDist = Dist( vPnt0[0], vPnt1[0]) / 20 ; for ( int i = 0 ; i < ssize( vMatch0) ; ++i) { + vdDistMismatch0.push_back( Dist( vMatch0[i].first, vMatch0b[i].first)) ; if ( ! AreSamePointEpsilon( vMatch0[i].first, vMatch0b[i].first, dMaxDist)) { int c = i + 1 ; - while ( ! AreSamePointEpsilon( vMatch0[c].first, vMatch0b[c].first, dMaxDist)) + // scorro in avanti + while ( ! AreSamePointEpsilon( vMatch0[c].first, vMatch0b[c].first, dMinDist) || vbMismatch0[c]) { + vdDistMismatch0.push_back( Dist( vMatch0[c].first, vMatch0b[c].first)) ; ++c ; - vMismatch0.emplace_back( i, c) ; + } + vdDistMismatch0.push_back( Dist( vMatch0[c].first, vMatch0b[c].first)) ; + //scorro indietro + int p = i - 1 ; + while ( p > 0 && ! AreSamePointEpsilon( vMatch0[p].first, vMatch0b[p].first, dMinDist) || vbMismatch0[p]) { + --p ; + } + vMismatch0.emplace_back( p, c) ; i = c ; } } @@ -5209,12 +5226,23 @@ SurfBezier::CreateByTwoCurves( const ICurve* pCurve0, const ICurve* pCurve1, int } vMismatch0.resize( nCurr + 1) ; + DBLVECTOR vdDistMismatch1 ; for ( int i = 0 ; i < ssize( vMatch1) ; ++i) { + vdDistMismatch1.push_back( Dist( vMatch1[i].first, vMatch1b[i].first)) ; if ( ! AreSamePointEpsilon( vMatch1[i].first, vMatch1b[i].first, dMaxDist)) { int c = i + 1 ; - while ( ! AreSamePointEpsilon( vMatch1[c].first, vMatch1b[c].first, dMaxDist)) + // scorro in avanti + while ( ! AreSamePointEpsilon( vMatch1[c].first, vMatch1b[c].first, dMinDist) || vbMismatch1[c]) { + vdDistMismatch1.push_back( Dist( vMatch1[c].first, vMatch1b[c].first)) ; ++c ; - vMismatch1.emplace_back( i, c) ; + } + vdDistMismatch1.push_back( Dist( vMatch1[c].first, vMatch1b[c].first)) ; + // scorro indietro + int p = i - 1 ; + while ( p > 0 && ! AreSamePointEpsilon( vMatch1[p].first, vMatch1b[p].first, dMinDist) || vbMismatch1[p]) { + --p ; + } + vMismatch1.emplace_back( p, c) ; i = c ; } } @@ -5633,7 +5661,7 @@ SurfBezier::CreateByTwoCurves( const ICurve* pCurve0, const ICurve* pCurve1, int if ( c_temp + 1 > dLastParamMatch1) pCC0.Set( CrvU0.CopyParamRange( dLastParamMatch1, c_temp + 1)) ; if ( j_temp + 1 > dLastParamMatch0) - pCC1.Set( CrvU1.CopyParamRange( dLastParamMatch0, j_temp + 1)) ; + pCC1.Set( CrvU1.CopyParamRange( dLastParamMatch0, j_temp + 1)) ; nPointsBetween0 = int( c_temp + 1 - floor( dLastParamMatch1) - 1) ; nPointsBetween1 = int( j_temp + 1 - floor( dLastParamMatch0) - 1) ; } From a27b9e871a33ddb837c8103fcaeb071c1a15c693 Mon Sep 17 00:00:00 2001 From: Daniele Bariletti Date: Wed, 8 Apr 2026 13:41:43 +0200 Subject: [PATCH 2/2] EgtGeomKernel : - piccola correzione alle rigate. --- SurfBezier.cpp | 134 ++++++++++++++++++++++++++----------------------- 1 file changed, 72 insertions(+), 62 deletions(-) diff --git a/SurfBezier.cpp b/SurfBezier.cpp index 7da5111..70ebca4 100644 --- a/SurfBezier.cpp +++ b/SurfBezier.cpp @@ -5193,72 +5193,74 @@ SurfBezier::CreateByTwoCurves( const ICurve* pCurve0, const ICurve* pCurve1, int DBLVECTOR vdDistMismatch0 ; double dMaxDist = Dist( vPnt0[0], vPnt1[0]) / 3 ; double dMinDist = Dist( vPnt0[0], vPnt1[0]) / 20 ; + int nPnt0 = CrvU0.GetCurveCount() ; for ( int i = 0 ; i < ssize( vMatch0) ; ++i) { vdDistMismatch0.push_back( Dist( vMatch0[i].first, vMatch0b[i].first)) ; if ( ! AreSamePointEpsilon( vMatch0[i].first, vMatch0b[i].first, dMaxDist)) { int c = i + 1 ; // scorro in avanti - while ( ! AreSamePointEpsilon( vMatch0[c].first, vMatch0b[c].first, dMinDist) || vbMismatch0[c]) { + while ( c < nPnt0 && ( ! AreSamePointEpsilon( vMatch0[c].first, vMatch0b[c].first, dMinDist) || vbMismatch0[c])) { vdDistMismatch0.push_back( Dist( vMatch0[c].first, vMatch0b[c].first)) ; ++c ; } vdDistMismatch0.push_back( Dist( vMatch0[c].first, vMatch0b[c].first)) ; //scorro indietro int p = i - 1 ; - while ( p > 0 && ! AreSamePointEpsilon( vMatch0[p].first, vMatch0b[p].first, dMinDist) || vbMismatch0[p]) { + while ( p > 0 && ( ! AreSamePointEpsilon( vMatch0[p].first, vMatch0b[p].first, dMinDist) || vbMismatch0[p])) { --p ; } vMismatch0.emplace_back( p, c) ; i = c ; } } - // faccio un merge di regioni adiacenti di mismatch - int nCurr = 0, nNext = 1 ; - while ( nNext < ssize( vMismatch0)) { - if ( vMismatch0[nNext].first - vMismatch0[nCurr].second < 2 + EPS_SMALL) { - vMismatch0[nCurr].second = vMismatch0[nNext].second ; - } - else { - ++nCurr ; - vMismatch0[nCurr] = vMismatch0[nNext] ; - } - ++nNext ; - } - vMismatch0.resize( nCurr + 1) ; + //// faccio un merge di regioni adiacenti di mismatch + //int nCurr = 0, nNext = 1 ; + //while ( nNext < ssize( vMismatch0)) { + // if ( vMismatch0[nNext].first - vMismatch0[nCurr].second < 2 + EPS_SMALL) { + // vMismatch0[nCurr].second = vMismatch0[nNext].second ; + // } + // else { + // ++nCurr ; + // vMismatch0[nCurr] = vMismatch0[nNext] ; + // } + // ++nNext ; + //} + //vMismatch0.resize( nCurr + 1) ; DBLVECTOR vdDistMismatch1 ; + int nPnt1 = CrvU1.GetCurveCount() ; for ( int i = 0 ; i < ssize( vMatch1) ; ++i) { vdDistMismatch1.push_back( Dist( vMatch1[i].first, vMatch1b[i].first)) ; if ( ! AreSamePointEpsilon( vMatch1[i].first, vMatch1b[i].first, dMaxDist)) { int c = i + 1 ; // scorro in avanti - while ( ! AreSamePointEpsilon( vMatch1[c].first, vMatch1b[c].first, dMinDist) || vbMismatch1[c]) { + while ( c < nPnt1 && ( ! AreSamePointEpsilon( vMatch1[c].first, vMatch1b[c].first, dMinDist) || vbMismatch1[c])) { vdDistMismatch1.push_back( Dist( vMatch1[c].first, vMatch1b[c].first)) ; ++c ; } vdDistMismatch1.push_back( Dist( vMatch1[c].first, vMatch1b[c].first)) ; // scorro indietro int p = i - 1 ; - while ( p > 0 && ! AreSamePointEpsilon( vMatch1[p].first, vMatch1b[p].first, dMinDist) || vbMismatch1[p]) { + while ( p > 0 && ( ! AreSamePointEpsilon( vMatch1[p].first, vMatch1b[p].first, dMinDist) || vbMismatch1[p])) { --p ; } vMismatch1.emplace_back( p, c) ; i = c ; } } - // faccio un merge di regioni adiacenti di mismatch - nCurr = 0, nNext = 1 ; - while ( nNext < ssize( vMismatch1)) { - if ( vMismatch1[nNext].first - vMismatch1[nCurr].second < 2 + EPS_SMALL) { - vMismatch1[nCurr].second = vMismatch1[nNext].second ; - } - else { - ++nCurr ; - vMismatch1[nCurr] = vMismatch1[nNext] ; - } - ++nNext ; - } - vMismatch1.resize( nCurr + 1) ; + //// faccio un merge di regioni adiacenti di mismatch + //nCurr = 0, nNext = 1 ; + //while ( nNext < ssize( vMismatch1)) { + // if ( vMismatch1[nNext].first - vMismatch1[nCurr].second < 2 + EPS_SMALL) { + // vMismatch1[nCurr].second = vMismatch1[nNext].second ; + // } + // else { + // ++nCurr ; + // vMismatch1[nCurr] = vMismatch1[nNext] ; + // } + // ++nNext ; + //} + //vMismatch1.resize( nCurr + 1) ; // verifico la presenza di eventuali "edge" lungo le polyline ( punti di passaggio di un edge e quindi cambi bruschi di direzione della polyline) BOOLVECTOR vEdgeSplit0, vEdgeSplit1 ; @@ -5552,48 +5554,46 @@ SurfBezier::CreateByTwoCurves( const ICurve* pCurve0, const ICurve* pCurve1, int else { // cerco se ho degli spigoli nella zona di mismatch // se ne ho definisco una regione compresa tra un estremo( start o end) e uno spigolo (presente su entrambe le curve) - INTVECTOR vnEdges0, vnEdges1 ; - if ( ssize( vMismatch0) > 0 && bMismatch0) { - for ( int i = max( vMismatch0[m0].first, c) ; i < vMismatch0[m0].second ; ++i) { - if ( vEdgeSplit0[i]) - vnEdges0.push_back(i) ; - } - } - if ( ssize( vMismatch1) > 0 && bMismatch1) { - for ( int i = max( vMismatch1[m1].first, j) ; i < vMismatch1[m1].second ; ++i) { - if ( vEdgeSplit1[i]) - vnEdges1.push_back(i) ; - } - } - - // se ho degli edge che non matchano tra loro semplicemente tratto tutta la regione di mismatch insieme - if ( ssize( vnEdges0) != ssize( vnEdges1) || ssize( vnEdges0) == 0 || ssize( vnEdges1) == 0) { - if ( bMismatch0 && bMismatch1) { + + if ( bMismatch0 && bMismatch1) { int c_temp0 = vMismatch0[m0].second ; int j_temp0 = int( vMatch0[c_temp0].second) ; int j_temp1 = vMismatch1[m1].second ; int c_temp1 = int( vMatch1[j_temp1].second) ; c_temp = max( c_temp0, c_temp1) ; j_temp = max( j_temp0, j_temp1) ; - } - else if ( bMismatch0) { - c_temp = vMismatch0[m0].second ; - j_temp = int( vMatch0[c_temp].second) ; - } - else if ( bMismatch1){ - j_temp = vMismatch1[m1].second ; - c_temp = int( vMatch1[j_temp].second) ; - } + } + else if ( bMismatch0) { + c_temp = vMismatch0[m0].second ; + j_temp = int( vMatch0[c_temp].second) ; + } + else if ( bMismatch1){ + j_temp = vMismatch1[m1].second ; + c_temp = int( vMatch1[j_temp].second) ; + } + INTVECTOR vnEdges0, vnEdges1 ; + for ( int i = c ; i < c_temp ; ++i) { + if ( vEdgeSplit0[i]) + vnEdges0.push_back(i) ; + } + for ( int i = j ; i < j_temp ; ++i) { + if ( vEdgeSplit1[i]) + vnEdges1.push_back(i) ; + } + + // se ho degli edge che non matchano tra loro semplicemente tratto tutta la regione di mismatch insieme + if ( ssize( vnEdges0) != ssize( vnEdges1) || ssize( vnEdges0) == 0 || ssize( vnEdges1) == 0) { + ; } // se ho corrispondenza tra gli edge (in numero) allora (do per scontato di accoppiarli e ) li prendo come estremi di zone da trattare separatamente else { // definisco gli estremi della zona da riparametrizzare // controllo se ho già matchato parte della zona di mismatch // cerco la coppia successiva alla corrente per determinare la zona su cui lavorare ora - bEndOnEdge = true ; - bool bAtHalfwayEdge = false ; + bEndOnEdge = true ; // se un edge fa da chiusura a questo tratto + bool bAtHalfwayEdge = false ; // se ho già percorso un tratto di questo mismatch e quindi parto da un edge for ( int i = 0 ; i < ssize( vnEdges0) ; ++i) { - if ( c == vnEdges0[i]) { + if ( c - 1 == vnEdges0[i]) { bAtHalfwayEdge = true ; if ( i < ssize( vnEdges0) - 1) { c_temp = vnEdges0[i+1] ; @@ -6421,8 +6421,18 @@ SurfBezier::CreateByIsoParamSet( const ICurve* pCurve0, const ICurve* pCurve1, c dLastParam1 = vIso[c].dParam1 ; ++c ; while ( c < ssize( vIso)) { - if ( vIso[c].dParam0 < dLastParam0 || vIso[c].dParam1 < dLastParam1) - return false ; + if ( vIso[c].dParam0 < dLastParam0) { + if ( dLastParam0 - vIso[c].dParam0 < EPS_ZERO) + vIso[c].dParam0 = dLastParam0 + EPS_PARAM ; + else + return false ; + } + if ( vIso[c].dParam1 < dLastParam1) { + if ( dLastParam1 - vIso[c].dParam1 < EPS_ZERO) + vIso[c].dParam1 = dLastParam1 + EPS_PARAM ; + else + return false ; + } dLastParam0 = vIso[c].dParam0 ; dLastParam1 = vIso[c].dParam1 ; ++c ; @@ -6486,7 +6496,7 @@ SurfBezier::CreateByIsoParamSet( const ICurve* pCurve0, const ICurve* pCurve1, c } else nPointsBetween1 = 0 ; - if ( nPointsBetween0 > 0 || nPointsBetween1 > 0) { + if ( nPointsBetween0 >= 0 || nPointsBetween1 >= 0) { // calcolo la parametrizzazione locale dei punti compresi tra le due isoparametriche double dLen0 = dLenCurr0 - dLenPrev0 ; double dLen1 = dLenCurr1 - dLenPrev1 ;