EgtGeomKernel :

- aggiunta HashGrids3d a SurfTm con lazy evaluation
- in CAvTool aggiunta verifica utensile ben definito.
This commit is contained in:
Dario Sassi
2018-12-10 07:50:42 +00:00
parent 9a27864087
commit b3d868bcc9
23 changed files with 349 additions and 297 deletions
+96 -13
View File
@@ -36,7 +36,7 @@ GEOOBJ_REGISTER( SRF_TRIMESH, NGE_S_TRM, SurfTriMesh) ;
SurfTriMesh::SurfTriMesh( void)
: m_nStatus( TO_VERIFY), m_dLinTol( STM_STD_LIN_TOL), m_dBoundaryAng( STM_STD_BOUNDARY_ANG),
m_dSmoothAng( STM_STD_SMOOTH_ANG), m_bOriented( false), m_bClosed( false), m_bFaceted( false),
m_nTimeStamp( 0), m_nTempProp( 0)
m_nTimeStamp( 0), m_nTempProp( 0), m_pHGrd3d( nullptr)
{
m_dCosBndAng = cos( m_dBoundaryAng * DEGTORAD) ;
m_dCosSmAng = cos( m_dSmoothAng * DEGTORAD) ;
@@ -45,14 +45,16 @@ SurfTriMesh::SurfTriMesh( void)
//----------------------------------------------------------------------------
SurfTriMesh::~SurfTriMesh( void)
{
ResetHashGrids3d() ;
}
//----------------------------------------------------------------------------
bool
SurfTriMesh::Init( int nNumVert, int nNumTria, int nNumFacet)
{
// imposto ricalcolo della grafica
// imposto ricalcolo della grafica e di hashgrids3d
m_OGrMgr.Reset() ;
ResetHashGrids3d() ;
// verifico validità parametri
if ( nNumVert < 3 || nNumTria < 1)
return false ;
@@ -80,6 +82,7 @@ SurfTriMesh::AddVertex( const Point3d& ptVert)
// imposto ricalcolo
m_nStatus = TO_VERIFY ;
m_OGrMgr.Reset() ;
ResetHashGrids3d() ;
// inserisco il vertice
try { m_vVert.emplace_back( ptVert) ;}
catch(...) { return SVT_NULL ;}
@@ -94,6 +97,7 @@ SurfTriMesh::SetVertex( int nInd, const StmVert& vV)
// imposto ricalcolo
m_nStatus = TO_VERIFY ;
m_OGrMgr.Reset() ;
ResetHashGrids3d() ;
// recupero la dimensione originale
int nPrevSize = int( m_vVert.size()) ;
// determino la dimensione necessaria
@@ -143,6 +147,7 @@ SurfTriMesh::AddTriangle( const int nIdVert[3])
// imposto ricalcolo
m_nStatus = TO_VERIFY ;
m_OGrMgr.Reset() ;
ResetHashGrids3d() ;
// inserisco il triangolo
try { m_vTria.emplace_back( nIdVert) ;}
catch(...) { return SVT_NULL ;}
@@ -157,6 +162,7 @@ SurfTriMesh::SetTriangle( int nInd, const StmTria& tT)
// imposto ricalcolo
m_nStatus = TO_VERIFY ;
m_OGrMgr.Reset() ;
ResetHashGrids3d() ;
// recupero la dimensione originale
int nPrevSize = int( m_vTria.size()) ;
// determino la dimensione necessaria
@@ -1040,8 +1046,9 @@ SurfTriMesh::Save( NgeWriter& ngeOut) const
bool
SurfTriMesh::Load( NgeReader& ngeIn)
{
// imposto ricalcolo della grafica
// imposto ricalcolo della grafica e di hashgrids3d
m_OGrMgr.Reset() ;
ResetHashGrids3d() ;
// leggo la prossima linea ( 2 parametri : dLinTol e dSmoothAng)
// tolleranza lineare di costruzione
double dLinTol ;
@@ -1680,6 +1687,7 @@ SurfTriMesh::CreateByExtrusion( const PolyLine& PL, const Vector3d& vtExtr)
// imposto ricalcolo
m_nStatus = ERR ;
m_OGrMgr.Reset() ;
ResetHashGrids3d() ;
// verifico se la polilinea è chiusa
bool bClosed = PL.IsClosed() ;
@@ -1749,6 +1757,7 @@ SurfTriMesh::CreateByPointCurve( const Point3d& ptP, const PolyLine& PL)
// imposto ricalcolo
m_nStatus = ERR ;
m_OGrMgr.Reset() ;
ResetHashGrids3d() ;
// costruisco la mesh
int nVertNbr = 1 + PL.GetPointNbr() ;
@@ -1799,7 +1808,8 @@ SurfTriMesh::CreateByTwoCurves( const PolyLine& PL1, const PolyLine& PL2)
// imposto ricalcolo
m_nStatus = ERR ;
m_OGrMgr.Reset() ;
ResetHashGrids3d() ;
// flag di curve chiuse
bool bClosed = PL1.IsClosed() && PL2.IsClosed() ;
// recupero i parametri delle due polilinee
@@ -2091,6 +2101,7 @@ SurfTriMesh::CreateByScrewing( const PolyLine& PL, const Point3d& ptAx, const Ve
// imposto ricalcolo
m_nStatus = ERR ;
m_OGrMgr.Reset() ;
ResetHashGrids3d() ;
// verifico se la polilinea è chiusa
bool bClosed = PL.IsClosed() ;
@@ -2325,6 +2336,7 @@ SurfTriMesh::DoCompacting( double dTol)
// imposto ricalcolo
m_nStatus = ERR ;
m_OGrMgr.Reset() ;
ResetHashGrids3d() ;
// definisco un Grid per i vertici della superficie
PointGrid3d VertGrid ;
@@ -2411,6 +2423,7 @@ SurfTriMesh::DoSewing( const ISurfTriMesh& stmOther, const Frame3d& frOther)
// imposto ricalcolo
m_nStatus = ERR ;
m_OGrMgr.Reset() ;
ResetHashGrids3d() ;
// definisco un Grid per i vertici delle due superfici
PointGrid3d VertGrid ;
@@ -2538,8 +2551,9 @@ SurfTriMesh::Translate( const Vector3d& vtMove)
if ( m_nStatus != OK)
return false ;
// imposto ricalcolo della grafica
// imposto ricalcolo della grafica e di hashgrids3d
m_OGrMgr.Reset() ;
ResetHashGrids3d() ;
// traslo i vertici
for ( int i = 0 ; i < GetVertexSize() ; ++ i) {
@@ -2562,8 +2576,9 @@ SurfTriMesh::Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng,
if ( vtAx.IsSmall())
return false ;
// imposto ricalcolo della grafica
// imposto ricalcolo della grafica e di hashgrids3d
m_OGrMgr.Reset() ;
ResetHashGrids3d() ;
// ruoto i vertici
for ( int i = 0 ; i < GetVertexSize() ; ++ i) {
@@ -2604,8 +2619,9 @@ SurfTriMesh::Scale( const Frame3d& frRef, double dCoeffX, double dCoeffY, double
if ( ( bZeroX && bZeroY) || ( bZeroX && bZeroZ) || ( bZeroY && bZeroZ))
return false ;
// imposto ricalcolo della grafica
// imposto ricalcolo della grafica e di hashgrids3d
m_OGrMgr.Reset() ;
ResetHashGrids3d() ;
// scalo i vertici
for ( int i = 0 ; i < GetVertexSize() ; ++ i) {
@@ -2697,8 +2713,9 @@ SurfTriMesh::Mirror( const Point3d& ptOn, const Vector3d& vtNorm)
if ( vtNorm.IsSmall())
return false ;
// imposto ricalcolo della grafica
// imposto ricalcolo della grafica e di hashgrids3d
m_OGrMgr.Reset() ;
ResetHashGrids3d() ;
// specchio i vertici
for ( int i = 0 ; i < GetVertexSize() ; ++ i)
@@ -2729,8 +2746,9 @@ SurfTriMesh::Shear( const Point3d& ptOn, const Vector3d& vtNorm, const Vector3d&
if ( vtNorm.IsSmall() || vtDir.IsSmall())
return false ;
// imposto ricalcolo della grafica
// imposto ricalcolo della grafica e di hashgrids3d
m_OGrMgr.Reset() ;
ResetHashGrids3d() ;
// eseguo scorrimento dei vertici
for ( int i = 0 ; i < GetVertexSize() ; ++ i) {
@@ -2760,8 +2778,9 @@ SurfTriMesh::ToGlob( const Frame3d& frRef)
if ( frRef.GetType() == Frame3d::ERR)
return false ;
// imposto ricalcolo della grafica
// imposto ricalcolo della grafica e di hashgrids3d
m_OGrMgr.Reset() ;
ResetHashGrids3d() ;
// trasformo i vertici
for ( int i = 0 ; i < GetVertexSize() ; ++ i) {
@@ -2790,8 +2809,9 @@ SurfTriMesh::ToLoc( const Frame3d& frRef)
if ( frRef.GetType() == Frame3d::ERR)
return false ;
// imposto ricalcolo della grafica
// imposto ricalcolo della grafica e di hashgrids3d
m_OGrMgr.Reset() ;
ResetHashGrids3d() ;
// trasformo i vertici
for ( int i = 0 ; i < GetVertexSize() ; ++ i) {
@@ -2824,8 +2844,9 @@ SurfTriMesh::LocToLoc( const Frame3d& frOri, const Frame3d& frDest)
if ( AreSameFrame( frOri, frDest))
return true ;
// imposto ricalcolo della grafica
// imposto ricalcolo della grafica e di hashgrids3d
m_OGrMgr.Reset() ;
ResetHashGrids3d() ;
// trasformo i vertici
for ( int i = 0 ; i < GetVertexSize() ; ++ i) {
@@ -2854,8 +2875,9 @@ SurfTriMesh::Invert( void)
for ( int i = 0 ; i < GetTriangleSize() ; ++ i)
InvertTriangle( i) ;
// imposto ricalcolo della grafica
// imposto ricalcolo della grafica e di hashgrids3d
m_OGrMgr.Reset() ;
ResetHashGrids3d() ;
return true ;
}
@@ -3069,3 +3091,64 @@ SurfTriMesh::Cut( const Plane3d& plPlane, bool bSaveOnEq)
return true ;
}
//----------------------------------------------------------------------------
void
SurfTriMesh::ResetHashGrids3d( void) const
{
if ( m_pHGrd3d != nullptr) {
delete m_pHGrd3d ;
m_pHGrd3d = nullptr ;
m_b3HGrd3d.Reset() ;
}
}
//----------------------------------------------------------------------------
bool
SurfTriMesh::VerifyHashGrids3d( void) const
{
// se già calcolato, non devo fare altro
if ( m_pHGrd3d != nullptr)
return true ;
// alloco
m_pHGrd3d = new HashGrids3d ;
if ( m_pHGrd3d == nullptr)
return false ;
// riempio
const int LIM_HG_TRIA = 127 ;
m_pHGrd3d->SetActivationGrid( GetTriangleCount() > LIM_HG_TRIA) ;
Triangle3d TriaH ;
int nT = GetFirstTriangle( TriaH) ;
while ( nT != SVT_NULL) {
BBox3d boxT ;
TriaH.GetLocalBBox( boxT) ;
m_b3HGrd3d.Add( boxT) ;
if ( ! m_pHGrd3d->Add( nT, boxT)) {
ResetHashGrids3d() ;
return false ;
}
nT = GetNextTriangle( nT, TriaH) ;
}
if ( ! m_pHGrd3d->Update()) {
ResetHashGrids3d() ;
return false ;
}
return true ;
}
//----------------------------------------------------------------------------
bool
SurfTriMesh::GetAllTriaOverlapBox( const BBox3d& b3Box, INTVECTOR& vT) const
{
if ( ! VerifyHashGrids3d())
return false ;
return m_pHGrd3d->Find( b3Box, vT) ;
}
//----------------------------------------------------------------------------
const BBox3d&
SurfTriMesh::GetAllTriaBox( void) const
{
VerifyHashGrids3d() ;
return m_b3HGrd3d ;
}