11from typing import Optional
2+ from typing import Type
23
34from compas .datastructures import Mesh
45from compas .geometry import Box
910from compas .geometry import Polygon
1011from compas .geometry import Transformation
1112from compas .geometry import Translation
12- from compas .geometry import bounding_box
13- from compas .geometry import identity_matrix
1413from compas .geometry import intersection_line_plane
1514from compas .geometry import is_point_in_polygon_xy
16- from compas .geometry import oriented_bounding_box
1715from compas_model .elements .element import Element
1816from compas_model .elements .element import Feature
1917from compas_model .interactions import BooleanModifier
@@ -51,26 +49,8 @@ class BeamElement(Element):
5149 The depth of the beam.
5250 length : float
5351 The length of the beam.
54- is_support : bool
55- Flag indicating if the beam is a support.
56- frame_bottom : :class:`compas.geometry.Frame`
57- Main frame of the beam.
58- frame_top : :class:`compas.geometry.Frame`
59- Second frame of the beam.
60- axis : :class:`compas.geometry.Line`
52+ center_line : :class:`compas.geometry.Line`
6153 Line axis of the beam.
62- section : :class:`compas.geometry.Polygon`
63- Section polygon of the beam.
64- polygon_bottom : :class:`compas.geometry.Polygon`
65- The bottom polygon of the beam.
66- polygon_top : :class:`compas.geometry.Polygon`
67- The top polygon of the beam.
68- transformation : :class:`compas.geometry.Transformation`
69- Transformation applied to the beam.
70- features : list[:class:`compas_model.features.BeamFeature`]
71- Features of the beam.
72- name : str
73- The name of the beam.
7454 """
7555
7656 @property
@@ -79,7 +59,6 @@ def __data__(self) -> dict:
7959 "width" : self .width ,
8060 "depth" : self .depth ,
8161 "length" : self .length ,
82- "is_support" : self .is_support ,
8362 "transformation" : self .transformation ,
8463 "features" : self ._features ,
8564 "name" : self .name ,
@@ -90,26 +69,16 @@ def __init__(
9069 width : float = 0.1 ,
9170 depth : float = 0.2 ,
9271 length : float = 3.0 ,
93- is_support : bool = False ,
9472 transformation : Optional [Transformation ] = None ,
9573 features : Optional [list [BeamFeature ]] = None ,
9674 name : Optional [str ] = None ,
9775 ) -> "BeamElement" :
98- super ().__init__ (frame = Frame .worldXY (), transformation = transformation , features = features , name = name )
99-
100- self .is_support : bool = is_support
76+ super ().__init__ (transformation = transformation , features = features , name = name )
10177
10278 self .width : float = width
10379 self .depth : float = depth
10480 self ._length : float = length
10581
106- self .points : list [list [float ]] = [[- width * 0.5 , - depth * 0.5 , 0 ], [- width * 0.5 , depth * 0.5 , 0 ], [width * 0.5 , depth * 0.5 , 0 ], [width * 0.5 , - depth * 0.5 , 0 ]]
107-
108- self .section : Polygon = Polygon (self .points )
109- self .axis : Line = Line ([0 , 0 , 0 ], [0 , 0 , length ])
110- self .frame_top : Frame = Frame (self .frame .point + self .axis .vector , self .frame .xaxis , self .frame .yaxis )
111- self .polygon_bottom , self .polygon_top = self .compute_top_and_bottom_polygons ()
112-
11382 def compute_elementgeometry (self ) -> Mesh :
11483 """Compute the shape of the beam from the given polygons .
11584 This shape is relative to the frame of the element.
@@ -119,13 +88,7 @@ def compute_elementgeometry(self) -> Mesh:
11988 :class:`compas.datastructures.Mesh`
12089 """
12190 box : Box = Box .from_width_height_depth (self .width , self .length , self .depth )
122- box .translate (
123- [
124- 0 ,
125- 0 ,
126- self .length * 0.5 ,
127- ]
128- )
91+ box .translate ([0 , 0 , self .length * 0.5 ])
12992 return box .to_mesh ()
13093
13194 @property
@@ -135,12 +98,11 @@ def length(self) -> float:
13598 @length .setter
13699 def length (self , length : float ):
137100 self ._length = length
101+ self .compute_elementgeometry ()
138102
139- self .section = Polygon (list (self .points ))
140-
141- self .axis = Line ([0 , 0 , 0 ], [0 , 0 , length ])
142- self .frame_top = Frame (self .frame .point + self .axis .vector , self .frame .xaxis , self .frame .yaxis )
143- self .polygon_bottom , self .polygon_top = self .compute_top_and_bottom_polygons ()
103+ @property
104+ def center_line (self ) -> Line :
105+ return Line ([0 , 0 , 0 ], [0 , 0 , self .length ])
144106
145107 def extend (self , distance : float ) -> None :
146108 """Extend the beam.
@@ -167,11 +129,12 @@ def compute_aabb(self, inflate: float = 0.0) -> Box:
167129 :class:`compas.geometry.Box`
168130 The axis-aligned bounding box.
169131 """
170- points : list [list [float ]] = self .geometry .vertices_attributes ("xyz" ) # type: ignore
171- box : Box = Box .from_bounding_box (bounding_box (points ))
172- box .xsize += inflate
173- box .ysize += inflate
174- box .zsize += inflate
132+ box = self .modelgeometry .aabb
133+ if self .inflate_aabb and self .inflate_aabb != 1.0 :
134+ box .xsize += self .inflate_aabb
135+ box .ysize += self .inflate_aabb
136+ box .zsize += self .inflate_aabb
137+ self ._aabb = box
175138 return box
176139
177140 def compute_obb (self , inflate : float = 0.0 ) -> Box :
@@ -187,11 +150,12 @@ def compute_obb(self, inflate: float = 0.0) -> Box:
187150 :class:`compas.geometry.Box`
188151 The oriented bounding box.
189152 """
190- points : list [list [float ]] = self .geometry .vertices_attributes ("xyz" ) # type: ignore
191- box : Box = Box .from_bounding_box (oriented_bounding_box (points ))
192- box .xsize += inflate
193- box .ysize += inflate
194- box .zsize += inflate
153+ box = self .modelgeometry .obb
154+ if self .inflate_aabb and self .inflate_aabb != 1.0 :
155+ box .xsize += self .inflate_obb
156+ box .ysize += self .inflate_obb
157+ box .zsize += self .inflate_obb
158+ self ._obb = box
195159 return box
196160
197161 def compute_collision_mesh (self ) -> Mesh :
@@ -202,25 +166,12 @@ def compute_collision_mesh(self) -> Mesh:
202166 :class:`compas.datastructures.Mesh`
203167 The collision mesh.
204168 """
205- from compas .geometry import convex_hull_numpy
206-
207- points : list [list [float ]] = self .geometry .vertices_attributes ("xyz" ) # type: ignore
208- vertices , faces = convex_hull_numpy (points )
209- vertices = [points [index ] for index in vertices ] # type: ignore
210- return Mesh .from_vertices_and_faces (vertices , faces )
169+ mesh = self .modelgeometry .convex_hull
170+ self ._collision_mesh = mesh
171+ return mesh
211172
212173 def compute_point (self ) -> Point :
213- """Computes a reference point for the element geometry (e.g. the centroid).
214-
215- Returns
216- -------
217- :class:`compas.geometry.Point`
218- The reference point.
219-
220- """
221-
222- xform : Transformation = identity_matrix if self .modeltransformation is None else self .modeltransformation
223- return self .frame .point .transformed (xform )
174+ return Point (* self .modelgeometry .centroid ())
224175
225176 def compute_top_and_bottom_polygons (self ) -> tuple [Polygon , Polygon ]:
226177 """Compute the top and bottom polygons of the beam.
@@ -244,31 +195,31 @@ def compute_top_and_bottom_polygons(self) -> tuple[Polygon, Polygon]:
244195 points1 .append (result1 )
245196 return Polygon (points0 ), Polygon (points1 )
246197
247- def _add_modifier_with_beam (self , target_element : "BeamElement" , modifier_type : type [Modifier ] = None , ** kwargs ) -> Modifier :
198+ def _add_modifier_with_beam (self , target_element : "BeamElement" , modifier_type : Type [Modifier ] = None , ** kwargs ) -> Modifier :
248199 if not modifier_type :
249200 raise ValueError ("Modifier type is not defined, please define a modifier type e.g. SlicerModfier." )
250201
251- if isinstance ( modifier_type , type ) and issubclass (modifier_type , BooleanModifier ):
202+ if issubclass (modifier_type , BooleanModifier ):
252203 return BooleanModifier (self .elementgeometry .transformed (self .modeltransformation ))
253204
254- if isinstance ( modifier_type , type ) and issubclass (modifier_type , SlicerModifier ):
205+ if issubclass (modifier_type , SlicerModifier ):
255206 return self ._create_slicer_modifier (target_element )
256207
257208 raise ValueError (f"Unknown modifier type: { modifier_type } " )
258209
259210 def _create_slicer_modifier (self , target_element : "BeamElement" ) -> Modifier :
260211 mesh = self .elementgeometry .transformed (self .modeltransformation )
261- axis = target_element .axis .transformed (target_element .modeltransformation )
212+ center_line = target_element .center_line .transformed (target_element .modeltransformation )
262213
263- p0 = axis .start
264- p1 = axis .end
214+ p0 = center_line .start
215+ p1 = center_line .end
265216
266217 closest_distance_to_end_point = float ("inf" )
267218 closest_face = 0
268219 for face in self .elementgeometry .faces ():
269220 polygon = mesh .face_polygon (face )
270221 frame = polygon .frame
271- result = intersection_line_plane (axis , Plane .from_frame (frame ))
222+ result = intersection_line_plane (center_line , Plane .from_frame (frame ))
272223 if result :
273224 point = Point (* result )
274225 xform = Transformation .from_frame_to_frame (frame , Frame .worldXY ())
0 commit comments