1212from compas_slicer .utilities .attributes_transfer import transfer_mesh_attributes_to_printpoints
1313from compas_slicer .visualization import should_visualize , visualize_slicer
1414
15- DATA_PATH = Path (__file__ ).parent / ' data'
15+ DATA_PATH = Path (__file__ ).parent / " data"
1616OUTPUT_PATH = slicer_utils .get_output_directory (DATA_PATH )
17- MODEL = ' distorted_v_closed_low_res.obj'
17+ MODEL = " distorted_v_closed_low_res.obj"
1818
1919
2020def main (visualize : bool = False ):
@@ -26,37 +26,37 @@ def main(visualize: bool = False):
2626 # Vertex attributes can only be entities that can be meaningfully multiplied with a float (ex. float, np.array ...)
2727
2828 # overhand attribute - Scalar value (per face)
29- mesh .update_default_face_attributes ({' overhang' : 0.0 })
29+ mesh .update_default_face_attributes ({" overhang" : 0.0 })
3030 for f_key , data in mesh .faces (data = True ):
3131 face_normal = mesh .face_normal (f_key , unitized = True )
32- data [' overhang' ] = Vector (0.0 , 0.0 , 1.0 ).dot (face_normal )
32+ data [" overhang" ] = Vector (0.0 , 0.0 , 1.0 ).dot (face_normal )
3333
3434 # face looking towards the positive y axis - Boolean value (per face)
35- mesh .update_default_face_attributes ({' positive_y_axis' : False })
35+ mesh .update_default_face_attributes ({" positive_y_axis" : False })
3636 for f_key , data in mesh .faces (data = True ):
3737 face_normal = mesh .face_normal (f_key , unitized = True )
3838 is_positive_y = Vector (0.0 , 1.0 , 0.0 ).dot (face_normal ) > 0 # boolean value
39- data [' positive_y_axis' ] = is_positive_y
39+ data [" positive_y_axis" ] = is_positive_y
4040
4141 # distance from plane - Scalar value (per vertex)
42- mesh .update_default_vertex_attributes ({' dist_from_plane' : 0.0 })
42+ mesh .update_default_vertex_attributes ({" dist_from_plane" : 0.0 })
4343 plane = (Point (0.0 , 0.0 , - 30.0 ), Vector (0.0 , 0.5 , 0.5 ))
4444 for v_key , data in mesh .vertices (data = True ):
45- v_coord = mesh .vertex_coordinates (v_key , axes = ' xyz' )
46- data [' dist_from_plane' ] = distance_point_plane (v_coord , plane )
45+ v_coord = mesh .vertex_coordinates (v_key , axes = " xyz" )
46+ data [" dist_from_plane" ] = distance_point_plane (v_coord , plane )
4747
4848 # direction towards point - Vector value (per vertex)
49- mesh .update_default_vertex_attributes ({' direction_to_pt' : 0.0 })
49+ mesh .update_default_vertex_attributes ({" direction_to_pt" : 0.0 })
5050 pt = Point (4.0 , 1.0 , 0.0 )
5151 for v_key , data in mesh .vertices (data = True ):
52- v_coord = mesh .vertex_coordinates (v_key , axes = ' xyz' )
53- data [' direction_to_pt' ] = np .array (normalize_vector (Vector .from_start_end (v_coord , pt )))
52+ v_coord = mesh .vertex_coordinates (v_key , axes = " xyz" )
53+ data [" direction_to_pt" ] = np .array (normalize_vector (Vector .from_start_end (v_coord , pt )))
5454
5555 # --------------- Slice mesh
5656 slicer = PlanarSlicer (mesh , layer_height = 5.0 )
5757 slicer .slice_model ()
5858 simplify_paths_rdp (slicer , threshold = 1.0 )
59- slicer_utils .save_to_json (slicer .to_data (), OUTPUT_PATH , ' slicer_data.json' )
59+ slicer_utils .save_to_json (slicer .to_data (), OUTPUT_PATH , " slicer_data.json" )
6060
6161 # --------------- Create printpoints
6262 print_organizer = PlanarPrintOrganizer (slicer )
@@ -67,25 +67,25 @@ def main(visualize: bool = False):
6767
6868 # --------------- Save printpoints to json (only json-serializable attributes are saved)
6969 printpoints_data = print_organizer .output_printpoints_dict ()
70- utils .save_to_json (printpoints_data , OUTPUT_PATH , ' out_printpoints.json' )
70+ utils .save_to_json (printpoints_data , OUTPUT_PATH , " out_printpoints.json" )
7171
7272 # --------------- Print the info to see the attributes of the printpoints (you can also visualize them on gh)
7373 print_organizer .printout_info ()
7474
7575 # --------------- Save printpoints attributes for visualization
76- overhangs_list = print_organizer .get_printpoints_attribute (attr_name = ' overhang' )
77- positive_y_axis_list = print_organizer .get_printpoints_attribute (attr_name = ' positive_y_axis' )
78- dist_from_plane_list = print_organizer .get_printpoints_attribute (attr_name = ' dist_from_plane' )
79- direction_to_pt_list = print_organizer .get_printpoints_attribute (attr_name = ' direction_to_pt' )
76+ overhangs_list = print_organizer .get_printpoints_attribute (attr_name = " overhang" )
77+ positive_y_axis_list = print_organizer .get_printpoints_attribute (attr_name = " positive_y_axis" )
78+ dist_from_plane_list = print_organizer .get_printpoints_attribute (attr_name = " dist_from_plane" )
79+ direction_to_pt_list = print_organizer .get_printpoints_attribute (attr_name = " direction_to_pt" )
8080
81- utils .save_to_json (overhangs_list , OUTPUT_PATH , ' overhangs_list.json' )
82- utils .save_to_json (positive_y_axis_list , OUTPUT_PATH , ' positive_y_axis_list.json' )
83- utils .save_to_json (dist_from_plane_list , OUTPUT_PATH , ' dist_from_plane_list.json' )
84- utils .save_to_json (utils .point_list_to_dict (direction_to_pt_list ), OUTPUT_PATH , ' direction_to_pt_list.json' )
81+ utils .save_to_json (overhangs_list , OUTPUT_PATH , " overhangs_list.json" )
82+ utils .save_to_json (positive_y_axis_list , OUTPUT_PATH , " positive_y_axis_list.json" )
83+ utils .save_to_json (dist_from_plane_list , OUTPUT_PATH , " dist_from_plane_list.json" )
84+ utils .save_to_json (utils .point_list_to_dict (direction_to_pt_list ), OUTPUT_PATH , " direction_to_pt_list.json" )
8585
8686 if visualize :
87- visualize_slicer (slicer , mesh )
87+ visualize_slicer (slicer , mesh , mesh_opacity = 0.6 , mesh_colorfield = "overhang" )
8888
8989
90- if __name__ == ' __main__' :
90+ if __name__ == " __main__" :
9191 main (visualize = should_visualize ())
0 commit comments