From 06a69fa66bcb434ccfa6597fd4c225af5912476d Mon Sep 17 00:00:00 2001 From: Daniele Bariletti Date: Thu, 15 Jun 2023 15:28:04 +0200 Subject: [PATCH] EgtGeomKernel : - pulizia del codice Problemi : - bug dovuto a problemi numerici sulle intersezione tra trim e celle --- Tree.cpp | 847 ++++++++++++++++++++++++------------------------------- Tree.h | 74 +++-- 2 files changed, 408 insertions(+), 513 deletions(-) diff --git a/Tree.cpp b/Tree.cpp index c8245c4..c4022ed 100644 --- a/Tree.cpp +++ b/Tree.cpp @@ -28,7 +28,7 @@ //---------------------------------------------------------------------------- Cell::Cell( void) : m_nId( -1),m_nTop ( -2), m_nBottom( -2), m_nLeft( -2), m_nRight ( -2), m_nParent( -2), m_nDepth( 0), - m_nChild1( -2), m_nChild2( -2), m_nFlag( -1), m_nFlag2( 0), m_nRightEdgeIn( -1), m_ptPbl(ORIG), m_ptPtr(), m_bProcessed(false), m_bSplitVert(true) + m_nChild1( -2), m_nChild2( -2), m_nFlag( -1), m_nFlag2( 0), m_nRightEdgeIn( -1), m_ptPbl( ORIG), m_ptPtr(), m_bProcessed( false), m_bSplitVert( true) { Point3d ptTr ( 1 * SBZ_TREG_COEFF, 1 * SBZ_TREG_COEFF) ; m_ptPtr = ptTr ; @@ -36,9 +36,9 @@ Cell::Cell( void) //---------------------------------------------------------------------------- -Cell::Cell( Point3d& ptBL, Point3d& ptTR) +Cell::Cell( const Point3d& ptBL, const Point3d& ptTR) : m_nId( -1),m_nTop ( -2), m_nBottom( -2), m_nLeft( -2), m_nRight ( -2), m_nParent( -2), m_nDepth( 0), - m_nChild1( -2), m_nChild2( -2), m_nFlag( -1), m_nFlag2( 0), m_nRightEdgeIn( -1), m_ptPbl(ptBL), m_ptPtr(ptTR), m_bProcessed(false), m_bSplitVert(true) + m_nChild1( -2), m_nChild2( -2), m_nFlag( -1), m_nFlag2( 0), m_nRightEdgeIn( -1), m_ptPbl( ptBL), m_ptPtr( ptTR), m_bProcessed( false), m_bSplitVert( true) {} @@ -77,7 +77,7 @@ Tree::Tree( void) } //---------------------------------------------------------------------------- -Tree::Tree( const SurfBezier* pSrfBz, bool bSplitPatches) +Tree::Tree( const SurfBezier* pSrfBz, const bool bSplitPatches) : m_bBilinear( false), m_bMulti( false), m_bClosed( false), m_bSplitPatches( bSplitPatches) { SetSurf( pSrfBz, m_bSplitPatches) ; @@ -90,7 +90,7 @@ Tree::~Tree( void) //---------------------------------------------------------------------------- void -Tree::SetSurf( const SurfBezier* pSrfBz, bool bSplitPatches) +Tree::SetSurf( const SurfBezier* pSrfBz, const bool bSplitPatches) { m_pSrfBz = pSrfBz ; m_bSplitPatches = bSplitPatches ; @@ -111,45 +111,17 @@ Tree::SetSurf( const SurfBezier* pSrfBz, bool bSplitPatches) if ( m_bTrimmed) { int nLoop = 0 ; INTVECTOR vChunk ; - // dalla superficie recupero un vettore con i loop di trim - // - //PtrOwner pLoop( GetBasicCurveComposite( m_pSrfBz->GetLoop( nLoop))) ; - //while ( ! IsNull( pLoop) && pLoop->IsValid()) { - // if ( nLoop == 0) { - // m_vLoop.push_back( Release( pLoop)) ; - // vChunck.push_back( nLoop) ; - // ++ nLoop ; - // } - // else { - // // se il loop corrente è contenuto nel precedente e sono girati in verso opposto, allora lo aggiungo allo stesso chunk - // if ( ) { - - // } - // // salvo il precedente chunk e creo un nuovo chunk - // else { - // m_vChunk.push_back( vChunk) ; - // vChunk.clear() ; - // vChunk.push_back( nLoop) ; - // } - // ++ nLoop ; - // PtrOwner pLoop( GetBasicCurveComposite( m_pSrfBz->GetLoop( nLoop))) ; - // } - //} // recupero la superficie di trim per avere accesso diretto ai loop e mantenendo le informazioni sui chunk - Frame3d frSurf ; - //const SurfFlatRegion* pTrimReg_( m_pSrfBz->GetTrimRegion()) ; - //PtrOwner pTrimReg( pTrimReg_->Clone()) ; PtrOwner pTrimReg( m_pSrfBz->GetTrimRegion()->Clone()) ; for ( int i = 0 ; i < pTrimReg->GetChunkCount() ; ++ i) { PtrOwner pChunk( pTrimReg->CloneChunk( i)) ; - //pChunk->Scale( frSurf, 1./ SBZ_TREG_COEFF, 1./ SBZ_TREG_COEFF, 1) ; for ( int j = 0 ; j < pChunk->GetLoopCount( 0) ; ++ j) { vChunk.push_back( nLoop) ; // i chunk della superficie orignale non possono avere dei sub chunk - PtrOwner pLoop (pChunk->GetLoop(0, j)) ; - m_vLoop.emplace_back( Release( pLoop )) ; + PtrOwner pLoop ( pChunk->GetLoop( 0, j)) ; + m_vLoop.emplace_back( Release( pLoop)) ; m_mChunk[nLoop] = i ; ++ nLoop ; } @@ -165,13 +137,13 @@ Tree::SetSurf( const SurfBezier* pSrfBz, bool bSplitPatches) Point3d ptP00, ptP10, ptP11, ptP01 ; bool bOk = false ; PNTVECTOR vVert ; - ptP00 = m_pSrfBz->GetControlPoint( 0, &bOk); + ptP00 = m_pSrfBz->GetControlPoint( 0, &bOk) ; vVert.push_back( ptP00) ; ptP10 = m_pSrfBz->GetControlPoint( nDegU * nSpanU, &bOk) ; vVert.push_back( ptP10) ; ptP11 = m_pSrfBz->GetControlPoint( ( nDegU * nSpanU + 1) * ( nDegV * nSpanV + 1) - 1, &bOk) ; vVert.push_back( ptP11) ; - ptP01 = m_pSrfBz->GetControlPoint( ( nDegU * nSpanU + 1 ) * ( nDegV * nSpanV), &bOk) ; + ptP01 = m_pSrfBz->GetControlPoint( ( nDegU * nSpanU + 1) * ( nDegV * nSpanV), &bOk) ; vVert.push_back( ptP01) ; m_mVert.insert( std::pair( -1, vVert)) ; // se richiesto divido preliminarmente le patches @@ -186,7 +158,7 @@ Tree::SetSurf( const SurfBezier* pSrfBz, bool bSplitPatches) INTVECTOR vLeaves ; GetHeightLeaves( -1, vLeaves) ; for ( int nId : vLeaves) { - for ( int j = nSpanV - 1 ; j > 0 ; --j ) { + for ( int j = nSpanV - 1 ; j > 0 ; --j) { m_mTree[nId].SetSplitDirVert( false) ; Split( nId, j * SBZ_TREG_COEFF) ; nId = m_mTree[nId].m_nChild2 ; @@ -202,11 +174,11 @@ Tree::SetSurf( const SurfBezier* pSrfBz, bool bSplitPatches) if ( ( AreSamePointApprox( ptP00, ptP01) && AreSamePointApprox( ptP10, ptP11)) || ( AreSamePointApprox( ptP00, ptP10) && AreSamePointApprox( ptP01, ptP11))) { m_bClosed = true ; - if ( AreSamePointApprox(ptP00, ptP01)) { + if ( AreSamePointApprox( ptP00, ptP01)) { m_mTree[-1].m_nTop = -1 ; m_mTree[-1].m_nBottom = -1 ; m_mTree[-1].SetSplitDirVert( false) ; - Split(-1) ; + Split( -1) ; // qui devo fare il controllo capped // devo controllare se i punti ai parametri U=0 e U=1 sono tutti coincidenti // in caso devo fare uno split nell'altra direzione @@ -227,7 +199,7 @@ Tree::SetSurf( const SurfBezier* pSrfBz, bool bSplitPatches) Split( 1) ; } } - if ( AreSamePointApprox(ptP00, ptP10)) { + if ( AreSamePointApprox( ptP00, ptP10)) { if( (int) m_mTree.size() == 1) { m_mTree[-1].m_nLeft = -1 ; m_mTree[-1].m_nRight = -1 ; @@ -242,7 +214,7 @@ Tree::SetSurf( const SurfBezier* pSrfBz, bool bSplitPatches) for ( int i = 1 ; i < nDegU * nSpanU + 1 ; ++ i) { ptU0 = m_pSrfBz->GetControlPoint( i, &bOk) ; bCapped0 = bCapped0 && AreSamePointApprox( ptP00, ptU0) ; - ptU1 = m_pSrfBz->GetControlPoint( i + ( nDegU * nSpanU + 1 ) * ( nDegV * nSpanV), &bOk) ; + ptU1 = m_pSrfBz->GetControlPoint( i + ( nDegU * nSpanU + 1) * ( nDegV * nSpanV), &bOk) ; bCapped1 = bCapped1 && AreSamePointApprox( ptP01, ptU1) ; } if ( bCapped0 && bCapped1) { @@ -279,7 +251,7 @@ Tree::SetSurf( const SurfBezier* pSrfBz, bool bSplitPatches) //---------------------------------------------------------------------------- void -Tree::Split( int nId, double dSplitValue) +Tree::Split( const int& nId, const double& dSplitValue) { // controllo che lo split non venga fatto sul lato della cella if ( ( m_mTree[nId].IsSplitVert() && dSplitValue > m_mTree[nId].GetBottomLeft().x + EPS_SMALL && dSplitValue < m_mTree[nId].GetTopRight().x - EPS_SMALL) || @@ -366,7 +338,7 @@ Tree::Split( int nId, double dSplitValue) //---------------------------------------------------------------------------- void -Tree::Split( int nId) +Tree::Split( const int& nId) { double dValue ; if ( m_mTree[nId].IsSplitVert()) @@ -453,7 +425,7 @@ Tree::BuildTree( double dLinTol, double dSideMin, double dSideMax) // ptP00P10 è un punto tra P00 e P10 double dCurvU = 0, dCurvV = 0 ; double dLenParU = ( m_mTree[nCToSplit].GetTopRight().x - m_mTree[nCToSplit].GetBottomLeft().x) / SBZ_TREG_COEFF ; - double dLenParV = ( m_mTree[nCToSplit].GetTopRight().y - m_mTree[nCToSplit].GetBottomLeft().y) / SBZ_TREG_COEFF; + double dLenParV = ( m_mTree[nCToSplit].GetTopRight().y - m_mTree[nCToSplit].GetBottomLeft().y) / SBZ_TREG_COEFF ; if ( dLenParU <= 1. / m_nDegV || dLenParV <= 1. / m_nDegU) { double dU = ( m_mTree[nCToSplit].GetTopRight().x + m_mTree[nCToSplit].GetBottomLeft().x) / 2 / SBZ_TREG_COEFF ; double dV = ( m_mTree[nCToSplit].GetTopRight().y + m_mTree[nCToSplit].GetBottomLeft().y) / 2 / SBZ_TREG_COEFF ; @@ -472,11 +444,11 @@ Tree::BuildTree( double dLinTol, double dSideMin, double dSideMax) // faccio un'analisi più fine della curvatura se almeno il grado di una curva di uno dei due parametri è alto e // se sto ancora guardando una cella abbastanza grande else{ - Point3d ptPSrf, ptP00P10, ptP10P11, ptP11P01, ptP01P00, ptPSrfMid; + Point3d ptPSrf, ptP00P10, ptP10P11, ptP11P01, ptP01P00, ptPSrfMid ; double dStep = 1. / m_nDegU ; for ( double k = dStep ; k < 1 ; k = k + dStep) { double dU = ( k * m_mTree[nCToSplit].GetTopRight().x + ( 1 - k) * m_mTree[nCToSplit].GetBottomLeft().x) / SBZ_TREG_COEFF ; - double dV = ( m_mTree[nCToSplit].GetTopRight().y + m_mTree[nCToSplit].GetBottomLeft().y) / 2 / SBZ_TREG_COEFF; + double dV = ( m_mTree[nCToSplit].GetTopRight().y + m_mTree[nCToSplit].GetBottomLeft().y) / 2 / SBZ_TREG_COEFF ; m_pSrfBz->GetPointD1D2( dU, dV, ISurfBezier::FROM_MINUS, ISurfBezier::FROM_MINUS, ptPSrf) ; if ( k == 0.5) ptPSrfMid = ptPSrf ; @@ -568,7 +540,7 @@ Tree::BuildTree( double dLinTol, double dSideMin, double dSideMax) int nStepsV = int( 51 * dDimV + 5 * ( 1 - dDimV)) ; for ( int u = 0 ; u < nStepsU && ! bSplit ; ++ u) { double dU = double ( u) / double ( nStepsU - 1) ; - double dULoc = (( 1 - dU) * m_mTree[nCToSplit].GetBottomLeft().x + dU * m_mTree[nCToSplit].GetTopRight().x) / SBZ_TREG_COEFF ; + double dULoc = ( ( 1 - dU) * m_mTree[nCToSplit].GetBottomLeft().x + dU * m_mTree[nCToSplit].GetTopRight().x) / SBZ_TREG_COEFF ; if ( ! m_pSrfBz->GetPointD1D2( dULoc, m_mTree[nCToSplit].GetBottomLeft().y / SBZ_TREG_COEFF, ISurfBezier::FROM_MINUS, ISurfBezier::FROM_MINUS, ptBz0) || ! m_pSrfBz->GetPointD1D2( dULoc, m_mTree[nCToSplit].GetTopRight().y / SBZ_TREG_COEFF, ISurfBezier::FROM_MINUS, ISurfBezier::FROM_MINUS, ptBz1)) return false ; @@ -652,7 +624,7 @@ Tree::BuildTree( double dLinTol, double dSideMin, double dSideMax) double dDistU = 0, dDistV = 0 ; PNTVECTOR vPtU, vPtV ; if ( ! m_bMulti) { - if ( std::max(dLen0, dLen2) > std::max(dLen1, dLen3)) { + if ( std::max( dLen0, dLen2) > std::max( dLen1, dLen3)) { bVert = true ; } else { @@ -660,9 +632,9 @@ Tree::BuildTree( double dLinTol, double dSideMin, double dSideMax) } } else { - for ( double i = 0.25 ; i < 1 ; i = i + 0.25 ) { - dU = (( 1 - i) * m_mTree[nCToSplit].GetBottomLeft().x + i * m_mTree[nCToSplit].GetTopRight().x) / SBZ_TREG_COEFF ; - dV = (( 1 - i) * m_mTree[nCToSplit].GetBottomLeft().y + i * m_mTree[nCToSplit].GetTopRight().y) / SBZ_TREG_COEFF ; + for ( double i = 0.25 ; i < 1 ; i = i + 0.25) { + dU = ( ( 1 - i) * m_mTree[nCToSplit].GetBottomLeft().x + i * m_mTree[nCToSplit].GetTopRight().x) / SBZ_TREG_COEFF ; + dV = ( ( 1 - i) * m_mTree[nCToSplit].GetBottomLeft().y + i * m_mTree[nCToSplit].GetTopRight().y) / SBZ_TREG_COEFF ; double dVLoc = ( m_mTree[nCToSplit].GetBottomLeft().y + m_mTree[nCToSplit].GetTopRight().y) / 2 / SBZ_TREG_COEFF ; double dULoc = ( m_mTree[nCToSplit].GetBottomLeft().x + m_mTree[nCToSplit].GetTopRight().x) / 2 / SBZ_TREG_COEFF ; m_pSrfBz->GetPointD1D2( dU, dVLoc, ISurfBezier::FROM_MINUS, ISurfBezier::FROM_MINUS, ptPSrfU) ; @@ -671,9 +643,9 @@ Tree::BuildTree( double dLinTol, double dSideMin, double dSideMax) vPtV.push_back( ptPSrfV) ; } // devo guardare se i tre punti in vPtU e vPtV sono allineati - CurveLine clU, clV; - clU.Set(vPtU[0], vPtU[1]) ; - clV.Set(vPtV[0], vPtV[1]) ; + CurveLine clU, clV ; + clU.Set( vPtU[0], vPtU[1]) ; + clV.Set( vPtV[0], vPtV[1]) ; DistPointCurve dpcU( vPtU[2], clU, false) ; DistPointCurve dpcV( vPtV[2], clV, false) ; dpcU.GetDist( dDistU) ; @@ -726,7 +698,7 @@ Tree::BuildTree( double dLinTol, double dSideMin, double dSideMax) } } else { - dErr = 1. / 4. * ( (ptP00 - ptP01) + (ptP11 - ptP10)).Len() ; + dErr = 1. / 4. * ( ( ptP00 - ptP01) + ( ptP11 - ptP10)).Len() ; } // se la cella è abbastanza grande da poter essere divisa ancora e devo approssimare meglio, la divido if ( dSideMinVal / 2 >= dSideMin && dSideMaxVal < dSideMax && dErr > dLinTol) { @@ -776,7 +748,7 @@ Tree::BuildTree( double dLinTol, double dSideMin, double dSideMax) void Tree::Balance() { - //for ( int i : vCheck ) { + //for ( int i : vCheck) { // // non ancora implementato // // rendo il tree balanced : ogni foglia deve avere una profondità di +- 1 rispetto alle foglie adiacenti. //} @@ -787,77 +759,77 @@ Tree::Balance() //---------------------------------------------------------------------------- void -Tree::GetTopNeigh( int nId, INTVECTOR& vTopNeighs) const +Tree::GetTopNeigh( const int& nId, INTVECTOR& vTopNeighs) const { if ( (int) vTopNeighs.size() == 0) { - if ( m_mTree.at(nId).m_nTop == -2) + if ( m_mTree.at( nId).m_nTop == -2) return ; - if ( m_mTree.at(m_mTree.at(nId).m_nTop).IsLeaf()) - vTopNeighs.push_back( m_mTree.at(nId).m_nTop) ; + if ( m_mTree.at( m_mTree.at( nId).m_nTop).IsLeaf()) + vTopNeighs.push_back( m_mTree.at( nId).m_nTop) ; else { - if ( m_mTree.at(m_mTree.at(nId).m_nTop).IsSplitVert()) { + if ( m_mTree.at( m_mTree.at( nId).m_nTop).IsSplitVert()) { // se la cella vicina è più piccola della cella indagata, allora entrambi i figli saranno vicini di quest'ultima - if ( m_mTree.at(m_mTree.at(nId).m_nTop).GetTopRight().x - m_mTree.at(m_mTree.at(nId).m_nTop).GetBottomLeft().x <= - m_mTree.at(nId).GetTopRight().x - m_mTree.at(nId).GetBottomLeft().x) { - vTopNeighs.push_back( m_mTree.at(m_mTree.at(nId).m_nTop).m_nChild1) ; - vTopNeighs.push_back( m_mTree.at(m_mTree.at(nId).m_nTop).m_nChild2) ; + if ( m_mTree.at( m_mTree.at( nId).m_nTop).GetTopRight().x - m_mTree.at( m_mTree.at( nId).m_nTop).GetBottomLeft().x <= + m_mTree.at( nId).GetTopRight().x - m_mTree.at( nId).GetBottomLeft().x) { + vTopNeighs.push_back( m_mTree.at( m_mTree.at( nId).m_nTop).m_nChild1) ; + vTopNeighs.push_back( m_mTree.at( m_mTree.at( nId).m_nTop).m_nChild2) ; } // altrimenti solo uno dei figli lo sarà else{ - if ( m_mTree.at(m_mTree.at(m_mTree.at(nId).m_nTop).m_nChild1).GetTopRight().x <= m_mTree.at(nId).GetBottomLeft().x || - m_mTree.at(m_mTree.at(m_mTree.at(nId).m_nTop).m_nChild1).GetBottomLeft().x >= m_mTree.at(nId).GetTopRight().x ) - vTopNeighs.push_back( m_mTree.at(m_mTree.at(nId).m_nTop).m_nChild2) ; + if ( m_mTree.at( m_mTree.at( m_mTree.at( nId).m_nTop).m_nChild1).GetTopRight().x <= m_mTree.at( nId).GetBottomLeft().x || + m_mTree.at( m_mTree.at( m_mTree.at( nId).m_nTop).m_nChild1).GetBottomLeft().x >= m_mTree.at( nId).GetTopRight().x ) + vTopNeighs.push_back( m_mTree.at( m_mTree.at( nId).m_nTop).m_nChild2) ; else - vTopNeighs.push_back( m_mTree.at(m_mTree.at(nId).m_nTop).m_nChild1) ; + vTopNeighs.push_back( m_mTree.at( m_mTree.at( nId).m_nTop).m_nChild1) ; } } else { - vTopNeighs.push_back( m_mTree.at(m_mTree.at(nId).m_nTop).m_nChild2) ; + vTopNeighs.push_back( m_mTree.at( m_mTree.at( nId).m_nTop).m_nChild2) ; } } bool bAllLeaves = true ; - for ( int i : vTopNeighs ) { - if ( ! m_mTree.at(i).IsLeaf()) + for ( int i : vTopNeighs) { + if ( ! m_mTree.at( i).IsLeaf()) bAllLeaves = false ; } - if ( ! bAllLeaves ) + if ( ! bAllLeaves) // almeno una cella tra i vicini trovati non è leaf quindi devo richiamare ricorsivamente questa funzione per trovare i suoi child GetTopNeigh( nId, vTopNeighs) ; } else { for ( int j = 0 ; j != (int) vTopNeighs.size() ; ++ j) { - int i = vTopNeighs.at(j) ; - if ( m_mTree.at(i).IsLeaf()) - continue; + int i = vTopNeighs.at( j) ; + if ( m_mTree.at( i).IsLeaf()) + continue ; else { // se la cella non è leaf la tolgo dal vettore delle foglie e aggiungo invece i suoi child vTopNeighs.erase( remove( vTopNeighs.begin(),vTopNeighs.end(),i)) ; -- j ; - if ( m_mTree.at(i).IsSplitVert() ) { + if ( m_mTree.at( i).IsSplitVert()) { // se la cella è più piccola della cella indagata, allora entrambi i figli saranno vicini di quest'ultima - if ( m_mTree.at(i).GetTopRight().x - m_mTree.at(i).GetBottomLeft().x <= - m_mTree.at(nId).GetTopRight().x - m_mTree.at(nId).GetBottomLeft().x) { - vTopNeighs.push_back( m_mTree.at(i).m_nChild1) ; - vTopNeighs.push_back( m_mTree.at(i).m_nChild2) ; + if ( m_mTree.at( i).GetTopRight().x - m_mTree.at( i).GetBottomLeft().x <= + m_mTree.at( nId).GetTopRight().x - m_mTree.at( nId).GetBottomLeft().x) { + vTopNeighs.push_back( m_mTree.at( i).m_nChild1) ; + vTopNeighs.push_back( m_mTree.at( i).m_nChild2) ; } // altrimenti solo uno dei figli lo sarà else { - if ( m_mTree.at(m_mTree.at(i).m_nChild1).GetTopRight().x <= m_mTree.at(nId).GetBottomLeft().x || - m_mTree.at(m_mTree.at(i).m_nChild1).GetBottomLeft().x >= m_mTree.at(nId).GetTopRight().x ) - vTopNeighs.push_back( m_mTree.at(i).m_nChild2) ; + if ( m_mTree.at( m_mTree.at( i).m_nChild1).GetTopRight().x <= m_mTree.at( nId).GetBottomLeft().x || + m_mTree.at( m_mTree.at( i).m_nChild1).GetBottomLeft().x >= m_mTree.at( nId).GetTopRight().x ) + vTopNeighs.push_back( m_mTree.at( i).m_nChild2) ; else - vTopNeighs.push_back( m_mTree.at(i).m_nChild1) ; + vTopNeighs.push_back( m_mTree.at( i).m_nChild1) ; } } else { - vTopNeighs.push_back( m_mTree.at(i).m_nChild2) ; + vTopNeighs.push_back( m_mTree.at( i).m_nChild2) ; } } } } std::vector vCells ; for ( int k : vTopNeighs) - vCells.push_back( m_mTree.at(k)) ; + vCells.push_back( m_mTree.at( k)) ; std::sort( vCells.begin(), vCells.end(), Cell::minorX) ; vTopNeighs.clear() ; for ( Cell c : vCells) @@ -867,77 +839,77 @@ Tree::GetTopNeigh( int nId, INTVECTOR& vTopNeighs) const //---------------------------------------------------------------------------- void -Tree::GetBottomNeigh( int nId, INTVECTOR& vBottomNeighs) const +Tree::GetBottomNeigh( const int& nId, INTVECTOR& vBottomNeighs) const { if ( (int) vBottomNeighs.size() == 0) { - if ( m_mTree.at(nId).m_nBottom == -2) + if ( m_mTree.at( nId).m_nBottom == -2) return ; - if ( m_mTree.at(m_mTree.at(nId).m_nBottom).IsLeaf()) - vBottomNeighs.push_back( m_mTree.at(nId).m_nBottom) ; + if ( m_mTree.at( m_mTree.at( nId).m_nBottom).IsLeaf()) + vBottomNeighs.push_back( m_mTree.at( nId).m_nBottom) ; else { - if ( m_mTree.at(m_mTree.at(nId).m_nBottom).IsSplitVert()) { + if ( m_mTree.at( m_mTree.at( nId).m_nBottom).IsSplitVert()) { // se la cella vicina è più piccola della cella indagata, allora entrambi i figli saranno vicini di quest'ultima - if ( m_mTree.at(m_mTree.at(nId).m_nBottom).GetTopRight().x - m_mTree.at(m_mTree.at(nId).m_nBottom).GetBottomLeft().x <= - m_mTree.at(nId).GetTopRight().x - m_mTree.at(nId).GetBottomLeft().x) { - vBottomNeighs.push_back( m_mTree.at(m_mTree.at(nId).m_nBottom).m_nChild1) ; - vBottomNeighs.push_back( m_mTree.at(m_mTree.at(nId).m_nBottom).m_nChild2) ; + if ( m_mTree.at( m_mTree.at( nId).m_nBottom).GetTopRight().x - m_mTree.at( m_mTree.at( nId).m_nBottom).GetBottomLeft().x <= + m_mTree.at( nId).GetTopRight().x - m_mTree.at( nId).GetBottomLeft().x) { + vBottomNeighs.push_back( m_mTree.at( m_mTree.at( nId).m_nBottom).m_nChild1) ; + vBottomNeighs.push_back( m_mTree.at( m_mTree.at( nId).m_nBottom).m_nChild2) ; } // altrimenti solo uno dei figli lo sarà else{ - if ( m_mTree.at(m_mTree.at(m_mTree.at(nId).m_nBottom).m_nChild1).GetTopRight().x <= m_mTree.at(nId).GetBottomLeft().x || - m_mTree.at(m_mTree.at(m_mTree.at(nId).m_nBottom).m_nChild1).GetBottomLeft().x >= m_mTree.at(nId).GetTopRight().x ) - vBottomNeighs.push_back( m_mTree.at(m_mTree.at(nId).m_nBottom).m_nChild2) ; + if ( m_mTree.at( m_mTree.at( m_mTree.at( nId).m_nBottom).m_nChild1).GetTopRight().x <= m_mTree.at( nId).GetBottomLeft().x || + m_mTree.at( m_mTree.at( m_mTree.at( nId).m_nBottom).m_nChild1).GetBottomLeft().x >= m_mTree.at( nId).GetTopRight().x ) + vBottomNeighs.push_back( m_mTree.at( m_mTree.at( nId).m_nBottom).m_nChild2) ; else - vBottomNeighs.push_back( m_mTree.at(m_mTree.at(nId).m_nBottom).m_nChild1) ; + vBottomNeighs.push_back( m_mTree.at( m_mTree.at( nId).m_nBottom).m_nChild1) ; } } else { - vBottomNeighs.push_back( m_mTree.at(m_mTree.at(nId).m_nBottom).m_nChild1) ; + vBottomNeighs.push_back( m_mTree.at( m_mTree.at( nId).m_nBottom).m_nChild1) ; } } bool bAllLeaves = true ; for ( int i : vBottomNeighs) { - if ( ! m_mTree.at(i).IsLeaf()) + if ( ! m_mTree.at( i).IsLeaf()) bAllLeaves = false ; } - if ( ! bAllLeaves ) + if ( ! bAllLeaves) // almeno una cella tra i vicini trovati non è leaf quindi devo richiamare ricorsivamente questa funzione per trovare i suoi child GetBottomNeigh( nId, vBottomNeighs) ; } else { for ( int j = 0 ; j != (int) vBottomNeighs.size() ; ++ j) { - int i = vBottomNeighs.at(j) ; - if ( m_mTree.at(i).IsLeaf()) - continue; + int i = vBottomNeighs.at( j) ; + if ( m_mTree.at( i).IsLeaf()) + continue ; else { // se la cella non è leaf la tolgo dal vettore delle foglie e aggiungo invece i suoi child vBottomNeighs.erase( remove( vBottomNeighs.begin(),vBottomNeighs.end(),i)) ; -- j ; - if ( m_mTree.at(i).IsSplitVert()) { + if ( m_mTree.at( i).IsSplitVert()) { // se la cella è più piccola della cella indagata, allora entrambi i figli saranno vicini di quest'ultima - if ( m_mTree.at(i).GetTopRight().x - m_mTree.at(i).GetBottomLeft().x <= - m_mTree.at(nId).GetTopRight().x - m_mTree.at(nId).GetBottomLeft().x) { - vBottomNeighs.push_back( m_mTree.at(i).m_nChild1) ; - vBottomNeighs.push_back( m_mTree.at(i).m_nChild2) ; + if ( m_mTree.at( i).GetTopRight().x - m_mTree.at( i).GetBottomLeft().x <= + m_mTree.at( nId).GetTopRight().x - m_mTree.at( nId).GetBottomLeft().x) { + vBottomNeighs.push_back( m_mTree.at( i).m_nChild1) ; + vBottomNeighs.push_back( m_mTree.at( i).m_nChild2) ; } // altrimenti solo uno dei figli lo sarà else { - if ( m_mTree.at(m_mTree.at(i).m_nChild1).GetTopRight().x <= m_mTree.at(nId).GetBottomLeft().x || - m_mTree.at(m_mTree.at(i).m_nChild1).GetBottomLeft().x >= m_mTree.at(nId).GetTopRight().x) - vBottomNeighs.push_back( m_mTree.at(i).m_nChild2) ; + if ( m_mTree.at( m_mTree.at( i).m_nChild1).GetTopRight().x <= m_mTree.at( nId).GetBottomLeft().x || + m_mTree.at( m_mTree.at( i).m_nChild1).GetBottomLeft().x >= m_mTree.at( nId).GetTopRight().x) + vBottomNeighs.push_back( m_mTree.at( i).m_nChild2) ; else - vBottomNeighs.push_back( m_mTree.at(i).m_nChild1) ; + vBottomNeighs.push_back( m_mTree.at( i).m_nChild1) ; } } else { - vBottomNeighs.push_back( m_mTree.at(i).m_nChild1) ; + vBottomNeighs.push_back( m_mTree.at( i).m_nChild1) ; } } } } std::vector vCells ; for ( int k : vBottomNeighs) - vCells.push_back( m_mTree.at(k)) ; + vCells.push_back( m_mTree.at( k)) ; std::sort( vCells.begin(), vCells.end(), Cell::minorX) ; vBottomNeighs.clear() ; for ( Cell c : vCells) @@ -947,77 +919,77 @@ Tree::GetBottomNeigh( int nId, INTVECTOR& vBottomNeighs) const //---------------------------------------------------------------------------- void -Tree::GetLeftNeigh( int nId, INTVECTOR& vLeftNeighs) const +Tree::GetLeftNeigh( const int& nId, INTVECTOR& vLeftNeighs) const { if ( (int) vLeftNeighs.size() == 0) { - if ( m_mTree.at(nId).m_nLeft == -2) + if ( m_mTree.at( nId).m_nLeft == -2) return ; - if ( m_mTree.at(m_mTree.at(nId).m_nLeft).IsLeaf()) - vLeftNeighs.push_back( m_mTree.at(nId).m_nLeft) ; + if ( m_mTree.at( m_mTree.at( nId).m_nLeft).IsLeaf()) + vLeftNeighs.push_back( m_mTree.at( nId).m_nLeft) ; else { - if ( ! m_mTree.at(m_mTree.at(nId).m_nLeft).IsSplitVert()) { + if ( ! m_mTree.at( m_mTree.at( nId).m_nLeft).IsSplitVert()) { // se la cella vicina è più piccola della cella indagata, allora entrambi i figli saranno vicini di quest'ultima - if ( m_mTree.at(m_mTree.at(nId).m_nLeft).GetTopRight().y - m_mTree.at(m_mTree.at(nId).m_nLeft).GetBottomLeft().y <= - m_mTree.at(nId).GetTopRight().y - m_mTree.at(nId).GetBottomLeft().y) { - vLeftNeighs.push_back( m_mTree.at(m_mTree.at(nId).m_nLeft).m_nChild1) ; - vLeftNeighs.push_back( m_mTree.at(m_mTree.at(nId).m_nLeft).m_nChild2) ; + if ( m_mTree.at( m_mTree.at( nId).m_nLeft).GetTopRight().y - m_mTree.at( m_mTree.at( nId).m_nLeft).GetBottomLeft().y <= + m_mTree.at( nId).GetTopRight().y - m_mTree.at( nId).GetBottomLeft().y) { + vLeftNeighs.push_back( m_mTree.at( m_mTree.at( nId).m_nLeft).m_nChild1) ; + vLeftNeighs.push_back( m_mTree.at( m_mTree.at( nId).m_nLeft).m_nChild2) ; } // altrimenti solo uno dei figli lo sarà else{ - if ( m_mTree.at(m_mTree.at(m_mTree.at(nId).m_nLeft).m_nChild1).GetTopRight().y <= m_mTree.at(nId).GetBottomLeft().y || - m_mTree.at(m_mTree.at(m_mTree.at(nId).m_nLeft).m_nChild1).GetBottomLeft().y >= m_mTree.at(nId).GetTopRight().y) - vLeftNeighs.push_back( m_mTree.at(m_mTree.at(nId).m_nLeft).m_nChild2) ; + if ( m_mTree.at( m_mTree.at( m_mTree.at( nId).m_nLeft).m_nChild1).GetTopRight().y <= m_mTree.at( nId).GetBottomLeft().y || + m_mTree.at( m_mTree.at( m_mTree.at( nId).m_nLeft).m_nChild1).GetBottomLeft().y >= m_mTree.at( nId).GetTopRight().y) + vLeftNeighs.push_back( m_mTree.at( m_mTree.at( nId).m_nLeft).m_nChild2) ; else - vLeftNeighs.push_back( m_mTree.at(m_mTree.at(nId).m_nLeft).m_nChild1) ; + vLeftNeighs.push_back( m_mTree.at( m_mTree.at( nId).m_nLeft).m_nChild1) ; } } else { - vLeftNeighs.push_back( m_mTree.at(m_mTree.at(nId).m_nLeft).m_nChild2) ; + vLeftNeighs.push_back( m_mTree.at( m_mTree.at( nId).m_nLeft).m_nChild2) ; } } bool bAllLeaves = true ; for ( int i : vLeftNeighs) { - if ( ! m_mTree.at(i).IsLeaf()) + if ( ! m_mTree.at( i).IsLeaf()) bAllLeaves = false ; } - if ( ! bAllLeaves ) + if ( ! bAllLeaves) // almeno una cella tra i vicini trovati non è leaf quindi devo richiamare ricorsivamente questa funzione per trovare i suoi child GetLeftNeigh( nId, vLeftNeighs) ; } else { for ( int j = 0 ; j != (int) vLeftNeighs.size() ; ++ j) { - int i = vLeftNeighs.at(j) ; - if ( m_mTree.at(i).IsLeaf()) - continue; + int i = vLeftNeighs.at( j) ; + if ( m_mTree.at( i).IsLeaf()) + continue ; else { // se la cella non è leaf la tolgo dal vettore delle foglie e aggiungo invece i suoi child vLeftNeighs.erase( remove( vLeftNeighs.begin(),vLeftNeighs.end(),i)) ; -- j ; - if ( ! m_mTree.at(i).IsSplitVert()) { + if ( ! m_mTree.at( i).IsSplitVert()) { // se la cella è più piccola della cella indagata, allora entrambi i figli saranno vicini di quest'ultima - if ( m_mTree.at(i).GetTopRight().y - m_mTree.at(i).GetBottomLeft().y <= - m_mTree.at(nId).GetTopRight().y - m_mTree.at(nId).GetBottomLeft().y) { - vLeftNeighs.push_back( m_mTree.at(i).m_nChild1) ; - vLeftNeighs.push_back( m_mTree.at(i).m_nChild2) ; + if ( m_mTree.at( i).GetTopRight().y - m_mTree.at( i).GetBottomLeft().y <= + m_mTree.at( nId).GetTopRight().y - m_mTree.at( nId).GetBottomLeft().y) { + vLeftNeighs.push_back( m_mTree.at( i).m_nChild1) ; + vLeftNeighs.push_back( m_mTree.at( i).m_nChild2) ; } // altrimenti solo uno dei figli lo sarà else { - if ( m_mTree.at(m_mTree.at(i).m_nChild1).GetTopRight().y <= m_mTree.at(nId).GetBottomLeft().y || - m_mTree.at(m_mTree.at(i).m_nChild1).GetBottomLeft().y >= m_mTree.at(nId).GetTopRight().y) - vLeftNeighs.push_back( m_mTree.at(i).m_nChild2) ; + if ( m_mTree.at( m_mTree.at( i).m_nChild1).GetTopRight().y <= m_mTree.at( nId).GetBottomLeft().y || + m_mTree.at( m_mTree.at( i).m_nChild1).GetBottomLeft().y >= m_mTree.at( nId).GetTopRight().y) + vLeftNeighs.push_back( m_mTree.at( i).m_nChild2) ; else - vLeftNeighs.push_back( m_mTree.at(i).m_nChild1) ; + vLeftNeighs.push_back( m_mTree.at( i).m_nChild1) ; } } else { - vLeftNeighs.push_back( m_mTree.at(i).m_nChild2) ; + vLeftNeighs.push_back( m_mTree.at( i).m_nChild2) ; } } } } std::vector vCells ; for ( int k : vLeftNeighs) - vCells.push_back( m_mTree.at(k)) ; + vCells.push_back( m_mTree.at( k)) ; std::sort( vCells.begin(), vCells.end(), Cell::minorY) ; vLeftNeighs.clear() ; for ( Cell c : vCells) @@ -1026,77 +998,77 @@ Tree::GetLeftNeigh( int nId, INTVECTOR& vLeftNeighs) const //---------------------------------------------------------------------------- void -Tree::GetRightNeigh( int nId, INTVECTOR& vRightNeighs) const +Tree::GetRightNeigh( const int& nId, INTVECTOR& vRightNeighs) const { if ( (int) vRightNeighs.size() == 0) { - if ( m_mTree.at(nId).m_nRight == -2) + if ( m_mTree.at( nId).m_nRight == -2) return ; - if ( m_mTree.at(m_mTree.at(nId).m_nRight).IsLeaf()) - vRightNeighs.push_back( m_mTree.at(nId).m_nRight) ; + if ( m_mTree.at( m_mTree.at( nId).m_nRight).IsLeaf()) + vRightNeighs.push_back( m_mTree.at( nId).m_nRight) ; else { - if ( ! m_mTree.at(m_mTree.at(nId).m_nRight).IsSplitVert()) { + if ( ! m_mTree.at( m_mTree.at( nId).m_nRight).IsSplitVert()) { // se la cella vicina è più piccola della cella indagata, allora entrambi i figli saranno vicini di quest'ultima - if ( m_mTree.at(m_mTree.at(nId).m_nRight).GetTopRight().y - m_mTree.at(m_mTree.at(nId).m_nRight).GetBottomLeft().y <= - m_mTree.at(nId).GetTopRight().y - m_mTree.at(nId).GetBottomLeft().y) { - vRightNeighs.push_back( m_mTree.at(m_mTree.at(nId).m_nRight).m_nChild1) ; - vRightNeighs.push_back( m_mTree.at(m_mTree.at(nId).m_nRight).m_nChild2) ; + if ( m_mTree.at( m_mTree.at( nId).m_nRight).GetTopRight().y - m_mTree.at( m_mTree.at( nId).m_nRight).GetBottomLeft().y <= + m_mTree.at( nId).GetTopRight().y - m_mTree.at( nId).GetBottomLeft().y) { + vRightNeighs.push_back( m_mTree.at( m_mTree.at( nId).m_nRight).m_nChild1) ; + vRightNeighs.push_back( m_mTree.at( m_mTree.at( nId).m_nRight).m_nChild2) ; } // altrimenti solo uno dei figli lo sarà else{ - if ( m_mTree.at(m_mTree.at(m_mTree.at(nId).m_nRight).m_nChild1).GetTopRight().y <= m_mTree.at(nId).GetBottomLeft().y || - m_mTree.at(m_mTree.at(m_mTree.at(nId).m_nRight).m_nChild1).GetBottomLeft().y >= m_mTree.at(nId).GetTopRight().y) - vRightNeighs.push_back( m_mTree.at(m_mTree.at(nId).m_nRight).m_nChild2) ; + if ( m_mTree.at( m_mTree.at( m_mTree.at( nId).m_nRight).m_nChild1).GetTopRight().y <= m_mTree.at( nId).GetBottomLeft().y || + m_mTree.at( m_mTree.at( m_mTree.at( nId).m_nRight).m_nChild1).GetBottomLeft().y >= m_mTree.at( nId).GetTopRight().y) + vRightNeighs.push_back( m_mTree.at( m_mTree.at( nId).m_nRight).m_nChild2) ; else - vRightNeighs.push_back( m_mTree.at(m_mTree.at(nId).m_nRight).m_nChild1) ; + vRightNeighs.push_back( m_mTree.at( m_mTree.at( nId).m_nRight).m_nChild1) ; } } else { - vRightNeighs.push_back( m_mTree.at(m_mTree.at(nId).m_nRight).m_nChild1) ; + vRightNeighs.push_back( m_mTree.at( m_mTree.at( nId).m_nRight).m_nChild1) ; } } bool bAllLeaves = true ; for ( int i : vRightNeighs) { - if ( ! m_mTree.at(i).IsLeaf()) + if ( ! m_mTree.at( i).IsLeaf()) bAllLeaves = false ; } - if ( ! bAllLeaves ) + if ( ! bAllLeaves) // almeno una cella tra i vicini trovati non è leaf quindi devo richiamare ricorsivamente questa funzione per trovare i suoi child GetRightNeigh( nId, vRightNeighs) ; } else { for ( int j = 0 ; j != (int) vRightNeighs.size() ; ++ j) { - int i = vRightNeighs.at(j) ; - if ( m_mTree.at(i).IsLeaf()) - continue; + int i = vRightNeighs.at( j) ; + if ( m_mTree.at( i).IsLeaf()) + continue ; else { // se la cella non è leaf la tolgo dal vettore delle foglie e aggiungo invece i suoi child vRightNeighs.erase( remove( vRightNeighs.begin(),vRightNeighs.end(), i)) ; -- j ; - if ( ! m_mTree.at(i).IsSplitVert()) { + if ( ! m_mTree.at( i).IsSplitVert()) { // se la cella è più piccola della cella indagata, allora entrambi i figli saranno vicini di quest'ultima - if ( m_mTree.at(i).GetTopRight().y - m_mTree.at(i).GetBottomLeft().y <= - m_mTree.at(nId).GetTopRight().y - m_mTree.at(nId).GetBottomLeft().y) { - vRightNeighs.push_back( m_mTree.at(i).m_nChild1) ; - vRightNeighs.push_back( m_mTree.at(i).m_nChild2) ; + if ( m_mTree.at( i).GetTopRight().y - m_mTree.at( i).GetBottomLeft().y <= + m_mTree.at( nId).GetTopRight().y - m_mTree.at( nId).GetBottomLeft().y) { + vRightNeighs.push_back( m_mTree.at( i).m_nChild1) ; + vRightNeighs.push_back( m_mTree.at( i).m_nChild2) ; } // altrimenti solo uno dei figli lo sarà else { - if ( m_mTree.at(m_mTree.at(i).m_nChild1).GetTopRight().y <= m_mTree.at(nId).GetBottomLeft().y || - m_mTree.at(m_mTree.at(i).m_nChild1).GetBottomLeft().y >= m_mTree.at(nId).GetTopRight().y) - vRightNeighs.push_back( m_mTree.at(i).m_nChild2) ; + if ( m_mTree.at( m_mTree.at( i).m_nChild1).GetTopRight().y <= m_mTree.at( nId).GetBottomLeft().y || + m_mTree.at( m_mTree.at( i).m_nChild1).GetBottomLeft().y >= m_mTree.at( nId).GetTopRight().y) + vRightNeighs.push_back( m_mTree.at( i).m_nChild2) ; else - vRightNeighs.push_back( m_mTree.at(i).m_nChild1) ; + vRightNeighs.push_back( m_mTree.at( i).m_nChild1) ; } } else { - vRightNeighs.push_back( m_mTree.at(i).m_nChild1) ; + vRightNeighs.push_back( m_mTree.at( i).m_nChild1) ; } } } } std::vector vCells ; for ( int k : vRightNeighs) - vCells.push_back( m_mTree.at(k)) ; + vCells.push_back( m_mTree.at( k)) ; std::sort( vCells.begin(), vCells.end(), Cell::minorY) ; vRightNeighs.clear() ; for ( Cell c : vCells) @@ -1105,41 +1077,41 @@ Tree::GetRightNeigh( int nId, INTVECTOR& vRightNeighs) const //---------------------------------------------------------------------------- void -Tree::GetRootNeigh( int nEdge, INTVECTOR& vNeigh) +Tree::GetRootNeigh( const int& nEdge, INTVECTOR& vNeigh) { int nId = -1 ; bool bMod = false ; - if ( nEdge == 0 ) { - if ( m_mTree[nId].m_nBottom == -2 ) { + if ( nEdge == 0) { + if ( m_mTree[nId].m_nBottom == -2) { m_mTree[nId].m_nBottom = -1 ; - bMod = true; + bMod = true ; } GetBottomNeigh( nId, vNeigh) ; if ( bMod) m_mTree[nId].m_nBottom = -2 ; } - else if ( nEdge == 1 ) { - if ( m_mTree[nId].m_nRight == -2 ) { + else if ( nEdge == 1) { + if ( m_mTree[nId].m_nRight == -2) { m_mTree[nId].m_nRight = -1 ; - bMod = true; + bMod = true ; } GetRightNeigh( nId, vNeigh) ; if ( bMod) m_mTree[nId].m_nRight = -2 ; } - else if ( nEdge == 2 ) { - if ( m_mTree[nId].m_nTop == -2 ) { + else if ( nEdge == 2) { + if ( m_mTree[nId].m_nTop == -2) { m_mTree[nId].m_nTop = -1 ; - bMod = true; + bMod = true ; } GetTopNeigh( nId, vNeigh) ; if ( bMod) m_mTree[nId].m_nTop = -2 ; } - else if ( nEdge == 3 ) { - if ( m_mTree[nId].m_nLeft == -2 ) { + else if ( nEdge == 3) { + if ( m_mTree[nId].m_nLeft == -2) { m_mTree[nId].m_nLeft = -1 ; - bMod = true; + bMod = true ; } GetLeftNeigh( nId, vNeigh) ; if ( bMod) @@ -1149,52 +1121,53 @@ Tree::GetRootNeigh( int nEdge, INTVECTOR& vNeigh) //---------------------------------------------------------------------------- int -Tree::GetHeightLeaves( int nId, INTVECTOR& vnLeaves, int d) const +Tree::GetHeightLeaves( const int& nId, INTVECTOR& vnLeaves, int d) const { - if ( nId == -1 && m_mTree.at(-1).IsLeaf()) { + if ( nId == -1 && m_mTree.at( -1).IsLeaf()) { vnLeaves.push_back( -1) ; return 0 ; } else { if ( (int) vnLeaves.size() == 0) { - if ( m_mTree.at(nId).IsLeaf()) + if ( m_mTree.at( nId).IsLeaf()) return d ; else { - vnLeaves.push_back( m_mTree.at(nId).m_nChild1) ; - vnLeaves.push_back( m_mTree.at(nId).m_nChild2) ; - if ( ! m_mTree.at(m_mTree.at(nId).m_nChild1).IsLeaf() || ! m_mTree.at(m_mTree.at(nId).m_nChild2).IsLeaf()) + vnLeaves.push_back( m_mTree.at( nId).m_nChild1) ; + vnLeaves.push_back( m_mTree.at( nId).m_nChild2) ; + if ( ! m_mTree.at( m_mTree.at( nId).m_nChild1).IsLeaf() || ! m_mTree.at( m_mTree.at( nId).m_nChild2).IsLeaf()) // almeno un child non è leaf quindi devo richiamare ricorsivamente questa funzione sui child in questione - d = GetHeightLeaves( nId, vnLeaves, m_mTree.at(m_mTree.at(nId).m_nChild1).m_nDepth) ; + d = GetHeightLeaves( nId, vnLeaves, m_mTree.at( m_mTree.at( nId).m_nChild1).m_nDepth) ; } } else { for ( int j = 0 ; j != (int) vnLeaves.size() ; ++ j) { - int i = vnLeaves.at(j) ; - if ( m_mTree.at(i).IsLeaf() ) { + int i = vnLeaves.at( j) ; + if ( m_mTree.at( i).IsLeaf()) { continue ; } else { // se la cella non è leaf la tolgo dal vettore delle foglie e aggiungo invece i suoi child vnLeaves.erase( remove( vnLeaves.begin(),vnLeaves.end(),i)) ; -- j ; - vnLeaves.push_back( m_mTree.at(i).m_nChild1) ; - vnLeaves.push_back( m_mTree.at(i).m_nChild2) ; - d = std::max ( d, m_mTree.at(m_mTree.at(i).m_nChild1).m_nDepth) ; + vnLeaves.push_back( m_mTree.at( i).m_nChild1) ; + vnLeaves.push_back( m_mTree.at( i).m_nChild2) ; + d = std::max ( d, m_mTree.at( m_mTree.at( i).m_nChild1).m_nDepth) ; } } return d ; } - return d - m_mTree.at(nId).m_nDepth ; + return d - m_mTree.at( nId).m_nDepth ; } } //---------------------------------------------------------------------------- int -Tree::GetDepth( int nId, int nRef = -2) const +Tree::GetDepth( const int& nId, const int& nRef = -2) const { int c = 0 ; - while ( m_mTree.at(nId).m_nParent != nRef) { - nId = m_mTree.at(nId).m_nParent ; + int nCell = nId ; + while ( m_mTree.at( nCell).m_nParent != nRef) { + nCell = m_mTree.at( nCell).m_nParent ; ++ c ; } return c ; @@ -1210,7 +1183,7 @@ struct generator //---------------------------------------------------------------------------- bool Tree::GetPolygons( std::vector& vPolygons) { - if ( (int) m_vPolygons.size() == 0 ) { + if ( (int) m_vPolygons.size() == 0) { if ( ! m_bTrimmed) { vPolygons.clear() ; POLYLINEVECTOR vPolygonsBasic ; @@ -1230,7 +1203,7 @@ Tree::GetPolygons( std::vector& vPolygons) { GetPolygonsBasic( vPolygonsBasic) ; // scorro sui poligoni delle celle non trimmate int nCells = (int)vPolygonsBasic.size() ; - for ( int i = 0 ; i < nCells ; ++i ) { + for ( int i = 0 ; i < nCells ; ++i) { // costruisco i poligoni partendo dal vettore delle intersezioni, come spiegato a pag15 di Cripps int nId = m_vnLeaves[i] ; @@ -1262,7 +1235,7 @@ Tree::GetPolygons( std::vector& vPolygons) { CreateIslandAndHoles( i, vPolygons, nPoly, vnParentChunk) ; } } - return true; + return true ; } } else { @@ -1283,12 +1256,12 @@ Tree::GetPolygonsBasic( POLYLINEVECTOR& vPolygons) for ( int nId : m_vnLeaves) { vVertices.clear() ; vNeigh.clear() ; - vVertices.push_back( m_mTree.at(nId).GetBottomLeft()) ; + vVertices.push_back( m_mTree.at( nId).GetBottomLeft()) ; GetBottomNeigh( nId, vNeigh) ; // aggiungo i vertici che sono sul lato bottom, solo se ho più di un vicino bottom if ( (int) vNeigh.size() != 0 && (int) vNeigh.size() != 1){ - for ( int j : vNeigh ) - vVertices.push_back( m_mTree.at(j).GetTopRight()) ; + for ( int j : vNeigh) + vVertices.push_back( m_mTree.at( j).GetTopRight()) ; bBottomRight = true ; } else @@ -1297,22 +1270,22 @@ Tree::GetPolygonsBasic( POLYLINEVECTOR& vPolygons) GetRightNeigh ( nId, vNeigh) ; // aggiungo i vertici che sono sul lato right, solo se ho più di un vicino right if ( (int) vNeigh.size() != 0 && (int) vNeigh.size() != 1){ - for ( int j : vNeigh ) - vVertices.push_back( m_mTree.at(j).GetBottomLeft()) ; + for ( int j : vNeigh) + vVertices.push_back( m_mTree.at( j).GetBottomLeft()) ; } // se non l'ho già aggiunto tramite i vicini bottom aggiungo il punto bottom right - else if ( ! bBottomRight ) { - Point3d ptBr( m_mTree.at(nId).GetTopRight().x, m_mTree.at(nId).GetBottomLeft().y) ; + else if ( ! bBottomRight) { + Point3d ptBr( m_mTree.at( nId).GetTopRight().x, m_mTree.at( nId).GetBottomLeft().y) ; vVertices.push_back( ptBr) ; } vNeigh.clear() ; - vVertices.push_back( m_mTree.at(nId).GetTopRight()) ; + vVertices.push_back( m_mTree.at( nId).GetTopRight()) ; GetTopNeigh ( nId, vNeigh) ; std::reverse( vNeigh.begin(), vNeigh.end()) ; // aggiungo i vertici che sono sul lato top, solo se ho più di un vicino top if ( (int) vNeigh.size() != 0 && (int) vNeigh.size() != 1) { for ( int j : vNeigh) - vVertices.push_back( m_mTree.at(j).GetBottomLeft()) ; + vVertices.push_back( m_mTree.at( j).GetBottomLeft()) ; bTopLeft = true ; } else @@ -1323,34 +1296,34 @@ Tree::GetPolygonsBasic( POLYLINEVECTOR& vPolygons) // aggiungo i vertici che sono sul lato left, solo se ho più di un vicino left if ( (int) vNeigh.size() != 0 && (int) vNeigh.size() != 1) { for ( int j : vNeigh) - vVertices.push_back( m_mTree.at(j).GetTopRight()) ; + vVertices.push_back( m_mTree.at( j).GetTopRight()) ; } // se non l'ho già aggiunto tramite i vicini top aggiungo il punto top left else if ( ! bTopLeft) { - Point3d ptTl( m_mTree.at(nId).GetBottomLeft().x, m_mTree.at(nId).GetTopRight().y) ; + Point3d ptTl( m_mTree.at( nId).GetBottomLeft().x, m_mTree.at( nId).GetTopRight().y) ; vVertices.push_back( ptTl) ; } vNeigh.clear() ; - vVertices.push_back( m_mTree.at(nId).GetBottomLeft()) ; + vVertices.push_back( m_mTree.at( nId).GetBottomLeft()) ; if ( ! m_bTrimmed) { // se ho una cella con vicino dello stesso grado ( quindi il poligono ha solo 5 punti) controllo la curvatura nella cella e // se necessario cambio l'ordine dei vertici per scegliere la diagonale di split migliore if ( vVertices.size() == 5) { - Point3d ptPSrf, ptP00, ptP10, ptP11, ptP01; + Point3d ptPSrf, ptP00, ptP10, ptP11, ptP01 ; double dU, dV ; - dU = ( m_mTree.at(nId).GetBottomLeft().x + m_mTree.at(nId).GetTopRight().x) / 2 / SBZ_TREG_COEFF; - dV = ( m_mTree.at(nId).GetBottomLeft().y + m_mTree.at(nId).GetTopRight().y) / 2 / SBZ_TREG_COEFF; + dU = ( m_mTree.at( nId).GetBottomLeft().x + m_mTree.at( nId).GetTopRight().x) / 2 / SBZ_TREG_COEFF ; + dV = ( m_mTree.at( nId).GetBottomLeft().y + m_mTree.at( nId).GetTopRight().y) / 2 / SBZ_TREG_COEFF ; m_pSrfBz->GetPointD1D2( dU, dV, ISurfBezier::FROM_MINUS, ISurfBezier::FROM_MINUS, ptPSrf) ; - ptP00 = m_mVert.at(nId).at(0) ; - ptP10 = m_mVert.at(nId).at(1) ; - ptP11 = m_mVert.at(nId).at(2) ; - ptP01 = m_mVert.at(nId).at(3) ; + ptP00 = m_mVert.at( nId).at( 0) ; + ptP10 = m_mVert.at( nId).at( 1) ; + ptP11 = m_mVert.at( nId).at( 2) ; + ptP01 = m_mVert.at( nId).at( 3) ; Point3d ptP00P11 = ( ptP00 + ptP11) / 2 ; Point3d ptP10P01 = ( ptP10 + ptP01) / 2 ; // ho la curvatura maggiore sulla diagonale tra P10 e P01, ruoto l'ordine dei vertici, in modo che triangulate prenda la diagonale giusta - if ( Dist(ptP00P11, ptPSrf) + EPS_SMALL > Dist(ptP10P01, ptPSrf)) { - rotate(vVertices.begin(), vVertices.begin() + 1,vVertices.end()) ; - vVertices.back() = vVertices.at(0) ; + if ( Dist( ptP00P11, ptPSrf) + EPS_SMALL > Dist( ptP10P01, ptPSrf)) { + rotate( vVertices.begin(), vVertices.begin() + 1,vVertices.end()) ; + vVertices.back() = vVertices.at( 0) ; } } } @@ -1358,7 +1331,7 @@ Tree::GetPolygonsBasic( POLYLINEVECTOR& vPolygons) m_vPolygons.emplace_back() ; m_vPolygons.back().emplace_back() ; for ( int i = 0 ; i < (int) vVertices.size() ; ++i) { - m_vPolygons.back().back().AddUPoint(i, vVertices.at(i)) ; + m_vPolygons.back().back().AddUPoint( i, vVertices.at( i)) ; } } @@ -1366,7 +1339,7 @@ Tree::GetPolygonsBasic( POLYLINEVECTOR& vPolygons) // restituisco i poligoni delle celle del tree nello spazio parametrico for ( int t = 0 ; t < (int)m_vPolygons.size() ; ++ t) { - for ( int z = 0 ; z < (int)m_vPolygons[t].size(); ++z ) { + for ( int z = 0 ; z < (int)m_vPolygons[t].size() ; ++z) { vPolygons.push_back( m_vPolygons[t][z]) ; } } @@ -1378,21 +1351,21 @@ void Tree::ResetTree( void) { // setto tutte le foglie a Processed = false - for ( int nC : m_vnLeaves ) { + for ( int nC : m_vnLeaves) { m_mTree[nC].SetProcessed( false) ; } } //---------------------------------------------------------------------------- INTVECTOR -Tree::FindCell( const Point3d& ptToAssign, CurveLine& clTrim) const +Tree::FindCell( const Point3d& ptToAssign, const CurveLine& clTrim) const { INTVECTOR nCells ; int nId = -1 ; // se fallisce ritorna un vettore vuoto // verifico che il punto sia all'interno dello spazio parametrico - if ( ptToAssign.x < m_mTree.at(-1).GetBottomLeft().x || ptToAssign.x > m_mTree.at( -1).GetTopRight().x || - ptToAssign.y < m_mTree.at(-1).GetBottomLeft().y || ptToAssign.y > m_mTree.at( -1).GetTopRight().y ) { + if ( ptToAssign.x < m_mTree.at( -1).GetBottomLeft().x || ptToAssign.x > m_mTree.at( -1).GetTopRight().x || + ptToAssign.y < m_mTree.at( -1).GetBottomLeft().y || ptToAssign.y > m_mTree.at( -1).GetTopRight().y ) { //nCells.push_back( - 2) ; return nCells ; } @@ -1404,35 +1377,35 @@ Tree::FindCell( const Point3d& ptToAssign, CurveLine& clTrim) const nId = nParents.back() ; } // individuo la foglia in cui ho lo start del loop - while ( ! m_mTree.at(nId).IsLeaf()) { - if ( m_mTree.at(nId).IsSplitVert()) { - double dMid = ( m_mTree.at(nId).GetBottomLeft().x + m_mTree.at(nId).GetTopRight().x) / 2 ; + while ( ! m_mTree.at( nId).IsLeaf()) { + if ( m_mTree.at( nId).IsSplitVert()) { + double dMid = ( m_mTree.at( nId).GetBottomLeft().x + m_mTree.at( nId).GetTopRight().x) / 2 ; if ( ptToAssign.x < dMid + EPS_SMALL) { - nId = m_mTree.at(nId).m_nChild1 ; + nId = m_mTree.at( nId).m_nChild1 ; } else { - nId = m_mTree.at(nId).m_nChild2 ; + nId = m_mTree.at( nId).m_nChild2 ; } } else { - double dMid = ( m_mTree.at(nId).GetBottomLeft().y + m_mTree.at(nId).GetTopRight().y) / 2 ; - if ( ptToAssign.y < dMid + EPS_SMALL ) { - nId = m_mTree.at(nId).m_nChild2 ; + double dMid = ( m_mTree.at( nId).GetBottomLeft().y + m_mTree.at( nId).GetTopRight().y) / 2 ; + if ( ptToAssign.y < dMid + EPS_SMALL) { + nId = m_mTree.at( nId).m_nChild2 ; } else { - nId = m_mTree.at(nId).m_nChild1 ; + nId = m_mTree.at( nId).m_nChild1 ; } } } nCells.push_back( nId) ; - Point3d ptBr( m_mTree.at(nId).GetTopRight().x , m_mTree.at(nId).GetBottomLeft().y) ; - Point3d ptTl( m_mTree.at(nId).GetBottomLeft().x , m_mTree.at(nId).GetTopRight().y) ; - if ( AreSamePointApprox(ptToAssign, ptTl) || - AreSamePointApprox( ptToAssign, m_mTree.at(nId).GetBottomLeft()) || - AreSamePointApprox(ptToAssign, ptBr) || - AreSamePointApprox( ptToAssign, m_mTree.at(nId).GetTopRight())) + Point3d ptBr( m_mTree.at( nId).GetTopRight().x , m_mTree.at( nId).GetBottomLeft().y) ; + Point3d ptTl( m_mTree.at( nId).GetBottomLeft().x , m_mTree.at( nId).GetTopRight().y) ; + if ( AreSamePointApprox( ptToAssign, ptTl) || + AreSamePointApprox( ptToAssign, m_mTree.at( nId).GetBottomLeft()) || + AreSamePointApprox( ptToAssign, ptBr) || + AreSamePointApprox( ptToAssign, m_mTree.at( nId).GetTopRight())) { Point3d ptToAssignPlus ; double dParam ; @@ -1454,24 +1427,23 @@ Tree::FindCell( const Point3d& ptToAssign, CurveLine& clTrim) const //---------------------------------------------------------------------------- INTVECTOR -Tree::FindCell( const Point3d& ptToAssign, CurveLine& cl, INTVECTOR vCells) const +Tree::FindCell( const Point3d& ptToAssign, const CurveLine& cl, INTVECTOR vCells) const { // se non trova nulla restituisce un vettore vuoto // restituisce sempre solo una cella // la CurveLine è il segmento di trim su cui giace ptToAssign - // devo usare ptInters + qualcosa/////////////////////////////////////////////// Point3d ptIntersPlus ; double dParam ; Vector3d vDir ; cl.GetParamAtPoint( ptToAssign, dParam, EPS_SMALL) ; + // mi sposto appena più avanti di ptToAssign cl.GetPointTang( dParam + EPS_SMALL, ICurve::FROM_MINUS, ptIntersPlus, vDir) ; INTVECTOR nCells ; int nId = -1 ; - bool bFound = false ; - for ( int nCell : vCells ) { - if ( ptIntersPlus.x >= m_mTree.at(nCell).GetBottomLeft().x && ptIntersPlus.x <= m_mTree.at(nCell).GetTopRight().x && - ptIntersPlus.y >= m_mTree.at(nCell).GetBottomLeft().y && ptIntersPlus.y <= m_mTree.at(nCell).GetTopRight().y) { + for ( int nCell : vCells) { + if ( ptIntersPlus.x >= m_mTree.at( nCell).GetBottomLeft().x && ptIntersPlus.x <= m_mTree.at( nCell).GetTopRight().x && + ptIntersPlus.y >= m_mTree.at( nCell).GetBottomLeft().y && ptIntersPlus.y <= m_mTree.at( nCell).GetTopRight().y) { nId = nCell ; nCells.push_back( nId) ; } @@ -1485,8 +1457,7 @@ Tree::TraceLoopLabelCell( void) { // approssimo i loop di trim con delle spezzate POLYLINEVECTOR vPlApprox ; - //for ( PtrOwner pCrv : m_vLoop){ - for ( int p = 0 ; p < (int) m_vLoop.size(); ++ p){ + for ( int p = 0 ; p < (int) m_vLoop.size() ; ++ p){ PtrOwner pCrv( m_vLoop[p]->Clone()) ; double dLinTol = 0.01 ; // questo è riferito allo spazio parametrico perché le curve di loop sono già state riscalate!!!!!! double dAngTolDeg = 5 ; @@ -1502,14 +1473,14 @@ Tree::TraceLoopLabelCell( void) POLYLINEVECTOR vplPolygons ; GetPolygonsBasic( vplPolygons) ; // percorro i loop trovando le interezioni con le celle e riempiendo i vettori m_vInters delle varie celle - for ( int i = 0 ; i < (int) vPlApprox.size(); ++ i) { + for ( int i = 0 ; i < (int) vPlApprox.size() ; ++ i) { PolyLine plLoop = vPlApprox[i] ; // calcolo se il loop è CCW o Cw double dArea ; Plane3d plExtPlane ; bool bCCW ; plLoop.IsClosedAndFlat( plExtPlane, dArea, 50 * EPS_SMALL) ; - if ( plExtPlane.GetVersN().z > 0 ) + if ( plExtPlane.GetVersN().z > 0) bCCW = true ; else bCCW = false ; @@ -1517,7 +1488,7 @@ Tree::TraceLoopLabelCell( void) Point3d ptStart ; plLoop.GetFirstPoint( ptStart) ; PNTULIST lPt = plLoop.GetUPointList() ; - PNTULIST:: iterator ptFirst = lPt.begin(); + PNTULIST:: iterator ptFirst = lPt.begin() ; PNTULIST:: iterator ptSecond = ptFirst ; std::advance( ptSecond, 1) ; CurveLine clFirst ; @@ -1543,7 +1514,11 @@ Tree::TraceLoopLabelCell( void) INTVECTOR :: iterator iter = find( m_vnLeaves.begin(), m_vnLeaves.end(), nId) ; int nIdPolygon = std::distance( m_vnLeaves.begin(), iter) ; bool bEraseNextPoint = false ; + // per debug + int c = 0 ; + Cell cUnderWork ; while ( plLoop.GetNextPoint( ptCurr)) { + ++ c ; // sto uscendo dalla cella, quindi cerco l'intersezione Point3d ptTStart, ptTEnd ; plLoop.GetPrevPoint( ptTStart) ; @@ -1551,7 +1526,7 @@ Tree::TraceLoopLabelCell( void) CurveLine clTrim ; clTrim.Set( ptTStart, ptTEnd) ; while( ! IsPointInsidePolyLine( ptCurr, vplPolygons[nIdPolygon], dLinTol)) { /// qui devo mettere una tolleranza negativa per poter tener conto anche dei punti che sono SULLA curva - if ( bEraseNextPoint ) { + if ( bEraseNextPoint) { vptInters.pop_back() ; bEraseNextPoint = false ; } @@ -1561,13 +1536,15 @@ Tree::TraceLoopLabelCell( void) // al precedente FindInters avrei dovuto passare di cella if ( ! FindInters( nId, clTrim, vptInters, true)) { // scarterò il punto molto vicino al lato e tengo solo l'intersezione del trim col lato - m_mTree[nId].m_vInters.back().vpt.pop_back() ; + //m_mTree[nId].m_vInters.back().vpt.pop_back() ; + vptInters.pop_back() ; plLoop.GetPrevPoint( ptTEnd) ; plLoop.GetPrevPoint( ptTStart) ; plLoop.GetNextPoint( ptCurr) ; clTrim.Set( ptTStart, ptTEnd) ; - //clTrim.ExtendEndByLen( EPS_SMALL * 2) ; - vptInters.clear() ; + clTrim.ExtendEndByLen( EPS_SMALL * 2) ; + clTrim.ExtendStartByLen( EPS_SMALL * 2) ; + //vptInters.clear() ; if ( FindInters( nId, clTrim, vptInters, true)) return false ; bEraseNextPoint = true ; @@ -1579,6 +1556,8 @@ Tree::TraceLoopLabelCell( void) m_mTree[nId].m_vInters.back().bCCW = bCCW ; // salvo il chunk del loop m_mTree[nId].m_vInters.back().nChunk = m_mChunk[i] ; + // per debug + cUnderWork = m_mTree[nId] ; } // aggiungo la fine del segmento nel vettore delle intersezioni vptInters.push_back( ptCurr) ; @@ -1587,7 +1566,6 @@ Tree::TraceLoopLabelCell( void) vptInters.pop_back() ; m_mTree[nId].m_vInters.back().vpt = vptInters ; if ( bLoopInside) { - //m_mTree[nId].m_vnLoop.push_back( i) ; // setto la categoria della cella if ( m_mTree[nId].m_nFlag == -1) m_mTree[nId].m_nFlag = 2 ; @@ -1621,8 +1599,8 @@ Tree::TraceLoopLabelCell( void) else if ( nId == nFirstCell) { int nOut = m_mTree[nId].m_vInters[nPass].nOut ; m_mTree[nId].m_vInters.back().vpt.insert( m_mTree[nId].m_vInters.back().vpt.end(), - m_mTree[nId].m_vInters[nPass].vpt.begin(), - m_mTree[nId].m_vInters[nPass].vpt.end()) ; + m_mTree[nId].m_vInters[nPass].vpt.begin(), + m_mTree[nId].m_vInters[nPass].vpt.end()) ; m_mTree[nId].m_vInters[nPass] = m_mTree[nId].m_vInters.back() ; m_mTree[nId].m_vInters.pop_back() ; // sistemo il lato d'uscita @@ -1633,7 +1611,7 @@ Tree::TraceLoopLabelCell( void) // riordino i vettori di intersezione per ogni cella e setto il flag RightEdgeIn for ( int nId : m_vnLeaves) { - std::sort( m_mTree[nId].m_vInters.begin( ), m_mTree[nId].m_vInters.end()) ; + std::sort( m_mTree[nId].m_vInters.begin(), m_mTree[nId].m_vInters.end()) ; SetRightEdgeIn( nId) ; } @@ -1651,30 +1629,19 @@ Tree::TraceLoopLabelCell( void) m_mTree[nCell].m_nFlag2 = 1 ; CategorizeCell( nCell) ; bool bDone = false ; - int nInProcessing = -1 ; - int c = 0 ; - int nDisplay = -1 ; // fintanto che la cella ha tra i vicini a destra una cella non elaborata mi sposto a destra // definisco una cella Processed se tutto il ramo a destra è categorizzato - while ( ((int)vNeigh.size() > 0 && ! bDone) || ! m_mTree[nCell].IsProcessed()) { - // per debug - if ( nInProcessing != nCell) { - nInProcessing = nCell ; - c = 0 ; - } - else - ++ c ; + while ( ( (int)vNeigh.size() > 0 && ! bDone) || ! m_mTree[nCell].IsProcessed()) { // verso la cella a destra più in basso da cui non sono ancora passato bool bProceeded = false ; - for ( int i = 0 ; i < (int)vNeigh.size(); ++ i) { - if ( m_mTree[vNeigh[i]].m_nFlag2 == 0 ) { + for ( int i = 0 ; i < (int)vNeigh.size() ; ++ i) { + if ( m_mTree[vNeigh[i]].m_nFlag2 == 0) { nCell = vNeigh[i] ; - nDisplay = m_mTree[nCell].m_nFlag ; bProceeded = true ; break ; } } - if ( ! bProceeded ) { + if ( ! bProceeded) { m_mTree[nCell].SetProcessed() ; } else { //categorizzo la cella @@ -1695,42 +1662,30 @@ Tree::TraceLoopLabelCell( void) } } } - // per debug - if ( c > 3) - break ; } vNeigh.clear() ; GetRightNeigh( nCell, vNeigh) ; // se non ho vicini a destra o se i vicini sono già tutti categorizzati // torno indietro a sinistra alla cella già categorizzata più bassa - //bDone = true ; - c = 0 ; while ( (int) vNeigh.size() == 0 || m_mTree[nCell].IsProcessed()) { - // per debug - if ( nInProcessing != nCell) { - nInProcessing = nCell ; - c = 0 ; - } - else - ++ c ; // trovo il vicino a sinistra, già categorizzato, più basso vNeigh.clear() ; GetLeftNeigh( nCell, vNeigh) ; - for ( int p = 0; p < (int)vNeigh.size() ; ++ p) { - if ( m_mTree[vNeigh[p]].m_nFlag2 != 0 ) { + for ( int p = 0 ; p < (int)vNeigh.size() ; ++ p) { + if ( m_mTree[vNeigh[p]].m_nFlag2 != 0) { nCell = vNeigh[p] ; break ; } } // se non ho vicini a sinistra sono tornato sul lato sinistro e quindi devo procedere alla cella più bassa non processata sul lato sinistro - if ( vNeigh.empty() ) { - for ( int p = 0 ; p < (int)vFirst.size() ; ++ p ) { - if ( m_mTree[vFirst[p]].m_nFlag2 == 0 ) { + if ( vNeigh.empty()) { + for ( int p = 0 ; p < (int)vFirst.size() ; ++ p) { + if ( m_mTree[vFirst[p]].m_nFlag2 == 0) { nCell = vFirst[p] ; break ; } } - if ( nCell == nLastLeft && m_mTree[nCell].IsProcessed() ) { + if ( nCell == nLastLeft && m_mTree[nCell].IsProcessed()) { // categorizzo m_mTree[nCell].m_nFlag2 = 1 ; CategorizeCell( nCell) ; @@ -1742,9 +1697,8 @@ Tree::TraceLoopLabelCell( void) vNeigh.clear() ; GetRightNeigh( nCell, vNeigh) ; bool bDone = true ; - for ( int k = 0; k < (int)vNeigh.size() ; ++ k) { - if ( ! m_mTree[vNeigh[k]].IsProcessed() ) { - //nCell = vNeigh[k] ; + for ( int k = 0 ; k < (int)vNeigh.size() ; ++ k) { + if ( ! m_mTree[vNeigh[k]].IsProcessed()) { bDone = false ; break ; } @@ -1756,9 +1710,6 @@ Tree::TraceLoopLabelCell( void) CategorizeCell( nCell) ; } } - // per debug - if ( c > 3) - break ; } vNeigh.clear() ; GetRightNeigh( nCell, vNeigh) ; @@ -1769,7 +1720,7 @@ Tree::TraceLoopLabelCell( void) //---------------------------------------------------------------------------- bool -Tree::FindInters( int& nId, CurveLine& clTrim, PNTVECTOR& vptInters, bool bFirstInters) +Tree::FindInters( int& nId, const CurveLine& clTrim, PNTVECTOR& vptInters, bool bFirstInters) { CurveLine clEdge , clEdge2 ; Point3d ptStart , ptEnd ; @@ -1882,9 +1833,7 @@ Tree::FindInters( int& nId, CurveLine& clTrim, PNTVECTOR& vptInters, bool bFirst } OnWhichEdge( nId, ptInters, nEdge) ; m_mTree[nId].m_vInters.back().nOut = nEdge ; - if ( (int)vptInters.size() == 0) - vptInters.push_back( ptInters) ; - else if ( ! AreSamePointExact(ptInters , vptInters.back())) + if ( (int)vptInters.size() == 0 || ! AreSamePointExact( ptInters , vptInters.back())) vptInters.push_back( ptInters) ; // salvo il vettore intersezione per la cella e capisco in quale altra cella passare if ( (int)vptInters.size() == 1) @@ -1902,7 +1851,7 @@ Tree::FindInters( int& nId, CurveLine& clTrim, PNTVECTOR& vptInters, bool bFirst if ( nEdge == 0) { GetTopNeigh( nId, vNeigh) ; std::reverse( vNeigh.begin(), vNeigh.end()) ; - for ( int j : vNeigh ) { + for ( int j : vNeigh) { if ( ptInters.x >= m_mTree[j].GetBottomLeft().x) { nId = j ; break ; @@ -1922,7 +1871,7 @@ Tree::FindInters( int& nId, CurveLine& clTrim, PNTVECTOR& vptInters, bool bFirst else if ( nEdge == 1) { GetLeftNeigh( nId, vNeigh) ; std::reverse( vNeigh.begin(), vNeigh.end()) ; - for ( int j : vNeigh ) { + for ( int j : vNeigh) { if ( ptInters.y >= m_mTree[j].GetBottomLeft().y) { nId = j ; break ; @@ -1941,7 +1890,7 @@ Tree::FindInters( int& nId, CurveLine& clTrim, PNTVECTOR& vptInters, bool bFirst } else if ( nEdge == 2) { GetBottomNeigh( nId, vNeigh) ; - for ( int j : vNeigh ) { + for ( int j : vNeigh) { if ( ptInters.x <= m_mTree[j].GetTopRight().x) { nId = j ; break ; @@ -1960,7 +1909,7 @@ Tree::FindInters( int& nId, CurveLine& clTrim, PNTVECTOR& vptInters, bool bFirst } else if ( nEdge == 3) { GetRightNeigh( nId, vNeigh) ; - for ( int j : vNeigh ) { + for ( int j : vNeigh) { if ( ptInters.y <= m_mTree[j].GetTopRight().y) { nId = j ; break ; @@ -2182,13 +2131,13 @@ Tree::FindInters( int& nId, CurveLine& clTrim, PNTVECTOR& vptInters, bool bFirst //---------------------------------------------------------------------------- bool -Tree::CreateCellPolygons( int nLeafId, std::vector& vPolygons, INTVECTOR& vToCheck, int& nPoly, INTVECTOR& vnParentChunk, PolyLine plCell) +Tree::CreateCellPolygons( const int& nLeafId, std::vector& vPolygons, INTVECTOR& vToCheck, int& nPoly, INTVECTOR& vnParentChunk, const PolyLine& plCell) { // conto quanti vertici in più ho per lato e creo un vettore dei vertici per lato int nId = m_vnLeaves[nLeafId] ; std::vector vEdgeVertex ; - Point3d ptTl(m_mTree[nId].GetBottomLeft().x, m_mTree[nId].GetTopRight().y) ; - Point3d ptBr(m_mTree[nId].GetTopRight().x, m_mTree[nId].GetBottomLeft().y) ; + Point3d ptTl( m_mTree[nId].GetBottomLeft().x, m_mTree[nId].GetTopRight().y) ; + Point3d ptBr( m_mTree[nId].GetTopRight().x, m_mTree[nId].GetBottomLeft().y) ; vEdgeVertex.emplace_back() ; vEdgeVertex.back().push_back( m_mTree[nId].GetTopRight()) ; vEdgeVertex.emplace_back() ; @@ -2210,12 +2159,10 @@ Tree::CreateCellPolygons( int nLeafId, std::vector& vPolygons, I while ( plCell.GetNextPoint( ptToAdd) && ! AreSamePointExact( ptToAdd, vEdgeVertex[next][0])) { vEdgeVertex[j].push_back( ptToAdd) ; } - //vEdgeVertex[next].push_back( ptToAdd) ; } // comincio a costruire il poligono INTVECTOR vToCheckNow = vToCheck ; - //vToCheck.clear() ; // vettore dei poligoni ( loop) della cella nId POLYLINEVECTOR vCellPolygons ; // costruisco i poligoni partendo dal vettore delle intersezioni, come spiegato a pag15 di Cripps @@ -2236,57 +2183,57 @@ Tree::CreateCellPolygons( int nLeafId, std::vector& vPolygons, I // indice del loop in m_vInters int j = vToCheckNow[w] ; Inters inA = m_mTree[nId].m_vInters[j] ; - if ( inA.nIn != -1 ) { + if ( inA.nIn != -1) { int nEdge ; - if ( nEdgeIn == -1 ) { + if ( nEdgeIn == -1) { // salvo il lato di ingresso del primo lato del poligono che sto costruendo nEdgeIn = inA.nIn ; nFirstLoopInPoly = j ; } - for ( Point3d ptInt : inA.vpt ) { + for ( Point3d ptInt : inA.vpt) { AddVertex( nId, vEdgeVertex, plTrimmedPoly, c, ptInt) ; } vAddedLoops.push_back( j) ; nEdge = inA.nOut ; // devo verificare di non essere uscito in un vertice, con un tratto sovrapposto al lato che ripercorrerò tra poco - Point3d ptLast, ptSecondToLast; - plTrimmedPoly.GetLastPoint(ptLast) ; - plTrimmedPoly.GetPrevPoint(ptSecondToLast) ; + Point3d ptLast, ptSecondToLast ; + plTrimmedPoly.GetLastPoint( ptLast) ; + plTrimmedPoly.GetPrevPoint( ptSecondToLast) ; Vector3d vLast = ptLast - ptSecondToLast ; - vLast.Normalize(); + vLast.Normalize() ; Vector3d vEdge ; if ( AreSameEdge( nEdge, 0)) { - if ( AreSamePointExact(ptLast, ptTl) ) { + if ( AreSamePointExact( ptLast, ptTl)) { vEdge = m_mTree[nId].GetBottomLeft() - ptTl ; vEdge.Normalize() ; - if ( AreOppositeVectorApprox(vLast, vEdge) ) { + if ( AreOppositeVectorApprox( vLast, vEdge)) { plTrimmedPoly.EraseLastUPoint() ; nEdge = 1 ; } } } - else if ( AreSameEdge( nEdge, 1) && AreSamePointExact(ptLast, m_mTree[nId].GetBottomLeft()) ) { + else if ( AreSameEdge( nEdge, 1) && AreSamePointExact( ptLast, m_mTree[nId].GetBottomLeft())) { vEdge = ptBr - m_mTree[nId].GetBottomLeft() ; vEdge.Normalize() ; - if ( AreOppositeVectorApprox(vLast, vEdge) ) { + if ( AreOppositeVectorApprox( vLast, vEdge)) { plTrimmedPoly.EraseLastUPoint() ; nEdge = 2 ; } } - else if ( AreSameEdge( nEdge, 2) ) { - if ( AreSamePointExact(ptLast, ptBr) ) { + else if ( AreSameEdge( nEdge, 2)) { + if ( AreSamePointExact( ptLast, ptBr)) { vEdge = m_mTree[nId].GetTopRight() - ptBr ; vEdge.Normalize() ; - if ( AreOppositeVectorApprox(vLast, vEdge) ) { + if ( AreOppositeVectorApprox( vLast, vEdge)) { plTrimmedPoly.EraseLastUPoint() ; nEdge = 3 ; } } } - else if ( AreSameEdge( nEdge, 3) && AreSamePointExact(ptLast, m_mTree[nId].GetTopRight()) ) { + else if ( AreSameEdge( nEdge, 3) && AreSamePointExact( ptLast, m_mTree[nId].GetTopRight())) { vEdge = ptTl - m_mTree[nId].GetTopRight() ; vEdge.Normalize() ; - if ( AreOppositeVectorApprox(vLast, vEdge) ) { + if ( AreOppositeVectorApprox( vLast, vEdge)) { plTrimmedPoly.EraseLastUPoint() ; nEdge = 0 ; } @@ -2294,16 +2241,16 @@ Tree::CreateCellPolygons( int nLeafId, std::vector& vPolygons, I // se mi è rimasto solo un punto sulla polyline vuol dire che avevo solo un tratto parallelo ad lato // quindi salto al prossimo loop - if ( plTrimmedPoly.GetPointNbr() == 1 ) { + if ( plTrimmedPoly.GetPointNbr() == 1) { plTrimmedPoly.Clear() ; if ( j == nFirstLoopInPoly) nEdgeIn = -1 ; continue ; } - if ( nEdge > 3 && nEdge != 7 ) { + if ( nEdge > 3 && nEdge != 7) { nEdge = nEdge - 3 ; } - else if ( nEdge == 7 ) { + else if ( nEdge == 7) { nEdge = 0 ; } // se ho altri Pass vado avanti ad aggiungere vertici finché trovo il prossimo o finché non sono tornato sul lato di partenza @@ -2323,7 +2270,6 @@ Tree::CreateCellPolygons( int nLeafId, std::vector& vPolygons, I } else { ++ nSecondCheck ; - //vToCheck.push_back( vToCheckNow[t]) ; } } @@ -2342,7 +2288,7 @@ Tree::CreateCellPolygons( int nLeafId, std::vector& vPolygons, I AddVertex( nId, vEdgeVertex, plTrimmedPoly, c, ptVert) ; if ( nEdge > 3 && nEdge != 7) nEdge = nEdge - 4 ; - else if ( nEdge < 3 ) + else if ( nEdge < 3) ++ nEdge ; else nEdge = 0 ; @@ -2357,7 +2303,7 @@ Tree::CreateCellPolygons( int nLeafId, std::vector& vPolygons, I // se ho trovato un altro loop salto all'inizio del for, dopo aver aggiunto eventuali punti intermedi if ( bValidNextStart) { for ( int p = 1 ; p < (int) vEdgeVertex[nEdge].size() ; ++ p) { - if ( CheckIfBefore( nEdge, vEdgeVertex[nEdge][p], m_mTree[nId].m_vInters[vToCheckNow[nNext]].vpt[0]) ) { + if ( CheckIfBefore( nEdge, vEdgeVertex[nEdge][p], m_mTree[nId].m_vInters[vToCheckNow[nNext]].vpt[0])) { plTrimmedPoly.AddUPoint( c, vEdgeVertex[nEdge][p]) ; ++ c ; } @@ -2370,7 +2316,7 @@ Tree::CreateCellPolygons( int nLeafId, std::vector& vPolygons, I Point3d ptStart ; plTrimmedPoly.GetFirstPoint( ptStart) ; for ( int p = 1 ; p < (int) vEdgeVertex[nEdge].size() ; ++ p) { - if ( CheckIfBefore( nEdge, vEdgeVertex[nEdge][p], ptStart) ) { + if ( CheckIfBefore( nEdge, vEdgeVertex[nEdge][p], ptStart)) { plTrimmedPoly.AddUPoint( c, vEdgeVertex[nEdge][p]) ; ++ c ; } @@ -2396,7 +2342,7 @@ Tree::CreateCellPolygons( int nLeafId, std::vector& vPolygons, I AddVertex( nId, vEdgeVertex, plTrimmedPoly, c, ptVert) ; if ( nEdge > 3 && nEdge != 7) nEdge = nEdge - 4 ; - else if ( nEdge < 3 ) + else if ( nEdge < 3) ++ nEdge ; else nEdge = 0 ; @@ -2430,8 +2376,8 @@ Tree::CreateCellPolygons( int nLeafId, std::vector& vPolygons, I // devo verificare se tra i loop che sono finiti in vToCheck in realtà qualcuno l'ho usato per fare un poligono///////////////////////////////////// for ( int k = 0 ; k < (int)vToCheck.size() ; ++ k) { for ( int i = 0 ; i < (int)vAddedLoops.size() ; ++ i) { - if ( vToCheck[k] == vAddedLoops[i] ) { - vToCheck.erase(vToCheck.begin() + k) ; + if ( vToCheck[k] == vAddedLoops[i]) { + vToCheck.erase( vToCheck.begin() + k) ; } } } @@ -2444,17 +2390,13 @@ Tree::CreateCellPolygons( int nLeafId, std::vector& vPolygons, I //---------------------------------------------------------------------------- bool -Tree::CreateIslandAndHoles( int nLeafId, std::vector& vPolygons, int& nPoly, INTVECTOR& vnParentChunk) +Tree::CreateIslandAndHoles( const int& nLeafId, std::vector& vPolygons, int& nPoly, INTVECTOR& vnParentChunk) { // vettore dei poligoni ( loop) della cella nId POLYLINEVECTOR vCellPolygons ; - // costruisco i poligoni partendo dal vettore delle intersezioni, come spiegato a pag15 di Cripps + // costruisco i poligoni partendo dal vettore delle intersezioni int nId = m_vnLeaves[nLeafId] ; PolyLine plTrimmedPoly ; - // numero di volte che la cella è stata attraversata da una curva di trim - int nPass = (int) m_mTree[nId].m_vInters.size() ; - // numero di vertici aggiunti al nuovo poligono - int c = 0 ; // loop interni in una cella intersecata if ( m_mTree[nId].m_nFlag == 3 || m_mTree[nId].m_nFlag == 2) { @@ -2462,7 +2404,6 @@ Tree::CreateIslandAndHoles( int nLeafId, std::vector& vPolygons, // numero dei loop interni passati Inters inA ; // se ho almeno un loop CW che non è contenuto in un altro poligono o in un loop interno CCW devo aggiungere il bordo - //bool bEdgeToAdd = true ; bool bAllContained = true ; bool bContained = false ; int nInters = (int) m_mTree[nId].m_vInters.size() ; @@ -2491,7 +2432,6 @@ Tree::CreateIslandAndHoles( int nLeafId, std::vector& vPolygons, break ; } - //if ( m_mTree[nId].m_nFlag == 2 && ( bEdgeToAdd || ! bAllContained)) { if ( m_mTree[nId].m_nFlag == 2 && ! bAllContained) { // i loop esterni sono CW, quindi prima dei loop di trim aggiungo il bordo cella Point3d ptVert = m_mTree[nId].GetTopRight() ; @@ -2504,7 +2444,7 @@ Tree::CreateIslandAndHoles( int nLeafId, std::vector& vPolygons, ptVert.x = m_mTree[nId].GetTopRight().x ; ptVert.y = m_mTree[nId].GetBottomLeft().y ; plInLoop.AddUPoint( 3, ptVert) ; - plInLoop.Close(); + plInLoop.Close() ; vCellPolygons.push_back( plInLoop) ; vPolygons.push_back( vCellPolygons) ; ++ nPoly ; @@ -2512,8 +2452,8 @@ Tree::CreateIslandAndHoles( int nLeafId, std::vector& vPolygons, vCellPolygons.clear() ; plInLoop.Clear() ; } - for ( int i = 0 ; i < nInters ; ++ i) { - inA = m_mTree[nId].m_vInters[i] ; + for ( int nLoop = 0 ; nLoop < nInters ; ++ nLoop) { + inA = m_mTree[nId].m_vInters[nLoop] ; if ( inA.nIn == -1) { // numero di vertici aggiunti al nuovo poligono int k = 0 ; @@ -2521,15 +2461,15 @@ Tree::CreateIslandAndHoles( int nLeafId, std::vector& vPolygons, plInLoop.AddUPoint( k, ptInt) ; ++ k ; } - plInLoop.Close(); + plInLoop.Close() ; bool bAdded = false ; // se il loop è CW devo controllare in quale altro dei poligoni che ho già aggiunto è contenuto if ( ! inA.bCCW) { Point3d ptStart ; plInLoop.GetFirstPoint( ptStart) ; int nOtherPoly = (int)vPolygons.size() ; - for ( int r = 0 ; r < nPoly ; ++r ) { - if ( IsPointInsidePolyLine( ptStart, vPolygons[nOtherPoly - r - 1][0], -0.01) && vnParentChunk[nPoly - r - 1] == inA.nChunk ) { + for ( int r = 0 ; r < nPoly ; ++r) { + if ( IsPointInsidePolyLine( ptStart, vPolygons[nOtherPoly - r - 1][0], -0.01) && vnParentChunk[nLoop - r - 1] == inA.nChunk) { vPolygons[nOtherPoly - r - 1].push_back( plInLoop) ; plInLoop.Clear() ; vnParentChunk.push_back( inA.nChunk) ; @@ -2557,7 +2497,7 @@ Tree::CreateIslandAndHoles( int nLeafId, std::vector& vPolygons, //---------------------------------------------------------------------------- bool -Tree::CheckIfBefore( PolyLine& pl, int nEdge) const +Tree::CheckIfBefore( const PolyLine& pl, const int& nEdge) const { // controllo se ptEnd è prima di ptStart sul lato nEdge rispetto al senso antiorario ( quindi se è dopo in senso orario) Point3d ptStart, ptEnd ; @@ -2566,13 +2506,13 @@ Tree::CheckIfBefore( PolyLine& pl, int nEdge) const if ( AreSameEdge( nEdge, 0)) { return ptEnd.x > ptStart.x ; } - else if ( AreSameEdge( nEdge, 1) ) { + else if ( AreSameEdge( nEdge, 1)) { return ptEnd.y > ptStart.y ; } - else if ( AreSameEdge( nEdge, 2) ) { + else if ( AreSameEdge( nEdge, 2)) { return ptEnd.x < ptStart.x ; } - else if ( AreSameEdge( nEdge, 3) ) { + else if ( AreSameEdge( nEdge, 3)) { return ptEnd.y < ptStart.y ; } return false ; @@ -2580,7 +2520,7 @@ Tree::CheckIfBefore( PolyLine& pl, int nEdge) const //---------------------------------------------------------------------------- bool -Tree::CheckIfBefore( Inters& inA) const +Tree::CheckIfBefore( const Inters& inA) const { // questa funzione è pensata in riferimento al lato 3, quindi nessuno dei due punti può stare su Edge = 3 // controllo se l'ingresso è prima dell'uscita @@ -2614,7 +2554,7 @@ Tree::CheckIfBefore( Inters& inA) const //---------------------------------------------------------------------------- bool -Tree::CheckIfBefore( int& nEdge1, Point3d& ptP1, int& nEdge2, Point3d& ptP2) const +Tree::CheckIfBefore( const int& nEdge1, const Point3d& ptP1, const int& nEdge2, const Point3d& ptP2) const { if ( nEdge1 == -1 || nEdge2 == -1) return false ; @@ -2643,20 +2583,20 @@ Tree::CheckIfBefore( int& nEdge1, Point3d& ptP1, int& nEdge2, Point3d& ptP2) con //---------------------------------------------------------------------------- bool -Tree::CheckIfBefore( int& nEdge, Point3d& ptP1, Point3d& ptP2) const +Tree::CheckIfBefore( const int& nEdge, const Point3d& ptP1, const Point3d& ptP2) const { // sul lato nEdge controllo se ptP1 viene prima di ptP2. // i lati vengono percorsi in senso antiorario - if ( AreSameEdge(nEdge, 0) ) { + if ( AreSameEdge( nEdge, 0)) { return ptP1.x > ptP2.x ; } - else if ( AreSameEdge(nEdge, 1) ) { + else if ( AreSameEdge( nEdge, 1)) { return ptP1.y > ptP2.y ; } - else if ( AreSameEdge(nEdge, 2) ) { + else if ( AreSameEdge( nEdge, 2)) { return ptP1.x < ptP2.x ; } - else if ( AreSameEdge(nEdge, 3) ) { + else if ( AreSameEdge( nEdge, 3)) { return ptP1.y < ptP2.y ; } return false ; @@ -2664,90 +2604,53 @@ Tree::CheckIfBefore( int& nEdge, Point3d& ptP1, Point3d& ptP2) const //---------------------------------------------------------------------------- bool -Tree::CheckIfAfter( PolyLine& pl, Point3d& ptNextStart, int nEdge) const -{ - // controllo se ptNextStart è più avanti rispetto a ptEnd in senso antiorario - // ATTENZIONE i due punti devono essere sullo stesso lato! - - // se i punti non sono sullo stesso lato ritorno false - Point3d ptEnd ; - pl.GetLastPoint( ptEnd) ; - if ( AreSameEdge(nEdge, 0) ) { - if ( ptNextStart.y > ptEnd.y - EPS_SMALL && ptNextStart.y < ptEnd.y + EPS_SMALL) - return ptEnd.x > ptNextStart.x ; - else - return false ; - } - else if ( AreSameEdge(nEdge, 1) ) { - if ( ptNextStart.x > ptEnd.x - EPS_SMALL && ptNextStart.x < ptEnd.x + EPS_SMALL) - return ptEnd.y > ptNextStart.y ; - else - return false ; - } - else if ( AreSameEdge(nEdge, 2) ) { - if ( ptNextStart.y > ptEnd.y - EPS_SMALL && ptNextStart.y < ptEnd.y + EPS_SMALL) - return ptEnd.x < ptNextStart.x ; - else - return false ; - } - else if ( AreSameEdge(nEdge, 3) ) { - if ( ptNextStart.x > ptEnd.x - EPS_SMALL && ptNextStart.x < ptEnd.x + EPS_SMALL) - return ptEnd.y < ptNextStart.y ; - else - return false ; - } - return false ; -} - -//---------------------------------------------------------------------------- -bool -Tree::AreSameEdge( int nEdge1, int nEdge2) const +Tree::AreSameEdge( const int& nEdge1, const int nEdge2) const { if ( nEdge1 == 0) { if ( nEdge2 == 4 || nEdge2 == 0 || nEdge2 == 7) - return true; + return true ; else return false ; } else if ( nEdge1 == 1) { if ( nEdge2 == 4 || nEdge2 == 1 || nEdge2 == 5) - return true; + return true ; else return false ; } else if ( nEdge1 == 2) { if ( nEdge2 == 6 || nEdge2 == 2 || nEdge2 == 5) - return true; + return true ; else return false ; } else if ( nEdge1 == 3) { if ( nEdge2 == 6 || nEdge2 == 3 || nEdge2 == 7) - return true; + return true ; else return false ; } else if ( nEdge1 == 4) { if ( nEdge2 == 0 || nEdge2 == 1 || nEdge2 == 7 || nEdge2 == 5) - return true; + return true ; else return false ; } else if ( nEdge1 == 5) { if ( nEdge2 == 2 || nEdge2 == 1 || nEdge2 == 4 || nEdge2 == 6) - return true; + return true ; else return false ; } else if ( nEdge1 == 6) { if ( nEdge2 == 2 || nEdge2 == 3 || nEdge2 == 5 || nEdge2 == 7) - return true; + return true ; else return false ; } else if ( nEdge1 == 7) { if ( nEdge2 == 0 || nEdge2 == 3 || nEdge2 == 4 || nEdge2 == 6) - return true; + return true ; else return false ; } @@ -2757,7 +2660,7 @@ Tree::AreSameEdge( int nEdge1, int nEdge2) const //---------------------------------------------------------------------------- bool -Tree::AddVertex( int nId, std::vector& vEdgeVertex, PolyLine& plTrimmedPoly, int& c, Point3d& ptToAdd) const +Tree::AddVertex( const int& nId, const std::vector& vEdgeVertex, PolyLine& plTrimmedPoly, int& c, const Point3d& ptToAdd) const { // se è il primo punto della PolyLine lo aggiungo if ( plTrimmedPoly.GetPointNbr() == 0) { @@ -2772,8 +2675,8 @@ Tree::AddVertex( int nId, std::vector& vEdgeVertex, PolyLine& plTrimm Point3d ptLast ; plTrimmedPoly.GetLastPoint( ptLast) ; // verifico di essere allineato con un lato, sennò aggiungo e basta - Vector3d vDir; - if ( ! AreSamePointExact(ptToAdd, ptLast)) + Vector3d vDir ; + if ( ! AreSamePointExact( ptToAdd, ptLast)) vDir = ptToAdd - ptLast ; else return true ; @@ -2794,7 +2697,7 @@ Tree::AddVertex( int nId, std::vector& vEdgeVertex, PolyLine& plTrimm if ( abs( vDir.x) > 1 - EPS_SMALL || abs( vDir.y) > 1 - EPS_SMALL) { // se su un edge devo fare dei controlli // edge 0 - if ( ptToAdd.x >= ptBL.x && ptToAdd.x <= ptTR.x && ptToAdd.y == ptTR.y && abs(vDir.x) > 1 - EPS_SMALL) { + if ( ptToAdd.x >= ptBL.x && ptToAdd.x <= ptTR.x && ptToAdd.y == ptTR.y && abs( vDir.x) > 1 - EPS_SMALL) { for ( int t = 0 ; t < (int)vEdgeVertex[0].size() ; ++ t) { Point3d ptIntermed = vEdgeVertex[0][t] ; if ( ptIntermed.x > ptToAdd.x && ptIntermed.x < ptLast.x) { @@ -2806,7 +2709,7 @@ Tree::AddVertex( int nId, std::vector& vEdgeVertex, PolyLine& plTrimm ++ c ; } // edge 1 - else if ( ptToAdd.y >= ptBL.y && ptToAdd.y <= ptTR.y && ptToAdd.x == ptBL.x && abs(vDir.y) > 1 - EPS_SMALL) { + else if ( ptToAdd.y >= ptBL.y && ptToAdd.y <= ptTR.y && ptToAdd.x == ptBL.x && abs( vDir.y) > 1 - EPS_SMALL) { for ( int t = 0 ; t < (int)vEdgeVertex[1].size() ; ++ t) { Point3d ptIntermed = vEdgeVertex[1][t] ; if ( ptIntermed.y > ptToAdd.y && ptIntermed.y < ptLast.y) { @@ -2818,7 +2721,7 @@ Tree::AddVertex( int nId, std::vector& vEdgeVertex, PolyLine& plTrimm ++ c ; } // edge 2 - else if ( ptToAdd.x >= ptBL.x && ptToAdd.x <= ptTR.x && ptToAdd.y == ptBL.y && abs(vDir.x) > 1 - EPS_SMALL) { + else if ( ptToAdd.x >= ptBL.x && ptToAdd.x <= ptTR.x && ptToAdd.y == ptBL.y && abs( vDir.x) > 1 - EPS_SMALL) { for ( int t = 0 ; t < (int)vEdgeVertex[2].size() ; ++ t) { Point3d ptIntermed = vEdgeVertex[2][t] ; if ( ptIntermed.x < ptToAdd.x && ptIntermed.x > ptLast.x) { @@ -2830,7 +2733,7 @@ Tree::AddVertex( int nId, std::vector& vEdgeVertex, PolyLine& plTrimm ++ c ; } // edge 3 - else if ( ptToAdd.y >= ptBL.y && ptToAdd.y <= ptTR.y && ptToAdd.x == ptTR.x && abs(vDir.y) > 1 - EPS_SMALL) { + else if ( ptToAdd.y >= ptBL.y && ptToAdd.y <= ptTR.y && ptToAdd.x == ptTR.x && abs( vDir.y) > 1 - EPS_SMALL) { for ( int t = 0 ; t < (int)vEdgeVertex[3].size() ; ++ t) { Point3d ptIntermed = vEdgeVertex[3][t] ; if ( ptIntermed.y < ptToAdd.y && ptIntermed.y > ptLast.y) { @@ -2844,13 +2747,13 @@ Tree::AddVertex( int nId, std::vector& vEdgeVertex, PolyLine& plTrimm // sono allineato con un lato, ma NON sono su un lato // aggiungo e basta else { - plTrimmedPoly.AddUPoint( c, ptToAdd); + plTrimmedPoly.AddUPoint( c, ptToAdd) ; ++ c ; } } // non su un edge, quindi aggiungo e basta else { - plTrimmedPoly.AddUPoint( c, ptToAdd); + plTrimmedPoly.AddUPoint( c, ptToAdd) ; ++ c ; } return true ; @@ -2861,19 +2764,19 @@ Tree::AddVertex( int nId, std::vector& vEdgeVertex, PolyLine& plTrimm //bool //Tree::SetRightEdgeIn( int nId, std::vector& vEdgeVertex, PolyLine& plTrimmedPoly) //{ -// Point3d ptBr( m_mTree.at(nId).GetTopRight().x , m_mTree.at(nId).GetBottomLeft().y) ; -// Point3d ptTR = m_mTree.at(nId).GetTopRight() ; +// Point3d ptBr( m_mTree.at( nId).GetTopRight().x , m_mTree.at( nId).GetBottomLeft().y) ; +// Point3d ptTR = m_mTree.at( nId).GetTopRight() ; // int nPos0 = -1 , nPos1 = -1 ; // bool bSave = false ; // PNTLIST lPtInt ; // for ( int k = 0 ; k < plTrimmedPoly.GetPointNbr() ; ++ k) { // Point3d ptIter ; // plTrimmedPoly. GetNextPoint( ptIter) ; -// if ( AreSamePointExact( ptIter, ptBr) ) { +// if ( AreSamePointExact( ptIter, ptBr)) { // nPos0 = k ; // bSave = bSave ^ true ; // } -// if ( AreSamePointExact( ptIter, ptTR) ) { +// if ( AreSamePointExact( ptIter, ptTR)) { // nPos1 = k ; // bSave = bSave ^ true ; // } @@ -2883,7 +2786,7 @@ Tree::AddVertex( int nId, std::vector& vEdgeVertex, PolyLine& plTrimm // } // lPtInt.pop_front() ; // // verifico se ci sono tutti e due i punti -// if ( nPos0 != -1 && nPos1 != -1 ) { +// if ( nPos0 != -1 && nPos1 != -1) { // // se sono di seguito tutto il lato destro è dentro // if ( nPos1 == nPos0 + 1 || nPos0 == nPos1 + 1) { // m_mTree[nId].m_nRightEdgeIn = 1 ; @@ -2896,7 +2799,7 @@ Tree::AddVertex( int nId, std::vector& vEdgeVertex, PolyLine& plTrimm // bool bAllOn = true ; // // PNTLIST::iterator lIter = lPtInt.begin() ; -// std::advance(lIter, 0) ; +// std::advance( lIter, 0) ; // for ( int p = 0 ; p < (int)lPtInt.size() ; ++ p) { // if ( ! clRightEdge.IsPointOn( *lIter)) { // bAllOn = false ; @@ -2923,16 +2826,14 @@ Tree::AddVertex( int nId, std::vector& vEdgeVertex, PolyLine& plTrimm //usando le intersezioni con le celle //---------------------------------------------------------------------------- bool -Tree::SetRightEdgeIn( int nId) +Tree::SetRightEdgeIn( const int& nId) { // categorizzo la cella in base a quanta parte del lato destro è conenuta all'interno delle curve di trim // RightEdgeIn -> 0 non contenuto ; 1 contenuto ; 2 in parte contenuto - Point3d ptBr( m_mTree.at(nId).GetTopRight().x , m_mTree.at(nId).GetBottomLeft().y) ; - Point3d ptTR = m_mTree.at(nId).GetTopRight() ; int nPass = (int) m_mTree[nId].m_vInters.size() ; bool bDone = false ; // se ho solo loop interni devo controllare se il più esterno è CCW ( lato destro esterno) o CW ( lato destro interno) - if ( m_mTree[nId].m_nFlag == 2 ) { + if ( m_mTree[nId].m_nFlag == 2) { bool bAllContained = true ; bool bContained = false ; Inters inA ; @@ -2982,7 +2883,7 @@ Tree::SetRightEdgeIn( int nId) bDone = true ; break ; } - else if ( m_mTree[nId].m_vInters[k].nOut == 7 && m_mTree[nId].m_vInters[k].nIn == 6 ) { + else if ( m_mTree[nId].m_vInters[k].nOut == 7 && m_mTree[nId].m_vInters[k].nIn == 6) { m_mTree[nId].m_nRightEdgeIn = 0 ; bDone = true ; break ; @@ -3040,7 +2941,7 @@ Tree::SetRightEdgeIn( int nId) //---------------------------------------------------------------------------- bool -Tree::CategorizeCell( int& nId) +Tree::CategorizeCell( const int& nId) { if ( m_mTree[nId].m_nFlag != -1) { return true ; @@ -3050,7 +2951,7 @@ Tree::CategorizeCell( int& nId) // mi servono i vicini di sinistra per capire se sono dentro il loop o fuori // nRightEdgeIn // 0 right edge fuori, 1 right edge dentro, 2 metà e metà // nFlag // 0 fuori, 1 intersecata, 2 contiene loop, 3 = 1 & 2, 4 dentro - if ( (int)vNeigh.size() == 0 ) { + if ( (int)vNeigh.size() == 0) { m_mTree[nId].m_nFlag = 0 ; } else if ( (int)vNeigh.size() == 1) { @@ -3070,7 +2971,7 @@ Tree::CategorizeCell( int& nId) } // se solo parte del right edge del vicino è compreso, allora devo verificare se la cella è contenuta o no // guardando nFlag del vicino bottom, che è già categorizzato! - else if ( m_mTree[vNeigh[0]].m_nRightEdgeIn == 2 ) { + else if ( m_mTree[vNeigh[0]].m_nRightEdgeIn == 2) { GetBottomNeigh( nId, vNeigh1) ; if ( (int) vNeigh1.size() > 0) { int nNeigh = vNeigh1[0] ; @@ -3085,16 +2986,16 @@ Tree::CategorizeCell( int& nId) m_mTree[nId].m_nFlag = 0 ; else if ( m_mTree[nNeigh].m_nRightEdgeIn == 1) m_mTree[nId].m_nFlag = 4 ; - else if ( m_mTree[nNeigh].m_nRightEdgeIn == 2 ) { + else if ( m_mTree[nNeigh].m_nRightEdgeIn == 2) { // in questo caso devo verificare le intersezioni sul lato destro del vicino bottom // scorro e cerco l'intersezione più alta, se è out la cella è dentro, se è in devo verificare l'out se è più a sinistra o a destra. int nPass = (int) m_mTree[nNeigh].m_vInters.size() ; bool bTopMost = false ; - bool bFound = false; + bool bFound = false ; Point3d ptInters, ptBr( m_mTree[nNeigh].GetTopRight().x, m_mTree[nNeigh].GetBottomLeft().y) ; ptInters = ptBr ; // inizializzato a vertice bottom right - int nEdgeIn = 3, nEdgeOut = 3, nLoop ; - for ( int r = 0 ; r < nPass; ++ r ) { + int nLoop ; + for ( int r = 0 ; r < nPass ; ++ r) { // trovo il loop che ha l'ingresso o l'uscita più in alto sul lato destro // verifico che o l'ingresso o l'uscita siano sul lato destro e che sia l'intersezione più alta su quel lato if ( m_mTree[nNeigh].m_vInters[r].nIn == 3 && ! CheckIfBefore( m_mTree[nNeigh].m_vInters[r].nIn, m_mTree[nNeigh].m_vInters[r].vpt[0], ptInters)) { @@ -3114,7 +3015,7 @@ Tree::CategorizeCell( int& nId) bFound = true ; break ; } - if ( m_mTree[nNeigh].m_vInters[r].nOut == 6 || m_mTree[nNeigh].m_vInters[r].nIn == 6 ) { + if ( m_mTree[nNeigh].m_vInters[r].nOut == 6 || m_mTree[nNeigh].m_vInters[r].nIn == 6) { nLoop = r ; ptInters = ptBr ; bFound = true ; @@ -3124,15 +3025,15 @@ Tree::CategorizeCell( int& nId) bTopMost = true ; } if ( bFound && bTopMost) { - if ( AreSameEdge(m_mTree[nNeigh].m_vInters[nLoop].nIn, 3) && AreSameEdge(m_mTree[nNeigh].m_vInters[nLoop].nOut, 3) ) { + if ( AreSameEdge( m_mTree[nNeigh].m_vInters[nLoop].nIn, 3) && AreSameEdge( m_mTree[nNeigh].m_vInters[nLoop].nOut, 3)) { if ( CheckIfBefore( m_mTree[nNeigh].m_vInters[nLoop])) m_mTree[nId].m_nFlag = 4 ; else m_mTree[nId].m_nFlag = 0 ; } - else if ( AreSameEdge(m_mTree[nNeigh].m_vInters[nLoop].nOut, 3)) + else if ( AreSameEdge( m_mTree[nNeigh].m_vInters[nLoop].nOut, 3)) m_mTree[nId].m_nFlag = 4 ; - else if ( AreSameEdge(m_mTree[nNeigh].m_vInters[nLoop].nIn, 3) ) { + else if ( AreSameEdge( m_mTree[nNeigh].m_vInters[nLoop].nIn, 3)) { // devo verificare se l'uscita è più a sinistra o più a destra della cella Point3d ptOut = m_mTree[nNeigh].m_vInters[nLoop].vpt.back() ; Point3d ptBr( m_mTree[nId].GetTopRight().x, m_mTree[nId].GetBottomLeft().y) ; @@ -3148,21 +3049,18 @@ Tree::CategorizeCell( int& nId) // se non ho vicini bottom devo per forza guardare il vicino a sinistra else { Point3d ptInters = m_mTree[vNeigh[0]].GetTopRight() ; - int nLoop ; int nEdge = 3 ; bool bIntersIn ; - for ( int k = 0 ; k < (int) m_mTree[vNeigh[0]].m_vInters.size() ; ++ k ) { - if ( AreSameEdge(m_mTree[vNeigh[0]].m_vInters[k].nIn, 3) ) { + for ( int k = 0 ; k < (int) m_mTree[vNeigh[0]].m_vInters.size() ; ++ k) { + if ( AreSameEdge( m_mTree[vNeigh[0]].m_vInters[k].nIn, 3)) { if ( CheckIfBefore( nEdge, m_mTree[vNeigh[0]].m_vInters[k].vpt[0], ptInters)) { ptInters = m_mTree[vNeigh[0]].m_vInters[k].vpt[0] ; - nLoop = k ; bIntersIn = true ; } } - if ( AreSameEdge(m_mTree[vNeigh[0]].m_vInters[k].nOut, 3)) { - if ( CheckIfBefore( nEdge, m_mTree[vNeigh[0]].m_vInters[k].vpt.back(), ptInters) ) { + if ( AreSameEdge( m_mTree[vNeigh[0]].m_vInters[k].nOut, 3)) { + if ( CheckIfBefore( nEdge, m_mTree[vNeigh[0]].m_vInters[k].vpt.back(), ptInters)) { ptInters = m_mTree[vNeigh[0]].m_vInters[k].vpt.back() ; - nLoop = k ; bIntersIn = false ; } } @@ -3198,7 +3096,7 @@ Tree::CategorizeCell( int& nId) //---------------------------------------------------------------------------- bool -Tree::CheckIfBetween( Inters& inA, Inters& inB) const +Tree::CheckIfBetween( const Inters& inA, const Inters& inB) const { // controllo se inB è compreso tra l'end e lo start di inA // ( dall'end di A percorro i bordi della cella fino a tornare allo start e devo incontrare In e Out di B) @@ -3220,11 +3118,11 @@ Tree::CheckIfBetween( Inters& inA, Inters& inB) const vEdges.push_back( nEdge) ; bool bFound = false ; for ( int i : vEdges) { - if ( AreSameEdge(inB.nIn, i)) { - if ( AreSameEdge(inB.nIn, inA.nIn) && AreSameEdge(inA.nIn, inA.nOut)) { + if ( AreSameEdge( inB.nIn, i)) { + if ( AreSameEdge( inB.nIn, inA.nIn) && AreSameEdge( inA.nIn, inA.nOut)) { nEdge = inA.nIn ; - //se l'inizio di A è prima della fine, allora devo controllare che B sia compreso tra Out e In (esterno) - if ( CheckIfBefore( nEdge, inA.vpt[0], inA.vpt.back()) ) { + //se l'inizio di A è prima della fine, allora devo controllare che B sia compreso tra Out e In ( esterno) + if ( CheckIfBefore( nEdge, inA.vpt[0], inA.vpt.back())) { if ( CheckIfBefore( nEdge, inA.vpt.back(), inB.vpt[0]) || CheckIfBefore( nEdge, inB.vpt[0], inA.vpt[0])) bFound = true ; } @@ -3234,27 +3132,28 @@ Tree::CheckIfBetween( Inters& inA, Inters& inB) const bFound = true ; } } - else if ( AreSameEdge(inB.nIn, inA.nOut)) { + else if ( AreSameEdge( inB.nIn, inA.nOut)) { PolyLine pl ; pl.AddUPoint( 0, inA.vpt[0]) ; pl.AddUPoint( 1, inA.vpt.back()) ; - if ( CheckIfAfter( pl, inB.vpt[0], i)) + Point3d ptEnd ; pl.GetLastPoint( ptEnd) ; + if ( CheckIfBefore( i, ptEnd, inB.vpt[0])) bFound = true ; } - else if ( AreSameEdge(inB.nIn, inA.nIn)) { + else if ( AreSameEdge( inB.nIn, inA.nIn)) { //devo controllare il loop b sia prima dell'inizio di A - if ( CheckIfBefore(inA.nIn, inB.vpt[0], inA.vpt[0])) + if ( CheckIfBefore( inA.nIn, inB.vpt[0], inA.vpt[0])) bFound = true ; } else // devo controllare che inB sia prima di OutB - if ( AreSameEdge(inB.nOut, inB.nIn) && CheckIfBefore( inB.nOut, inB.vpt[0], inB.vpt.back())) { + if ( AreSameEdge( inB.nOut, inB.nIn) && CheckIfBefore( inB.nOut, inB.vpt[0], inB.vpt.back())) { bFound = true ; } - else if ( ! AreSameEdge(inB.nOut,inB.nIn)) + else if ( ! AreSameEdge( inB.nOut,inB.nIn)) bFound = true ; } - if ( AreSameEdge(inB.nOut, i) && ! bFound && CheckIfBefore(i, inA.vpt[0], inB.vpt.back()) && CheckIfBefore(i, inA.vpt.back(), inB.vpt.back())) + if ( AreSameEdge( inB.nOut, i) && ! bFound && CheckIfBefore( i, inA.vpt[0], inB.vpt.back()) && CheckIfBefore( i, inA.vpt.back(), inB.vpt.back())) break ; } return bFound ; @@ -3275,10 +3174,10 @@ Tree::GetLeaves( std::vector& vLeaves) const //---------------------------------------------------------------------------- bool -Tree::OnWhichEdge( int nId, Point3d& ptToAssign, int& nEdge) const +Tree::OnWhichEdge( const int& nId, const Point3d& ptToAssign, int& nEdge) const { - Point3d ptTR = m_mTree.at(nId).GetTopRight() ; - Point3d ptBL = m_mTree.at(nId).GetBottomLeft() ; + Point3d ptTR = m_mTree.at( nId).GetTopRight() ; + Point3d ptBL = m_mTree.at( nId).GetBottomLeft() ; Point3d ptTl ( ptBL.x, ptTR.y) ; Point3d ptBr ( ptTR.x, ptBL.y) ; diff --git a/Tree.h b/Tree.h index cbe70a6..3f79dac 100644 --- a/Tree.h +++ b/Tree.h @@ -68,19 +68,19 @@ class Cell public : ~Cell( void) ; Cell( void) ; - Cell( Point3d& ptBL, Point3d& ptTR) ; + Cell( const Point3d& ptBL, const Point3d& ptTR) ; inline bool IsSame( const Cell& cOtherCell) const ; - void SetBottomLeft( Point3d ptBL) { m_ptPbl = ptBL ; } - void SetTopRight( Point3d ptTR) { m_ptPtr = ptTR ; } - void SetSplitDirVert( bool bVert) { m_bSplitVert = bVert ; } - void SetParent( int nParent) { m_nParent = nParent ; } + void SetBottomLeft( const Point3d ptBL) { m_ptPbl = ptBL ; } + void SetTopRight( const Point3d ptTR) { m_ptPtr = ptTR ; } + void SetSplitDirVert( const bool bVert) { m_bSplitVert = bVert ; } + void SetParent( const int& nParent) { m_nParent = nParent ; } Point3d GetBottomLeft( void) const { return m_ptPbl ; } Point3d GetTopRight( void) const { return m_ptPtr ; } double GetSplitValue( void) const { return m_dSplit ; } bool IsSplitVert( void) const { return m_bSplitVert ; } // se true la cella verrebbe splittata verticalmente, sennò orizzontalmente bool IsLeaf( void) const ; // flag che indica se la cella ha figli o se è una foglia bool IsProcessed( void) const { return m_bProcessed ; } // flag che indica se tutti i figli della cella, se ce ne sono, sono stati processati - void SetProcessed( bool bProcessed = true) { m_bProcessed = bProcessed ; } + void SetProcessed( const bool bProcessed = true) { m_bProcessed = bProcessed ; } static bool minorX ( const Cell& c1, const Cell& c2) { return c1.m_ptPbl.x < c2.m_ptPbl.x ; } static bool minorY ( const Cell& c1, const Cell& c2) { return c1.m_ptPbl.y < c2.m_ptPbl.y ; } @@ -99,7 +99,6 @@ class Cell // 0 esterna, 1 intersecata, 2 contiene un loop, 3 intersecata e contenente un loop, 4 contenuta in un loop int m_nFlag2 ; // falg che indica se la cella è stata attraversata durante l'ultima fase del labelling int m_nRightEdgeIn ; // 0 right edge fuori, 1 right edge dentro, 2 metà e metà - //INTVECTOR m_vnLoop ; // indice dei loop contenuti nella cella std::vector m_vInters ; // vettore delle intersezioni della cella con i loop di trim // ogni elemento del vettore è l'insieme dei punti che caratterizza un atrtaversamento della cella @@ -116,47 +115,46 @@ class Tree public : ~Tree( void) ; Tree( void) ; - Tree ( const SurfBezier* pSrfBz, bool bSplitPatches = true) ; - void SetSurf( const SurfBezier* pSrfBz, bool bSplitPatches = true) ; - bool BuildTree( double dLinTol = LIN_TOL_STD, double dSideMin = 5, double dSideMax = INFINITO) ; // dSideMax è il massimo per la dimensione maggiore di un triangolo della trimesh + Tree ( const SurfBezier* pSrfBz, const bool bSplitPatches = true) ; + void SetSurf( const SurfBezier* pSrfBz, const bool bSplitPatches = true) ; + bool BuildTree( const double dLinTol = LIN_TOL_STD, const double dSideMin = 5, const double dSideMax = INFINITO) ; // dSideMax è il massimo per la dimensione maggiore di un triangolo della trimesh // dSideMin è lunghezza minima del lato di una cella nello spazio reale - bool BuildTree_test( double dLinTol = LIN_TOL_STD, double dSideMin = 5, double dSideMax = INFINITO) ; + bool BuildTree_test( const double dLinTol = LIN_TOL_STD, const double dSideMin = 5, const double dSideMax = INFINITO) ; bool GetPolygons( std::vector& vPolygons) ; bool GetPolygonsBasic( POLYLINEVECTOR& vPolygons) ; // restituisce il poligono corrispondente ad ogni cella foglia dell'albero // ad ogni poligono sono stati aggiunti tutti i vertici dei vicini posizionati sui suoi lati bool GetLeaves ( std::vector& vLeaves) const ; private : - void Split( int nId, double dSplitValue) ; // funzione di split di una cella al parametro indicato nella direzione data da bVert - void Split( int nId) ; // funzione di split di una cella dell'albero a metà nella direzione data da bVert + void Split( const int& nId, const double& dSplitValue) ; // funzione di split di una cella al parametro indicato nella direzione data da bVert + void Split( const int& nId) ; // funzione di split di una cella dell'albero a metà nella direzione data da bVert void Balance () ; // creo rami in modo che tutte tutte le foglie abbiano come adiacenti foglie ad una profonditù di +- 1 - int GetHeightLeaves ( int nId, INTVECTOR& vnLeaves, int d = 0) const ; // altezza del subtree a partire dal nodo nId - int GetDepth ( int nId, int nRef) const ; // livello del nodo nId - void GetTopNeigh( int nId, INTVECTOR& vTopNeighs) const ; // restituisce le celle foglie che sono adiacenti al lato top - void GetBottomNeigh( int nId, INTVECTOR& vBottomNeighs) const ; // restituisce le celle foglie che sono adiacenti al lato bottom - void GetLeftNeigh( int nId, INTVECTOR& vLeftNeighs) const ; // restituisce le celle foglie che sono adiacenti al lato left - void GetRightNeigh( int nId, INTVECTOR& vRightNeighs) const ; // restituisce le celle foglie che sono adiacenti al lato right - void GetRootNeigh( int nEdge, INTVECTOR& vNeigh) ; // restituisce le foglie dell'albero che sono adiacenti al lato nEdge, numerato a partire dal top ( 0) in senso antiorario + int GetHeightLeaves ( const int& nId, INTVECTOR& vnLeaves, int d = 0) const ; // altezza del subtree a partire dal nodo nId + int GetDepth ( const int& nId, const int& nRef) const ; // livello del nodo nId + void GetTopNeigh( const int& nId, INTVECTOR& vTopNeighs) const ; // restituisce le celle foglie che sono adiacenti al lato top + void GetBottomNeigh( const int& nId, INTVECTOR& vBottomNeighs) const ; // restituisce le celle foglie che sono adiacenti al lato bottom + void GetLeftNeigh( const int& nId, INTVECTOR& vLeftNeighs) const ; // restituisce le celle foglie che sono adiacenti al lato left + void GetRightNeigh( const int& nId, INTVECTOR& vRightNeighs) const ; // restituisce le celle foglie che sono adiacenti al lato right + void GetRootNeigh( const int& nEdge, INTVECTOR& vNeigh) ; // restituisce le foglie dell'albero che sono adiacenti al lato nEdge, numerato a partire dal top ( 0) in senso antiorario void ResetTree ( void) ; // resetto m_bProcessed a false per tutti i nodi dell'albero - INTVECTOR FindCell ( const Point3d& ptToAssign, CurveLine& cl) const ; // dato un punto, trova la cella foglia a cui appartiene - INTVECTOR FindCell ( const Point3d& ptToAssign, CurveLine& cl, INTVECTOR vCells) const ; // dato un punto, trova la cella foglia a cui appartiene + INTVECTOR FindCell ( const Point3d& ptToAssign, const CurveLine& cl) const ; // dato un punto, trova la cella foglia a cui appartiene + INTVECTOR FindCell ( const Point3d& ptToAssign, const CurveLine& cl, INTVECTOR vCells) const ; // dato un punto, trova la cella foglia a cui appartiene bool TraceLoopLabelCell( void) ; // tracing dei loop e labelling delle celle - bool FindInters( int& nId, CurveLine& clTrim, PNTVECTOR& vptInters, bool bFirstInters = true) ; // trova le intersezioni tra una cella e una linea di trim + bool FindInters( int& nId, const CurveLine& clTrim, PNTVECTOR& vptInters, bool bFirstInters = true) ; // trova le intersezioni tra una cella e una linea di trim // resituisce l'id della cella verso cui la curva di trim esce e il vettore delle intersezioni per la cella successiva con il primo punto - bool CreateCellPolygons ( int nLeafId, std::vector& vPolygons, INTVECTOR& vToCheck, int& nPoly, INTVECTOR& vnParentChunk, PolyLine plCell) ; - bool CreateIslandAndHoles ( int nLeafId, std::vector& vPolygons, int& nPoly, INTVECTOR& vnParentChunk) ; - bool CheckIfBefore( PolyLine& pl, int nEdge) const ; - bool CheckIfBefore( Inters& inA) const ; - bool CheckIfBefore( int& nEdge1, Point3d& ptP1, int& nEdge2, Point3d& ptP2) const ; - bool CheckIfBefore( int& nEdge, Point3d& ptP1, Point3d& ptP2) const ; - bool CheckIfAfter( PolyLine& pl, Point3d& ptNextStart, int nEdge) const ; - bool AreSameEdge( int nEdge1, int nEdge2) const ; - bool AddVertex( int nId, std::vector& vEdgeVertex, PolyLine& plTrimmedPoly, int& c, Point3d& ptToAdd) const ; + bool CreateCellPolygons ( const int& nLeafId, std::vector& vPolygons, INTVECTOR& vToCheck, int& nPoly, INTVECTOR& vnParentChunk, const PolyLine& plCell) ; + bool CreateIslandAndHoles ( const int& nLeafId, std::vector& vPolygons, int& nPoly, INTVECTOR& vnParentChunk) ; + bool CheckIfBefore( const PolyLine& pl, const int& nEdge) const ; + bool CheckIfBefore( const Inters& inA) const ; + bool CheckIfBefore( const int& nEdge1, const Point3d& ptP1, const int& nEdge2, const Point3d& ptP2) const ; + bool CheckIfBefore( const int& nEdge, const Point3d& ptP1, const Point3d& ptP2) const ; + bool AreSameEdge( const int& nEdge1, const int nEdge2) const ; + bool AddVertex( const int& nId, const std::vector& vEdgeVertex, PolyLine& plTrimmedPoly, int& c, const Point3d& ptToAdd) const ; //bool SetRightEdgeIn( int nId, std::vector& vEdgeVertex, PolyLine& plTrimmedPoly) ; - bool SetRightEdgeIn( int nId) ; - bool CategorizeCell( int& nId) ; - bool CheckIfBetween( Inters& inA, Inters& inB) const ; - bool OnWhichEdge( int nId, Point3d& ptToAssign, int& nEdge) const ; + bool SetRightEdgeIn( const int& nId) ; + bool CategorizeCell( const int& nId) ; + bool CheckIfBetween( const Inters& inA, const Inters& inB) const ; + bool OnWhichEdge( const int& nId, const Point3d& ptToAssign, int& nEdge) const ; private : const SurfBezier* m_pSrfBz ; // superficie di bezier @@ -164,7 +162,6 @@ private : bool m_bTrimmed ; // superficie trimmata std::vector m_vChunk ; // elenco dei loop divisi per chunk std::map m_mChunk ; - //std::vector m_vLoop ; ICURVEPOVECTOR m_vLoop ; // curve di loop. la 0 è il bordo dello spazio parametrico, le altre sono i loop interni bool m_bBilinear ; // superficie bilineare bool m_bMulti ; // superficie multi-patch @@ -174,8 +171,7 @@ private : int m_nDegV ; // grado della superficie nel parametro V int m_nSpanU ; int m_nSpanV ; - std::vector m_vPolygons ; // vettore dei poligoni del tree - //std::map m_mPolygons ; // mappa dei poligoni + std::vector m_vPolygons ; // vettore dei poligoni del tree std::map m_mTree ; // mappa che contiene tutti i nodi e le foglie dell'albero. -2 è puntatore Null e -1 è root std::map m_mVert ; // mappa che contiene tutti i vertici 3d delle celle del tree. L'Id è lo stesso che la cella ha in m_mTree INTVECTOR m_vnLeaves ; // vettore delle foglie