3dPrinting :

- migliorie nei setti ( ingressi, uscite e gestione intersezioni).
This commit is contained in:
SaraP
2022-09-12 15:37:38 +02:00
parent 03ed942b2f
commit 858ebf2db6
4 changed files with 293 additions and 225 deletions
+73 -99
View File
@@ -266,7 +266,7 @@ local function ReorderPath( vOldIds, vNewIds)
EgtSpAddPoint( pt:getX(), pt:getY(), pt:getZ(), 0, 0, pt:getX(), pt:getY(), pt:getZ(), 0, 0)
end
local ptS = EgtSP( nParentIdx)
EgtSpSetOpenBound( true, SHP_OB.NEAR_PNT, ptS:getX(), ptS:getY(), ptS:getZ(), 0, 0)
EgtSpSetOpenBound( true, SHP_OB.NEAR_PNT, ptS:getX(), ptS:getY(), ptS:getZ(), 0, 0)
local vOrd, _ = EgtSpCalculate( SHP_TY.OPEN)
EgtSpTerminate()
@@ -385,37 +385,9 @@ end
-------------------------------------------------------------------
--------------------------- RIBS -----------------------------------
--------------------------------------------------------------------
local function TrimRibsOffset( nCrv, nOffs1, nOffs2, nOffsGrp, bIn)
local ptInt1 = EgtIP( nCrv, nOffs1, ORIG())
local ptInt2 = EgtIP( nCrv, nOffs2, ORIG())
local dPar1, dPar2
if ptInt1 then dPar1 = EgtCurveParamAtPoint( nCrv, ptInt1) end
if ptInt2 then dPar2 = EgtCurveParamAtPoint( nCrv, ptInt2) end
if dPar1 and dPar2 then
-- la curva viene spezzata in tre parti
if dPar1 > dPar2 then
dPar1, dPar2 = dPar2, dPar1
end
local nCopy = EgtCopyGlob( nCrv, nOffsGrp)
EgtTrimCurveEndAtParam( nCrv, dPar1)
EgtTrimCurveStartAtParam( nCopy, dPar2)
EgtSetInfo( nCopy, KEY_SPLIT_RIB, nCrv)
elseif dPar1 or dPar2 then
if bIn then
EgtTrimCurveEndAtParam( nCrv, dPar1 or dPar2)
else
EgtTrimCurveStartAtParam( nCrv, dPar1 or dPar2)
end
end
end
--------------------------------------------------------------------
-- Funzione che sistema le intersezioni fra costolature nel caso generico
local function AdjustRibsOffsetForIntersection( nCrv1, nCrv2, LayerParams, nOffsGrp, bIn)
local function AdjustRibsOffsetForIntersection( nCrv1, nCrv2, LayerParams, nOffsGrp)
-- calcolo gli offset della curva principale ( nCrv1) da usare per trim
local nShells = EgtGetInfo( nCrv1, KEY_RIBS_SHELLS_NBR, 'i')
@@ -423,74 +395,66 @@ local function AdjustRibsOffsetForIntersection( nCrv1, nCrv2, LayerParams, nOffs
local nOverlap2 = EgtGetInfo( nCrv2, KEY_RIBS_OVERLAP, 'i')
local nOverlap = min( nOverlap1, nOverlap2)
local dOffs = ( nShells - 1) * LayerParams.dStrand / 2
local nOffsM = EgtOffsetCurveAdv( nCrv1, - dOffs - ( 1 - nOverlap / 100) * LayerParams.dStrand)
local nOffsP = EgtOffsetCurveAdv( nCrv1, dOffs + ( 1 - nOverlap / 100) * LayerParams.dStrand)
local vSplit = {}
local nSrf = EgtSurfFrFatCurve( nOffsGrp, nCrv1, dOffs + ( 1 - nOverlap / 100) * LayerParams.dStrand, false)
-- recupero gli offset della curva secondaria ( nCrv2)
local vOffs2 = EgtGetNameInGroup( nOffsGrp, EgtGetName( nCrv2))
-- trim degli offset della curva secondaria
for i = 1, #vOffs2 do
TrimRibsOffset( vOffs2[i], nOffsM, nOffsP, nOffsGrp, bIn)
end
EgtErase( nOffsM)
EgtErase( nOffsP)
local nId, nCnt = EgtTrimCurveWithRegion( vOffs2[i], nSrf, false, true)
EgtChangeId( nId, vOffs2[i])
if nCnt > 1 then
EgtSetInfo( nId + 1, KEY_SPLIT_RIB, vOffs2[i])
EgtRelocateGlob( nId + 1, nOffsGrp, GDB_IN.LAST_SON)
end
end
EgtErase( nSrf)
end
--------------------------------------------------------------------
-- Funzione che sistema le intersezioni fra costolature nel caso di 2 passate
local function AdjustRibsOffsetForIntersection2Shells( nCrv1, nCrv2, LayerParams, nOffsGrp, bIn)
local function AdjustRibsOffsetForIntersection2Shells( nCrv1, nCrv2, LayerParams, nOffsGrp, nOrigGrp)
-- recupero gli offset delle due curve
local vOffs1 = EgtGetNameInGroup( nOffsGrp, EgtGetName( nCrv1))
local vOffs2 = EgtGetNameInGroup( nOffsGrp, EgtGetName( nCrv2))
-- recupero gli offset originali delle due curve
local vOffsOrig1 = EgtGetNameInGroup( nOrigGrp, EgtGetName( nCrv1))
local vOffsOrig2 = EgtGetNameInGroup( nOrigGrp, EgtGetName( nCrv2))
local vCopy1 = {}
for i = 1, #vOffs1 do
local nId = EgtCopyGlob( vOffs1[i], nOffsGrp)
table.insert( vCopy1, nId)
-- costruisco le superfici da usare per trim
local nOverlap = EgtGetInfo( nCrv1, KEY_RIBS_OVERLAP, 'i')
local dOffs = LayerParams.dStrand / 2 + ( 1 - nOverlap / 100) * LayerParams.dStrand
local nRect1 = EgtRectangle3P( nOffsGrp, EgtSP( vOffsOrig1[1]), EgtEP( vOffsOrig1[2]), EgtEP( vOffsOrig1[1]))
local nSrf1 = EgtSurfFlatRegion( nOffsGrp, {nRect1})
local vtN1 = EgtSurfFrNormVersor( nSrf1, GDB_ID.ROOT)
if LayerParams.vtSlicing * vtN1 < 0 then
EgtInvertSurf( nSrf1)
end
local nRect2 = EgtRectangle3P( nOffsGrp, EgtSP( vOffsOrig2[1]), EgtEP( vOffsOrig2[2]), EgtEP( vOffsOrig2[1]))
local nSrf2 = EgtSurfFlatRegion( nOffsGrp, {nRect2})
local vtN2 = EgtSurfFrNormVersor( nSrf2, GDB_ID.ROOT)
if LayerParams.vtSlicing * vtN2 < 0 then
EgtInvertSurf( nSrf2)
end
-- trim degli offset di nCrv1
local vOffs1 = EgtGetNameInGroup( nOffsGrp, EgtGetName( nCrv1))
for i = 1, #vOffs1 do
-- trovo gli offset di nCrv2 coinvolti nell'intersezione
local vIds = {}
for j = 1, #vOffs2 do
local ptInt = EgtIP( vOffs1[i], vOffs2[j], ORIG())
if ptInt then table.insert( vIds, j) end
end
if #vIds > 0 then
local bInCrv1 = false
-- se viene trovata una sola intersezione devo calcolare bIn per nCrv1
if #vIds == 1 then
table.insert( vIds, EgtIf( vIds[1] == 1, 2, 1))
local ptInt = EgtIP( nCrv1, nCrv2, ORIG())
local dParInt = EgtCurveParamAtPoint( nCrv1, ptInt)
local _, dParE = EgtCurveDomain( nCrv1)
bInCrv1 = abs( dParInt - dParE) < 100 * GEO.EPS_SMALL
end
TrimRibsOffset( vOffs1[i], vOffs2[vIds[1]], vOffs2[vIds[2]], nOffsGrp, bInCrv1)
end
end
local nId, nCnt = EgtTrimCurveWithRegion( vOffs1[i], nSrf2, false, true)
end
-- trim degli offset di nCrv2
local vOffs2 = EgtGetNameInGroup( nOffsGrp, EgtGetName( nCrv2))
for i = 1, #vOffs2 do
-- trovo gli offset di nCrv1 coinvolti nell'intersezione
local vIds = {}
for j = 1, #vCopy1 do
local ptInt = EgtIP( vOffs2[i], vCopy1[j], ORIG())
if ptInt then table.insert( vIds, j) end
end
if #vIds > 0 then
if #vIds == 1 then table.insert( vIds, EgtIf( vIds[1] == 1, 2, 1)) end
TrimRibsOffset( vOffs2[i], vCopy1[vIds[1]], vCopy1[vIds[2]], nOffsGrp, bIn)
end
local nId, nCnt = EgtTrimCurveWithRegion( vOffs2[i], nSrf1, false, true)
end
for i = 1, #vCopy1 do
EgtErase( vCopy1[i])
end
EgtErase( nSrf1)
EgtErase( nRect1)
EgtErase( nSrf2)
EgtErase( nRect2)
end
--------------------------------------------------------------------
@@ -527,20 +491,19 @@ local function HandleRibsIntersections( nRibsGrp, LayerParams, nOffsGrp, nRibsPa
local dPar1 = EgtCurveParamAtPoint( vRibsIds[i], ptInt)
local dPar2 = EgtCurveParamAtPoint( vRibsIds[j], ptInt)
local _, dParE1 = EgtCurveDomain( vRibsIds[i])
local _, dParE2 = EgtCurveDomain( vRibsIds[j])
local _, dParE2 = EgtCurveDomain( vRibsIds[j])
local bIn = abs( dPar1 - dParE1) < 50 * GEO.EPS_SMALL or abs( dPar2 - dParE2) < 50 * GEO.EPS_SMALL
local nCrv1 = vRibsIds[i] -- curva principale che non viene tagliata
local nCrv2 = vRibsIds[j] -- curve secondaria da modificare
if dPar1 < 50 * GEO.EPS_SMALL or abs( dPar1 - dParE1) < 50 * GEO.EPS_SMALL then
if dPar1 < 10 * GEO.EPS_SMALL or abs( dPar1 - dParE1) < 10 * GEO.EPS_SMALL then
nCrv1, nCrv2 = nCrv2, nCrv1
end
if bAllTwoStrands then
-- nel caso di 2 passate gestione speciale
AdjustRibsOffsetForIntersection2Shells( nCrv1, nCrv2, LayerParams, nRibsPathGrp, bIn)
AdjustRibsOffsetForIntersection2Shells( nCrv1, nCrv2, LayerParams, nRibsPathGrp, nOffsGrp)
else
AdjustRibsOffsetForIntersection( nCrv1, nCrv2, LayerParams, nRibsPathGrp, bIn)
AdjustRibsOffsetForIntersection( nCrv1, nCrv2, LayerParams, nRibsPathGrp)
end
end
EgtErase( nPtId)
@@ -575,6 +538,10 @@ local function ReorderRibs( nGrp, bInvertOrder, dStrand, nMaxNbr)
table.insert( vSPRibs, vIds[i])
end
end
local ptS = ORIG()
EgtSpSetOpenBound( true, SHP_OB.NEAR_PNT, ptS:getX(), ptS:getY(), ptS:getZ(), 0, 0)
local vOrd, dLen = EgtSpCalculate( SHP_TY.OPEN)
EgtSpTerminate()
@@ -585,12 +552,14 @@ local function ReorderRibs( nGrp, bInvertOrder, dStrand, nMaxNbr)
-- sistemo nomi
local kMax = nMaxNbr + 1
local dTol = 500 * GEO.EPS_SMALL
for i = 1, nMaxNbr do
local vIds = EgtGetNameInGroup( nGrp, RIBS_CRV .. tostring(i)) or {}
for j = 2, #vIds do
local ptM = EgtMP( vIds[j])
local dDist = EgtPointCurveDist( ptM, vIds[j-1])
if abs( dDist - dStrand) < 20 * GEO.EPS_SMALL then
local dDistS = EgtPointCurveDist( EgtSP( vIds[j]), vIds[j-1])
local dDistM = EgtPointCurveDist( EgtMP( vIds[j]), vIds[j-1])
local dDistE = EgtPointCurveDist( EgtEP( vIds[j]), vIds[j-1])
if abs( dDistS - dStrand) < dTol or abs( dDistM - dStrand) < dTol or abs( dDistE - dStrand) < dTol then
-- se le costolatura è vicina alla precedente avrà lo stesso nome
EgtSetName( vIds[j], EgtGetName( vIds[j-1]))
EgtRelocateGlob( vIds[j], vIds[j-1], GDB_IN.AFTER)
@@ -695,7 +664,7 @@ local function ReorderRibsInters2Shells( nOffsGrp, dStrand)
-- prendo la prima tra le curve a disposizione
nCurrCrv = vIds[1]
table.remove( vIds, 1)
EgtSetName( nCurrCrv, RIBS_CRV .. tostring(k))
EgtSetName( nCurrCrv, RIBS_CRV .. tostring(k))
local pt = EgtEP( nCurrCrv)
local _, dParE = EgtCurveDomain( nCurrCrv)
local nCnt = 0
@@ -713,7 +682,7 @@ local function ReorderRibsInters2Shells( nOffsGrp, dStrand)
-- controllo che sia vicino ad uno degli estremi
local dParS, dParE = EgtCurveDomain( vIds[j])
if abs( dParMinDist - dParS) < 500 * GEO.EPS_SMALL then
bAdd = true
bAdd = true
elseif abs( dParMinDist - dParE) < 500 * GEO.EPS_SMALL then
bAdd = true
-- è se necessaria inversione di vIds[j]
@@ -769,7 +738,12 @@ local function ReorderRibsInters2Shells( nOffsGrp, dStrand)
end
end
-- se non ho più curve da collegare
if not bFound then
if not bFound and nCnt == 0 then
-- se era la prima curva faccio un tentativo invertendola
nCnt = 1
EgtInvertCurve( nCurrCrv)
pt = EgtEP( nCurrCrv)
elseif not bFound then
nCurrCrv = nil
end
end
@@ -848,13 +822,13 @@ local function CalcRibsPaths( nSliceGrp, nRibsGrp, LayerParams, nIdx, nMaxStrand
EgtOutLog( 'Warning: Ribs not possibile (layer '..tostring( nIdx)..') - CalcPaths')
EgtErase( vOrderedRibs[i])
else
local nCrv, nCnt = EgtTrimCurveWithRegion( vOrderedRibs[i], vSurfOffs[nOverlap], true, false)
tOldNewIds[ vOrderedRibs[i]] = {}
-- elimino tratti troppo corti
for nInd = 0, nCnt - 1 do
local nCrv, nCnt = EgtTrimCurveWithRegion( vOrderedRibs[i], vSurfOffs[nOverlap], true, false)
tOldNewIds[ vOrderedRibs[i]] = {}
-- elimino tratti troppo corti
for nInd = 0, nCnt - 1 do
local dLen = EgtCurveLength( nCrv + nInd)
if dLen < 10 * MIN_LEN then
if dLen < MIN_RIBS_LEN then
EgtErase( nCrv + nInd)
else
table.insert( tOldNewIds[ vOrderedRibs[i]], nCrv + nInd)
@@ -871,7 +845,7 @@ local function CalcRibsPaths( nSliceGrp, nRibsGrp, LayerParams, nIdx, nMaxStrand
-- salvo info della superficie di trim associata
EgtSetInfo( nCrv + nInd, KEY_ASSOCIATED_SURF, vSurfOffs[nOverlap])
if nInd == 0 then
-- aggiorno la info
local nInfo = EgtGetInfo( nCrv + nInd, KEY_SPLIT_RIB, 'i')
@@ -887,7 +861,7 @@ local function CalcRibsPaths( nSliceGrp, nRibsGrp, LayerParams, nIdx, nMaxStrand
end
end
end
end
end
end
end