Skip to content

Commit

Permalink
Merge pull request diffCheckOrg#57 from diffCheckOrg/df_joint
Browse files Browse the repository at this point in the history
MERGE: added `DFJoint` class
  • Loading branch information
9and3 authored Aug 7, 2024
2 parents 17327bb + 307eaed commit b379924
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
2 changes: 1 addition & 1 deletion deps/eigen
Submodule eigen updated from 3f0665 to 0b646f
71 changes: 69 additions & 2 deletions src/gh/diffCheck/diffCheck/df_geometries.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,51 @@ def is_joint(self):
def id(self):
return self.__id

@dataclass
class DFJoint:
"""
This class represents a joint, in diffCheck, a joint is a collection of faces
For convenience, this is used only as a return type from the DFBeam class's property for retrieveing joints
"""

id: int
faces: typing.List[DFFace]

def __post_init__(self):
self.id = self.id
self.faces = self.faces or []

def __repr__(self):
return f"Joint id: {self.id}, Faces: {len(self.faces)}"

def to_brep(self):
"""
Convert the joint to a Rhino Brep object
"""
brep = rg.Brep()
for face in self.faces:
brep.Append(face.to_brep_face())
brep.Compact()
return brep

def to_mesh(self, max_edge_length):
"""
Convert the joint to a Rhino Mesh object
"""
rhino_brep_faces = [f.to_brep_face() for f in self.faces]
mesh = rg.Mesh()

new_faces = [f.DuplicateFace(True) for f in rhino_brep_faces]

for f in new_faces:
param = rg.MeshingParameters()
param.MaximumEdgeLength = max_edge_length
mesh_part = rg.Mesh.CreateFromBrep(f, param)[0]
mesh.Append(mesh_part)

mesh.Faces.ConvertQuadsToTriangles()
mesh.Compact()
return mesh

@dataclass
class DFBeam:
Expand All @@ -214,6 +259,8 @@ def __post_init__(self):
self._joint_faces = []
self._side_faces = []

self._joints = []

self.__id = uuid.uuid4().int

@classmethod
Expand Down Expand Up @@ -274,6 +321,18 @@ def joint_faces(self):
def side_faces(self):
return [face for face in self.faces if not face.is_joint]

@property
def joints(self):
joints : typing.List[DFJoint] = []
temp_faces = self.joint_faces.copy()
while len(temp_faces) > 0:
joint_id = temp_faces[0].joint_id
joint_faces = [face for face in temp_faces if face.joint_id == joint_id]
joint = DFJoint(joint_id, joint_faces)
joints.append(joint)
temp_faces = [face for face in temp_faces if face.joint_id != joint_id]
return joints


@dataclass
class DFAssembly:
Expand All @@ -288,9 +347,11 @@ def __post_init__(self):
self.beams = self.beams
self.name = self.name or "Unnamed Assembly"

self._all_jointfaces = []
self._all_sidefaces = []
self._all_jointfaces: typing.List[DFFace] = []
self._all_sidefaces: typing.List[DFFace] = []

self._all_joints: typing.List[DFJoint] = []

def __repr__(self):
return f"Assembly: {self.name}, Beams: {len(self.beams)}"

Expand Down Expand Up @@ -370,3 +431,9 @@ def all_side_faces(self):
for beam in self.beams:
self._all_sidefaces.extend(beam.side_faces)
return self._all_sidefaces

@property
def all_joints(self):
for beam in self.beams:
self._all_joints.extend(beam.joints)
return self._all_joints
Binary file added unnamed.gh
Binary file not shown.

0 comments on commit b379924

Please sign in to comment.