From ea588844c5e93770b5299e3425544b7b53579334 Mon Sep 17 00:00:00 2001 From: "luca.mazzoleni" Date: Fri, 19 Apr 2024 13:01:16 +0200 Subject: [PATCH 1/4] - aggiunte e modifiche a GetMainFaces --- LuaLibs/FaceData.lua | 49 +++++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/LuaLibs/FaceData.lua b/LuaLibs/FaceData.lua index e42f737..5568d8f 100644 --- a/LuaLibs/FaceData.lua +++ b/LuaLibs/FaceData.lua @@ -82,6 +82,7 @@ function FaceData.GetFacesByAdjacencyNumber( Proc) local FacesByAdjacencyNumber = {} for i = 1, Proc.Fct do + -- TODO questo non funziona!! table.insert( FacesByAdjacencyNumber[#Proc.Faces[i].Adjacencies], i - 1) end @@ -92,6 +93,12 @@ end local function GetBottomFace( Proc) local BottomFace = {} + if Proc.Topology.Family == 'Tunnel' then + return BottomFace + elseif not ( Proc.FeatureTopology.Family == 'Rabbet' or Proc.FeatureTopology.Family == 'VGroove' or Proc.FeatureTopology.Family == 'Groove' or Proc.FeatureTopology.Family == 'Pocket') then + error( 'GetBottomFace : Topology not implemented') + end + -- la faccia di fondo ha sempre Fct - 1 adiacenze. Se si trovano più facce di fondo si sceglie quella con minor elevazione local vFacesByAdjNumber = FaceData.GetFacesByAdjacencyNumber( Proc) local vBottomFace = vFacesByAdjNumber[ Proc.Fct - 1] @@ -123,27 +130,39 @@ local function GetBottomFace( Proc) end ------------------------------------------------------------------------------------------------------------- -local function GetLongFaces( Proc) +local function GetLongFaces( Proc, MainFaces) local LongFaces = {} if Proc.Fct > 5 then - error( 'GetLongFaces : More than 5 faces not supported') + error( 'GetLongFaces : Topology not implemented') end - local idBottomFace = GDB_ID.NULL - if Proc.MainFaces.BottomFace.Id then - idBottomFace = Proc.MainFaces.BottomFace.Id + local idBottomFace + if MainFaces.BottomFace then + idBottomFace = MainFaces.BottomFace.Id else local BottomFace = GetBottomFace( Proc) - idBottomFace = BottomFace.Id + idBottomFace = BottomFace.Id or GDB_ID.NULL end - -- facce adiacenti a quella di fondo, ordinate - local FacesAdjacentToBottom = GetAdjacentFaces( Proc, idBottomFace) - table.sort( FacesAdjacentToBottom, function( a, b) return a.LengthOnMainFace > b.LengthOnMainFace end) + local FacesToAnalyze = {} + for i = 1, Proc.Fct do + if Proc.Faces[i].Id ~= idBottomFace then + FacesToAnalyze[i] = Proc.Faces[i] + end + end + + + if Proc.FeatureTopology.Family == 'Tunnel' then + + else + -- facce adiacenti a quella di fondo, ordinate + FacesToAnalyze = GetAdjacentFaces( Proc, idBottomFace) + table.sort( FacesToAnalyze, function( a, b) return a.LengthOnMainFace > b.LengthOnMainFace end) + end -- la prima faccia lunga è sempre la prima della lista - LongFaces[1].Id = FacesAdjacentToBottom[1].Id + LongFaces[1].Id = FacesToAnalyze[1].Id -- si cerca l'eventuale seconda faccia lunga, ossia quella non adiacente alla prima if Proc.Fct > 3 then for i = 1, Proc.Fct do @@ -211,17 +230,9 @@ function FaceData.GetMainFaces( Proc) -- faccia di fondo if Proc.FeatureTopology.Family == 'Rabbet' or Proc.FeatureTopology.Family == 'VGroove' or Proc.FeatureTopology.Family == 'Groove' or Proc.FeatureTopology.Family == 'Pocket' then MainFaces.BottomFace = GetBottomFace( Proc) + MainFaces.LongFaces = GetLongFaces( Proc, MainFaces) end - -- facce lunghe - if Proc.FeatureTopology.Family == 'Rabbet' or Proc.FeatureTopology.Family == 'VGroove' or Proc.FeatureTopology.Family == 'Groove' or Proc.FeatureTopology.Family == 'Pocket' or Proc.FeatureTopology.Family == 'Tunnel' then - MainFaces.LongFaces = GetLongFaces( Proc) - end - - -- facce laterali - - - return MainFaces end From 10399347f0c2f5e74fdbd5e7d7b6db2e6f7a06b0 Mon Sep 17 00:00:00 2001 From: "luca.mazzoleni" Date: Fri, 19 Apr 2024 19:12:51 +0200 Subject: [PATCH 2/4] =?UTF-8?q?-=20in=20GetMainFaces=20aggiunta=20faccia?= =?UTF-8?q?=20di=20mezzo=20tunnel=20e=20varie=20migliorie=20-=20in=20GetFa?= =?UTF-8?q?cesData=20non=20si=20trimmano=20pi=C3=B9=20le=20superfici?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LuaLibs/BeamExec.lua | 2 +- LuaLibs/FaceData.lua | 289 ++++++++++++++++++++++++++----------------- 2 files changed, 175 insertions(+), 116 deletions(-) diff --git a/LuaLibs/BeamExec.lua b/LuaLibs/BeamExec.lua index f01e37f..f8bbd48 100644 --- a/LuaLibs/BeamExec.lua +++ b/LuaLibs/BeamExec.lua @@ -495,7 +495,7 @@ local function CollectFeatures( PartId, b3Raw) end -- informazioni facce e topologia Proc.AdjacencyMatrix = FaceData.GetAdjacencyMatrix( Proc) - Proc.Faces = FaceData.GetFacesInfo( Proc, b3Raw) + Proc.Faces = FaceData.GetFacesInfo( Proc) Proc.Topology = FeatureData.GetTopology( Proc, b3Raw) -- se topologia feature riconosciuta, oppure da non calcolare perchè il riconoscimento topologico è basato sulla feature stessa if Proc.Topology.Name ~= 'NOT_IMPLEMENTED' then diff --git a/LuaLibs/FaceData.lua b/LuaLibs/FaceData.lua index 9b7f28c..dc5d080 100644 --- a/LuaLibs/FaceData.lua +++ b/LuaLibs/FaceData.lua @@ -63,17 +63,22 @@ local function GetAdjacentFaces( Proc, idFace) for i = 1, Proc.Fct do if vAdj[idFace + 1][i] and vAdj[idFace + 1][i] ~= 0 and ( idFace + 1 ~= i) then - local _, ptP1, ptP2 = EgtSurfTmFacetsContact( Proc.Id, idFace, i - 1, GDB_ID.ROOT) - local dLength = dist( ptP1, ptP2) AdjacentFaces[i] = {} AdjacentFaces[i].Id = i - 1 - AdjacentFaces[i].LengthOnMainFace = dLength end end return AdjacentFaces end +--------------------------------------------------------------------- +local function GetFacesContactLength( Proc, idFace1, idFace2) + local _, ptP1, ptP2 = EgtSurfTmFacetsContact( Proc.Id, idFace1, idFace2, GDB_ID.ROOT) + local dLength = dist( ptP1, ptP2) + + return dLength +end + --------------------------------------------------------------------- -- restituisce una tabella che correla numero di adiacenze e id delle facce con quello stesso numero di adiacenze function FaceData.GetFacesByAdjacencyNumber( Proc) @@ -82,7 +87,7 @@ function FaceData.GetFacesByAdjacencyNumber( Proc) for i = 1, Proc.Fct do if not FacesByAdjacencyNumber[#Proc.Faces[i].Adjacencies] then FacesByAdjacencyNumber[#Proc.Faces[i].Adjacencies] = {} - end + end table.insert( FacesByAdjacencyNumber[#Proc.Faces[i].Adjacencies], i - 1) end @@ -90,123 +95,16 @@ function FaceData.GetFacesByAdjacencyNumber( Proc) end ------------------------------------------------------------------------------------------------------------- -local function GetBottomFace( Proc) - local BottomFace = {} - - if Proc.Topology.Family == 'Tunnel' then - return BottomFace - elseif not ( Proc.FeatureTopology.Family == 'Rabbet' or Proc.FeatureTopology.Family == 'VGroove' or Proc.FeatureTopology.Family == 'Groove' or Proc.FeatureTopology.Family == 'Pocket') then - error( 'GetBottomFace : Topology not implemented') - end - - -- la faccia di fondo ha sempre Fct - 1 adiacenze. Se si trovano più facce di fondo si sceglie quella con minor elevazione - local vFacesByAdjNumber = FaceData.GetFacesByAdjacencyNumber( Proc) - local vBottomFace = vFacesByAdjNumber[ Proc.Fct - 1] - local nBottomFace - if #vBottomFace > 1 then - local dMinElevation = GEO.INFINITO - for i = 1, #vBottomFace do - for j = 1, Proc.Fct do - if vBottomFace[i] == Proc.Faces[j].Id then - if Proc.Faces[j].Elevation < dMinElevation then - dMinElevation = Proc.Faces[j].Elevation - nBottomFace = Proc.Faces[j].Id - end - end - end - end - else - nBottomFace = vBottomFace[1] - end - - BottomFace.Id = nBottomFace - BottomFace.FrameHV = Proc.Faces[nBottomFace + 1].FrameHV - BottomFace.Width = Proc.Faces[nBottomFace + 1].Width - BottomFace.Height = Proc.Faces[nBottomFace + 1].Height - BottomFace.Elevation = Proc.Faces[nBottomFace + 1].Elevation - BottomFace.VtN = Proc.Faces[nBottomFace + 1].VtN - - return BottomFace -end - -------------------------------------------------------------------------------------------------------------- -local function GetLongFaces( Proc, MainFaces) - local LongFaces = {} - - if Proc.Fct > 5 then - error( 'GetLongFaces : Topology not implemented') - end - - local idBottomFace - if MainFaces.BottomFace then - idBottomFace = MainFaces.BottomFace.Id - else - local BottomFace = GetBottomFace( Proc) - idBottomFace = BottomFace.Id or GDB_ID.NULL - end - - local FacesToAnalyze = {} - for i = 1, Proc.Fct do - if Proc.Faces[i].Id ~= idBottomFace then - FacesToAnalyze[i] = Proc.Faces[i] - end - end - - - if Proc.FeatureTopology.Family == 'Tunnel' then - - else - -- facce adiacenti a quella di fondo, ordinate - FacesToAnalyze = GetAdjacentFaces( Proc, idBottomFace) - table.sort( FacesToAnalyze, function( a, b) return a.LengthOnMainFace > b.LengthOnMainFace end) - end - - -- la prima faccia lunga è sempre la prima della lista - LongFaces[1].Id = FacesToAnalyze[1].Id - -- si cerca l'eventuale seconda faccia lunga, ossia quella non adiacente alla prima - if Proc.Fct > 3 then - for i = 1, Proc.Fct do - if ( i - 1) ~= idBottomFace and ( i - 1) ~= LongFaces[1].Id then - local bIsAdjacent = false - for j = 1, #Proc.Faces[i].Adjacences do - if Proc.Faces[i].Adjacences[j].Id == LongFaces[i].Id then - bIsAdjacent = true - end - end - if not bIsAdjacent then - LongFaces[2].Id = i - 1 - break - end - end - end - end - - for i = 1, #LongFaces do - for j = 1, Proc.Fct do - if LongFaces[i].Id == Proc.Faces[j].Id then - LongFaces[i].Frame = Proc.Faces[j].FrameHV - LongFaces[i].Width = Proc.Faces[j].Width - LongFaces[i].Height = Proc.Faces[j].Height - LongFaces[i].Elevation = Proc.Faces[j].Elevation - LongFaces[i].VtN = Proc.Faces[j].VtN - end - end - end - - return LongFaces -end - -------------------------------------------------------------------------------------------------------------- -function FaceData.GetFacesInfo( Proc, b3Raw) +function FaceData.GetFacesInfo( Proc) local Faces = {} local b3Solid = EgtGetBBoxGlob( EgtGetFirstNameInGroup( Proc.PartId, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD) for i = 1, Proc.Fct do Faces[i] = {} Faces[i].Id = i - 1 - Faces[i].VtN = EgtSurfTmFacetNormVersor( Proc.Id, i - 1, GDB_ID.ROOT ) + Faces[i].PtCenter, Faces[i].VtN = EgtSurfTmFacetCenter( Proc.Id, i - 1, GDB_ID.ROOT) if Proc.Fct < 6 then - local frHV, dFaceWidth, dFaceHeight = BeamLib.GetFaceHvRefDim( Proc.Id, i - 1, b3Raw) + local frHV, dFaceWidth, dFaceHeight = BeamLib.GetFaceHvRefDim( Proc.Id, i - 1) -- frame OCS faccia Faces[i].FrameHV = frHV -- larghezza OCS faccia @@ -223,12 +121,173 @@ function FaceData.GetFacesInfo( Proc, b3Raw) return Faces end +------------------------------------------------------------------------------------------------------------- +local function GetFaceInfoFromId( Proc, idFace) + local Face = {} + + if not Proc.Faces then + Proc.Faces = FaceData.GetFacesInfo( Proc) + end + + Face.Id = idFace + Face.FrameHV = Proc.Faces[Face.Id + 1].FrameHV + Face.Width = Proc.Faces[Face.Id + 1].Width + Face.Height = Proc.Faces[Face.Id + 1].Height + Face.Elevation = Proc.Faces[Face.Id + 1].Elevation + Face.VtN = Proc.Faces[Face.Id + 1].VtN + + return Face +end + +------------------------------------------------------------------------------------------------------------- +-- TODO valutare se +local function GetTunnelFaces( Proc) + local TunnelAddedFaces = {} + + -- TODO scrivere il box della parte nella Proc o fare funzione per recuperarlo + local b3Part = EgtGetBBoxGlob( EgtGetFirstNameInGroup( Proc.PartId, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD) + + if not ( Proc.Topology.IsThrough and Proc.Fct < 5) then + error( 'GetTunnelFaces : Topology not implemented') + end + + -- direzione del tunnel + local vtTunnelDirection = Proc.Faces[1].VtN ^ Proc.Faces[Proc.Faces[1].AdjacentFaces[1].Id + 1].VtN + + -- centro del tunnel + local frTunnel = Frame3d( Proc.Faces[1].PtCenter, vtTunnelDirection) + local b3Tunnel = EgtGetBBoxRef( Proc.Id, GDB_BB.STANDARD, frTunnel) + local ptTunnelCenter = b3Tunnel:getCenter() + ptTunnelCenter:toGlob( frTunnel) + + -- recupero gruppo per geometria addizionale + local nAddGrpId = BeamLib.GetAddGroup( Proc.PartId) + if not nAddGrpId then + -- TODO gestire meglio questo errore. Non conviene creare e verificare all'inizio se il gruppo esiste? + EgtOutLog( 'Error : missing AddGroup') + return TunnelAddedFaces + end + + -- faccia centrale, si crea larga come la parte e poi si trimma + TunnelAddedFaces.MiddleFaceTm.Id = EgtSurfTmPlaneInBBox( nAddGrpId, ptTunnelCenter, vtTunnelDirection, b3Part, GDB_ID.ROOT) + -- TODO se non si riesce a costruire la faccia bisogna dare errore o semplicemente non ritornarla?? + for i = 1, Proc.Fct do + EgtCutSurfTmPlane( TunnelAddedFaces.MiddleFaceTm.Id, Proc.Faces[i].PtCenter, -Proc.Faces[i].VtN, false, GDB_ID.ROOT) + end + + return TunnelAddedFaces +end + +------------------------------------------------------------------------------------------------------------- +local function GetBottomFace( Proc) + local BottomFace = {} + + if Proc.Topology.Family == 'Tunnel' then + return BottomFace + elseif not ( Proc.FeatureTopology.Family == 'Rabbet' or Proc.FeatureTopology.Family == 'VGroove' or Proc.FeatureTopology.Family == 'Groove' or Proc.FeatureTopology.Family == 'Pocket') then + error( 'GetBottomFace : Topology not implemented') + end + + -- la faccia di fondo ha sempre Fct - 1 adiacenze. Se si trovano più facce di fondo si sceglie quella con minor elevazione + local vFacesByAdjNumber = FaceData.GetFacesByAdjacencyNumber( Proc) + local vBottomFace = vFacesByAdjNumber[ Proc.Fct - 1] + local idBottomFace + if #vBottomFace > 1 then + local dMinElevation = GEO.INFINITO + for i = 1, #vBottomFace do + for j = 1, Proc.Fct do + if vBottomFace[i] == Proc.Faces[j].Id then + if Proc.Faces[j].Elevation < dMinElevation then + dMinElevation = Proc.Faces[j].Elevation + idBottomFace = Proc.Faces[j].Id + end + end + end + end + else + idBottomFace = vBottomFace[1] + end + + BottomFace = GetFaceInfoFromId( Proc, idBottomFace) + + return BottomFace +end + +------------------------------------------------------------------------------------------------------------- +local function GetLongFaces( Proc, MainFaces) + local LongFaces = {} + + if Proc.Fct > 5 then + error( 'GetLongFaces : Topology not implemented') + end + + local idBottomFace = GDB_ID.NULL + if MainFaces.BottomFace then + idBottomFace = MainFaces.BottomFace.Id + else + local BottomFace = GetBottomFace( Proc) + idBottomFace = BottomFace.Id or idBottomFace + end + + local idTunnelMiddleFace = GDB_ID.NULL + if Proc.Topology.Family == 'Tunnel' then + if MainFaces.TunnelAddedFaces then + idTunnelMiddleFace = MainFaces.TunnelAddedFaces.MiddleFaceTm.Id + else + local TunnelAddedFaces = GetTunnelFaces( Proc) + idTunnelMiddleFace = TunnelAddedFaces.MiddleFaceTm.Id or idTunnelMiddleFace + end + end + + local FacesToAnalyze = {} + for i = 1, Proc.Fct do + if Proc.Faces[i].Id ~= idBottomFace then + FacesToAnalyze[i] = Proc.Faces[i] + if Proc.Topology.Family == 'Tunnel' then + FacesToAnalyze[i].LengthOnMainFace = GetFacesContactLength( Proc, idTunnelMiddleFace, Proc.Faces[i].Id) + else + FacesToAnalyze[i].LengthOnMainFace = GetFacesContactLength( Proc, idBottomFace, Proc.Faces[i].Id) + end + end + end + table.sort( FacesToAnalyze, function( a, b) return a.LengthOnMainFace > b.LengthOnMainFace end) + + -- la prima faccia lunga è sempre la prima della lista + LongFaces[1].Id = FacesToAnalyze[1].Id + -- si cerca l'eventuale seconda faccia lunga, ossia quella non adiacente alla prima + if Proc.Fct > 3 then + for i = 1, #FacesToAnalyze do + if ( i - 1) ~= idBottomFace and ( i - 1) ~= LongFaces[1].Id then + local bIsAdjacent = false + for j = 1, #FacesToAnalyze[i].Adjacences do + if FacesToAnalyze[i].Adjacences[j].Id == LongFaces[i].Id then + bIsAdjacent = true + end + end + if not bIsAdjacent then + LongFaces[2].Id = i - 1 + break + end + end + end + end + + for i = 1, #LongFaces do + LongFaces[i] = GetFaceInfoFromId( Proc, LongFaces[i].Id) + end + + return LongFaces +end + ------------------------------------------------------------------------------------------------------------- -- recupero facce principali della feature, in base alla topologia function FaceData.GetMainFaces( Proc) local MainFaces = {} - -- faccia di fondo + if Proc.Topology.IsThrough and Proc.Fct < 5 then + MainFaces.TunnelAddedFaces = GetTunnelFaces( Proc) + end + if Proc.Topology.Family == 'Rabbet' or Proc.Topology.Family == 'VGroove' or Proc.Topology.Family == 'Groove' or Proc.Topology.Family == 'Pocket' then MainFaces.BottomFace = GetBottomFace( Proc) MainFaces.LongFaces = GetLongFaces( Proc, MainFaces) From 8cda36a838b5319e2309ca86450d6a77879ad20b Mon Sep 17 00:00:00 2001 From: "luca.mazzoleni" Date: Fri, 19 Apr 2024 19:15:08 +0200 Subject: [PATCH 3/4] - piccola correzione in GetMainFaces --- LuaLibs/FaceData.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LuaLibs/FaceData.lua b/LuaLibs/FaceData.lua index dc5d080..f625a75 100644 --- a/LuaLibs/FaceData.lua +++ b/LuaLibs/FaceData.lua @@ -288,7 +288,7 @@ function FaceData.GetMainFaces( Proc) MainFaces.TunnelAddedFaces = GetTunnelFaces( Proc) end - if Proc.Topology.Family == 'Rabbet' or Proc.Topology.Family == 'VGroove' or Proc.Topology.Family == 'Groove' or Proc.Topology.Family == 'Pocket' then + if Proc.Topology.Family == 'Rabbet' or Proc.Topology.Family == 'VGroove' or Proc.Topology.Family == 'Groove' or Proc.Topology.Family == 'Pocket' or Proc.Topology.Family == 'Tunnel' then MainFaces.BottomFace = GetBottomFace( Proc) MainFaces.LongFaces = GetLongFaces( Proc, MainFaces) end From 7bcce7463b546aa707be896ea7d3f5e37ba87ee9 Mon Sep 17 00:00:00 2001 From: "luca.mazzoleni" Date: Mon, 22 Apr 2024 18:37:46 +0200 Subject: [PATCH 4/4] -GetMainFaces completa, da testare; da risolvere problema tunnel -in FaceData migliorie varie --- LuaLibs/BeamExec.lua | 1 + LuaLibs/FaceData.lua | 204 +++++++++++++++++++++++++++---------------- 2 files changed, 128 insertions(+), 77 deletions(-) diff --git a/LuaLibs/BeamExec.lua b/LuaLibs/BeamExec.lua index f8bbd48..14f1f79 100644 --- a/LuaLibs/BeamExec.lua +++ b/LuaLibs/BeamExec.lua @@ -485,6 +485,7 @@ local function CollectFeatures( PartId, b3Raw) Proc.MainId = Proc.Id + nAddMainId end Proc.Box = EgtGetBBoxGlob( ProcId, GDB_BB.STANDARD) + EgtOutLog( '------Feature ' .. Proc.FeatureId .. '------') -- se esiste la geometria if Proc.Box and not Proc.Box:isEmpty() then -- TODO fare una funzione per recuperare i dati delle feature che non passano dal calcolo della topologia? diff --git a/LuaLibs/FaceData.lua b/LuaLibs/FaceData.lua index f625a75..53d1d0c 100644 --- a/LuaLibs/FaceData.lua +++ b/LuaLibs/FaceData.lua @@ -51,24 +51,24 @@ function FaceData.GetTriangularFaces( Proc) end ------------------------------------------------------------------------------------------------------------- -local function GetAdjacentFaces( Proc, idFace) - local AdjacentFaces = {} - - local vAdj - if Proc.AdjacencyMatrix then - vAdj = Proc.AdjacencyMatrix - else - vAdj = FaceData.GetAdjacencyMatrix( Proc) - end +local function GetNotAdjacentFaces( Proc, idFace) + local NotAdjacentFaces = {} for i = 1, Proc.Fct do - if vAdj[idFace + 1][i] and vAdj[idFace + 1][i] ~= 0 and ( idFace + 1 ~= i) then - AdjacentFaces[i] = {} - AdjacentFaces[i].Id = i - 1 + if Proc.Faces[i].Id ~= idFace then + local bIsAdjacent = false + for j = 1, #Proc.Faces[idFace + 1].Adjacencies do + if Proc.Faces[i].Id == Proc.Faces[idFace + 1].Adjacencies[j] then + bIsAdjacent = true + end + end + if not bIsAdjacent then + table.insert( NotAdjacentFaces, Proc.Faces[i]) + end end end - return AdjacentFaces + return NotAdjacentFaces end --------------------------------------------------------------------- @@ -84,11 +84,11 @@ end function FaceData.GetFacesByAdjacencyNumber( Proc) local FacesByAdjacencyNumber = {} + for i = 1, 10 do + FacesByAdjacencyNumber[i] = {} + end for i = 1, Proc.Fct do - if not FacesByAdjacencyNumber[#Proc.Faces[i].Adjacencies] then - FacesByAdjacencyNumber[#Proc.Faces[i].Adjacencies] = {} - end - table.insert( FacesByAdjacencyNumber[#Proc.Faces[i].Adjacencies], i - 1) + table.insert( FacesByAdjacencyNumber[#Proc.Faces[i].Adjacencies], Proc.Faces[i]) end return FacesByAdjacencyNumber @@ -96,8 +96,16 @@ end ------------------------------------------------------------------------------------------------------------- function FaceData.GetFacesInfo( Proc) + EgtOutLog( '---Faces START---') local Faces = {} + local b3Solid = EgtGetBBoxGlob( EgtGetFirstNameInGroup( Proc.PartId, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD) + local vAdj + if Proc.AdjacencyMatrix then + vAdj = Proc.AdjacencyMatrix + else + vAdj = FaceData.GetAdjacencyMatrix( Proc) + end for i = 1, Proc.Fct do Faces[i] = {} @@ -113,46 +121,44 @@ function FaceData.GetFacesInfo( Proc) Faces[i].Height = dFaceHeight -- elevazione calcolata rispetto al box della parte Faces[i].Elevation = EgtSurfTmFacetElevationInBBox( Proc.Id, i - 1, b3Solid, true, GDB_ID.ROOT) + + -- TODO valutare se fare un output unico alla fine o gestire log in altro modo + EgtOutLog( 'Facet ' .. Faces[i].Id .. ' of ' .. Proc.Fct - 1) + EgtOutLog( ' VtN: ' .. tostring( Faces[i].VtN)) + -- adiacenze della faccia - Faces[i].Adjacencies = GetAdjacentFaces( Proc, i - 1) + -- TODO chiamarle in modo che si capisca che sono solo gli id e non l'intero oggetto faccia + Faces[i].Adjacencies = {} + for j = 1, Proc.Fct do + if vAdj[i][j] and vAdj[i][j] ~= 0 and ( i ~= j) then + table.insert( Faces[i].Adjacencies, j - 1) + if EgtGetDebugLevel() >= 3 then + EgtOutLog( ' Adjacent to facet: ' .. j - 1) + end + end + end end end + EgtOutLog( '---Faces END---') return Faces end ------------------------------------------------------------------------------------------------------------- -local function GetFaceInfoFromId( Proc, idFace) - local Face = {} - - if not Proc.Faces then - Proc.Faces = FaceData.GetFacesInfo( Proc) - end - - Face.Id = idFace - Face.FrameHV = Proc.Faces[Face.Id + 1].FrameHV - Face.Width = Proc.Faces[Face.Id + 1].Width - Face.Height = Proc.Faces[Face.Id + 1].Height - Face.Elevation = Proc.Faces[Face.Id + 1].Elevation - Face.VtN = Proc.Faces[Face.Id + 1].VtN - - return Face -end - -------------------------------------------------------------------------------------------------------------- --- TODO valutare se +-- TODO valutare refactoring per mettere i calcoli del tunnel in una funzione +-- TODO valutare se restituire anche altre informazioni oltre alle facce (es: box); magari metterle in funzione a parte chiamata allo stesso livello della GetMainFAces local function GetTunnelFaces( Proc) local TunnelAddedFaces = {} -- TODO scrivere il box della parte nella Proc o fare funzione per recuperarlo local b3Part = EgtGetBBoxGlob( EgtGetFirstNameInGroup( Proc.PartId, 'Box') or GDB_ID.NULL, GDB_BB.STANDARD) - if not ( Proc.Topology.IsThrough and Proc.Fct < 5) then + if not ( Proc.Topology.IsThrough and Proc.Topology.AllRightAngles and Proc.Fct < 5) then error( 'GetTunnelFaces : Topology not implemented') end -- direzione del tunnel - local vtTunnelDirection = Proc.Faces[1].VtN ^ Proc.Faces[Proc.Faces[1].AdjacentFaces[1].Id + 1].VtN + local vtTunnelDirection = Proc.Faces[1].VtN ^ Proc.Faces[ Proc.Faces[1].Adjacencies[1] + 1].VtN -- centro del tunnel local frTunnel = Frame3d( Proc.Faces[1].PtCenter, vtTunnelDirection) @@ -169,6 +175,7 @@ local function GetTunnelFaces( Proc) end -- faccia centrale, si crea larga come la parte e poi si trimma + TunnelAddedFaces.MiddleFaceTm = {} TunnelAddedFaces.MiddleFaceTm.Id = EgtSurfTmPlaneInBBox( nAddGrpId, ptTunnelCenter, vtTunnelDirection, b3Part, GDB_ID.ROOT) -- TODO se non si riesce a costruire la faccia bisogna dare errore o semplicemente non ritornarla?? for i = 1, Proc.Fct do @@ -184,32 +191,25 @@ local function GetBottomFace( Proc) if Proc.Topology.Family == 'Tunnel' then return BottomFace - elseif not ( Proc.FeatureTopology.Family == 'Rabbet' or Proc.FeatureTopology.Family == 'VGroove' or Proc.FeatureTopology.Family == 'Groove' or Proc.FeatureTopology.Family == 'Pocket') then + elseif not ( Proc.Topology.Family == 'Rabbet' or Proc.Topology.Family == 'VGroove' or Proc.Topology.Family == 'Groove' or Proc.Topology.Family == 'Pocket') then error( 'GetBottomFace : Topology not implemented') end -- la faccia di fondo ha sempre Fct - 1 adiacenze. Se si trovano più facce di fondo si sceglie quella con minor elevazione - local vFacesByAdjNumber = FaceData.GetFacesByAdjacencyNumber( Proc) - local vBottomFace = vFacesByAdjNumber[ Proc.Fct - 1] - local idBottomFace - if #vBottomFace > 1 then + local FacesByAdjacencyNumber = FaceData.GetFacesByAdjacencyNumber( Proc) + local BottomFaces = FacesByAdjacencyNumber[ Proc.Fct - 1] + if #BottomFaces > 1 then local dMinElevation = GEO.INFINITO - for i = 1, #vBottomFace do - for j = 1, Proc.Fct do - if vBottomFace[i] == Proc.Faces[j].Id then - if Proc.Faces[j].Elevation < dMinElevation then - dMinElevation = Proc.Faces[j].Elevation - idBottomFace = Proc.Faces[j].Id - end - end + for i = 1, #BottomFaces do + if Proc.Faces[BottomFaces[i].Id + 1].Elevation < dMinElevation then + dMinElevation = Proc.Faces[BottomFaces[i].Id + 1].Elevation + BottomFace = Proc.Faces[BottomFaces[i].Id + 1] end end else - idBottomFace = vBottomFace[1] + BottomFace = BottomFaces[1] end - BottomFace = GetFaceInfoFromId( Proc, idBottomFace) - return BottomFace end @@ -242,57 +242,107 @@ local function GetLongFaces( Proc, MainFaces) local FacesToAnalyze = {} for i = 1, Proc.Fct do if Proc.Faces[i].Id ~= idBottomFace then - FacesToAnalyze[i] = Proc.Faces[i] + table.insert( FacesToAnalyze, Proc.Faces[i]) if Proc.Topology.Family == 'Tunnel' then - FacesToAnalyze[i].LengthOnMainFace = GetFacesContactLength( Proc, idTunnelMiddleFace, Proc.Faces[i].Id) + -- TODO questo non funziona nei tunnel, da modificare + FacesToAnalyze[#FacesToAnalyze].LengthOnMainFace = GetFacesContactLength( Proc, idTunnelMiddleFace, Proc.Faces[i].Id) else - FacesToAnalyze[i].LengthOnMainFace = GetFacesContactLength( Proc, idBottomFace, Proc.Faces[i].Id) + FacesToAnalyze[#FacesToAnalyze].LengthOnMainFace = GetFacesContactLength( Proc, idBottomFace, Proc.Faces[i].Id) end end end table.sort( FacesToAnalyze, function( a, b) return a.LengthOnMainFace > b.LengthOnMainFace end) -- la prima faccia lunga è sempre la prima della lista - LongFaces[1].Id = FacesToAnalyze[1].Id + LongFaces[1] = FacesToAnalyze[1] -- si cerca l'eventuale seconda faccia lunga, ossia quella non adiacente alla prima if Proc.Fct > 3 then - for i = 1, #FacesToAnalyze do - if ( i - 1) ~= idBottomFace and ( i - 1) ~= LongFaces[1].Id then - local bIsAdjacent = false - for j = 1, #FacesToAnalyze[i].Adjacences do - if FacesToAnalyze[i].Adjacences[j].Id == LongFaces[i].Id then - bIsAdjacent = true - end - end - if not bIsAdjacent then - LongFaces[2].Id = i - 1 - break - end - end + local NotAdjacentFaces = GetNotAdjacentFaces(Proc, LongFaces[1].Id) + if #NotAdjacentFaces > 0 then + LongFaces[2] = NotAdjacentFaces[1] end end - for i = 1, #LongFaces do - LongFaces[i] = GetFaceInfoFromId( Proc, LongFaces[i].Id) - end - return LongFaces end +------------------------------------------------------------------------------------------------------------- +local function GetSideFaces( Proc, MainFaces) + local SideFaces = {} + + if Proc.Fct > 5 then + error( 'GetSideFaces : Topology not implemented') + end + + local idBottomFace = GDB_ID.NULL + if MainFaces.BottomFace then + idBottomFace = MainFaces.BottomFace.Id + else + local BottomFace = GetBottomFace( Proc) + idBottomFace = BottomFace.Id or idBottomFace + end + local LongFaces = {} + if MainFaces.LongFaces then + LongFaces = MainFaces.LongFaces + else + LongFaces = GetLongFaces( Proc, MainFaces) + end + + for i = 1, Proc.Fct do + if i ~= idBottomFace + 1 then + local bIsSideFace = true + for j = 1, #LongFaces do + if Proc.Faces[i].Id == LongFaces[j].Id then + bIsSideFace = false + break + end + end + if bIsSideFace then + table.insert( SideFaces, Proc.Faces[i]) + end + end + end + + return SideFaces +end + ------------------------------------------------------------------------------------------------------------- -- recupero facce principali della feature, in base alla topologia function FaceData.GetMainFaces( Proc) + EgtOutLog( '---MainFaces START---') local MainFaces = {} - if Proc.Topology.IsThrough and Proc.Fct < 5 then + if Proc.Topology.IsThrough and Proc.Topology.AllRightAngles and Proc.Fct < 5 then MainFaces.TunnelAddedFaces = GetTunnelFaces( Proc) end if Proc.Topology.Family == 'Rabbet' or Proc.Topology.Family == 'VGroove' or Proc.Topology.Family == 'Groove' or Proc.Topology.Family == 'Pocket' or Proc.Topology.Family == 'Tunnel' then MainFaces.BottomFace = GetBottomFace( Proc) MainFaces.LongFaces = GetLongFaces( Proc, MainFaces) + MainFaces.SideFaces = GetSideFaces( Proc, MainFaces) end + -- TODO funzione apposita per informazioni log? + if EgtGetDebugLevel() >= 3 then + if MainFaces.BottomFace then + EgtOutLog( 'Bottom Face : ' .. MainFaces.BottomFace.Id) + end + if MainFaces.LongFaces then + for i = 1, #MainFaces.LongFaces do + EgtOutLog( 'Long Face : ' .. MainFaces.LongFaces[i].Id) + end + end + if MainFaces.SideFaces then + for i = 1, #MainFaces.SideFaces do + EgtOutLog( 'Side Face : ' .. MainFaces.SideFaces[i].Id) + end + end + if MainFaces.TunnelAddedFaces then + EgtOutLog( 'Middle Face (Trimesh): ' .. MainFaces.TunnelAddedFaces.MiddleFaceTm.Id) + end + end + + EgtOutLog( '---MainFaces END---') return MainFaces end