def main():
    start_time = time.time()

    # ==========================================================================
    # Load mesh
    # ==========================================================================
    compas_mesh = Mesh.from_obj(os.path.join(DATA, MODEL))

    # ==========================================================================
    # Move to origin
    # ==========================================================================
    move_mesh_to_point(compas_mesh, Point(0, 0, 0))

    # ==========================================================================
    # Slicing
    # options: 'default': Both for open and closed paths. But slow
    #          'cgal':    Very fast. Only for closed paths.
    #                     Requires additional installation (compas_cgal).
    # ==========================================================================
    slicer = PlanarSlicer(compas_mesh, slicer_type="default", layer_height=1.5)
    slicer.slice_model()

    # ==========================================================================
    # Generate brim
    # ==========================================================================
    generate_brim(slicer, layer_width=3.0, number_of_brim_paths=3)

    # ==========================================================================
    # Simplify the paths by removing points with a certain threshold
    # change the threshold value to remove more or less points
    # ==========================================================================
    simplify_paths_rdp(slicer, threshold=0.3)

    # ==========================================================================
    # Smooth the seams between layers
    # change the smooth_distance value to achieve smoother, or more abrupt seams
    # ==========================================================================
    seams_smooth(slicer, smooth_distance=10)

    # ==========================================================================
    # Prints out the info of the slicer
    # ==========================================================================
    slicer.printout_info()

    # ==========================================================================
    # Save slicer data to JSON
    # ==========================================================================
    save_to_json(slicer.to_data(), OUTPUT_DIR, 'slicer_data.json')

    # ==========================================================================
    # Initializes the PlanarPrintOrganizer and creates PrintPoints
    # ==========================================================================
    print_organizer = PlanarPrintOrganizer(slicer)
    print_organizer.create_printpoints()

    # ==========================================================================
    # Set fabrication-related parameters
    # ==========================================================================
    set_extruder_toggle(print_organizer, slicer)
    add_safety_printpoints(print_organizer, z_hop=10.0)
    set_linear_velocity(print_organizer, "constant", v=25.0)
    set_blend_radius(print_organizer, d_fillet=10.0)

    # ==========================================================================
    # Prints out the info of the PrintOrganizer
    # ==========================================================================
    slicer.printout_info()

    print_organizer.printout_info()

    # ==========================================================================
    # Converts the PrintPoints to data and saves to JSON
    # =========================================================================
    printpoints_data = print_organizer.output_printpoints_dict()
    utils.save_to_json(printpoints_data, OUTPUT_DIR, 'out_printpoints.json')

    # ==========================================================================
    # Initializes the compas_viewer and visualizes results
    # ==========================================================================
    """
Esempio n. 2
0
# Save slicer data to JSON
# ==========================================================================
save_to_json(slicer.to_data(), OUTPUT_DIR, 'slicer_data.json')

# ==========================================================================
# Initializes the PlanarPrintOrganizer and creates PrintPoints
# ==========================================================================
print_organizer = PlanarPrintOrganizer(slicer)
print_organizer.create_printpoints()

# ==========================================================================
# Set fabrication-related parameters
# ==========================================================================
set_extruder_toggle(print_organizer, slicer)
add_safety_printpoints(print_organizer, z_hop=10.0)
set_linear_velocity(print_organizer, "constant", v=25.0)
set_blend_radius(print_organizer, d_fillet=10.0)

# ==========================================================================
# Prints out the info of the PrintOrganizer
# ==========================================================================
print_organizer.printout_info()

# ==========================================================================
# Converts the PrintPoints to data and saves to JSON
# =========================================================================
printpoints_data = print_organizer.output_printpoints_dict()
utils.save_to_json(printpoints_data, OUTPUT_DIR, 'out_printpoints.json')

# ==========================================================================
# Initializes the compas_viewer and visualizes results
Esempio n. 3
0
parameters = {
    'avg_layer_height': 5.0  # controls number of curves that will be generated
}

preprocessor = CurvedSlicingPreprocessor(mesh, parameters, DATA_PATH)
preprocessor.create_compound_targets()

## --- slicing
slicer = CurvedSlicer(mesh, preprocessor, parameters)
slicer.slice_model()  # compute_norm_of_gradient contours
simplify_paths_rdp(slicer, threshold=1.0)
slicer.printout_info()
utils.save_to_json(slicer.to_data(), OUTPUT_PATH, 'curved_slicer.json')

# ### --- Print organizer
print_organizer = CurvedPrintOrganizer(slicer, parameters, DATA_PATH)
print_organizer.create_printpoints()

set_extruder_toggle(print_organizer, slicer)
add_safety_printpoints(print_organizer, z_hop=10.0)
set_linear_velocity(print_organizer, "by_layer_height")
set_blend_radius(print_organizer, d_fillet=10.0)

### --- Save printpoints dictionary to json file
printpoints_data = print_organizer.output_printpoints_dict()
utils.save_to_json(printpoints_data, OUTPUT_PATH, 'out_printpoints.json')

end_time = time.time()
print("Total elapsed time", round(end_time - start_time, 2), "seconds")