From 4daa62db978a542f6e823deb5075e83fd938fcd5 Mon Sep 17 00:00:00 2001 From: Daniele Bariletti Date: Thu, 15 Jun 2023 10:47:53 +0200 Subject: [PATCH] EgtGeomKernel : - risolti i bug noti - fatti con successo test con superfici e curve complesse manca - pulizia del codice. --- SurfBezier.cpp | 10 +- Tree.cpp | 310 +++++++++++++------------------------------------ Tree.h | 2 +- 3 files changed, 90 insertions(+), 232 deletions(-) diff --git a/SurfBezier.cpp b/SurfBezier.cpp index b74b70c..bbf3689 100644 --- a/SurfBezier.cpp +++ b/SurfBezier.cpp @@ -1500,8 +1500,9 @@ SurfBezier::GetAuxSurf( void) const // costruttore della superficie Tree Tree( this, true) ; - Tree.BuildTree_test() ; - //Tree.BuildTree( 0.05, 1) ; + //Tree.BuildTree_test() ; + Tree.BuildTree( 0.05, 1) ; + //Tree.BuildTree( 0.2, 5) ; //Tree.BuildTree( 0.5, 10) ; //Tree.BuildTree( 1, 25) ; vector vvPL ; @@ -1547,8 +1548,9 @@ bool SurfBezier::GetLeaves( std::vector>& vLeaves) const { Tree Tree( this, true) ; - Tree.BuildTree_test() ; - //Tree.BuildTree( 0.05, 1) ; + //Tree.BuildTree_test() ; + Tree.BuildTree( 0.05, 1) ; + //Tree.BuildTree( 0.2, 5) ; //Tree.BuildTree( 0.5, 10) ; //Tree.BuildTree( 1, 25) ; std::vector vCells ; diff --git a/Tree.cpp b/Tree.cpp index a357514..c8245c4 100644 --- a/Tree.cpp +++ b/Tree.cpp @@ -1245,7 +1245,6 @@ Tree::GetPolygons( std::vector& vPolygons) { else { // vettore in cui salvo il chunk di appartenenza di ogni loop che attraversa la cella INTVECTOR vnParentChunk ; - //int nEdgeIn = -1 ; // vettore in cui salvo i loop che non appartengono al poligono che sto cotruendo nel ciclo attuale e da cui ripasserò dopo INTVECTOR vToCheck( (int) m_mTree[nId].m_vInters.size()) ; std::generate_n( vToCheck.begin(), (int) m_mTree[nId].m_vInters.size(), generator()) ; @@ -1280,7 +1279,7 @@ Tree::GetPolygonsBasic( POLYLINEVECTOR& vPolygons) PNTVECTOR vVertices ; INTVECTOR vNeigh ; bool bBottomRight , bTopLeft ; - // scorro lungo tutte le celle leaves ( dell'albero bilanciato) e oltre agli angoli della cella aggiungo alla polyline anche i vertici sui lati + // scorro lungo tutte le celle leaves e oltre agli angoli della cella aggiungo alla polyline anche i vertici sui lati for ( int nId : m_vnLeaves) { vVertices.clear() ; vNeigh.clear() ; @@ -1378,32 +1377,6 @@ Tree::GetPolygonsBasic( POLYLINEVECTOR& vPolygons) void Tree::ResetTree( void) { - //// setto tutti i nodi (foglie comprese) a Processed = false - //int nCToReset = -1 ; - //while ( nCToReset != -2 && m_mTree[nCToReset].IsProcessed() == true) { - // if ( m_mTree[nCToReset].IsLeaf()) { - // m_mTree[nCToReset].SetProcessed( false) ; - // - // // risalgo i parent finché non trovo il primo Child2 da deprocessare - // nCToReset = m_mTree[nCToReset].m_nParent ; - // if ( ! m_mTree[m_mTree[nCToReset].m_nChild1].IsProcessed() && ! m_mTree[m_mTree[nCToReset].m_nChild2].IsProcessed()) - // m_mTree[nCToReset].SetProcessed( false) ; - // while ( ! m_mTree[m_mTree[nCToReset].m_nChild2].IsProcessed()) { - // if ( m_mTree[nCToReset].m_nParent != -2) - // nCToReset = m_mTree[nCToReset].m_nParent ; - // if ( ! m_mTree[m_mTree[nCToReset].m_nChild1].IsProcessed() && ! m_mTree[m_mTree[nCToReset].m_nChild2].IsProcessed()) - // m_mTree[nCToReset].SetProcessed( false) ; - // if ( nCToReset == -1 && ! m_mTree[m_mTree[nCToReset].m_nChild2].IsProcessed()) - // break ; - // } - // nCToReset = m_mTree[nCToReset].m_nChild2 ; - - // } - // else { - // nCToReset = m_mTree[nCToReset].m_nChild1 ; - // } - //} - // setto tutte le foglie a Processed = false for ( int nC : m_vnLeaves ) { m_mTree[nC].SetProcessed( false) ; @@ -1414,8 +1387,6 @@ Tree::ResetTree( void) INTVECTOR Tree::FindCell( const Point3d& ptToAssign, CurveLine& clTrim) const { - // riordino le celle da sinistra a destra ( rispetto al verso della cl) - // devo ancora aggiungerla questa feature!!!//////////////////////////////////////////////////////////////////////////////////////////////////////////// INTVECTOR nCells ; int nId = -1 ; // se fallisce ritorna un vettore vuoto @@ -1425,12 +1396,6 @@ Tree::FindCell( const Point3d& ptToAssign, CurveLine& clTrim) const //nCells.push_back( - 2) ; return nCells ; } - - //// se lo spazio parametrico non è stato suddiviso ( ho un piano), restituisco la cella root - //if ( m_mTree.at(nId).IsLeaf() ) { - // nCells.push_back( nId) ; - // return nCells ; - //} // se ho diviso preliminarmente le patches e in uno dei due parametri ho un numero dispari di patches devo individuare a mano la cella parent // in cui individuare la foglia giusta @@ -1459,46 +1424,11 @@ Tree::FindCell( const Point3d& ptToAssign, CurveLine& clTrim) const } } } - //if ( nId != -1) - // nCells.push_back( nId) ; - - //if ( nId == -1) - // nId = -2 ; nCells.push_back( nId) ; - //// devo verificare se sono sul bordo di una cella: in questo caso dovrei restituire anche il vicino con cui condivido quel lato!! ///////////////////// - 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) ; - //IntCrvCrvInfo aInfo, bInfo ; - //CurveLine clEdge, clEdge2 ; - //if ( AreSamePointApprox(ptToAssign, ptTl)){ - // // lato top - // clEdge.Set( m_mTree.at(nId).GetTopRight(), ptTl) ; - // IntersLineLine illTrimEdge( clTrim, clEdge, true) ; - // illTrimEdge.GetIntCrvCrvInfo( aInfo) ; - // // lato sinistro - // clEdge2.Set( ptTl, m_mTree.at(nId).GetBottomLeft()) ; - // IntersLineLine illTrimEdge2( clTrim, clEdge2, true) ; - // illTrimEdge2.GetIntCrvCrvInfo( bInfo) ; - // if ( aInfo.bOverlap) { - // if ( aInfo.bCBOverEq ) { - - // } - // } - //} - //else if ( AreSamePointApprox( ptToAssign, m_mTree.at(nId).GetBottomLeft())) { - - //} - //else if ( AreSamePointApprox(ptToAssign, ptBr)) { - - //} - //else if (AreSamePointApprox( ptToAssign, ptTl)) { - - //} - - if ( AreSamePointApprox(ptToAssign, ptTl) || AreSamePointApprox( ptToAssign, m_mTree.at(nId).GetBottomLeft()) || AreSamePointApprox(ptToAssign, ptBr) || @@ -1545,10 +1475,6 @@ Tree::FindCell( const Point3d& ptToAssign, CurveLine& cl, INTVECTOR vCells) cons nId = nCell ; nCells.push_back( nId) ; } - //if ( bFound) - // break ; - //if ( nCells.size() > 0) - // bFound = true ; } return nCells ; } @@ -1596,15 +1522,10 @@ Tree::TraceLoopLabelCell( void) std::advance( ptSecond, 1) ; CurveLine clFirst ; clFirst.Set( ptFirst->first, ptSecond->first) ; + // individuo la cella da cui parte il loop INTVECTOR nCells = FindCell( ptStart, clFirst) ; - int nId, nFirstCell ; - if ( (int)nCells.size() == 1) { - nId = nCells[0] ; - } - else { - nId = nCells.back() ; - } - nFirstCell = nId ; + int nId = nCells.back() ; + int nFirstCell = nId ; // trovo quali punti della polyline sono nella cella e l'intersezione PNTVECTOR vptInters ; vptInters.push_back( ptStart) ; @@ -1621,7 +1542,6 @@ Tree::TraceLoopLabelCell( void) Point3d ptCurr ; INTVECTOR :: iterator iter = find( m_vnLeaves.begin(), m_vnLeaves.end(), nId) ; int nIdPolygon = std::distance( m_vnLeaves.begin(), iter) ; - bool bVertex = false ; bool bEraseNextPoint = false ; while ( plLoop.GetNextPoint( ptCurr)) { // sto uscendo dalla cella, quindi cerco l'intersezione @@ -1637,11 +1557,10 @@ Tree::TraceLoopLabelCell( void) } bLoopInside = false ; // trovo l'intersezione e passo alla cella successiva. nId viene aggiornato dalla funzione FindInters - bVertex = false ; // se non trovo l'intersezione vuol dire che non sono nella cella giusta! // al precedente FindInters avrei dovuto passare di cella - if ( ! FindInters( nId, clTrim, vptInters, bVertex)) { - // scaterò il punto molto vicino al lato e tengo solo l'intersezione del trim col lato + 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() ; plLoop.GetPrevPoint( ptTEnd) ; plLoop.GetPrevPoint( ptTStart) ; @@ -1649,7 +1568,7 @@ Tree::TraceLoopLabelCell( void) clTrim.Set( ptTStart, ptTEnd) ; //clTrim.ExtendEndByLen( EPS_SMALL * 2) ; vptInters.clear() ; - if ( FindInters( nId, clTrim, vptInters, bVertex)) + if ( FindInters( nId, clTrim, vptInters, true)) return false ; bEraseNextPoint = true ; } @@ -1681,34 +1600,25 @@ Tree::TraceLoopLabelCell( void) // sono tornato alla cella di partenza, quindi devo fare il merge dei due vettori di intersezione che ho creato per questa cella // per lo stesso loop else { - // verifico se sono effettivamente nella cella di partenza o nella penultima cella - // devo verificare se il loop finisce in un vertice! in questo caso sono nella penultima cella! e devo fare un FindInters di nuovo per sistemare - Point3d ptLast = m_mTree[nId].m_vInters.back().vpt.back() ; // devo recuperare l'intersezione del trim con i bordi delle celle//////////////////// - //Point3d ptLast = ptCurr ; + // verifico se sono effettivamente nella cella di partenza o in una cella adiacente if ( nId != nFirstCell) { - Point3d ptTl( m_mTree[nId].GetBottomLeft().x, m_mTree[nId].GetTopRight().y) ; - Point3d ptBr( m_mTree[nId].GetTopRight().x, m_mTree[nId].GetBottomLeft().y) ; - int nLastId, nEdge ; - // qui devo tener conto anche della possibilità che il trim termini parzialmente coincidente con un lato/////////////////////////////////// - if ( AreSamePointApprox( m_mTree[nId].GetTopRight(), ptLast) || - AreSamePointApprox( ptTl, ptLast) || - AreSamePointApprox( m_mTree[nId].GetBottomLeft(), ptLast) || - AreSamePointApprox( ptBr, ptLast) || - OnWhichEdge( nId, ptLast,nEdge)) { - Point3d ptTStart, ptTEnd ; - plLoop.GetPrevPoint( ptTEnd) ; - plLoop.GetPrevPoint( ptTStart) ; - CurveLine clTrim ; - clTrim.Set( ptTStart, ptTEnd) ; - vptInters.clear() ; - nLastId = nId ; - FindInters( nId, clTrim, vptInters, bVertex) ; - if ( ! AreSamePointExact( vptInters[0], m_mTree[nLastId].m_vInters.back().vpt.back())) - m_mTree[nLastId].m_vInters.back().vpt.push_back( vptInters[0]) ; - } + Point3d ptFirst = m_mTree[nFirstCell].m_vInters[nPass].vpt[0] ; + Point3d ptLast = m_mTree[nId].m_vInters.back().vpt.back() ; + //sistemo l'ingresso della prima cella + int nEdge ; + OnWhichEdge( nFirstCell, ptFirst, nEdge) ; + m_mTree[nFirstCell].m_vInters[nPass].nIn = nEdge ; + // sistemo l'uscita dell'ultima cella + OnWhichEdge( nId, ptLast, nEdge) ; + m_mTree[nId].m_vInters.back().nOut = nEdge ; + // sistemo il flag dell'ultima cella + if ( m_mTree[nId].m_nFlag == -1) + m_mTree[nId].m_nFlag = 1 ; + else if ( m_mTree[nId].m_nFlag == 2) + m_mTree[nId].m_nFlag = 3 ; } // sono tornato nella cella iniziale, quindi giunto i due vettori intersezione - if ( nId == nFirstCell) { + 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(), @@ -1718,30 +1628,6 @@ Tree::TraceLoopLabelCell( void) // sistemo il lato d'uscita m_mTree[nId].m_vInters[nPass].nOut = nOut ; } - // se non sono tornato alla cella di partenza - else { - m_mTree[nId].m_vInters.pop_back() ; - if ( (int)m_mTree[nId].m_vInters.size() == 0) - m_mTree[nId].m_nFlag = 0 ; - // aggiusto nIn della cella di partenza ( in questo caso dovrei aver avuto un ingresso direttamente in un vertice) - Point3d ptFirst = m_mTree[nFirstCell].m_vInters[nPass].vpt[0] ; - Point3d ptTl( m_mTree[nFirstCell].GetBottomLeft().x, m_mTree[nFirstCell].GetTopRight().y) ; - Point3d ptBr( m_mTree[nFirstCell].GetTopRight().x, m_mTree[nFirstCell].GetBottomLeft().y) ; - if ( AreSamePointApprox( m_mTree[nFirstCell].GetTopRight(), ptFirst)) - m_mTree[nFirstCell].m_vInters[nPass].nIn = 7 ; - else if (AreSamePointApprox( ptTl, ptFirst)) - m_mTree[nFirstCell].m_vInters[nPass].nIn = 4 ; - else if (AreSamePointApprox( m_mTree[nFirstCell].GetBottomLeft(), ptFirst)) - m_mTree[nFirstCell].m_vInters[nPass].nIn = 5 ; - else if (AreSamePointApprox( ptBr, ptFirst)) - m_mTree[nFirstCell].m_vInters[nPass].nIn = 6 ; - // sono su un lato e non su un vertice - else { - int nEdge ; - OnWhichEdge( nFirstCell, ptFirst, nEdge) ; - m_mTree[nFirstCell].m_vInters[nPass].nIn = nEdge ; - } - } } } @@ -1791,7 +1677,7 @@ Tree::TraceLoopLabelCell( void) if ( ! bProceeded ) { m_mTree[nCell].SetProcessed() ; } - else { //categorizzo la cella/////////////////////////////////////////////////////////// + else { //categorizzo la cella m_mTree[nCell].m_nFlag2 = 1 ; CategorizeCell( nCell) ; } @@ -1845,7 +1731,7 @@ Tree::TraceLoopLabelCell( void) } } if ( nCell == nLastLeft && m_mTree[nCell].IsProcessed() ) { - // categorizzo//////////////////////////////////////////////////////////////////////////// + // categorizzo m_mTree[nCell].m_nFlag2 = 1 ; CategorizeCell( nCell) ; bAllDone = true ; @@ -1876,20 +1762,6 @@ Tree::TraceLoopLabelCell( void) } vNeigh.clear() ; GetRightNeigh( nCell, vNeigh) ; - - //// se sono all'ultimo elemento di vFirst controllo se ho processato tutti i suoi vicini di destra - //if ( nCell == nLastLeft){ - // vNeigh.clear() ; - // GetRightNeigh( nCell, vNeigh) ; - // bAllDone = true ; - // for( int j = 0 ; j < (int) vNeigh.size(); ++ j) { - // if ( ! m_mTree[vNeigh[j]].IsProcessed() ) { - // bAllDone = false ; - // break ; - // } - // } - //} - } return true ; @@ -1897,7 +1769,7 @@ Tree::TraceLoopLabelCell( void) //---------------------------------------------------------------------------- bool -Tree::FindInters( int& nId, CurveLine& clTrim, PNTVECTOR& vptInters, bool& bVertex) +Tree::FindInters( int& nId, CurveLine& clTrim, PNTVECTOR& vptInters, bool bFirstInters) { CurveLine clEdge , clEdge2 ; Point3d ptStart , ptEnd ; @@ -1917,12 +1789,10 @@ Tree::FindInters( int& nId, CurveLine& clTrim, PNTVECTOR& vptInters, bool& bVert nEdge = 0 ; // lato sopra clEdge.Set( ptTR, ptTl) ; - //if ( ptEnd.x >= ptBL.x) - // ;// lato sinistro - //else //if ( ptEnd.x < ptBL.x) + // lato sinistro if ( ptEnd.x < ptBL.x) clEdge2.Set( ptTl, ptBL) ; - else if ( AreSamePointExact( ptEnd, ptTl)) { + else if ( AreSamePointExact( ptEnd, ptTl) && bFirstInters) { nEdge = 4 ; ptInters = ptTl ; bIntersFound = true ; @@ -1932,13 +1802,10 @@ Tree::FindInters( int& nId, CurveLine& clTrim, PNTVECTOR& vptInters, bool& bVert nEdge = 1 ; // lato sinistro clEdge.Set( ptTl, ptBL) ; - //if ( ptEnd.y >= ptBL.y) - // ; - //// lato sotto - //else //if ( ptEnd.y < ptBL.y) + // lato sotto if ( ptEnd.y < ptBL.y) clEdge2.Set( ptBL, ptBr) ; - else if ( AreSamePointExact( ptEnd, ptBL)) { + else if ( AreSamePointExact( ptEnd, ptBL) && bFirstInters) { nEdge = 5 ; ptInters = ptBL ; bIntersFound = true ; @@ -1948,13 +1815,10 @@ Tree::FindInters( int& nId, CurveLine& clTrim, PNTVECTOR& vptInters, bool& bVert nEdge = 2 ; // lato sotto clEdge.Set( ptBL, ptBr) ; - //if ( ptEnd.x <= ptTR.x) - // ; - //// lato destro - //else //if ( ptEnd.x > ptTR.x) + // lato destro if ( ptEnd.x > ptTR.x) clEdge2.Set( ptBr, ptTR) ; - else if ( AreSamePointExact( ptEnd, ptBr)) { + else if ( AreSamePointExact( ptEnd, ptBr) && bFirstInters) { nEdge = 6 ; ptInters = ptBr ; bIntersFound = true ; @@ -1964,13 +1828,10 @@ Tree::FindInters( int& nId, CurveLine& clTrim, PNTVECTOR& vptInters, bool& bVert nEdge = 3 ; // lato desto clEdge.Set( ptBr, ptTR) ; - //if ( ptEnd.y <= ptTR.y) - // ; - //// lato sopra - //else //if ( ptEnd.y > ptTR.y) + // lato sopra if ( ptEnd.y > ptTR.y) clEdge2.Set( ptTR, ptTl) ; - else if ( AreSamePointExact( ptEnd, ptTR)) { + else if ( AreSamePointExact( ptEnd, ptTR) && bFirstInters) { nEdge = 7 ; ptInters = ptTR ; bIntersFound = true ; @@ -1979,59 +1840,47 @@ Tree::FindInters( int& nId, CurveLine& clTrim, PNTVECTOR& vptInters, bool& bVert else return false ; + if ( ! bIntersFound) { // intersezione e controlli IntersLineLine illExit( clTrim, clEdge, true) ; IntCrvCrvInfo aInfo, aInfo2 ; bool bIntersOn1Found = true ; - if ( ! illExit.GetIntCrvCrvInfo( aInfo) && ! clEdge2.IsValid()) { + if ( ! illExit.GetIntCrvCrvInfo( aInfo)) { bIntersOn1Found = false ; - return false ; + if ( ! clEdge2.IsValid()) + return false ; } - if ( clEdge2.IsValid()){ + else if ( aInfo.bOverlap && ! bFirstInters) { + ptInters = aInfo.IciA[1].ptI ; + bIntersFound = true ; + } + if ( clEdge2.IsValid() && ! bIntersFound){ IntersLineLine illExit2( clTrim, clEdge2, true) ; - //if ( ! illExit2.GetIntCrvCrvInfo( aInfo2) ) - // return false ; // verifico su quale dei due lati ho l'intersezione - if ( ! illExit2.GetIntCrvCrvInfo( aInfo2)) - if ( bIntersOn1Found) - ptInters = aInfo.IciA[0].ptI ; + if ( ! illExit2.GetIntCrvCrvInfo( aInfo2)){ + if ( bIntersOn1Found) { + // se ho intersezione su Edge1 con sovrapposizione, seleziono o il primo punto o il secondo. + if ( aInfo.bOverlap && ! bFirstInters) + ptInters = aInfo.IciA[1].ptI ; + else + ptInters = aInfo.IciA[0].ptI ; + } else return false ; + } else { - // solo intersezione sul lato 2 - if ( illExit.GetNumInters() == 0 ) { + //// solo intersezione sul lato 2 + if ( aInfo2.bOverlap && ! bFirstInters) + ptInters = aInfo2.IciA[1].ptI ; + else ptInters = aInfo2.IciA[0].ptI ; - if ( nEdge > 3 && nEdge != 7) - nEdge = nEdge - 4 ; - else if ( nEdge < 3 ) - ++ nEdge ; - else - nEdge = 0 ; - } - // intersezione sul vertice della cella - else { - ptInters = aInfo2.IciA[0].ptI ; - bVertex = true ; - // la cella adiacente in diagonale a quel vertice - nEdge = nEdge + 4 ; - } } } else ptInters = aInfo.IciA[0].ptI ; } - // devo controllare se l'intersezione è in un vertice ed eventualmente correggere nEdge - if ( nEdge < 4) { - if ( AreSamePointExact( ptInters, ptTl)) - nEdge = 4 ; - else if ( AreSamePointExact( ptInters, ptBL)) - nEdge = 5 ; - else if ( AreSamePointExact( ptInters, ptBr)) - nEdge = 6 ; - else if ( AreSamePointExact( ptInters, ptTR)) - nEdge = 7 ; - } + OnWhichEdge( nId, ptInters, nEdge) ; m_mTree[nId].m_vInters.back().nOut = nEdge ; if ( (int)vptInters.size() == 0) vptInters.push_back( ptInters) ; @@ -2366,7 +2215,7 @@ Tree::CreateCellPolygons( int nLeafId, std::vector& vPolygons, I // comincio a costruire il poligono INTVECTOR vToCheckNow = vToCheck ; - vToCheck.clear() ; + //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 @@ -2461,7 +2310,7 @@ Tree::CreateCellPolygons( int nLeafId, std::vector& vPolygons, I bool bNotCameBack = true ; bool bValidNextStart = false ; bool bAtNextStart = false ; - if ( w < nPassToCheck - 1) { // ho messo w al posto di j //////////////////////////////////////////////////////////////////////////////////////// + if ( w < nPassToCheck - 1) { int nSecondCheck = 0 ; int nNext ; // ciclo sui loop successivi per vedere se ne ho uno con un valid start @@ -2474,7 +2323,7 @@ Tree::CreateCellPolygons( int nLeafId, std::vector& vPolygons, I } else { ++ nSecondCheck ; - vToCheck.push_back( vToCheckNow[t]) ; + //vToCheck.push_back( vToCheckNow[t]) ; } } @@ -2910,10 +2759,12 @@ Tree::AreSameEdge( int nEdge1, int nEdge2) const bool Tree::AddVertex( int nId, std::vector& vEdgeVertex, PolyLine& plTrimmedPoly, int& c, Point3d& ptToAdd) const { - //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) ; - //Point3d ptBL = m_mTree.at(nId).GetBottomLeft() ; - //Point3d ptTR = m_mTree.at(nId).GetTopRight() ; + // se è il primo punto della PolyLine lo aggiungo + if ( plTrimmedPoly.GetPointNbr() == 0) { + plTrimmedPoly.AddUPoint( c, ptToAdd) ; + ++ c ; + return true ; + } Point3d ptBr = vEdgeVertex[3][0] ; Point3d ptTR = vEdgeVertex[0][0] ; Point3d ptTl = vEdgeVertex[1][0] ; @@ -3005,6 +2856,7 @@ Tree::AddVertex( int nId, std::vector& vEdgeVertex, PolyLine& plTrimm return true ; } +//usando i poligoni ////---------------------------------------------------------------------------- //bool //Tree::SetRightEdgeIn( int nId, std::vector& vEdgeVertex, PolyLine& plTrimmedPoly) @@ -3068,6 +2920,7 @@ Tree::AddVertex( int nId, std::vector& vEdgeVertex, PolyLine& plTrimm // return true ; //} +//usando le intersezioni con le celle //---------------------------------------------------------------------------- bool Tree::SetRightEdgeIn( int nId) @@ -3093,7 +2946,7 @@ Tree::SetRightEdgeIn( int nId) for( int c = 0 ; c < nInters ; ++ c){ inB = m_mTree[nId].m_vInters[c] ; if ( inB.nIn == -1) { - if ( inB != inA && inB.nChunk == inA.nChunk) { + if ( inB != inA && inB.nChunk == inA.nChunk && inB.bCCW) { bContained = true ; break ; } @@ -3124,21 +2977,16 @@ Tree::SetRightEdgeIn( int nId) } // considero anche ingressi/ uscite dai vertici 6 e 7 // controllo nei vertici - if ( m_mTree[nId].m_vInters[k].nOut == 6 && m_mTree[nId].m_vInters[k].nIn == 7) { + else if ( m_mTree[nId].m_vInters[k].nOut == 6 && m_mTree[nId].m_vInters[k].nIn == 7) { m_mTree[nId].m_nRightEdgeIn = 1 ; bDone = true ; break ; } - 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 ; } - /*if ( AreSameEdge( m_mTree[nId].m_vInters[k].nIn, 3) || AreSameEdge( m_mTree[nId].m_vInters[k].nOut, 3) ) { - m_mTree[nId].m_nRightEdgeIn = 2 ; - bDone = true ; - break ; - }*/ } // se non ho inters sul lato destro devo verificare se è tutto dentro o tutto fuori if ( ! bDone) { @@ -3434,14 +3282,22 @@ Tree::OnWhichEdge( int nId, Point3d& ptToAssign, int& nEdge) const Point3d ptTl ( ptBL.x, ptTR.y) ; Point3d ptBr ( ptTR.x, ptBL.y) ; - if ( ptToAssign.x >= ptBL.x && ptToAssign.x <= ptTR.x && abs( ptToAssign.y - ptTR.y) < EPS_SMALL) + if ( ptToAssign.x > ptBL.x && ptToAssign.x < ptTR.x && abs( ptToAssign.y - ptTR.y) < EPS_SMALL) nEdge = 0 ; - else if ( ptToAssign.y >= ptBL.y && ptToAssign.y <= ptTR.y && abs( ptToAssign.x - ptBL.x) < EPS_SMALL) + else if ( ptToAssign.y > ptBL.y && ptToAssign.y < ptTR.y && abs( ptToAssign.x - ptBL.x) < EPS_SMALL) nEdge = 1 ; - else if ( ptToAssign.x >= ptBL.x && ptToAssign.x <= ptTR.x && abs( ptToAssign.y - ptBL.y) < EPS_SMALL) + else if ( ptToAssign.x > ptBL.x && ptToAssign.x < ptTR.x && abs( ptToAssign.y - ptBL.y) < EPS_SMALL) nEdge = 2 ; - else if ( ptToAssign.y >= ptBL.y && ptToAssign.y <= ptTR.y && abs( ptToAssign.x - ptTR.x) < EPS_SMALL) + else if ( ptToAssign.y > ptBL.y && ptToAssign.y < ptTR.y && abs( ptToAssign.x - ptTR.x) < EPS_SMALL) nEdge = 3 ; + if ( AreSamePointApprox( ptToAssign, ptTR)) + nEdge = 7 ; + else if ( AreSamePointApprox( ptToAssign, ptTl)) + nEdge = 4 ; + else if ( AreSamePointApprox( ptToAssign, ptBL)) + nEdge = 5 ; + else if ( AreSamePointApprox( ptToAssign, ptBr)) + nEdge = 6 ; else return false ; return true ; diff --git a/Tree.h b/Tree.h index 62a3830..cbe70a6 100644 --- a/Tree.h +++ b/Tree.h @@ -141,7 +141,7 @@ private : 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 bool TraceLoopLabelCell( void) ; // tracing dei loop e labelling delle celle - bool FindInters( int& nId, CurveLine& clTrim, PNTVECTOR& vptInters, bool& bVertex) ; // trova le intersezioni tra una cella e una linea di trim + bool FindInters( int& nId, 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) ;