From 4a4a7d648bdd542496e88b42ba916f0c4bbb8e62 Mon Sep 17 00:00:00 2001 From: SaraP Date: Thu, 20 Jul 2023 12:44:32 +0200 Subject: [PATCH] 3dPrinting : - aggiunta chiusura dei percorsi di extra shell - aggiunto clamp sui valori di strand width. --- LuaLibs/CalcPaths.lua | 116 +++++++++++++++++++++++++++------------ LuaLibs/CalcSlices.lua | 4 ++ LuaLibs/CalcToolPath.lua | 18 ++++-- 3 files changed, 99 insertions(+), 39 deletions(-) diff --git a/LuaLibs/CalcPaths.lua b/LuaLibs/CalcPaths.lua index da8f8f1..c471350 100644 --- a/LuaLibs/CalcPaths.lua +++ b/LuaLibs/CalcPaths.lua @@ -25,6 +25,7 @@ local function GetLayerParamsForPathCalc() LayerParams.nShellsNbr = EgtGetInfo( s_nPartId, KEY_SHELLS_NBR, 'i') LayerParams.dStrand = EgtGetInfo( s_nPartId, KEY_STRAND, 'd') LayerParams.dInnerStrand = EgtGetInfo( s_nPartId, KEY_INNER_STRAND, 'd') or LayerParams.dStrand + LayerParams.dInnerStrand = EgtClamp( LayerParams.dInnerStrand, 0.5 * LayerParams.dStrand, 1.5 * LayerParams.dStrand) LayerParams.dLayHeight = EgtGetInfo( s_nPartId, KEY_SLICE_STEP, 'd') LayerParams.dStrandOverlap = EgtGetInfo( s_nPartId, KEY_STRAND_OVERLAP, 'd') or 0 LayerParams.dOffs = EgtGetInfo( s_nPartId, KEY_OFFSET_SLICE, 'd') @@ -44,6 +45,7 @@ local function GetLayerParamsForPathCalc() LayerParams.nCeilType = EgtGetInfo( s_nPartId, KEY_CEIL_TYPE, 'i') or FILL_TYPE.OFFSET -- parametri infill LayerParams.dInfillStrand = EgtGetInfo( s_nPartId, KEY_INFILL_STRAND, 'd') or LayerParams.dStrand + LayerParams.dInfillStrand = EgtClamp( LayerParams.dInfillStrand, 0.5 * LayerParams.dStrand, 1.5 * LayerParams.dStrand) LayerParams.bInfillLink = EgtGetInfo( s_nPartId, KEY_INFILL_LINK, 'b') or false LayerParams.dInfillOverlap = EgtGetInfo( s_nPartId, KEY_INFILL_OVERLAP, 'd') or 0 LayerParams.nInfillType = EgtGetInfo( s_nPartId, KEY_INFILL_TYPE, 'i') or FILL_TYPE.NONE @@ -2577,7 +2579,9 @@ end --------------------------------------------------------------------- local function ReorderExtraShells( nPathGrp, vPtStart, LayerParams) - + + local dAlpha = 1.2 + -- verifico se posso unire due tratti consecutivi della stessa shell local nFirst = EgtGetFirstNameInGroup( nPathGrp, EXTRA_SHELL_CRV .. '*') while nFirst do @@ -2588,7 +2592,7 @@ local function ReorderExtraShells( nPathGrp, vPtStart, LayerParams) local dStrand = EgtIf( nType == TYPE.EXTRA_OUTER_SHELL, LayerParams.dStrand, LayerParams.dInnerStrand) local nCurr = vShells[1] for i = 2, #vShells do - if dist( EgtEP( nCurr), EgtSP( vShells[i])) < dStrand + GEO.EPS_SMALL then + if dist( EgtEP( nCurr), EgtSP( vShells[i])) < dAlpha * dStrand + GEO.EPS_SMALL then -- unisco le curve EgtAddCurveCompoLine( nCurr, EgtSP( vShells[i])) EgtAddCurveCompoCurve( nCurr, vShells[i]) @@ -2597,7 +2601,7 @@ local function ReorderExtraShells( nPathGrp, vPtStart, LayerParams) end end -- check su prima e ultima curva - if nCurr ~= nFirst and dist( EgtEP( nCurr), EgtSP( nFirst)) < dStrand + GEO.EPS_SMALL then + if nCurr ~= nFirst and dist( EgtEP( nCurr), EgtSP( nFirst)) < dAlpha * dStrand + GEO.EPS_SMALL then -- unisco le curve EgtAddCurveCompoLine( nCurr, EgtSP( nFirst)) EgtAddCurveCompoCurve( nCurr, nFirst) @@ -2607,7 +2611,7 @@ local function ReorderExtraShells( nPathGrp, vPtStart, LayerParams) vShells = EgtGetNameInGroup( nPathGrp, sName) for i = 1, #vShells do if not EgtCurveIsClosed( vShells[i]) then - if dist( EgtSP( vShells[i]), EgtEP( vShells[i])) < dStrand + GEO.EPS_SMALL then + if dist( EgtSP( vShells[i]), EgtEP( vShells[i])) < dAlpha * dStrand + GEO.EPS_SMALL then EgtCloseCurveCompo( vShells[i]) end end @@ -2628,38 +2632,42 @@ local function ReorderExtraShells( nPathGrp, vPtStart, LayerParams) end -- cerco di creare percorsi - local k = 0 -- indice da utilizzare per i nomi - while #vIds > 0 do - k = k + 1 - -- prendo la prima tra le curve a disposizione - local nCurrCrv = vIds[1] - table.remove( vIds, 1) - EgtSetName( nCurrCrv, EXTRA_SHELL_CRV .. tostring(k)) - + local k = 1 -- indice da utilizzare per i nomi + local vUsed = {} -- flag per indicare se corrispondente elemento di vIds è già stato considerato + for i = 1, #vIds do + vUsed[i] = false + end + + local nCurr = vIds[1] + vUsed[1] = true + EgtSetName( nCurr, EXTRA_SHELL_CRV .. tostring(k)) + while nCurr do + local bEndChain = false local nCnt = 0 - -- se curva è chiusa - if EgtCurveIsClosed( nCurrCrv) then - ModifyStartPoint( nCurrCrv, vPtStart) - -- setto a nil per ripartire subito con curva successiva - nCurrCrv = nil + local vLinkedShells = { nCurr} + local dCurrStrand + local bSameStrand = true + + if EgtCurveIsClosed( nCurr) then + ModifyStartPoint( nCurr, vPtStart) + -- se è chiusa costituisce già una catena + bEndChain = true end - -- scorro alla ricerca di una curva che posso collegare alla corrente - while nCurrCrv do - local ptSCurr = EgtSP( nCurrCrv) - local ptECurr = EgtEP( nCurrCrv) + while not bEndChain do + local ptSCurr = EgtSP( nCurr) + local ptECurr = EgtEP( nCurr) + local nCurrType = EgtGetInfo( nCurr, KEY_TYPE, 'i') + dCurrStrand = EgtIf( nCurrType == TYPE.EXTRA_OUTER_SHELL, LayerParams.dStrand, LayerParams.dInnerStrand) + local bFound = false - local nCurrType = EgtGetInfo( nCurrCrv, KEY_TYPE, 'i') - local dCurrStrand = EgtIf( nCurrType == TYPE.EXTRA_OUTER_SHELL, LayerParams.dStrand, LayerParams.dInnerStrand) for j = 1, #vIds do - - if not EgtCurveIsClosed( vIds[j]) then + if not vUsed[j] and not EgtCurveIsClosed( vIds[j]) then local ptS = EgtSP( vIds[j]) local ptE = EgtEP( vIds[j]) - local nTypeJ = EgtGetInfo( vIds[j], KEY_TYPE, 'i') local dStrandJ = EgtIf( nTypeJ == TYPE.EXTRA_OUTER_SHELL, LayerParams.dStrand, LayerParams.dInnerStrand) - local dVal = 1.5 * max( dCurrStrand, dStrandJ) + local dVal = dAlpha * max( dCurrStrand, dStrandJ) local bLink = false if dist( ptECurr, ptE) < dVal then @@ -2672,30 +2680,60 @@ local function ReorderExtraShells( nPathGrp, vPtStart, LayerParams) bLink = true elseif nCnt == 0 and dist( ptSCurr, ptS) < dVal then -- congiungo start-start - EgtInvertCurve( nCurrCrv) - UpdateInvertInfo( nCurrCrv) + EgtInvertCurve( nCurr) + UpdateInvertInfo( nCurr) bLink = true end if bLink then nCnt = nCnt + 1 - EgtRelocateGlob( vIds[j], nCurrCrv, GDB_IN.AFTER) + EgtRelocateGlob( vIds[j], nCurr, GDB_IN.AFTER) EgtSetName( vIds[j], EXTRA_SHELL_CRV .. tostring( k)) + table.insert( vLinkedShells, vIds[j]) + if abs( dStrandJ - dCurrStrand) > GEO.EPS_SMALL then + bSameStrand = false + end -- aggiorno per collegamento successivo bFound = true - nCurrCrv = vIds[j] - table.remove( vIds, j) + nCurr = vIds[j] + vUsed[j] = true break end end end - -- se non ho più curve da collegare - if not bFound then - nCurrCrv = nil + + -- se non ho trovato setti da collegare la catena è finita, altrimenti posso cercare successivo + bEndChain = not bFound + end + + -- verifico se posso unire tutti i tratti appena trovati + if #vLinkedShells > 1 and bSameStrand and EgtGetInfo( vLinkedShells[1], KEY_TYPE, 'i') == TYPE.EXTRA_OUTER_SHELL and + dist( EgtSP( vLinkedShells[1]), EgtEP( vLinkedShells[#vLinkedShells])) < dAlpha * dCurrStrand + GEO.EPS_SMALL then + -- unisco le curve + for i = 2, #vLinkedShells do + EgtAddCurveCompoLine( vLinkedShells[1], EgtSP( vLinkedShells[i])) + EgtAddCurveCompoCurve( vLinkedShells[1], vLinkedShells[i]) + end + EgtCloseCurveCompo( vLinkedShells[1]) + + ModifyStartPoint( vLinkedShells[1], vPtStart) + EgtSetInfo( vLinkedShells[1], KEY_CLOSED_CRV, true) + end + + -- cerco il prossimo da cui partire + nCurr = nil + for i = 1, #vIds do + if not vUsed[i] then + nCurr = vIds[i] + vUsed[i] = true + k = k + 1 + EgtSetName( nCurr, EXTRA_SHELL_CRV .. tostring(k)) + break end end end + end -------------------------------------------------------------------- @@ -2772,6 +2810,14 @@ local function CalcExtraShellsPath( nMaxShellNbrDiff, nShellNbrGrp, nCrvGrpId, d local nCrv, nCnt = EgtTrimCurveWithRegion( nCrvOffs, nTrimSurf, true, true) if nCrv and nCnt ~= 0 then + -- verifico se posso unire primo e ultimo tratto + if nCrv and nCnt > 1 and AreSamePointApprox( EgtEP( nCrv + nCnt - 1), EgtSP( nCrv)) then + EgtRelocateGlob( nCrv + nCnt - 1, nCrv, GDB_IN.AFTER) + EgtAddCurveCompoCurve( nCrv + nCnt - 1, nCrv) + EgtChangeId( nCrv + nCnt - 1, nCrv) + nCnt = nCnt - 1 + end + for nId = nCrv, nCrv + nCnt - 1 do local dLen = EgtCurveLength( nId) local bValid = true diff --git a/LuaLibs/CalcSlices.lua b/LuaLibs/CalcSlices.lua index 6e819e3..3a84ed9 100644 --- a/LuaLibs/CalcSlices.lua +++ b/LuaLibs/CalcSlices.lua @@ -99,6 +99,7 @@ local function GetRibParams( nId) local RibParam = {} ReadParam( nId, KEY_RIBS_STRAND, 'd', s_dStrand, RibParam) + RibParam[KEY_RIBS_STRAND] = EgtClamp( RibParam[KEY_RIBS_STRAND], 0.5 * s_dStrand, 1.5 * s_dStrand) ReadParam( nId, KEY_RIBS_SHELLS_NBR, 'i', 0, RibParam) ReadParam( nId, KEY_RIBS_INVERT_DIR, 'b', false, RibParam) ReadParam( nId, KEY_RIBS_LEAD_IN_INVERT, 'b', false, RibParam) @@ -133,6 +134,7 @@ local function GetAuxSolidsParams( nId) local AuxSolidsParam = {} ReadParam( nId, KEY_AUX_SOLIDS_STRAND, 'd', s_dStrand, AuxSolidsParam) + RibParam[KEY_RIBS_STRAND] = EgtClamp( RibParam[KEY_RIBS_STRAND], 0.5 * s_dStrand, 1.5 * s_dStrand) ReadParam( nId, KEY_AUX_SOLIDS_SHELLS_NBR, 'i', 0, AuxSolidsParam) ReadParam( nId, KEY_AUX_SOLIDS_OVERLAP, 'd', 0, AuxSolidsParam) ReadParam( nId, KEY_AUX_SOLIDS_INFILL, 'i', FILL_TYPE.NONE, AuxSolidsParam) @@ -624,6 +626,7 @@ local function PrepareInfill( nStmId, vtSlicing) local dGridOverlap = EgtGetInfo( s_nPartId, KEY_INFILL_GRID_OVERLAP, 'd') or 0 local dOffsStm = EgtGetInfo( s_nPartId, KEY_OFFSET_SLICE, 'd') local dStrand = EgtGetInfo( s_nPartId, KEY_INFILL_STRAND, 'd') or s_dStrand + dStrand = EgtClamp( dStrand, 0.5 * s_dStrand, 1.5 * s_dStrand) -- creo gruppo per infill local nInfillGrp = EgtGroup( s_nPartId) @@ -657,6 +660,7 @@ local function PrepareAuxSolidsInfill( nSolidsLay, vtSlicing) local dOffsY = ReadParam( vIds[i], KEY_AUX_SOLIDS_OFFSET_Y, 'd', 0) local dGridOverlap = ReadParam( vIds[i], KEY_AUX_SOLIDS_GRID_OVERLAP, 'd', 0) local dStrand = ReadParam( vIds[i], KEY_AUX_SOLIDS_STRAND, 'd', s_dStrand) + dStrand = EgtClamp( dStrand, 0.5 * s_dStrand, 1.5 * s_dStrand) -- creo gruppo associato local nInfillGrp = EgtGroup( s_nPartId) diff --git a/LuaLibs/CalcToolPath.lua b/LuaLibs/CalcToolPath.lua index 5be7b9d..07cefb0 100644 --- a/LuaLibs/CalcToolPath.lua +++ b/LuaLibs/CalcToolPath.lua @@ -23,6 +23,7 @@ local function GetLayerParamsForToolPathCalc() LayerParams.bSpiralVase = EgtGetInfo( s_nPartId, KEY_SPIRAL_VASE, 'b') or false LayerParams.dStrand = EgtGetInfo( s_nPartId, KEY_STRAND, 'd') LayerParams.dInnerStrand = EgtGetInfo( s_nPartId, KEY_INNER_STRAND, 'd') or LayerParams.dStrand + LayerParams.dInnerStrand = EgtClamp( LayerParams.dInnerStrand, 0.5 * LayerParams.dStrand, 1.5 * LayerParams.dStrand) LayerParams.dLayHeight = EgtGetInfo( s_nPartId, KEY_SLICE_STEP, 'd') LayerParams.dOffs = EgtGetInfo( s_nPartId, KEY_OFFSET_SLICE, 'd') LayerParams.bInvert = ( EgtGetInfo( s_nPartId, KEY_PRINT_DIRECTION, 'i') == PRINT_DIRECTION.CW) @@ -45,6 +46,7 @@ local function GetLayerParamsForToolPathCalc() LayerParams.dTDiam = EgtGetInfo( s_nPartId, KEY_TOOL_DIAM, 'd') -- parametri infill LayerParams.dInfillStrand = EgtGetInfo( s_nPartId, KEY_INFILL_STRAND, 'd') or LayerParams.dStrand + LayerParams.dInfillStrand = EgtClamp( LayerParams.dInfillStrand, 0.5 * LayerParams.dStrand, 1.5 * LayerParams.dStrand) LayerParams.bInfillLink = EgtGetInfo( s_nPartId, KEY_INFILL_LINK, 'b') or false LayerParams.dInfillCoasting = EgtGetInfo( s_nPartId, KEY_INFILL_COASTING, 'd') or 0 LayerParams.dInfillWipe = EgtGetInfo( s_nPartId, KEY_INFILL_WIPE, 'd') or 0 @@ -582,7 +584,15 @@ local function CalcExtraShellToolPath( vEntIds, nTpathGrpId, LayerParams) end sPrevName = sCurrName end - + + -- aggiungo offset lead point sulle extra shell chiuse + for i = 1, #vIds do + if EgtCurveIsClosed( vIds[i]) then + local nCopy = EgtCopyGlob( nTpathGrpId, vIds[i]) + AddOffsetLeadPoint( {vIds[i]}, nCopy, LayerParams.dOffsetLP, LINK_TYPE.NONE) + end + end + -- aggiungo coasting/wipe for i = 1, #vIds do -- verifico non sia collegato al successivo tramite link @@ -702,8 +712,8 @@ local function VerifyInfillLink( nLinkId, nCurr, nNext, vIds, dStrand, nGrpTmp) -- se tratto lineare allineato come curva corrente if AreSameVectorApprox( vtS, vtE) and vtS * vtDirCurr < - 1 + GEO.EPS_SMALL then -- verifico distanza - local nCrvTest = EgtCurveCompoFromPoints( nGrpTmp, { EgtUP( nCurrLoc, dPar), EgtUP( nCurrLoc, dPar + 1)}) - local dDist = EgtPointCurveDist( EgtUP( nLinkLoc, dParCrv - 0.5), nNextLoc) + local nCrvTest = EgtCurveCompoFromPoints( nGrpTmp, { EgtUP( nNextLoc, dPar), EgtUP( nNextLoc, dPar + 1)}) + local dDist = EgtPointCurveDist( EgtUP( nLinkLoc, dParCrv - 0.5), nCrvTest) if dDist < dMinDist + GEO.EPS_SMALL then return false end @@ -1123,7 +1133,7 @@ local function ComputeRibsLinkOnDiffCrvs( nCrvS, nCrvE, dParS, dParE) local _, _, dParFinal = EgtPointCurveDist( EgtUP( nCrvE, dParE, GDB_ID.ROOT), nCrvS, GDB_ID.ROOT) local nCrv1 = ComputeShortestCrv( nCrvS, dParS, dParFinal) - -- recupero il tratto interessato sulla cruva2 + -- recupero il tratto interessato sulla curva2 local _, _, dParStart = EgtPointCurveDist( EgtUP( nCrvS, dParS, GDB_ID.ROOT), nCrvE, GDB_ID.ROOT) local nCrv2 = ComputeShortestCrv( nCrvE, dParStart, dParE)