Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
101 changes: 101 additions & 0 deletions lecture_09/assignment_04/dominik_reisach/curved_slicing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import os
import numpy as np
from compas.datastructures import Mesh
import logging
import compas_slicer.utilities as utils
from compas_slicer.slicers import InterpolationSlicer
from compas_slicer.post_processing import simplify_paths_rdp
from compas_slicer.pre_processing import InterpolationSlicingPreprocessor
from compas_slicer.print_organization import set_extruder_toggle, set_linear_velocity_by_range
from compas_slicer.print_organization import add_safety_printpoints
from compas_slicer.pre_processing import create_mesh_boundary_attributes
from compas_slicer.print_organization import InterpolationPrintOrganizer
from compas_slicer.post_processing import seams_smooth
from compas_slicer.print_organization import smooth_printpoints_up_vectors, smooth_printpoints_layer_heights
from compas_slicer.post_processing import generate_brim
from compas.geometry import Vector, Point, normalize_vector
from compas_slicer.utilities.attributes_transfer import transfer_mesh_attributes_to_printpoints

from path_adjust import create_overhang_texture

logger = logging.getLogger('logger')
logging.basicConfig(format='%(levelname)s - %(message)s', level=logging.INFO)

DATA_PATH = os.path.join(os.path.dirname(__file__), 'data')
OUTPUT_PATH = utils.get_output_directory(DATA_PATH)
OBJ_INPUT_NAME = os.path.join(DATA_PATH, 'sculpture.obj')


def main():
# --- Load initial_mesh
mesh = Mesh.from_obj(os.path.join(DATA_PATH, OBJ_INPUT_NAME))

# --- Load targets (boundaries)
low_boundary_vs = utils.load_from_json(DATA_PATH, 'boundaryLOW.json')
high_boundary_vs = utils.load_from_json(DATA_PATH, 'boundaryHIGH.json')
create_mesh_boundary_attributes(mesh, low_boundary_vs, high_boundary_vs)

avg_layer_height = 10.0

parameters = {
'avg_layer_height': avg_layer_height, # controls number of curves that will be generated
'min_layer_height': 0.3,
'max_layer_height': 5.0 # 2.0,
}

# --- Create pre-processor
preprocessor = InterpolationSlicingPreprocessor(mesh, parameters, DATA_PATH)
preprocessor.create_compound_targets()

# --- slicing
slicer = InterpolationSlicer(mesh, preprocessor, parameters)
slicer.slice_model() # compute_norm_of_gradient contours
seams_smooth(slicer, smooth_distance=10)

simplify_paths_rdp(slicer, threshold=0.4)
create_overhang_texture(slicer, overhang_distance=10)
slicer.printout_info()
utils.save_to_json(slicer.to_data(), OUTPUT_PATH, 'curved_slicer.json')

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

set_linear_velocity_by_range(print_organizer, param_func=lambda ppt: ppt.layer_height,
parameter_range=[avg_layer_height*0.5, avg_layer_height*2.0],
velocity_range=[150, 70], bound_remapping=False)
set_extruder_toggle(print_organizer, slicer)
add_safety_printpoints(print_organizer, z_hop=10.0)
smooth_printpoints_up_vectors(print_organizer, strength=0.5, iterations=10)
smooth_printpoints_layer_heights(print_organizer, strength=0.5, iterations=5)


# --- Add attributes to mesh
# overhand attribute - Scalar value (per face)
# mesh.update_default_face_attributes({'overhang': 0.0})
# for f_key, data in mesh.faces(data=True):
# face_normal = mesh.face_normal(f_key, unitized=True)
# data['overhang'] = Vector(0.0, 0.0, 1.0).dot(face_normal)

# # vertex laplacian - Vector value (per vertex)
# mesh.update_default_vertex_attributes({'v_normal': 0.0})
# for v_key, data in mesh.vertices(data=True):
# n = mesh.vertex_normal(v_key)
# data['v_normal'] = Vector(*n)

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

# --- Save printpoints attributes for visualization
# overhangs_list = print_organizer.get_printpoints_attribute(attr_name='overhang')
# v_normal_list = print_organizer.get_printpoints_attribute(attr_name='v_normal')
# utils.save_to_json(overhangs_list, OUTPUT_PATH, 'overhangs_list.json')
# utils.save_to_json(utils.point_list_to_dict(v_normal_list), OUTPUT_PATH, 'v_normal_list.json')


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

if __name__ == "__main__":
main()
178 changes: 178 additions & 0 deletions lecture_09/assignment_04/dominik_reisach/data/boundaryHIGH.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
[
4488,
4489,
4490,
4491,
4492,
4493,
4494,
4495,
4496,
4497,
4498,
4499,
4500,
4501,
4502,
4503,
4504,
4505,
4506,
4507,
4508,
4509,
4510,
4511,
4512,
4513,
4514,
4515,
4516,
4517,
4518,
4519,
4520,
4521,
4522,
4523,
4524,
4525,
4526,
4527,
4528,
4529,
4530,
4531,
4532,
4533,
4534,
4535,
4536,
4537,
4538,
4539,
4540,
4541,
4542,
4543,
4544,
4545,
4546,
4547,
4548,
4549,
4550,
4551,
4552,
4553,
4554,
4555,
4556,
4557,
4558,
4559,
4560,
4561,
4562,
4563,
4564,
4565,
4566,
4567,
4568,
4569,
4570,
4571,
4572,
4573,
4574,
4575,
17864,
17868,
17871,
17874,
17877,
17880,
17883,
17886,
17889,
17892,
17895,
17898,
17901,
17904,
17907,
17910,
17913,
17916,
17919,
17922,
17925,
17928,
17931,
17934,
17937,
17940,
17943,
17946,
17949,
17952,
17955,
17958,
17961,
17964,
17967,
17970,
17973,
17976,
17979,
17982,
17985,
17988,
17991,
17994,
17997,
18000,
18003,
18006,
18009,
18012,
18015,
18018,
18021,
18024,
18027,
18030,
18033,
18036,
18039,
18042,
18045,
18048,
18051,
18054,
18057,
18060,
18063,
18066,
18069,
18072,
18075,
18078,
18081,
18084,
18087,
18090,
18093,
18096,
18099,
18102,
18105,
18108,
18111,
18114,
18117,
18120,
18123,
18126
]
Loading