From 4731df3702de38441fd3bf38edb332ca4c1ed9e9 Mon Sep 17 00:00:00 2001 From: DarioS Date: Sun, 26 Sep 2021 16:27:31 +0200 Subject: [PATCH] =?UTF-8?q?EgtGeomKernel=202.3i2=20:=20-=20modificata=20co?= =?UTF-8?q?mpletamente=20SurfTriMesh::GetSilhouette=20ora=20richiede=20un?= =?UTF-8?q?=20parametro=20per=20la=20tolleranza=20nel=20calcolo=20(diminui?= =?UTF-8?q?ta=20sensibilit=C3=A0=20a=20problemi=20topologici)=20-=20aggiun?= =?UTF-8?q?ta=20funzione=20GetSurfFlatRegionFromTriangle.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- EgtGeomKernel.rc | Bin 11710 -> 11710 bytes SfrCreate.cpp | 35 ++++++++++++++++++++++++------ SurfTriMesh.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++- SurfTriMesh.h | 6 +++--- 4 files changed, 85 insertions(+), 11 deletions(-) diff --git a/EgtGeomKernel.rc b/EgtGeomKernel.rc index 50dcb017871d34b0c3871da232f91b6e5f1cf84e..ba184468120877e984f9770c2bfecac322ddaeff 100644 GIT binary patch delta 94 zcmdlNy)SyhFE&P_&A-_cnHh~HD{|{@_Trkr0u;H;XNwSVW8B;$>;>dw2zN+>g;Df- LFmBFL4&ed-Vf-5U delta 94 zcmdlNy)SyhFE&QQ&A-_cnHdcyD{|{@_Trkr0u;H;XNwSVW8B;$>;>dw2zN+>g;Df- LFmBFL4&ed-U|t&X diff --git a/SfrCreate.cpp b/SfrCreate.cpp index 957dc03..d21c5ac 100644 --- a/SfrCreate.cpp +++ b/SfrCreate.cpp @@ -279,13 +279,34 @@ GetSurfFlatRegionFromFatCurve( ICurve* pCrv, double dRadius, bool bSquareEnds, b //---------------------------------------------------------------------------- ISurfFlatRegion* -GetSurfFlatRegionFromPolyLine( const PolyLine& ContourPolyLine) +GetSurfFlatRegionFromTriangle( const Triangle3d& Tria) { // Creo la regione. PtrOwner pSfr( CreateBasicSurfFlatRegion()) ; if ( IsNull( pSfr)) return nullptr ; - // Creo curva composita. + // Creo curva composita. + PtrOwner pLoop( CreateBasicCurveComposite()) ; + if ( IsNull( pLoop)) + return nullptr ; + if ( ! pLoop->AddPoint( Tria.GetP( 0)) || + ! pLoop->AddLine( Tria.GetP( 1)) || + ! pLoop->AddLine( Tria.GetP( 2)) || + ! pLoop->Close()) + return nullptr ; + pSfr->AddExtLoop( Release( pLoop)) ; + return Release( pSfr) ; +} + +//---------------------------------------------------------------------------- +ISurfFlatRegion* +GetSurfFlatRegionFromPolyLine( const PolyLine& ContourPolyLine) +{ + // Creo la regione. + PtrOwner pSfr( CreateBasicSurfFlatRegion()) ; + if ( IsNull( pSfr)) + return nullptr ; + // Creo curva composita. PtrOwner pLoop( CreateBasicCurveComposite()) ; if ( IsNull( pLoop)) return nullptr ; @@ -307,13 +328,13 @@ GetSurfFlatRegionFromPolyLine( const PolyLine& ContourPolyLine) ISurfFlatRegion* GetSurfFlatRegionFromPolyLineVector( const POLYLINEVECTOR& vContoursPolyLineVec) { - // Creo la regione. + // Creo la regione. PtrOwner pSfr( CreateBasicSurfFlatRegion()) ; if ( IsNull( pSfr)) return nullptr ; - // Ciclo sulle PolyLine. + // Ciclo sulle PolyLine. for ( int nL = 0 ; nL < int( vContoursPolyLineVec.size()) ; ++ nL) { - // Creo curva composita. + // Creo curva composita. PtrOwner pLoop( CreateBasicCurveComposite()) ; if ( IsNull( pLoop)) return nullptr ; @@ -327,11 +348,11 @@ GetSurfFlatRegionFromPolyLineVector( const POLYLINEVECTOR& vContoursPolyLineVec) ptSt = ptEn ; bContinue = vContoursPolyLineVec[nL].GetNextPoint( ptEn) ; } - // Loop esterno + // Loop esterno if ( nL == 0) { pSfr->AddExtLoop( Release( pLoop)) ; } - // Loop interno + // Loop interno else { pSfr->AddIntLoop( Release( pLoop)) ; } diff --git a/SurfTriMesh.cpp b/SurfTriMesh.cpp index 0a8b3ff..a96df26 100644 --- a/SurfTriMesh.cpp +++ b/SurfTriMesh.cpp @@ -991,7 +991,7 @@ SurfTriMesh::MarchOneTria( int& nT, int& nV, int nTimeStamp, //---------------------------------------------------------------------------- bool -SurfTriMesh::GetSilhouette( const Vector3d& vtDir, POLYLINEVECTOR& vPL) const +SurfTriMesh::GetSilhouette( const Vector3d& vtDir, double dTol, POLYLINEVECTOR& vPL) const { // Verifico lo stato if ( m_nStatus != OK) @@ -1002,6 +1002,57 @@ SurfTriMesh::GetSilhouette( const Vector3d& vtDir, POLYLINEVECTOR& vPL) const if ( ! vtVers.Normalize()) return false ; + // Controlli su tolleranza + dTol = max( dTol, 100 * EPS_SMALL) ; + + // Determino il riferimento di proiezione + Frame3d frOCS ; frOCS.Set( ORIG, vtVers) ; + Frame3d frBox = frOCS ; frBox.Invert() ; + BBox3d b3Box ; + GetBBox( frBox, b3Box) ; + frOCS.Translate( b3Box.GetMin().z * frOCS.VersZ()) ; + + // calcolo la regione dei triangoli proiettati + PtrOwner pSfr ; + Triangle3d Tria ; + int nT = GetFirstTriangle( Tria) ; + while ( nT != SVT_NULL) { + // verifico la normale e il triangolo proiettato + if ( Tria.GetN() * vtVers > EPS_ZERO && + Tria.Scale( frOCS, 1, 1, 0) && Tria.GetSqMinHeight() > SQ_EPS_SMALL) { + PtrOwner pSfrTria( GetSurfFlatRegionFromTriangle( Tria)) ; + if ( ! IsNull( pSfrTria)) { + pSfrTria->Offset( dTol, ICurve::OFF_FILLET) ; + if ( IsNull( pSfr)) + pSfr.Set( Release( pSfrTria)) ; + else + pSfr->Add( *pSfrTria) ; + } + } + // passo al successivo + nT = GetNextTriangle( nT, Tria) ; + } + + // Se non esiste la regione + if ( IsNull( pSfr)) + return false ; + + // Effettuo contro-offset + pSfr->Offset( -dTol, ICurve::OFF_EXTEND) ; + + // Recupero i contorni della regione + for ( int i = 0 ; i < pSfr->GetChunkCount() ; ++ i) { + for ( int j = 0 ; j < pSfr->GetLoopCount( i) ; ++ j) { + PolyLine PL ; + if ( pSfr->ApproxLoopWithLines( i, j, LIN_TOL_STD, ANG_TOL_STD_DEG, ICurve::APL_STD, PL)) + vPL.emplace_back( PL) ; + } + } + + return true ; + +#if 0 + // Copio la superficie PtrOwner pStm( Clone()) ; if ( IsNull( pStm)) @@ -1021,6 +1072,8 @@ SurfTriMesh::GetSilhouette( const Vector3d& vtDir, POLYLINEVECTOR& vPL) const // Recupero i loop della nuova superficie return pStm->GetLoops( vPL) ; + +#endif } //---------------------------------------------------------------------------- diff --git a/SurfTriMesh.h b/SurfTriMesh.h index bd32138..303e6c7 100644 --- a/SurfTriMesh.h +++ b/SurfTriMesh.h @@ -1,7 +1,7 @@ //---------------------------------------------------------------------------- -// EgalTech 2014-2019 +// EgalTech 2014-2021 //---------------------------------------------------------------------------- -// File : SurfTriMesh.h Data : 12.02.19 Versione : 2.1b2 +// File : SurfTriMesh.h Data : 26.09.21 Versione : 2.3i2 // Contenuto : Dichiarazione della classe Superficie TriMesh. // // @@ -278,7 +278,7 @@ class SurfTriMesh : public ISurfTriMesh, public IGeoObjRW bool GetTriangleBoundaryEdges( int nId, TriFlags3d& TFlags) const override ; bool GetTriangleSmoothNormals( int nId, TriNormals3d& TNrms) const override ; bool GetLoops( POLYLINEVECTOR& vPL) const override ; - bool GetSilhouette( const Vector3d& vtDir, POLYLINEVECTOR& vPL) const override ; + bool GetSilhouette( const Vector3d& vtDir, double dTol, POLYLINEVECTOR& vPL) const override ; int GetFacetCount( void) const override ; int GetFacetSize( void) const override { return int( m_vFacet.size()) ; }