EgtGeomKernel :
- aggiunta gestione parti connesse in SurfTriMesh.
This commit is contained in:
+153
-8
@@ -1,13 +1,14 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// EgalTech 2014-2015
|
||||
// EgalTech 2014-2019
|
||||
//----------------------------------------------------------------------------
|
||||
// File : SurfTriMesh.cpp Data : 15.05.14 Versione : 1.5e5
|
||||
// File : SurfTriMesh.cpp Data : 02.01.19 Versione : 1.9l4
|
||||
// Contenuto : Implementazione della classe Superfici TriMesh.
|
||||
//
|
||||
//
|
||||
//
|
||||
// Modifiche : 26.03.14 DS Creazione modulo.
|
||||
// 15.05.14 DS Corr. errore CreateByTwoCurves che dava loop infinito.
|
||||
// 02.01.19 LM Aggiunta gestione connessione.
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
@@ -26,6 +27,7 @@
|
||||
#include "/EgtDev/Include/EGkUiUnits.h"
|
||||
#include "/EgtDev/Include/EgtPointerOwner.h"
|
||||
#include <new>
|
||||
#include <set>
|
||||
|
||||
using namespace std ;
|
||||
|
||||
@@ -36,7 +38,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_pHGrd3d( nullptr)
|
||||
m_nTimeStamp( 0), m_nTempProp( 0), m_pHGrd3d( nullptr), m_nParts( -1)
|
||||
{
|
||||
m_dCosBndAng = cos( m_dBoundaryAng * DEGTORAD) ;
|
||||
m_dCosSmAng = cos( m_dSmoothAng * DEGTORAD) ;
|
||||
@@ -81,6 +83,7 @@ SurfTriMesh::AddVertex( const Point3d& ptVert)
|
||||
{
|
||||
// imposto ricalcolo
|
||||
m_nStatus = TO_VERIFY ;
|
||||
m_nParts = - 1 ;
|
||||
m_OGrMgr.Reset() ;
|
||||
ResetHashGrids3d() ;
|
||||
// inserisco il vertice
|
||||
@@ -146,6 +149,7 @@ SurfTriMesh::AddTriangle( const int nIdVert[3])
|
||||
return SVT_DEL ;
|
||||
// imposto ricalcolo
|
||||
m_nStatus = TO_VERIFY ;
|
||||
m_nParts = - 1 ;
|
||||
m_OGrMgr.Reset() ;
|
||||
ResetHashGrids3d() ;
|
||||
// inserisco il triangolo
|
||||
@@ -230,6 +234,8 @@ SurfTriMesh::RemoveTriangle( int nId)
|
||||
m_vTria[nId].nIdVert[0] = SVT_DEL ;
|
||||
// invalido calcolo facce
|
||||
m_bFaceted = false ;
|
||||
// invalido calcolo connettività
|
||||
m_nParts = - 1 ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
@@ -926,6 +932,7 @@ SurfTriMesh::CopyFrom( const SurfTriMesh& stmSrc)
|
||||
m_nTempProp = stmSrc.m_nTempProp ;
|
||||
m_bFaceted = stmSrc.m_bFaceted ;
|
||||
m_vFacet = stmSrc.m_vFacet ;
|
||||
m_nParts = stmSrc.m_nParts ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
@@ -958,9 +965,13 @@ SurfTriMesh::Dump( string& sOut, bool bMM, const char* szNewLine) const
|
||||
GetVolume( dVolume) ;
|
||||
sOut += "Closed Volume=" + ToString( GetVolumeInUiUnits( dVolume, bMM), 1) + szNewLine ;
|
||||
}
|
||||
// se segnalo eventuale incongruenza di orientamento
|
||||
// segnalo eventuale incongruenza di orientamento
|
||||
if ( ! m_bOriented)
|
||||
sOut += string( "Inconsistent Orientation") + szNewLine ;
|
||||
// segnalo numero di parti se più di una
|
||||
int nParts = GetPartCount() ;
|
||||
if ( nParts > 1)
|
||||
sOut += string( "Parts =") + ToString( nParts) + szNewLine ;
|
||||
// numero di vertici
|
||||
sOut += "Vert : Nbr=" + ToString( GetVertexCount()) +
|
||||
" Size=" + ToString( GetVertexSize()) + szNewLine ;
|
||||
@@ -1046,8 +1057,9 @@ SurfTriMesh::Save( NgeWriter& ngeOut) const
|
||||
bool
|
||||
SurfTriMesh::Load( NgeReader& ngeIn)
|
||||
{
|
||||
// imposto ricalcolo della grafica e di hashgrids3d
|
||||
// imposto ricalcolo della grafica, della connessione e di hashgrids3d
|
||||
m_OGrMgr.Reset() ;
|
||||
m_nParts = -1 ;
|
||||
ResetHashGrids3d() ;
|
||||
// leggo la prossima linea ( 2 parametri : dLinTol e dSmoothAng)
|
||||
// tolleranza lineare di costruzione
|
||||
@@ -1063,7 +1075,6 @@ SurfTriMesh::Load( NgeReader& ngeIn)
|
||||
m_dCosSmAng = cos( dSmoothAng * DEGTORAD) ;
|
||||
// leggo la prossima linea
|
||||
// prima di versione 1010 3 parametri : flag di chiusa, num vertici, num tria
|
||||
// da versione 1010 leggo flag di orientata
|
||||
bool bOriented ;
|
||||
bool bClosed ;
|
||||
int nNumVert ;
|
||||
@@ -1193,6 +1204,9 @@ SurfTriMesh::Validate( bool bCorrect)
|
||||
m_bFaceted = false ;
|
||||
}
|
||||
|
||||
// invalido calcolo connessione
|
||||
m_nParts = - 1 ;
|
||||
|
||||
return ( m_nStatus == OK) ;
|
||||
}
|
||||
|
||||
@@ -1446,6 +1460,8 @@ SurfTriMesh::AdjustTopology( void)
|
||||
{
|
||||
// dichiaro sfaccettatura da ricalcolare
|
||||
ResetFaceting() ;
|
||||
// invalido calcolo connessione
|
||||
m_nParts = - 1 ;
|
||||
// verifica indici
|
||||
if ( ! Validate( true))
|
||||
return false ;
|
||||
@@ -3085,9 +3101,8 @@ SurfTriMesh::Cut( const Plane3d& plPlane, bool bSaveOnEq)
|
||||
}
|
||||
|
||||
// se necessario, aggiorno tutto
|
||||
if ( bModif) {
|
||||
if ( bModif)
|
||||
return AdjustVertices() && DoCompacting() ;
|
||||
}
|
||||
|
||||
return true ;
|
||||
}
|
||||
@@ -3152,3 +3167,133 @@ SurfTriMesh::GetAllTriaBox( void) const
|
||||
VerifyHashGrids3d() ;
|
||||
return m_b3HGrd3d ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
int
|
||||
SurfTriMesh::GetPartCount( void) const
|
||||
{
|
||||
if ( ! IsValid())
|
||||
return 0 ;
|
||||
if ( m_nParts == - 1 && ! VerifyConnection())
|
||||
return 0 ;
|
||||
return m_nParts ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
SurfTriMesh::VerifyConnection( void) const
|
||||
{
|
||||
if ( ! IsValid())
|
||||
return false ;
|
||||
|
||||
// reset connessione
|
||||
for ( auto Tria : m_vTria)
|
||||
Tria.nPart = SVT_NULL ;
|
||||
|
||||
// ciclo sui triangoli
|
||||
m_nParts = 0 ;
|
||||
for ( int i = 0 ; i < int( m_vTria.size()) ; ++ i) {
|
||||
// salto triangoli cancellati o già assegnati
|
||||
if ( m_vTria[i].nIdVert[0] == SVT_DEL ||
|
||||
m_vTria[i].nPart != SVT_NULL)
|
||||
continue ;
|
||||
// assegno indice di parte connessa al triangolo
|
||||
m_vTria[i].nPart = m_nParts ;
|
||||
++ m_nParts ;
|
||||
// set di triangoli da aggiornare
|
||||
set<int> stTria ;
|
||||
stTria.insert( i) ;
|
||||
while ( ! stTria.empty()) {
|
||||
// tolgo un triangolo dal set
|
||||
const auto iIt = stTria.begin() ;
|
||||
int nT = *iIt ;
|
||||
stTria.erase( iIt) ;
|
||||
// aggiorno i triangoli adiacenti
|
||||
for ( int j = 0 ; j < 3 ; ++ j) {
|
||||
int nAdjT = m_vTria[nT].nIdAdjac[j] ;
|
||||
if ( nAdjT != SVT_NULL && m_vTria[nAdjT].nPart == SVT_NULL) {
|
||||
m_vTria[nAdjT].nPart = m_vTria[nT].nPart ;
|
||||
stTria.insert( nAdjT) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
SurfTriMesh::RemovePart( int nPart)
|
||||
{
|
||||
if ( ! IsValid())
|
||||
return false ;
|
||||
|
||||
// Il numero delle componenti deve essere maggiore di zero o calcolabile
|
||||
if ( m_nParts == -1 && ! VerifyConnection())
|
||||
return false ;
|
||||
|
||||
// Se la componente non esiste, errore
|
||||
if ( m_nParts <= 0 || nPart < 0 || nPart >= m_nParts)
|
||||
return false ;
|
||||
|
||||
int nPartsOld = m_nParts ;
|
||||
// Rimuovo i triangoli della componente nPart
|
||||
for ( int i = 0 ; i < int( m_vTria.size()) ; ++ i) {
|
||||
if ( m_vTria[i].nPart == nPart)
|
||||
RemoveTriangle( i) ;
|
||||
}
|
||||
|
||||
// Aggiorno il numero di componenti
|
||||
m_nParts = nPartsOld - 1 ;
|
||||
|
||||
// imposto ricalcolo della grafica e di hashgrids3d
|
||||
m_OGrMgr.Reset() ;
|
||||
ResetHashGrids3d() ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
SurfTriMesh*
|
||||
SurfTriMesh::ClonePart( int nPart) const
|
||||
{
|
||||
if ( ! IsValid())
|
||||
return nullptr ;
|
||||
|
||||
// Il numero delle componenti deve essere maggiore di zero o calcolabile
|
||||
if ( m_nParts == -1 && ! VerifyConnection())
|
||||
return nullptr ;
|
||||
|
||||
// Se la componente non esiste, errore
|
||||
if ( m_nParts <= 0 || nPart < 0 || nPart >= m_nParts)
|
||||
return nullptr ;
|
||||
|
||||
// Creo nuovo oggetto SurfTriMesh
|
||||
PtrOwner<SurfTriMesh> pSurfTM( new( nothrow) SurfTriMesh) ;
|
||||
if ( IsNull( pSurfTM))
|
||||
return nullptr ;
|
||||
|
||||
// Copio il valore dei membri
|
||||
pSurfTM->m_dLinTol = m_dLinTol ;
|
||||
pSurfTM->m_dBoundaryAng = m_dBoundaryAng ;
|
||||
pSurfTM->m_dCosBndAng = m_dCosBndAng ;
|
||||
pSurfTM->m_dSmoothAng = m_dSmoothAng ;
|
||||
pSurfTM->m_dCosSmAng = m_dCosSmAng ;
|
||||
pSurfTM->m_nParts = 1 ;
|
||||
|
||||
// Copio i triangoli
|
||||
for ( int i = 0 ; i < int( m_vTria.size()) ; ++ i) {
|
||||
if ( m_vTria[i].nIdVert[0] != SVT_DEL && m_vTria[i].nPart == nPart) {
|
||||
int nNewInd[3] = { pSurfTM->AddVertex( m_vVert[m_vTria[i].nIdVert[0]].ptP),
|
||||
pSurfTM->AddVertex( m_vVert[m_vTria[i].nIdVert[1]].ptP),
|
||||
pSurfTM->AddVertex( m_vVert[m_vTria[i].nIdVert[2]].ptP)} ;
|
||||
pSurfTM->AddTriangle( nNewInd) ;
|
||||
}
|
||||
}
|
||||
|
||||
// Aggiusto la superficie
|
||||
pSurfTM->DoCompacting() ;
|
||||
|
||||
// Restituisco la nuova superficie
|
||||
return Release( pSurfTM) ;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user