Skip to content

Commit

Permalink
CLEANUP
Browse files Browse the repository at this point in the history
  • Loading branch information
petrasvestartas committed Oct 25, 2024
1 parent bb30394 commit 5eb30a9
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ def shift_left(lst, n):
points.append(points[0])
return Polyline(points)

######################################################################################
# Read polylines from an exrernal file, in this case compas_wood xml dataset.
######################################################################################
xml_polylines = read_xml_polylines(
foldername= str(Path.cwd() / "src/compas_wood/datasets/") + '/',
filename='type_plates_name_side_to_side_edge_inplane_hilti_square_shell',
Expand All @@ -139,137 +141,84 @@ def shift_left(lst, n):

xml_polylines.reverse()

######################################################################################
# Create joints.
######################################################################################
wood_globals.face_to_face_side_to_side_joints_rotated_joint_as_average = False
wood_globals.face_to_face_side_to_side_joints_all_treated_as_rotated = False
new_polyline_lists = []

polylines_lists, output_types = get_connection_zones(
polylines_lists, output_types, polylines_lists_cleaned = get_connection_zones(
input_polyline_pairs=xml_polylines,
input_joint_parameters_and_types=[1500, 1.0, 6],
input_output_type=4)
input_output_type=4,
remove_duplicate_polylines = True)


# Remove duplicate polylines - bug in the code.
wood_globals.face_to_face_side_to_side_joints_rotated_joint_as_average = True
wood_globals.face_to_face_side_to_side_joints_all_treated_as_rotated = True

for polylines in polylines_lists:
new_polylines = []
for polyline in polylines:
if polyline not in new_polylines:
new_polylines.append(polyline)
new_polyline_lists.append(new_polylines)
polylines_lists = new_polyline_lists

# wood_globals.face_to_face_side_to_side_joints_rotated_joint_as_average = True
# wood_globals.face_to_face_side_to_side_joints_all_treated_as_rotated = True

# polylines_lists, output_types = get_connection_zones(
# input_polyline_pairs=xml_polylines,
# input_joint_parameters_and_types=[1500, 1.0, 53],
# input_output_type=3)
polylines_lists_connectors, output_types_connectors, polylines_lists_connector_cleaned = get_connection_zones(
input_polyline_pairs=xml_polylines,
input_joint_parameters_and_types=[1500, 1.0, 53],
input_output_type=3,
remove_duplicate_polylines = True)

######################################################################################
# Cut Polylines with planes.
######################################################################################

# Remove duplicate polylines - bug in the code.

# for polylines in polylines_lists:
# new_polylines = []
# for polyline in polylines:
# if polyline not in new_polylines:
# new_polylines.append(polyline)
# if len(new_polylines) == 2:
# new_polyline_lists.append(list(new_polylines))
# new_polylines.clear()

# split new_polylines into two polylines
geometry = []
polylines_lists = new_polyline_lists

def cut_polygons_with_planes(polygons, planes, geometry):
def cut_polygons_with_planes(polylines_lists, indices, planes_lists, geometry):
cut_polygons = []
for i, polygon in enumerate(polygons):
cut_polygon = None
for plane in planes[i]:
cut_polygon = cut_polygon_with_plane(polygon, plane)
if cut_polygon:
if len(cut_polygon) > 2:
cut_polygons.append(cut_polygon)
geometry.extend(cut_polygons)
for index in range(len(indices)):
polygons = [polylines_lists[indices[index]][0],polylines_lists[indices[index]][1]]
planes = planes_lists[index]

for polygon in polygons:
cut_polygon = polygon.copy()
for plane in planes:
cut_polygon = cut_polygon_with_plane(cut_polygon, plane)
if cut_polygon:
if len(cut_polygon) > 2:
geometry.append(cut_polygon)
return cut_polygons


polygons = [
polylines_lists[0][0],
polylines_lists[0][1],
polylines_lists[0][0],
]
indices = [0, 0]

planes = [
[Plane(Point(3505,4000,10), [1, 0, 0])],
[Plane(Point(3505,4000,10), [1, 0, 0])],
[Plane(Point(3505,4000,10), [-1, 0, 0]), Plane(Point(3205,4000,10), [1, 0, 0]) ]
]
cut_polygons_with_planes(polygons, planes, geometry)

print(geometry)




# plane = Plane(Point(3505,4000,10), [-1, 0, 0])
# geometry.append(cut_polygon_with_plane(polylines_lists[0][0], plane))
# geometry.append(cut_polygon_with_plane(polylines_lists[0][1], plane))
cut_polygons_with_planes(polylines_lists_cleaned, indices, planes, geometry)
geometry.append(polylines_lists_cleaned) # Add the original polylines to the geometry

######################################################################################
# Mesh Polylines.
######################################################################################


# meshes = []


# for plines in polylines_lists:
# mesh = closed_mesh_from_polylines(plines)
# meshes.append(mesh)


# Create meshes.
# meshes = mesh_boolean_difference_from_polylines(polylines_lists)

# # Serialize meshes.
# json_dump(meshes, 'data/json_dump/type_plates_name_side_to_side_edge_inplane_hilti_part6.json')
######################################################################################
# Serialize
######################################################################################

# Vizualize.
# json_dump(meshes, 'data/json_dump/type_plates_name_side_to_side_edge_inplane_hilti_part6.json')

try:
pass

# flatten all the geometry

######################################################################################
# Vizualize
######################################################################################

geometry.append(polylines_lists)
add_geometry(geometry)
add_geometry(geometry)
run()


# run()
# print(polylines_lists[0])

# from compas_viewer import Viewer
# from compas.geometry import Scale

# viewer = Viewer(show_grid=False, rendermode='ghosted')
# scale = 1e-2

# for i, polylines in enumerate(polylines_lists):
# # if(i == 1):
# for polyline in polylines:
# polyline.transform(Scale.from_factors([scale, scale, scale]))
# viewer.scene.add(polyline, show_points=False, line_width=2, linecolor=(255, 0, 100))
# # break

# # print(meshes[0])
# for i, mesh in enumerate(meshes):
# mesh.transform(Scale.from_factors([scale, scale, scale]))
# viewer.scene.add(mesh, show_points=False, hide_coplanaredges=True, lineswidth=2, linecolor=(0, 0, 0))
# viewer.show()

except ImportError:
print("compas_viewer is not installed.")


21 changes: 19 additions & 2 deletions src/compas_wood/binding/binding_get_connection_zones.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def get_connection_zones(
input_joint_volume_parameters=[0, 0, 0],
input_custom_joints=[],
input_custom_joints_types=[],
remove_duplicate_polylines=False,
):
"""
Get connection zones for the given input parameters.
Expand Down Expand Up @@ -57,7 +58,9 @@ def get_connection_zones(
Custom joints.
input_custom_joints_types : list[int], optional
Custom joints types.
input_face_to_face_side_to_side_joints_rotated_joint_as_average : bool, optional
remove_duplicate_polylines : bool, optional
Remove duplicate polylines.
Returns
-------
Expand Down Expand Up @@ -92,4 +95,18 @@ def get_connection_zones(
to_double1(input_joint_volume_parameters),
)

return from_point3(w_output_plines), from_cut_type2(w_output_types)
polylines_lists = from_point3(w_output_plines)
output_types = list(w_output_types)

new_polyline_lists = []
if remove_duplicate_polylines:
for polylines in polylines_lists:
new_polylines = []
for polyline in polylines:
if polyline not in new_polylines:
new_polylines.append(polyline)
if len(new_polylines) == 2:
new_polyline_lists.append(list(new_polylines))
new_polylines.clear()

return polylines_lists, output_types, new_polyline_lists

0 comments on commit 5eb30a9

Please sign in to comment.