EgtGeomKernel :

- aggiunta funzione per l'approsimazione di curve con limitazione sulla lunghezza dei singoli tratti.
This commit is contained in:
Daniele Bariletti
2026-07-08 17:26:51 +02:00
parent f0137d26f4
commit 4d3b7ea6cf
11 changed files with 194 additions and 20 deletions
+12 -9
View File
@@ -737,7 +737,7 @@ PolyLine::AdjustForMaxSegmentLen( double dMaxLen)
//-----------------------------------------------------------------------------
static bool
DouglasPeuckerSimplification( const PNTUVECTOR& vPtU, const double dSqTol, const int nIndStart,
const int nIndEnd, INTVECTOR& vInd)
const int nIndEnd, INTVECTOR& vInd, double dMaxLen)
{
// se indici uguali, ritorno
if ( nIndStart == nIndEnd)
@@ -745,7 +745,7 @@ DouglasPeuckerSimplification( const PNTUVECTOR& vPtU, const double dSqTol, const
// distanza massima e indice del punto associato
double dMaxSqDist = 0. ;
int nMaxInd = 0 ;
int nMaxInd = nIndStart + 1 ;
// scorro i punti intermedi tra nIndStart e nIndEnd
for ( int i = nIndStart + 1 ; i < nIndEnd ; ++ i) {
@@ -761,12 +761,15 @@ DouglasPeuckerSimplification( const PNTUVECTOR& vPtU, const double dSqTol, const
// se la distanza massima trovata è sopra la tolleranza, allora controllo la parte di PolyLine tra
// (nIndStart, nMaxInd) e quella tra (nMaxInd, nIndEnd)
if ( dMaxSqDist > dSqTol) {
bool bSplit = dMaxSqDist > dSqTol ;
if ( dMaxLen < INFINITO)
bSplit = bSplit || ( nIndEnd - nIndStart > 1 && Dist( vPtU[nIndStart].first, vPtU[nIndEnd].first) > dMaxLen) ;
if ( bSplit) {
// inserisco il punto
vInd.push_back( nMaxInd) ;
// split
if ( ! DouglasPeuckerSimplification( vPtU, dSqTol, nIndStart, nMaxInd, vInd) ||
! DouglasPeuckerSimplification( vPtU, dSqTol, nMaxInd, nIndEnd, vInd))
if ( ! DouglasPeuckerSimplification( vPtU, dSqTol, nIndStart, nMaxInd, vInd, dMaxLen) ||
! DouglasPeuckerSimplification( vPtU, dSqTol, nMaxInd, nIndEnd, vInd, dMaxLen))
return false ;
}
@@ -775,7 +778,7 @@ DouglasPeuckerSimplification( const PNTUVECTOR& vPtU, const double dSqTol, const
//----------------------------------------------------------------------------
bool
PolyLine::RemoveAlignedPoints( double dToler, bool bStartEnd)
PolyLine::RemoveAlignedPoints( double dToler, bool bStartEnd, double dMaxLen)
{
// se non ci sono almeno 3 punti, esco subito
if ( m_lUPoints.size() < 3)
@@ -796,7 +799,7 @@ PolyLine::RemoveAlignedPoints( double dToler, bool bStartEnd)
if ( ! IsClosed()) {
// considero tutti i punti della PolyLine
vInd.push_back( 0) ;
if ( ! DouglasPeuckerSimplification( vPtU, dSqTol, 0, int( vPtU.size()) - 1, vInd))
if ( ! DouglasPeuckerSimplification( vPtU, dSqTol, 0, int( vPtU.size()) - 1, vInd, dMaxLen))
return false ;
vInd.push_back( int( vPtU.size()) - 1) ;
}
@@ -814,10 +817,10 @@ PolyLine::RemoveAlignedPoints( double dToler, bool bStartEnd)
}
// recupero due PolyLine di approssimazione
vInd.push_back( 0) ;
if ( ! DouglasPeuckerSimplification( vPtU, dSqTol, 0, nMaxInd, vInd))
if ( ! DouglasPeuckerSimplification( vPtU, dSqTol, 0, nMaxInd, vInd, dMaxLen))
return false ;
vInd.push_back( nMaxInd) ;
if ( ! DouglasPeuckerSimplification( vPtU, dSqTol, nMaxInd, int( vPtU.size()) - 1, vInd))
if ( ! DouglasPeuckerSimplification( vPtU, dSqTol, nMaxInd, int( vPtU.size()) - 1, vInd, dMaxLen))
return false ;
vInd.push_back( int( vPtU.size()) - 1) ;
}