From 5bb7fdd63424f1399e4c3ddf94f25ab8b28dd503 Mon Sep 17 00:00:00 2001 From: "luca.mazzoleni" Date: Wed, 28 Jun 2023 11:32:48 +0200 Subject: [PATCH] - aggiunta libreria WFeatureTopology per il riconoscimento topologico delle feature (da completare) - spostate alcune funzioni da FreeContour a WallLib --- .gitignore | 2 + LuaLibs/WFeatureTopology.lua | 130 ++++++++++++++++++++++++++++++++ LuaLibs/WProcessFreeContour.lua | 92 +--------------------- LuaLibs/WallLib.lua | 26 +++++++ bin/Images/.placeholder | 0 bin/LuaLibs/.placeholder | 0 6 files changed, 162 insertions(+), 88 deletions(-) create mode 100644 LuaLibs/WFeatureTopology.lua delete mode 100644 bin/Images/.placeholder delete mode 100644 bin/LuaLibs/.placeholder diff --git a/.gitignore b/.gitignore index 4789404..362a109 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,5 @@ /bin/LuaLibs/*.lua /bin/Images/*.png .vscode/settings.json +bin/LuaLibs/.placeholder +bin/Images/.placeholder diff --git a/LuaLibs/WFeatureTopology.lua b/LuaLibs/WFeatureTopology.lua new file mode 100644 index 0000000..fb33173 --- /dev/null +++ b/LuaLibs/WFeatureTopology.lua @@ -0,0 +1,130 @@ +-- WFeatureTopology.lua by Egaltech s.r.l. 2023/06/23 +-- Libreria per classificazione topologica feature pareti + +-- Tabella per definizione modulo +local WFeatureTopology = {} + +-- Include +require( 'EgtBase') + +EgtOutLog( ' WFeatureTopology started', 1) + +--------------------------------------------------------------------- +local function GetAdjacencyMatrix(Proc ) + local vAdj = {} + for i = 1, Proc.Fct do + for j = 1, Proc.Fct do + if i ~= j then + vAdj[i][j] = 0 + else + _, _, _, vAdj[i][j] = EgtSurfTmFacetsContact( Proc.Id, i, j, GDB_ID.ROOT) + end + j = j + 1 + end + i = i + 1 + end + return vAdj +end + +--------------------------------------------------------------------- +local function AreAllAnglesConcaveOrRight( Proc) + local vAdj = GetAdjacencyMatrix( Proc) + local bAllConcave, bAllRight = true, true + for i = 1, Proc.Fct do + for j = 1, Proc.Fct do + if vAdj[i][j] and vAdj[i][j] > 0 then + bAllConcave = false + bAllRight = false + break + elseif vAdj[i][j] and vAdj[i][j] + 90 > GEO.EPS_SMALL then + bAllRight = false + end + end + end + return bAllConcave, bAllRight +end + +--------------------------------------------------------------------- +local function GetTopologyLongName( sFamily, bIsThrough, bAllRightAngles, bIsParallel, nNumberOfFaces) + -- feature passante o cieca + local sThrough = '_' + if bIsThrough ~= nil then EgtIf( bIsThrough, 'Through', 'Blind') end + -- tutti gli angoli della feature sono retti oppure no + local sAllRightAngles = '_' + if bAllRightAngles ~= nil then EgtIf( bAllRightAngles, 'RightAngles', 'NotRightAngles') end + -- tutte le dimensioni della feature sono parallele agli assi principali del pezzo oppure no + local sParallel = '_' + if bIsParallel ~= nil then EgtIf( bIsParallel, 'Parallel', 'NotParallel') end + + local sLongName = sFamily .. '-' .. sThrough .. '-' .. sAllRightAngles .. '-' .. sParallel .. nNumberOfFaces + return sLongName +end + +--------------------------------------------------------------------- +function WFeatureTopology.Bevel( Proc) + local sFamily + local bIsThrough + local bAllRightAngles + local bIsParallel + local sLongName = '' + + local bAllAnglesConcave + bAllAnglesConcave, bAllRightAngles = AreAllAnglesConcaveOrRight( Proc) + if Proc.Fct == 1 and IsAnyDimensionLongAsPart( Proc) then + sFamily = 'Bevel' + bIsThrough = true + elseif Proc.Fct == 2 and bAllAnglesConcave and ( not IsAnyDimensionLongAsPart( Proc) or IsOneFaceTriangular( Proc)) then + sFamily = 'Bevel' + bIsThrough = false + end + bIsParallel = IsFeatureParallelToPart( Proc, sFamily) + + if sFamily then + sLongName = GetTopologyLongName( sFamily, bIsThrough, bAllRightAngles, bIsParallel, Proc.Fct) + return sFamily, bIsThrough, bAllRightAngles, bIsParallel, sLongName + else + return nil + end +end + +function WFeatureTopology.ClassifyTopology( Proc) + local sTopologicalName + if Proc.Fct == 1 then + if IsAnyDimensionLongAsPart( Proc) then + sTopologicalName = 'Bevel_Through___Parallel_1' + end + elseif Proc.Fct == 2 then + if vAdj[1][1] and abs( vAdj[1][1] - 90) < GEO.EPS_SMALL then + + end + end +end + + + + + + + + + + + + + + + + + + + + + + + + + + + +------------------------------------------------------------------------------------------------------------- +return WFeatureTopology \ No newline at end of file diff --git a/LuaLibs/WProcessFreeContour.lua b/LuaLibs/WProcessFreeContour.lua index 52e3dc8..cd6bf6d 100644 --- a/LuaLibs/WProcessFreeContour.lua +++ b/LuaLibs/WProcessFreeContour.lua @@ -20,6 +20,7 @@ -- 2023/04/17 Lavorazione CleanCorner sempre forzata con lato di lavoro in centro. -- 2023/05/25 Funzioni EgtAddMachining sostituite da WM.AddMachining in modo da trascrivere le priorità da btl alle lavorazioni. -- 2023/06/06 Aggiunta gestione lavorazione per lamatura speciale affondata con Tool_ID specifico. +-- 2023/06/26 Funzione Is3EdgesApprox spostata in WallLib. -- Tabella per definizione modulo local WPF = {} @@ -148,64 +149,6 @@ function WPF.FlipClassify( Proc, b3Raw) return nFlip0, nFlip1 end ---------------------------------------------------------------------- -local function TestElleShape3( nIdGeom, nNumFacet) - -- valida solo nel caso di tre facce - if nNumFacet ~= 3 then return false end - -- determino se L con una faccia terminale o U con tre facce - local bIsL = true - for i = 1, 3 do - local vFacAdj = EgtSurfTmFacetAdjacencies( nIdGeom, i - 1)[1] - -- le conto - local nCount = 0 - for j = 1, #vFacAdj do - if vFacAdj[j] >= 0 then - nCount = nCount + 1 - end - end - if nCount == 1 then - bIsL = false - break - end - end - return bIsL -end - ---------------------------------------------------------------------- -local function TestElleShape4( nIdGeom, nNumFacet) - -- valida solo nel caso di quattro facce - if nNumFacet ~= 4 then return false end - -- determino se L con due facce terminali o O - local nFac3Adj = 0 - local dMinArea3 = GEO.INFINITO * GEO.INFINITO - local dMaxArea2 = 0 - for i = 1, 4 do - local vFacAdj = EgtSurfTmFacetAdjacencies( nIdGeom, i - 1)[1] - -- le conto - local nCount = 0 - for j = 1, #vFacAdj do - if vFacAdj[j] >= 0 then - nCount = nCount + 1 - end - end - local _, dH, dV = EgtSurfTmFacetMinAreaRectangle( nIdGeom, i - 1, GDB_ID.ROOT) - local dArea = dH * dV - if nCount == 2 then - dMaxArea2 = max( dMaxArea2, dArea) - elseif nCount == 3 then - dMinArea3 = min( dMinArea3, dArea) - nFac3Adj = nFac3Adj + 1 - end - end - if nFac3Adj ~= 2 then return false end - -- verifico se L profonda oppure lunga - if dMinArea3 < dMaxArea2 then - return 1 - else - return 2 - end -end - --------------------------------------------------------------------- local function VerifyCornerType( Proc) -- Verifico il tipo di lavorazione su angolo : @@ -1243,33 +1186,6 @@ local function GetMaxDepth( vtNz, dMillDiam, dDiamTh, dMaxDepth, dFreeLen) end end ---------------------------------------------------------------------- --- Funzione per determinare se la faccia ha lati molto corti (trascurabili) ed è quindi approssimabile ad una 3 facce -local function Is3EdgesApprox( Proc, nFacet, nAddGrpId) - local bResult = false - local nContourId = EgtExtractSurfTmFacetLoops( Proc.Id, nFacet, nAddGrpId) - EgtMergeCurvesInCurveCompo( nContourId) - -- recupero il numero effettivo di lati - local _, nEntityCount = EgtCurveDomain( nContourId) - local nEdges = nEntityCount - if nContourId then - if nEntityCount and nEntityCount == 3 then - bResult = true - -- rimuovo i lati molto corti dal conteggio totale - elseif nEntityCount then - for i = 1, nEntityCount do - local dLength = EgtCurveCompoLength( nContourId, i - 1) - if dLength < 15 then nEdges = nEdges - 1 end - end - end - if nEdges == 3 then bResult = true end - end - if bResult == true then - EgtOutLog( 'FreeContour : Face with ' .. tointeger( nEntityCount) .. ' edges skipped (approx 3 edges)') - end - return bResult -end - --------------------------------------------------------------------- local function AddMillings( sMilling, vFace, Proc, nRawId, b3Raw, nConeCut, nAddGrpId) -- flag per fresature non passanti @@ -1292,7 +1208,7 @@ local function AddMillings( sMilling, vFace, Proc, nRawId, b3Raw, nConeCut, nAdd end -- verifico se la facce hanno alcuni lati molto corti e possono quindi essere approssimate a 3 lati for currentFace = 1, #vFace do - if Is3EdgesApprox( Proc, vFace[currentFace].Fac, nAddGrpId) then + if WL.Is3EdgesApprox( Proc, vFace[currentFace].Fac, nAddGrpId) then vFace[currentFace].Is3EdgesApprox = true end end @@ -2460,9 +2376,9 @@ local function MakeByPocket( Proc, nRawId, b3Raw) local nAddGrpId = WL.GetAddGroup( Proc.PartId) local nNewProc, nNumFacet = RemoveBottomFaceAndReorder( Proc, nAddGrpId, nFacet) -- se ho forma a L - local bIsL = ( nNumFacet == 2 or TestElleShape3( nNewProc, nNumFacet) or TestElleShape4( nNewProc, nNumFacet) == 2) + local bIsL = ( nNumFacet == 2 or WL.TestElleShape3( nNewProc, nNumFacet) or WL.TestElleShape4( nNewProc, nNumFacet) == 2) -- verifico se U - local bIsU = ( nNumFacet == 3 and not TestElleShape3( nNewProc, nNumFacet)) + local bIsU = ( nNumFacet == 3 and not WL.TestElleShape3( nNewProc, nNumFacet)) local dMiddleFacetLength = 0 if bIsU then local _, dH2, dV2 = EgtSurfTmFacetMinAreaRectangle( nNewProc, 1, GDB_ID.ROOT) diff --git a/LuaLibs/WallLib.lua b/LuaLibs/WallLib.lua index 0a04d4d..e456e33 100644 --- a/LuaLibs/WallLib.lua +++ b/LuaLibs/WallLib.lua @@ -1,5 +1,6 @@ -- WallLib.lua by Egaltech s.r.l. 2022/04/04 -- Libreria globale per Pareti +-- 2023/06/26 Spostata qui Is3EdgesApprox da FreeContour. Ora cerca autonomamente il gruppo se non viene passato. -- Tabella per definizione modulo local WallLib = {} @@ -374,6 +375,31 @@ function WallLib.TestElleShape4( nIdGeom, nNumFacet) end end +--------------------------------------------------------------------- +-- Funzione per determinare se la faccia ha lati molto corti (trascurabili) ed è quindi approssimabile ad una 3 facce +function WallLib.Is3EdgesApprox( Proc, nFacet, nAddGrpId) + nAddGrpId = nAddGrpId or WallLib.GetAddGroup( Proc.PartId) + local bResult = false + local nContourId = EgtExtractSurfTmFacetLoops( Proc.Id, nFacet, nAddGrpId) + EgtMergeCurvesInCurveCompo( nContourId) + -- recupero il numero effettivo di lati + local _, nEntityCount = EgtCurveDomain( nContourId) + local nEdges = nEntityCount + if nContourId then + if nEntityCount and nEntityCount == 3 then + bResult = true + -- rimuovo i lati molto corti dal conteggio totale + elseif nEntityCount then + for i = 1, nEntityCount do + local dLength = EgtCurveCompoLength( nContourId, i - 1) + if dLength < 15 then nEdges = nEdges - 1 end + end + end + if nEdges == 3 then bResult = true end + end + return bResult +end + ------------------------------------------------------------------------------------------------------------- -- restituisce le facce del grezzo interessate dalla feature Proc function WallLib.GetProcessAffectedFaces( Proc, nPartId) diff --git a/bin/Images/.placeholder b/bin/Images/.placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/bin/LuaLibs/.placeholder b/bin/LuaLibs/.placeholder deleted file mode 100644 index e69de29..0000000