EgtGeomKernel :

- codice di test per Zmap.
This commit is contained in:
Riccardo Elitropi
2024-04-22 08:06:33 +02:00
parent a5a96c2bb5
commit 9bc315bd1d
4 changed files with 767 additions and 280 deletions
+178
View File
@@ -21,12 +21,14 @@
#include "DistPointLine.h"
#include "GeoConst.h"
#include "/EgtDev/Include/EGkIntersLinePlane.h"
#include "/EgtDev/Include/EGkIntersLineSurfTm.h"
#include "/EgtDev/Include/EGkUiUnits.h"
#include "/EgtDev/Include/EGkIntervals.h"
#include "/EgtDev/Include/EGkStringUtils3d.h"
#include "/EgtDev/Include/EgtNumUtils.h"
#include <thread>
#include <future>
#include "IntersLineBox.h"
using namespace std ;
@@ -93,6 +95,54 @@ VolZmap::Clear( void)
return true ;
}
//----------------------------------------------------------------------------
bool
VolZmap::IsEmpty( void)
{
// controllo validità
if ( ! IsValid())
return false ;
bool bIsEmpty = true ; // flag
// ciclo sul numero di mappe
for ( int i = 0 ; bIsEmpty && i < m_nMapNum ; ++ i) {
// ciclo sulle dimensioni di ogni mappa
for ( int j = 0 ; bIsEmpty && j < m_nDim[i] ; ++ j) {
// controllo se esiste un tratto di dexel non vuoto
bIsEmpty = ( int( m_Values[i][j].size()) == 1 &&
abs( m_Values[i][j][0].dMin) < EPS_ZERO &&
m_Values[i][j][0].nToolMin == 0 &&
m_Values[i][j][0].nCompo == 1) ;
if ( bIsEmpty) {
switch ( i) {
case 0 :
bIsEmpty = ( m_Values[i][j][0].vtMinN.IsZminus() &&
abs( m_Values[i][j][0].dMax) < EPS_ZERO &&
m_Values[i][j][0].vtMaxN.IsZplus() &&
m_Values[i][j][0].nToolMax == 0) ;
break ;
case 1 :
bIsEmpty = ( m_Values[i][j][0].vtMinN.IsZminus() &&
abs( m_Values[i][j][0].dMax) < EPS_ZERO &&
m_Values[i][j][0].vtMaxN.IsXplus() &&
m_Values[i][j][0].nToolMax == 0 ) ;
break ;
case 2 :
bIsEmpty = ( m_Values[i][j][0].vtMinN.IsYminus() &&
abs( m_Values[i][j][0].dMax) < EPS_ZERO &&
m_Values[i][j][0].vtMaxN.IsYplus() &&
m_Values[i][j][0].nToolMax == 0 ) ;
break ;
}
}
}
}
return bIsEmpty ;
}
//----------------------------------------------------------------------------
VolZmap*
VolZmap::Clone( void) const
@@ -1657,6 +1707,134 @@ VolZmap::SetToModifyDexelBlocks( int nGrid, int nDex, int nInt)
return true ;
}
//----------------------------------------------------------------------------
bool
VolZmap::AddSrfTm( const ISurfTriMesh* pStm)
{
// controllo sulla superficie
double dVol ;
if ( pStm == nullptr || ! pStm->IsValid() || ! pStm->IsClosed() ||
! pStm->GetVolume( dVol) || dVol < 0)
return false ;
// controllo se il Box3d della superficie si interseca con il Box3d dello Zmap corrente
BBox3d BBox_stm ;
if ( ! pStm->GetLocalBBox( BBox_stm))
return false ;
BBox3d BBox_curr ;
if ( ! GetLocalBBox( BBox_curr))
return false ;
BBox3d BBox_inters ;
if ( BBox_stm.FindIntersection( BBox_curr, BBox_inters) && BBox_inters.IsEmpty())
return true ; // se non ci sono intersezioni, la superficie non influenza lo Zmap
// determino i punti estremi del bounding box corrente
BBox3d BBoxCurr ;
if ( ! GetLocalBBox( BBoxCurr))
return false ;
Point3d ptMapOrig, ptMapEnd ;
BBoxCurr.GetMinMax( ptMapOrig, ptMapEnd) ;
// determino le dimensioni lineari del BBox
Vector3d vtLen = ptMapEnd - ptMapOrig ;
// creo uno Zmap vuoto per la TriMesh
PtrOwner<VolZmap> pZmapStm( CreateBasicVolZmap()) ;
if ( IsNull( pZmapStm) ||
! pZmapStm->CreateEmptyMap( ptMapOrig, BBoxCurr.GetDimX() + 10 * EPS_SMALL,
BBoxCurr.GetDimY() + 10 * EPS_SMALL,
BBoxCurr.GetDimZ() + 10 * EPS_SMALL,
m_dStep, IsTriDexel()))
return false ;
// ciclo sulle griglie
bool bCompleted = true ;
for ( int g = 0 ; g < pZmapStm->m_nMapNum ; ++ g) {
// definisco dei sistemi di riferimento ausiliari
Frame3d frMapFrame ;
if ( g == 0)
frMapFrame = m_MapFrame ;
else if ( g == 1)
frMapFrame.Set( ptMapOrig, Y_AX, Z_AX, X_AX) ;
else if ( g == 2)
frMapFrame.Set( ptMapOrig, Z_AX, X_AX, Y_AX) ;
// oggetto per calcolo massivo intersezioni
IntersParLinesSurfTm intPLSTM( frMapFrame, *pStm) ;
// numero massimo di thread
int nThreadMax = max( 1, int( thread::hardware_concurrency()) - 1) ;
vector<future<bool>> vRes ;
vRes.resize( nThreadMax) ;
if ( pZmapStm->m_nNx[g] > pZmapStm->m_nNy[g]) {
int nDexNum = pZmapStm->m_nNx[g] / nThreadMax ;
int nRemainder = pZmapStm->m_nNx[g] % nThreadMax ;
int nInfI = 0 ;
int nSupI = 0 ;
for ( int nThread = 0 ; nThread < nThreadMax ; ++ nThread) {
nInfI = nSupI ;
nSupI = nInfI + ( nThread < nRemainder ? nDexNum + 1 : nDexNum) ;
vRes[nThread] = async( launch::async, &VolZmap::CreateMapPart, this, g,
nInfI, nSupI, 0, pZmapStm->m_nNy[g], ref( vtLen), ref( ptMapOrig), ref( *pStm), ref( intPLSTM)) ;
}
}
else {
int nDexNum = pZmapStm->m_nNy[g] / nThreadMax ;
int nRemainder = pZmapStm->m_nNy[g] % nThreadMax ;
int nInfJ = 0 ;
int nSupJ = 0 ;
for ( int nThread = 0 ; nThread < nThreadMax ; ++ nThread) {
nInfJ = nSupJ ;
nSupJ = nInfJ + ( nThread < nRemainder ? nDexNum + 1 : nDexNum) ;
vRes[nThread] = async( launch::async, &VolZmap::CreateMapPart, this, g,
0, pZmapStm->m_nNx[g], nInfJ, nSupJ, ref( vtLen), ref( ptMapOrig), ref( *pStm), ref( intPLSTM)) ;
}
}
// ciclo per attendere che tutti gli async abbiano terminato.
int nTerminated = 0 ;
while ( nTerminated < nThreadMax) {
for ( int nL = 0 ; nL < nThreadMax ; ++ nL) {
// Async terminato
if ( vRes[nL].valid() && vRes[nL].wait_for( chrono::microseconds{ 1}) == future_status::ready) {
++ nTerminated ;
bCompleted = bCompleted && vRes[nL].get() ;
}
}
}
// bho ( ???????? )
if ( ! bCompleted)
return false ;
// aggiungo ora gli intervalli ricavati allo Zmap corrente ( *this)
// ciclo sui dexel della mappa
for ( int nD = 0 ; nD < int( pZmapStm->m_Values[g].size()) ; ++ nD) {
// se spillone vuoto, passo al successivo
if ( pZmapStm->m_Values[g][nD].empty())
continue ;
// indici di spillone
int nI = nD % pZmapStm->m_nNx[g] ;
int nJ = nD / pZmapStm->m_nNx[g] ;
// ciclo sui voxel associati
for ( int nV = 0 ; nV < int( pZmapStm->m_Values[g][nD].size()) ; ++ nV) {
// estremi del voxel
double dMin = pZmapStm->m_Values[g][nD][nV].dMin ;
double dMax = pZmapStm->m_Values[g][nD][nV].dMax ;
// vettori associati agli estremi
Vector3d vtMaxN = pZmapStm->m_Values[g][nD][nV].vtMaxN ;
Vector3d vtMinN = pZmapStm->m_Values[g][nD][nV].vtMinN ;
// aggiungo l'intervallo // per ora... (???)
AddIntervals( g, nI, nJ, dMin, dMax, vtMinN, vtMaxN, 0) ;
}
}
}
return true ;
}
//----------------------------------------------------------------------------
bool
VolZmap::IsMapPartABox( int nMap, int nInfI, int nSupI, int nInfJ, int nSupJ, double& dMinZ, double& dMaxZ)