EgtGeomKernel 1.9b1 :

- in Zmap N_DEXVOXRATIO riportato a 1
- in Zmap migliorie a visualizzazione
- in Zmap migliorate GetDepth e AvoidBox.
This commit is contained in:
Dario Sassi
2018-02-03 18:57:18 +00:00
parent f36c453415
commit fdef0bb7a3
5 changed files with 271 additions and 380 deletions
+188 -272
View File
@@ -2062,12 +2062,14 @@ VolZmap::ExtMarchingCubes( int nBlock, TRIA3DEXLIST& lstTria, TriHolder& triHold
CurrentTriangle.SetGrade( 1) ;
else
CurrentTriangle.SetGrade( 0) ;
// Valido il triangolo
CurrentTriangle.Validate( true) ;
// Setto le normali a ogni vertice
CurrentTriangle.SetVertexNorm( 0, CurrentTriangle.GetN()) ;
CurrentTriangle.SetVertexNorm( 1, CompoVert[nCompCount - 1][nj].vtNorm) ;
CurrentTriangle.SetVertexNorm( 2, CompoVert[nCompCount - 1][ni].vtNorm) ;
if ( CurrentTriangle.GetVertexNorm( 1) * CurrentTriangle.GetVertexNorm( 2) > 0)
CurrentTriangle.SetVertexNorm( 0, 0.5 * ( CurrentTriangle.GetVertexNorm( 1) +
CurrentTriangle.GetVertexNorm( 2))) ;
// Valido il triangolo
CurrentTriangle.Validate( true) ;
// Aggiungo triangolo al vettore temporaneo
triContainer.emplace_back( CurrentTriangle) ;
}
@@ -2155,6 +2157,12 @@ VolZmap::ExtMarchingCubes( int nBlock, TRIA3DEXLIST& lstTria, TriHolder& triHold
CurrentTriangle.SetAttrib( 2, CompoVert[nCompCount - 1][ni].nToolFlag) ;
CurrentTriangle.SetVertexNorm( 1, CompoVert[nCompCount - 1][nj].vtNorm) ;
CurrentTriangle.SetVertexNorm( 2, CompoVert[nCompCount - 1][ni].vtNorm) ;
if ( CurrentTriangle.GetVertexNorm( 1) * CurrentTriangle.GetVertexNorm( 2) > 0)
CurrentTriangle.SetVertexNorm( 0, 0.5 * ( CurrentTriangle.GetVertexNorm( 1) +
CurrentTriangle.GetVertexNorm( 2))) ;
// Valido il triangolo
CurrentTriangle.Validate( true) ;
// Assegno i colori
if ( CurrentTriangle.GetAttrib( 1) < 0 ||
CurrentTriangle.GetAttrib( 2) < 0)
CurrentTriangle.SetGrade( - 1) ;
@@ -2163,7 +2171,6 @@ VolZmap::ExtMarchingCubes( int nBlock, TRIA3DEXLIST& lstTria, TriHolder& triHold
CurrentTriangle.SetGrade( 1) ;
else
CurrentTriangle.SetGrade( 0) ;
CurrentTriangle.Validate( true) ;
// Aggiungo triangolo al vettore temporaneo
triContainer.emplace_back( CurrentTriangle) ;
}
@@ -2232,13 +2239,18 @@ VolZmap::ExtMarchingCubes( int nBlock, TRIA3DEXLIST& lstTria, TriHolder& triHold
// Costruisco triangoli di prova
for ( int ni = 0 ; ni < nVertComp[nCompCount - 1] ; ++ ni) {
int nj = ( ni + 1 < nVertComp[nCompCount - 1]) ? ni + 1 : 0 ;
// Il triangolo è pronto
// Il triangolo è pronto
Triangle3dEx CurrentTriangle ;
CurrentTriangle.Set( ptSol, CompoVert[nCompCount - 1][nj].ptInt, CompoVert[nCompCount - 1][ni].ptInt) ;
CurrentTriangle.SetAttrib( 1, CompoVert[nCompCount - 1][nj].nToolFlag) ;
CurrentTriangle.SetAttrib( 2, CompoVert[nCompCount - 1][ni].nToolFlag) ;
CurrentTriangle.SetVertexNorm( 1, CompoVert[nCompCount - 1][nj].vtNorm) ;
CurrentTriangle.SetVertexNorm( 2, CompoVert[nCompCount - 1][ni].vtNorm) ;
if ( CurrentTriangle.GetVertexNorm( 1) * CurrentTriangle.GetVertexNorm( 2) > 0)
CurrentTriangle.SetVertexNorm( 0, 0.5 * ( CurrentTriangle.GetVertexNorm( 1) +
CurrentTriangle.GetVertexNorm( 2))) ;
CurrentTriangle.Validate( true) ;
// Assegno i colori
if ( CurrentTriangle.GetAttrib( 1) < 0 ||
CurrentTriangle.GetAttrib( 2) < 0)
CurrentTriangle.SetGrade( - 1) ;
@@ -2247,8 +2259,7 @@ VolZmap::ExtMarchingCubes( int nBlock, TRIA3DEXLIST& lstTria, TriHolder& triHold
CurrentTriangle.SetGrade( 1) ;
else
CurrentTriangle.SetGrade( 0) ;
CurrentTriangle.Validate( true) ;
// Aggiungo triangolo al vettore temporaneo
// Aggiungo triangolo al vettore temporaneo
triContainer.emplace_back( CurrentTriangle) ;
}
}
@@ -2346,11 +2357,16 @@ VolZmap::ExtMarchingCubes( int nBlock, TRIA3DEXLIST& lstTria, TriHolder& triHold
// Aggiungo una componente per il vettore
// dei triangoli della componente connessa.
triHold[nCurrent].vCompoTria.resize( nNewFeatureNum) ;
triHold[nCurrent].vbFlipped.resize( nNewFeatureNum) ;
for ( int ni = 0 ; ni < int( vInnerTriaTemp.size()) ; ++ ni) {
// Riporto le coordinate nel sistema in cui è immerso lo Zmap
vInnerTriaTemp[ni].ToGlob( m_MapFrame) ;
triHold[nCurrent].vCompoTria[nOldFeatureNum].emplace_back( vInnerTriaTemp[ni]) ;
}
triHold[nCurrent].vbFlipped[nOldFeatureNum].resize( vInnerTriaTemp.size()) ;
for ( int ni = 0 ; ni < int( vInnerTriaTemp.size()) ; ++ ni) {
triHold[nCurrent].vbFlipped[nOldFeatureNum][ni] = false ;
}
}
// Triangoli di frontiera
@@ -2585,182 +2601,134 @@ VolZmap::FlipEdgesII( TriHolder& TriHold) const
{
// Numero di voxel in cui si presentano sharp feature
int nVoxelNum = int( TriHold.size()) ;
// Ciclo sui voxel con sharp feature
for ( int n1 = 0 ; n1 < nVoxelNum ; ++ n1) {
for ( int n2 = n1 ; n2 < nVoxelNum ; ++ n2) {
// Se i voxel sono adiacenti proseguo
if ( abs( TriHold[n2].i - TriHold[n1].i) <= 1 ||
abs( TriHold[n2].j - TriHold[n1].j) <= 1 ||
abs( TriHold[n2].k - TriHold[n1].k) <= 1 ) {
// Numero delle componenti connesse nei due voxel
int nNumCompo1 = int( TriHold[n1].ptCompoVert.size()) ;
int nNumCompo2 = int( TriHold[n2].ptCompoVert.size()) ;
// Ciclo sulle componenti
int nCompo1 = 0 ;
for ( ; nCompo1 < nNumCompo1 ; ++ nCompo1) {
int nCompo2 = ( n1 == n2 ? nCompo1 + 1 : 0) ;
for ( ; nCompo2 < nNumCompo2 ; ++ nCompo2) {
// Numero di triangoli per le componenti connesse
int nTriNum1 = int( TriHold[n1].vCompoTria[nCompo1].size()) ;
int nTriNum2 = int( TriHold[n2].vCompoTria[nCompo2].size()) ;
for ( int nTri1 = 0 ; nTri1 < nTriNum1 ; ++ nTri1) {
bool bModified = false ;
for ( int nTri2 = 0 ; nTri2 < nTriNum2 ; ++ nTri2) {
INTVECTOR SharedIndex ;
for ( int nVert1 = 0 ; nVert1 < 3 ; ++ nVert1) {
for ( int nVert2 = 0 ; nVert2 < 3 ; ++ nVert2) {
Point3d ptP1 = TriHold[n1].vCompoTria[nCompo1][nTri1].GetP( nVert1) ;
Point3d ptP2 = TriHold[n2].vCompoTria[nCompo2][nTri2].GetP( nVert2) ;
if ( AreSamePointEpsilon( ptP1, ptP2, EPS_ZERO)) {
Point3d ptVert1 = TriHold[n1].ptCompoVert[nCompo1] ;
Point3d ptVert2 = TriHold[n2].ptCompoVert[nCompo2] ;
if ( ! ( AreSamePointEpsilon( ptP1, ptVert1, EPS_ZERO) ||
AreSamePointEpsilon( ptP2, ptVert2, EPS_ZERO))) {
SharedIndex.emplace_back( nVert1) ;
SharedIndex.emplace_back( nVert2) ;
}
// Punti che devono essere in comune fra i due triangoli
Point3d ptP11 = TriHold[n1].vCompoTria[nCompo1][nTri1].GetP( 1) ;
Point3d ptP12 = TriHold[n1].vCompoTria[nCompo1][nTri1].GetP( 2) ;
Point3d ptP21 = TriHold[n2].vCompoTria[nCompo2][nTri2].GetP( 1) ;
Point3d ptP22 = TriHold[n2].vCompoTria[nCompo2][nTri2].GetP( 2) ;
// I triangoli sono da flippare
if ( AreSamePointEpsilon( ptP11, ptP22, EPS_ZERO) &&
AreSamePointEpsilon( ptP12, ptP21, EPS_ZERO)) {
// Assegno l'array dei punti di contorno
Point3d vPnt[4] ;
vPnt[0] = TriHold[n1].vCompoTria[nCompo1][nTri1].GetP( 1) ;
vPnt[1] = TriHold[n1].ptCompoVert[nCompo1] ;
vPnt[2] = TriHold[n1].vCompoTria[nCompo1][nTri1].GetP( 2) ;
vPnt[3] = TriHold[n2].ptCompoVert[nCompo2] ;
// Valuto se i triangoli giacciono su un piano
PolygonPlane Polygon ;
for ( int i = 0 ; i < 4 ; ++ i)
Polygon.AddPoint( vPnt[i]) ;
Plane3d plPlane ;
bool bOnPlane = Polygon.GetPlane( plPlane) ;
for ( int i = 0 ; i < 4 && bOnPlane ; ++ i)
bOnPlane = PointInPlaneApprox( vPnt[i], plPlane) ;
// Se sono su un piano controllo se avviene inversione
bool bInv = false ;
if ( bOnPlane) {
Triangle3d trT1 = TriHold[n1].vCompoTria[nCompo1][nTri1] ;
Triangle3d trT2 = TriHold[n2].vCompoTria[nCompo2][nTri2] ;
int nVert1, nVert2 ;
// Determino gli indici dei punti sharp-feature
for ( int nP = 0 ; nP < 3 ; ++ nP) {
if ( nP != 1 && nP != 2)
nVert1 = nP ;
if ( nP != 2 && nP != 1)
nVert2 = nP ;
}
if ( SharedIndex.size() > 2)
break ;
trT1.SetP( 1, trT2.GetP( nVert2)) ;
trT2.SetP( 1, trT1.GetP( nVert1)) ;
trT1.Validate( true) ;
trT2.Validate( true) ;
bInv = ( trT1.GetN() * trT2.GetN() < 0) ;
}
if ( SharedIndex.size() > 2)
// Se non vi è inversione eseguo il flipping
if ( ! bInv) {
// Vertice condiviso fra nTri1 e quello del suo fan
int nCol1 = TriHold[n1].vCompoTria[nCompo1][nTri1].GetAttrib( 2) ;
int nCol2 = TriHold[n2].vCompoTria[nCompo2][nTri2].GetAttrib( 2) ;
// Modifico i punti e gli indici
TriHold[n1].vCompoTria[nCompo1][nTri1].SetP( 1, TriHold[n2].ptCompoVert[nCompo2]) ;
TriHold[n2].vCompoTria[nCompo2][nTri2].SetP( 1, TriHold[n1].ptCompoVert[nCompo1]) ;
TriHold[n1].vCompoTria[nCompo1][nTri1].SetGrade( nCol1) ;
TriHold[n2].vCompoTria[nCompo2][nTri2].SetGrade( nCol2) ;
// Setto le normali
Vector3d vtN1 = TriHold[n1].vCompoTria[nCompo1][nTri1].GetVertexNorm( 2) ;
Vector3d vtN2 = TriHold[n2].vCompoTria[nCompo2][nTri2].GetVertexNorm( 2) ;
TriHold[n1].vCompoTria[nCompo1][nTri1].SetVertexNorm( 0, vtN1) ;
TriHold[n1].vCompoTria[nCompo1][nTri1].SetVertexNorm( 1, vtN1) ;
TriHold[n2].vCompoTria[nCompo2][nTri2].SetVertexNorm( 0, vtN2) ;
TriHold[n2].vCompoTria[nCompo2][nTri2].SetVertexNorm( 1, vtN2) ;
// Valido i triangoli
TriHold[n1].vCompoTria[nCompo1][nTri1].Validate( true) ;
TriHold[n2].vCompoTria[nCompo2][nTri2].Validate( true) ;
// Avvenuto flipping
bModified = true ;
break ;
}
// Si deve operare la modifica dei triangoli
if ( SharedIndex.size() > 2) {
// Verifico che i due lati adiacenti siano controversi
int nProd = ( SharedIndex[2] - SharedIndex[0]) * ( SharedIndex[3] - SharedIndex[1]) ;
if ( nProd != 1 && nProd != - 2 && nProd != 4 && nProd != 0) {
// Assegno l'array dei punti di contorno
Point3d vPnt[4] ;
vPnt[0] = TriHold[n1].vCompoTria[nCompo1][nTri1].GetP( SharedIndex[0]) ;
vPnt[1] = TriHold[n1].ptCompoVert[nCompo1] ;
vPnt[2] = TriHold[n1].vCompoTria[nCompo1][nTri1].GetP( SharedIndex[2]) ;
vPnt[3] = TriHold[n2].ptCompoVert[nCompo2] ;
// Valuto se i triangoli giacciono su un piano
PolygonPlane Polygon ;
for ( int i = 0 ; i < 4 ; ++ i)
Polygon.AddPoint( vPnt[i]) ;
Plane3d plPlane ;
bool bOnPlane = Polygon.GetPlane( plPlane) ;
for ( int i = 0 ; i < 4 && bOnPlane ; ++ i)
bOnPlane = PointInPlaneApprox( vPnt[i], plPlane) ;
// Se sono su un piano controllo se avviene inversione
bool bInv = false ;
if ( bOnPlane) {
Triangle3d trT1 = TriHold[n1].vCompoTria[nCompo1][nTri1] ;
Triangle3d trT2 = TriHold[n2].vCompoTria[nCompo2][nTri2] ;
int nVert1, nVert2 ;
// Determino gli indici dei punti sharp-feature
for ( int nP = 0 ; nP < 3 ; ++ nP) {
if ( nP != SharedIndex[0] && nP != SharedIndex[2])
nVert1 = nP ;
if ( nP != SharedIndex[1] && nP != SharedIndex[3])
nVert2 = nP ;
}
trT1.SetP( SharedIndex[0], trT2.GetP( nVert2)) ;
trT2.SetP( SharedIndex[3], trT1.GetP( nVert1)) ;
trT1.Validate( true) ;
trT2.Validate( true) ;
bInv = ( trT1.GetN() * trT2.GetN() < 0) ;
}
else {
// In questo caso i due triangoli sono necessariamente su un piano,
// quindi hanno normali concordi. Per ognuno dei due cerco nei rispettivi
// ventagli un triangolo con normale concorde con colore definito. Assegno
// tale colore ai triangoli.
int nPrv1 = ( nTri1 != 0 ? nTri1 : int( TriHold[n1].vCompoTria[nCompo1].size())) - 1 ;
int nNxt1 = ( nTri1 != TriHold[n1].vCompoTria[nCompo1].size() - 1 ? nTri1 + 1 : 0) ;
int nPrv2 = ( nTri2 != 0 ? nTri2 : int( TriHold[n2].vCompoTria[nCompo2].size())) - 1 ;
int nNxt2 = ( nTri2 != TriHold[n2].vCompoTria[nCompo2].size() - 1 ? nTri2 + 1 : 0) ;
// Prodotti scalari del primo triangolo con i suoi adiacenti
double dDotP1 = TriHold[n1].vCompoTria[nCompo1][nTri1].GetN() *
TriHold[n1].vCompoTria[nCompo1][nPrv1].GetN() ;
double dDotN1 = TriHold[n1].vCompoTria[nCompo1][nTri1].GetN() *
TriHold[n1].vCompoTria[nCompo1][nNxt1].GetN() ;
// Prendo il maggiore fra i due, e comunque maggiore di 0.5
int nAdjT1 = - 1 ;
if ( dDotP1 > 0.5 || dDotN1 > 0.5)
nAdjT1 = ( dDotP1 > dDotN1 ? nPrv1 : nNxt1) ;
// Prodotti scalari del primo triangolo con i suoi adiacenti
double dDotP2 = TriHold[n2].vCompoTria[nCompo2][nTri2].GetN() *
TriHold[n2].vCompoTria[nCompo2][nPrv2].GetN() ;
double dDotN2 = TriHold[n2].vCompoTria[nCompo2][nTri2].GetN() *
TriHold[n2].vCompoTria[nCompo2][nNxt2].GetN() ;
// Prendo il maggiore fra i due, e comunque maggiore di 0.5
int nAdjT2 = - 1 ;
if ( dDotP2 > 0.5 || dDotN2 > 0.5)
nAdjT2 = ( dDotP2 > dDotN2 ? nPrv2 : nNxt2) ;
// Se abbiamo trovato triangoli adiacenti validi
// assegnamo il colorea quelli correnti.
if ( nAdjT1 != - 1) {
int nCol = TriHold[n1].vCompoTria[nCompo1][nAdjT1].GetGrade() ;
TriHold[n1].vCompoTria[nCompo1][nTri1].SetGrade( nCol) ;
TriHold[n2].vCompoTria[nCompo2][nTri2].SetGrade( nCol) ;
}
// Se non vi è inversione eseguo il flipping
if ( ! bInv) {
// Vertice condiviso fra nTri1 e quello del suo fan
int nCol1 = TriHold[n1].vCompoTria[nCompo1][nTri1].GetAttrib( SharedIndex[2]) ;
int nCol2 = TriHold[n2].vCompoTria[nCompo2][nTri2].GetAttrib( SharedIndex[1]) ;
// Modifico i punti e gli indici
TriHold[n1].vCompoTria[nCompo1][nTri1].SetP( SharedIndex[0],
TriHold[n2].ptCompoVert[nCompo2]) ;
TriHold[n2].vCompoTria[nCompo2][nTri2].SetP( SharedIndex[3],
TriHold[n1].ptCompoVert[nCompo1]) ;
TriHold[n1].vCompoTria[nCompo1][nTri1].SetGrade( nCol1) ;
TriHold[n2].vCompoTria[nCompo2][nTri2].SetGrade( nCol2) ;
// Valido i triangoli
TriHold[n1].vCompoTria[nCompo1][nTri1].Validate( true) ;
TriHold[n2].vCompoTria[nCompo2][nTri2].Validate( true) ;
// Setto le normali a ogni vertice
Vector3d vtNorm1 = TriHold[n1].vCompoTria[nCompo1][nTri1].GetVertexNorm( SharedIndex[2]) ;
Vector3d vtNorm2 = TriHold[n2].vCompoTria[nCompo2][nTri2].GetVertexNorm( SharedIndex[1]) ;
int nFeatureIndex1 = 0 ;
int nFeatureIndex2 = 0 ;
for ( ; nFeatureIndex1 < 3 && nFeatureIndex2 < 3 ; ) {
if ( ! ( nFeatureIndex1 != SharedIndex[0] &&
nFeatureIndex1 != SharedIndex[2]))
++ nFeatureIndex1 ;
else if ( ! ( nFeatureIndex2 != SharedIndex[1] &&
nFeatureIndex2 != SharedIndex[3]))
++ nFeatureIndex2 ;
else
break ;
}
TriHold[n1].vCompoTria[nCompo1][nTri1].SetVertexNorm( SharedIndex[0], vtNorm1) ;
TriHold[n1].vCompoTria[nCompo1][nTri1].SetVertexNorm( nFeatureIndex1, vtNorm1) ;
TriHold[n2].vCompoTria[nCompo2][nTri2].SetVertexNorm( SharedIndex[3], vtNorm2) ;
TriHold[n2].vCompoTria[nCompo2][nTri2].SetVertexNorm( nFeatureIndex2, vtNorm2) ;
bModified = true ;
break ;
}
else {
// In questo caso i due triangoli sono necessariamente su un piano,
// quindi hanno normali concordi. Per ognuno dei due cerco nei rispettivi
// ventagli un triangolo con normale concorde con colore definito. Assegno
// tale colore ai triangoli.
int nPrv1 = ( nTri1 != 0 ? nTri1 : int( TriHold[n1].vCompoTria[nCompo1].size())) - 1 ;
int nNxt1 = ( nTri1 != TriHold[n1].vCompoTria[nCompo1].size() - 1 ? nTri1 + 1 : 0) ;
int nPrv2 = ( nTri2 != 0 ? nTri2 : int( TriHold[n2].vCompoTria[nCompo2].size())) - 1 ;
int nNxt2 = ( nTri2 != TriHold[n2].vCompoTria[nCompo2].size() - 1 ? nTri2 + 1 : 0) ;
double dDotP1 = TriHold[n1].vCompoTria[nCompo1][nTri1].GetN() *
TriHold[n1].vCompoTria[nCompo1][nPrv1].GetN() ;
double dDotN1 = TriHold[n1].vCompoTria[nCompo1][nTri1].GetN() *
TriHold[n1].vCompoTria[nCompo1][nNxt1].GetN() ;
int nAdjT1 = - 1 ;
if ( dDotP1 > 0.5 || dDotN1 > 0.5)
nAdjT1 = ( dDotP1 > dDotN1 ? nPrv1 : nNxt1) ;
double dDotP2 = TriHold[n2].vCompoTria[nCompo2][nTri2].GetN() *
TriHold[n2].vCompoTria[nCompo2][nPrv2].GetN() ;
double dDotN2 = TriHold[n2].vCompoTria[nCompo2][nTri2].GetN() *
TriHold[n2].vCompoTria[nCompo2][nNxt2].GetN() ;
int nAdjT2 = - 1 ;
if ( dDotP2 > 0.5 || dDotN2 > 0.5)
nAdjT2 = ( dDotP2 > dDotN2 ? nPrv2 : nNxt2) ;
if ( nAdjT1 != - 1) {
int nCol = TriHold[n1].vCompoTria[nCompo1][nAdjT1].GetGrade() ;
TriHold[n1].vCompoTria[nCompo1][nTri1].SetGrade( nCol) ;
TriHold[n2].vCompoTria[nCompo2][nTri2].SetGrade( nCol) ;
}
else if ( nAdjT2 != - 1) {
int nCol = TriHold[n2].vCompoTria[nCompo2][nAdjT2].GetGrade() ;
TriHold[n1].vCompoTria[nCompo1][nTri1].SetGrade( nCol) ;
TriHold[n2].vCompoTria[nCompo2][nTri2].SetGrade( nCol) ;
}
}
}
}
}
else if ( nAdjT2 != - 1) {
int nCol = TriHold[n2].vCompoTria[nCompo2][nAdjT2].GetGrade() ;
TriHold[n1].vCompoTria[nCompo1][nTri1].SetGrade( nCol) ;
TriHold[n2].vCompoTria[nCompo2][nTri2].SetGrade( nCol) ;
}
}
}
}
if ( bModified)
break ;
}
@@ -2778,28 +2746,21 @@ VolZmap::FlipEdgesBB( TriaMatrix& InterTria) const
{
// Numero di blocchi
size_t nBlocksNum = InterTria.size() ;
// ciclo sui blocchi
for ( size_t tFB = 0 ; tFB < nBlocksNum ; ++ tFB) {
int nFBijk[3] ;
GetBlockIJKFromN( int( tFB), nFBijk) ;
for ( size_t tLB = tFB ; tLB < nBlocksNum ; ++ tLB) {
int nLBijk[3] ;
GetBlockIJKFromN( int( tLB), nLBijk) ;
// Se i blocchi non sono adiacenti salto l'iterazione
if ( ! ( abs( nFBijk[0] - nLBijk[0]) <= 1 &&
abs( nFBijk[1] - nLBijk[1]) <= 1 &&
abs( nFBijk[2] - nLBijk[2]) <= 1))
continue ;
// Numero di voxel nei blocchi correnti
size_t nVoxelNumFB = InterTria[tFB].size() ;
size_t nVoxelNumLB = InterTria[tLB].size() ;
// Ciclo sui voxel dei due blocchi
for ( size_t tVFB = 0 ; tVFB < nVoxelNumFB ; ++ tVFB) {
for ( size_t tVLB = 0 ; tVLB < nVoxelNumLB ; ++ tVLB) {
@@ -2817,118 +2778,73 @@ VolZmap::FlipEdgesBB( TriaMatrix& InterTria) const
// Numero di triangoli delle componenti connesse
size_t nTriFBNum = InterTria[tFB][tVFB].vCompoTria[tCmpF].size() ;
size_t nTriLBNum = InterTria[tLB][tVLB].vCompoTria[tCmpL].size() ;
// Ciclo sui triangoli
for ( size_t tTriFB = 0 ; tTriFB < nTriFBNum ; ++ tTriFB) {
bool bModified = false ;
for ( size_t tTriLB = 0 ; tTriLB < nTriLBNum ; ++ tTriLB) {
INTVECTOR SharedIndex ;
for ( int nVertF = 0 ; nVertF < 3 ; ++ nVertF) {
for ( int nVertL = 0 ; nVertL < 3 ; ++ nVertL) {
Point3d ptPF = InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB].GetP( nVertF) ;
Point3d ptPL = InterTria[tLB][tVLB].vCompoTria[tCmpL][tTriLB].GetP( nVertL) ;
if ( AreSamePointEpsilon( ptPF, ptPL, EPS_ZERO)) {
Point3d ptVertF = InterTria[tFB][tVFB].ptCompoVert[tCmpF] ;
Point3d ptVertL = InterTria[tLB][tVLB].ptCompoVert[tCmpL] ;
if ( ! ( AreSamePointEpsilon( ptPF, ptVertF, EPS_ZERO) ||
AreSamePointEpsilon( ptPL, ptVertL, EPS_ZERO))) {
SharedIndex.emplace_back( nVertF) ;
SharedIndex.emplace_back( nVertL) ;
}
}
if ( SharedIndex.size() > 2)
break ;
}
if ( SharedIndex.size() > 2)
break ;
}
// Punti che devono essere in comune fra i due triangoli
Point3d ptPF1 = InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB].GetP( 1) ;
Point3d ptPF2 = InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB].GetP( 2) ;
Point3d ptPL1 = InterTria[tLB][tVLB].vCompoTria[tCmpL][tTriLB].GetP( 1) ;
Point3d ptPL2 = InterTria[tLB][tVLB].vCompoTria[tCmpL][tTriLB].GetP( 2) ;
// Si deve operare la modifica dei triangoli
if ( SharedIndex.size() > 2) {
// Verifico che i due lati adiacenti siano controversi
int nProd = ( SharedIndex[2] - SharedIndex[0]) * ( SharedIndex[3] - SharedIndex[1]) ;
if ( nProd != 1 && nProd != - 2 && nProd != 4 && nProd != 0) {
// Assegno l'array dei punti di contorno
Point3d vPnt[4] ;
vPnt[0] = InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB].GetP( SharedIndex[0]) ;
vPnt[1] = InterTria[tFB][tVFB].ptCompoVert[tCmpF] ;
vPnt[2] = InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB].GetP( SharedIndex[2]) ;
vPnt[3] = InterTria[tLB][tVLB].ptCompoVert[tCmpL] ;
// Valuto se i triangoli giacciono su un piano
PolygonPlane Polygon ;
for ( int i = 0 ; i < 4 ; ++ i)
Polygon.AddPoint( vPnt[i]) ;
Plane3d plPlane ;
bool bOnPlane = Polygon.GetPlane( plPlane) ;
for ( int i = 0 ; i < 4 && bOnPlane ; ++ i)
bOnPlane = PointInPlaneApprox( vPnt[i], plPlane) ;
// Se sono su un piano controllo se avviene inversione
bool bInv = false ;
if ( bOnPlane) {
Triangle3dEx trTF = InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB] ;
Triangle3dEx trTL = InterTria[tLB][tVLB].vCompoTria[tCmpL][tTriLB] ;
int nVertF, nVertL ;
// Determino gli indici dei punti sharp-feature
for ( int nP = 0 ; nP < 3 ; ++ nP) {
if ( nP != SharedIndex[0] && nP != SharedIndex[2])
nVertF = nP ;
if ( nP != SharedIndex[1] && nP != SharedIndex[3])
nVertL = nP ;
}
trTF.SetP( SharedIndex[0], trTL.GetP( nVertL)) ;
trTF.Validate( true) ;
trTL.SetP( SharedIndex[3], trTF.GetP( nVertF)) ;
trTL.Validate( true) ;
bInv = ( trTF.GetN() * trTL.GetN() < 0) ;
}
// Se non vi è inversione eseguo il flipping
if ( ! bInv) {
// Vertice condiviso fra nTri1 e quello del suo fan
int nColF = InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB].GetAttrib( SharedIndex[2]) ;
int nColL = InterTria[tLB][tVLB].vCompoTria[tCmpL][tTriLB].GetAttrib( SharedIndex[1]) ;
// modifico punti e colori
InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB].SetP( SharedIndex[0],
InterTria[tLB][tVLB].ptCompoVert[tCmpL]) ;
InterTria[tLB][tVLB].vCompoTria[tCmpL][tTriLB].SetP( SharedIndex[3],
InterTria[tFB][tVFB].ptCompoVert[tCmpF]) ;
InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB].SetGrade( nColF) ;
InterTria[tLB][tVLB].vCompoTria[tCmpL][tTriLB].SetGrade( nColL) ;
// Valido i triangoli
InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB].Validate( true) ;
InterTria[tLB][tVLB].vCompoTria[tCmpL][tTriLB].Validate( true) ;
// Setto le normali a ogni vertice
Vector3d vtNormF = InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB].GetVertexNorm( SharedIndex[2]) ;
Vector3d vtNormL = InterTria[tLB][tVLB].vCompoTria[tCmpL][tTriLB].GetVertexNorm( SharedIndex[1]) ;
int nFeatureIndexF = 0 ;
int nFeatureIndexL = 0 ;
for ( ; nFeatureIndexF < 3 && nFeatureIndexL < 3 ; ) {
if ( ! ( nFeatureIndexF != SharedIndex[0] &&
nFeatureIndexF != SharedIndex[2]))
++ nFeatureIndexF ;
else if ( ! ( nFeatureIndexL != SharedIndex[1] &&
nFeatureIndexL != SharedIndex[3]))
++ nFeatureIndexL ;
else
break ;
}
InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB].SetVertexNorm( SharedIndex[0], vtNormF) ;
InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB].SetVertexNorm( nFeatureIndexF, vtNormF) ;
InterTria[tLB][tVLB].vCompoTria[tCmpL][tTriLB].SetVertexNorm( SharedIndex[3], vtNormL) ;
InterTria[tLB][tVLB].vCompoTria[tCmpL][tTriLB].SetVertexNorm( nFeatureIndexL, vtNormL) ;
bModified = true ;
break ;
if ( AreSamePointEpsilon( ptPF1, ptPL2, EPS_ZERO) &&
AreSamePointEpsilon( ptPF2, ptPL1, EPS_ZERO)) {
// Assegno l'array dei punti di contorno
Point3d vPnt[4] ;
vPnt[0] = InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB].GetP( 1) ;
vPnt[1] = InterTria[tFB][tVFB].ptCompoVert[tCmpF] ;
vPnt[2] = InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB].GetP( 2) ;
vPnt[3] = InterTria[tLB][tVLB].ptCompoVert[tCmpL] ;
// Valuto se i triangoli giacciono su un piano
PolygonPlane Polygon ;
for ( int i = 0 ; i < 4 ; ++ i)
Polygon.AddPoint( vPnt[i]) ;
Plane3d plPlane ;
bool bOnPlane = Polygon.GetPlane( plPlane) ;
for ( int i = 0 ; i < 4 && bOnPlane ; ++ i)
bOnPlane = PointInPlaneApprox( vPnt[i], plPlane) ;
// Se sono su un piano controllo se avviene inversione
bool bInv = false ;
if ( bOnPlane) {
Triangle3dEx trTF = InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB] ;
Triangle3dEx trTL = InterTria[tLB][tVLB].vCompoTria[tCmpL][tTriLB] ;
int nVertF, nVertL ;
// Determino gli indici dei punti sharp-feature
for ( int nP = 0 ; nP < 3 ; ++ nP) {
if ( nP != 1 && nP != 2)
nVertF = nP ;
if ( nP != 2 && nP != 1)
nVertL = nP ;
}
trTF.SetP( 1, trTL.GetP( nVertL)) ;
trTF.Validate( true) ;
trTL.SetP( 1, trTF.GetP( nVertF)) ;
trTL.Validate( true) ;
bInv = ( trTF.GetN() * trTL.GetN() < 0) ;
}
// Se non vi è inversione eseguo il flipping
if ( ! bInv) {
// Vertice condiviso fra nTri1 e quello del suo fan
int nColF = InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB].GetAttrib( 2) ;
int nColL = InterTria[tLB][tVLB].vCompoTria[tCmpL][tTriLB].GetAttrib( 2) ;
// modifico punti e colori
InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB].SetP( 1, InterTria[tLB][tVLB].ptCompoVert[tCmpL]) ;
InterTria[tLB][tVLB].vCompoTria[tCmpL][tTriLB].SetP( 1, InterTria[tFB][tVFB].ptCompoVert[tCmpF]) ;
InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB].SetGrade( nColF) ;
InterTria[tLB][tVLB].vCompoTria[tCmpL][tTriLB].SetGrade( nColL) ;
// Valido i triangoli
InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB].Validate( true) ;
InterTria[tLB][tVLB].vCompoTria[tCmpL][tTriLB].Validate( true) ;
// Setto le normali a ogni vertice
Vector3d vtNormF = InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB].GetVertexNorm( 2) ;
Vector3d vtNormL = InterTria[tLB][tVLB].vCompoTria[tCmpL][tTriLB].GetVertexNorm( 2) ;
InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB].SetVertexNorm( 1, vtNormF) ;
InterTria[tFB][tVFB].vCompoTria[tCmpF][tTriFB].SetVertexNorm( 0, vtNormF) ;
InterTria[tLB][tVLB].vCompoTria[tCmpL][tTriLB].SetVertexNorm( 1, vtNormL) ;
InterTria[tLB][tVLB].vCompoTria[tCmpL][tTriLB].SetVertexNorm( 0, vtNormL) ;
bModified = true ;
break ;
}
}
}