diff --git a/EgtGeomKernel.rc b/EgtGeomKernel.rc index 2d37101..d93cc2c 100644 Binary files a/EgtGeomKernel.rc and b/EgtGeomKernel.rc differ diff --git a/VolZmap.cpp b/VolZmap.cpp index 6f1a4f4..039a79f 100644 --- a/VolZmap.cpp +++ b/VolZmap.cpp @@ -40,6 +40,10 @@ using namespace std ; +#if !defined(_WIN64) + int VolZmap::m_nDexelNbr = 0 ; +#endif + //---------------------------------------------------------------------------- GEOOBJ_REGISTER( VOL_ZMAP, NGE_V_ZMP, VolZmap) ; @@ -64,6 +68,13 @@ VolZmap::VolZmap(void) //---------------------------------------------------------------------------- VolZmap::~VolZmap( void) { + // Se versione 32-bit aggiorno il numero di Dexel complessivi rimuovendo il numero dei correnti + #if !defined(_WIN64) + int nDexelNbr = 0 ; + for ( int i = 0 ; i < ssize( m_nDim) ; ++ i) + nDexelNbr += m_nDim[i] ; + m_nDexelNbr = max( 0, m_nDexelNbr - nDexelNbr) ; + #endif } //---------------------------------------------------------------------------- @@ -84,6 +95,13 @@ VolZmap::Clear( void) m_nNumBlock = 0 ; m_nConnectedCompoCount = 0 ; m_MapFrame.Reset() ; + // Se versione 32-bit aggiorno il numero di Dexel complessivi rimuovendo il numero dei correnti + #if !defined(_WIN64) + int nDexelNbr = 0 ; + for ( int i = 0 ; i < ssize( m_nDim) ; ++ i) + nDexelNbr += m_nDim[i] ; + m_nDexelNbr = max( 0, m_nDexelNbr - nDexelNbr) ; + #endif for ( int i = 0 ; i < N_MAPS ; ++ i) { m_nNx[i] = 0 ; m_nNy[i] = 0 ; @@ -1928,8 +1946,6 @@ VolZmap::RemoveFins( const Vector3d& vtDir, double dThick) // Indici del dexel int nI = nDex % m_nNx[nGrid] ; int nJ = nDex / m_nNx[nGrid] ; - // Recupero il numero di intervalli presenti nel Dexel corrente - int nIntervals = ssize( pZMapCopy->m_Values[nGrid][nDex]) ; // Scorro gli intervalli presenti for ( int nInfo = 0 ; nInfo < ssize( pZMapCopy->m_Values[nGrid][nDex]) ; ++ nInfo) { // Recupero l'intervallo corrente diff --git a/VolZmap.h b/VolZmap.h index 2f6e098..f29ea72 100644 --- a/VolZmap.h +++ b/VolZmap.h @@ -81,10 +81,10 @@ class VolZmap : public IVolZmap, public IGeoObjRW public : // IVolZmap bool CopyFrom( const IGeoObj* pGObjSrc) override ; bool Clear( void) override ; - bool Create( const Point3d& ptO, double dDimX, double dDimY, double dDimZ, double dStep, bool bTriDex) override ; - bool CreateEmpty( const Point3d& ptO, double dDimX, double dDimY, double dDimZ, double dStep, bool bTriDex) override ; - bool CreateFromFlatRegion( const ISurfFlatRegion& Surf, double dDimZ, double dStep, bool bTriDex) override ; - bool CreateFromTriMesh( const ISurfTriMesh& Surf, double dStep, bool bTriDex, double dExtraBox = 0) override ; + bool Create( const Point3d& ptO, double dDimX, double dDimY, double dDimZ, double dStep, bool bTriDex, int* nError = nullptr) override ; + bool CreateEmpty( const Point3d& ptO, double dDimX, double dDimY, double dDimZ, double dStep, bool bTriDex, int* nError = nullptr) override ; + bool CreateFromFlatRegion( const ISurfFlatRegion& Surf, double dDimZ, double dStep, bool bTriDex, int* nError = nullptr) override ; + bool CreateFromTriMesh( const ISurfTriMesh& Surf, double dStep, bool bTriDex, double dExtraBox = 0, int* nError = nullptr) override ; int GetBlockCount( void) const override ; int GetBlockUpdatingCounter( int nBlock) const override ; bool GetBlockTriangles( int nBlock, TRIA3DEXVECTOR& vTria) const override ; @@ -227,7 +227,16 @@ class VolZmap : public IVolZmap, public IGeoObjRW typedef std::unordered_map VoxelContainer ; // Unordered map per la coerenza topologica typedef std::unordered_map InterVoxMatter ; - + #if !defined(_WIN64) + // Numero massimo approssimativo di Dexel per versione 32-bit per evitare Crash con memoria + #if defined(_DEBUG) + static const int MAX_DEXEL_32_BIT = 3000000 + 1 ; + #else + static const int MAX_DEXEL_32_BIT = 5000000 + 1 ; + #endif + static int m_nDexelNbr ; // numero corrente di Dexel presenti + #endif + private : bool CopyFrom( const VolZmap& clSrc) ; bool ResetGraphics( void) ; @@ -488,7 +497,7 @@ class VolZmap : public IVolZmap, public IGeoObjRW // Funzioni per Offset di Zmap bool OffsetFillet( double dOffs) ; bool OffsetSharped( double dOffs, int nType) ; - // Funzione analisi punti/Normali + // Funzione analisi punti/Normali per Alette bool GetLocalPoint( int nGrid, int nI, int nJ, double dZ, Point3d& ptLoc) ; bool ComputePointAndNormalForRemovingFins( int nGrid, int nI, int nJ, double dZ, const Vector3d& vtDir, double dThick, bool bMinVsMax, int nTool, diff --git a/VolZmapCreation.cpp b/VolZmapCreation.cpp index 7a5358b..696dfaf 100644 --- a/VolZmapCreation.cpp +++ b/VolZmapCreation.cpp @@ -27,8 +27,8 @@ using namespace std ; // ------------------------- CREAZIONE MAPPA -------------------------------------------------------------------------------------- //---------------------------------------------------------------------------- -bool -VolZmap::Create( const Point3d& ptO, double dDimX, double dDimY, double dDimZ, double dStep, bool bTriDex) +bool +VolZmap::Create( const Point3d& ptO, double dDimX, double dDimY, double dDimZ, double dStep, bool bTriDex, int* nError) { // Controlli sull'ammissibilità delle dimensioni lineari del grezzo e del passo if ( dStep < EPS_SMALL || dDimX < EPS_SMALL || dDimY < EPS_SMALL || dDimZ < EPS_SMALL) @@ -51,7 +51,7 @@ VolZmap::Create( const Point3d& ptO, double dDimX, double dDimY, double dDimZ, d m_nNx[0] = max( int( ( dDimX + EPS_SMALL) / m_dStep + 0.5), 1) ; m_nNy[0] = max( int( ( dDimY + EPS_SMALL) / m_dStep + 0.5), 1) ; - // Numero di componenti connesse + // Numero di componenti connesse m_nConnectedCompoCount = 1 ; // Se tridexel @@ -67,7 +67,7 @@ VolZmap::Create( const Point3d& ptO, double dDimX, double dDimY, double dDimZ, d m_nNx[1] = 0 ; m_nNy[1] = 0 ; m_nNx[2] = 0 ; - m_nNy[2] = 0 ; + m_nNy[2] = 0 ; } // Definisco il numero di blocchi lungo x,y e z @@ -81,12 +81,24 @@ VolZmap::Create( const Point3d& ptO, double dDimX, double dDimY, double dDimZ, d for ( int i = 0 ; i < m_nMapNum ; ++ i) m_nDim[i] = m_nNx[i] * m_nNy[i] ; + // Se versione 32-bit controllo di non superare il numero di Dexel massimo + #if !defined(_WIN64) + for ( int i = 0 ; i < ssize( m_nDim) ; ++ i) + m_nDexelNbr += m_nDim[i] ; + if ( m_nDexelNbr >= MAX_DEXEL_32_BIT) { + Clear() ; + if ( nError != nullptr) + *nError = 1 ; + return false ; + } + #endif + // Creazione delle celle per ogni mappa for ( int i = 0 ; i < m_nMapNum ; ++ i) m_Values[i].resize( m_nDim[i]) ; // Riempimento delle celle - for ( int i = 0 ; i < m_nMapNum ; ++ i) + for ( int i = 0 ; i < m_nMapNum ; ++ i) { for ( int j = 0 ; j < m_nDim[i] ; ++ j) { // Aggiungo il tratto al dexel vuoto @@ -98,7 +110,7 @@ VolZmap::Create( const Point3d& ptO, double dDimX, double dDimY, double dDimZ, d switch ( i) { case 0 : m_Values[i][j][0].vtMinN = - Z_AX ; - m_Values[i][j][0].dMax = dDimZ ; + m_Values[i][j][0].dMax = dDimZ ; m_Values[i][j][0].vtMaxN = Z_AX ; m_Values[i][j][0].nToolMax = 0 ; break ; @@ -113,9 +125,10 @@ VolZmap::Create( const Point3d& ptO, double dDimX, double dDimY, double dDimZ, d m_Values[i][j][0].dMax = dDimY ; m_Values[i][j][0].vtMaxN = Y_AX ; m_Values[i][j][0].nToolMax = 0 ; - break ; + break ; } } + } // Definizione delle limitazioni iniziali in Z per ogni mappa m_dMinZ[0] = 0 ; @@ -136,7 +149,7 @@ VolZmap::Create( const Point3d& ptO, double dDimX, double dDimY, double dDimZ, d //---------------------------------------------------------------------------- bool -VolZmap::CreateEmpty( const Point3d& ptO, double dDimX, double dDimY, double dDimZ, double dStep, bool bTriDex) +VolZmap::CreateEmpty( const Point3d& ptO, double dDimX, double dDimY, double dDimZ, double dStep, bool bTriDex, int* nError) { // Controlli sull'ammissibilità delle dimensioni lineari del grezzo e del passo if ( dStep < EPS_SMALL || dDimX < EPS_SMALL || dDimY < EPS_SMALL || dDimZ < EPS_SMALL) @@ -187,6 +200,18 @@ VolZmap::CreateEmpty( const Point3d& ptO, double dDimX, double dDimY, double dDi for ( int i = 0 ; i < m_nMapNum ; ++ i) m_nDim[i] = m_nNx[i] * m_nNy[i] ; + // Se versione 32-bit controllo di non superare il numero di Dexel massimo + #if !defined(_WIN64) + for ( int i = 0 ; i < ssize( m_nDim) ; ++ i) + m_nDexelNbr += m_nDim[i] ; + if ( m_nDexelNbr >= MAX_DEXEL_32_BIT) { + Clear() ; + if ( nError != nullptr) + *nError = 1 ; + return false ; + } + #endif + // Creazione delle celle per ogni mappa for ( int i = 0 ; i < m_nMapNum ; ++ i) m_Values[i].resize( m_nDim[i]) ; @@ -210,7 +235,7 @@ VolZmap::CreateEmpty( const Point3d& ptO, double dDimX, double dDimY, double dDi //---------------------------------------------------------------------------- bool -VolZmap::CreateFromFlatRegion( const ISurfFlatRegion& Surf, double dDimZ, double dStep, bool bTriDex) +VolZmap::CreateFromFlatRegion( const ISurfFlatRegion& Surf, double dDimZ, double dStep, bool bTriDex, int* nError) { // Aggiorno la dimensione della mappa 1 o 3 m_nMapNum = ( bTriDex ? 3 : 1) ; @@ -250,14 +275,35 @@ VolZmap::CreateFromFlatRegion( const ISurfFlatRegion& Surf, double dDimZ, double m_nNx[1] = m_nNy[0] ; m_nNy[1] = int( ( dDimZ + EPS_SMALL) / m_dStep + 0.5) ; m_nDim[1] = m_nNx[1] * m_nNy[1] ; - m_Values[1].resize( m_nDim[1]) ; m_nNx[2] = m_nNy[1] ; m_nNy[2] = m_nNx[0] ; m_nDim[2] = m_nNx[2] * m_nNy[2] ; + // Se versione 32-bit controllo di non superare il numero di Dexel massimo + #if !defined(_WIN64) + for ( int i = 0 ; i < ssize( m_nDim) ; ++ i) + m_nDexelNbr += m_nDim[i] ; + if ( m_nDexelNbr >= MAX_DEXEL_32_BIT) { + Clear() ; + if ( nError != nullptr) + *nError = 1 ; + return false ; + } + #endif + m_Values[1].resize( m_nDim[1]) ; m_Values[2].resize( m_nDim[2]) ; } - + // Se dimensione singola else { + // Se versione 32-bit controllo di non superare il numero di Dexel massimo + #if !defined(_WIN64) + m_nDexelNbr += m_nDim[0] ; + if ( m_nDexelNbr >= MAX_DEXEL_32_BIT) { + Clear() ; + if ( nError != nullptr) + *nError = 1 ; + return false ; + } + #endif m_nNx[1] = 0 ; m_nNy[1] = 0 ; m_nDim[1] = 0 ; @@ -788,7 +834,7 @@ VolZmap::SubtractMapPart( int nMap, int nInfI, int nSupI, int nInfJ, int nSupJ, //---------------------------------------------------------------------------- bool -VolZmap::CreateFromTriMesh( const ISurfTriMesh& Surf, double dStep, bool bTriDex, double dExtraBox) +VolZmap::CreateFromTriMesh( const ISurfTriMesh& Surf, double dStep, bool bTriDex, double dExtraBox, int* nError) { // Se la superficie non è chiusa oppure orientata al contrario non ha senso continuare double dVol ; @@ -838,14 +884,33 @@ VolZmap::CreateFromTriMesh( const ISurfTriMesh& Surf, double dStep, bool bTriDex m_nNx[1] = m_nNy[0] ; m_nNy[1] = int( ( vtLen.z + EPS_SMALL) / m_dStep + 0.5) ; m_nDim[1] = m_nNx[1] * m_nNy[1] ; - m_Values[1].resize( m_nDim[1]) ; m_nNx[2] = m_nNy[1] ; m_nNy[2] = m_nNx[0] ; m_nDim[2] = m_nNx[2] * m_nNy[2] ; + #if !defined(_WIN64) + for ( int i = 0 ; i < ssize( m_nDim) ; ++ i) + m_nDexelNbr += m_nDim[i] ; + if ( m_nDexelNbr >= MAX_DEXEL_32_BIT) { + Clear() ; + if ( nError != nullptr) + *nError = 1 ; + return false ; + } + #endif + m_Values[1].resize( m_nDim[1]) ; m_Values[2].resize( m_nDim[2]) ; } - + // Se a dimensione singola else { + #if !defined(_WIN64) + m_nDexelNbr += m_nDim[0] ; + if ( m_nDexelNbr >= MAX_DEXEL_32_BIT) { + Clear() ; + if ( nError != nullptr) + *nError = 1 ; + return false ; + } + #endif m_nNx[1] = 0 ; m_nNy[1] = 0 ; m_nDim[1] = 0 ; diff --git a/VolZmapVolume.cpp b/VolZmapVolume.cpp index 5afd9cb..79411f9 100644 --- a/VolZmapVolume.cpp +++ b/VolZmapVolume.cpp @@ -968,8 +968,8 @@ VolZmap::ComputePointAndNormalForRemovingFins( int nGrid, int nI, int nJ, double double dExpandY = ( m_MapFrame.VersY() * Y_AX) * dThick * ( vtDirProj * Y_AX) ; double dExpandZ = ( m_MapFrame.VersZ() * Z_AX) * dThick * ( vtDirProj * Z_AX) ; BBoxLoc.Expand( max( ( m_dStep + EPS_SMALL), dExpandX), - max( ( m_dStep + EPS_SMALL), dExpandY), - max( ( m_dStep + EPS_SMALL), dExpandZ)) ; + max( ( m_dStep + EPS_SMALL), dExpandY), + max( ( m_dStep + EPS_SMALL), dExpandZ)) ; // Porto il Box nel Frame della Mappa corrente BBox3d BBoxInGrid = GetToLoc( BBoxLoc, m_MapFrame) ;