diff --git a/Pocketing.cpp b/Pocketing.cpp index c3aada9..d4874f9 100644 --- a/Pocketing.cpp +++ b/Pocketing.cpp @@ -2943,7 +2943,8 @@ Pocketing::CalcZigZag( const ISurfFlatRegion* pSrfZigZag, ICRVCOMPOPOVECTOR& vpC pSeg1->GetEndPoint( ptE_Seg1) ; double dUS_Link = EPS_SMALL ; vpCrvs.back()->GetParamAtPoint( ptE_Seg1, dUS_Link) ; - vpCrvs.back()->TrimEndAtParam( dUS_Link) ; + if ( ! vpCrvs.back()->TrimEndAtParam( dUS_Link)) + vpCrvs.back()->Clear() ; //AssignFeedZigZagLink( pCrvLink) ; // assegno la Feed al Link if ( ! AssignFeedZigZagOneWay( pCrvLink, true, vLineAbove, vLineUnder, vAddedLinks)) @@ -3217,10 +3218,12 @@ Pocketing::CalcZigZagLink( ICurveComposite* pCrv1, ICurveComposite* pCrv2, ICurv if ( pCrvTest->AddCurve( pCrvH1->Clone()) && pCrvTest->AddCurve( pCrvTempLink->Clone()) && pCrvTest->AddCurve( pCrvH2->Clone())) { - pCrv1->TrimEndAtParam( dUE1) ; + if ( ! pCrv1->TrimEndAtParam( dUE1)) + pCrv1->Clear() ; pCrvLink->Clear() ; pCrvLink->AddCurve( Release( pCrvTempLink)) ; - pCrv2->TrimStartAtParam( dUS2) ; + if ( ! pCrv2->TrimStartAtParam( dUS2)) + pCrv2->Clear() ; return true ; } } @@ -3281,11 +3284,13 @@ Pocketing::CalcZigZagLink( ICurveComposite* pCrv1, ICurveComposite* pCrv2, ICurv pCrvH1->GetEndPoint( ptCrv1_e) ; pCrv1->GetParamAtPoint( ptCrv1_e, dULink_s) ; - pCrv1->TrimEndAtParam( dULink_s) ; + if ( ! pCrv1->TrimEndAtParam( dULink_s)) + pCrv1->Clear() ; pCrvH2->GetStartPoint( ptCrv2_s) ; pCrv2->GetParamAtPoint( ptCrv2_s, dULink_e) ; - pCrv2->TrimStartAtParam( dULink_e) ; + if ( ! pCrv2->TrimStartAtParam( dULink_e)) + pCrv2->Clear() ; pCrv_smoothed->GetParamAtPoint( ptCrv1_e, dULink_s) ; pCrv_smoothed->GetParamAtPoint( ptCrv2_s, dULink_e) ; @@ -3877,7 +3882,7 @@ Pocketing::AddOneWay( const ISurfFlatRegion* pSrfPock, const Vector3d& vtTool, c ICRVCOMPOPOVECTOR vCrvOEF ; bool bChanged = false ; PtrOwner pSrfToAdapt( CloneSurfFlatRegion( pSrfIdeal)) ; - if ( AdaptSfrWithRaw( pSrfToAdapt, vtTrasl, 100.0, vCrvOEF, bChanged)) { + if ( AdaptSfrWithRaw( pSrfToAdapt, vtTrasl, 100.0, vCrvOEF, bChanged, j, dStep)) { vSrfSliced[j-1].Set( pSrfToAdapt->Clone()) ; if ( ! IsNull( vSrfSliced[j-1])) { for ( int h = 0 ; h < ( int)vCrvOEF.size() ; ++h) @@ -4412,7 +4417,7 @@ Pocketing::AddSpiralIn( const ISurfFlatRegion* pSrfPock, const Vector3d& vtTool, nStep, vtTool, dElev, dDepth, dStep)) return false ; - //return false ; + return false ; Point3d ptP1 ; // per LeadIn // ciclo su tutti gli step @@ -4704,7 +4709,8 @@ Pocketing::AddSpiralIn( const ISurfFlatRegion* pSrfPock, const Vector3d& vtTool, if ( GetLeadInType() == POCKET_LI_GLIDE) { double dLen ; pRet->GetLength( dLen) ; if ( dLen > m_Params.m_dLiTang + 10 * EPS_SMALL) - pRet->TrimEndAtLen( dLen - m_Params.m_dLiTang) ; + if ( ! pRet->TrimEndAtLen( dLen - m_Params.m_dLiTang)) + pRet->Clear() ; else pRet->Clear() ; } @@ -5012,7 +5018,8 @@ Pocketing::AddSpiralOut( const ISurfFlatRegion* pSrfPock, const Vector3d& vtTool if ( GetLeadInType() == POCKET_LI_GLIDE) { double dLen ; pRet->GetLength( dLen) ; if ( dLen > m_Params.m_dLiTang + 10 * EPS_SMALL) - pRet->TrimEndAtLen( dLen - m_Params.m_dLiTang) ; + if ( ! pRet->TrimEndAtLen( dLen - m_Params.m_dLiTang)) + pRet->Clear() ; else pRet->Clear() ; } @@ -6047,9 +6054,11 @@ Pocketing::CutOffsetToClosestPoint( ICRVCOMPOPOVECTOR& vCurves, const Point3d& p double dUTan, dUS, dUE ; vCurves[nIndex]->GetParamAtPoint( ptCL, dUTan) ; pCrv1->AddCurve( vCurves[nIndex]->Clone()) ; - pCrv1->TrimEndAtParam( dUTan) ; + if ( ! pCrv1->TrimEndAtParam( dUTan)) + pCrv1->Clear() ; pCrv2->AddCurve( vCurves[nIndex]->Clone()) ; - pCrv2->TrimStartAtParam( dUTan) ; + if ( ! pCrv2->TrimStartAtParam( dUTan)) + pCrv2->Clear() ; return true ; } @@ -6098,9 +6107,11 @@ Pocketing::CutLinkToClosestPoint( ICURVEPOVECTOR& vCurves, ICRVCOMPOPOVECTOR& vO double dUS, dUE, dUTan ; vCurves[nIndex]->GetParamAtPoint( ptCL, dUTan) ; pCrv1->AddCurve( vCurves[nIndex]->Clone()) ; - pCrv1->TrimEndAtParam( dUTan) ; + if ( ! pCrv1->TrimEndAtParam( dUTan)) + pCrv1->Clear( ) ; pCrv2->AddCurve( vCurves[nIndex]->Clone()) ; - pCrv2->TrimStartAtParam( dUTan) ; + if ( ! pCrv2->TrimStartAtParam( dUTan)) + pCrv2->Clear() ; return true ; } @@ -7522,7 +7533,8 @@ Pocketing::AdjustTrapezoidSpiralForAngles( ICurveComposite* pMCrv, const ICurveC dPar = 0.5 ; pMCrv->GetPointD1D2( dPar, ICurve::FROM_MINUS, ptCrv) ; } - pMCrv->TrimStartAtParam( dPar) ; + if ( ! pMCrv->TrimStartAtParam( dPar)) + pMCrv->Clear() ; if ( ptP1.y > dPocketSize) { // se ptP1 è esterno alla svuotatura scambio i punti in modo da usare ptP2 per il biarco ( così da non farlo fuoriuscire troppo) @@ -7576,7 +7588,8 @@ Pocketing::AdjustTrapezoidSpiralForAngles( ICurveComposite* pMCrv, const ICurveC ptInt = aInfo.IciA[0].ptI ; double dPar = 0 ; pMCrv->GetParamAtPoint( ptInt, dPar) ; - pMCrv->TrimStartAtParam( dPar) ; + if ( ! pMCrv->TrimStartAtParam( dPar)) + pMCrv->Clear() ; pCompo->AddPoint( ptP2) ; pCompo->AddLine( ptInt) ; @@ -8792,7 +8805,8 @@ Pocketing::AdjustContourWithOpenEdges( ICurveComposite* pCompo, ICRVCOMPOPOVECTO } } if ( bFound) { - pJCrv->TrimEndAtParam( aInfo.IciA[0].dU) ; + if ( ! pJCrv->TrimEndAtParam( aInfo.IciA[0].dU)) + pJCrv->Clear() ; vpCrvs[i]->TrimStartAtParam( aInfo.IciB[0].dU) ; pCompo->AddCurve( ::Release( pJCrv), true, 10 * EPS_SMALL) ; } @@ -8844,8 +8858,10 @@ Pocketing::AdjustContourWithOpenEdges( ICurveComposite* pCompo, ICRVCOMPOPOVECTO IntCrvCrvInfo aInfo ; if ( intCC.GetIntCrvCrvInfo( 0, aInfo) && !bInVsOut) { double dUs, dUe ; pCompo->GetDomain( dUs, dUe) ; - pCompo->TrimEndAtParam( dUe - dUL + aInfo.IciB[0].dU) ; - pJCrv->TrimStartAtParam( aInfo.IciA[0].dU) ; + if ( ! pCompo->TrimEndAtParam( dUe - dUL + aInfo.IciB[0].dU)) + pCompo->Clear() ; + if ( ! pJCrv->TrimStartAtParam( aInfo.IciA[0].dU)) + pJCrv->Clear() ; pCompo->AddCurve( ::Release( pJCrv), true, 10 * EPS_SMALL) ; } else { @@ -8895,12 +8911,15 @@ Pocketing::AdjustPathOutsideRawForOpenEdges( const ICurveComposite* pCompo, cons double dUTrimS, dUTrimE ; PtrOwner pCompo_Prec( CloneCurveComposite( pCompo)) ; pCompo_Prec->GetParamAtPoint( ptCrvOpenS, dUTrimS) ; - pCompo_Prec->TrimEndAtParam( dUTrimS) ; + if ( ! pCompo_Prec->TrimEndAtParam( dUTrimS)) + pCompo_Prec->Clear() ; PtrOwner pCompo_Succ( CloneCurveComposite( pCompo)) ; pCompo_Succ->GetParamAtPoint( ptCrvOpenE, dUTrimE) ; - pCompo_Succ->TrimStartAtParam( dUTrimE) ; + if ( ! pCompo_Succ->TrimStartAtParam( dUTrimE)) + pCompo_Succ->Clear() ; PtrOwner pCrvOpen( CloneCurveComposite( pCompo)) ; - pCrvOpen->TrimStartEndAtParam( dUTrimS, dUTrimE) ; + if ( ! pCrvOpen->TrimStartEndAtParam( dUTrimS, dUTrimE)) + pCrvOpen->Clear() ; PtrOwner pCompo_noOpenCrv( CloneCurveComposite( pCompo_Succ)) ; pCompo_noOpenCrv->AddCurve( pCompo_Prec->Clone()) ; @@ -8924,7 +8943,8 @@ Pocketing::AdjustPathOutsideRawForOpenEdges( const ICurveComposite* pCompo, cons double dUS, dUE ; pCrvOpen_clone->GetParamAtLength( dRad, dUS) ; pCrvOpen_clone->GetParamAtLength( dLen - dRad, dUE) ; - pCrvOpen_clone->TrimStartEndAtParam( dUS, dUE) ; + if ( ! pCrvOpen_clone->TrimStartEndAtParam( dUS, dUE)) + pCrvOpen->Clear() ; bool bOk = true ; // 4) Creo regione squadrata da questa curva PtrOwner pSfrInc( GetSurfFlatRegionFromFatCurve( Release( pCrvOpen_clone), dRad, true, false)) ; @@ -8941,12 +8961,17 @@ Pocketing::AdjustPathOutsideRawForOpenEdges( const ICurveComposite* pCompo, cons pCrv_CompoHelp->AddLine( ptE) ; pSfrInc.Set( CreateSurfFlatRegion()) ; pSfrInc->AddExtLoop( Release( pCrv_CompoHelp)) ; - //m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfrInc->Clone()) ; bOk = false ; if ( IsNull( pSfrInc) || ! pSfrInc->IsValid()) return false ; } + //int p = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfrInc->Clone()) ; + //m_pGeomDB->SetMaterial( p, PURPLE) ; + //int bb = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvOpen->Clone()) ; + //m_pGeomDB->SetMaterial( bb, WHITE) ; + + // -------------- AGGIORNAMENTO DELLA REGIONE DI INFLUENZA -------------- // creo un vettore con la pCompo senza lato aperto e le isole contenute al suo interno ICRVCOMPOPOVECTOR vCrvToCheck ; @@ -8954,7 +8979,7 @@ Pocketing::AdjustPathOutsideRawForOpenEdges( const ICurveComposite* pCompo, cons for ( int i = 0 ; i < ( int)vCrvIsland.size() ; ++ i) vCrvToCheck.emplace_back( vCrvIsland[i]->Clone()) ; - // scorro il vettore creato... + // scorro il vettore creato... for ( int c = 0 ; c < ( int)vCrvToCheck.size() ; ++ c) { // 1) recupero la curva corrente PtrOwner pCrvCurr( CloneCurveComposite( vCrvToCheck[c])) ; @@ -8966,73 +8991,102 @@ Pocketing::AdjustPathOutsideRawForOpenEdges( const ICurveComposite* pCompo, cons for ( int i = 0 ; i < ( int)ccClass.size() ; ++ i) { if ( ccClass[i].nClass == CRVC_IN) { // 2) Trovo il tratto di curva interno - PtrOwner pCrvCurrPartIn( GetCurveComposite( pCrvCurr->CopyParamRange( ccClass[i].dParS, - ccClass[i].dParE))) ; - if ( IsNull( pCrvCurrPartIn) || ! pCrvCurrPartIn->IsValid()) - continue ; - pCrvCurrPartIn->SetExtrusion( vtExtr) ; - - // 3) ricavo il punto iniziale e il punto finale, assieme ai vettori tangenti - Point3d ptS1 ; pCrvCurrPartIn->GetStartPoint( ptS1) ; - Point3d ptE1 ; pCrvCurrPartIn->GetEndPoint( ptE1) ; - Vector3d vtS1 ; pCrvCurrPartIn->GetStartDir( vtS1) ; - Vector3d vtE1 ; pCrvCurrPartIn->GetEndDir( vtE1) ; - - // 4) effettuo l'Offset della curva del diametro del tool - OffsetCurve OffsCrv ; - if ( ! OffsCrv.Make( pCrvCurrPartIn, - dDiam, ICurve::OFF_FILLET)) { - m_pMchMgr->SetLastError( 2412, "Error in Pocketing : Offset not computable") ; + PtrOwner pCrvCurrPartIn_( CloneCurveComposite( pCrvCurr)) ; + if ( IsNull( pCrvCurr) || ! pCrvCurr->IsValid()) return false ; - } + if ( ! pCrvCurrPartIn_->TrimStartEndAtParam( ccClass[i].dParS, ccClass[i].dParE)) + pCrvCurrPartIn_->Clear() ; + //PtrOwner pCrvCurrPartIn( GetCurveComposite( pCrvCurr->CopyParamRange( ccClass[i].dParS, + // ccClass[i].dParE))) ; + if ( IsNull( pCrvCurrPartIn_) || ! pCrvCurrPartIn_->IsValid()) + continue ; - // 5) scorro tutte le curve di Offset che si sono formate, prendendo sempre la più lunga tra le rimanenti - PtrOwner pOffLongestCrv( OffsCrv.GetLongerCurve()) ; - while ( ! IsNull( pOffLongestCrv)) { + //int ppoo = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvCurrPartIn_->Clone()) ; + //m_pGeomDB->SetMaterial( ppoo, ORANGE) ; + + // Cerco solo i tratti di curva che sono chiusi + ICURVEPOVECTOR vCrvOpen, vCrvClose ; + if ( ! GetHomogeneousParts( pCrvCurrPartIn_, vCrvOpen, vCrvClose)) + return false ; + + if ( pCompo->GetCurveCount() == 86) + int a = 0 ; + + for ( int t_Open = 0 ; t_Open < ( int)vCrvClose.size() ; ++ t_Open) { + PtrOwner pCrvCurrPartIn( CreateCurveComposite()) ; + pCrvCurrPartIn->AddCurve( vCrvClose[t_Open]->Clone()) ; + if ( IsNull( pCrvCurrPartIn) || ! pCrvCurrPartIn->IsValid()) + continue ; + pCrvCurrPartIn->SetExtrusion( vtExtr) ; + PtrOwner pCrvCurrPartIn_Clone( CloneCurveComposite( pCrvCurrPartIn)) ; + if ( IsNull( pCrvCurrPartIn_Clone) || ! pCrvCurrPartIn_Clone->IsValid()) + continue ; + + //int pp = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvCurrPartIn->Clone()) ; + //m_pGeomDB->SetMaterial( pp, YELLOW) ; + + // 3) ricavo il punto iniziale e il punto finale, assieme ai vettori tangenti + Point3d ptS1 ; pCrvCurrPartIn->GetStartPoint( ptS1) ; + Point3d ptE1 ; pCrvCurrPartIn->GetEndPoint( ptE1) ; + Vector3d vtS1 ; pCrvCurrPartIn->GetStartDir( vtS1) ; + Vector3d vtE1 ; pCrvCurrPartIn->GetEndDir( vtE1) ; + + // 4) effettuo l'Offset della curva del diametro del tool + OffsetCurve OffsCrv ; + if ( ! OffsCrv.Make( pCrvCurrPartIn_Clone, - dDiam, ICurve::OFF_FILLET)) { + m_pMchMgr->SetLastError( 2412, "Error in Pocketing : Offset not computable") ; + return false ; + } + + // 5) scorro tutte le curve di Offset che si sono formate, prendendo sempre la più lunga tra le rimanenti + PtrOwner pOffLongestCrv( OffsCrv.GetLongerCurve()) ; + while ( ! IsNull( pOffLongestCrv)) { // 6) escludo le curve che si chiudono su se stesse dopo l'Offset - if ( ! pOffLongestCrv->IsClosed()) { - // 7) trasformo la curva in composita - PtrOwner pCompoPartInOffs( CreateCurveComposite()) ; - pCompoPartInOffs->AddCurve( pOffLongestCrv->Clone()) ; - // 8) creo due archi che collegano i punti iniziali e finali della curva originale e di quella con offset - PtrOwner pArcS( CreateCurveArc()) ; - PtrOwner pArcE( CreateCurveArc()) ; - if ( IsNull( pArcS) || IsNull( pArcE)) - return false ; - Point3d ptS2 ; pCompoPartInOffs->GetStartPoint( ptS2) ; - Point3d ptE2 ; pCompoPartInOffs->GetEndPoint( ptE2) ; - Vector3d vtS2 ; pCompoPartInOffs->GetStartDir( vtS2) ; - Vector3d vtE2 ; pCompoPartInOffs->GetEndDir( vtE2) ; - pArcS->Set2PVN( ptS1, ptS2, - vtS1, - vtExtr) ; - pArcE->Set2PVN( ptE2, ptE1, vtE2, - vtExtr) ; - // 9) creo il loop esterno della regione da aggiungere - PtrOwner pCrvExtBorder( CreateCurveComposite()) ; - if ( IsNull( pCrvExtBorder)) - return false ; - pCrvExtBorder->AddCurve( Release( pArcS)) ; // primo tratto lineare - pCrvExtBorder->AddCurve( Release( pCompoPartInOffs)) ; // tratto di offset - pCrvExtBorder->AddCurve( Release( pArcE)) ; // secondo tratto lineare - pCrvCurrPartIn->Invert() ; // inversione del tratto interno - pCrvExtBorder->AddCurve( Release( pCrvCurrPartIn)) ; // aggiunta del tratto interno - - //int rrr = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvExtBorder->Clone()) ; - //m_pGeomDB->SetMaterial( rrr, RED) ; - - if ( pCrvExtBorder->IsClosed()) { - // 9) Creo la nuova regione da aggiungere a quella di influenza - PtrOwner pSfrExpan( CreateSurfFlatRegion()) ; - if ( IsNull( pSfrExpan)) + if ( ! pOffLongestCrv->IsClosed()) { + // 7) trasformo la curva in composita + PtrOwner pCompoPartInOffs( CreateCurveComposite()) ; + pCompoPartInOffs->AddCurve( pOffLongestCrv->Clone()) ; + // 8) creo due archi che collegano i punti iniziali e finali della curva originale e di quella con offset + PtrOwner pArcS( CreateCurveArc()) ; + PtrOwner pArcE( CreateCurveArc()) ; + if ( IsNull( pArcS) || IsNull( pArcE)) return false ; - pSfrExpan->AddExtLoop( Release( pCrvExtBorder)) ; - //int green = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfrExpan->Clone()) ; // - //m_pGeomDB->SetMaterial( green, GREEN) ; // - if ( pSfrExpan->IsValid()) { - if ( AreOppositeVectorApprox( pSfrExpan->GetNormVersor(), vtExtr)) - pSfrExpan->Invert() ; - pSfrInc->Add( *pSfrExpan) ; + Point3d ptS2 ; pCompoPartInOffs->GetStartPoint( ptS2) ; + Point3d ptE2 ; pCompoPartInOffs->GetEndPoint( ptE2) ; + Vector3d vtS2 ; pCompoPartInOffs->GetStartDir( vtS2) ; + Vector3d vtE2 ; pCompoPartInOffs->GetEndDir( vtE2) ; + pArcS->Set2PVN( ptS1, ptS2, - vtS1, - vtExtr) ; + pArcE->Set2PVN( ptE2, ptE1, vtE2, - vtExtr) ; + // 9) creo il loop esterno della regione da aggiungere + PtrOwner pCrvExtBorder( CreateCurveComposite()) ; + if ( IsNull( pCrvExtBorder)) + return false ; + pCrvExtBorder->AddCurve( Release( pArcS)) ; // primo tratto lineare + pCrvExtBorder->AddCurve( Release( pCompoPartInOffs)) ; // tratto di offset + pCrvExtBorder->AddCurve( Release( pArcE)) ; // secondo tratto lineare + pCrvCurrPartIn->Invert() ; // inversione del tratto interno + pCrvExtBorder->AddCurve( pCrvCurrPartIn->Clone()) ; // aggiunta del tratto interno + + //int rrr = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvExtBorder->Clone()) ; + //m_pGeomDB->SetMaterial( rrr, RED) ; + + if ( pCrvExtBorder->IsClosed()) { + // 9) Creo la nuova regione da aggiungere a quella di influenza + PtrOwner pSfrExpan( CreateSurfFlatRegion()) ; + if ( IsNull( pSfrExpan)) + return false ; + pSfrExpan->AddExtLoop( Release( pCrvExtBorder)) ; + //int green = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfrExpan->Clone()) ; // + //m_pGeomDB->SetMaterial( green, GREEN) ; // + if ( pSfrExpan->IsValid()) { + if ( AreOppositeVectorApprox( pSfrExpan->GetNormVersor(), vtExtr)) + pSfrExpan->Invert() ; + pSfrInc->Add( *pSfrExpan) ; + } } } + pOffLongestCrv.Set( OffsCrv.GetLongerCurve()) ; } - pOffLongestCrv.Set( OffsCrv.GetLongerCurve()) ; } } } @@ -9043,10 +9097,10 @@ Pocketing::AdjustPathOutsideRawForOpenEdges( const ICurveComposite* pCompo, cons PtrOwner pSrfInc_toDraw( CloneSurfFlatRegion( pSfrInc)) ; pSrfInc_toDraw->Translate( vtTrasl) ; - if ( ! bOk) { + //if ( ! bOk) { //int brown1 = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrfInc_toDraw->Clone()) ; // //m_pGeomDB->SetMaterial( brown1, BROWN) ; - } + //} // recupero il Grezzo e sottraggo tutto ciò che sta nella regione if ( pStmRaw != nullptr) { @@ -9068,12 +9122,12 @@ Pocketing::AdjustPathOutsideRawForOpenEdges( const ICurveComposite* pCompo, cons PtrOwner pSrfInc_toDraw1( CloneSurfFlatRegion( pSfrInc)) ; pSrfInc_toDraw1->Translate( vtTrasl) ; - if ( ! bOk) { + //if ( ! bOk) { //int P = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pStmRaw->Clone()) ; // //m_pGeomDB->SetMaterial( P, LIME) ; //int brown = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrfInc_toDraw1->Clone()) ; // - //m_pGeomDB->SetMaterial( brown, YELLOW) ; - } + //m_pGeomDB->SetMaterial( brown, WHITE) ; + //} // RECUPERO DELLA CURVA DI BORDO ESTERNA DA AGGIUNGERE ALLA SVUOTATURA PtrOwner pCrvNewBorder( GetCurveComposite( pSfrInc->GetLoop( 0, 0))) ; @@ -9093,7 +9147,8 @@ Pocketing::AdjustPathOutsideRawForOpenEdges( const ICurveComposite* pCompo, cons if ( ! DistPointCurve( ptEND, *pCrvNewBorder).GetParamAtMinDistPoint( 0, dUEND, nFlag)) return false ; } - pCrvNewBorder->TrimEndAtParam( dUEND) ; + if ( ! pCrvNewBorder->TrimEndAtParam( dUEND)) + pCrvNewBorder->Clear() ; pNewCrv->Clear() ; pNewCrv->AddCurve( Release( pCrvNewBorder)) ; @@ -9354,7 +9409,7 @@ Pocketing::GetParamsAtEachStep( ISURFFRPOVECTOR& vSrfSliced, vectorClone()) ; // la superificie potrebbe non essere valida ( ad esempio se già svuotata tutta con un Tool in precedenza...) @@ -9385,7 +9440,7 @@ Pocketing::GetParamsAtEachStep( ISURFFRPOVECTOR& vSrfSliced, vectorGetChunkCount() == 0 || ! pSrf->IsValid()) return true ; - PtrOwner pSrf_toDraw( CloneSurfFlatRegion( pSrf)) ; + /*PtrOwner pSrf_toDraw( CloneSurfFlatRegion( pSrf)) ; pSrf_toDraw->Translate( vtTrasl) ; int a = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf_toDraw->Clone()) ; m_pGeomDB->SetMaterial( a, BLUE) ; @@ -9451,13 +9508,18 @@ Pocketing::AdaptSfrWithRaw( ISurfFlatRegion* pSrf, Vector3d vtTrasl, const doubl const ICurveComposite* pCrvCompo( GetCurveComposite( pSrf_toDraw->GetLoop( c, l))) ; for ( int u = 0 ; u < pCrvCompo->GetCurveCount() ; ++ u) { int nProp0 ; pCrvCompo->GetCurveTempProp( u, nProp0, 0) ; + int nProp1 ; pCrvCompo->GetCurveTempProp( u, nProp1, 1) ; int aaa = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvCompo->GetCurve( u)->Clone()) ; - m_pGeomDB->SetMaterial( aaa, nProp0 == 0 ? BLUE : RED) ; + if ( nProp1 != -99) + m_pGeomDB->SetMaterial( aaa, nProp0 == 0 ? BLUE : RED) ; + else + m_pGeomDB->SetMaterial( aaa, Color( 1.0, 0.5, 0.0)) ; } } - } + }*/ } } + //return true ; // salvo una copia della superficie attuale PtrOwner pSrf_noOpenEdge( CloneSurfFlatRegion( pSrf)) ; @@ -9468,6 +9530,10 @@ Pocketing::AdaptSfrWithRaw( ISurfFlatRegion* pSrf, Vector3d vtTrasl, const doubl if ( ! ModifySurfByOpenEdge( pSrf, vCrvOEFlags, vtTrasl, pStmRaw)) return false ; + PtrOwner pSrf_toDraw( CloneSurfFlatRegion( pSrf)) ; + pSrf_toDraw->Translate( vtTrasl) ; + //m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf_toDraw->Clone()) ; + /*for ( int c = 0 ; c < pSrf->GetChunkCount() ; ++ c) { for ( int l = 0 ; l < pSrf->GetLoopCount( c) ; ++ l) { const ICurveComposite* pCrvCompo( GetCurveComposite( pSrf->GetLoop( c, l))) ; @@ -9494,7 +9560,7 @@ Pocketing::AdaptSfrWithRaw( ISurfFlatRegion* pSrf, Vector3d vtTrasl, const doubl //---------------------------------------------------------------------------- bool Pocketing::AdjustFakeOpenEdges( ICurveComposite* pCrvCompo, const ISurfFlatRegion* pSfrOrig, const ISurfTriMesh* pStmRaw, - const Vector3d vtTrasl) + const Vector3d vtTrasl, bool bFromProj) { // controllo dei parametri if ( pCrvCompo == nullptr || ! pCrvCompo->IsValid() || pCrvCompo->GetCurveCount() == 0) @@ -9571,8 +9637,10 @@ Pocketing::AdjustFakeOpenEdges( ICurveComposite* pCrvCompo, const ISurfFlatRegio } } - //for ( int i = 0 ; i < vCrvExtProj.size() ; ++ i) - //m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vCrvExtProj[i]->Clone()) ; + if ( bFromProj) { + //for ( int i = 0 ; i < vCrvExtProj.size() ; ++ i) + //m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vCrvExtProj[i]->Clone()) ; + } //------------------------------------------------------------------------------------------------------------- // ---------------- CREAZIONE DELLA VERA A PROPRIA REGIONE DI INCIDENZA, COME SOMMA DELLE @@ -9606,8 +9674,10 @@ Pocketing::AdjustFakeOpenEdges( ICurveComposite* pCrvCompo, const ISurfFlatRegio pSrf_ind0->Invert() ; pSrf_Proj->Add( *pSrf_ind0) ; - int ooo = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf_Proj->Clone()) ; - m_pGeomDB->SetMaterial( ooo, Color( 0.0, 1.0, 0.0, 0.3)) ; + if ( bFromProj) { + //int ooo = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf_Proj->Clone()) ; + //m_pGeomDB->SetMaterial( ooo, Color( 0.0, 1.0, 0.0, 0.3)) ; + } // =============================================================================================================== // Clono la superificie originaria, portandola allo step corrente @@ -9616,21 +9686,27 @@ Pocketing::AdjustFakeOpenEdges( ICurveComposite* pCrvCompo, const ISurfFlatRegio return false ; pSrfOrig_clone->Translate( vtTrasl) ; - int oooo = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrfOrig_clone->Clone()) ; - m_pGeomDB->SetMaterial( oooo, Color( 0.0, 0.0, 0.0, 0.3)) ; + if ( bFromProj) { + //int oooo = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrfOrig_clone->Clone()) ; + //m_pGeomDB->SetMaterial( oooo, Color( 0.0, 0.0, 0.0, 0.3)) ; + } // ho cambiato un lato aperto in chiuso ? bool bLoopL_isChanged = false ; - + const int MAX_TRY = 10 ; + int nCont = -1 ; // calcolo la regione critica PtrOwner pSrf_critica( CloneSurfFlatRegion( pSrf_Proj)) ; pSrf_critica->Subtract( *pSrfOrig_clone) ; - int ooooy = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf_critica->Clone()) ; - m_pGeomDB->SetMaterial( ooooy, ORANGE) ; + if ( bFromProj) { + //int ooooy = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf_critica->Clone()) ; + //m_pGeomDB->SetMaterial( ooooy, ORANGE) ; + } do { + ++nCont ; bLoopL_isChanged = false ; // creo i tratti di curva omogonei ( tratti uniformi chiusi o aperti) ICURVEPOVECTOR vCrvOpen ; ICURVEPOVECTOR vCrvClose ; @@ -9672,8 +9748,10 @@ Pocketing::AdjustFakeOpenEdges( ICurveComposite* pCrvCompo, const ISurfFlatRegio PtrOwner pCrv_tOpen_Offs( CloneCurveComposite( pCrvlonger)) ; if ( IsNull( pCrv_tOpen_Offs) || ! pCrv_tOpen_Offs->IsValid()) return false ; - int YE = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrv_tOpen_Offs->Clone()) ; - m_pGeomDB->SetMaterial( YE, YELLOW) ; + if ( bFromProj) { + //int YE = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrv_tOpen_Offs->Clone()) ; + //m_pGeomDB->SetMaterial( YE, YELLOW) ; + } CRVCVECTOR ccClass ; if ( pSrf_critica->GetCurveClassification( *pCrv_tOpen_Offs, 10 * EPS_SMALL, ccClass)) { for ( int j = 0 ; j < ( int)ccClass.size() && ! bLoopL_isChanged ; ++ j) { @@ -9701,9 +9779,11 @@ Pocketing::AdjustFakeOpenEdges( ICurveComposite* pCrvCompo, const ISurfFlatRegio double dUStart ; // parametro relativo iniziale double dUEnd ; // parametro relativo finale - PtrOwner CIAO( pCrv_tOpen_Offs->CopyParamRange( ccClass[j].dParS, ccClass[j].dParE)) ; - int YEs = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, CIAO->Clone()) ; - m_pGeomDB->SetMaterial( YEs, Color( 0.95, 0.0, 0.63, 1.0)) ; + PtrOwner CIAO( pCrv_tOpen_Offs->CopyParamRange( ccClass[j].dParS, ccClass[j].dParE)) ; + if ( bFromProj) { + //int YEs = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, CIAO->Clone()) ; + //m_pGeomDB->SetMaterial( YEs, Color( 0.95, 0.0, 0.63, 1.0)) ; + } // ------------------------------ PARAMETRO FINALE ----------------------------------- // se non sono su un raccordo ... @@ -9784,8 +9864,10 @@ Pocketing::AdjustFakeOpenEdges( ICurveComposite* pCrvCompo, const ISurfFlatRegio // ricomposizione con tagli per non perdere le proprietà appena impostate dUStart += dU_jump ; dUEnd += dU_jump ; - pCrv_Bef->TrimEndAtParam( dUStart) ; - pCrv_Aft->TrimStartAtParam( dUEnd) ; + if ( ! pCrv_Bef->TrimEndAtParam( dUStart)) + pCrv_Bef->Clear() ; + if ( ! pCrv_Aft->TrimStartAtParam( dUEnd)) + pCrv_Aft->Clear() ; if ( ! IsNull( pCrv_Bef) && pCrv_Bef->IsValid()) pCrv_New->AddCurve( Release( pCrv_Bef)) ; pCrv_curr_Close->AddCurve( pCrvCompo_Clone_Trasl->CopyParamRange( dUStart, dUEnd)) ; @@ -9794,8 +9876,8 @@ Pocketing::AdjustFakeOpenEdges( ICurveComposite* pCrvCompo, const ISurfFlatRegio pCrv_curr_Close->SetCurveTempProp( uu, -99, 1) ; // chiusa } if ( ! IsNull( pCrv_curr_Close) && pCrv_curr_Close->IsValid()) { - int YEss = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrv_curr_Close->Clone()) ; - m_pGeomDB->SetMaterial( YEss, GREEN) ; + //int YEss = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrv_curr_Close->Clone()) ; + //m_pGeomDB->SetMaterial( YEss, GREEN) ; pCrv_New->AddCurve( Release( pCrv_curr_Close)) ; } else @@ -9815,7 +9897,7 @@ Pocketing::AdjustFakeOpenEdges( ICurveComposite* pCrvCompo, const ISurfFlatRegio pCrvlonger.Set( OffsCrv.GetLongerCurve()) ; } } - } while ( bLoopL_isChanged) ; + } while ( bLoopL_isChanged && nCont < MAX_TRY) ; // sotituisco la curva originale, traslo e miglioro... if ( pCrvCompo_Clone_Trasl != nullptr && pCrvCompo_Clone_Trasl->IsValid() && pCrvCompo_Clone_Trasl->IsClosed()) { @@ -9846,6 +9928,9 @@ Pocketing::ModifySurfByOpenEdge( ISurfFlatRegion* pSrf, ICRVCOMPOPOVECTOR& vCrvO if ( IsNull( pSrfFinal)) return false ; + // salvo un vettore contenente tutte le isole + ICRVCOMPOPOVECTOR vCrvToTIsl ; + // per ogni Chunck della superificie ottenuta... for ( int c = 0 ; c < pSrf->GetChunkCount() ; ++ c) { @@ -9940,6 +10025,7 @@ Pocketing::ModifySurfByOpenEdge( ISurfFlatRegion* pSrf, ICRVCOMPOPOVECTOR& vCrvO } } vCrvModIsland.emplace_back( pCrvIsl->Clone()) ; + vCrvToTIsl.emplace_back( pCrvIsl->Clone()) ; } // 6) Creo la nuova superificie da svuotare @@ -9957,6 +10043,46 @@ Pocketing::ModifySurfByOpenEdge( ISurfFlatRegion* pSrf, ICRVCOMPOPOVECTOR& vCrvO pSrfFinal->Add( *pSrfHelp_) ; } + //int bb = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrfFinal->Clone()) ; + //m_pGeomDB->SetMaterial( bb, BLACK) ; + //for ( int is = 0 ; is < ( int)vCrvToTIsl.size() ; ++ is) { + // int bb = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vCrvToTIsl[is]->Clone()) ; + // m_pGeomDB->SetMaterial( bb, WHITE) ; + //} + + // ora che ho la superificie finale, questa potrebbe contenere più isole rispetto a quelle originarie + // devo togliere le isole che non fanno overlap con nessun isola originaria + SurfFlatRegionByContours pSrf_noFakeIslands ; + for ( int c = 0 ; c < pSrfFinal->GetChunkCount() ; ++ c) { + // aggiungo il bordo esterno + pSrf_noFakeIslands.AddCurve( pSrfFinal->GetLoop( c, 0)) ; + for ( int l = 1 ; l < pSrfFinal->GetLoopCount( c) ; ++ l) { + PtrOwner pCrv( pSrfFinal->GetLoop( c, l )) ; + PtrOwner pCrvCompo( CreateCurveComposite()) ; + if ( IsNull( pCrvCompo)) + return false ; + bool bIsRealIsland = false ; + pCrvCompo->AddCurve( pCrv->Clone()) ; + for ( int is = 0 ; is < ( int)vCrvToTIsl.size() && !bIsRealIsland ; ++ is) { + for ( int u = 0 ; u < pCrvCompo->GetCurveCount() && !bIsRealIsland ; ++ u) { + const ICurve* pCrv_u = pCrvCompo->GetCurve( u) ; + if ( pCrv_u == nullptr) + return false ; + int nStat = -1 ; + if ( CheckSimpleOverlap( pCrv_u, vCrvToTIsl[is], nStat, 50 * EPS_SMALL) && nStat == 1) + bIsRealIsland = true ; + } + } + if ( bIsRealIsland) + pSrf_noFakeIslands.AddCurve( Release( pCrv)) ; + } + } + + // aggiorno la superficie originaria + pSrfFinal.Set( pSrf_noFakeIslands.GetSurf()) ; + if ( IsNull( pSrfFinal)) + return false ; + pSrf->Clear() ; pSrf->CopyFrom( pSrfFinal) ; return pSrf->IsValid() && pSrf->GetChunkCount() > 0 ; @@ -10120,7 +10246,7 @@ Pocketing::IntersSurfWithRaw( ISurfFlatRegion* pSfrPock, const ISurfTriMesh* pSt // ricalcolo i lati aperti ( se richisto) if ( bComputeOpenEdge) { PtrOwner pStmRaw_clone( CloneSurfTriMesh( pStmRaw)) ; - if ( IsNull( pStmRaw_clone) || ! SetOpenOrCloseEdge( pSrfByCurves, pSfrPock, false, pStmRaw_clone, vtTrasl)) + if ( IsNull( pStmRaw_clone) || ! SetOpenOrCloseEdge( pSrfByCurves, pSfrPock, pSfrPock, false, pStmRaw_clone, vtTrasl)) return false ; } @@ -10133,27 +10259,29 @@ Pocketing::IntersSurfWithRaw( ISurfFlatRegion* pSfrPock, const ISurfTriMesh* pSt //---------------------------------------------------------------------------- bool -Pocketing::SetOpenOrCloseEdge( ISurfFlatRegion* pSrfTP, const ISurfFlatRegion* pSrfOrig, bool bFromProj, - ISurfTriMesh* pStmRaw, Vector3d vtTrasl) +Pocketing::SetOpenOrCloseEdge( ISurfFlatRegion* pSrfTP, const ISurfFlatRegion* pSrfForCrvs, const ISurfFlatRegion* pSrfOrig, + bool bFromProj, ISurfTriMesh* pStmRaw, Vector3d vtTrasl, bool bCheckfakeOpenEdge) { // controllo parametri - if ( pSrfTP == nullptr || pSrfTP->GetChunkCount() == 0 || pSrfOrig == nullptr || pSrfOrig->GetChunkCount() == 0) + if ( pSrfTP == nullptr || pSrfTP->GetChunkCount() == 0 || + pSrfForCrvs == nullptr || pSrfForCrvs->GetChunkCount() == 0 || + pSrfOrig == nullptr || pSrfOrig->GetChunkCount() == 0) return false ; // recupero le proprietà - PtrOwner pCrvEL( pSrfOrig->GetLoop( 0, 0)) ; + PtrOwner pCrvEL( pSrfForCrvs->GetLoop( 0, 0)) ; int nProp0 = pCrvEL->GetTempProp( 0) ; int nProp1 = pCrvEL->GetTempProp( 1) ; // creo un vettore contenente tutti i loop esterni ed Interni della superificie originaria - int nExtLoop = pSrfOrig->GetChunkCount() ; + int nExtLoop = pSrfForCrvs->GetChunkCount() ; ICRVCOMPOPOVECTOR vCrvAll ; - for ( int c = 0 ; c < ( int)pSrfOrig->GetChunkCount() ; ++ c) - vCrvAll.emplace_back( GetCurveComposite( pSrfOrig->GetLoop( c, 0))) ; - for ( int c = 0 ; c < ( int)pSrfOrig->GetChunkCount() ; ++ c) - for ( int l = 1 ; l < ( int)pSrfOrig->GetLoopCount( c) ; ++ l) - vCrvAll.emplace_back( GetCurveComposite( pSrfOrig->GetLoop( c, l))) ; + for ( int c = 0 ; c < ( int)pSrfForCrvs->GetChunkCount() ; ++ c) + vCrvAll.emplace_back( GetCurveComposite( pSrfForCrvs->GetLoop( c, 0))) ; + for ( int c = 0 ; c < ( int)pSrfForCrvs->GetChunkCount() ; ++ c) + for ( int l = 1 ; l < ( int)pSrfForCrvs->GetLoopCount( c) ; ++ l) + vCrvAll.emplace_back( GetCurveComposite( pSrfForCrvs->GetLoop( c, l))) ; // superificie da ritornare ( aggiornata) SurfFlatRegionByContours pSrfMod ; @@ -10232,8 +10360,8 @@ Pocketing::SetOpenOrCloseEdge( ISurfFlatRegion* pSrfTP, const ISurfFlatRegion* p pCrv->SetTempProp( nProp1, 1) ; // controllo se i lati aperti impostati sono effettivamente aperti ( se non sono nella proieizone) - if ( ! bFromProj) - if ( ! AdjustFakeOpenEdges( pCrv, pSrfOrig, pStmRaw, vtTrasl)) + if ( bCheckfakeOpenEdge) + if ( ! AdjustFakeOpenEdges( pCrv, pSrfOrig, pStmRaw, vtTrasl, bFromProj)) return false ; // aggiungo la curva alla nuova superificie @@ -10708,7 +10836,7 @@ Pocketing::GetSurfByAdj( const ISurfTriMesh* pSrfOri, INTVECTOR& vBannedId, int //---------------------------------------------------------------------------- bool Pocketing::GetProjStmOnSfr( const ISurfFlatRegion* pSfr, const ISurfTriMesh* pStmRaw, const ISurfFlatRegion* pSrfOrig, - ISurfFlatRegion* pSfrRawBoxProj) + const int nStep, double dStep, const Vector3d& vtTrasl, ISurfFlatRegion* pSfrRawBoxProj) { // controllo dei parametri if ( pSfr == nullptr || ! pSfr->IsValid() || pSfr->GetChunkCount() == 0 || @@ -10763,12 +10891,18 @@ Pocketing::GetProjStmOnSfr( const ISurfFlatRegion* pSfr, const ISurfTriMesh* pSt PtrOwner pSfrPock( CloneSurfFlatRegion( pSfr)) ; if( IsNull( pSfrPock)) return false ; - // ------------------------- CREAZIONE DEL PIANO DI TAGLIO -------------------------------------- + + // costante di estrusione per creazione delle regioni + const double STEP_HEIGHT = 500. ; + + // ------------------------- CREAZIONE DEI PIANI DI TAGLIO NEAR, FAR E DI PROIEZIONE -------------------------------------- // recupero il piano di proiezione ( piano che contiene la flatRegion) PtrOwner pCrv( GetCurveComposite( pSfrPock->GetLoop( 0, 0))) ; if ( IsNull( pCrv)) return false ; - Plane3d plProj ; + //int nn5 = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfrPock->Clone()) ; + //m_pGeomDB->SetMaterial( nn5, BLACK) ; + Plane3d plNear, plFar, plProj ; Point3d ptCen ; if ( ! pCrv->GetCentroid( ptCen)) // punto if ( ! pCrv->GetStartPoint( ptCen)) @@ -10776,12 +10910,27 @@ Pocketing::GetProjStmOnSfr( const ISurfFlatRegion* pSfr, const ISurfTriMesh* pSt Vector3d vtNorm = pSfrPock->GetNormVersor() ; // normale if ( vtNorm.IsSmall()) return false ; - plProj.Set( ptCen, -vtNorm) ; // così taglio tutto cià che sta nel semipiano negativo - if ( ! plProj.IsValid()) + plNear.Set( ptCen - 2 * EPS_SMALL * vtNorm, -vtNorm ) ; // taglio tutto ciò che sta nel semipiano negativo + Vector3d vtTraslPlane = ( nStep == 1 ? STEP_HEIGHT : dStep) * vtNorm ; + plFar.Set( ptCen + vtTraslPlane, vtNorm) ; // taglio tutto ciò che sta nel semepiano positivo + plProj.Set( ptCen, -vtNorm) ; + if ( ! plNear.IsValid() || ! plFar.IsValid() || ! plProj.IsValid()) return false ; + PtrOwner PSrfPlaneNear( GetSurfFlatRegionRectangle( 5000, 5000)) ; + PSrfPlaneNear->Translate( Vector3d( -2500, -2500, 0)) ; + Frame3d frNear ; frNear.Set( ptCen - 2 * EPS_SMALL * vtNorm, plNear.GetVersN()) ; + PSrfPlaneNear->ToGlob( frNear) ; + PtrOwner PSrfPlaneFar( GetSurfFlatRegionRectangle( 5000, 5000)) ; + PSrfPlaneFar->Translate( Vector3d( -2500, -2500, 0)) ; + Frame3d frFar ; frFar.Set( ptCen + vtTraslPlane, plFar.GetVersN()) ; + PSrfPlaneFar->ToGlob( frFar) ; + //int nn = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, PSrfPlaneNear->Clone()) ; + //m_pGeomDB->SetMaterial( nn, Color( 128., 128., 128., 0.15)) ; + //int gg = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, PSrfPlaneFar->Clone()) ; + //m_pGeomDB->SetMaterial( gg, Color( 128., 128., 128., 0.15)) ; // ---------------------- RICERCA DELLA REGIONE DI INCIDENZA DI PROIEZIONE -------------------------- - // offsetto la regione della quantità richiesta + // offsetto la regione della quantità richiesta ( raggio di ricerca per eventuali proeizioni) PtrOwner pSrf_Pock_Clone(CloneSurfFlatRegion( pSfrPock)) ; if ( ! pSrf_Pock_Clone->Offset( m_dMaxLenRawProj, ICurve::OFF_CHAMFER)) return false ; @@ -10789,14 +10938,55 @@ Pocketing::GetProjStmOnSfr( const ISurfFlatRegion* pSfr, const ISurfTriMesh* pSt for ( int c = 0 ; c < pSrf_Pock_Clone->GetChunkCount() ; ++ c) for ( int l = 0 ; l < pSrf_Pock_Clone->GetLoopCount( c) ; ++ l) vCrv.emplace_back( pSrf_Pock_Clone->GetLoop( c, l)) ; - PtrOwner pSrf_ForCuttingRaw( GetSurfTriMeshByRegionExtrusion( vCrv, vtNorm * 1000)) ; + PtrOwner pSrf_ForCuttingRaw( GetSurfTriMeshByRegionExtrusion( vCrv, vtNorm * STEP_HEIGHT)) ; // --------------------- CREAZIONE PARTE DI GREZZO AL DI SOPRA DELLA REGIONE SI SVUOTATURA - // -----------------------------------NELLA REGIONE DI INCIDENZA ----------------------------- - // creo la Trimesh del grezzo e la taglio con il piano + // ----------------------------------- NELLA REGIONE DI INCIDENZA ----------------------------- + // clono la Trimesh del Grezzo PtrOwner pSrfRaw_clone( CloneSurfTriMesh( pStmRaw)) ; if ( IsNull( pSrfRaw_clone)) return false ; + // taglio la Trimesh con il piano near e il piano far + pSrfRaw_clone->Cut( plNear, true) ; + if ( pSrfRaw_clone->IsValid()) + pSrfRaw_clone->Cut( plFar, true) ; + // se step > 1 -> chiudo la superificie dalla parte del piano di far + if ( nStep > 1 && ! IsNull( pSrfRaw_clone) && pSrfRaw_clone->IsValid()) { + POLYLINEVECTOR vPL ; + pSrfRaw_clone->GetLoops( vPL) ; + //m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrfRaw_clone->Clone()) ; + for ( int p = 0 ; p < ( int)vPL.size() ; ++ p) { + // controllo se questa curva è contenuta nel piano dove svuoto, nel caso quindi la salto + Plane3d plCheck ; double dArea ; Point3d ptCheck ; + if ( vPL[p].IsClosedAndFlat( plCheck, dArea)) { + if ( vPL[p].GetPointNbr() > 0 ) { + if ( vPL[p].GetFirstPoint( ptCheck)) { + double dDist = DistPointPlane( ptCheck, plNear) ; + if ( abs ( dDist) < 50 * EPS_SMALL) + continue ; + } + } + } + PtrOwner pStm_SideAtFar( CreateSurfTriMesh()) ; + if ( pStm_SideAtFar->CreateByFlatContour( vPL[p])) { + Vector3d vtN ; + if ( pStm_SideAtFar->GetFacetNormal( 0, vtN) && AreOppositeVectorApprox( vtN, plNear.GetVersN())) + pStm_SideAtFar->Invert() ; + //m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pStm_SideAtFar->Clone()) ; + } + pSrfRaw_clone->DoSewing( *Release( pStm_SideAtFar)) ; + } + } + + //int RawIdPart = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrfRaw_clone->Clone()) ; + //m_pGeomDB->SetMaterial( RawIdPart, Color( 0./nStep, 255./( 1. * nStep), 255./( 1.* nStep), 0.65)) ; + //if ( nStep == 2) + // return false ; + + // controllo validità + if ( ! pSrfRaw_clone->IsValid() || pSrfRaw_clone->GetTriangleCount() == 0) + pSrfRaw_clone.Set( CloneSurfTriMesh( pStmRaw)) ; + // considero la parte di grezzo interna alla regione di incidenza if ( ! pSrfRaw_clone->CutWithOtherSurf( *pSrf_ForCuttingRaw, true, true)) return false ; if ( ! pSrfRaw_clone->IsValid() || pSrfRaw_clone->GetTriangleCount() == 0) { @@ -10860,7 +11050,9 @@ Pocketing::GetProjStmOnSfr( const ISurfFlatRegion* pSfr, const ISurfTriMesh* pSt // controllo validità della curva ( che sia chiusa e non degenere) double dArea = EPS_SMALL ; Plane3d plCheck ; - if ( ! pCrvProjFacef->IsClosed() || ! pCrvProjFacef->GetArea( plCheck, dArea) || dArea <= EPS_SMALL) + if ( ! pCrvProjFacef->IsClosed() || + ! pCrvProjFacef->GetArea( plCheck, dArea) || + dArea <= 5 * EPS_SMALL) continue ; // creo la curva composita associata PtrOwner pCrvBorderProj_f( CreateCurveComposite()) ; @@ -10920,10 +11112,10 @@ Pocketing::GetProjStmOnSfr( const ISurfFlatRegion* pSfr, const ISurfTriMesh* pSt if ( IsNull( pSrf_Proj_Ext)) return false ; - //for ( int p = 1 ; p < ( int)vCrvExtProj.size() ; ++ p) { + for ( int p = 1 ; p < ( int)vCrvExtProj.size() ; ++ p) { //int g = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vCrvExtProj[p]->Clone()) ; //m_pGeomDB->SetMaterial( g, BLACK) ; - //} + } // ---------------- CREAZIONE DELLA VERA A PROPRIA REGIONE DI INCIDENZA, COME SOMMA DELLE // ----------------------------- SINGOLE FLATREGIONS DI PROIEZIONE ----------------------------- @@ -10943,20 +11135,47 @@ Pocketing::GetProjStmOnSfr( const ISurfFlatRegion* pSfr, const ISurfTriMesh* pSt if ( AreOppositeVectorApprox( pSrf_H->GetNormVersor() , pSrf_Clone->GetNormVersor())) pSrf_H->Invert() ; } - if ( pSrf_Proj_Ext->GetChunkCount() == 0) + if ( pSrf_Proj_Ext->GetChunkCount() == 0) { pSrf_Proj_Ext.Set( Release( pSrf_H)) ; - else - pSrf_Proj_Ext->Add( *Release( pSrf_H)) ; + } + else { + PtrOwner pSrf_Check( CloneSurfFlatRegion( pSrf_Proj_Ext)) ; + if ( IsNull( pSrf_Check)) + return false ; + if ( ! pSrf_Proj_Ext->Add( *Release( pSrf_H)) || ! pSrf_Proj_Ext->IsValid()) + pSrf_Proj_Ext.Set( Release( pSrf_Proj_Ext)) ; + } } } } + if ( IsNull( pSrf_Proj_Ext) || ! pSrf_Proj_Ext->IsValid()) + return true ; + // creo la vera e propria regione di proiezione, sommando la proiezione esterna con la superifcie originale da svuotare PtrOwner pSrf_Proj( CloneSurfFlatRegion( pSrf_Proj_Ext)) ; if ( IsNull( pSrf_Proj) || ! pSrf_Proj->IsValid()) return false ; pSrf_Proj->Add( *pSfr) ; + pSrf_Proj->Add( *pSfr) ; - + // controllo i loop della superificie creata ------------------------ + SurfFlatRegionByContours SrfByC ; + for ( int c = 0 ; c < pSrf_Proj->GetChunkCount() ; ++ c) { + for ( int l = 0 ; l < pSrf_Proj->GetLoopCount( c) ; ++ l) { + PtrOwner pCrvTmp( pSrf_Proj->GetLoop( c, l)) ; + if ( IsNull( pCrvTmp) || ! pCrvTmp->IsValid() || ! pCrvTmp->IsClosed()) + continue ; + double dArea = 0. ; + Plane3d plCheck = plProj ; + if ( pCrvTmp->GetArea( plCheck, dArea) && dArea < 500 * EPS_SMALL) + continue ; + SrfByC.AddCurve( Release( pCrvTmp)) ; + } + } + PtrOwner pSrf_Check( SrfByC.GetSurf()) ; + if ( ! IsNull( pSrf_Check) && pSrf_Check->IsValid()) + pSrf_Proj.Set( Release( pSrf_Check)) ; + // ------------------------------------------------------------------ // --------- LA PROIEZIONE DEL GREZZO DEVE ESTENDERE LA MIA SUPERIFCIE ORIGINARIA ( DERIVANTE DALL'INTERSEZIONE) PRESSO // I LATI APERTI DI ESSA. USO LA FUNZIONE AdjustContourWithOpenEdges FORZADO COME COLLEGAMENTI DELLE RETTE CHIUSE ------ @@ -11004,6 +11223,8 @@ Pocketing::GetProjStmOnSfr( const ISurfFlatRegion* pSfr, const ISurfTriMesh* pSt PtrOwner pSrfProj_Clone_Clone( CloneSurfFlatRegion( pSfrProj_Clone)) ; if ( ! CutProjectionToFitShape( pSfrProj_Clone, pSrfOrig)) return false ; + //int ghh = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSfrProj_Clone->Clone()) ; + //m_pGeomDB->SetMaterial( ghh, ORANGE) ; // Recupero le TmpProp e creo la nuova superificie mediante questo loop esterno PtrOwner pCrv_NewExt( pSfrProj_Clone->GetLoop( 0, 0)) ; if ( IsNull( pCrv_NewExt) || ! pCrv_NewExt->IsValid()) @@ -11014,6 +11235,13 @@ Pocketing::GetProjStmOnSfr( const ISurfFlatRegion* pSfr, const ISurfTriMesh* pSt pCrvCompo_NewExt->AddCurve( Release( pCrv_NewExt)) ; // Imposto le temp prop if ( pCrvCompo_NewExt->IsValid()) { + /*if( nStep == 2) { + m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pCrvCompo_NewExt->Clone()) ; + for ( int ii = 0 ; ii < vCrvExtProj.size() ; ++ii) { + int jjj = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vCrvExtProj[ii]->Clone()) ; + m_pGeomDB->SetMaterial( jjj, RED) ; + } + }*/ if ( ! SetTmpPropWithRawProjectedFaces( pCrvCompo_NewExt, vCrvExtProj, pSfr->GetNormVersor()) || ! CheckSmallPartsForOpenEdge( pCrvCompo)) return false ; @@ -11049,62 +11277,32 @@ Pocketing::CutProjectionToFitShape( ISurfFlatRegion* pSrfProjected, const ISurfF pSrfOrig == nullptr || ! pSrfOrig->IsValid() || pSrfOrig->GetChunkCount() == 0) return false ; - ICRVCOMPOPOVECTOR vCrvNULL ; - ICRVCOMPOPOVECTOR vCrvClose ; - for ( int c = 0 ; c < pSrfOrig->GetChunkCount() ; ++ c) { // per ogni Chunk c - for ( int l = 0 ; l < pSrfOrig->GetLoopCount( c) ; ++ l) { // per ogni Loop l + // ricavo i tratti tutti i possibili aperti della superificie + ICURVEPOVECTOR vCrvAllClose ; + for ( int c = 0 ; c < pSrfOrig->GetChunkCount() ; ++ c) { // per ogni Chunk c + for ( int l = 0 ; l < pSrfOrig->GetLoopCount( c) ; ++ l) { // per ogni Loop l // estraggo la curva di bordo PtrOwner pCrvCompo( GetCurveComposite( pSrfOrig->GetLoop( c, l ))) ; if ( IsNull( pCrvCompo) || ! pCrvCompo->IsValid() || pCrvCompo->GetCurveCount() == 0) return false ; - // controllo se la curva ha tutti i lati aperti - bool bIsAllOpen = true ; - int nCurrTempProp_ ; - for ( int u = 0 ; u < pCrvCompo->GetCurveCount() && bIsAllOpen ; ++ u) { - pCrvCompo->GetCurveTempProp( u, nCurrTempProp_, 0) ; - bIsAllOpen = nCurrTempProp_ == 1 ; - } - if ( bIsAllOpen) - // se tutti lati aperti... + ICURVEPOVECTOR vCrvOpen, vCrvClose ; + if ( ! GetHomogeneousParts( pCrvCompo, vCrvOpen, vCrvClose, true)) + return false ; + // se nessun lato aperto, esco + if (( int)vCrvClose.size() == 0) continue ; - else { - AdjustContourStart( pCrvCompo, vCrvNULL) ; - for ( int u = 1 ; u < pCrvCompo->GetCurveCount() ; ++ u) { - int nTmpProp0 ; pCrvCompo->GetCurveTempProp( u, nTmpProp0, 0) ; - if ( nTmpProp0 == 1) { - pCrvCompo->ChangeStartPoint( u + 1) ; - break ; - } - } - PtrOwner pCrvClosed( CreateCurveComposite()) ; - if ( IsNull( pCrvClosed)) - return false ; - int nCrv = 0 ; - for ( int u = 0 ; u < pCrvCompo->GetCurveCount() ; ++ u) { - int nCurrTmpProp ; pCrvCompo->GetCurveTempProp( u, nCurrTmpProp, 0) ; - if ( nCurrTmpProp == 0) { // se chiusa - if ( nCrv == 0) - pCrvClosed->Clear() ; - pCrvClosed->AddCurve( pCrvCompo->GetCurve( u)->Clone()) ; - ++ nCrv ; - } - else { // se aperta - if ( nCrv != 0) - vCrvClose.emplace_back( pCrvClosed->Clone()) ; - nCrv = 0 ; - } - } - // l'ultima curva è sempre chiusa... - vCrvClose.emplace_back( Release( pCrvClosed)) ; - } + else + for ( int u = 0 ; u < ( int)vCrvClose.size() ; ++ u) + vCrvAllClose.emplace_back( Release( vCrvClose[u])) ; } } - // se nessun lato aperto, esco - if (( int)vCrvClose.size() == 0) + if (( int)vCrvAllClose.size() == 0) return true ; // trasformo la superificie di proiezione in Trimesh + //int B = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrfProjected->Clone()) ; + //m_pGeomDB->SetMaterial( B, BLACK) ; PtrOwner pStmProj( CloneSurfTriMesh( pSrfProjected->GetAuxSurf())) ; if ( IsNull( pStmProj) || ! pStmProj->IsValid() || pStmProj->GetTriangleCount() == 0) return false ; @@ -11119,8 +11317,8 @@ Pocketing::CutProjectionToFitShape( ISurfFlatRegion* pSrfProjected, const ISurfF // porto tutto in questo frame ICRVCOMPOPOVECTOR vCrvClose_c ; - for ( int i = 0 ; i < ( int)vCrvClose.size() ; ++ i) { - PtrOwner pCrvClose_i( CloneCurveComposite( vCrvClose[i])) ; + for ( int i = 0 ; i < ( int)vCrvAllClose.size() ; ++ i) { + PtrOwner pCrvClose_i( CloneCurveComposite( vCrvAllClose[i])) ; if ( IsNull( pCrvClose_i) || ! pCrvClose_i->IsValid() || pCrvClose_i->GetCurveCount() == 0) return false ; pCrvClose_i->ToLoc( frPock) ; @@ -11158,41 +11356,17 @@ Pocketing::CutProjectionToFitShape( ISurfFlatRegion* pSrfProjected, const ISurfF if ( IsNull( pStmProj) || ! pStmProj->IsValid()) return true ; // ... ricoverto La Trimesh in FlatRegione - SurfFlatRegionByContours SrfProj_H ; - POLYLINEVECTOR vPl ; - pStmProj->GetLoops( vPl) ; + PtrOwner pSfrProj( CreateSurfFlatRegion()) ; + if ( IsNull( pSfrProj)) + return false ; Plane3d plPlane ; plPlane.Set( ORIG, Z_AX) ; - for ( int i = 0 ; i < ( int)vPl.size() ; ++ i) { - // recupero la curva composita - PolyLine PL = vPl[i] ; - PtrOwner pCrv( CreateCurveComposite()) ; - pCrv->FromPolyLine( PL) ; - PolyArc PA ; - pCrv->ApproxWithArcsEx( 5 * EPS_SMALL, ANG_TOL_STD_DEG, LIN_FEA_STD, PA) ; - pCrv->Clear() ; - pCrv->FromPolyArc( PA) ; - // la converto in una semplice cruva per proiettarla su piano XY - // dato che le curve sono prese da una trimesh, le riproietto per sicurezza e per evitare approssimazioni - double dS, dE ; - pCrv->GetDomain( dS, dE) ; - PtrOwner pCrv_c( pCrv->CopyParamRange( dS, dE)) ; - if ( IsNull( pCrv_c) || ! pCrv_c->IsValid()) - return false ; - PtrOwner pCrv_proj( ProjectCurveOnPlane( *pCrv_c, plPlane)) ; - if ( IsNull( pCrv_proj) || ! pCrv_proj->IsValid()) - return false ; - SrfProj_H.AddCurve( Release( pCrv_proj)) ; // aggiungo le curve proiettate - } - - // recupero la Flat region di prozione e controllo la validità - PtrOwner pStmProj_HH( SrfProj_H.GetSurf()) ; - if ( IsNull( pStmProj_HH) || ! pStmProj_HH->IsValid() || pStmProj_HH->GetChunkCount() == 0) - return true ; + if ( ! GetSfrByStm( pStmProj, pSfrProj, plPlane, V_NULL, 0.)) + return false ; // la risporto in globale e sostituisco - pStmProj_HH->ToGlob( frPock) ; + pSfrProj->ToGlob( frPock) ; pSrfProjected->Clear() ; - pSrfProjected->CopyFrom( pStmProj_HH) ; + pSrfProjected->CopyFrom( pSfrProj) ; return pSrfProjected != nullptr && pSrfProjected->IsValid() && pSrfProjected->GetChunkCount() > 0 ; } @@ -11201,7 +11375,7 @@ Pocketing::CutProjectionToFitShape( ISurfFlatRegion* pSrfProjected, const ISurfF bool Pocketing::ProjectRaw( ISurfFlatRegion* pSrf, const Vector3d& vtTrasl, const ISurfTriMesh* pStmRaw, int nId, const double& dRawSecLen, const ISurfFlatRegion* pSrfOrig, - double dAreaToll) + int nStep, double dStep, double dAreaToll) { // controllo se funzione necessaria if ( ! m_bProjectRaw) @@ -11256,6 +11430,9 @@ Pocketing::ProjectRaw( ISurfFlatRegion* pSrf, const Vector3d& vtTrasl, // vettore delle isole in ogni Chunk per lo step corrente ICRVCOMPOPOVECTOR vCrvIsl ; + //int BB = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf_clone->Clone()) ; + //m_pGeomDB->SetMaterial( BB, BLACK) ; + // per ogni chunk della superificie originaria da svuotare for ( int c = 0 ; c < pSrf_clone->GetChunkCount() ; ++ c) { @@ -11272,7 +11449,8 @@ Pocketing::ProjectRaw( ISurfFlatRegion* pSrf, const Vector3d& vtTrasl, // ricavo la FlatRegion della proiezione di ogni faccia del grezzo tagliato dal // semipiano positivo definito dal chunk c allo step attuale ( vtTrasl) PtrOwner pSrfOnPlPlus( CreateSurfFlatRegion()) ; - if ( IsNull( pSrfOnPlPlus) || ! GetProjStmOnSfr( pSrf_clone_ChunkC, pStmRaw, pSrfOrig, pSrfOnPlPlus)) + if ( IsNull( pSrfOnPlPlus) || + ! GetProjStmOnSfr( pSrf_clone_ChunkC, pStmRaw, pSrfOrig, nStep, dStep, vtTrasl, pSrfOnPlPlus)) return false ; if ( IsNull( pSrfOnPlPlus) || ! pSrfOnPlPlus->IsValid() || pSrfOnPlPlus->GetChunkCount() == 0) pSrfOnPlPlus.Set( pSrf_clone_ChunkC) ; @@ -11304,10 +11482,10 @@ Pocketing::ProjectRaw( ISurfFlatRegion* pSrf, const Vector3d& vtTrasl, // converto le due regioni in Trimesh PtrOwner pStm1( CloneSurfTriMesh( pSrf_Final->GetAuxSurf())) ; PtrOwner pStm2( CloneSurfTriMesh( pSrfOnPlPlus->GetAuxSurf())) ; - int rr = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pStm1->Clone()) ; - int rrr = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pStm2->Clone()) ; - m_pGeomDB->SetMaterial( rr, RED) ; - m_pGeomDB->SetMaterial( rrr, ORANGE) ; + //int rr = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pStm1->Clone()) ; + //int rrr = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pStm2->Clone()) ; + //m_pGeomDB->SetMaterial( rr, RED) ; + //m_pGeomDB->SetMaterial( rrr, ORANGE) ; if ( ! IsNull( pStm1) && ! IsNull( pStm2) && pStm1->IsValid() && pStm2->IsValid()) { // controllo validità delle normali Vector3d vtN1, vtN2 ; @@ -11323,7 +11501,7 @@ Pocketing::ProjectRaw( ISurfFlatRegion* pSrf, const Vector3d& vtTrasl, // ricavo la Trimesh della zuppa di triangoli PtrOwner pStmResult( sTM_TSoup.GetSurf()) ; //pStm1->Add( *Release( pStm2)) ; - m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pStmResult->Clone()) ; + //m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pStmResult->Clone()) ; if ( ! IsNull( pStmResult) && pStmResult->IsValid()) { // dalla TriMesh ricavata ne estraggo la FlatRegion PtrOwner pSfrResult( CreateSurfFlatRegion()) ; @@ -11332,44 +11510,61 @@ Pocketing::ProjectRaw( ISurfFlatRegion* pSrf, const Vector3d& vtTrasl, if ( GetSfrByStm( pStmResult, pSfrResult, plPock, vtExtr, dThick)) pSrf_Final.Set( Release( pSfrResult)) ; } - return false ; } } } } + /*for ( int i = 0 ; i < vSfr_gained.size() ; ++ i) { + int rr = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, vSfr_gained[i]->Clone()) ; + m_pGeomDB->SetMaterial( rr, RED) ; + } + int bl = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrf_Final->Clone()) ; + m_pGeomDB->SetMaterial( bl, BLUE) ; + int pu = m_pGeomDB->AddGeoObj( GDB_ID_NULL, GDB_ID_ROOT, pSrfOrig->Clone()) ; + m_pGeomDB->SetMaterial( pu, PURPLE) ;*/ + // può capitare che da due Chunk distinti, mediante la proeizione questi si uniscano formandone uno solo... // Imposto nuovamente le Temp Prop + PtrOwner pStmRaw_clone( CloneSurfTriMesh( pStmRaw)) ; PtrOwner pSrf_Final_WithOCEdge( CreateSurfFlatRegion()) ; if ( IsNull( pSrf_Final_WithOCEdge)) return false ; - if ( ( int)vSfr_gained.size() != pSrf_Final->GetChunkCount()) { - for ( int c = 0 ; c < pSrf_Final->GetChunkCount() ; ++ c) { - PtrOwner pSrfChunk_c( pSrf_Final->CloneChunk( c)) ; - if ( IsNull( pSrfChunk_c) || ! pSrfChunk_c->IsValid()) - return false ; - for ( int i = 0 ; i < ( int)vSfr_gained.size() ; ++ i) - SetOpenOrCloseEdge( pSrfChunk_c, vSfr_gained[i], true) ; - - if ( pSrf_Final_WithOCEdge->GetChunkCount() == 0) - pSrf_Final.Set( Release( pSrfChunk_c)) ; - else - pSrf_Final->Add( *Release( pSrfChunk_c)) ; + if ( nStep == 8) + double g = 9.81 ; + for ( int c = 0 ; c < pSrf_Final->GetChunkCount() ; ++ c) { + PtrOwner pSrfChunk_c( pSrf_Final->CloneChunk( c)) ; + if ( IsNull( pSrfChunk_c) || ! pSrfChunk_c->IsValid()) + return false ; + for ( int i = 0 ; i < ( int)vSfr_gained.size() ; ++ i) { + // porto le superifici alla base della svuotatura... + pSrfChunk_c->Translate( - vtTrasl) ; + vSfr_gained[i]->Translate( - vtTrasl) ; + SetOpenOrCloseEdge( pSrfChunk_c, vSfr_gained[i], pSrfOrig, true, pStmRaw_clone, + vtTrasl, i == ( int)vSfr_gained.size() -1) ; + // ...le riporto allo step corrente + pSrfChunk_c->Translate( vtTrasl) ; + vSfr_gained[i]->Translate( vtTrasl) ; } + + if ( pSrf_Final_WithOCEdge->GetChunkCount() == 0) + pSrf_Final_WithOCEdge.Set( Release( pSrfChunk_c)) ; + else + pSrf_Final_WithOCEdge->Add( *Release( pSrfChunk_c)) ; } // aggiungo tutte le isole... for ( int is = 0 ; is < ( int)vCrvIsl.size() ; ++ is) - pSrf_Final->AddIntLoop( Release( vCrvIsl[is])) ; + pSrf_Final_WithOCEdge->AddIntLoop( Release( vCrvIsl[is])) ; - if ( ! IsNull( pSrf_Final) && pSrf_Final->IsValid()) { + if ( ! IsNull( pSrf_Final_WithOCEdge) && pSrf_Final_WithOCEdge->IsValid()) { // Controllo delle aree, se alla fine di tutto sono ancora uguali, allora esco double dArea_orig = 0 ; double dArea_finale = 0 ; - if ( pSrf_Final->GetArea( dArea_finale) && pSrf->GetArea( dArea_orig) && abs( dArea_orig - dArea_finale) < dAreaToll) + if ( pSrf_Final_WithOCEdge->GetArea( dArea_finale) && pSrf->GetArea( dArea_orig) && abs( dArea_orig - dArea_finale) < dAreaToll) return true ; // esco, alla fine non ho modificato la superificie originale mediante la proiezione con il grezzo pSrf->Clear() ; - pSrf->CopyFrom( Release( pSrf_Final)) ; - pSrf->Translate( - vtTrasl) ; // ritraslo la superificie come in origine + pSrf->CopyFrom( Release( pSrf_Final_WithOCEdge)) ; + pSrf->Translate( - vtTrasl) ; // ritraslo la superificie come in origine ( alla base) } return true ; @@ -11891,7 +12086,8 @@ Pocketing::SetTmpPropByOverlap( ICurveComposite* pCrv_, int nInd, const ICurveCo // copio le sottocurve toccate PtrOwner pCrvOriRange( CloneCurveComposite( pCrvOri)) ; - pCrvOriRange->TrimStartEndAtParam( floor( dUS), ceil( dUE)) ; + if ( ! pCrvOriRange->TrimStartEndAtParam( floor( dUS), ceil( dUE))) + pCrvOriRange->Clear() ; if ( ! pCrvOriRange->IsValid()) { nStat = 2 ; @@ -12103,8 +12299,10 @@ Pocketing::SetTmpPropWithRawProjectedFaces( ICurveComposite* pCrvCompo_NewExt, I ! pCrv_Bef->IsValid() || ! pCrv_Aft->IsValid()) return false ; // ricomposizione con tagli per non perdere le proprietà appena impostate - pCrv_Bef->TrimEndAtParam( u) ; - pCrv_Aft->TrimStartAtParam( u + 1) ; + if ( ! pCrv_Bef->TrimEndAtParam( u)) + pCrv_Bef->Clear() ; + if ( ! pCrv_Aft->TrimStartAtParam( u + 1)) + pCrv_Aft->Clear() ; if ( ! IsNull( pCrv_Bef) && pCrv_Bef->IsValid()) pCrv_New->AddCurve( Release( pCrv_Bef)) ; int nCrv = 0 ; @@ -12553,8 +12751,10 @@ Pocketing::AssignFeedOnCorners( ICurveComposite* pCrv, const ICurveComposite* pC double duS ; double duE ; pCrv_clone->GetParamAtPoint( ptS, duS) ; pCrv_clone->GetParamAtPoint( ptE, duE) ; - pCrv_back->TrimEndAtParam( duS) ; - pCrv_forward->TrimStartAtParam( duE) ; + if ( ! pCrv_back->TrimEndAtParam( duS)) + pCrv_back->Clear() ; + if ( ! pCrv_forward->TrimStartAtParam( duE)) + pCrv_forward->Clear() ; pCrv_clone->Clear() ; pCrv_clone->AddCurve( Release( pCrv_back)) ; pCrv_clone->AddCurve( vCrvMinFeed[i]->Clone()) ; @@ -12760,7 +12960,7 @@ Pocketing::AssignFeedSpiral( ICurveComposite* pCrv, const ISurfFlatRegion* pSrfR pCrv->Clear() ; pCrv->AddCurve( Release( pCrv_new)) ; - // controllo eventuali suvrapposizioni tra la curva attuale e i Link in precedenza percorsi + // controllo eventuali sovrapposizioni tra la curva attuale e i Link in precedenza percorsi for ( int l = 0 ; l < ( int)vLinks_done.size() ; ++ l) { IntersCurveCurve intCC( *pCrv, *vLinks_done[l]) ; for ( int i = 0 ; i < intCC.GetIntersCount() ; ++ i) { @@ -12770,9 +12970,11 @@ Pocketing::AssignFeedSpiral( ICurveComposite* pCrv, const ISurfFlatRegion* pSrfR continue ; PtrOwner pCrv_before( CloneCurveComposite( pCrv)) ; - pCrv_before->TrimEndAtParam( aInfo.IciA[0].dU) ; + if ( ! pCrv_before->TrimEndAtParam( aInfo.IciA[0].dU)) + pCrv_before->Clear() ; PtrOwner pCrv_after( CloneCurveComposite( pCrv)) ; - pCrv_after->TrimStartAtParam( aInfo.IciA[1].dU) ; + if ( ! pCrv_after->TrimStartAtParam( aInfo.IciA[1].dU)) + pCrv_after->Clear() ; PtrOwner pCrv_overlap( GetCurveComposite( pCrv->CopyParamRange( aInfo.IciA[0].dU, aInfo.IciA[1].dU))) ; for ( int u = 0 ; u < pCrv_overlap->GetCurveCount() ; ++ u) pCrv_overlap->SetCurveTempProp( u, FEED_DIVISOR * GetMaxFeed(), 0) ; @@ -12820,8 +13022,10 @@ Pocketing::AssignFeedSpiral( ICurveComposite* pCrv, const ISurfFlatRegion* pSrfR pCrv->GetCurve( u)->GetLength( dLen) ; if ( dLen < dToll + 5 * EPS_SMALL) { PtrOwner pCrvCompo( CloneCurveComposite( pCrv)) ; - pCrvCompo->TrimStartAtParam( u) ; - pCrvCompo->TrimEndAtLen( dLen + m_TParams.m_dDiam) ; + if ( ! pCrvCompo->TrimStartAtParam( u)) + pCrvCompo->Clear() ; + if ( ! pCrvCompo->TrimEndAtLen( dLen + m_TParams.m_dDiam)) + pCrvCompo->Clear() ; if ( pCrvCompo->IsValid()) { bool bFound = false ; for ( int uu = 1 ; uu < pCrvCompo->GetCurveCount() ; ++ uu) { @@ -13155,6 +13359,8 @@ Pocketing::GetHomogeneousParts( ICurveComposite* pCrvCompo, ICURVEPOVECTOR& vCrv vCrvClose.clear() ; if ( pCrvCompo == nullptr || ! pCrvCompo->IsValid() || pCrvCompo->GetCurveCount() == 0) // se curva non valida return true ; + if ( ! pCrvCompo->IsClosed()) + bCallAdjust = false ; // controllo se la curva ha solo tratti aperti o tratti chiusi --------------------- int nFirstTmpProp = -1 ; @@ -13214,7 +13420,7 @@ Pocketing::GetHomogeneousParts( ICurveComposite* pCrvCompo, ICURVEPOVECTOR& vCrv } // unisco il primo e l'ultimo tratto chiuso, avendo cambiato l'inizio e la fine - if ( vCrvClose.size() > 0) { + if ( vCrvClose.size() > 0 && bCallAdjust) { PtrOwner pCrvCompoFirstLast( CreateCurveComposite()) ; if ( IsNull( pCrvCompoFirstLast)) return false ; diff --git a/Pocketing.h b/Pocketing.h index 2766591..74b12a9 100644 --- a/Pocketing.h +++ b/Pocketing.h @@ -100,9 +100,10 @@ class Pocketing : public Machining BOOLVECTOR& vbChangedPrec, const ISurfFlatRegion* pSrfChunk, const int& nStep, const Vector3d vtTool, const double& dElev, const double& dDepth, const double& dStep) ; bool AdaptSfrWithRaw( ISurfFlatRegion* pSrf, Vector3d vtTrasl, const double& dRawSecLen, - ICRVCOMPOPOVECTOR& vCrvOEFlags, bool& bChanged, double dAreaToll = 500 * EPS_SMALL) ; + ICRVCOMPOPOVECTOR& vCrvOEFlags, bool& bChanged, int nStep, double dStep, + double dAreaToll = 500 * EPS_SMALL) ; bool AdjustFakeOpenEdges( ICurveComposite* pCrvCompo, const ISurfFlatRegion* pSrfOrig, const ISurfTriMesh* pStmRaw, - const Vector3d vtTrasl) ; + const Vector3d vtTrasl, bool bFromProj = false) ; bool GetStmRawPart( int nId, ISurfTriMesh* pSrfTMRaw, Frame3d frPocket = GLOB_FRM) ; bool CheckSmallPartsForOpenEdge( ICurveComposite* pCrvCompo, double dToll = 1500 * EPS_SMALL) ; bool SetTmpPropWithRawProjectedFaces( ICurveComposite* pCrvCompo_NewExt, ICRVCOMPOPOVECTOR& vCrvExtProj, @@ -111,12 +112,14 @@ class Pocketing : public Machining bool& bIsChanged, double dAreaToll = 500 * EPS_SMALL, bool bInVsOut = true, bool bRemoveSmallRawParts = false, bool bComputeOpenEdge = true) ; bool ProjectRaw( ISurfFlatRegion* pSrf, const Vector3d& vtTrals, const ISurfTriMesh* pSrfProjRaw, int nId, - const double& dRawSecLen, const ISurfFlatRegion* pSrfOrig, double dAreaToll = 500 * EPS_SMALL) ; + const double& dRawSecLen, const ISurfFlatRegion* pSrfOrig, int nStep, double dStep, + double dAreaToll = 500 * EPS_SMALL) ; bool AdjustAngleForProjectedFace( const ISurfFlatRegion* pSrfFaceT, ICurveComposite* pCrvEdgeBorder, double dAngle) ; - bool SetOpenOrCloseEdge( ISurfFlatRegion* pSrfTP, const ISurfFlatRegion* pSrfOrig, bool bFromProj = false, - ISurfTriMesh* pStmRaw = nullptr, Vector3d vtTrasl = V_NULL) ; + bool SetOpenOrCloseEdge( ISurfFlatRegion* pSrfTP, const ISurfFlatRegion* pSrfForCrvs, const ISurfFlatRegion* pSrfOrig, + bool bFromProj = false, ISurfTriMesh* pStmRaw = nullptr, Vector3d vtTrasl = V_NULL, + bool bCheckFakeOpenEdge = true) ; bool GetProjStmOnSfr( const ISurfFlatRegion* pSfr, const ISurfTriMesh* pStmRaw, const ISurfFlatRegion* pSrfOrig, - ISurfFlatRegion* pSfrRawBoxProj) ; + const int nStep, double dStep, const Vector3d& vtTrasl, ISurfFlatRegion* pSfrRawBoxProj) ; bool CutProjectionToFitShape( ISurfFlatRegion* pSrfProjected, const ISurfFlatRegion* pSrfOrig) ; bool AjustCurveForProjRawOnFace( const ICurveLine* pL1, ICurveLine* pL2, const ICurveComposite* pCrvBorder, ICurveComposite* pCompo, int nStat, PNTVECTOR vPtTan, ISurfFlatRegion* pSrfProjRaw) ; @@ -331,7 +334,7 @@ class Pocketing : public Machining bool m_bOpenOutRaw ; // flag forzatura lati aperti sempre fuori dal grezzo double m_dOpenMinSafe ; // minima distanza di sicurezza di attacco su lato aperto bool m_bIntersRaw = true ; // flag per intersezione con grezzo - bool m_bProjectRaw = false ; // flag di proiezione del grezzo + bool m_bProjectRaw = true ; // flag di proiezione del grezzo double m_dMaxLenRawProj = 100 ; // lunghezza massima per contatto di proiezione bool m_bOptOffset = true ; // flag per ottimizzazione numero di Offset necessari bool m_bOptOffsetCM = false ; // flag per ottimizzazione numero di Offset necessari con centroidi e medial Axis