- in GetMainFaces aggiunta faccia di mezzo tunnel e varie migliorie

- in GetFacesData non si trimmano più le superfici
This commit is contained in:
luca.mazzoleni
2024-04-19 19:12:51 +02:00
parent 10c1cd55f3
commit 10399347f0
2 changed files with 175 additions and 116 deletions
+1 -1
View File
@@ -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
+174 -115
View File
@@ -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)