Skip to content

Commit

Permalink
FIX: faster dfassembly preview
Browse files Browse the repository at this point in the history
  • Loading branch information
9and3 committed Nov 27, 2024
1 parent a888e99 commit 1dc468a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
15 changes: 1 addition & 14 deletions src/gh/components/DF_preview_assembly/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import System

import typing

import Rhino.Geometry as rg

from ghpythonlib.componentbase import executingcomponent as component
Expand Down Expand Up @@ -93,18 +91,7 @@ def DrawViewportWires(self, args):
## DFBeams
#######################################
if len(self._dfassembly.beams) > 1:
# beams' obb
df_cloud = diffCheck.diffcheck_bindings.dfb_geometry.DFPointCloud()
vertices_pt3d_rh : typing.List[rg.Point3d] = [vertex.to_rg_point3d() for vertex in beam.vertices]
df_cloud.points = [np.array([vertex.X, vertex.Y, vertex.Z]).reshape(3, 1) for vertex in vertices_pt3d_rh]
obb: rg.Brep = diffCheck.df_cvt_bindings.cvt_dfOBB_2_rhbrep(df_cloud.get_tight_bounding_box())
# args.Display.DrawBrepWires(obb, System.Drawing.Color.Red) ## keep for debugging

# axis arrow
obb_faces = obb.Faces
obb_faces = sorted(obb_faces, key=lambda face: rg.AreaMassProperties.Compute(face).Area)
obb_endfaces = obb_faces[:2]
beam_axis = rg.Line(obb_endfaces[0].GetBoundingBox(True).Center, obb_endfaces[1].GetBoundingBox(True).Center)
beam_axis = beam.axis
extension_length = 0.5 * diffCheck.df_util.get_doc_2_meters_unitf()
beam_axis.Extend(extension_length, extension_length)
args.Display.DrawArrow(beam_axis, System.Drawing.Color.Magenta)
Expand Down
16 changes: 6 additions & 10 deletions src/gh/diffCheck/diffCheck/df_geometries.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def __setstate__(self, state: typing.Dict):
if "_center" in state and state["_center"] is not None:
state["_center"] = rg.Point3d.FromJSON(state["_center"])
if "_axis" in state and state["_axis"] is not None:
state["_axis"] = rg.Vector3d.FromJSON(state["_axis"])
state["_axis"] = rg.Line.FromJSON(state["_axis"])
self.__dict__.update(state)

def __repr__(self):
Expand All @@ -428,13 +428,12 @@ def __repr__(self):
def deepcopy(self):
return DFBeam(self.name, [face.deepcopy() for face in self.faces])

def compute_axis(self, is_unitized: bool = True) -> rg.Vector3d:
def compute_axis(self, is_unitized: bool = True) -> rg.Line:
"""
This is an utility function that computes the axis of the beam.
This is an utility function that computes the axis of the beam as a line.
The axis is calculated as the vector passing through the two most distance joint's centroids.
:param is_unitized: If True, the beam's axis is unitized
:return axis: The axis of the beam
:return axis: The axis of the beam as a line
"""
joints = self.joints
joint1 = joints[0]
Expand All @@ -451,15 +450,12 @@ def compute_axis(self, is_unitized: bool = True) -> rg.Vector3d:
joint1 = j1
joint2 = j2

axis = rg.Vector3d(
axis_ln = rg.Line(
joint1.center.to_rg_point3d(),
joint2.center.to_rg_point3d()
)

if is_unitized:
axis.Unitize()

return axis
return axis_ln

@classmethod
def from_brep_face(cls, brep, is_roundwood=False):
Expand Down

0 comments on commit 1dc468a

Please sign in to comment.