diff --git a/EgtGeomKernel.rc b/EgtGeomKernel.rc index 19b6ff2..f990cc1 100644 Binary files a/EgtGeomKernel.rc and b/EgtGeomKernel.rc differ diff --git a/VolTriZmapCalculus.cpp b/VolTriZmapCalculus.cpp index e353f2f..f77445f 100644 --- a/VolTriZmapCalculus.cpp +++ b/VolTriZmapCalculus.cpp @@ -25,6 +25,9 @@ using namespace std ; //---------------------------------------------------------------------------- +// Punti e vettore devono esse espressi nel medesimo sistema di riferimento. +// Il box è allineato con gli assi di tale sistema di riferimento. +// Viene restituito true in caso di intersezione, false altrimenti. bool VolZmap::IntersLineBox( const Point3d& ptP, const Vector3d& vtV, const Point3d& ptMin, const Point3d& ptMax) const { @@ -34,6 +37,10 @@ VolZmap::IntersLineBox( const Point3d& ptP, const Vector3d& vtV, const Point3d& } //---------------------------------------------------------------------------- +// Punti e vettore devono esse espressi nel medesimo sistema di riferimento. +// Il box è allineato con gli assi di tale sistema di riferimento. +// In dU1, dU2 vengono restituiti i parametri a cui si trovano le intersezioni. +// Viene restituito true in caso di intersezione, false altrimenti. bool VolZmap::IntersLineBox( const Point3d& ptP, const Vector3d& vtV, const Point3d& ptMin, const Point3d& ptMax, double& dU1, double& dU2) const @@ -95,17 +102,25 @@ VolZmap::IntersLineZMapLattice( const Point3d& ptP, const Vector3d& vtV, double& } //---------------------------------------------------------------------------- +// Trova le intersezioni di una retta, definita tramite un suo punto e il vettore della direzione, +// e il bounding box dello Zmap. Punto e vettore devono essere espressi nel sistema di riferimento +// intrinseco dello Zmap. Se vi è intersezione viene restitutito true, false altrimenti. +// Se vi è intersezione in dU1 e dU2 vengono restituiti i parametri a cui avvengono le intersezioni. bool -VolZmap::IntersLineZMapBBox( const Point3d& ptP, const Vector3d& vtV, unsigned int nGrid, double& dU1, double& dU2) const +VolZmap::IntersLineZMapBBox( const Point3d& ptP, const Vector3d& vtV, double& dU1, double& dU2) const { // Punti estremi del box dello Zmap Point3d ptMin = ORIG ; - Point3d ptMax = ptMin + Vector3d( m_nNx[nGrid] * m_dStep, m_nNy[nGrid] * m_dStep, m_dMaxZ[nGrid]) ; + Point3d ptMax = ptMin + Vector3d( m_nNx[0] * m_dStep, m_nNy[0] * m_dStep, m_dMaxZ[0]) ; return IntersLineBox( ptP, vtV, ptMin, ptMax, dU1, dU2) ; } //---------------------------------------------------------------------------- +// Trova le intersezioni fra una retta e un dexel parallelepipedale (gli intervalli sono +// parallelepipdi). Punto e vettore devono essere espressi nel sistema grilgia che coincide +// con quello intrinseco dello Zmap solo nel caso della prima griglia. Per le altre griglie +// è necessario permutare ciclicamente le coordinate. bool VolZmap::IntersLineDexel( const Point3d& ptP, const Vector3d& vtV, unsigned int nGrid, unsigned int nI, unsigned int nJ, double& dU1, double& dU2) const @@ -144,6 +159,10 @@ VolZmap::IntersLineDexel( const Point3d& ptP, const Vector3d& vtV, unsigned int } //---------------------------------------------------------------------------- +// Trova le intersezioni fra una semi-retta e un dexel parallelepipedale (gli intervalli sono +// parallelepipdi). Punto e vettore devono essere espressi nel sistema grilgia che coincide +// con quello intrinseco dello Zmap solo nel caso della prima griglia. Per le altre griglie +// è necessario permutare ciclicamente le coordinate. bool VolZmap::IntersRayDexel( const Point3d& ptP, const Vector3d& vtV, unsigned int nGrid, unsigned int nI, unsigned int nJ, double& dU1, double& dU2) const @@ -196,8 +215,8 @@ VolZmap::GetDepth( const Point3d& ptPLoc, const Vector3d& vtDLoc, double& dInLen { Point3d ptP = ptPLoc ; Vector3d vtD = vtDLoc ; - ptP.ToLoc( m_MapFrame[0]) ; - vtD.ToLoc( m_MapFrame[0]) ; + ptP.ToLoc( m_MapFrame) ; + vtD.ToLoc( m_MapFrame) ; if ( bExact) return GetDepthWithVoxel( ptP, vtD, dInLength, dOutLength, true) ; @@ -212,12 +231,10 @@ VolZmap::GetDepth( const Point3d& ptPLoc, const Vector3d& vtDLoc, double& dInLen // OutLength = distanza di uscita bool VolZmap::GetDepthWithDexel( const Point3d& ptP, const Vector3d& vtV, double& dInLength, double& dOutLength) const -{ - int nGrid = 0 ; - +{ // Intersezione fra semiretta e BBox dello Zmap double dU1, dU2 ; - bool bTest = IntersLineZMapBBox( ptP, vtV, nGrid, dU1, dU2) && ( dU1 > 0 || dU2 > 0) ; + bool bTest = IntersLineZMapBBox( ptP, vtV, dU1, dU2) && ( dU1 > 0 || dU2 > 0) ; // Semiretta esterna al box dello Zmap quindi esterna anche allo Zmap if ( ! bTest) { @@ -226,88 +243,144 @@ VolZmap::GetDepthWithDexel( const Point3d& ptP, const Vector3d& vtV, double& dIn return true ; } - Point3d ptI, ptF ; - // Una sola intersezione valida ( punto interno, intersezione valida 2) - if ( dU1 < 0 && dU2 > 0) { - ptI = ptP ; - ptF = ptP + dU2 * vtV ; - } - // due soluzioni valide ( punto esterno) - else { - ptI = ptP + dU1 * vtV ; - ptF = ptP + dU2 * vtV ; - } - - // Inizializzo distanze - dInLength = INFINITO ; - dOutLength = - INFINITO ; + double dInLen[3] ; + double dOutLen[3] ; - // Determino asse di spostamento maggiore - bool bOnX = ( abs( ptF.y - ptI.y) <= abs( ptF.x - ptI.x)) ; + // Ciclo sulle griglie + for ( int nGrid = 0 ; nGrid < int( m_nMapNum) ; ++ nGrid) { - // Movimento crescente su asse di movimento principale - if ( ( bOnX && ptF.x < ptI.x) || ( ! bOnX && ptF.y < ptI.y) ) - swap( ptI, ptF) ; + Point3d ptP0 = ptP ; + Vector3d vtV0 = vtV ; - // Pendenza - double dDeltaX = ( ptF.x - ptI.x) ; - double dDeltaY = ( ptF.y - ptI.y) ; - double dM = 0 ; - if ( bOnX && abs( dDeltaX) > EPS_SMALL) - dM = dDeltaY / dDeltaX ; - else if ( ! bOnX && abs( dDeltaY) > EPS_SMALL) - dM = dDeltaX / dDeltaY ; - - // Determinazione degli indici i j dei punti ptI e ptF - int nIi = Clamp( int( floor( ptI.x / m_dStep)), 0, m_nNx[nGrid] - 1) ; - int nIj = Clamp( int( floor( ptI.y / m_dStep)), 0, m_nNy[nGrid] - 1) ; - int nFi = Clamp( int( floor( ptF.x / m_dStep)), 0, m_nNx[nGrid] - 1) ; - int nFj = Clamp( int( floor( ptF.y / m_dStep)), 0, m_nNy[nGrid] - 1) ; - - // mi muovo - int i = nIi ; int j = nIj ; - while ( ( bOnX && i <= nFi) || ( ! bOnX && j <= nFj)) { - - // Eseguo controllo - double dU1, dU2 ; - if ( IntersRayDexel( ptP, vtV, nGrid, i, j, dU1, dU2)) { - dInLength = min( dInLength, dU1) ; - dOutLength = max( dOutLength, dU2) ; - } - - // Calcolo spostamento (a destra o sopra) - if ( bOnX) { - double dMoveX = ( ( i + 1) * m_dStep - ptI.x) ; - double dMoveY = dMoveX * dM ; - double dY = ptI.y + dMoveY ; - int nNewJ = Clamp( int( floor( dY / m_dStep)), 0, m_nNy[nGrid] - 1) ; - if ( nNewJ != j) - j = nNewJ ; - else - ++ i ; + Point3d ptI, ptF ; + // Una sola intersezione valida ( punto interno, intersezione valida 2) + if ( dU1 < 0 && dU2 > 0) { + ptI = ptP ; + ptF = ptP + dU2 * vtV ; } + // due soluzioni valide ( punto esterno) else { - double dMoveY = ( ( j + 1) * m_dStep - ptI.y) ; - double dMoveX = dMoveY * dM ; - double dX = ptI.x + dMoveX ; - int nNewI = Clamp( int( floor( dX / m_dStep)), 0, m_nNx[nGrid] - 1) ; - if ( nNewI != i) - i = nNewI ; - else - ++ j ; + ptI = ptP + dU1 * vtV ; + ptF = ptP + dU2 * vtV ; } + // Passo dal sistema intrinseco alla griglia + if ( nGrid == 1) { + swap( ptP0.y, ptP0.z) ; + swap( ptP0.x, ptP0.z) ; + swap( vtV0.y, vtV0.z) ; + swap( vtV0.x, vtV0.z) ; + swap( ptI.y, ptI.z) ; + swap( ptI.x, ptI.z) ; + swap( ptF.y, ptF.z) ; + swap( ptF.x, ptF.z) ; + } + else if ( nGrid == 2) { + swap( ptP0.x, ptP0.z) ; + swap( ptP0.y, ptP0.z) ; + swap( vtV0.x, vtV0.z) ; + swap( vtV0.y, vtV0.z) ; + swap( ptI.x, ptI.z) ; + swap( ptI.y, ptI.z) ; + swap( ptF.x, ptF.z) ; + swap( ptF.y, ptF.z) ; + } + + // Inizializzo distanze + dInLen[nGrid] = INFINITO ; + dOutLen[nGrid] = - INFINITO ; + + // Determino asse di spostamento maggiore + bool bOnX = ( abs( ptF.y - ptI.y) <= abs( ptF.x - ptI.x)) ; + + // Movimento crescente su asse di movimento principale + if ( ( bOnX && ptF.x < ptI.x) || ( ! bOnX && ptF.y < ptI.y) ) + swap( ptI, ptF) ; + + // Pendenza + double dDeltaX = ( ptF.x - ptI.x) ; + double dDeltaY = ( ptF.y - ptI.y) ; + double dM = 0 ; + if ( bOnX && abs( dDeltaX) > EPS_SMALL) + dM = dDeltaY / dDeltaX ; + else if ( ! bOnX && abs( dDeltaY) > EPS_SMALL) + dM = dDeltaX / dDeltaY ; + + // Determinazione degli indici i j dei punti ptI e ptF + int nIi = Clamp( int( floor( ptI.x / m_dStep)), 0, m_nNx[nGrid] - 1) ; + int nIj = Clamp( int( floor( ptI.y / m_dStep)), 0, m_nNy[nGrid] - 1) ; + int nFi = Clamp( int( floor( ptF.x / m_dStep)), 0, m_nNx[nGrid] - 1) ; + int nFj = Clamp( int( floor( ptF.y / m_dStep)), 0, m_nNy[nGrid] - 1) ; + + // mi muovo + int i = nIi ; int j = nIj ; + while ( ( bOnX && i <= nFi) || ( ! bOnX && j <= nFj)) { + + // Eseguo controllo + double dU1, dU2 ; + if ( IntersRayDexel( ptP0, vtV0, nGrid, i, j, dU1, dU2)) { + dInLen[nGrid] = min( dInLen[nGrid], dU1) ; + dOutLen[nGrid] = max( dOutLen[nGrid], dU2) ; + } + + // Calcolo spostamento (a destra o sopra) + if ( bOnX) { + double dMoveX = ( ( i + 1) * m_dStep - ptI.x) ; + double dMoveY = dMoveX * dM ; + double dY = ptI.y + dMoveY ; + int nNewJ = Clamp( int( floor( dY / m_dStep)), 0, m_nNy[nGrid] - 1) ; + if ( nNewJ != j) + j = nNewJ ; + else + ++ i ; + } + else { + double dMoveY = ( ( j + 1) * m_dStep - ptI.y) ; + double dMoveX = dMoveY * dM ; + double dX = ptI.x + dMoveX ; + int nNewI = Clamp( int( floor( dX / m_dStep)), 0, m_nNx[nGrid] - 1) ; + if ( nNewI != i) + i = nNewI ; + else + ++ j ; + } + } + + // Se non abbiamo incontrato materiale + if ( dInLen[nGrid] > dOutLen[nGrid] - EPS_SMALL) { + dInLen[nGrid] = - 2 ; + dOutLen[nGrid] = - 2 ; + } + // Se parto dall'interno + else if ( dInLen[nGrid] < - EPS_SMALL) + dInLen[nGrid] = - 1 ; } - // Se non abbiamo incontrato materiale - if ( dInLength > dOutLength - EPS_SMALL) { + if ( m_nMapNum == 1) { + dInLength = dInLen[0] ; + dOutLength = dOutLen[0] ; + return true ; + } + + + if ( abs( dInLen[0] + 2) < EPS_SMALL && + abs( dInLen[1] + 2) < EPS_SMALL && + abs( dInLen[2] + 2) < EPS_SMALL) { dInLength = - 2 ; dOutLength = - 2 ; return true ; } - - // Se parto dall'interno - if ( dInLength < - EPS_SMALL) - dInLength = - 1 ; + else { + + dInLength = INFINITO ; + dOutLength = - INFINITO ; + for ( int nGr = 0 ; nGr < 3 ; ++ nGr) { + if ( dInLen[nGr] > - 2 && dInLen[nGr] < dInLength) + dInLength = dInLen[nGr] ; + if ( dOutLen[nGr] > - 2 && dOutLen[nGr] > dOutLength) + dOutLength = dOutLen[nGr] ; + } + } + return true ; } @@ -325,7 +398,7 @@ VolZmap::GetDepthWithVoxel( const Point3d& ptP, const Vector3d& vtD, double& dIn double dU1, dU2 ; // Intersezione fra semiretta e BBox dello Zmap - bool bLineBBoxInters = IntersLineZMapBBox( ptP, vtD, 0, dU1, dU2) && ( dU1 > 0 || dU2 > 0) ; + bool bLineBBoxInters = IntersLineZMapBBox( ptP, vtD, dU1, dU2) && ( dU1 > 0 || dU2 > 0) ; // Semiretta esterna al box dello Zmap quindi esterna anche allo Zmap if ( ! bLineBBoxInters) { dInLength = - 2 ; @@ -415,8 +488,8 @@ VolZmap::GetDepthWithVoxel( const Point3d& ptP, const Vector3d& vtD, double& dIn continue ; // se altrimenti c'è una sola intersezione else if ( nIntType == ILTT_VERT || - nIntType == ILTT_EDGE || - nIntType == ILTT_IN) { + nIntType == ILTT_EDGE || + nIntType == ILTT_IN) { LineTriaInt NewInt ; NewInt.dPar = ( ptLineTria1 - ptP) * vtD ; NewInt.dDot = vtD * CurrTria.GetN() ; @@ -521,7 +594,7 @@ VolZmap::AvoidBox( const Frame3d& frBox, const Vector3d& vtDiag) const BBox3d b3Box( ORIG, ORIG + vtDiag) ; // lo porto nel riferimento intrinseco dello Zmap - b3Box.LocToLoc( frBox, m_MapFrame[0]) ; + b3Box.LocToLoc( frBox, m_MapFrame) ; // BBox dello Zmap nel suo riferimento intrinseco BBox3d b3Zmap( ORIG, Point3d( m_nNx[0] * m_dStep, m_nNy[0] * m_dStep, m_dMaxZ[0])) ; @@ -538,12 +611,12 @@ VolZmap::AvoidBox( const Frame3d& frBox, const Vector3d& vtDiag) const int nEnJ = Clamp( int( b3Int.GetMax().y / m_dStep), 0, m_nNy[0] -1) ; // Vettore direzione dei dexel nel riferimento del Box - Vector3d vtK = Z_AX ; vtK.LocToLoc( m_MapFrame[0], frBox) ; + Vector3d vtK = Z_AX ; vtK.LocToLoc( m_MapFrame, frBox) ; // Riferimento intrinseco dei dexel nel riferimento del box - Point3d ptO = ORIG ; ptO.LocToLoc( m_MapFrame[0], frBox) ; - Vector3d vtX = X_AX ; vtX.LocToLoc( m_MapFrame[0], frBox) ; - Vector3d vtY = Y_AX ; vtY.LocToLoc( m_MapFrame[0], frBox) ; + Point3d ptO = ORIG ; ptO.LocToLoc( m_MapFrame, frBox) ; + Vector3d vtX = X_AX ; vtX.LocToLoc( m_MapFrame, frBox) ; + Vector3d vtY = Y_AX ; vtY.LocToLoc( m_MapFrame, frBox) ; // Ciclo di intersezione dei dexel con il BBox for ( int i = nStI ; i <= nEnI ; ++ i) { @@ -1414,7 +1487,7 @@ VolZmap::GetPlaneIntersection( const Plane3d& plPlane, POCRVVECTOR& vpLoop) cons return false ; // Porto il piano nel sistema Zmap Plane3d plPlaneL = plPlane ; - plPlaneL.ToLoc( m_MapFrame[0]) ; + plPlaneL.ToLoc( m_MapFrame) ; // Vettore del piano Vector3d vtNL = plPlaneL.GetVersN() ; @@ -1466,7 +1539,7 @@ VolZmap::GetPlaneIntersection( const Plane3d& plPlane, POCRVVECTOR& vpLoop) cons return false ; } pLoop->SetExtrusion( vtNL) ; - pLoop->ToGlob( m_MapFrame[0]) ; + pLoop->ToGlob( m_MapFrame) ; // Se normali controverse, devo invertire il verso del loop. if ( nSign < 0) pLoop->Invert() ; diff --git a/VolTriZmapCreation.cpp b/VolTriZmapCreation.cpp index 3a80fc5..36aa22f 100644 --- a/VolTriZmapCreation.cpp +++ b/VolTriZmapCreation.cpp @@ -42,8 +42,8 @@ VolZmap::Create( const Point3d& ptO, double dLengthX, double dLengthY, double dL // di uno si ottengono da una permutazione ciclica di quelle del precedente sistema. // es: X(n) = Z(n-1), Y(n) = X(n-1), Z(n) = Y(n-1) - // Definisco i sistemi di riferimento - m_MapFrame[0].Set( ptO, X_AX, Y_AX, Z_AX) ; + // Definisco il sistema di riferimento intrinseco + m_MapFrame.Set( ptO, X_AX, Y_AX, Z_AX) ; // Definisco i vettori dei limiti su indici m_nNx[0] = static_cast ( floor( ( dLengthX + 0.5 * m_dStep + EPS_SMALL) / m_dStep)) ; @@ -64,8 +64,6 @@ VolZmap::Create( const Point3d& ptO, double dLengthX, double dLengthY, double dL // Se tridexel if ( bTriDex) { - m_MapFrame[1].Set( ptO, Y_AX, Z_AX, X_AX) ; - m_MapFrame[2].Set( ptO, Z_AX, X_AX, Y_AX) ; m_nNx[1] = static_cast ( floor( ( dLengthY + 0.5 * m_dStep + EPS_SMALL) / m_dStep)) ; m_nNy[1] = static_cast ( floor( ( dLengthZ + 0.5 * m_dStep + EPS_SMALL) / m_dStep)) ; @@ -83,9 +81,7 @@ VolZmap::Create( const Point3d& ptO, double dLengthX, double dLengthY, double dL // altrimenti mono dexel else { - m_MapFrame[1].Set( ptO, Y_AX, Z_AX, X_AX) ; - m_MapFrame[2].Set( ptO, Z_AX, X_AX, Y_AX) ; - + m_nNx[1] = 0 ; m_nNy[1] = 0 ; @@ -183,8 +179,8 @@ VolZmap::CreateFromFlatRegion( const ISurfFlatRegion& Surf, double dDimZ, double SurfBBox.GetMinMax( ptMapOrig, ptMapEnd) ; SurfBBox.Expand( 100 * EPS_SMALL, 100 * EPS_SMALL, 0) ; - // Sistema di riferimento mappa - m_MapFrame[0].Set( ptMapOrig, X_AX, Y_AX, Z_AX) ; + // Sistema di riferimento intrinseco dello Zmap + m_MapFrame.Set( ptMapOrig, X_AX, Y_AX, Z_AX) ; // Determino le dimensioni lineari X Y della griglia double dLengthX = ptMapEnd.x - ptMapOrig.x ; @@ -215,10 +211,7 @@ VolZmap::CreateFromFlatRegion( const ISurfFlatRegion& Surf, double dDimZ, double // Se Tridexel ridimensiono anche gli altri vettori if ( bTriDex) { - - m_MapFrame[1].Set( ptMapOrig, Y_AX, Z_AX, X_AX) ; - m_MapFrame[2].Set( ptMapOrig, Z_AX, X_AX, Y_AX) ; - + m_nNx[1] = static_cast ( floor( ( dLengthY + 0.5 * m_dStep + EPS_SMALL) / m_dStep)) ; m_nNy[1] = static_cast ( floor( ( dDimZ + 0.5 * m_dStep + EPS_SMALL) / m_dStep)) ; @@ -241,9 +234,7 @@ VolZmap::CreateFromFlatRegion( const ISurfFlatRegion& Surf, double dDimZ, double } else { - m_MapFrame[1].Set( ptMapOrig, Y_AX, Z_AX, X_AX) ; - m_MapFrame[2].Set( ptMapOrig, Z_AX, X_AX, Y_AX) ; - + m_nNx[1] = 0 ; m_nNy[1] = 0 ; @@ -510,8 +501,8 @@ VolZmap::CreateFromTriMesh( const ISurfTriMesh& Surf, double dPrec, bool bTriDex // quindi espandiamo il bounding box per ovviare al problema. SurfBBox.Expand( 100 * EPS_SMALL, 100 * EPS_SMALL, 100 * EPS_SMALL) ; - // Sistema di riferimento mappa - m_MapFrame[0].Set( ptMapOrig, Frame3d::TOP) ; + // Sistema di riferimento intrinseco dello Zmap + m_MapFrame.Set( ptMapOrig, Frame3d::TOP) ; // Il passo di discretizzazione non può essere inferiore a 100 * EPS_SMALL m_dStep = max( dPrec, 100 * EPS_SMALL) ; @@ -544,9 +535,7 @@ VolZmap::CreateFromTriMesh( const ISurfTriMesh& Surf, double dPrec, bool bTriDex // Se Tridexel ridimensiono anche gli altri vettori if ( bTriDex) { - m_MapFrame[1].Set( ptMapOrig, Y_AX, Z_AX, X_AX) ; // Sarà Front Left - m_MapFrame[2].Set( ptMapOrig, Z_AX, X_AX, Y_AX) ; - + m_nNx[1] = static_cast ( floor( ( vtLen.y + 0.5 * m_dStep + EPS_SMALL) / m_dStep)) ; m_nNy[1] = static_cast ( floor( ( vtLen.z + 0.5 * m_dStep + EPS_SMALL) / m_dStep)) ; @@ -569,9 +558,7 @@ VolZmap::CreateFromTriMesh( const ISurfTriMesh& Surf, double dPrec, bool bTriDex } else { - m_MapFrame[1].Set( ptMapOrig, Y_AX, Z_AX, X_AX) ; - m_MapFrame[2].Set( ptMapOrig, Z_AX, X_AX, Y_AX) ; - + m_nNx[1] = 0 ; m_nNy[1] = 0 ; m_nDim[1] = 0 ; @@ -587,8 +574,17 @@ VolZmap::CreateFromTriMesh( const ISurfTriMesh& Surf, double dPrec, bool bTriDex // ciclo sulle griglie for ( unsigned int g = 0 ; g < 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( m_MapFrame[g], Surf) ; + IntersParLinesSurfTm intPLSTM( frMapFrame, Surf) ; // Determinazione e ridimensionamento dei dexel interni alla trimesh for ( unsigned int i = 0 ; i < m_nNx[g] ; ++ i) { diff --git a/VolTriZmapGraphics.cpp b/VolTriZmapGraphics.cpp index 56c0d91..57b9cb0 100644 --- a/VolTriZmapGraphics.cpp +++ b/VolTriZmapGraphics.cpp @@ -29,11 +29,7 @@ using namespace std ; -// ------------------------- STRUTTURA VERTICE TRIANGOLO - NORMALE ALLA SUPERFICIE ------------------------------------------------ -struct VectorField { - Point3d ptInt ; - Vector3d vtNorm ; -} ; + // ------------------------- UNORDERED MAP PER LA GESTIONE DEI TRIANGOLI GRANDI --------------------------------------------------- @@ -159,6 +155,345 @@ DotTest( const VectorField CompoVert[], int nCompoElem, Vector3d& vtAvg, double return true ; } + +//---------------------------------------------------------------------------- +bool +VolZmap::GridControl( VectorField VecField[], VectorField CompoVert[][12], + int nIndArrey[][4], int nVertComp[], int nCompCount, bool& bGridControl) const +{ + // Ordino i 4 indici in senso crescente + for ( int nSrtInd1 = 0 ; nSrtInd1 < nVertComp[nCompCount - 1] - 1 ; ++ nSrtInd1) { + for ( int nSrtInd2 = nSrtInd1 + 1 ; nSrtInd2 < nVertComp[nCompCount - 1] ; ++ nSrtInd2) { + if ( nIndArrey[nCompCount - 1][nSrtInd1] > nIndArrey[nCompCount - 1][nSrtInd2]) + swap( nIndArrey[nCompCount - 1][nSrtInd1], nIndArrey[nCompCount - 1][nSrtInd2]) ; + } + } + + if ( ( nIndArrey[nCompCount - 1][0] == 0 && nIndArrey[nCompCount - 1][1] == 2 && + nIndArrey[nCompCount - 1][2] == 9 && nIndArrey[nCompCount - 1][3] == 10) || + ( nIndArrey[nCompCount - 1][0] == 4 && nIndArrey[nCompCount - 1][1] == 6 && + nIndArrey[nCompCount - 1][2] == 9 && nIndArrey[nCompCount - 1][3] == 10) || + ( nIndArrey[nCompCount - 1][0] == 4 && nIndArrey[nCompCount - 1][1] == 6 && + nIndArrey[nCompCount - 1][2] == 8 && nIndArrey[nCompCount - 1][3] == 11) || + ( nIndArrey[nCompCount - 1][0] == 0 && nIndArrey[nCompCount - 1][1] == 2 && + nIndArrey[nCompCount - 1][2] == 8 && nIndArrey[nCompCount - 1][3] == 11) || + ( nIndArrey[nCompCount - 1][0] == 1 && nIndArrey[nCompCount - 1][1] == 3 && + nIndArrey[nCompCount - 1][2] == 8 && nIndArrey[nCompCount - 1][3] == 9 ) || + ( nIndArrey[nCompCount - 1][0] == 1 && nIndArrey[nCompCount - 1][1] == 3 && + nIndArrey[nCompCount - 1][2] == 10 && nIndArrey[nCompCount - 1][3] == 11) || + ( nIndArrey[nCompCount - 1][0] == 5 && nIndArrey[nCompCount - 1][1] == 7 && + nIndArrey[nCompCount - 1][2] == 10 && nIndArrey[nCompCount - 1][3] == 11) || + ( nIndArrey[nCompCount - 1][0] == 5 && nIndArrey[nCompCount - 1][1] == 7 && + nIndArrey[nCompCount - 1][2] == 8 && nIndArrey[nCompCount - 1][3] == 9 )) { + + + if ( AreSameVectorApprox( VecField[nIndArrey[nCompCount - 1][0]].vtNorm, VecField[nIndArrey[nCompCount - 1][1]].vtNorm) && + abs( VecField[nIndArrey[nCompCount - 1][0]].vtNorm * VecField[nIndArrey[nCompCount - 1][2]].vtNorm) < EPS_SMALL && + abs( VecField[nIndArrey[nCompCount - 1][0]].vtNorm * VecField[nIndArrey[nCompCount - 1][3]].vtNorm) < EPS_SMALL) { + + Point3d ptBarycenter = ( CompoVert[nCompCount - 1][0].ptInt + CompoVert[nCompCount - 1][1].ptInt + + CompoVert[nCompCount - 1][2].ptInt + CompoVert[nCompCount - 1][3].ptInt) / 4 ; + + Vector3d vtVecField = VecField[nIndArrey[nCompCount - 1][0]].vtNorm ; + + if ( vtVecField.x * vtVecField.x > 1 - EPS_SMALL * EPS_SMALL) { + + if ( abs( CompoVert[nCompCount - 1][0].ptInt.x - ptBarycenter.x) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][1].ptInt.x - ptBarycenter.x) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][2].ptInt.x - ptBarycenter.x) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][3].ptInt.x - ptBarycenter.x) < EPS_SMALL) { + + double dXBar = ptBarycenter.x / m_dStep - 0.5 ; + int nBarLimSup = int( m_nNx[0]) ; + int nBarInd = 0 ; + + while ( nBarInd < nBarLimSup) { + double dXInd = double( nBarInd) ; + if ( abs( dXInd - dXBar) < EPS_SMALL) { + bGridControl = false ; + break ; + } + ++ nBarInd ; + } + } + } + else if ( vtVecField.y * vtVecField.y > 1 - EPS_SMALL * EPS_SMALL) { + + if ( abs( CompoVert[nCompCount - 1][0].ptInt.y - ptBarycenter.y) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][1].ptInt.y - ptBarycenter.y) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][2].ptInt.y - ptBarycenter.y) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][3].ptInt.y - ptBarycenter.y) < EPS_SMALL) { + + double dYBar = ptBarycenter.y / m_dStep - 0.5 ; + int nBarLimSup = int( m_nNy[0]) ; + int nBarInd = 0 ; + + while ( nBarInd < nBarLimSup) { + double dYInd = double( nBarInd) ; + if ( abs( dYInd - dYBar) < EPS_SMALL) { + bGridControl = false ; + break ; + } + ++ nBarInd ; + } + } + } + else if ( vtVecField.z * vtVecField.z > 1 - EPS_SMALL * EPS_SMALL) { + + if ( abs( CompoVert[nCompCount - 1][0].ptInt.z - ptBarycenter.z) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][1].ptInt.z - ptBarycenter.z) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][2].ptInt.z - ptBarycenter.z) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][3].ptInt.z - ptBarycenter.z) < EPS_SMALL) { + + double dZBar = ptBarycenter.z / m_dStep - 0.5 ; + int nBarLimSup = int( m_nNy[1]) ; + int nBarInd = 0 ; + + while ( nBarInd < nBarLimSup) { + double dZInd = double( nBarInd) ; + if ( abs( dZInd - dZBar) < EPS_SMALL) { + bGridControl = false ; + break ; + } + ++ nBarInd ; + } + } + } + } + else if ( AreSameVectorApprox( VecField[nIndArrey[nCompCount - 1][2]].vtNorm, VecField[nIndArrey[nCompCount - 1][3]].vtNorm) && + abs( VecField[nIndArrey[nCompCount - 1][2]].vtNorm * VecField[nIndArrey[nCompCount - 1][0]].vtNorm) < EPS_SMALL && + abs( VecField[nIndArrey[nCompCount - 1][2]].vtNorm * VecField[nIndArrey[nCompCount - 1][1]].vtNorm) < EPS_SMALL) { + + Point3d ptBarycenter = ( CompoVert[nCompCount - 1][0].ptInt + CompoVert[nCompCount - 1][1].ptInt + + CompoVert[nCompCount - 1][2].ptInt + CompoVert[nCompCount - 1][3].ptInt) / 4 ; + + Vector3d vtVecField = VecField[nIndArrey[nCompCount - 1][2]].vtNorm ; + + if ( vtVecField.x * vtVecField.x > 1 - EPS_SMALL * EPS_SMALL) { + + if ( abs( CompoVert[nCompCount - 1][0].ptInt.x - ptBarycenter.x) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][1].ptInt.x - ptBarycenter.x) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][2].ptInt.x - ptBarycenter.x) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][3].ptInt.x - ptBarycenter.x) < EPS_SMALL) { + + double dXBar = ptBarycenter.x / m_dStep - 0.5 ; + int nBarLimSup = int( m_nNx[0]) ; + int nBarInd = 0 ; + + while ( nBarInd < nBarLimSup) { + double dXInd = double( nBarInd) ; + if ( abs( dXInd - dXBar) < EPS_SMALL) { + bGridControl = false ; + break ; + } + ++ nBarInd ; + } + } + } + else if ( vtVecField.y * vtVecField.y > 1 - EPS_SMALL * EPS_SMALL) { + + if ( abs( CompoVert[nCompCount - 1][0].ptInt.y - ptBarycenter.y) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][1].ptInt.y - ptBarycenter.y) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][2].ptInt.y - ptBarycenter.y) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][3].ptInt.y - ptBarycenter.y) < EPS_SMALL) { + + double dYBar = ptBarycenter.y / m_dStep - 0.5 ; + int nBarLimSup = int( m_nNy[0]) ; + int nBarInd = 0 ; + + while ( nBarInd < nBarLimSup) { + double dYInd = double( nBarInd) ; + if ( abs( dYInd - dYBar) < EPS_SMALL) { + bGridControl = false ; + break ; + } + ++ nBarInd ; + } + } + } + else if ( vtVecField.z * vtVecField.z > 1 - EPS_SMALL * EPS_SMALL) { + + if ( abs( CompoVert[nCompCount - 1][0].ptInt.z - ptBarycenter.z) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][1].ptInt.z - ptBarycenter.z) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][2].ptInt.z - ptBarycenter.z) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][3].ptInt.z - ptBarycenter.z) < EPS_SMALL) { + + double dZBar = ptBarycenter.z / m_dStep - 0.5 ; + int nBarLimSup = int( m_nNy[1]) ; + int nBarInd = 0 ; + + while ( nBarInd < nBarLimSup) { + double dZInd = double( nBarInd) ; + if ( abs( dZInd - dZBar) < EPS_SMALL) { + bGridControl = false ; + break ; + } + ++ nBarInd ; + } + } + } + } + } + + else if ( ( nIndArrey[nCompCount - 1][0] == 0 && nIndArrey[nCompCount - 1][1] == 1 && + nIndArrey[nCompCount - 1][2] == 4 && nIndArrey[nCompCount - 1][3] == 5) || + ( nIndArrey[nCompCount - 1][0] == 1 && nIndArrey[nCompCount - 1][1] == 2 && + nIndArrey[nCompCount - 1][2] == 5 && nIndArrey[nCompCount - 1][3] == 6) || + ( nIndArrey[nCompCount - 1][0] == 2 && nIndArrey[nCompCount - 1][1] == 3 && + nIndArrey[nCompCount - 1][2] == 6 && nIndArrey[nCompCount - 1][3] == 7) || + ( nIndArrey[nCompCount - 1][0] == 0 && nIndArrey[nCompCount - 1][1] == 3 && + nIndArrey[nCompCount - 1][2] == 4 && nIndArrey[nCompCount - 1][3] == 7)) { + + + if ( AreSameVectorApprox( VecField[nIndArrey[nCompCount - 1][0]].vtNorm, VecField[nIndArrey[nCompCount - 1][2]].vtNorm) && + abs( VecField[nIndArrey[nCompCount - 1][0]].vtNorm * VecField[nIndArrey[nCompCount - 1][1]].vtNorm) < EPS_SMALL && + abs( VecField[nIndArrey[nCompCount - 1][0]].vtNorm * VecField[nIndArrey[nCompCount - 1][3]].vtNorm) < EPS_SMALL) { + + Point3d ptBarycenter = ( CompoVert[nCompCount - 1][0].ptInt + CompoVert[nCompCount - 1][1].ptInt + + CompoVert[nCompCount - 1][2].ptInt + CompoVert[nCompCount - 1][3].ptInt) / 4 ; + + Vector3d vtVecField = VecField[nIndArrey[nCompCount - 1][0]].vtNorm ; + + if ( vtVecField.x * vtVecField.x > 1 - EPS_SMALL * EPS_SMALL) { + + if ( abs( CompoVert[nCompCount - 1][0].ptInt.x - ptBarycenter.x) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][1].ptInt.x - ptBarycenter.x) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][2].ptInt.x - ptBarycenter.x) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][3].ptInt.x - ptBarycenter.x) < EPS_SMALL) { + + double dXBar = ptBarycenter.x / m_dStep - 0.5 ; + int nBarLimSup = int( m_nNx[0]) ; + int nBarInd = 0 ; + + while ( nBarInd < nBarLimSup) { + double dXInd = double( nBarInd) ; + if ( abs( dXInd - dXBar) < EPS_SMALL) { + bGridControl = false ; + break ; + } + ++ nBarInd ; + } + } + } + else if ( vtVecField.y * vtVecField.y > 1 - EPS_SMALL * EPS_SMALL) { + + if ( abs( CompoVert[nCompCount - 1][0].ptInt.y - ptBarycenter.y) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][1].ptInt.y - ptBarycenter.y) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][2].ptInt.y - ptBarycenter.y) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][3].ptInt.y - ptBarycenter.y) < EPS_SMALL) { + + double dYBar = ptBarycenter.y / m_dStep - 0.5 ; + int nBarLimSup = int( m_nNy[0]) ; + int nBarInd = 0 ; + + while ( nBarInd < nBarLimSup) { + double dYInd = double( nBarInd) ; + if ( abs( dYInd - dYBar) < EPS_SMALL) { + bGridControl = false ; + break ; + } + ++ nBarInd ; + } + } + } + else if ( vtVecField.z * vtVecField.z > 1 - EPS_SMALL * EPS_SMALL) { + + if ( abs( CompoVert[nCompCount - 1][0].ptInt.z - ptBarycenter.z) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][1].ptInt.z - ptBarycenter.z) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][2].ptInt.z - ptBarycenter.z) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][3].ptInt.z - ptBarycenter.z) < EPS_SMALL) { + + double dZBar = ptBarycenter.z / m_dStep - 0.5 ; + int nBarLimSup = int( m_nNy[1]) ; + int nBarInd = 0 ; + + while ( nBarInd < nBarLimSup) { + double dZInd = double( nBarInd) ; + if ( abs( dZInd - dZBar) < EPS_SMALL) { + bGridControl = false ; + break ; + } + ++ nBarInd ; + } + } + } + } + else if ( AreSameVectorApprox( VecField[nIndArrey[nCompCount - 1][1]].vtNorm, VecField[nIndArrey[nCompCount - 1][3]].vtNorm) && + abs( VecField[nIndArrey[nCompCount - 1][1]].vtNorm * VecField[nIndArrey[nCompCount - 1][0]].vtNorm) < EPS_SMALL && + abs( VecField[nIndArrey[nCompCount - 1][1]].vtNorm * VecField[nIndArrey[nCompCount - 1][2]].vtNorm) < EPS_SMALL) { + + Point3d ptBarycenter = ( CompoVert[nCompCount - 1][0].ptInt + CompoVert[nCompCount - 1][1].ptInt + + CompoVert[nCompCount - 1][2].ptInt + CompoVert[nCompCount - 1][3].ptInt) / 4 ; + + Vector3d vtVecField = VecField[nIndArrey[nCompCount - 1][0]].vtNorm ; + + if ( vtVecField.x * vtVecField.x > 1 - EPS_SMALL * EPS_SMALL) { + + if ( abs( CompoVert[nCompCount - 1][0].ptInt.x - ptBarycenter.x) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][1].ptInt.x - ptBarycenter.x) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][2].ptInt.x - ptBarycenter.x) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][3].ptInt.x - ptBarycenter.x) < EPS_SMALL) { + + double dXBar = ptBarycenter.x / m_dStep - 0.5 ; + int nBarLimSup = int( m_nNx[0]) ; + int nBarInd = 0 ; + + while ( nBarInd < nBarLimSup) { + double dXInd = double( nBarInd) ; + if ( abs( dXInd - dXBar) < EPS_SMALL) { + bGridControl = false ; + break ; + } + ++ nBarInd ; + } + } + } + else if ( vtVecField.y * vtVecField.y > 1 - EPS_SMALL * EPS_SMALL) { + + if ( abs( CompoVert[nCompCount - 1][0].ptInt.y - ptBarycenter.y) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][1].ptInt.y - ptBarycenter.y) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][2].ptInt.y - ptBarycenter.y) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][3].ptInt.y - ptBarycenter.y) < EPS_SMALL) { + + double dYBar = ptBarycenter.y / m_dStep - 0.5 ; + int nBarLimSup = int( m_nNy[0]) ; + int nBarInd = 0 ; + + while ( nBarInd < nBarLimSup) { + double dYInd = double( nBarInd) ; + if ( abs( dYInd - dYBar) < EPS_SMALL) { + bGridControl = false ; + break ; + } + ++ nBarInd ; + } + } + } + else if ( vtVecField.z * vtVecField.z > 1 - EPS_SMALL * EPS_SMALL) { + + if ( abs( CompoVert[nCompCount - 1][0].ptInt.z - ptBarycenter.z) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][1].ptInt.z - ptBarycenter.z) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][2].ptInt.z - ptBarycenter.z) < EPS_SMALL && + abs( CompoVert[nCompCount - 1][3].ptInt.z - ptBarycenter.z) < EPS_SMALL) { + + double dZBar = ptBarycenter.z / m_dStep - 0.5 ; + int nBarLimSup = int( m_nNy[1]) ; + int nBarInd = 0 ; + + while ( nBarInd < nBarLimSup) { + double dZInd = double( nBarInd) ; + if ( abs( dZInd - dZBar) < EPS_SMALL) { + bGridControl = false ; + break ; + } + ++ nBarInd ; + } + } + } + } + } + return true ; +} // ------------------------- VISUALIZZAZIONE -------------------------------------------------------------------------------------- //---------------------------------------------------------------------------- @@ -181,20 +516,29 @@ VolZmap::GetDexelLines( int nDir, int nPos1, int nPos2, POLYLINELIST& lstPL) con if ( nPos < 0 || nPos >= int( m_Values[nDir].size())) return false ; + // Definisco un sistema di riferimento opportuno + Frame3d frMapFrame ; + if ( nDir == 0) + frMapFrame = m_MapFrame ; + else if ( nDir == 1) + frMapFrame.Set( m_MapFrame.Orig(), m_MapFrame.VersY(), m_MapFrame.VersZ(), m_MapFrame.VersX()) ; + else if ( nDir == 2) + frMapFrame.Set( m_MapFrame.Orig(), m_MapFrame.VersZ(), m_MapFrame.VersX(), m_MapFrame.VersY()) ; + // Calcolo coordinate punto double dX = m_dStep * ( 0.5 + nPos1) ; double dY = m_dStep * ( 0.5 + nPos2) ; // Determino il punto di partenza sulla griglia - Point3d ptP = m_MapFrame[nDir].Orig() + dX * m_MapFrame[nDir].VersX() + dY * m_MapFrame[nDir].VersY() ; + Point3d ptP = frMapFrame.Orig() + dX * frMapFrame.VersX() + dY * frMapFrame.VersY() ; // Creo le polilinee for ( int j = 0 ; j < int( m_Values[nDir][nPos].size()) ; j += 1) { // aggiungo polilinea a lista lstPL.emplace_back() ; // inserisco punti estremi - lstPL.back().AddUPoint( 0, ptP + m_Values[nDir][nPos][j].dMin * m_MapFrame[nDir].VersZ()) ; - lstPL.back().AddUPoint( 1, ptP + m_Values[nDir][nPos][j].dMax * m_MapFrame[nDir].VersZ()) ; + lstPL.back().AddUPoint( 0, ptP + m_Values[nDir][nPos][j].dMin * frMapFrame.VersZ()) ; + lstPL.back().AddUPoint( 1, ptP + m_Values[nDir][nPos][j].dMax * frMapFrame.VersZ()) ; } return true ; } @@ -217,32 +561,41 @@ VolZmap::GetDexelLines( int nDir, int nPos1, int nPos2, POLYLINELIST& lstPL) con if ( nPos < 0 || nPos >= int( m_Values[nDir].size())) return false ; + // Definisco un sistema di riferimento opportuno + Frame3d frMapFrame ; + if ( nDir == 0) + frMapFrame = m_MapFrame ; + else if ( nDir == 1) + frMapFrame.Set( m_MapFrame.Orig(), m_MapFrame.VersY(), m_MapFrame.VersZ(), m_MapFrame.VersX()) ; + else if ( nDir == 2) + frMapFrame.Set( m_MapFrame.Orig(), m_MapFrame.VersZ(), m_MapFrame.VersX(), m_MapFrame.VersY()) ; + // Calcolo coordinate punto double dX = m_dStep * ( 0.5 + nPos1) ; double dY = m_dStep * ( 0.5 + nPos2) ; // Determino il punto di partenza sulla griglia - Point3d ptP = m_MapFrame[nDir].Orig() + dX * m_MapFrame[nDir].VersX() + dY * m_MapFrame[nDir].VersY() ; + Point3d ptP = frMapFrame.Orig() + dX * frMapFrame.VersX() + dY * frMapFrame.VersY() ; // Creo le polilinee for ( int j = 0 ; j < int( m_Values[nDir][nPos].size()) ; j += 1) { // aggiungo polilinea a lista lstPL.emplace_back() ; // calcolo e inserisco punto inizio spillone - Point3d ptQ = ptP + m_Values[nDir][nPos][j].dMin * m_MapFrame[nDir].VersZ() ; + Point3d ptQ = ptP + m_Values[nDir][nPos][j].dMin * frMapFrame.VersZ() ; lstPL.back().AddUPoint( 0, ptQ) ; // calcolo e inserisco punto su termine sua normale Vector3d vtV = m_Values[nDir][nPos][j].vtMinN ; - vtV.ToGlob( m_MapFrame[0]) ; + vtV.ToGlob( m_MapFrame) ; lstPL.back().AddUPoint( 1, ptQ + vtV * m_dStep / 4) ; // aggiungo polilinea a lista lstPL.emplace_back() ; // calcolo e inserisco punto fine spillone - Point3d ptR = ptP + m_Values[nDir][nPos][j].dMax * m_MapFrame[nDir].VersZ() ; + Point3d ptR = ptP + m_Values[nDir][nPos][j].dMax * frMapFrame.VersZ() ; lstPL.back().AddUPoint( 0, ptR) ; // calcolo e inserisco punto su termine sua normale Vector3d vtW = m_Values[nDir][nPos][j].vtMaxN ; - vtW.ToGlob( m_MapFrame[0]) ; + vtW.ToGlob( m_MapFrame) ; lstPL.back().AddUPoint( 1, ptR + vtW * m_dStep / 4) ; } return true ; @@ -489,53 +842,53 @@ VolZmap::CalcChunkPrisms( int nPos1, int nPos2, int nDim1, int nDim2, TRIA3DLIST // calcolo coordinate punti double dX = m_dStep * nPos1 ; double dY = m_dStep * nPos2 ; - Point3d ptP1 = m_MapFrame[0].Orig() + dX * m_MapFrame[0].VersX() + dY * m_MapFrame[0].VersY() ; - Point3d ptP2 = ptP1 + nDim1 * m_dStep * m_MapFrame[0].VersX() ; - Point3d ptP3 = ptP2 + nDim2 * m_dStep * m_MapFrame[0].VersY() ; - Point3d ptP4 = ptP1 + nDim2 * m_dStep * m_MapFrame[0].VersY() ; + Point3d ptP1 = m_MapFrame.Orig() + dX * m_MapFrame.VersX() + dY * m_MapFrame.VersY() ; + Point3d ptP2 = ptP1 + nDim1 * m_dStep * m_MapFrame.VersX() ; + Point3d ptP3 = ptP2 + nDim2 * m_dStep * m_MapFrame.VersY() ; + Point3d ptP4 = ptP1 + nDim2 * m_dStep * m_MapFrame.VersY() ; // creo le facce sopra e sotto - Vector3d vtDZt = m_Values[0][nPos][0].dMax * m_MapFrame[0].VersZ() ; - Vector3d vtDZb = m_Values[0][nPos][0].dMin * m_MapFrame[0].VersZ() ; + Vector3d vtDZt = m_Values[0][nPos][0].dMax * m_MapFrame.VersZ() ; + Vector3d vtDZb = m_Values[0][nPos][0].dMin * m_MapFrame.VersZ() ; // faccia superiore P1t->P2t->P3t->P4t : sempre visibile lstTria.emplace_back() ; - lstTria.back().Set( ptP1 + vtDZt, ptP2 + vtDZt, ptP3 + vtDZt, m_MapFrame[0].VersZ()) ; + lstTria.back().Set( ptP1 + vtDZt, ptP2 + vtDZt, ptP3 + vtDZt, m_MapFrame.VersZ()) ; lstTria.emplace_back() ; - lstTria.back().Set( ptP3 + vtDZt, ptP4 + vtDZt, ptP1 + vtDZt, m_MapFrame[0].VersZ()) ; + lstTria.back().Set( ptP3 + vtDZt, ptP4 + vtDZt, ptP1 + vtDZt, m_MapFrame.VersZ()) ; // faccia inferiore P1b->P4b->P3b->P2b : sempre visibile lstTria.emplace_back() ; - lstTria.back().Set( ptP1 + vtDZb, ptP4 + vtDZb, ptP3 + vtDZb, - m_MapFrame[0].VersZ()) ; + lstTria.back().Set( ptP1 + vtDZb, ptP4 + vtDZb, ptP3 + vtDZb, - m_MapFrame.VersZ()) ; lstTria.emplace_back() ; - lstTria.back().Set( ptP3 + vtDZb, ptP2 + vtDZb, ptP1 + vtDZb, - m_MapFrame[0].VersZ()) ; + lstTria.back().Set( ptP3 + vtDZb, ptP2 + vtDZb, ptP1 + vtDZb, - m_MapFrame.VersZ()) ; // creo le facce laterali for ( int j = 0 ; j < nDim2 ; ++ j) { int nPosD = nPos + nDim1 - 1 + j * m_nNx[0] ; int nPosEst = ( nPos1 + nDim1 - 1 < int( m_nNx[0] - 1) ? nPosD + 1 : - 1) ; - Point3d ptP2D = ptP2 + j * m_dStep * m_MapFrame[0].VersY() ; - Point3d ptP3D = ptP2D + m_dStep * m_MapFrame[0].VersY() ; - AddDexelSideFace( nPosD, nPosEst, ptP2D, ptP3D, m_MapFrame[0].VersZ(), m_MapFrame[0].VersX(), lstTria) ; + Point3d ptP2D = ptP2 + j * m_dStep * m_MapFrame.VersY() ; + Point3d ptP3D = ptP2D + m_dStep * m_MapFrame.VersY() ; + AddDexelSideFace( nPosD, nPosEst, ptP2D, ptP3D, m_MapFrame.VersZ(), m_MapFrame.VersX(), lstTria) ; } for ( int i = 0 ; i < nDim1 ; ++ i) { int nPosD = nPos + ( nDim2 - 1) * m_nNx[0] + i ; int nPosNord = ( nPos2 + nDim2 - 1 < int( m_nNy[0] - 1) ? nPosD + m_nNx[0] : - 1) ; - Point3d ptP4D = ptP4 + i * m_dStep * m_MapFrame[0].VersX() ; - Point3d ptP3D = ptP4D + m_dStep * m_MapFrame[0].VersX() ; - AddDexelSideFace( nPosD, nPosNord, ptP3D, ptP4D, m_MapFrame[0].VersZ(), m_MapFrame[0].VersY(), lstTria) ; + Point3d ptP4D = ptP4 + i * m_dStep * m_MapFrame.VersX() ; + Point3d ptP3D = ptP4D + m_dStep * m_MapFrame.VersX() ; + AddDexelSideFace( nPosD, nPosNord, ptP3D, ptP4D, m_MapFrame.VersZ(), m_MapFrame.VersY(), lstTria) ; } for ( int j = 0 ; j < nDim2 ; ++ j) { int nPosD = nPos + j * m_nNx[0] ; int nPosWest = ( nPos1 > 0 ? nPosD - 1 : - 1) ; - Point3d ptP1D = ptP1 + j * m_dStep * m_MapFrame[0].VersY() ; - Point3d ptP4D = ptP1D + m_dStep * m_MapFrame[0].VersY() ; - AddDexelSideFace( nPosD, nPosWest, ptP4D, ptP1D, m_MapFrame[0].VersZ(), - m_MapFrame[0].VersX(), lstTria) ; + Point3d ptP1D = ptP1 + j * m_dStep * m_MapFrame.VersY() ; + Point3d ptP4D = ptP1D + m_dStep * m_MapFrame.VersY() ; + AddDexelSideFace( nPosD, nPosWest, ptP4D, ptP1D, m_MapFrame.VersZ(), - m_MapFrame.VersX(), lstTria) ; } for ( int i = 0 ; i < nDim1 ; ++ i) { int nPosD = nPos + i ; int nPosSud = ( nPos2 > 0 ? nPosD - m_nNx[0] : - 1) ; - Point3d ptP1D = ptP1 + i * m_dStep * m_MapFrame[0].VersX() ; - Point3d ptP2D = ptP1D + m_dStep * m_MapFrame[0].VersX() ; - AddDexelSideFace( nPosD, nPosSud, ptP1D, ptP2D, m_MapFrame[0].VersZ(), - m_MapFrame[0].VersY(), lstTria) ; + Point3d ptP1D = ptP1 + i * m_dStep * m_MapFrame.VersX() ; + Point3d ptP2D = ptP1D + m_dStep * m_MapFrame.VersX() ; + AddDexelSideFace( nPosD, nPosSud, ptP1D, ptP2D, m_MapFrame.VersZ(), - m_MapFrame.VersY(), lstTria) ; } // return true ; @@ -555,36 +908,36 @@ VolZmap::CalcDexelPrisms( int nPos1, int nPos2, TRIA3DLIST& lstTria) const // calcolo coordinate punto double dX = m_dStep * nPos1 ; double dY = m_dStep * nPos2 ; - Point3d ptP1 = m_MapFrame[0].Orig() + dX * m_MapFrame[0].VersX() + dY * m_MapFrame[0].VersY() ; - Point3d ptP2 = ptP1 + m_dStep * m_MapFrame[0].VersX() ; - Point3d ptP3 = ptP2 + m_dStep * m_MapFrame[0].VersY() ; - Point3d ptP4 = ptP1 + m_dStep * m_MapFrame[0].VersY() ; + Point3d ptP1 = m_MapFrame.Orig() + dX * m_MapFrame.VersX() + dY * m_MapFrame.VersY() ; + Point3d ptP2 = ptP1 + m_dStep * m_MapFrame.VersX() ; + Point3d ptP3 = ptP2 + m_dStep * m_MapFrame.VersY() ; + Point3d ptP4 = ptP1 + m_dStep * m_MapFrame.VersY() ; // creo le facce sopra e sotto di ogni intervallo (sempre visibili) for ( int i = 0 ; i < int( m_Values[0][nPos].size()) ; i += 1) { - Vector3d vtDZt = m_Values[0][nPos][i].dMax * m_MapFrame[0].VersZ() ; - Vector3d vtDZb = m_Values[0][nPos][i].dMin * m_MapFrame[0].VersZ() ; + Vector3d vtDZt = m_Values[0][nPos][i].dMax * m_MapFrame.VersZ() ; + Vector3d vtDZb = m_Values[0][nPos][i].dMin * m_MapFrame.VersZ() ; // faccia superiore P1t->P2t->P3t->P4t : sempre visibile lstTria.emplace_back() ; - lstTria.back().Set( ptP1 + vtDZt, ptP2 + vtDZt, ptP3 + vtDZt, m_MapFrame[0].VersZ()) ; + lstTria.back().Set( ptP1 + vtDZt, ptP2 + vtDZt, ptP3 + vtDZt, m_MapFrame.VersZ()) ; lstTria.emplace_back() ; - lstTria.back().Set( ptP3 + vtDZt, ptP4 + vtDZt, ptP1 + vtDZt, m_MapFrame[0].VersZ()) ; + lstTria.back().Set( ptP3 + vtDZt, ptP4 + vtDZt, ptP1 + vtDZt, m_MapFrame.VersZ()) ; // faccia inferiore P1b->P4b->P3b->P2b : sempre visibile lstTria.emplace_back() ; - lstTria.back().Set( ptP1 + vtDZb, ptP4 + vtDZb, ptP3 + vtDZb, - m_MapFrame[0].VersZ()) ; + lstTria.back().Set( ptP1 + vtDZb, ptP4 + vtDZb, ptP3 + vtDZb, - m_MapFrame.VersZ()) ; lstTria.emplace_back() ; - lstTria.back().Set( ptP3 + vtDZb, ptP2 + vtDZb, ptP1 + vtDZb, - m_MapFrame[0].VersZ()) ; + lstTria.back().Set( ptP3 + vtDZb, ptP2 + vtDZb, ptP1 + vtDZb, - m_MapFrame.VersZ()) ; } // creo le facce laterali int nPosEst = ( nPos1 < int( m_nNx[0] - 1) ? nPos + 1 : - 1) ; - AddDexelSideFace( nPos, nPosEst, ptP2, ptP3, m_MapFrame[0].VersZ(), m_MapFrame[0].VersX(), lstTria) ; + AddDexelSideFace( nPos, nPosEst, ptP2, ptP3, m_MapFrame.VersZ(), m_MapFrame.VersX(), lstTria) ; int nPosNord = ( nPos2 < int( m_nNy[0] - 1) ? nPos + m_nNx[0] : - 1) ; - AddDexelSideFace( nPos, nPosNord, ptP3, ptP4, m_MapFrame[0].VersZ(), m_MapFrame[0].VersY(), lstTria) ; + AddDexelSideFace( nPos, nPosNord, ptP3, ptP4, m_MapFrame.VersZ(), m_MapFrame.VersY(), lstTria) ; int nPosWest = ( nPos1 > 0 ? nPos - 1 : - 1) ; - AddDexelSideFace( nPos, nPosWest, ptP4, ptP1, m_MapFrame[0].VersZ(), - m_MapFrame[0].VersX(), lstTria) ; + AddDexelSideFace( nPos, nPosWest, ptP4, ptP1, m_MapFrame.VersZ(), - m_MapFrame.VersX(), lstTria) ; int nPosSud = ( nPos2 > 0 ? nPos - m_nNx[0] : - 1) ; - AddDexelSideFace( nPos, nPosSud, ptP1, ptP2, m_MapFrame[0].VersZ(), - m_MapFrame[0].VersY(), lstTria) ; + AddDexelSideFace( nPos, nPosSud, ptP1, ptP2, m_MapFrame.VersZ(), - m_MapFrame.VersY(), lstTria) ; return true ; } @@ -920,210 +1273,9 @@ VolZmap::ProcessCube( int nVoxI, int nVoxJ, int nVoxK, TRIA3DLIST& lstTria, TriH // Controllo per il caso piano su una griglia // con versori normali a due a due paralleli. bool bGridControl = true ; - - if ( nFeatureType != NO_FEATURE) { - - if ( nVertComp[nCompCount - 1] == 4) { - - // Ordino i 4 indici in senso crescente - for ( int nSrtInd1 = 0 ; nSrtInd1 < nVertComp[nCompCount - 1] - 1 ; ++ nSrtInd1) { - for ( int nSrtInd2 = nSrtInd1 + 1 ; nSrtInd2 < nVertComp[nCompCount - 1] ; ++ nSrtInd2) { - if ( nIndArrey[nCompCount - 1][nSrtInd1] > nIndArrey[nCompCount - 1][nSrtInd2]) - swap( nIndArrey[nCompCount - 1][nSrtInd1], nIndArrey[nCompCount - 1][nSrtInd2]) ; - } - } - - if ( ( nIndArrey[nCompCount - 1][0] == 0 && nIndArrey[nCompCount - 1][1] == 2 && - nIndArrey[nCompCount - 1][2] == 9 && nIndArrey[nCompCount - 1][3] == 10) || - ( nIndArrey[nCompCount - 1][0] == 4 && nIndArrey[nCompCount - 1][1] == 6 && - nIndArrey[nCompCount - 1][2] == 9 && nIndArrey[nCompCount - 1][3] == 10) || - ( nIndArrey[nCompCount - 1][0] == 4 && nIndArrey[nCompCount - 1][1] == 6 && - nIndArrey[nCompCount - 1][2] == 8 && nIndArrey[nCompCount - 1][3] == 11) || - ( nIndArrey[nCompCount - 1][0] == 0 && nIndArrey[nCompCount - 1][1] == 2 && - nIndArrey[nCompCount - 1][2] == 8 && nIndArrey[nCompCount - 1][3] == 11) || - ( nIndArrey[nCompCount - 1][0] == 1 && nIndArrey[nCompCount - 1][1] == 3 && - nIndArrey[nCompCount - 1][2] == 8 && nIndArrey[nCompCount - 1][3] == 9 ) || - ( nIndArrey[nCompCount - 1][0] == 1 && nIndArrey[nCompCount - 1][1] == 3 && - nIndArrey[nCompCount - 1][2] == 10 && nIndArrey[nCompCount - 1][3] == 11) || - ( nIndArrey[nCompCount - 1][0] == 5 && nIndArrey[nCompCount - 1][1] == 7 && - nIndArrey[nCompCount - 1][2] == 10 && nIndArrey[nCompCount - 1][3] == 11) || - ( nIndArrey[nCompCount - 1][0] == 5 && nIndArrey[nCompCount - 1][1] == 7 && - nIndArrey[nCompCount - 1][2] == 8 && nIndArrey[nCompCount - 1][3] == 9 )) { - - VectorField LocVecF[12], LocCompV[12] ; - - for ( int LocInd = 0 ; LocInd < 12 ; ++ LocInd) { - LocVecF[LocInd] = VecField[LocInd] ; - LocCompV[LocInd] = CompoVert[nCompCount - 1][LocInd] ; - } - - if ( ( AreSameVectorApprox( LocVecF[nIndArrey[nCompCount - 1][0]].vtNorm, LocVecF[nIndArrey[nCompCount - 1][1]].vtNorm) && - abs( LocVecF[nIndArrey[nCompCount - 1][0]].vtNorm *LocVecF[nIndArrey[nCompCount - 1][2]].vtNorm) < EPS_SMALL && - abs( LocVecF[nIndArrey[nCompCount - 1][0]].vtNorm * LocVecF[nIndArrey[nCompCount - 1][3]].vtNorm) < EPS_SMALL) || - ( AreSameVectorApprox( LocVecF[nIndArrey[nCompCount - 1][2]].vtNorm, LocVecF[nIndArrey[nCompCount - 1][3]].vtNorm) && - abs( LocVecF[nIndArrey[nCompCount - 1][2]].vtNorm * LocVecF[nIndArrey[nCompCount - 1][0]].vtNorm) < EPS_SMALL && - abs( LocVecF[nIndArrey[nCompCount - 1][2]].vtNorm * LocVecF[nIndArrey[nCompCount - 1][1]].vtNorm) < EPS_SMALL)) { - - Point3d ptBarycenter = ( LocCompV[0].ptInt + LocCompV[1].ptInt + - LocCompV[2].ptInt + LocCompV[3].ptInt) / 4 ; - - if ( abs( LocCompV[0].ptInt.x - ptBarycenter.x) < EPS_SMALL && - abs( LocCompV[1].ptInt.x - ptBarycenter.x) < EPS_SMALL && - abs( LocCompV[2].ptInt.x - ptBarycenter.x) < EPS_SMALL && - abs( LocCompV[3].ptInt.x - ptBarycenter.x) < EPS_SMALL) { - - double dXBar = ptBarycenter.x / m_dStep - 0.5 ; - int nBarLimSup = int( m_nNx[0]) ; - int nBarInd = 0 ; - - while ( nBarInd < nBarLimSup) { - - double dXInd = double( nBarInd) ; - - if ( abs( dXInd - dXBar) < EPS_SMALL) { - - bGridControl = false ; - break ; - } - ++ nBarInd ; - } - } - else if ( abs( LocCompV[0].ptInt.y - ptBarycenter.y) < EPS_SMALL && - abs( LocCompV[1].ptInt.y - ptBarycenter.y) < EPS_SMALL && - abs( LocCompV[2].ptInt.y - ptBarycenter.y) < EPS_SMALL && - abs( LocCompV[3].ptInt.y - ptBarycenter.y) < EPS_SMALL) { - - double dYBar = ptBarycenter.y / m_dStep - 0.5 ; - int nBarLimSup = int( m_nNy[0]) ; - int nBarInd = 0 ; - - while ( nBarInd < nBarLimSup) { - - double dYInd = double( nBarInd) ; - - if ( abs( dYInd - dYBar) < EPS_SMALL) { - - bGridControl = false ; - break ; - } - ++ nBarInd ; - } - } - else if ( abs( LocCompV[0].ptInt.z - ptBarycenter.z) < EPS_SMALL && - abs( LocCompV[1].ptInt.z - ptBarycenter.z) < EPS_SMALL && - abs( LocCompV[2].ptInt.z - ptBarycenter.z) < EPS_SMALL && - abs( LocCompV[3].ptInt.z - ptBarycenter.z) < EPS_SMALL) { - - double dZBar = ptBarycenter.z / m_dStep - 0.5 ; - int nBarLimSup = int( m_nNy[1]) ; - int nBarInd = 0 ; - - while ( nBarInd < nBarLimSup) { - - double dZInd = double( nBarInd) ; - - if ( abs( dZInd - dZBar) < EPS_SMALL) { - - bGridControl = false ; - break ; - } - ++ nBarInd ; - } - } - } - } - else if ( ( nIndArrey[nCompCount - 1][0] == 0 && nIndArrey[nCompCount - 1][1] == 1 && - nIndArrey[nCompCount - 1][2] == 4 && nIndArrey[nCompCount - 1][3] == 5) || - ( nIndArrey[nCompCount - 1][0] == 1 && nIndArrey[nCompCount - 1][1] == 2 && - nIndArrey[nCompCount - 1][2] == 5 && nIndArrey[nCompCount - 1][3] == 6) || - ( nIndArrey[nCompCount - 1][0] == 2 && nIndArrey[nCompCount - 1][1] == 3 && - nIndArrey[nCompCount - 1][2] == 6 && nIndArrey[nCompCount - 1][3] == 7) || - ( nIndArrey[nCompCount - 1][0] == 0 && nIndArrey[nCompCount - 1][1] == 3 && - nIndArrey[nCompCount - 1][2] == 4 && nIndArrey[nCompCount - 1][3] == 7)) { - - VectorField LocVecF[12], LocCompV[12] ; - - for ( int LocInd = 0 ; LocInd < 12 ; ++ LocInd) { - LocVecF[LocInd] = VecField[LocInd] ; - LocCompV[LocInd] = CompoVert[nCompCount - 1][LocInd] ; - } - - if ( ( AreSameVectorApprox( LocVecF[nIndArrey[nCompCount - 1][0]].vtNorm, LocVecF[nIndArrey[nCompCount - 1][2]].vtNorm) && - abs( LocVecF[nIndArrey[nCompCount - 1][0]].vtNorm * LocVecF[nIndArrey[nCompCount - 1][1]].vtNorm) < EPS_SMALL && - abs( LocVecF[nIndArrey[nCompCount - 1][0]].vtNorm * LocVecF[nIndArrey[nCompCount - 1][3]].vtNorm) < EPS_SMALL) || - ( AreSameVectorApprox( LocVecF[nIndArrey[nCompCount - 1][1]].vtNorm, LocVecF[nIndArrey[nCompCount - 1][3]].vtNorm) && - abs( LocVecF[nIndArrey[nCompCount - 1][1]].vtNorm * LocVecF[nIndArrey[nCompCount - 1][0]].vtNorm) < EPS_SMALL && - abs( LocVecF[nIndArrey[nCompCount - 1][1]].vtNorm * LocVecF[nIndArrey[nCompCount - 1][2]].vtNorm) < EPS_SMALL)) { - - Point3d ptBarycenter = ( LocCompV[0].ptInt + LocCompV[1].ptInt + - LocCompV[2].ptInt + LocCompV[3].ptInt) / 4 ; - - if ( abs( LocCompV[0].ptInt.x - ptBarycenter.x) < EPS_SMALL && - abs( LocCompV[1].ptInt.x - ptBarycenter.x) < EPS_SMALL && - abs( LocCompV[2].ptInt.x - ptBarycenter.x) < EPS_SMALL && - abs( LocCompV[3].ptInt.x - ptBarycenter.x) < EPS_SMALL) { - - double dXBar = ptBarycenter.x / m_dStep - 0.5 ; - int nBarLimSup = int( m_nNx[0]) ; - int nBarInd = 0 ; - - while ( nBarInd < nBarLimSup) { - - double dXInd = double( nBarInd) ; - - if ( abs( dXInd - dXBar) < EPS_SMALL) { - - bGridControl = false ; - break ; - } - ++ nBarInd ; - } - } - else if ( abs( LocCompV[0].ptInt.y - ptBarycenter.y) < EPS_SMALL && - abs( LocCompV[1].ptInt.y - ptBarycenter.y) < EPS_SMALL && - abs( LocCompV[2].ptInt.y - ptBarycenter.y) < EPS_SMALL && - abs( LocCompV[3].ptInt.y - ptBarycenter.y) < EPS_SMALL) { - - double dYBar = ptBarycenter.y / m_dStep - 0.5 ; - int nBarLimSup = int( m_nNy[0]) ; - int nBarInd = 0 ; - - while ( nBarInd < nBarLimSup) { - - double dYInd = double( nBarInd) ; - - if ( abs( dYInd - dYBar) < EPS_SMALL) { - - bGridControl = false ; - break ; - } - ++ nBarInd ; - } - } - else if ( abs( LocCompV[0].ptInt.z - ptBarycenter.z) < EPS_SMALL && - abs( LocCompV[1].ptInt.z - ptBarycenter.z) < EPS_SMALL && - abs( LocCompV[2].ptInt.z - ptBarycenter.z) < EPS_SMALL && - abs( LocCompV[3].ptInt.z - ptBarycenter.z) < EPS_SMALL) { - - double dZBar = ptBarycenter.z / m_dStep - 0.5 ; - int nBarLimSup = int( m_nNy[1]) ; - int nBarInd = 0 ; - - while ( nBarInd < nBarLimSup) { - - double dZInd = double( nBarInd) ; - - if ( abs( dZInd - dZBar) < EPS_SMALL) { - - bGridControl = false ; - break ; - } - ++ nBarInd ; - } - } - } - } - } + if ( nFeatureType != NO_FEATURE) { + if ( nVertComp[nCompCount - 1] == 4) + GridControl( VecField, CompoVert, nIndArrey, nVertComp, nCompCount, bGridControl) ; } // Flag ExtMC @@ -1179,10 +1331,24 @@ VolZmap::ProcessCube( int nVoxI, int nVoxJ, int nVoxK, TRIA3DLIST& lstTria, TriH // Esprimo la soluzione nel sistema di riferimento z-map Point3d ptSol = ptGravityCenter + vtFeature ; - // Limito la feature a una distanza dal baricentro pari alla diagonale del voxel - double dDistFeature = vtFeature.Len() ; - const double MAX_DIST = sqrt( 3) * N_DEXVOXRATIO * m_dStep ; - bool bOutside = ( dDistFeature > MAX_DIST) ; + // Limito la feature entro i secondi voxel vicini, + // nel caso essa esca dal reticolo la limito entro una + // distanza dal baricentro pari alla diagonale del voxel. + bool bOutside = false ; + + int nFtVxI, nFtVxJ, nFtVxK ; + if ( GetPointVoxel( ptSol, nFtVxI, nFtVxJ, nFtVxK)) { + + if ( abs( nFtVxI - nVoxI) > 2 || + abs( nFtVxJ - nVoxJ) > 2 || + abs( nFtVxK - nVoxK) > 2) + bOutside = true ; + } + else { + double dDistFeature = vtFeature.Len() ; + const double MAX_DIST = sqrt( 3) * N_DEXVOXRATIO * m_dStep ; + bOutside = ( dDistFeature > MAX_DIST) ; + } TRIA3DVECTOR triContainer ; @@ -1516,9 +1682,9 @@ VolZmap::ExtMarchingCubes( int nBlock, TRIA3DLIST& 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) ; + int nIndex = CalcIndex( i, j, k) ; // Se vi è qualche intersezione fra segmenti e superficie // continuo altrimenti passo al prossimo voxel. @@ -1788,7 +1954,7 @@ VolZmap::ExtMarchingCubes( int nBlock, TRIA3DLIST& lstTria, TriHolder& triHold) // Il triangolo è pronto CurrentTriangle.Set( VecField[i0].ptInt, VecField[i1].ptInt, VecField[i2].ptInt) ; bool bV = CurrentTriangle.Validate( true) ; - CurrentTriangle.ToGlob( m_MapFrame[0]) ; + CurrentTriangle.ToGlob( m_MapFrame) ; // Aggiungo alla lista lstTria.emplace_back( CurrentTriangle) ; @@ -1854,197 +2020,9 @@ VolZmap::ExtMarchingCubes( int nBlock, TRIA3DLIST& lstTria, TriHolder& triHold) // Controllo per il caso piano su una griglia // con versori normali a due a due paralleli. bool bGridControl = true ; - - if ( nFeatureType != NO_FEATURE) { - - if ( nVertComp[nCompCount - 1] == 4) { - - // Ordino i 4 indici in senso crescente - for ( int nSrtInd1 = 0 ; nSrtInd1 < nVertComp[nCompCount - 1] - 1 ; ++ nSrtInd1) { - for ( int nSrtInd2 = nSrtInd1 + 1 ; nSrtInd2 < nVertComp[nCompCount - 1] ; ++ nSrtInd2) { - if ( nIndArrey[nCompCount - 1][nSrtInd1] > nIndArrey[nCompCount - 1][nSrtInd2]) - swap( nIndArrey[nCompCount - 1][nSrtInd1], nIndArrey[nCompCount - 1][nSrtInd2]) ; - } - } - - if ( ( nIndArrey[nCompCount - 1][0] == 0 && nIndArrey[nCompCount - 1][1] == 2 && - nIndArrey[nCompCount - 1][2] == 9 && nIndArrey[nCompCount - 1][3] == 10) || - ( nIndArrey[nCompCount - 1][0] == 4 && nIndArrey[nCompCount - 1][1] == 6 && - nIndArrey[nCompCount - 1][2] == 9 && nIndArrey[nCompCount - 1][3] == 10) || - ( nIndArrey[nCompCount - 1][0] == 4 && nIndArrey[nCompCount - 1][1] == 6 && - nIndArrey[nCompCount - 1][2] == 8 && nIndArrey[nCompCount - 1][3] == 11) || - ( nIndArrey[nCompCount - 1][0] == 0 && nIndArrey[nCompCount - 1][1] == 2 && - nIndArrey[nCompCount - 1][2] == 8 && nIndArrey[nCompCount - 1][3] == 11) || - ( nIndArrey[nCompCount - 1][0] == 1 && nIndArrey[nCompCount - 1][1] == 3 && - nIndArrey[nCompCount - 1][2] == 8 && nIndArrey[nCompCount - 1][3] == 9 ) || - ( nIndArrey[nCompCount - 1][0] == 1 && nIndArrey[nCompCount - 1][1] == 3 && - nIndArrey[nCompCount - 1][2] == 10 && nIndArrey[nCompCount - 1][3] == 11) || - ( nIndArrey[nCompCount - 1][0] == 5 && nIndArrey[nCompCount - 1][1] == 7 && - nIndArrey[nCompCount - 1][2] == 10 && nIndArrey[nCompCount - 1][3] == 11) || - ( nIndArrey[nCompCount - 1][0] == 5 && nIndArrey[nCompCount - 1][1] == 7 && - nIndArrey[nCompCount - 1][2] == 8 && nIndArrey[nCompCount - 1][3] == 9 )) { - - VectorField LocVecF[12], LocCompV[12] ; - - for ( int LocInd = 0 ; LocInd < 12 ; ++ LocInd) { - LocVecF[LocInd] = VecField[LocInd] ; - LocCompV[LocInd] = CompoVert[nCompCount - 1][LocInd] ; - } - - if ( ( AreSameVectorApprox( LocVecF[nIndArrey[nCompCount - 1][0]].vtNorm, LocVecF[nIndArrey[nCompCount - 1][1]].vtNorm) && - abs( LocVecF[nIndArrey[nCompCount - 1][0]].vtNorm *LocVecF[nIndArrey[nCompCount - 1][2]].vtNorm) < EPS_SMALL && - abs( LocVecF[nIndArrey[nCompCount - 1][0]].vtNorm * LocVecF[nIndArrey[nCompCount - 1][3]].vtNorm) < EPS_SMALL) || - ( AreSameVectorApprox( LocVecF[nIndArrey[nCompCount - 1][2]].vtNorm, LocVecF[nIndArrey[nCompCount - 1][3]].vtNorm) && - abs( LocVecF[nIndArrey[nCompCount - 1][2]].vtNorm * LocVecF[nIndArrey[nCompCount - 1][0]].vtNorm) < EPS_SMALL && - abs( LocVecF[nIndArrey[nCompCount - 1][2]].vtNorm * LocVecF[nIndArrey[nCompCount - 1][1]].vtNorm) < EPS_SMALL)) { - - Point3d ptBarycenter = ( LocCompV[0].ptInt + LocCompV[1].ptInt + - LocCompV[2].ptInt + LocCompV[3].ptInt) / 4 ; - - if ( abs( LocCompV[0].ptInt.x - ptBarycenter.x) < EPS_SMALL && - abs( LocCompV[1].ptInt.x - ptBarycenter.x) < EPS_SMALL && - abs( LocCompV[2].ptInt.x - ptBarycenter.x) < EPS_SMALL && - abs( LocCompV[3].ptInt.x - ptBarycenter.x) < EPS_SMALL) { - - double dXBar = ptBarycenter.x / m_dStep - 0.5 ; - int nBarLimSup = int( m_nNx[0]) ; - int nBarInd = 0 ; - - while ( nBarInd < nBarLimSup) { - double dXInd = double( nBarInd) ; - if ( abs( dXInd - dXBar) < EPS_SMALL) { - bGridControl = false ; - break ; - } - ++ nBarInd ; - } - } - - else if ( abs( LocCompV[0].ptInt.y - ptBarycenter.y) < EPS_SMALL && - abs( LocCompV[1].ptInt.y - ptBarycenter.y) < EPS_SMALL && - abs( LocCompV[2].ptInt.y - ptBarycenter.y) < EPS_SMALL && - abs( LocCompV[3].ptInt.y - ptBarycenter.y) < EPS_SMALL) { - - double dYBar = ptBarycenter.y / m_dStep - 0.5 ; - int nBarLimSup = int( m_nNy[0]) ; - int nBarInd = 0 ; - - while ( nBarInd < nBarLimSup) { - double dYInd = double( nBarInd) ; - if ( abs( dYInd - dYBar) < EPS_SMALL) { - bGridControl = false ; - break ; - } - ++ nBarInd ; - } - } - - else if ( abs( LocCompV[0].ptInt.z - ptBarycenter.z) < EPS_SMALL && - abs( LocCompV[1].ptInt.z - ptBarycenter.z) < EPS_SMALL && - abs( LocCompV[2].ptInt.z - ptBarycenter.z) < EPS_SMALL && - abs( LocCompV[3].ptInt.z - ptBarycenter.z) < EPS_SMALL) { - - double dZBar = ptBarycenter.z / m_dStep - 0.5 ; - int nBarLimSup = int( m_nNy[1]) ; - int nBarInd = 0 ; - - while ( nBarInd < nBarLimSup) { - double dZInd = double( nBarInd) ; - if ( abs( dZInd - dZBar) < EPS_SMALL) { - bGridControl = false ; - break ; - } - ++ nBarInd ; - } - } - } - } - - else if ( ( nIndArrey[nCompCount - 1][0] == 0 && nIndArrey[nCompCount - 1][1] == 1 && - nIndArrey[nCompCount - 1][2] == 4 && nIndArrey[nCompCount - 1][3] == 5) || - ( nIndArrey[nCompCount - 1][0] == 1 && nIndArrey[nCompCount - 1][1] == 2 && - nIndArrey[nCompCount - 1][2] == 5 && nIndArrey[nCompCount - 1][3] == 6) || - ( nIndArrey[nCompCount - 1][0] == 2 && nIndArrey[nCompCount - 1][1] == 3 && - nIndArrey[nCompCount - 1][2] == 6 && nIndArrey[nCompCount - 1][3] == 7) || - ( nIndArrey[nCompCount - 1][0] == 0 && nIndArrey[nCompCount - 1][1] == 3 && - nIndArrey[nCompCount - 1][2] == 4 && nIndArrey[nCompCount - 1][3] == 7)) { - - VectorField LocVecF[12], LocCompV[12] ; - - for ( int LocInd = 0 ; LocInd < 12 ; ++ LocInd) { - LocVecF[LocInd] = VecField[LocInd] ; - LocCompV[LocInd] = CompoVert[nCompCount - 1][LocInd] ; - } - - if ( ( AreSameVectorApprox( LocVecF[nIndArrey[nCompCount - 1][0]].vtNorm, LocVecF[nIndArrey[nCompCount - 1][2]].vtNorm) && - abs( LocVecF[nIndArrey[nCompCount - 1][0]].vtNorm * LocVecF[nIndArrey[nCompCount - 1][1]].vtNorm) < EPS_SMALL && - abs( LocVecF[nIndArrey[nCompCount - 1][0]].vtNorm * LocVecF[nIndArrey[nCompCount - 1][3]].vtNorm) < EPS_SMALL) || - ( AreSameVectorApprox( LocVecF[nIndArrey[nCompCount - 1][1]].vtNorm, LocVecF[nIndArrey[nCompCount - 1][3]].vtNorm) && - abs( LocVecF[nIndArrey[nCompCount - 1][1]].vtNorm * LocVecF[nIndArrey[nCompCount - 1][0]].vtNorm) < EPS_SMALL && - abs( LocVecF[nIndArrey[nCompCount - 1][1]].vtNorm * LocVecF[nIndArrey[nCompCount - 1][2]].vtNorm) < EPS_SMALL)) { - - Point3d ptBarycenter = ( LocCompV[0].ptInt + LocCompV[1].ptInt + - LocCompV[2].ptInt + LocCompV[3].ptInt) / 4 ; - - if ( abs( LocCompV[0].ptInt.x - ptBarycenter.x) < EPS_SMALL && - abs( LocCompV[1].ptInt.x - ptBarycenter.x) < EPS_SMALL && - abs( LocCompV[2].ptInt.x - ptBarycenter.x) < EPS_SMALL && - abs( LocCompV[3].ptInt.x - ptBarycenter.x) < EPS_SMALL) { - - double dXBar = ptBarycenter.x / m_dStep - 0.5 ; - int nBarLimSup = int( m_nNx[0]) ; - int nBarInd = 0 ; - - while ( nBarInd < nBarLimSup) { - double dXInd = double( nBarInd) ; - if ( abs( dXInd - dXBar) < EPS_SMALL) { - bGridControl = false ; - break ; - } - ++ nBarInd ; - } - } - - else if ( abs( LocCompV[0].ptInt.y - ptBarycenter.y) < EPS_SMALL && - abs( LocCompV[1].ptInt.y - ptBarycenter.y) < EPS_SMALL && - abs( LocCompV[2].ptInt.y - ptBarycenter.y) < EPS_SMALL && - abs( LocCompV[3].ptInt.y - ptBarycenter.y) < EPS_SMALL) { - - double dYBar = ptBarycenter.y / m_dStep - 0.5 ; - int nBarLimSup = int( m_nNy[0]) ; - int nBarInd = 0 ; - - while ( nBarInd < nBarLimSup) { - double dYInd = double( nBarInd) ; - if ( abs( dYInd - dYBar) < EPS_SMALL) { - bGridControl = false ; - break ; - } - ++ nBarInd ; - } - } - - else if ( abs( LocCompV[0].ptInt.z - ptBarycenter.z) < EPS_SMALL && - abs( LocCompV[1].ptInt.z - ptBarycenter.z) < EPS_SMALL && - abs( LocCompV[2].ptInt.z - ptBarycenter.z) < EPS_SMALL && - abs( LocCompV[3].ptInt.z - ptBarycenter.z) < EPS_SMALL) { - - double dZBar = ptBarycenter.z / m_dStep - 0.5 ; - int nBarLimSup = int( m_nNy[1]) ; - int nBarInd = 0 ; - - while ( nBarInd < nBarLimSup) { - double dZInd = double( nBarInd) ; - if ( abs( dZInd - dZBar) < EPS_SMALL) { - bGridControl = false ; - break ; - } - ++ nBarInd ; - } - } - } - } - } + if ( nFeatureType != NO_FEATURE) { + if ( nVertComp[nCompCount - 1] == 4) + GridControl( VecField, CompoVert, nIndArrey, nVertComp, nCompCount, bGridControl) ; } // Flag ExtMC @@ -2100,11 +2078,25 @@ VolZmap::ExtMarchingCubes( int nBlock, TRIA3DLIST& lstTria, TriHolder& triHold) // Esprimo la soluzione nel sistema di riferimento z-map Point3d ptSol = ptGravityCenter + vtFeature ; - // Limito la feature a una distanza dal baricentro pari alla diagonale del voxel - double dDistFeature = vtFeature.Len() ; - const double MAX_DIST = sqrt( 3) * N_DEXVOXRATIO * m_dStep ; - bool bOutside = ( dDistFeature > MAX_DIST) ; - + // Limito la feature entro i secondi voxel vicini, + // nel caso essa esca dal reticolo la limito entro una + // distanza dal baricentro pari alla diagonale del voxel. + bool bOutside = false ; + + int nFtVxI, nFtVxJ, nFtVxK ; + if ( GetPointVoxel( ptSol, nFtVxI, nFtVxJ, nFtVxK)) { + + if ( abs( nFtVxI - i) > 2 || + abs( nFtVxJ - j) > 2 || + abs( nFtVxK - k) > 2) + bOutside = true ; + } + else { + double dDistFeature = vtFeature.Len() ; + const double MAX_DIST = sqrt( 3) * N_DEXVOXRATIO * m_dStep ; + bOutside = ( dDistFeature > MAX_DIST) ; + } + TRIA3DVECTOR triContainer ; // Costruisco triangoli di prova @@ -2333,7 +2325,8 @@ VolZmap::ExtMarchingCubes( int nBlock, TRIA3DLIST& lstTria, TriHolder& triHold) int nVoxIJK[3] = { i, j, k} ; Point3d ptTemp = ptSol ; Triangle3d trTemp = triContainer[ni] ; - if ( ! bBoundary || ! IsATriangleOnBorder( trTemp, ptTemp, nLimits, nVoxIJK)) + bool bTriangleOnBorder = IsATriangleOnBorder( trTemp, ptTemp, nLimits, nVoxIJK) ; + if ( ! bBoundary || ! bTriangleOnBorder) vInnerTriaTemp.emplace_back( triContainer[ni]) ; else vBorderTriaTemp.emplace_back( triContainer[ni]) ; @@ -2341,7 +2334,7 @@ VolZmap::ExtMarchingCubes( int nBlock, TRIA3DLIST& lstTria, TriHolder& triHold) } // Porto la soluzione nel sistema in cui è immerso lo Zmap - ptSol.ToGlob( m_MapFrame[0]) ; + ptSol.ToGlob( m_MapFrame) ; // Metto i triangoli negli appositi contenitori: @@ -2378,7 +2371,7 @@ VolZmap::ExtMarchingCubes( int nBlock, TRIA3DLIST& lstTria, TriHolder& triHold) triHold[nCurrent].vCompoTria.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[0]) ; + vInnerTriaTemp[ni].ToGlob( m_MapFrame) ; triHold[nCurrent].vCompoTria[nOldFeatureNum].emplace_back( vInnerTriaTemp[ni]) ; } } @@ -2414,7 +2407,7 @@ VolZmap::ExtMarchingCubes( int nBlock, TRIA3DLIST& lstTria, TriHolder& triHold) m_InterBlockTria[nBlock][nCurrent].vCompoTria.resize( nNewFeatureNum) ; for ( int ni = 0 ; ni < int( vBorderTriaTemp.size()) ; ++ ni) { // Riporto le coordinate nel sistema in cui è immerso lo Zmap - vBorderTriaTemp[ni].ToGlob( m_MapFrame[0]) ; + vBorderTriaTemp[ni].ToGlob( m_MapFrame) ; m_InterBlockTria[nBlock][nCurrent].vCompoTria[nOldFeatureNum].emplace_back( vBorderTriaTemp[ni]) ; } } @@ -2431,7 +2424,7 @@ VolZmap::ExtMarchingCubes( int nBlock, TRIA3DLIST& lstTria, TriHolder& triHold) CompoTriVert[nCompCount - 1][TriIndex+2].ptInt) ; bool bV = CurrentTriangle.Validate( true) ; // Riporto le coordinate nel sistema in cui è immerso lo Zmap - CurrentTriangle.ToGlob( m_MapFrame[0]) ; + CurrentTriangle.ToGlob( m_MapFrame) ; // Aggiungo alla lista lstTria.emplace_back( CurrentTriangle) ; } @@ -2449,7 +2442,7 @@ VolZmap::ExtMarchingCubes( int nBlock, TRIA3DLIST& lstTria, TriHolder& triHold) CompoTriVert[nCompCount - 1][TriIndex+2].ptInt) ; bool bV = CurrentTriangle.Validate( true) ; // Riporto le coordinate nel sistema in cui è immerso lo Zmap - CurrentTriangle.ToGlob( m_MapFrame[0]) ; + CurrentTriangle.ToGlob( m_MapFrame) ; // Aggiungo alla lista lstTria.emplace_back( CurrentTriangle) ; } @@ -2710,12 +2703,12 @@ VolZmap::FlipEdgesBB( TriaMatrix& InterTria) const size_t nBlocksNum = InterTria.size() ; // ciclo sui blocchi - for ( size_t tFB = 0 ; tFB < nBlocksNum - 1 ; ++ tFB) { + for ( size_t tFB = 0 ; tFB < nBlocksNum ; ++ tFB) { int nFBijk[3] ; GetBlockIJKFromN( int( tFB), nFBijk) ; - for ( size_t tLB = tFB + 1 ; tLB < nBlocksNum ; ++ tLB) { + for ( size_t tLB = tFB ; tLB < nBlocksNum ; ++ tLB) { int nLBijk[3] ; GetBlockIJKFromN( int( tLB), nLBijk) ; @@ -3526,10 +3519,10 @@ VolZmap::ProcessVoxContXY( VoxelContainer& VoxContXY, bool bPlus, TRIA3DLIST& ls Point3d ptT3( ( nMinI * N_DEXVOXRATIO + 0.5) * m_dStep, ( ( ( nMaxJ + 1) * N_DEXVOXRATIO + 0.5) * m_dStep), dCordZ) ; - ptT0.ToGlob( m_MapFrame[0]) ; - ptT1.ToGlob( m_MapFrame[0]) ; - ptT2.ToGlob( m_MapFrame[0]) ; - ptT3.ToGlob( m_MapFrame[0]) ; + ptT0.ToGlob( m_MapFrame) ; + ptT1.ToGlob( m_MapFrame) ; + ptT2.ToGlob( m_MapFrame) ; + ptT3.ToGlob( m_MapFrame) ; Triangle3d Tria0, Tria1 ; if ( bPlus) { @@ -3645,10 +3638,10 @@ VolZmap::ProcessVoxContYZ( VoxelContainer& VoxContYZ, bool bPlus, TRIA3DLIST& ls Point3d ptT3( dCordX, ( nMinJ * N_DEXVOXRATIO + 0.5) * m_dStep, ( ( ( nMaxK + 1) * N_DEXVOXRATIO + 0.5) * m_dStep)) ; - ptT0.ToGlob( m_MapFrame[0]) ; - ptT1.ToGlob( m_MapFrame[0]) ; - ptT2.ToGlob( m_MapFrame[0]) ; - ptT3.ToGlob( m_MapFrame[0]) ; + ptT0.ToGlob( m_MapFrame) ; + ptT1.ToGlob( m_MapFrame) ; + ptT2.ToGlob( m_MapFrame) ; + ptT3.ToGlob( m_MapFrame) ; Triangle3d Tria0, Tria1 ; if ( bPlus) { @@ -3764,10 +3757,10 @@ VolZmap::ProcessVoxContXZ( VoxelContainer& VoxContXZ, bool bPlus, TRIA3DLIST& ls Point3d ptT3( ( nMinI * N_DEXVOXRATIO + 0.5) * m_dStep, dCordY, ( ( ( nMaxK + 1) * N_DEXVOXRATIO + 0.5) * m_dStep)) ; - ptT0.ToGlob( m_MapFrame[0]) ; - ptT1.ToGlob( m_MapFrame[0]) ; - ptT2.ToGlob( m_MapFrame[0]) ; - ptT3.ToGlob( m_MapFrame[0]) ; + ptT0.ToGlob( m_MapFrame) ; + ptT1.ToGlob( m_MapFrame) ; + ptT2.ToGlob( m_MapFrame) ; + ptT3.ToGlob( m_MapFrame) ; Triangle3d Tria0, Tria1 ; if ( bPlus) { diff --git a/VolTriZmapVolume.cpp b/VolTriZmapVolume.cpp index 4a8cf75..79b11b4 100644 --- a/VolTriZmapVolume.cpp +++ b/VolTriZmapVolume.cpp @@ -52,6 +52,7 @@ VolZmap::SubtractIntervals( unsigned int nGrid, unsigned int nI, unsigned int nJ // Riporto le coordinate cicliche nell'ordine di partenza Vector3d vtNmi = vtNMin ; Vector3d vtNma = vtNMax ; + // Passo dalla grilgia al sistema intrinseco if ( nGrid == 1) { swap( vtNmi.x, vtNmi.z) ; swap( vtNmi.y, vtNmi.z) ; @@ -318,41 +319,7 @@ VolZmap::SubtractIntervals( unsigned int nGrid, unsigned int nI, unsigned int nJ return true ; } -//---------------------------------------------------------------------------- -bool -VolZmap::SubtractIntervals( unsigned int nGrid, const Point3d & ptP, - double dMin, double dMax, const Vector3d& vtNMin, const Vector3d& vtNMax) -{ - // Controllo che il numero di griglia sia entro i limiti. - if ( nGrid < 0 || nGrid > 2) - return false ; - // ptP è espresso nel sistema locale e viene convertito in quello intrinseco (localFrame) - Point3d ptPL = ptP ; - ptPL.ToLoc( m_MapFrame[nGrid]) ; - - double dX, dY, dZ ; // Coordinate di ptPL nel sistema intrinseco - double dhMin, dhMax ; // Altezze dMin e dMax RIESPRESSE nel sistema intrinseco (dMin e dMax sono altezze rispetto a ptP) - - dX = ptPL.x ; dY = ptPL.y ; dZ = ptPL.z ; - dhMin = dZ + dMin ; dhMax = dZ + dMax ; - - // Cerco il punto della griglia più vicino - double integerPartX = floor( dX / m_dStep) ; - double integerPartY = floor( dY / m_dStep) ; - - unsigned int i = static_cast (integerPartX) ; // Indici del punto di griglia più vicino. - unsigned int j = static_cast (integerPartY) ; // i = 0, 1, ..., m_Nx - 1 ; j = 0, 1, ..., m_Ny - 1 ; - - // Controllo che gli indici ottenuti siano nella griglia: - // se sono dentro la griglia chiamo l'altra subtract - if ( i >= 0 && i < m_nNx[nGrid] && - j >= 0 && j < m_nNy[nGrid]) - return SubtractIntervals( nGrid, i, j, dhMin, dhMax, vtNMin, vtNMax) ; - // altrimenti non succede niente - else - return true ; -} //---------------------------------------------------------------------------- bool @@ -585,46 +552,8 @@ VolZmap::AddIntervals( unsigned int nGrid, unsigned int nI, unsigned int nJ, return true ; } -//---------------------------------------------------------------------------- -bool -VolZmap::AddIntervals( unsigned int nGrid, const Point3d & ptP, - double dMin, double dMax, const Vector3d& vtNMin, const Vector3d& vtNMax) -{ -// // Controllo che il numero di griglia sia entro i limiti. -// if ( nGrid < 0 || nGrid > 2) -// return false ; -// -// // ptP è espresso nel sistema locale e viene convertito in quello intrinseco (localFrame) -// Point3d ptPL = ptP ; -// ptPL.ToLoc( m_MapFrame[nGrid]) ; -// -// double dX, dY, dZ ; // Coordinate di ptPL nel sistema intrinseco -// double dhMin, dhMax ; // Altezze dMin e dMax RIESPRESSE nel sistema intrinseco (dMin e dMax sono altezze rispetto a ptP) -// -// dX = ptPL.x ; dY = ptPL.y ; dZ = ptPL.z ; -// dhMin = dZ + dMin ; dhMax = dZ + dMax ; -// -// // Cerco il punto della griglia più vicino -// double integerPartX = floor( dX / m_dStep) ; -// double integerPartY = floor( dY / m_dStep) ; -// -// unsigned int i = static_cast (integerPartX) ; // Indici del punto di griglia più vicino. -// unsigned int j = static_cast (integerPartY) ; // i = 0, 1, ..., m_Nx - 1 ; j = 0, 1, ..., m_Ny - 1 -// -// // Controllo che gli indici ottenuti siano nella griglia: -// // se sono dentro la griglia chiamo l'altra add -// if ( i >= 0 && i < m_nNx[nGrid] && -// j >= 0 && j < m_nNy[nGrid]) -// -// return AddIntervals( nGrid, i, j, dhMin, dhMax, vtNMin, vtNMax) ; -// else -// // altrimenti non succede niente - return false ; -} - // ------------------------- LAVORAZIONI -------------------------------------------------------------------------------------- - //---------------------------------------------------------------------------- bool VolZmap::MillingStep( const Point3d& ptPs, const Vector3d& vtDs, const Point3d& ptPe, const Vector3d& vtDe) @@ -645,10 +574,10 @@ VolZmap::MillingStep( const Point3d& ptPs, const Vector3d& vtDs, const Vector3d& Point3d ptLe[3] ; ptLs[0] = ptPs ; - ptLs[0].ToLoc( m_MapFrame[0]) ; + ptLs[0].ToLoc( m_MapFrame) ; ptLe[0] = ptPe ; - ptLe[0].ToLoc( m_MapFrame[0]) ; + ptLe[0].ToLoc( m_MapFrame) ; if ( m_nMapNum > 1) { ptLs[1].x = ptLs[0].y ; ptLs[1].y = ptLs[0].z ; ptLs[1].z = ptLs[0].x ; @@ -671,11 +600,11 @@ VolZmap::MillingStep( const Point3d& ptPs, const Vector3d& vtDs, const Vector3d& Vector3d vtLe[3] ; vtLs[0] = vtDs ; - vtLs[0].ToLoc( m_MapFrame[0]) ; + vtLs[0].ToLoc( m_MapFrame) ; vtLs[0].Normalize() ; vtLe[0] = vtDe ; - vtLe[0].ToLoc( m_MapFrame[0]) ; + vtLe[0].ToLoc( m_MapFrame) ; vtLe[0].Normalize() ; if ( m_nMapNum > 1) { @@ -691,11 +620,11 @@ VolZmap::MillingStep( const Point3d& ptPs, const Vector3d& vtDs, const Vector3d& Vector3d vtALe[3] ; vtALs[0] = vtAs ; - vtALs[0].ToLoc( m_MapFrame[0]) ; + vtALs[0].ToLoc( m_MapFrame) ; vtALs[0].Normalize() ; vtALe[0] = vtAe ; - vtALe[0].ToLoc( m_MapFrame[0]) ; + vtALe[0].ToLoc( m_MapFrame) ; vtALe[0].Normalize() ; if ( m_nMapNum > 1) { diff --git a/VolZmap.cpp b/VolZmap.cpp index 261dd37..ac17387 100644 --- a/VolZmap.cpp +++ b/VolZmap.cpp @@ -58,8 +58,8 @@ VolZmap::Clear( void) m_nMapNum = 0 ; m_nNumBlock = 0 ; m_nConnectedCompoCount = 0 ; - for ( int i = 0 ; i < N_MAPS ; ++ i) { - m_MapFrame[i].Reset() ; + m_MapFrame.Reset() ; + for ( int i = 0 ; i < N_MAPS ; ++ i) { m_nNx[i] = 0 ; m_nNy[i] = 0 ; m_nDim[i] = 0 ; @@ -119,11 +119,11 @@ VolZmap::CopyFrom( const VolZmap& vzmSrc) m_nFracLin[1] = vzmSrc.m_nFracLin[1] ; m_nFracLin[2] = vzmSrc.m_nFracLin[2] ; m_nConnectedCompoCount = vzmSrc.m_nConnectedCompoCount ; + + m_MapFrame = vzmSrc.m_MapFrame ; for ( int i = 0 ; i < int ( m_nMapNum) ; ++ i) { - m_MapFrame[i] = vzmSrc.m_MapFrame[i] ; - m_nNx[i] = vzmSrc.m_nNx[i] ; m_nNy[i] = vzmSrc.m_nNy[i] ; m_nDim[i] = vzmSrc.m_nDim[i] ; @@ -228,10 +228,11 @@ VolZmap::Save( NgeWriter& ngeOut) const // passo di campionamento (distanza tra spilloni) if ( ! ngeOut.WriteDouble( m_dStep, ";", true)) return false ; - // per ogni mappa : sistema di riferimento, numero di passi in X e Y intrinseci - for ( unsigned int i = 0 ; i < m_nMapNum ; ++ i) { - if ( ! ngeOut.WriteFrame( m_MapFrame[i], ";", true)) - return false ; + // sistema di riferimento + if ( ! ngeOut.WriteFrame( m_MapFrame, ";", true)) + return false ; + // per ogni mappa : numero di passi in X e Y e quote z estremali + for ( unsigned int i = 0 ; i < m_nMapNum ; ++ i) { if ( ! ngeOut.WriteInt( m_nNx[i], ",", false)) return false ; if ( ! ngeOut.WriteInt( m_nNy[i], ",", false)) @@ -304,10 +305,11 @@ VolZmap::Load( NgeReader& ngeIn) // passo di campionamento (distanza tra spilloni) if ( ! ngeIn.ReadDouble( m_dStep, ";", true)) return false ; - // per ogni mappa : sistema di riferimento, numero di passi in X e Y intrinseci - for ( unsigned int i = 0 ; i < m_nMapNum ; ++ i) { - if ( ! ngeIn.ReadFrame( m_MapFrame[i], ";", true)) + // sistema di riferimento + if ( ! ngeIn.ReadFrame( m_MapFrame, ";", true)) return false ; + // per ogni mappa : numero di passi in X e Y e quote z estremali + for ( unsigned int i = 0 ; i < m_nMapNum ; ++ i) { if ( ! ngeIn.ReadInt( m_nNx[i], ",", false)) return false ; if ( ! ngeIn.ReadInt( m_nNy[i], ",", false)) @@ -385,23 +387,23 @@ VolZmap::GetLocalBBox( BBox3d& b3Loc, int nFlag) const if ( ( nFlag & BBF_EXACT) == 0) { b3Loc.Add( ORIG) ; b3Loc.Add( Point3d( m_nNx[0] * m_dStep, m_nNy[0] * m_dStep, m_dMaxZ[0])) ; - b3Loc.ToGlob( m_MapFrame[0]) ; + b3Loc.ToGlob( m_MapFrame) ; return true ; } // calcolo preciso // ciclo sui dexel (punti in basso con ciclo aggiunto per punti in alto di ultima riga) double dY = 0 ; for ( size_t j = 0 ; j <= m_nNy[0] ; ++ j) { - size_t jc = ( ( j != m_nNy[0]) ? j : m_nNy[0] -1) ; + size_t jc = ( ( j != m_nNy[0]) ? j : m_nNy[0] - 1) ; double dX = 0 ; // punto a sinistra di ogni dexel (aggiungo un ciclo per fare punto a destra di ultimo) for ( size_t i = 0 ; i <= m_nNx[0] ; ++ i) { - size_t ic = ( ( i != m_nNx[0]) ? i : m_nNx[0] -1) ; + size_t ic = ( ( i != m_nNx[0]) ? i : m_nNx[0] - 1) ; size_t nPos = ic + jc * m_nNx[0] ; if ( m_Values[0][nPos].size() > 0) { - Point3d ptP = m_MapFrame[0].Orig() + dX * m_MapFrame[0].VersX() + dY * m_MapFrame[0].VersY() ; - b3Loc.Add( ptP + m_Values[0][nPos][0].dMin * m_MapFrame[0].VersZ()) ; - b3Loc.Add( ptP + m_Values[0][nPos][m_Values[0][nPos].size()-1].dMax * m_MapFrame[0].VersZ()) ; + Point3d ptP = m_MapFrame.Orig() + dX * m_MapFrame.VersX() + dY * m_MapFrame.VersY() ; + b3Loc.Add( ptP + m_Values[0][nPos][0].dMin * m_MapFrame.VersZ()) ; + b3Loc.Add( ptP + m_Values[0][nPos][m_Values[0][nPos].size()-1].dMax * m_MapFrame.VersZ()) ; } // passo al punto successivo dX += m_dStep ; @@ -423,7 +425,7 @@ VolZmap::GetBBox( const Frame3d& frRef, BBox3d& b3Ref, int nFlag) const // reset box b3Ref.Reset() ; // trasformo il riferimento locale tramite quello passato - Frame3d frUse = m_MapFrame[0] ; + Frame3d frUse = m_MapFrame ; frUse.ToGlob( frRef) ; // se richiesto approssimato if ( ( nFlag & BBF_EXACT) == 0) { @@ -466,9 +468,8 @@ VolZmap::Translate( const Vector3d& vtMove) return false ; // imposto ricalcolo della grafica ResetGraphics() ; - // traslo i riferimenti - for ( int i = 0 ; i < int( m_nMapNum) ; ++ i) - m_MapFrame[i].Translate( vtMove) ; + // traslo il riferimento + m_MapFrame.Translate( vtMove) ; return true ; } @@ -481,9 +482,8 @@ VolZmap::Rotate( const Point3d& ptAx, const Vector3d& vtAx, double dCosAng, doub return false ; // imposto ricalcolo della grafica ResetGraphics() ; - // ruoto i riferimenti - for ( int i = 0 ; i < int( m_nMapNum) ; ++ i) - m_MapFrame[i].Rotate( ptAx, vtAx, dCosAng, dSinAng) ; + // ruoto il riferimento + m_MapFrame.Rotate( ptAx, vtAx, dCosAng, dSinAng) ; return true ; } @@ -526,9 +526,8 @@ VolZmap::ToGlob( const Frame3d& frRef) return false ; // imposto ricalcolo della grafica ResetGraphics() ; - // trasformo il riferimento - for ( int i = 0 ; i < int ( m_nMapNum) ; ++ i) - m_MapFrame[i].ToGlob( frRef) ; + // trasformo il riferimento + m_MapFrame.ToGlob( frRef) ; return true ; } @@ -541,9 +540,8 @@ VolZmap::ToLoc( const Frame3d& frRef) return false ; // imposto ricalcolo della grafica ResetGraphics() ; - // trasformo il riferimento - for ( int i = 0 ; i < int( m_nMapNum) ; ++ i) - m_MapFrame[i].ToLoc( frRef) ; + // trasformo il riferimento + m_MapFrame.ToLoc( frRef) ; return true ; } @@ -556,9 +554,8 @@ VolZmap::LocToLoc( const Frame3d& frOri, const Frame3d& frDest) return false ; // imposto ricalcolo della grafica ResetGraphics() ; - // trasformo il riferimento - for ( int i = 0 ; i < int( m_nMapNum) ; ++ i) - m_MapFrame[i].LocToLoc( frOri, frDest) ; + // trasformo il riferimento + m_MapFrame.LocToLoc( frOri, frDest) ; return true ; } @@ -1090,12 +1087,10 @@ VolZmap::ClonePart( int nPart) const // Dimensiono raccolta triangoli di feature tra blocchi pVolume->m_InterBlockTria.resize( pVolume->m_nNumBlock) ; - // Sistemi di riferimento delle griglie del nuovo solido + // Sistema di riferimento intrinseco del nuovo solido Point3d ptNewO( dNewOx, dNewOy, dNewOz) ; - pVolume->m_MapFrame[0].Set( ptNewO, X_AX, Y_AX, Z_AX) ; - pVolume->m_MapFrame[1].Set( ptNewO, Y_AX, Z_AX, X_AX) ; - pVolume->m_MapFrame[2].Set( ptNewO, Z_AX, X_AX, Y_AX) ; - + pVolume->m_MapFrame.Set( ptNewO, X_AX, Y_AX, Z_AX) ; + // Setto lo stato del nuovo Solido pVolume->m_nStatus = m_nStatus ; diff --git a/VolZmap.h b/VolZmap.h index 00e73b8..c6b591c 100644 --- a/VolZmap.h +++ b/VolZmap.h @@ -40,6 +40,12 @@ typedef std::vector TriHolder ; // il primo indice individua il blocco, il secondo il voxel typedef std::vector TriaMatrix ; +// ------------------------- STRUTTURA VERTICE TRIANGOLO - NORMALE ALLA SUPERFICIE ------------------------------------------------ +struct VectorField { + Point3d ptInt ; + Vector3d vtNorm ; +} ; + //---------------------------------------------------------------------------- class VolZmap : public IVolZmap, public IGeoObjRW { @@ -161,15 +167,14 @@ class VolZmap : public IVolZmap, public IGeoObjRW bool IsPointInsideVoxelApprox( int nI, int nJ, int nK, const Point3d& ptP, double dPrec = EPS_SMALL) const ; bool GetPointVoxel( const Point3d& ptP, int& nVoxI, int& nVoxJ, int& nVoxK) const ; bool IsZInsideInterval( int nGrid, int nDex, double dZ) const ; + bool GridControl( VectorField VecField[], VectorField CompoVert[][12], + int nIndArrey[][4], int nVertComp[], int nCompCount, bool& bGridControl) const ; // OPERAZIONI SU INTERVALLI bool SubtractIntervals( unsigned int nGrid, unsigned int nI, unsigned int nJ, double dMin, double dMax, const Vector3d& vtNMin, const Vector3d& vtNMax) ; - bool SubtractIntervals( unsigned int nGrid, const Point3d& ptP, - double dMin, double dMax, const Vector3d& vtNMin, const Vector3d& vtNMax) ; bool AddIntervals( unsigned int nGrid, unsigned int nI, unsigned int nJ, double dMin, double dMax, const Vector3d& vtNMin, const Vector3d& vtNMax) ; - bool AddIntervals( unsigned int nGrid, const Point3d& ptP, - double dMin, double dMax, const Vector3d& vtNMin, const Vector3d& vtNMax) ; + // SOTTRAZIONI // UTENSILI @@ -252,7 +257,7 @@ class VolZmap : public IVolZmap, public IGeoObjRW bool IntersLineBox( const Point3d& ptP, const Vector3d& vtV, const Point3d& ptMin, const Point3d& ptMax, double& dU1, double& dU2) const ; bool IntersLineZMapLattice( const Point3d& ptP, const Vector3d& vtV, double& dU1, double& dU2) const ; - bool IntersLineZMapBBox( const Point3d& ptP, const Vector3d& vtV, unsigned int nGrid, double& dU1, double& dU2) const ; + bool IntersLineZMapBBox( const Point3d& ptP, const Vector3d& vtV, double& dU1, double& dU2) const ; bool IntersLineDexel( const Point3d& ptP, const Vector3d& vtV, unsigned int nGrid, unsigned int nI, unsigned int nJ, double& dU1, double& dU2) const ; bool IntersRayDexel( const Point3d& ptP, const Vector3d& vtV, unsigned int nGrid, unsigned int nI, unsigned int nJ, @@ -323,7 +328,7 @@ class VolZmap : public IVolZmap, public IGeoObjRW int m_nTempProp ; // proprietà temporanea double m_dStep ; // passo delle griglie unsigned int m_nMapNum ; // numero di griglie ( 1 o 3) - Frame3d m_MapFrame[N_MAPS] ; // riferimenti delle griglie + Frame3d m_MapFrame ; // riferimento intrinseco dello Zmap unsigned int m_nNx[N_MAPS] ; // dimensione di ciascuna griglia in X unsigned int m_nNy[N_MAPS] ; // dimensione di ciascuna griglia in Y unsigned int m_nDim[N_MAPS] ; // dimensione di ciascuna griglia ( X * Y)