From 3babdc7cd11e79400e5153d35a497efc14240927 Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Wed, 24 Jan 2018 11:39:11 +0000 Subject: [PATCH] EgtGeomKernel : - modifiche a Zmap per normali smooth. --- VolZmapGraphics.cpp | 60 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 6 deletions(-) diff --git a/VolZmapGraphics.cpp b/VolZmapGraphics.cpp index 7922958..42d43b5 100644 --- a/VolZmapGraphics.cpp +++ b/VolZmapGraphics.cpp @@ -1425,7 +1425,7 @@ VolZmap::ProcessCube( int nVoxI, int nVoxJ, int nVoxK, TRIA3DEXLIST& lstTria, Tr // Il triangolo è pronto Triangle3d CurrentTriangle ; CurrentTriangle.Set( ptSol, CompoVert[nCompCount - 1][nj].ptInt, CompoVert[nCompCount - 1][ni].ptInt) ; - CurrentTriangle.Validate( true) ; + CurrentTriangle.Validate( true) ; // Aggiungo triangolo al vettore temporaneo triContainer.emplace_back( CurrentTriangle) ; } @@ -1660,7 +1660,7 @@ VolZmap::ExtMarchingCubes( int nBlock, TRIA3DEXLIST& lstTria, TriHolder& triHold for ( int i = nLimits[0] ; i < nLimits[1] ; ++ i) { for ( int j = nLimits[2] ; j < nLimits[3] ; ++ j) { for ( int k = nLimits[4] ; k < nLimits[5] ; ++ k) { - + // Classificazione dei vertici: interni o esterni al materiale int nIndex = CalcIndex( i, j, k) ; @@ -2222,6 +2222,9 @@ VolZmap::ExtMarchingCubes( int nBlock, TRIA3DEXLIST& lstTria, TriHolder& triHold else CurrentTriangle.SetGrade( 0) ; CurrentTriangle.Validate( true) ; + CurrentTriangle.SetVertexNorm( 0, V_NULL) ; + CurrentTriangle.SetVertexNorm( 1, V_NULL) ; + CurrentTriangle.SetVertexNorm( 2, V_NULL) ; // Aggiungo triangolo al vettore temporaneo triContainer.emplace_back( CurrentTriangle) ; } @@ -2305,6 +2308,9 @@ VolZmap::ExtMarchingCubes( int nBlock, TRIA3DEXLIST& lstTria, TriHolder& triHold else CurrentTriangle.SetGrade( 0) ; CurrentTriangle.Validate( true) ; + CurrentTriangle.SetVertexNorm( 0, V_NULL) ; + CurrentTriangle.SetVertexNorm( 1, V_NULL) ; + CurrentTriangle.SetVertexNorm( 2, V_NULL) ; // Aggiungo triangolo al vettore temporaneo triContainer.emplace_back( CurrentTriangle) ; } @@ -2464,10 +2470,15 @@ VolZmap::ExtMarchingCubes( int nBlock, TRIA3DEXLIST& lstTria, TriHolder& triHold CurrentTriangle.SetGrade( nTool0) ; else if ( nTool1 == nTool2) CurrentTriangle.SetGrade( nTool1) ; - // Setto le normali del campo vettoriali ai relativi vertici - CurrentTriangle.SetVertexNorm( 0, CompoTriVert[nCompCount - 1][TriIndex].vtNorm) ; - CurrentTriangle.SetVertexNorm( 1, CompoTriVert[nCompCount - 1][TriIndex+1].vtNorm) ; - CurrentTriangle.SetVertexNorm( 2, CompoTriVert[nCompCount - 1][TriIndex+2].vtNorm) ; + // Setto le normali del campo vettoriali ai relativi vertici se non siamo in + // caso di triangoli ribaltati, altrimenti chiamiamo solo Validate( true) + if ( CurrentTriangle.GetVertexNorm( 0).SqLen() > EPS_SMALL * EPS_SMALL && + CurrentTriangle.GetVertexNorm( 1).SqLen() > EPS_SMALL * EPS_SMALL && + CurrentTriangle.GetVertexNorm( 2).SqLen() > EPS_SMALL * EPS_SMALL) { + CurrentTriangle.SetVertexNorm( 0, CompoTriVert[nCompCount - 1][TriIndex].vtNorm) ; + CurrentTriangle.SetVertexNorm( 1, CompoTriVert[nCompCount - 1][TriIndex+1].vtNorm) ; + CurrentTriangle.SetVertexNorm( 2, CompoTriVert[nCompCount - 1][TriIndex+2].vtNorm) ; + } // Valido il triangolo bool bV = CurrentTriangle.Validate( true) ; // Riporto le coordinate nel sistema in cui è immerso lo Zmap @@ -2776,6 +2787,23 @@ VolZmap::FlipEdgesII( TriHolder& TriHold, bool bGraph) const } } } + // La gestione dei triangoli ribaltati annulla le normali ai vertici + // di tutti i triangoli del fan. A quelli che poi partecipano a un flipping + // le normali vengono aggiustate in tale sede, ai rimanenti devono ancora essere + // aggiustate. Tale operazione è svolta qui. + int nNumComp = int( TriHold[n1].ptCompoVert.size()) ; + for ( int nComp = 0 ; nComp < nNumComp ; ++ nComp) { + int nTriNum = int( TriHold[n1].vCompoTria[nComp].size()) ; + for ( int nTri = 0 ; nTri < nTriNum ; ++ nTri) { + Vector3d vtV0 = TriHold[n1].vCompoTria[nComp][nTri].GetVertexNorm( 0) ; + Vector3d vtV1 = TriHold[n1].vCompoTria[nComp][nTri].GetVertexNorm( 1) ; + Vector3d vtV2 = TriHold[n1].vCompoTria[nComp][nTri].GetVertexNorm( 2) ; + if ( vtV0.SqLen() < EPS_SMALL * EPS_SMALL || + vtV1.SqLen() < EPS_SMALL * EPS_SMALL || + vtV2.SqLen() < EPS_SMALL * EPS_SMALL) + TriHold[n1].vCompoTria[nComp][nTri].Validate( true) ; + } + } } return true ; @@ -2955,6 +2983,26 @@ VolZmap::FlipEdgesBB( TriaMatrix& InterTria) const } } } + // La gestione dei triangoli ribaltati annulla le normali ai vertici + // di tutti i triangoli del fan. A quelli che poi partecipano a un flipping + // le normali vengono aggiustate in tale sede, ai rimanenti devono ancora essere + // aggiustate. Tale operazione è svolta qui. + int nVoxelNum = int( InterTria[tFB].size()) ; + for ( int nVox = 0 ; nVox < nVoxelNum ; ++ nVox) { + int nCompNum = int( InterTria[tFB][nVox].ptCompoVert.size()) ; + for ( int nComp = 0 ; nComp < nCompNum ; ++ nComp) { + int nTriNum = int( InterTria[tFB][nVox].vCompoTria[nComp].size()) ; + for ( int nTri = 0 ; nTri < nTriNum ; ++ nTri) { + Vector3d vtV0 = InterTria[tFB][nVox].vCompoTria[nComp][nTri].GetVertexNorm( 0) ; + Vector3d vtV1 = InterTria[tFB][nVox].vCompoTria[nComp][nTri].GetVertexNorm( 1) ; + Vector3d vtV2 = InterTria[tFB][nVox].vCompoTria[nComp][nTri].GetVertexNorm( 2) ; + if ( vtV0.SqLen() < EPS_SMALL * EPS_SMALL || + vtV1.SqLen() < EPS_SMALL * EPS_SMALL || + vtV2.SqLen() < EPS_SMALL * EPS_SMALL) + InterTria[tFB][nVox].vCompoTria[nComp][nTri].Validate( true) ; + } + } + } } return true ; }