EgtGeomKernel :

- razionalizzazioni varie.
This commit is contained in:
Dario Sassi
2019-02-11 17:45:26 +00:00
parent fca22fc56b
commit 88fd76934d
5 changed files with 91 additions and 96 deletions
+77 -77
View File
@@ -19,8 +19,8 @@
#include "MC_Tables.h"
#include "PolygonPlane.h"
#include "/EgtDev/Include/EGkIntervals.h"
#include "/EgtDev/Include/EgtNumUtils.h"
#include "/EgtDev/Include/EGkStringUtils3d.h"
#include "/EgtDev/Include/EgtNumUtils.h"
#include "/EgtDev/Extern/Eigen/Core"
#include "/EgtDev/Extern/Eigen/SVD"
@@ -30,7 +30,7 @@ using namespace std ;
static const int MAX_FAN_BASE_VERTS = 7 ;
typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor, MAX_FAN_BASE_VERTS, 3> SvdMatrix ;
typedef Eigen::Matrix<double, Eigen::Dynamic, 1, Eigen::ColMajor, MAX_FAN_BASE_VERTS, 1> SvdVector ;
typedef Eigen::JacobiSVD<SvdMatrix, Eigen::QRPreconditioners::HouseholderQRPreconditioner> SvdDecomposer ;
typedef Eigen::JacobiSVD<SvdMatrix, Eigen::QRPreconditioners::ColPivHouseholderQRPreconditioner> SvdDecomposer ;
// ------------------------- TABELLA BLOCCHI ADIACENTI ----------------------------------------------------------------------------
static int NeighbourTable[8][4] = {
@@ -481,24 +481,19 @@ VolZmap::GetAllTriangles( TRIA3DEXLIST& lstTria) const
bool
VolZmap::GetTriangles( bool bAllBlocks, INTVECTOR& nModifiedBlocks, TRIA3DEXLISTVECTOR& vLstTria) const
{
// Se nessun blocco modificato, è richiesta esterna e li considero tutti modificati
bool bSomeModif = false ;
for ( int i = 0 ; i < m_nNumBlock ; ++ i) {
if ( m_BlockToUpdate[i]) {
bSomeModif = true ;
break ;
}
}
if ( ! bSomeModif)
bAllBlocks = true ;
// Caso di singola mappa
if ( m_nMapNum == 1) {
nModifiedBlocks.resize( m_nNumBlock) ;
vLstTria.reserve( m_nNumBlock) ;
UpGradeGraphicsSingleMap( bAllBlocks, nModifiedBlocks) ;
UpdateSingleMapGraphics( nModifiedBlocks) ;
// Se richiesti tutti, dichiaro tutti modificati
if ( bAllBlocks) {
for ( int i = 0 ; i < m_nNumBlock ; ++ i)
nModifiedBlocks[i] = i ;
}
for ( int t = 0 ; t < m_nNumBlock ; ++ t) {
if ( nModifiedBlocks[t] >= 0) {
@@ -512,10 +507,16 @@ VolZmap::GetTriangles( bool bAllBlocks, INTVECTOR& nModifiedBlocks, TRIA3DEXLIST
// Caso con tre mappe
else {
nModifiedBlocks.resize( m_nNumBlock + 1) ;
vLstTria.reserve( m_nNumBlock + 1) ;
UpdateTripleMapGraphics( nModifiedBlocks) ;
UpGradeGraphics( bAllBlocks, nModifiedBlocks) ;
// Se richiesti tutti, dichiaro tutti modificati
if ( bAllBlocks) {
for ( int i = 0 ; i < m_nNumBlock + 1 ; ++ i)
nModifiedBlocks[i] = i ;
}
// Alloco lo spazio
vLstTria.reserve( m_nNumBlock + 1) ;
// Calcolo i triangoli sui blocchi
for ( int t = 0 ; t < m_nNumBlock ; ++ t) {
@@ -549,15 +550,6 @@ VolZmap::GetTriangles( bool bAllBlocks, INTVECTOR& nModifiedBlocks, TRIA3DEXLIST
for ( int t2 = 0 ; t2 < int( m_BlockSharpTria[t][t1].vCompoTria.size()) ; ++ t2) {
// ciclo sui triangoli delle componenti connesse
for ( int t3 = 0 ; t3 < int( m_BlockSharpTria[t][t1].vCompoTria[t2].size()) ; ++ t3) {
// Controllo normali
Vector3d vtN = m_BlockSharpTria[t][t1].vCompoTria[t2][t3].GetN() ;
bool bNormN = vtN.IsNormalized() ;
for ( int nV = 0 ; nV < 3 ; ++ nV) {
Vector3d vtNV = m_BlockSharpTria[t][t1].vCompoTria[t2][t3].GetVertexNorm( nV) ;
bool bNormV = vtNV.IsNormalized() ;
if ( bNormN && bNormV && vtN * vtNV < 0.7)
m_BlockSharpTria[t][t1].vCompoTria[t2][t3].SetVertexNorm( nV, vtN) ;
}
// aggiungo triangolo alla lista
vLstTria[nModifiedBlocks[t]].emplace_back( m_BlockSharpTria[t][t1].vCompoTria[t2][t3]) ;
}
@@ -567,7 +559,7 @@ VolZmap::GetTriangles( bool bAllBlocks, INTVECTOR& nModifiedBlocks, TRIA3DEXLIST
}
// Inserisco in lista i triangoli di frontiera tra feature di blocchi diversi
if ( nModifiedBlocks[nModifiedBlocks.size() - 1] >= 0) {
if ( nModifiedBlocks[m_nNumBlock] >= 0) {
vLstTria.resize( vLstTria.size() + 1) ;
int nPos = int( vLstTria.size()) - 1 ;
for ( int t = 0 ; t < int( m_InterBlockToBeFlippedSharpTria.size()) ; ++ t) {
@@ -575,22 +567,12 @@ VolZmap::GetTriangles( bool bAllBlocks, INTVECTOR& nModifiedBlocks, TRIA3DEXLIST
for ( int t2 = 0 ; t2 < int( m_InterBlockToBeFlippedSharpTria[t][t1].vCompoTria.size()) ; ++ t2) {
for ( int t3 = 0 ; t3 < int( m_InterBlockToBeFlippedSharpTria[t][t1].vCompoTria[t2].size()) ; ++ t3) {
if ( m_InterBlockToBeFlippedSharpTria[t][t1].vCompoTria[t2][t3].GetArea() > SQ_EPS_SMALL) {
// Controllo normali
Vector3d vtN = m_InterBlockToBeFlippedSharpTria[t][t1].vCompoTria[t2][t3].GetN() ;
bool bNormN = vtN.IsNormalized() ;
for ( int nV = 0 ; nV < 3 ; ++ nV) {
Vector3d vtNV = m_InterBlockToBeFlippedSharpTria[t][t1].vCompoTria[t2][t3].GetVertexNorm( nV) ;
bool bNormV = vtNV.IsNormalized() ;
if ( bNormN && bNormV && vtN * vtNV < 0.7)
m_InterBlockToBeFlippedSharpTria[t][t1].vCompoTria[t2][t3].SetVertexNorm( nV, vtN) ;
}
// aggiungo triangolo alla lista
vLstTria[nPos].emplace_back( m_InterBlockToBeFlippedSharpTria[t][t1].vCompoTria[t2][t3]) ;
}
}
}
}
m_InterBlockToBeFlippedSharpTria[t].clear() ;
}
}
}
@@ -798,20 +780,9 @@ VolZmap::AddDexelSideFace( int nPos, int nPosAdj, const Point3d& ptP, const Poin
//----------------------------------------------------------------------------
bool
VolZmap::UpGradeGraphics( bool bAllBlocks, INTVECTOR& nModifiedBlocks) const
VolZmap::UpdateTripleMapGraphics( INTVECTOR& nModifiedBlocks) const
{
// Se nessun blocco modificato, è richiesta esterna e li considero tutti modificati
bool bSomeModif = false ;
for ( int i = 0 ; i < m_nNumBlock ; ++ i) {
if ( m_BlockToUpdate[i]) {
bSomeModif = true ;
break ;
}
}
if ( ! bSomeModif)
bAllBlocks = true ;
nModifiedBlocks.resize( m_nNumBlock + 1) ;
nModifiedBlocks.resize( m_nNumBlock + 1, -1) ;
vector<VoxelContainer> vVoxContainerVec ;
vVoxContainerVec.resize( m_nNumBlock) ;
@@ -894,71 +865,100 @@ VolZmap::UpGradeGraphics( bool bAllBlocks, INTVECTOR& nModifiedBlocks) const
}
}
bool bCalcInterBlock = false ;
int nUpDatedBlockCount = 0 ;
// Calcolo i triangoli sui blocchi
int nUpdatedBlockCount = 0 ;
for ( int t = 0 ; t < m_nNumBlock ; ++ t) {
// Se il blocco deve essere processato
if ( bAllBlocks || m_BlockToUpdate[t]) {
if ( m_BlockToUpdate[t]) {
// processo ...
nModifiedBlocks[t] = nUpDatedBlockCount ;
++ nUpDatedBlockCount ;
nModifiedBlocks[t] = nUpdatedBlockCount ;
++ nUpdatedBlockCount ;
ExtMarchingCubes( int( t), vVoxContainerVec[t]) ;
}
else
nModifiedBlocks[t] = -1 ;
}
// Regolarizzo la catena
RegulateFeaturesChain( vVoxContainerVec) ;
// Costruisco i triangoli di feature
bool bCalcInterBlock = false ;
for ( int t = 0 ; t < int( m_nNumBlock) ; ++ t) {
// Se il blocco è stato processato
if ( bAllBlocks || m_BlockToUpdate[t]) {
if ( m_BlockToUpdate[t]) {
CreateSharpFeatureTriangle( t, vVoxContainerVec[t]) ;
++ m_BlockUpGradingCounter[t] ;
++ m_BlockUpdatingCounter[t] ;
// Flipping fra voxel interni
FlipEdgesII( t) ;
bCalcInterBlock = true ;
m_BlockToUpdate[t] = false ;
// Sistemo le normali ai vertici (ciclo sui voxel)
for ( int t1 = 0 ; t1 < int( m_BlockSharpTria[t].size()) ; ++ t1) {
// ciclo sulle componenti connesse del voxel
for ( int t2 = 0 ; t2 < int( m_BlockSharpTria[t][t1].vCompoTria.size()) ; ++ t2) {
// ciclo sui triangoli delle componenti connesse
for ( int t3 = 0 ; t3 < int( m_BlockSharpTria[t][t1].vCompoTria[t2].size()) ; ++ t3) {
// Controllo normali
Vector3d vtN = m_BlockSharpTria[t][t1].vCompoTria[t2][t3].GetN() ;
bool bNormN = vtN.IsNormalized() ;
for ( int nV = 0 ; nV < 3 ; ++ nV) {
Vector3d vtNV = m_BlockSharpTria[t][t1].vCompoTria[t2][t3].GetVertexNorm( nV) ;
bool bNormV = vtNV.IsNormalized() ;
if ( bNormN && bNormV && vtN * vtNV < 0.7)
m_BlockSharpTria[t][t1].vCompoTria[t2][t3].SetVertexNorm( nV, vtN) ;
}
}
}
}
}
}
// Calcolo i triangoli di frontiera tra feature di blocchi diversi
// copio i triangoli di frontiera in una matrice gemella
// di m_InterBlockTria per avere sempre a disposizione i triangoli non flippati.
// Calcolo i triangoli di frontiera tra feature di blocchi diversi (lavoro su copia e conservo gli originali)
SharpTriaMatrix InterBlockTria ;
if ( bCalcInterBlock) {
// Eseguo
m_InterBlockToBeFlippedSharpTria = m_InterBlockOriginalSharpTria ;
++ m_BlockUpGradingCounter[m_nNumBlock] ;
++ m_BlockUpdatingCounter[m_nNumBlock] ;
FlipEdgesBB() ;
// Aggiungo indice modificati
nModifiedBlocks.back() = nUpdatedBlockCount ;
// Sistemo le normali ai vertici
for ( int t = 0 ; t < int( m_InterBlockToBeFlippedSharpTria.size()) ; ++ t) {
for ( int t1 = 0 ; t1 < int( m_InterBlockToBeFlippedSharpTria[t].size()) ; ++ t1) {
for ( int t2 = 0 ; t2 < int( m_InterBlockToBeFlippedSharpTria[t][t1].vCompoTria.size()) ; ++ t2) {
for ( int t3 = 0 ; t3 < int( m_InterBlockToBeFlippedSharpTria[t][t1].vCompoTria[t2].size()) ; ++ t3) {
if ( m_InterBlockToBeFlippedSharpTria[t][t1].vCompoTria[t2][t3].GetArea() > SQ_EPS_SMALL) {
// Controllo normali
Vector3d vtN = m_InterBlockToBeFlippedSharpTria[t][t1].vCompoTria[t2][t3].GetN() ;
bool bNormN = vtN.IsNormalized() ;
for ( int nV = 0 ; nV < 3 ; ++ nV) {
Vector3d vtNV = m_InterBlockToBeFlippedSharpTria[t][t1].vCompoTria[t2][t3].GetVertexNorm( nV) ;
bool bNormV = vtNV.IsNormalized() ;
if ( bNormN && bNormV && vtN * vtNV < 0.7)
m_InterBlockToBeFlippedSharpTria[t][t1].vCompoTria[t2][t3].SetVertexNorm( nV, vtN) ;
}
}
}
}
}
}
}
// Inserisco in lista i triangoli di frontiera tra feature di blocchi diversi
if ( bCalcInterBlock)
nModifiedBlocks.back() = nUpDatedBlockCount ;
else
nModifiedBlocks.back() = - 1 ;
return true ;
}
//----------------------------------------------------------------------------
bool
VolZmap::UpGradeGraphicsSingleMap( bool bAllBlocks, INTVECTOR& nModifiedBlocks) const
VolZmap::UpdateSingleMapGraphics( INTVECTOR& nModifiedBlocks) const
{
const int MAX_DIM_CHUNK = 128 ;
int nUpDatedBlockCount = 0 ;
int nUpdatedBlockCount = 0 ;
// Ciclo sui blocchi
for ( int t = 0 ; t < m_nNumBlock ; ++ t) {
// Se il blocco deve essere aggiornato, eseguo
if ( bAllBlocks || m_BlockToUpdate[t]) {
if ( m_BlockToUpdate[t]) {
m_SingleMapTria[t].clear() ;
@@ -985,11 +985,11 @@ VolZmap::UpGradeGraphicsSingleMap( bool bAllBlocks, INTVECTOR& nModifiedBlocks)
}
}
++ m_BlockUpGradingCounter[t] ;
++ m_BlockUpdatingCounter[t] ;
nModifiedBlocks[t] = nUpDatedBlockCount ;
nModifiedBlocks[t] = nUpdatedBlockCount ;
++ nUpDatedBlockCount ;
++ nUpdatedBlockCount ;
m_BlockToUpdate[t] = false ;
}