EgtGeomKernel :

- piccole migliorie e correzioni.
This commit is contained in:
Dario Sassi
2025-09-09 09:12:53 +02:00
parent 8ddc1c70e1
commit c7aad8d917
+90 -78
View File
@@ -798,7 +798,7 @@ PolyLine::RemoveAlignedPoints( double dToler)
vInd.push_back( 0) ;
if ( ! DouglasPeuckerSimplification( vPtU, dSqTol, 0, int( vPtU.size()) - 1, vInd))
return false ;
vInd.push_back( vPtU.size() - 1) ;
vInd.push_back( int( vPtU.size()) - 1) ;
}
// altrimenti chiusa
else {
@@ -819,7 +819,7 @@ PolyLine::RemoveAlignedPoints( double dToler)
vInd.push_back( nMaxInd) ;
if ( ! DouglasPeuckerSimplification( vPtU, dSqTol, nMaxInd, int( vPtU.size()) - 1, vInd))
return false ;
vInd.push_back( vPtU.size() - 1) ;
vInd.push_back( int( vPtU.size()) - 1) ;
}
// ordino in senso crescente
@@ -827,7 +827,7 @@ PolyLine::RemoveAlignedPoints( double dToler)
// se chiusa e almeno 4 punti rimasti, controllo allineamento dell'inizio con precedente e successivo rimasti
if ( IsClosed() && vInd.size() >= 4) {
if ( DistPointLine( vPtU[vInd[0]].first, vPtU[vInd[1]].first, vPtU[vInd[vInd.size()-2]].first).IsEpsilon( dToler)) {
if ( DistPointLine( vPtU[vInd[0]].first, vPtU[vInd[1]].first, vPtU[vInd[int(vInd.size())-2]].first).IsEpsilon( dToler)) {
vInd.erase( vInd.begin()) ;
vInd.back() = vInd.front() ;
}
@@ -1447,7 +1447,7 @@ IsPointInsidePolyLine( const Point3d& ptP, const PolyLine& plPoly, double dToler
}
// Determino tangente di riferimento
Vector3d vtTang ;
// se minima distanza nell'estremo iniziale del segmento
// se minima distanza nell'estremo iniziale del segmento
if ( AreSamePointApprox( ptMinDist, prev( itMinDistEnd)->first)) {
// direzione del segmento
Vector3d vtCurrTg = itMinDistEnd->first - prev( itMinDistEnd)->first ;
@@ -1463,7 +1463,7 @@ IsPointInsidePolyLine( const Point3d& ptP, const PolyLine& plPoly, double dToler
vtTang = vtPrevTg + vtCurrTg ;
vtTang.Normalize() ;
}
// se altrimenti minima distanza nell'estremo finale del segmento
// se altrimenti minima distanza nell'estremo finale del segmento
else if ( AreSamePointApprox( ptMinDist, itMinDistEnd->first)) {
// direzione del segmento
Vector3d vtCurrTg = itMinDistEnd->first - prev( itMinDistEnd)->first ;
@@ -1479,7 +1479,7 @@ IsPointInsidePolyLine( const Point3d& ptP, const PolyLine& plPoly, double dToler
vtTang = vtCurrTg + vtNextTg ;
vtTang.Normalize() ;
}
// altrimenti minima distanza con l'interno
// altrimenti minima distanza con l'interno
else {
vtTang = itMinDistEnd->first - prev( itMinDistEnd)->first ;
}
@@ -1614,8 +1614,9 @@ AssociatePolyLinesMinDistPoints( const PolyLine& PL1, const PolyLine& PL2, PNTIV
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
// indica la presenza di punti interni in comune tra le due polylines
bCommonInternalPoints = false ;
vPnt1.reserve( PL1.GetPointNbr()) ;
Point3d ptP1 ;
@@ -1659,7 +1660,7 @@ AssociatePolyLinesMinDistPoints( const PolyLine& PL1, const PolyLine& PL2, PNTIV
nMinJ = nLastJ ;
// verifica se è un punto interno in comune con l'altra polyline
if ( i < nTotP1 - 1 && dDist < EPS_SMALL && abs( dMinDistPar - floor( dMinDistPar + 0.5)) < EPS_SMALL)
if ( i < nTotP1 - 1 && dDist < EPS_SMALL && abs( dMinDistPar - floor( dMinDistPar + 0.5)) < EPS_SMALL)
bCommonInternalPoints = true ;
vPnt1[i].second = nMinJ ;
@@ -1689,7 +1690,7 @@ AssociatePolyLinesMinDistPoints( const PolyLine& PL1, const PolyLine& PL2, PNTIV
if ( nMinI < nLastI)
nMinI = nLastI ;
if ( j < nTotP2 - 1 && dDist < EPS_SMALL && abs( dMinDistPar - floor( dMinDistPar + 0.5)) < EPS_SMALL)
if ( j < nTotP2 - 1 && dDist < EPS_SMALL && abs( dMinDistPar - floor( dMinDistPar + 0.5)) < EPS_SMALL)
bCommonInternalPoints = true ;
vPnt2[j].second = nMinI ;
@@ -1702,21 +1703,21 @@ AssociatePolyLinesMinDistPoints( const PolyLine& PL1, const PolyLine& PL2, PNTIV
bool
MatchPolyLinesAddingPoints( const PolyLine& PL1, const PolyLine& PL2, int nType, PNTIVECTOR& vPnt1, PNTIVECTOR& vPnt2)
{
// prima trovo le associazioni senza aggiunte di punti
// prima trovo le associazioni senza aggiunte di punti
Point3d ptP2 ;
CurveComposite cc1, cc2 ;
cc1.FromPolyLine( PL1) ;
cc2.FromPolyLine( PL2) ;
int nPnt1 = PL1.GetPointNbr() ;
int nPnt2 = PL2.GetPointNbr() ;
vector<pair<Point3d,double>> vMatch2 ;
vector<POINTU> vMatch2 ;
PL2.GetFirstPoint( ptP2) ;
while ( PL2.GetNextPoint( ptP2, true)) {
DistPointCurve dpc( ptP2, cc1, false) ;
int nFlag = 0 ;
double dParam ; dpc.GetParamAtMinDistPoint( 0, dParam, nFlag) ;
Point3d ptJoint ; dpc.GetMinDistPoint( 0, ptJoint, nFlag) ;
vMatch2.push_back( pair<Point3d,double>( ptJoint, dParam)) ;
vMatch2.emplace_back( ptJoint, dParam) ;
}
int nAtStart2 = 0 ; // match ripetuti dalla curva U0 allo start della curva U1
@@ -1783,9 +1784,9 @@ MatchPolyLinesAddingPoints( const PolyLine& PL1, const PolyLine& PL2, int nType,
}
if ( ! bFoundMatch) {
++nRep2 ;
++ nRep2 ;
// capisco se il punto è rep o se lo è il suo successivo
if( j + 1 < dParam)
if ( j + 1 < dParam)
nCase = 1 ;
else
nCase = 2 ;
@@ -1819,7 +1820,7 @@ MatchPolyLinesAddingPoints( const PolyLine& PL1, const PolyLine& PL2, int nType,
continue ;
}
else if ( dParam > nPnt1 - EPS_SMALL ) {
vbRep2[c] = nAtEnd1 == 0 ? false : true ;
vbRep2[c] = ( nAtEnd1 == 0 ? false : true) ;
vbRep2.back() = true ;
++ nAtEnd1 ;
++c ;
@@ -1835,21 +1836,21 @@ MatchPolyLinesAddingPoints( const PolyLine& PL1, const PolyLine& PL2, int nType,
else {
dLastParamMatch = dParam ;
ptLastPointMatch = ptJoint ;
//se sono troppo vicino ad uno split esistente allora non faccio nulla
if( abs(dParam - round( dParam)) < 100 * EPS_PARAM) {
// se sono troppo vicino ad uno split esistente allora non faccio nulla
if ( abs( dParam - round( dParam)) < 100 * EPS_PARAM) {
++c ;
continue ;
}
vdSplit2.push_back( dParam) ;
// verifico se ho un match per questo punto
// in tal caso vuol dire che sto creando una ripetizione nRep0
// verifico se ho un match per questo punto
// in tal caso vuol dire che sto creando una ripetizione nRep0
int nCase = 0 ;
for ( int j = 0 ; j < int( vdMatch1.size()) ; ++j) {
if ( abs(vdMatch1[j] - (c + 1)) < EPS_SMALL) {
// devo però verificare che non ci sia un match successivo, perché in quel caso non ho una ripetizione
if ( abs( vdMatch1[j] - (c + 1)) < EPS_SMALL) {
// devo però verificare che non ci sia un match successivo, perché in quel caso non ho una ripetizione
bool bFoundMatch = false ;
for ( int z = int( vdMatch1[j]) ; z < int( vMatch2.size()) ; ++z) {
if ( abs( vMatch2[z].second - ( j + 1 )) < EPS_SMALL ) {
if ( abs( vMatch2[z].second - ( j + 1 )) < EPS_SMALL) {
bFoundMatch = true ;
break ;
}
@@ -1857,8 +1858,8 @@ MatchPolyLinesAddingPoints( const PolyLine& PL1, const PolyLine& PL2, int nType,
if ( ! bFoundMatch) {
++nRep1 ;
// capisco se il punto è rep o se lo è il suo successivo
if( j + 1 < dParam)
// capisco se il punto è rep o se lo è il suo successivo
if ( j + 1 < dParam)
nCase = 1 ;
else
nCase = 2 ;
@@ -1871,56 +1872,68 @@ MatchPolyLinesAddingPoints( const PolyLine& PL1, const PolyLine& PL2, int nType,
++c ;
}
// applico effettivamente gli split e aggiungo gli elementi ai vettori vbRep
// applico effettivamente gli split e aggiungo gli elementi ai vettori vbRep
int nUnit = 0 ;
if ( ! vdSplit1.empty())
nUnit = int( vdSplit1.back()) ;
for ( int z = int( vdSplit1.size() - 1) ; z >= 0 ; --z) {
nUnit = int( vdSplit1.back()) ;
for ( int z = int( vdSplit1.size()) - 1 ; z >= 0 ; --z) {
double dSplit = vdSplit1[z] ;
int nSplit = int( dSplit) ;
// se sto cercando di fare uno split sulla stessa curva che ho già splittato al passaggio precedente allora devo
// riscalare
if ( nSplit == nUnit && z < int( vdSplit1.size() - 1)) {
dSplit = nSplit + ( dSplit - nSplit) / (vdSplit1[z+1] - nSplit);
// se sto cercando di fare uno split sulla stessa curva che ho già splittato al passaggio precedente allora devo
// riscalare
if ( nSplit == nUnit && z < int( vdSplit1.size()) - 1) {
dSplit = nSplit + ( dSplit - nSplit) / ( vdSplit1[z+1] - nSplit) ;
}
nUnit = nSplit ;
cc2.AddJoint( dSplit) ;
switch( vnAddedOrNextIsRep1[z]) {
case 0 : if( vbRep2[nSplit])
++ nRep2 ;
// di default aggiungerei false, ma se il successivo è già un Rep allora anche questo deve esserlo
vbRep2.insert( vbRep2.begin() + nSplit, vbRep2[nSplit]) ; break ;
case 1 : vbRep2.insert( vbRep2.begin() + nSplit, true) ; break ;
case 2 : if ( vbRep2[nSplit])
--nRep2 ;
else
vbRep2[nSplit] = true ;
vbRep2.insert( vbRep2.begin() + nSplit, false) ; break ;
switch ( vnAddedOrNextIsRep1[z]) {
case 0 :
if ( vbRep2[nSplit])
++ nRep2 ;
// di default aggiungerei false, ma se il successivo è già un Rep allora anche questo deve esserlo
vbRep2.insert( vbRep2.begin() + nSplit, vbRep2[nSplit]) ;
break ;
case 1 :
vbRep2.insert( vbRep2.begin() + nSplit, true) ;
break ;
case 2 :
if ( vbRep2[nSplit])
--nRep2 ;
else
vbRep2[nSplit] = true ;
vbRep2.insert( vbRep2.begin() + nSplit, false) ;
break ;
}
}
if( ! vdSplit2.empty())
if ( ! vdSplit2.empty())
nUnit = int( vdSplit2.back()) ;
for ( int z = int( vdSplit2.size() - 1) ; z >= 0 ; --z) {
for ( int z = int( vdSplit2.size()) - 1 ; z >= 0 ; --z) {
double dSplit = vdSplit2[z] ;
int nSplit = int( dSplit) ;
// se sto cercando di fare uno split sulla stessa curva che ho già splittato al passaggio precedente allora devo
// riscalare
if ( nSplit == nUnit && z < int( vdSplit2.size() - 1)) {
dSplit = nSplit + ( dSplit - nSplit) / (vdSplit2[z+1] - nSplit);
// se sto cercando di fare uno split sulla stessa curva che ho già splittato al passaggio precedente allora devo
// riscalare
if ( nSplit == nUnit && z < int( vdSplit2.size()) - 1) {
dSplit = nSplit + ( dSplit - nSplit) / (vdSplit2[z+1] - nSplit) ;
}
nUnit = nSplit ;
cc1.AddJoint( dSplit) ;
switch( vnAddedOrNextIsRep2[z]) {
case 0 : if( vbRep1[nSplit])
++ nRep1 ;
// di default aggiungerei false, ma se il successivo è già un Rep allora anche questo deve esserlo
vbRep1.insert( vbRep1.begin() + nSplit, vbRep1[nSplit]) ; break ;
case 1 : vbRep1.insert( vbRep1.begin() + nSplit, true) ; break ;
case 2 : if( vbRep1[nSplit])
-- nRep1 ;
else
vbRep1[nSplit] = true ;
vbRep1.insert( vbRep1.begin() + nSplit, false) ; break ;
switch ( vnAddedOrNextIsRep2[z]) {
case 0 :
if ( vbRep1[nSplit])
++ nRep1 ;
// di default aggiungerei false, ma se il successivo è già un Rep allora anche questo deve esserlo
vbRep1.insert( vbRep1.begin() + nSplit, vbRep1[nSplit]) ;
break ;
case 1 :
vbRep1.insert( vbRep1.begin() + nSplit, true) ;
break ;
case 2 :
if ( vbRep1[nSplit])
-- nRep1 ;
else
vbRep1[nSplit] = true ;
vbRep1.insert( vbRep1.begin() + nSplit, false) ;
break ;
}
}
@@ -1932,12 +1945,12 @@ MatchPolyLinesAddingPoints( const PolyLine& PL1, const PolyLine& PL2, int nType,
int nCrv2 = 0 ;
while ( nAddedSpan < nPnt1 + nAtStart1 + nAtEnd1 + nRep2) {
if ( nCrv1 >= nPnt1)
nCrv1 = nPnt1 - 1;
nCrv1 = nPnt1 - 1 ;
if ( nCrv2 >= nPnt2)
nCrv2 = nPnt2 - 1;
nCrv2 = nPnt2 - 1 ;
bool bRep1 = vbRep1[nCrv1] ;
bool bRep2 = vbRep2[nCrv2] ;
if ( bRep1 && bRep2 ) {
if ( bRep1 && bRep2) {
vbRep1[nCrv1] = false ;
bRep1 = false ;
vbRep2[nCrv2] = false ;
@@ -1949,41 +1962,40 @@ MatchPolyLinesAddingPoints( const PolyLine& PL1, const PolyLine& PL2, int nType,
++ nCrv2 ;
if ( ! bRep2 || nCrv1 == nPnt1 - 1)
++ nCrv1 ;
++nAddedSpan ;
++ nAddedSpan ;
}
// se non sono arrivato all'ultima curva su U0 o U1 vuol dire che ho creato delle ripetizioni che non ho contato prima
if( nCrv2 < nPnt2) {
// se non sono arrivato all'ultima curva su U0 o U1 vuol dire che ho creato delle ripetizioni che non ho contato prima
if ( nCrv2 < nPnt2) {
nRep2 += nPnt2 - nCrv2 ;
for ( int z = int( vbRep2.size() - 1) ; z >= nCrv2 ; --z)
for ( int z = int( vbRep2.size()) - 1 ; z >= nCrv2 ; --z)
vbRep2[z] = true ;
}
if( nCrv1 < nPnt1) {
nRep1 += nPnt1 - nCrv1 ;
for ( int z = int( vbRep1.size() - 1) ; z >= nCrv1 ; --z)
for ( int z = int( vbRep1.size()) - 1 ; z >= nCrv1 ; --z)
vbRep1[z] = true ;
}
// trovo il numero di span che dovrà avere la superficie
// ( numero di sottocurve che compongono la U0 + tutte le ripetizioni dei match di punti della curva U1 con i punti di U0)
// trovo il numero di span che dovrà avere la superficie
// ( numero di sottocurve che compongono la U0 + tutte le ripetizioni dei match di punti della curva U1 con i punti di U0)
int nPnt = nPnt1 + nAtStart1 + nAtEnd1 + nRep2 ;
if( nPnt != nPnt2 + nAtStart2 + nAtEnd2 + nRep1)
LOG_DBG_ERR( GetEGkLogger(), "There could be an error in the creation of a ruled surface in mode RLT_B_MINDIST_PLUS") ;
if ( nPnt != nPnt2 + nAtStart2 + nAtEnd2 + nRep1)
LOG_DBG_ERR( GetEGkLogger(), "There could be an error in the creation of a ruled surface in mode RLT_B_MINDIST_PLUS") ;
// aggiungo i punti di controllo scorrendo in contemporanea le due curve
// aggiungo i punti di controllo scorrendo in contemporanea le due curve
nAddedSpan = 0 ;
nCrv1 = 0 ;
nCrv2 = 0 ;
bool bLast1 = false ;
bool bLast2 = false ;
while ( nAddedSpan < nPnt) {
if ( nCrv1 >= nPnt1){
nCrv1 = nPnt1 - 1;
if ( nCrv1 >= nPnt1) {
nCrv1 = nPnt1 - 1 ;
bLast1 = true ;
}
if ( nCrv2 >= nPnt2) {
nCrv2 = nPnt2 - 1;
nCrv2 = nPnt2 - 1 ;
bLast2 = true ;
}
bool bRep1 = vbRep1[nCrv1] ;
@@ -2002,4 +2014,4 @@ MatchPolyLinesAddingPoints( const PolyLine& PL1, const PolyLine& PL2, int nType,
}
return true ;
}
}