From fb9f94c76edb6db0324b75affbb438443e76ac5b Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Sat, 19 Sep 2020 10:35:31 +0000 Subject: [PATCH] =?UTF-8?q?EgtGeomKernel=20:=20-=20aggiunta=20gestione=20l?= =?UTF-8?q?ivello=20di=20debug=20tramite=20Set/GetEGkDebugLev=20-=20introd?= =?UTF-8?q?uzione=20della=20costante=20SQ=5FINFINITO=20=3D=20INFINITO=20*?= =?UTF-8?q?=20INFINITO=20-=20corretta=20triangolazione=20per=20oggetti=20m?= =?UTF-8?q?olto=20grandi=20(si=20usava=20INFINITO=20invece=20di=20SQ=5FINF?= =?UTF-8?q?INITO)=20-=20corretta=20scalatura=20di=20curve=20composite=20(q?= =?UTF-8?q?uando=20si=20espande=20si=20aggiusta=20la=20continuit=C3=A0=20t?= =?UTF-8?q?ra=20le=20curve=20componenti).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ArcCenTgCurvePnt.cpp | 2 +- ArcPntDirTgCurve.cpp | 2 +- ChainCurves.cpp | 2 +- CircleCenTgCurve.cpp | 4 ++-- CurveBezier.cpp | 13 ++++++++----- CurveByApprox.cpp | 5 +++-- CurveComposite.cpp | 26 ++++++++++++++++++++++++++ DistPointCrvAux.cpp | 2 +- DllMain.h | 5 +++-- EGkDllMain.cpp | 17 +++++++++++++++++ IntersCurveCurve.cpp | 2 +- LinePntMinDistCurve.cpp | 2 +- LinePntPerpCurve.cpp | 2 +- LinePntTgCurve.cpp | 4 ++-- PolyLine.cpp | 6 +++--- SelfIntersCurve.cpp | 2 +- SurfTriMeshFaceting.cpp | 4 ++-- Triangulate.cpp | 6 +++--- 18 files changed, 77 insertions(+), 29 deletions(-) diff --git a/ArcCenTgCurvePnt.cpp b/ArcCenTgCurvePnt.cpp index 7083783..52b48d4 100644 --- a/ArcCenTgCurvePnt.cpp +++ b/ArcCenTgCurvePnt.cpp @@ -153,7 +153,7 @@ CurveArc* GetArcCenTgCompoPnt( const Point3d& ptCen, const CurveComposite& crvCo const Point3d& ptNearEnd, const Vector3d& vtN, Point3d* pPtTg) { // ciclo sulla curva composita - double dMinSqDist = INFINITO * INFINITO ; + double dMinSqDist = SQ_INFINITO ; PtrOwner pCrvArc ; for ( const ICurve* pCrv = crvCompo.GetFirstCurve() ; pCrv != nullptr ; diff --git a/ArcPntDirTgCurve.cpp b/ArcPntDirTgCurve.cpp index a0cbddc..9c39cca 100644 --- a/ArcPntDirTgCurve.cpp +++ b/ArcPntDirTgCurve.cpp @@ -323,7 +323,7 @@ GetArcPntDirTgCompo( const Point3d& ptP, const Vector3d& vtDir, const CurveCompo const Point3d& ptNear, const Vector3d& vtN, Point3d* pPtTg) { // ciclo sulla curva composita - double dMinSqDist = INFINITO * INFINITO ; + double dMinSqDist = SQ_INFINITO ; PtrOwner pCrvNew ; for ( const ICurve* pCrv = crvCompo.GetFirstCurve() ; pCrv != nullptr ; diff --git a/ChainCurves.cpp b/ChainCurves.cpp index 18c8f66..55fad0f 100644 --- a/ChainCurves.cpp +++ b/ChainCurves.cpp @@ -274,7 +274,7 @@ ChainCurves::ChooseStart( const Point3d& ptStart, const INTVECTOR& vStart, int& // altrimenti, cerco la migliore int nI = - 1 ; - double dSqDistMin = INFINITO * INFINITO ; + double dSqDistMin = SQ_INFINITO ; for ( int i = 0 ; i < nSize ; ++ i) { // recupero indice e verso int nId = abs( vStart[i]) - 1 ; diff --git a/CircleCenTgCurve.cpp b/CircleCenTgCurve.cpp index 3dddf54..af30d69 100644 --- a/CircleCenTgCurve.cpp +++ b/CircleCenTgCurve.cpp @@ -158,7 +158,7 @@ GetCircleCenTgArc( const Point3d& ptCen, const Vector3d& vtN, const CurveArc& cr // scelgo la soluzione più vicina al punto di riferimento int nIdOk = 0 ; - double dMinSqDist = INFINITO * INFINITO ; + double dMinSqDist = SQ_INFINITO ; for ( int i = 0 ; i < nSol ; ++ i) { double dSqDist = SqDist( vCenPtg[i].second, ptNear) ; if ( dSqDist < dMinSqDist) { @@ -225,7 +225,7 @@ GetCircleCenTgCompo( const Point3d& ptCen, const Vector3d& vtN, const CurveCompo const Point3d& ptNear, Point3d* pPtTg) { // ciclo sulla curva composita - double dMinSqDist = INFINITO * INFINITO ; + double dMinSqDist = SQ_INFINITO ; PtrOwner pCrvArc ; for ( const ICurve* pCrv = crvCompo.GetFirstCurve() ; pCrv != nullptr ; diff --git a/CurveBezier.cpp b/CurveBezier.cpp index 9101725..e0299ad 100644 --- a/CurveBezier.cpp +++ b/CurveBezier.cpp @@ -863,7 +863,8 @@ CurveBezier::CalcSingularParam( void) const GetPointD1D2( vdRoot[i], ptPos, &vtDer1) ; if ( vtDer1.IsZero()) { m_dParSing = vdRoot[i] ; - LOG_DBG_INFO( GetEGkLogger(), "INFO : Found Singularity in CurveBezier") + if ( GetEGkDebugLev() >= 5) + LOG_DBG_INFO( GetEGkLogger(), "INFO : Found Singularity in CurveBezier") return true ; } } @@ -1027,7 +1028,7 @@ CurveBezier::GetSegmentLength( int nLev, double dU0, double dU1, double dU2, const double LEN_RATIO = 1.2 ; // verifica superamento del massimo livello di recursione per debug - if ( nLev >= MAX_LEV) + if ( nLev >= MAX_LEV && GetEGkDebugLev() >= 5) LOG_DBG_ERR( GetEGkLogger(), "ERROR : Exceeded recursions") // calcolo delle distanze @@ -1319,7 +1320,8 @@ CurveBezier::FlatOrSplit( int nLev, const CurveBezier& crvBez, double dParStart, const int MAX_LEV = 10 ; if ( nLev >= MAX_LEV) { // segnalo situazione per debug - LOG_DBG_ERR( GetEGkLogger(), "ERROR : Exceeded recursions") + if ( GetEGkDebugLev() >= 5) + LOG_DBG_ERR( GetEGkLogger(), "ERROR : Exceeded recursions") // considero la curva piatta (inserisco il punto se abbastanza lontano dal precedente) ed esco Point3d ptLast ; PL.GetLastPoint( ptLast) ; @@ -1484,7 +1486,8 @@ CurveBezier::BiArcOrSplit( int nLev, PolyLine& PL, double dLinTol, double dAngTo if ( nLev >= MAX_LEV) { dMaxDist = 0 ; // segnalo situazione per debug - LOG_DBG_ERR( GetEGkLogger(), "ERROR : Exceeded recursions") + if ( GetEGkDebugLev() >= 5) + LOG_DBG_ERR( GetEGkLogger(), "ERROR : Exceeded recursions") } // se lunghezza abbastanza picccola, forzo l'accettazione della curva @@ -1514,7 +1517,7 @@ CurveBezier::BiArcOrSplit( int nLev, PolyLine& PL, double dLinTol, double dAngTo // se raggiunto il massimo livello di recursione, errore if ( nLev >= MAX_LEV) { // segnalo situazione per debug - LOG_DBG_ERR( GetEGkLogger(), "ERROR : Exceeded recursions") + LOG_ERROR( GetEGkLogger(), "ERROR : Exceeded recursions") return false ; } diff --git a/CurveByApprox.cpp b/CurveByApprox.cpp index 4ad1b57..3b595a6 100644 --- a/CurveByApprox.cpp +++ b/CurveByApprox.cpp @@ -468,7 +468,8 @@ CurveByApprox::BiArcOrSplit( int nLev, PolyLine& PL, double dLinTol, double dAng if ( nLev >= MAX_LEV) { dMaxDist = 0 ; // segnalo situazione per debug - LOG_DBG_ERR( GetEGkLogger(), "ERROR : Exceeded recursions") + if ( GetEGkDebugLev() >= 5) + LOG_DBG_ERR( GetEGkLogger(), "ERROR : Exceeded recursions") } // se lunghezza abbastanza picccola, forzo l'accettazione della curva @@ -498,7 +499,7 @@ CurveByApprox::BiArcOrSplit( int nLev, PolyLine& PL, double dLinTol, double dAng // se raggiunto il massimo livello di recursione, errore if ( nLev >= MAX_LEV) { // segnalo situazione per debug - LOG_DBG_ERR( GetEGkLogger(), "ERROR : Exceeded recursions") + LOG_ERROR( GetEGkLogger(), "ERROR : Exceeded recursions") return false ; } diff --git a/CurveComposite.cpp b/CurveComposite.cpp index 90bdf03..d276692 100644 --- a/CurveComposite.cpp +++ b/CurveComposite.cpp @@ -2185,6 +2185,9 @@ CurveComposite::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, dou if ( abs( dCoeffX) < EPS_ZERO && abs( dCoeffY) < EPS_ZERO && abs( dCoeffZ) < EPS_ZERO) return false ; + // verifico se chiusa + bool bClosed = IsClosed() ; + // calcolo bbox allineato con riferimento di scalatura e senza tener conto dello spessore // lo scalo per verificare se tutto si riduce a un punto BBox3d b3Ref ; @@ -2223,6 +2226,29 @@ CurveComposite::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, dou } } + // se ingrandimento, aggiusto coincidenza estremi delle singole curve + if ( abs( dCoeffX) > 1 || abs( dCoeffY) > 1 || abs( dCoeffZ) > 1) { + int nCount = int( m_CrvSmplS.size()) ; + for ( int i = 0 ; i < nCount ; ++ i) { + int j = i - 1 ; + if ( j < 0) { + if ( bClosed) + j = nCount - 1 ; + else + continue ; + } + ICurve* pCrvPrev = m_CrvSmplS[j] ; + ICurve* pCrvCurr = m_CrvSmplS[i] ; + Point3d ptEndPrev ; pCrvPrev->GetEndPoint( ptEndPrev) ; + Point3d ptStaCurr ; pCrvCurr->GetStartPoint( ptStaCurr) ; + if ( ! AreSamePointApprox( ptEndPrev, ptStaCurr)) { + Point3d ptNew = Media( ptEndPrev, ptStaCurr) ; + pCrvPrev->ModifyEnd( ptNew) ; + pCrvCurr->ModifyStart( ptNew) ; + } + } + } + // scalo vettore estrusione, lo normalizzo e aggiusto spessore m_VtExtr.Scale( frRef, dCoeffX, dCoeffY, dCoeffZ) ; double dLen = m_VtExtr.Len() ; diff --git a/DistPointCrvAux.cpp b/DistPointCrvAux.cpp index 95324fd..a6ca717 100644 --- a/DistPointCrvAux.cpp +++ b/DistPointCrvAux.cpp @@ -146,7 +146,7 @@ PolishMinDistPointCurve( const Point3d& ptP, const ICurve& cCurve, } while ( nCount < MAX_COUNT && abs( dPar - dPrevPar) > EPS_PARAM && abs( dSqCosA) > COS_ORTO_ANG_ZERO * COS_ORTO_ANG_ZERO) ; - if ( nCount == MAX_COUNT) + if ( nCount == MAX_COUNT && GetEGkDebugLev() >= 5) LOG_DBG_ERR( GetEGkLogger(), "ERROR : Exceeded recursions") ; return true ; diff --git a/DllMain.h b/DllMain.h index 356e64b..d7ecbb1 100644 --- a/DllMain.h +++ b/DllMain.h @@ -1,7 +1,7 @@ //---------------------------------------------------------------------------- -// EgalTech 2013-2013 +// EgalTech 2013-2020 //---------------------------------------------------------------------------- -// File : DllMain.h Data : 18.12.13 Versione : 1.4l2 +// File : DllMain.h Data : 19.09.20 Versione : 2.2i2 // Contenuto : Prototipi funzioni per uso locale della DLL. // // @@ -17,6 +17,7 @@ #include //----------------------------------------------------------------------------- +int GetEGkDebugLev( void) ; ILogger* GetEGkLogger( void) ; const std::string& GetEGkKey( void) ; int ProcessEvents( int nProg, int nPause) ; diff --git a/EGkDllMain.cpp b/EGkDllMain.cpp index 9af4caf..9589754 100644 --- a/EGkDllMain.cpp +++ b/EGkDllMain.cpp @@ -78,6 +78,23 @@ GetEGkVersion( void) return s_szEGkNameVer ; } +//----------------------------------------------------------------------------- +static int s_nDebugLev = 0 ; + +//----------------------------------------------------------------------------- +void +SetEGkDebugLev( int nDebugLev) +{ + s_nDebugLev = nDebugLev ; +} + +//----------------------------------------------------------------------------- +int +GetEGkDebugLev( void) +{ + return s_nDebugLev ; +} + //----------------------------------------------------------------------------- static ILogger* s_pLogger = nullptr ; diff --git a/IntersCurveCurve.cpp b/IntersCurveCurve.cpp index 57df98d..794fb97 100644 --- a/IntersCurveCurve.cpp +++ b/IntersCurveCurve.cpp @@ -341,7 +341,7 @@ IntersCurveCurve::GetIntersPointNearTo( int nCrv, const Point3d& ptNear, Point3d // ricerca del punto più vicino tra le intersezioni singole bool bFound = false ; - double dMinSqDist = INFINITO * INFINITO ; + double dMinSqDist = SQ_INFINITO ; for ( int i = 0 ; i < m_nIntersCount ; ++ i) { // se è un'intersezione singola if ( ! m_Info[i].bOverlap) { diff --git a/LinePntMinDistCurve.cpp b/LinePntMinDistCurve.cpp index 8d3f2e6..6fbf3f4 100644 --- a/LinePntMinDistCurve.cpp +++ b/LinePntMinDistCurve.cpp @@ -28,7 +28,7 @@ GetLinePointMinDistCurve( const Point3d& ptP, const ICurve& cCrv, const Point3d& DistPointCurve dstPtCurve( ptP, cCrv) ; // ciclo su questi punti per trovare il più vicino al desiderato bool bFound = false ; - double dMinSqDist = INFINITO * INFINITO ; + double dMinSqDist = SQ_INFINITO ; Point3d ptFoot ; MinDistPCInfo mdInfo ; for ( int i = 0 ; dstPtCurve.GetMinDistInfo( i, mdInfo) ; ++ i) { diff --git a/LinePntPerpCurve.cpp b/LinePntPerpCurve.cpp index 84b9df3..c4c9493 100644 --- a/LinePntPerpCurve.cpp +++ b/LinePntPerpCurve.cpp @@ -149,7 +149,7 @@ CurveLine* GetLinePointPerpCompo( const Point3d& ptP, const CurveComposite& crvCompo, const Point3d& ptNear) { // ciclo sulla curva composita - double dMinSqDist = INFINITO * INFINITO ; + double dMinSqDist = SQ_INFINITO ; PtrOwner pCrvLine ; for ( const ICurve* pCrv = crvCompo.GetFirstCurve() ; pCrv != nullptr ; diff --git a/LinePntTgCurve.cpp b/LinePntTgCurve.cpp index ae5af07..ae3affe 100644 --- a/LinePntTgCurve.cpp +++ b/LinePntTgCurve.cpp @@ -131,7 +131,7 @@ GetLinePointTgArc( const Point3d& ptP, const CurveArc& crvArc, const Point3d& pt // scelgo la soluzione più vicina al punto di riferimento int nIdOk = 0 ; - double dMinSqDist = INFINITO * INFINITO ; + double dMinSqDist = SQ_INFINITO ; for ( int i = 0 ; i < nSol ; ++ i) { double dSqDist = SqDist( vBiPnt[i].second, ptNear) ; if ( dSqDist < dMinSqDist) { @@ -182,7 +182,7 @@ CurveLine* GetLinePointTgCompo( const Point3d& ptP, const CurveComposite& crvCompo, const Point3d& ptNear) { // ciclo sulla curva composita - double dMinSqDist = INFINITO * INFINITO ; + double dMinSqDist = SQ_INFINITO ; PtrOwner pCrvLine ; for ( const ICurve* pCrv = crvCompo.GetFirstCurve() ; pCrv != nullptr ; diff --git a/PolyLine.cpp b/PolyLine.cpp index 508764a..88c31ca 100644 --- a/PolyLine.cpp +++ b/PolyLine.cpp @@ -862,7 +862,7 @@ PolyLine::MyApproxOnSide( const Vector3d& vtN, bool bLeftSide, double dToler) // --- si verifica se possibile eliminare il punto corrente rimanendo dal lato voluto e in tolleranza --- // distanza del punto corrente dal segmento che unisce gli adiacenti DistPointLine dPL( currP->first, precP->first, nextP->first) ; - double dSqDist = INFINITO * INFINITO ; + double dSqDist = SQ_INFINITO ; dPL.GetSqDist( dSqDist) ; // se punti allineati if ( dSqDist < SQ_EPS_SMALL) { @@ -916,7 +916,7 @@ PolyLine::MyApproxOnSide( const Vector3d& vtN, bool bLeftSide, double dToler) ptInt.ToGlob( frNorm) ; // verifico che distanza dell'intersezione dal segmento currP-nextP sia inferiore a tolleranza corrente DistPointLine dIL( ptInt, currP->first, nextP->first) ; - double dSqDist2 = INFINITO * INFINITO ; + double dSqDist2 = SQ_INFINITO ; dIL.GetSqDist( dSqDist2) ; // se eliminabile if ( dSqDist2 < dCurrToler * dCurrToler) { @@ -1139,7 +1139,7 @@ PolyLine::GetMinAreaRectangleXY( Point3d& ptCen, Vector3d& vtAx, double& dLen, d // Starting edge nCount-1 -> 0 int l = 0, m = 0, n = 0 ; - double dMinArea = INFINITO * INFINITO ; + double dMinArea = SQ_INFINITO ; { // Edge indexes int i = 0 ; diff --git a/SelfIntersCurve.cpp b/SelfIntersCurve.cpp index 399cc39..1074b65 100644 --- a/SelfIntersCurve.cpp +++ b/SelfIntersCurve.cpp @@ -250,7 +250,7 @@ SelfIntersCurve::GetIntersPointNearTo( const Point3d& ptNear, Point3d& ptI) // ricerca del punto più vicino tra le intersezioni singole bool bFound = false ; - double dMinSqDist = INFINITO * INFINITO ; + double dMinSqDist = SQ_INFINITO ; for ( int i = 0 ; i < m_nIntersCount ; ++ i) { // se è un'intersezione singola if ( ! m_Info[i].bOverlap) { diff --git a/SurfTriMeshFaceting.cpp b/SurfTriMeshFaceting.cpp index 139d50b..eb065a6 100644 --- a/SurfTriMeshFaceting.cpp +++ b/SurfTriMeshFaceting.cpp @@ -231,7 +231,7 @@ SurfTriMesh::GetFacetNearestEndPoint( int nF, const Point3d& ptNear, Point3d& pt return false ; // ciclo sui triangoli e sui loro lati di bordo bool bFound = false ; - double dMinSqDist = INFINITO * INFINITO ; + double dMinSqDist = SQ_INFINITO ; for ( int i = 0 ; i < int( vTria.size()) ; ++i) { int nT = vTria[i] ; for ( int j = 0 ; j < 3 ; ++ j) { @@ -264,7 +264,7 @@ SurfTriMesh::GetFacetNearestMidPoint( int nF, const Point3d& ptNear, Point3d& pt return false ; // ciclo sui triangoli e sui loro lati di bordo bool bFound = false ; - double dMinSqDist = INFINITO * INFINITO ; + double dMinSqDist = SQ_INFINITO ; for ( int i = 0 ; i < int( vTria.size()) ; ++i) { int nT = vTria[i] ; for ( int j = 0 ; j < 3 ; ++ j) { diff --git a/Triangulate.cpp b/Triangulate.cpp index 37a8bea..9fe61b8 100644 --- a/Triangulate.cpp +++ b/Triangulate.cpp @@ -346,7 +346,7 @@ Triangulate::MakeByEC2( const PNTVECTOR& vPt, const INTVECTOR& vPol, INTVECTOR& double dSqDist = SqDist(vPt[vPol[vPrev[i]]], vPt[vPol[vNext[i]]]) ; // Try with 3 next int j = i ; - double dSqDist1 = INFINITO ; + double dSqDist1 = SQ_INFINITO ; for ( int h = 0 ; h < 3 ; ++ h) { j = vNext[j] ; if ( vEar[j] == EAS_NULL) @@ -358,7 +358,7 @@ Triangulate::MakeByEC2( const PNTVECTOR& vPt, const INTVECTOR& vPol, INTVECTOR& } // Try with 3 prev int k = i ; - double dSqDist2 = INFINITO ; + double dSqDist2 = SQ_INFINITO ; for ( int h = 0 ; h < 3 ; ++ h) { k = vPrev[k] ; if ( vEar[k] == EAS_NULL) @@ -916,7 +916,7 @@ Triangulate::GetOuterPntToJoin( const PNTVECTOR& vPt, const Point3d& ptP, int& n if ( bSwap) swap( ptPb, ptPc) ; double dMinTan = INFINITO ; - double dMinSqDist = INFINITO * INFINITO ; + double dMinSqDist = SQ_INFINITO ; for ( int i = 0 ; i < nNumPt ; ++ i) { // salto il punto già trovato if ( i == nJ)