-GetMainFaces completa, da testare; da risolvere problema tunnel
-in FaceData migliorie varie
This commit is contained in:
@@ -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?
|
||||
|
||||
+127
-77
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user