diff --git a/AdjustLoops.cpp b/AdjustLoops.cpp index 73db878..c6f1f96 100644 --- a/AdjustLoops.cpp +++ b/AdjustLoops.cpp @@ -15,7 +15,7 @@ #include "stdafx.h" #include "GeoConst.h" #include "CurveComposite.h" -#include "RemoveCurveSpikes.h" +#include "RemoveCurveDefects.h" #include "AdjustLoops.h" #include "/EgtDev/Include/EGkIntersCurves.h" #include "/EgtDev/Include/EGkIntervals.h" @@ -266,10 +266,10 @@ AdjustLoops( ICurve* pCurve, ICURVEPLIST& CrvLst) // se curva composita CurveComposite* pCrvCo = GetBasicCurveComposite( pCrv) ; if ( pCrvCo != nullptr) { + // elimino eventuali Spikes e Small Z + pCrvCo->RemoveSmallDefects( 2 * LIN_TOL_MIN, ANG_TOL_STD_DEG, true) ; // unisco eventuali tratti allineati pCrvCo->MergeCurves( LIN_TOL_MIN, ANG_TOL_STD_DEG) ; - // elimino eventuali spikes - RemoveCurveSpikes( pCrvCo) ; } } diff --git a/CurveByApprox.cpp b/CurveByApprox.cpp index afb1d2e..cc84baf 100644 --- a/CurveByApprox.cpp +++ b/CurveByApprox.cpp @@ -17,6 +17,7 @@ #include "CalcDerivate.h" #include "BiArcs.h" #include "DistPointLine.h" +#include "RemoveCurveDefects.h" #include "/EgtDev/Include/EGkCurveByApprox.h" #include "/EgtDev/Include/EGkPolyLine.h" #include "/EgtDev/Include/EGkPolyArc.h" @@ -65,6 +66,8 @@ CurveByApprox::GetCurve( int nType, double dLinTol, double dAngTolDeg, double dL PtrOwner pCC( CreateBasicCurveComposite()) ; if ( ! pCC->FromPolyArc( PA)) return nullptr ; + // elimino eventuali Small Z + pCC->RemoveSmallDefects( dLinTol, dAngTolDeg) ; // eventuale fusione di curve compatibili pCC->MergeCurves( dLinTol, dAngTolDeg) ; // restituisco la curva diff --git a/CurveComposite.cpp b/CurveComposite.cpp index dbb3e3b..bdfda4c 100644 --- a/CurveComposite.cpp +++ b/CurveComposite.cpp @@ -21,6 +21,7 @@ #include "CurveBezier.h" #include "PolygonPlane.h" #include "SurfFlatRegion.h" +#include "RemoveCurveDefects.h" #include "GeoConst.h" #include "GeoObjFactory.h" #include "NgeWriter.h" @@ -3075,6 +3076,13 @@ CurveComposite::MergeCurves( double dLinTol, double dAngTolDeg, bool bStartEnd, return true ; } +//---------------------------------------------------------------------------- +bool +CurveComposite::RemoveSmallDefects( double dLinTol, double dAngTolDeg, bool bAlsoSpikes) +{ + return (( ! bAlsoSpikes || RemoveCurveSpikes( this, dLinTol)) && RemoveCurveSmallZs(this, dLinTol)) ; +} + //---------------------------------------------------------------------------- static bool SplitTopBottomArcs( CurveComposite& cCompo) diff --git a/CurveComposite.h b/CurveComposite.h index e641285..80ea1d6 100644 --- a/CurveComposite.h +++ b/CurveComposite.h @@ -157,6 +157,7 @@ class CurveComposite : public ICurveComposite, public IGeoObjRW bool ArcsToBezierCurves( void) override ; bool ArcsBezierCurvesToArcsPerpExtr( double dLinTol, double dAngTolDeg) override ; bool MergeCurves( double dLinTol, double dAngTolDeg, bool bStartEnd = true, bool bNeedSameProp = false) override ; + bool RemoveSmallDefects( double dLinTol, double dAngTolDeg, bool bAlsoSpikes = false) override ; bool RemoveUndercutOnY( double dLinTol, double dAngTolDeg) override ; bool IsAPoint( void) const override ; bool IsALine( double dLinTol, Point3d& ptStart, Point3d& ptEnd) const override ; diff --git a/DistPointCrvComposite.cpp b/DistPointCrvComposite.cpp index 5ca251a..45f57fb 100644 --- a/DistPointCrvComposite.cpp +++ b/DistPointCrvComposite.cpp @@ -89,8 +89,18 @@ DistPointCrvComposite::DistPointCrvComposite( const Point3d& ptP, const ICurveCo } } // altrimenti aggiungo - else - m_Info.push_back( aInfo) ; + else { + if ( dCurrDist < m_dDist) { + // aggiorno i minimi + m_dDist = dCurrDist ; + // inserisco in testa + m_Info.insert( m_Info.begin(), aInfo) ; + } + else { + // inserisco in coda + m_Info.push_back( aInfo) ; + } + } // passo al successivo ++ i ; } diff --git a/EgtGeomKernel.rc b/EgtGeomKernel.rc index 3cc30ae..0a0d3d7 100644 Binary files a/EgtGeomKernel.rc and b/EgtGeomKernel.rc differ diff --git a/EgtGeomKernel.vcxproj b/EgtGeomKernel.vcxproj index 4d3fd25..2d75b21 100644 --- a/EgtGeomKernel.vcxproj +++ b/EgtGeomKernel.vcxproj @@ -391,7 +391,7 @@ copy $(TargetPath) \EgtProg\Dll64 - + @@ -609,7 +609,7 @@ copy $(TargetPath) \EgtProg\Dll64 - + diff --git a/EgtGeomKernel.vcxproj.filters b/EgtGeomKernel.vcxproj.filters index 44fad35..f6a5e4c 100644 --- a/EgtGeomKernel.vcxproj.filters +++ b/EgtGeomKernel.vcxproj.filters @@ -327,7 +327,7 @@ File di origine\GeoOffset - + File di origine\GeoInters @@ -857,7 +857,7 @@ File di intestazione\Include - + File di intestazione diff --git a/OffsetCurve.cpp b/OffsetCurve.cpp index 3ac0419..d1e9dfc 100644 --- a/OffsetCurve.cpp +++ b/OffsetCurve.cpp @@ -17,6 +17,7 @@ #include "CurveComposite.h" #include "CurveLine.h" #include "CurveArc.h" +#include "RemoveCurveDefects.h" #include "GeoConst.h" #include "/EgtDev/Include/EGkOffsetCurve.h" #include "/EgtDev/Include/EGkIntersCurves.h" @@ -159,6 +160,9 @@ OffsetCurve::Make( const ICurve* pCrv, double dDist, int nType) // verifico se curva chiusa e non forzata aperta bool bClosed = ccCopy.IsClosed() && ( nType & ICurve::OFF_FORCE_OPEN) == 0 ; + // elimino eventuali piccole Z + RemoveCurveSmallZs( &ccCopy, 10 * EPS_SMALL) ; + // unisco parti allineate (tranne gli estremi) ccCopy.MergeCurves( 10 * EPS_SMALL, ANG_TOL_STD_DEG, false) ; diff --git a/RemoveCurveDefects.cpp b/RemoveCurveDefects.cpp new file mode 100644 index 0000000..c4c7d04 --- /dev/null +++ b/RemoveCurveDefects.cpp @@ -0,0 +1,128 @@ +//---------------------------------------------------------------------------- +// EgalTech 2017-2022 +//---------------------------------------------------------------------------- +// File : RemoveCurveDefects.cpp Data : 13.11.22 Versione : 2.4k2 +// Contenuto : Implementazione rimozione spikes di curva. +// +// +// +// Modifiche : 02.10.17 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "GeoConst.h" +#include "CurveComposite.h" +#include "DistPointLine.h" +#include "RemoveCurveDefects.h" +#include "/EgtDev/Include/EGkDistPointCurve.h" +#include + +using namespace std ; + +//---------------------------------------------------------------------------- +bool +RemoveCurveSpikes( ICurveComposite* pCurve, double dLinTol) +{ + // verifico validità curva + if ( pCurve == nullptr) + return false ; + // verifico e sistemo tolleranza lineare + dLinTol = max( dLinTol, EPS_SMALL) ; + // recupero il numero di curve semplici componenti la composta + int nCrvCount = pCurve->GetCurveCount() ; + if ( nCrvCount < 2 || ( nCrvCount < 3 && pCurve->IsClosed())) + return true ; + // ciclo sulle curve elementari della composita + int nStart = pCurve->IsClosed() ? 0 : 1 ; + for ( int i = nStart ; i < nCrvCount ; ++ i) { + // recupero due curve consecutive + const ICurve* pPrevCrv = pCurve->GetCurve( ( i > 0 ? i - 1 : nCrvCount - 1)) ; + const ICurve* pNextCrv = pCurve->GetCurve( i) ; + // se sono entrambe rette + if ( pPrevCrv->GetType() == CRV_LINE && pNextCrv->GetType() == CRV_LINE) { + // recupero i punti estremi + Point3d ptStart ; pPrevCrv->GetStartPoint( ptStart) ; + Point3d ptMid ; pPrevCrv->GetEndPoint( ptMid) ; + Point3d ptEnd ; pNextCrv->GetEndPoint( ptEnd) ; + // recupero le direzioni negli estremi + Vector3d vtPrev ; pPrevCrv->GetStartDir( vtPrev) ; + Vector3d vtNext ; pNextCrv->GetStartDir( vtNext) ; + // verifico se spike + double dPrevDist, dNextDist ; + if ( vtPrev * vtNext < cos( 175 * DEGTORAD) && + (( DistPointLine( ptStart, ptMid, ptEnd).GetDist( dPrevDist) && dPrevDist < dLinTol) || + ( DistPointLine( ptEnd, ptStart, ptMid).GetDist( dNextDist) && dNextDist < dLinTol))) { + // se spike ha base abbastanza larga, basta togliere uno dei due lati + if ( SqDist( ptStart, ptEnd) > SQ_EPS_SMALL) { + pCurve->RemoveJoint( i) ; + -- nCrvCount ; + -- i ; + } + // altrimenti bisogna togliere entrambi + else { + pCurve->RemoveJoint( i - 1) ; + pCurve->RemoveJoint( i) ; + nCrvCount -= 2 ; + i = max( i - 2, nStart - 1) ; + } + } + } + // !!! Aggiungere la gestione degli altri tipi di curve !!! + } + + return true ; +} + +//---------------------------------------------------------------------------- +bool +RemoveCurveSmallZs( ICurveComposite* pCurve, double dLinTol) +{ + // verifico validità curva + if ( pCurve == nullptr) + return false ; + // verifico e sistemo tolleranza lineare + dLinTol = max( dLinTol, EPS_SMALL) ; + // recupero il numero di curve semplici componenti la composta + int nCrvCount = pCurve->GetCurveCount() ; + if ( nCrvCount < 2 || ( nCrvCount < 3 && pCurve->IsClosed())) + return true ; + // ciclo sulle curve elementari della composita + int nStart = pCurve->IsClosed() ? 0 : 1 ; + int nEnd = pCurve->IsClosed() ? nCrvCount : nCrvCount - 1 ; + for ( int i = nStart ; i < nEnd ; ++ i) { + // recupero tre curve consecutive + const ICurve* pPrevCrv = pCurve->GetCurve( ( i > 0 ? i - 1 : nCrvCount - 1)) ; + const ICurve* pCurrCrv = pCurve->GetCurve( i) ; + const ICurve* pNextCrv = pCurve->GetCurve( ( i < nCrvCount - 1 ? i + 1 : 0)) ; + // se la curva corrente è una retta + if ( pCurrCrv->GetType() == CRV_LINE) { + // recupero tre punti notevoli della curva + Point3d ptStart ; pCurrCrv->GetStartPoint( ptStart) ; + Point3d ptMid ; pCurrCrv->GetMidPoint( ptMid) ; + Point3d ptEnd ; pCurrCrv->GetEndPoint( ptEnd) ; + // recupero le direzioni negli estremi + Vector3d vtPrev ; pPrevCrv->GetEndDir( vtPrev) ; + Vector3d vtNext ; pNextCrv->GetStartDir( vtNext) ; + // verifico se Small Z + double dDistS, dDistM1, dDistM2, dDistE ; + if ( vtPrev * vtNext > cos( 30 * DEGTORAD) && + (( DistPointCurve( ptStart, *pNextCrv).GetDist( dDistS) && dDistS < dLinTol) && + ( DistPointCurve( ptMid, *pNextCrv).GetDist( dDistM1) && dDistM1 < dLinTol) && + ( DistPointCurve( ptMid, *pPrevCrv).GetDist( dDistM2) && dDistM2 < dLinTol) && + ( DistPointCurve( ptEnd, *pPrevCrv).GetDist( dDistE) && dDistE < dLinTol))) { + // rimuovo il segmento + pCurve->RemoveJoint( i) ; + -- nCrvCount ; + -- nEnd ; + -- i ; + // porto il nuovo estremo sul punto medio + pCurve->ModifyJoint( i + 1, ptMid) ; + } + } + } + + return true ; +} diff --git a/RemoveCurveSpikes.h b/RemoveCurveDefects.h similarity index 57% rename from RemoveCurveSpikes.h rename to RemoveCurveDefects.h index e301a6b..ef044b9 100644 --- a/RemoveCurveSpikes.h +++ b/RemoveCurveDefects.h @@ -1,20 +1,21 @@ -//---------------------------------------------------------------------------- -// EgalTech 2017-2017 -//---------------------------------------------------------------------------- -// File : RemoveCurveSpikes.h Data : 02.10.17 Versione : 1.8j1 -// Contenuto : Dichiarazione funzione rimozione spikes curve. -// -// -// -// Modifiche : 02.10.17 DS Creazione modulo. -// -// -//---------------------------------------------------------------------------- - -#pragma once - -#include "/EgtDev/Include/EGkCurveComposite.h" - - -//---------------------------------------------------------------------------- -bool RemoveCurveSpikes( ICurveComposite* pCurve) ; +//---------------------------------------------------------------------------- +// EgalTech 2017-2022 +//---------------------------------------------------------------------------- +// File : RemoveCurveDefects.h Data : 13.11.22 Versione : 2.4k2 +// Contenuto : Dichiarazione funzioni rimozione difetti curve. +// +// +// +// Modifiche : 02.10.17 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/EGkCurveComposite.h" + + +//---------------------------------------------------------------------------- +bool RemoveCurveSpikes( ICurveComposite* pCurve, double dLinTol = EPS_SMALL) ; +bool RemoveCurveSmallZs( ICurveComposite* pCurve, double dLinTol = EPS_SMALL) ; diff --git a/RemoveCurveSpikes.cpp b/RemoveCurveSpikes.cpp deleted file mode 100644 index 278fd03..0000000 --- a/RemoveCurveSpikes.cpp +++ /dev/null @@ -1,74 +0,0 @@ -//---------------------------------------------------------------------------- -// EgalTech 2017-2017 -//---------------------------------------------------------------------------- -// File : RemoveCurveSpikes.cpp Data : 02.10.17 Versione : 1.8j1 -// Contenuto : Implementazione rimozione spikes di curva. -// -// -// -// Modifiche : 02.10.17 DS Creazione modulo. -// -// -//---------------------------------------------------------------------------- - -//--------------------------- Include ---------------------------------------- -#include "stdafx.h" -#include "GeoConst.h" -#include "CurveComposite.h" -#include "DistPointLine.h" -#include "RemoveCurveSpikes.h" -#include - -using namespace std ; - -//---------------------------------------------------------------------------- -bool -RemoveCurveSpikes( ICurveComposite* pCurve) -{ - // verifico validità curva - if ( pCurve == nullptr) - return false ; - // recupero il numero di curve semplici componenti la composta - int nCrvCount = pCurve->GetCurveCount() ; - if ( nCrvCount < 2 || ( nCrvCount < 3 && pCurve->IsClosed())) - return true ; - // ciclo sulle curve elementari della composita - int nStart = pCurve->IsClosed() ? 0 : 1 ; - for ( int i = nStart ; i < nCrvCount ; ++ i) { - // recupero due curve consecutive - const ICurve* pPrevCrv = pCurve->GetCurve( ( i > 0 ? i - 1 : nCrvCount - 1)) ; - const ICurve* pNextCrv = pCurve->GetCurve( i) ; - // se sono entrambe rette - if ( pPrevCrv->GetType() == CRV_LINE && pNextCrv->GetType() == CRV_LINE) { - // recupero i punti estremi - Point3d ptStart ; pPrevCrv->GetStartPoint( ptStart) ; - Point3d ptMid ; pPrevCrv->GetEndPoint( ptMid) ; - Point3d ptEnd ; pNextCrv->GetEndPoint( ptEnd) ; - // recupero le direzioni negli estremi - Vector3d vtPrev ; pPrevCrv->GetStartDir( vtPrev) ; - Vector3d vtNext ; pNextCrv->GetStartDir( vtNext) ; - // verifico se spike - double dPrevDist, dNextDist ; - if ( vtPrev * vtNext < cos( 175 * DEGTORAD) && - (( DistPointLine( ptStart, ptMid, ptEnd).GetDist( dPrevDist) && dPrevDist < EPS_SMALL) || - ( DistPointLine( ptEnd, ptStart, ptMid).GetDist( dNextDist) && dNextDist < EPS_SMALL))) { - // se spike ha base abbastanza larga, basta togliere uno dei due lati - if ( SqDist( ptStart, ptEnd) > SQ_EPS_SMALL) { - pCurve->RemoveJoint( i) ; - -- nCrvCount ; - -- i ; - } - // altrimenti bisogna togliere entrambi - else { - pCurve->RemoveJoint( i - 1) ; - pCurve->RemoveJoint( i) ; - nCrvCount -= 2 ; - i = max( i - 2, nStart - 1) ; - } - } - } - // !!! Aggiungere la gestione degli altri tipi di curve !!! - } - - return true ; -} \ No newline at end of file