diff --git a/SurfBezier.cpp b/SurfBezier.cpp index c072092..b74b70c 100644 --- a/SurfBezier.cpp +++ b/SurfBezier.cpp @@ -1500,9 +1500,9 @@ SurfBezier::GetAuxSurf( void) const // costruttore della superficie Tree Tree( this, true) ; - //Tree.BuildTree_test() ; + Tree.BuildTree_test() ; //Tree.BuildTree( 0.05, 1) ; - Tree.BuildTree( 0.5, 10) ; + //Tree.BuildTree( 0.5, 10) ; //Tree.BuildTree( 1, 25) ; vector vvPL ; Tree.GetPolygons( vvPL) ; @@ -1547,9 +1547,9 @@ bool SurfBezier::GetLeaves( std::vector>& vLeaves) const { Tree Tree( this, true) ; - //Tree.BuildTree_test() ; + Tree.BuildTree_test() ; //Tree.BuildTree( 0.05, 1) ; - Tree.BuildTree( 0.5, 10) ; + //Tree.BuildTree( 0.5, 10) ; //Tree.BuildTree( 1, 25) ; std::vector vCells ; Tree.GetLeaves( vCells) ; diff --git a/Tree.cpp b/Tree.cpp index 23c5e5d..a357514 100644 --- a/Tree.cpp +++ b/Tree.cpp @@ -1434,7 +1434,7 @@ Tree::FindCell( const Point3d& ptToAssign, CurveLine& clTrim) const // 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 - if ( m_bSplitPatches && ( (m_nSpanU % 2 != 0 && m_nSpanU > 1) || (m_nSpanV % 2 != 0 && m_nSpanV > 1))) { + if ( m_bSplitPatches && ( m_nSpanU > 1 || m_nSpanV > 1)) { INTVECTOR nParents = FindCell( ptToAssign, clTrim, m_vnParents) ; nId = nParents.back() ; } @@ -1664,7 +1664,7 @@ Tree::TraceLoopLabelCell( void) // aggiungo la fine del segmento nel vettore delle intersezioni vptInters.push_back( ptCurr) ; } - if ( AreSamePointExact( ptCurr, ptStart)) + if ( nId == nFirstCell) vptInters.pop_back() ; m_mTree[nId].m_vInters.back().vpt = vptInters ; if ( bLoopInside) { @@ -1683,16 +1683,18 @@ Tree::TraceLoopLabelCell( void) 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() ; - Point3d ptLast = ptCurr ; + Point3d ptLast = m_mTree[nId].m_vInters.back().vpt.back() ; // devo recuperare l'intersezione del trim con i bordi delle celle//////////////////// + //Point3d ptLast = ptCurr ; 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 ; + 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)) { + AreSamePointApprox( ptBr, ptLast) || + OnWhichEdge( nId, ptLast,nEdge)) { Point3d ptTStart, ptTEnd ; plLoop.GetPrevPoint( ptTEnd) ; plLoop.GetPrevPoint( ptTStart) ; @@ -1733,6 +1735,12 @@ Tree::TraceLoopLabelCell( void) 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 ; + } } } } @@ -2619,7 +2627,7 @@ Tree::CreateIslandAndHoles( int nLeafId, std::vector& vPolygons, 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 ; } @@ -3416,3 +3424,25 @@ Tree::GetLeaves( std::vector& vLeaves) const return true ; } + +//---------------------------------------------------------------------------- +bool +Tree::OnWhichEdge( int nId, Point3d& ptToAssign, int& nEdge) const +{ + 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) ; + + 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) + nEdge = 1 ; + 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) + nEdge = 3 ; + else + return false ; + return true ; +} diff --git a/Tree.h b/Tree.h index 39e5333..62a3830 100644 --- a/Tree.h +++ b/Tree.h @@ -45,7 +45,7 @@ struct Inters { pl.GetAreaXY( dAreaB) ; } return nIn < b.nIn || - ( bEqIn && nIn == -1 && dAreaA > dAreaB) || + ( bEqIn && nIn == -1 && abs(dAreaA) > abs(dAreaB)) || ( bEqIn && nIn == 0 && vpt[0].x > b.vpt[0].x) || ( bEqIn && nIn == 1 && vpt[0].y > b.vpt[0].y) || ( bEqIn && nIn == 2 && vpt[0].x < b.vpt[0].x) || @@ -156,6 +156,7 @@ private : bool SetRightEdgeIn( int nId) ; bool CategorizeCell( int& nId) ; bool CheckIfBetween( Inters& inA, Inters& inB) const ; + bool OnWhichEdge( int nId, Point3d& ptToAssign, int& nEdge) const ; private : const SurfBezier* m_pSrfBz ; // superficie di bezier