From 360484c9af4cfe9fba36452cc47f0cda601fe4a2 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Thu, 29 Feb 2024 08:47:44 +0100 Subject: [PATCH] EgtGeomKernel : - correzioni a RemoveAlignedPoints di Polyline (si usano indici e non il parametro U come ordine dei punti). --- PolyLine.cpp | 68 ++++++++++++++++++++-------------------------------- 1 file changed, 26 insertions(+), 42 deletions(-) diff --git a/PolyLine.cpp b/PolyLine.cpp index b89aae7..83400c9 100644 --- a/PolyLine.cpp +++ b/PolyLine.cpp @@ -721,22 +721,10 @@ PolyLine::AdjustForMaxSegmentLen( double dMaxLen) return true ; } -//---------------------------------------------------------------------------- -static bool -PointsInTolerance( const PNTVECTOR& vRPT, const Point3d& ptP1, const Point3d& ptP2, double dSqTol) -{ - for ( const auto& ptQ : vRPT) { - double dSqDist ; - if ( ! DistPointLine( ptQ, ptP1, ptP2).GetSqDist( dSqDist) || dSqDist > dSqTol) - return false ; - } - return true ; -} - //----------------------------------------------------------------------------- static bool -douglasPeuckerSimplification( const PNTUVECTOR& vPtU, const double dSqTol, const int nIndStart, - const int nIndEnd, PNTUVECTOR& vPtU_simple) +DouglasPeuckerSimplification( const PNTUVECTOR& vPtU, const double dSqTol, const int nIndStart, + const int nIndEnd, INTVECTOR& vInd) { // se indici uguali, ritorno if ( nIndStart == nIndEnd) @@ -762,10 +750,10 @@ douglasPeuckerSimplification( const PNTUVECTOR& vPtU, const double dSqTol, const // (nIndStart, nMaxInd) e quella tra (nMaxInd, nIndEnd) if ( dMaxSqDist > dSqTol) { // inserisco il punto - vPtU_simple.push_back( vPtU[nMaxInd]) ; + vInd.push_back( nMaxInd) ; // split - if ( ! douglasPeuckerSimplification( vPtU, dSqTol, nIndStart, nMaxInd, vPtU_simple) || - ! douglasPeuckerSimplification( vPtU, dSqTol, nMaxInd, nIndEnd, vPtU_simple)) + if ( ! DouglasPeuckerSimplification( vPtU, dSqTol, nIndStart, nMaxInd, vInd) || + ! DouglasPeuckerSimplification( vPtU, dSqTol, nMaxInd, nIndEnd, vInd)) return false ; } @@ -782,27 +770,24 @@ PolyLine::RemoveAlignedPoints( double dToler) // controllo minimo valore di tolleranza dToler = max( dToler, LIN_TOL_MIN) ; double dSqTol = dToler * dToler ; + // vettore contenente i punti della polyline - PNTUVECTOR vPtU ; vPtU.resize( int( m_lUPoints.size())) ; - // interatore primo punto - auto ptAct = m_lUPoints.begin() ; - for ( int i = 0 ; i < int( m_lUPoints.size()) ; ++ i) { - vPtU[i] = *ptAct; - ptAct = next( ptAct) ; // incremento iteratore - } + PNTUVECTOR vPtU ; vPtU.reserve( m_lUPoints.size()) ; + for ( const auto& ptCurr : m_lUPoints) + vPtU.emplace_back( ptCurr) ; - // vettore indice dei punti semplificati - PNTUVECTOR vPtU_simple ; + // vettore indici dei punti rimanenti + INTVECTOR vInd ; vInd.reserve( vPtU.size()) ; - // POLYLINE APERTA + // se aperta if ( ! IsClosed()) { // considero tutti i punti della PolyLine - vPtU_simple.push_back( vPtU.front()) ; - if ( ! douglasPeuckerSimplification( vPtU, dSqTol, 0, int( vPtU.size()) - 1, vPtU_simple)) + vInd.push_back( 0) ; + if ( ! DouglasPeuckerSimplification( vPtU, dSqTol, 0, int( vPtU.size()) - 1, vInd)) return false ; - vPtU_simple.push_back( vPtU.back()) ; + vInd.push_back( vPtU.size() - 1) ; } - // POLYLINE CHIUSA + // altrimenti chiusa else { // cerco il punto pił distante dal primo double dMaxDist = 0. ; @@ -815,23 +800,22 @@ PolyLine::RemoveAlignedPoints( double dToler) } } // recupero due PolyLine di approssimazione - vPtU_simple.push_back( vPtU.front()) ; - if ( ! douglasPeuckerSimplification( vPtU, dSqTol, 0, nMaxInd, vPtU_simple)) + vInd.push_back( 0) ; + if ( ! DouglasPeuckerSimplification( vPtU, dSqTol, 0, nMaxInd, vInd)) return false ; - vPtU_simple.push_back( vPtU[ nMaxInd]) ; - if ( ! douglasPeuckerSimplification( vPtU, dSqTol, nMaxInd, int( vPtU.size()) - 1, vPtU_simple)) + vInd.push_back( nMaxInd) ; + if ( ! DouglasPeuckerSimplification( vPtU, dSqTol, nMaxInd, int( vPtU.size()) - 1, vInd)) return false ; - vPtU_simple.push_back( vPtU.back()) ; + vInd.push_back( vPtU.size() - 1) ; } - // ordino - sort( vPtU_simple.begin(), vPtU_simple.end(), - []( const POINTU& a , const POINTU& b) { return ( a.second < b.second) ; }) ; + // ordino in senso crescente + sort( vInd.begin(), vInd.end()) ; - // pulisco e aggiungo i parametri ricavati + // rimetto in lista i soli punti rimasti m_lUPoints.clear() ; - for ( int i = 0 ; i < int( vPtU_simple.size()) ; ++ i) - m_lUPoints.push_back( vPtU_simple[i]) ; + for ( auto Ind : vInd) + m_lUPoints.push_back( vPtU[Ind]) ; return true ; }