Exemplo n.º 1
0
def main():
    compas_mesh = Mesh.from_obj(os.path.join(DATA, MODEL))
    move_mesh_to_point(compas_mesh, Point(0, 0, 0))

    # Slicing
    slicer = PlanarSlicer(compas_mesh, slicer_type="cgal", layer_height=5.0)
    slicer.slice_model()

    # Sorting into vertical layers and reordering
    sort_into_vertical_layers(slicer, max_paths_per_layer=10)
    reorder_vertical_layers(slicer, align_with="x_axis")

    # Post-processing
    generate_brim(slicer, layer_width=3.0, number_of_brim_offsets=5)
    simplify_paths_rdp_igl(slicer, threshold=0.7)
    seams_smooth(slicer, smooth_distance=10)
    slicer.printout_info()
    save_to_json(slicer.to_data(), OUTPUT_DIR, 'slicer_data.json')

    # PlanarPrintOrganization
    print_organizer = PlanarPrintOrganizer(slicer)
    print_organizer.create_printpoints()

    set_extruder_toggle(print_organizer, slicer)
    add_safety_printpoints(print_organizer, z_hop=10.0)
    set_linear_velocity_constant(print_organizer, v=25.0)
    set_blend_radius(print_organizer, d_fillet=10.0)

    print_organizer.printout_info()

    printpoints_data = print_organizer.output_printpoints_dict()
    utils.save_to_json(printpoints_data, OUTPUT_DIR, 'out_printpoints.json')
Exemplo n.º 2
0
def main():

    compas_mesh = Mesh.from_obj(os.path.join(DATA, MODEL))
    delta = get_param({}, key='delta',
                      defaults_type='gcode')  # boolean for delta printers
    print_volume_x = get_param({}, key='print_volume_x',
                               defaults_type='gcode')  # in mm
    print_volume_y = get_param({}, key='print_volume_y',
                               defaults_type='gcode')  # in mm
    if delta:
        move_mesh_to_point(compas_mesh, Point(0, 0, 0))
    else:
        move_mesh_to_point(compas_mesh,
                           Point(print_volume_x / 2, print_volume_y / 2, 0))

    # ----- slicing
    slicer = PlanarSlicer(compas_mesh, slicer_type="cgal", layer_height=4.5)
    slicer.slice_model()
    generate_brim(slicer, layer_width=3.0, number_of_brim_offsets=4)
    simplify_paths_rdp_igl(slicer, threshold=0.6)
    seams_smooth(slicer, smooth_distance=10)
    slicer.printout_info()
    save_to_json(slicer.to_data(), OUTPUT_DIR, 'slicer_data.json')

    # ----- print organization
    print_organizer = PlanarPrintOrganizer(slicer)
    print_organizer.create_printpoints()
    # Set fabrication-related parameters
    set_extruder_toggle(print_organizer, slicer)
    print_organizer.printout_info()

    # create and output gcode
    gcode_parameters = {}  # leave all to default
    gcode_text = print_organizer.output_gcode(gcode_parameters)
    utils.save_to_text_file(gcode_text, OUTPUT_DIR, 'my_gcode.gcode')
Exemplo n.º 3
0
def main():
    start_time = time.time()

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

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

    ### --- Slicer
    # 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="cgal", 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.7)

    ### --- 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()

    viewer = ObjectViewer()
    viewer.view.use_shaders = False
    slicer.visualize_on_viewer(viewer)

    utils.save_to_json(slicer.to_data(), OUTPUT_DIR, 'slicer_data.json')

    ### --- Fabrication - related information
    print_organizer = PrintOrganizer(slicer)
    print_organizer.create_printpoints(compas_mesh)
    print_organizer.set_extruder_toggle()
    print_organizer.add_safety_printpoints(z_hop=20)
    print_organizer.set_linear_velocity("constant", v=25)

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

    print_organizer.visualize_on_viewer(viewer, visualize_polyline=True, visualize_printpoints=False)
    viewer.update()
    viewer.show()

    end_time = time.time()
    print("Total elapsed time", round(end_time - start_time, 2), "seconds")
def create_setup(filename):
    """ Setting up the stage for testing. """
    FILE = os.path.abspath(os.path.join(DATA, filename))
    compas_mesh = Mesh.from_obj(FILE)
    slicer = PlanarSlicer(compas_mesh, slicer_type="default", layer_height=20)
    slicer.slice_model()
    generate_brim(slicer, layer_width=3.0, number_of_brim_offsets=3)
    simplify_paths_rdp(slicer, threshold=1.3)
    # seams_smooth(slicer, smooth_distance=10)
    slicer.printout_info()
    print_organizer = PlanarPrintOrganizer(slicer)
    print_organizer.create_printpoints()
    return slicer, print_organizer
Exemplo n.º 5
0
def main():
    start_time = time.time()

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

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

    ### --- Slicer
    # try out different slicers by changing the slicer_type
    # options: 'default', 'meshcut', '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 printpaths by removing points with a certain threshold
    # change the threshold value to remove more or less points
    simplify_paths_rdp(slicer, threshold=0.9)

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

    viewer = ObjectViewer()
    viewer.view.use_shaders = False
    slicer.visualize_on_viewer(viewer)

    utils.save_to_json(slicer.to_data(), OUTPUT_DIR, 'slicer_data.json')

    ### --- Fabrication - related information
    print_organizer = PrintOrganizer(slicer)
    print_organizer.create_printpoints(compas_mesh)
    print_organizer.set_extruder_toggle()
    print_organizer.add_safety_printpoints(z_hop=20)
    print_organizer.set_linear_velocity("constant", v=25)

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

    # # print_organizer.visualize_on_viewer(viewer, visualize_polyline=True, visualize_printpoints=False)
    viewer.update()
    viewer.show()

    end_time = time.time()
    print("Total elapsed time", round(end_time - start_time, 2), "seconds")
Exemplo n.º 6
0
def test_planar_slicing_success():
    """ Tests simple planar slicing. """
    slicer = PlanarSlicer(compas_mesh,
                          slicer_type="default",
                          layer_height=layer_height)
    slicer.slice_model()

    assert isinstance(slicer.layers, list), "The layers are not a list"
    print(len(slicer.layers))
    assert len(
        slicer.layers) == no_of_layers, "Wrong number of generated layers"
    assert isinstance(
        slicer.layers[0], Layer
    ), "The slicer does not contain layers of type 'compas_slicer.Layer'"
    for i in range(len(slicer.layers)):
        assert len(
            slicer.layers[i].paths
        ) == 1, "There is a layer with empty Contours list at index %d" % i
        assert isinstance(slicer.layers[i].paths[0],
                          Path), "Wrong class type in Layer.Contour list"
        assert slicer.layers[i].paths[0].is_closed, "Path resulting from slicing of cylinder using 'planar_compas' is " \
                                                    "open. It should be closed "
Exemplo n.º 7
0
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="cgal", layer_height=1.5)
    slicer.slice_model()

    # ==========================================================================
    # Generate brim / raft
    # ==========================================================================
    # NOTE: Typically you would want to use either a brim OR a raft,
    # however, in this example both are used to explain the functionality
    generate_brim(slicer, layer_width=3.0, number_of_brim_offsets=4)
    generate_raft(slicer,
                  raft_offset=20,
                  distance_between_paths=5,
                  direction="xy_diagonal",
                  raft_layers=1)

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

    # ==========================================================================
    # 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_constant(print_organizer, 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
    # ==========================================================================
    viewer = app.App(width=1600, height=1000)
    # slicer.visualize_on_viewer(viewer, visualize_mesh=False, visualize_paths=True)
    print_organizer.visualize_on_viewer(viewer, visualize_printpoints=True)
    viewer.show()

    end_time = time.time()
    print("Total elapsed time", round(end_time - start_time, 2), "seconds")
Exemplo n.º 8
0
    plane = (Point(0.0, 0.0, -30.0), Vector(0.0, 0.5, 0.5))
    for v_key, data in mesh.vertices(data=True):
        v_coord = mesh.vertex_coordinates(v_key, axes='xyz')
        data['dist_from_plane'] = distance_point_plane(v_coord, plane)

    # direction towards point - Vector value (per vertex)
    mesh.update_default_vertex_attributes({'direction_to_pt': 0.0})
    pt = Point(4.0, 1.0, 0.0)
    for v_key, data in mesh.vertices(data=True):
        v_coord = mesh.vertex_coordinates(v_key, axes='xyz')
        data['direction_to_pt'] = np.array(
            normalize_vector(Vector.from_start_end(v_coord, pt)))

    # --------------- Slice mesh
    slicer = PlanarSlicer(mesh, slicer_type="default", layer_height=5.0)
    slicer.slice_model()
    simplify_paths_rdp_igl(slicer, threshold=1.0)
    slicer_utils.save_to_json(slicer.to_data(), OUTPUT_PATH,
                              'slicer_data.json')

    # --------------- Create printpoints
    print_organizer = PlanarPrintOrganizer(slicer)
    print_organizer.create_printpoints()

    # --------------- Transfer mesh attributes to printpoints
    transfer_mesh_attributes_to_printpoints(mesh,
                                            print_organizer.printpoints_dict)

    # --------------- Save printpoints to json (only json-serializable attributes are saved)
    printpoints_data = print_organizer.output_printpoints_dict()
    utils.save_to_json(printpoints_data, OUTPUT_PATH, 'out_printpoints.json')
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
    # ==========================================================================
    """