diff --git a/Pocketing.cpp b/Pocketing.cpp index 2f7f7b4..a1532a0 100644 --- a/Pocketing.cpp +++ b/Pocketing.cpp @@ -1243,8 +1243,6 @@ Pocketing::GetCurves( SelData Id, ICURVEPLIST& lstPC, ISurfTriMesh* pStmTmp) } // ciclo sui chunk for ( int nC = nCstart ; nC < nCend ; ++ nC) { - // creo vettore delle curve - CICURVEPVECTOR vCrv ; // recupero i contorni del chunk for ( int nL = 0 ; nL < pSfr->GetLoopCount( nC) ; ++ nL) { PtrOwner pCrvLoop( ConvertCurveToComposite( pSfr->GetLoop( nC, nL))) ; @@ -1257,13 +1255,8 @@ Pocketing::GetCurves( SelData Id, ICURVEPLIST& lstPC, ISurfTriMesh* pStmTmp) // tutte le curve sono chiuse ResetCurveAllTempProp( pCrvLoop) ; // aggiungo il loop al vettore di curve - vCrv.emplace_back( Release( pCrvLoop)) ; + lstPC.emplace_back( Release( pCrvLoop)) ; } - // creo la TriMesh associata ( tutti i lati sono chiusi) - PtrOwner pStm_extr( GetSurfTriMeshByRegionExtrusion( vCrv, 3000 * vtN)) ; - if ( IsNull( pStm_extr) || ! pStm_extr->IsValid()) - return false ; - pStmTmp->Add( *pStm_extr) ; } return true ; } @@ -1501,8 +1494,8 @@ Pocketing::CreateStmForIntersection( ISurfTriMesh* pStm, ICRVCOMPOPOVECTOR& vCrv for ( int i = 0 ; i < int( vCrvCompo.size()) ; ++ i) { vCrvCompo[i]->ToLoc( frHeight) ; // porto in locale Point3d ptOnCurve ; - if ( ! vCrvCompo[0]->GetCentroid( ptOnCurve)) - if ( ! vCrvCompo[0]->GetStartPoint( ptOnCurve)) + if ( ! vCrvCompo[i]->GetCentroid( ptOnCurve)) + if ( ! vCrvCompo[i]->GetStartPoint( ptOnCurve)) return false ; CurveQuotes CrvQt ; CrvQt.nCrvInd = i ; @@ -1513,32 +1506,44 @@ Pocketing::CreateStmForIntersection( ISurfTriMesh* pStm, ICRVCOMPOPOVECTOR& vCrv // ordino le quote sort( vdCrvQuotes.begin(), vdCrvQuotes.end(), []( CurveQuotes &CrvQt0, CurveQuotes &CrvQt1) { - return CrvQt0.dQuote < CrvQt0.dQuote ; }) ; + return CrvQt0.dQuote < CrvQt1.dQuote ; }) ; // creo una FlatRegion con le curve alla stessa quota ISURFFRPOVECTOR vSfrByQuotes ; int nInd = 0 ; - while( nInd < int( vdCrvQuotes.size())) { + while ( nInd < int( vdCrvQuotes.size())) { // regione tempoeranea con la curva attuale SurfFlatRegionByContours sfrBC ; - sfrBC.AddCurve( vCrvCompo[vdCrvQuotes[nInd].nCrvInd]) ; - ++ nInd ; - for ( int j = nInd ; j < int( vdCrvQuotes.size()) ; ++ j) { - nInd = j ; - if ( abs( vdCrvQuotes[j].dQuote - vdCrvQuotes[nInd].dQuote) > EPS_SMALL) - break ; + sfrBC.AddCurve( vCrvCompo[vdCrvQuotes[nInd].nCrvInd]->Clone()) ; + for ( int j = nInd + 1 ; j < int( vdCrvQuotes.size()) ; ++ j) { // se curva successiva alla stessa quota -> aggiungo alla regione - sfrBC.AddCurve( vCrvCompo[vdCrvQuotes[j].nCrvInd]) ; + if ( abs( vdCrvQuotes[j].dQuote - vdCrvQuotes[j-1].dQuote) < EPS_SMALL) { + sfrBC.AddCurve( vCrvCompo[vdCrvQuotes[j].nCrvInd]->Clone()) ; + ++ nInd ; + } + else + break ; } + ++ nInd ; // creo la regione - PtrOwner pSfrCurr( sfrBC.GetSurf()) ; - if ( IsNull( pSfrCurr) || ! pSfrCurr->IsValid()) + PtrOwner pSfrFinal( CreateSurfFlatRegion()) ; + if ( IsNull( pSfrFinal)) return false ; - // inverto se necessario - if ( AreOppositeVectorApprox( m_vtNormal, pSfrCurr->GetNormVersor())) - pSfrCurr->Invert() ; + PtrOwner pSfrCurr( sfrBC.GetSurf()) ; + while ( ! IsNull( pSfrCurr) && pSfrCurr->IsValid()) { + // inverto se necessario + if ( AreOppositeVectorApprox( m_vtNormal, pSfrCurr->GetNormVersor())) + pSfrCurr->Invert() ; + if ( ! pSfrFinal->IsValid()) + pSfrFinal.Set( Release( pSfrCurr)) ; + else + if ( ! pSfrFinal->Add( *pSfrCurr) || ! pSfrFinal->IsValid()) + return false ; + pSfrCurr.Set( sfrBC.GetSurf()) ; + } + // aggiungo al vettore - vSfrByQuotes.emplace_back( Release( pSfrCurr)) ; + vSfrByQuotes.emplace_back( Release( pSfrFinal)) ; } // devo allargare i lati aperti della curva esterna, così la superficie si adatterà al finito mediante l'intersezione @@ -1564,14 +1569,11 @@ Pocketing::CreateStmForIntersection( ISurfTriMesh* pStm, ICRVCOMPOPOVECTOR& vCrv if ( IsNull( pStmTmp) || ! pStmTmp->IsValid()) return false ; // aggiungo questa regione a quella passata come parametro alla funzione - pStm->Add( *pStmTmp) ; + if ( ! pStm->Add( *pStmTmp)) + return false ; } } - - m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pStm->Clone()) ; - - return true ; } @@ -1607,19 +1609,30 @@ Pocketing::GetExtendedLoopToFitStmVolume( ICurveComposite* pCrvLoop) return pCrvLoop->IsClosed() && pCrvLoop->IsValid() ; } + // porto tutto nel piano XY ( per le intersezioni in futuro) + Point3d ptOrig ; pCrvLoop->GetCentroid( ptOrig) ; + Frame3d frZ ; frZ.Set( ptOrig, m_vtNormal) ; + if ( ! frZ.IsValid()) + return false ; + pCrvLoop->ToLoc( frZ) ; + for ( int i = 0 ; i < int( vCrvOpen.size()) ; ++ i) + vCrvOpen[i]->ToLoc( frZ) ; + for ( int i = 0 ; i < int( vCrvClose.size()) ; ++ i) + vCrvClose[i]->ToLoc( frZ) ; + // scorro i tratti chusi ( se presenti sono almeno due) for ( int cl = 0 ; cl < int( vCrvClose.size()) - 1 ; ++ cl) { // linea di estensione sulla parte finale Point3d ptSL1 ; vCrvClose[cl]->GetEndPoint( ptSL1) ; Vector3d vtSL1 ; vCrvClose[cl]->GetEndDir( vtSL1) ; PtrOwner pLineS( CreateCurveLine()) ; - if ( IsNull( pLineS) || pLineS->SetPVL( ptSL1, vtSL1, 30000)) + if ( IsNull( pLineS) || ! pLineS->SetPVL( ptSL1, vtSL1, 30000)) return false ; // linea di estensione sulla parte finale Point3d ptSL2 ; vCrvClose[cl+1]->GetStartPoint( ptSL2) ; Vector3d vtSL2 ; vCrvClose[cl+1]->GetStartDir( vtSL2) ; vtSL2.Invert() ; PtrOwner pLineE( CreateCurveLine()) ; - if ( IsNull( pLineE) || pLineE->SetPVL( ptSL2, vtSL2, 30000)) + if ( IsNull( pLineE) || ! pLineE->SetPVL( ptSL2, vtSL2, 30000)) return false ; // se le linee di intersecano IntersCurveCurve IntCC( *pLineE, *pLineS) ; @@ -1635,11 +1648,11 @@ Pocketing::GetExtendedLoopToFitStmVolume( ICurveComposite* pCrvLoop) pCrvLoop->GetParamAtPoint( ptSL2, dUE) ; // tratto precedente PtrOwner pCrvPrec( CloneCurveComposite( pCrvLoop)) ; - if ( IsNull( pCrvPrec) || pCrvPrec->TrimEndAtParam( dUS)) + if ( IsNull( pCrvPrec) || ! pCrvPrec->TrimEndAtParam( dUS)) return false ; // tratto successivo PtrOwner pCrvSucc( CloneCurveComposite( pCrvLoop)) ; - if ( IsNull( pCrvSucc) || pCrvSucc->TrimStartAtParam( dUE)) + if ( IsNull( pCrvSucc) || ! pCrvSucc->TrimStartAtParam( dUE)) return false ; pCrvLoop->Clear() ; if ( ! pCrvLoop->AddCurve( Release( pCrvPrec)) || @@ -1694,24 +1707,30 @@ Pocketing::GetExtendedLoopToFitStmVolume( ICurveComposite* pCrvLoop) pCrvLoop->GetParamAtPoint( ptSL2, dUE) ; // tratto precedente PtrOwner pCrvPrec( CloneCurveComposite( pCrvLoop)) ; - if ( IsNull( pCrvPrec) || pCrvPrec->TrimEndAtParam( dUS)) + if ( IsNull( pCrvPrec) || ! pCrvPrec->TrimEndAtParam( dUS)) return false ; // tratto successivo PtrOwner pCrvSucc( CloneCurveComposite( pCrvLoop)) ; - if ( IsNull( pCrvSucc) || pCrvSucc->TrimStartAtParam( dUE)) + if ( IsNull( pCrvSucc) || ! pCrvSucc->TrimStartAtParam( dUE)) return false ; pCrvLoop->Clear() ; - if ( ! pCrvLoop->AddCurve( Release( pCrvPrec)) || - ! pCrvLoop->AddLine( ptInters_S) || - ! pCrvLoop->AddCurve( Release( pCrvOffs)) || - ! pCrvLoop->AddLine( ptInters_E) || - ! pCrvLoop->AddCurve( Release( pCrvSucc))) + if ( ! pCrvLoop->AddCurve( Release( pCrvPrec))) + return false ; + if ( ! pCrvLoop->AddLine( ptInters_S)) + return false ; + if ( ! pCrvLoop->AddCurve( Release( pCrvOffs))) + return false ; + if ( ! pCrvLoop->AddLine( ptSL2)) + return false ; + if ( ! pCrvLoop->AddCurve( Release( pCrvSucc))) return false ; } else // non definito return false ; } + // riporto nel frame originario + pCrvLoop->ToGlob( frZ) ; return pCrvLoop->IsClosed() && pCrvLoop->IsValid() ; } @@ -1771,9 +1790,6 @@ Pocketing::SetPocketingVolume( const Point3d& ptInside, ISurfTriMesh* pStm) DistPointSurfTm DistPtStm( ptInside, *pStmRawPart) ; if ( DistPtStm.IsPointInside()) { pStmCurrRawPart->CopyFrom( pStmRawPart) ; - IGeoPoint3d* ptIns( CreateGeoPoint3d()) ; ptIns->Set( ptInside) ; - m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, ptIns) ; - m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pStmCurrRawPart->Clone()) ; if ( ! pStmCurrRawPart->IsValid()) return false ; bFound = true ; @@ -1784,7 +1800,7 @@ Pocketing::SetPocketingVolume( const Point3d& ptInside, ISurfTriMesh* pStm) // passo alla entità successiva nEntId = m_pGeomDB->GetNext( nEntId) ; } - nLayId =m_pGeomDB->GetNextGroup( nLayId) ; + nLayId = m_pGeomDB->GetNextGroup( nLayId) ; } nPartId = m_pMchMgr->GetNextPartInRawPart( nPartId) ; } @@ -1802,7 +1818,8 @@ Pocketing::SetPocketingVolume( const Point3d& ptInside, ISurfTriMesh* pStm) return false ; if ( ! m_pStmVolPocket->Intersect( *pStm)) // intersezione return false ; - m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, m_pStmVolPocket->Clone()) ; + int b = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, m_pStmVolPocket->Clone()) ; + m_pGeomDB->SetMaterial( b, BLUE) ; return m_pStmVolPocket->IsValid() && m_pStmVolPocket->GetTriangleCount() > 0 ; } @@ -14971,36 +14988,59 @@ Pocketing::GetHomogeneousParts( ICurveComposite* pCrvCompo, ICURVEPOVECTOR& vCrv ICRVCOMPOPOVECTOR vCrvNULL ; AdjustContourStart( pCrvCompo, vCrvNULL) ; } - ICURVEPOVECTOR vCrvClose_tmp ; - + // estraggo parti con proprietà uniforme in un vettore int nCurrTempProp ; int nParStart = 0 ; for ( int i = 0 ; i < pCrvCompo->GetCurveCount() ; ++ i) { int nTempProp ; pCrvCompo->GetCurveTempProp( i, nTempProp) ; - if ( i == 0) { + if ( i == 0) nCurrTempProp = nTempProp ; - nParStart = i ; - } - else if ( nCurrTempProp != nTempProp) { + else if ( nCurrTempProp != nTempProp || i == pCrvCompo->GetCurveCount() - 1) { + // ricavo la curva uniforme PtrOwner pCrv( pCrvCompo->CopyParamRange( nParStart, i)) ; if ( IsNull( pCrv)) return false ; + // setto la Tmp Prop come da originale pCrv->SetTempProp( nCurrTempProp) ; + // converto in composita PtrOwner pCrvSameTmpProp( CreateCurveComposite()) ; pCrvSameTmpProp->AddCurve( Release( pCrv)) ; + // ultimo pezzo di curva + if ( i == pCrvCompo->GetCurveCount() - 1) { + // ricavo ultima curva + PtrOwner pCrv_Last( pCrvCompo->GetLastCurve()->Clone()) ; + if ( IsNull( pCrv_Last)) + return false ; + // prendo tmp prop + int nLastTmpProp = pCrv_Last->GetTempProp( 0) ; + // se tmp prop come tratto precedente -> la aggiungo alla curva attuale + if ( nLastTmpProp == nCurrTempProp) + pCrvSameTmpProp->AddCurve( Release( pCrv_Last)) ; + else { + // se tmp prop differente -> inserisco la curva nel vettore corrispondente + if ( nLastTmpProp == 0) + vCrvClose.emplace_back( Release( pCrv_Last)) ; + else + vCrvOpen.emplace_back( Release( pCrv_Last)) ; + } + } + // sistemazione della curva pCrvSameTmpProp->MergeCurves( 10 * EPS_SMALL, 10 * EPS_ANG_SMALL) ; + // inserimento nel vettore di aperti e chiusi a seconda del caso if ( nCurrTempProp == 1) - vCrvOpen.emplace_back( Release( pCrvSameTmpProp)) ; // se aperta + vCrvOpen.emplace_back( Release( pCrvSameTmpProp)) ; // se aperta if ( nCurrTempProp == 0) - vCrvClose_tmp.emplace_back( Release( pCrvSameTmpProp)) ; // se chiusa + vCrvClose.emplace_back( Release( pCrvSameTmpProp)) ; // se chiusa + // aggiornamento parametri nCurrTempProp = nTempProp ; nParStart = i ; } } // unisco il primo e l'ultimo tratto chiuso, avendo cambiato l'inizio e la fine +#if 0 : if ( vCrvClose.size() > 0 && bCallAdjust) { PtrOwner pCrvCompoFirstLast( CreateCurveComposite()) ; if ( IsNull( pCrvCompoFirstLast)) @@ -15008,8 +15048,10 @@ Pocketing::GetHomogeneousParts( ICurveComposite* pCrvCompo, ICURVEPOVECTOR& vCrv pCrvCompoFirstLast->AddCurve( vCrvClose.back()->Clone()) ; pCrvCompoFirstLast->AddCurve( vCrvClose.front()->Clone()) ; vCrvClose.front().Set( Release( pCrvCompoFirstLast)) ; - vCrvClose.pop_back() ; + if ( int( vCrvClose.size() != 1)) + vCrvClose.pop_back() ; } +#endif return true ; }