From fb2ff7757f79c24891a7244ad2f676749803508c Mon Sep 17 00:00:00 2001 From: Ioanna Mitropoulou Date: Sat, 18 Feb 2023 09:51:25 +0100 Subject: [PATCH 1/5] Updates for michigan workshop example --- src/compas_slicer/geometry/layer.py | 9 +++------ src/compas_slicer/parameters/defaults_layers.py | 2 +- .../preprocessing_utils/topological_sorting.py | 3 +++ .../print_organization/interpolation_print_organizer.py | 2 +- src/compas_slicer/slicers/interpolation_slicer.py | 3 +-- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/compas_slicer/geometry/layer.py b/src/compas_slicer/geometry/layer.py index 6c965e10..f1d932dd 100644 --- a/src/compas_slicer/geometry/layer.py +++ b/src/compas_slicer/geometry/layer.py @@ -192,17 +192,13 @@ class VerticalLayersManager: Attributes ---------- - threshold_max_centroid_dist: - float. The maximum get_distance that the centroids of two successive paths can have to belong in the same - VerticalLayer. max_paths_per_layer: int Maximum number of layers that a vertical layer can consist of. If None, then the vertical layer has an unlimited number of layers. """ - def __init__(self, threshold_max_centroid_dist, avg_layer_height, max_paths_per_layer=None): + def __init__(self, avg_layer_height, max_paths_per_layer=None): self.layers = [VerticalLayer(id=0)] # vertical_layers_print_data that contain isocurves (compas_slicer.Path) - self.threshold_max_centroid_dist = threshold_max_centroid_dist self.avg_layer_height = avg_layer_height self.max_paths_per_layer = max_paths_per_layer @@ -218,7 +214,8 @@ def add(self, path): other_centroids = get_vertical_layers_centroids_list(self.layers) candidate_layer = self.layers[utils.get_closest_pt_index(centroid, other_centroids)] - if np.linalg.norm(candidate_layer.head_centroid - centroid) < self.threshold_max_centroid_dist: + threshold_max_centroid_dist = 5 * self.avg_layer_height + if np.linalg.norm(candidate_layer.head_centroid - centroid) < threshold_max_centroid_dist: if self.max_paths_per_layer: if len(candidate_layer.paths) < self.max_paths_per_layer: selected_layer = candidate_layer diff --git a/src/compas_slicer/parameters/defaults_layers.py b/src/compas_slicer/parameters/defaults_layers.py index 37bbf5b9..3fe90ca0 100644 --- a/src/compas_slicer/parameters/defaults_layers.py +++ b/src/compas_slicer/parameters/defaults_layers.py @@ -15,5 +15,5 @@ def layers_default_param(key): 'avg_layer_height': 5.0, 'max_layer_height': 50.0, 'min_layer_height': 0.1, - 'vertical_layers_max_centroid_dist': 25.0 + # 'vertical_layers_max_centroid_dist': 25.0 } diff --git a/src/compas_slicer/pre_processing/preprocessing_utils/topological_sorting.py b/src/compas_slicer/pre_processing/preprocessing_utils/topological_sorting.py index fc2d144d..ea1d8c0b 100644 --- a/src/compas_slicer/pre_processing/preprocessing_utils/topological_sorting.py +++ b/src/compas_slicer/pre_processing/preprocessing_utils/topological_sorting.py @@ -307,10 +307,13 @@ def get_children_of_node(self, root): children = [] root_segment = self.segments[root] root_last_crv_pts = root_segment.paths[-1].points + # utils.save_to_json(utils.point_list_to_dict(root_last_crv_pts), self.OUTPUT_PATH, "root_last_crv_pts.json") for i, segment in enumerate(self.segments): if i != root: segment_first_curve_pts = segment.paths[0].points + # utils.save_to_json(utils.point_list_to_dict(segment_first_curve_pts), self.OUTPUT_PATH, + # "segment_first_curve_pts.json") if are_neighboring_point_clouds(root_last_crv_pts, segment_first_curve_pts, self.max_d_threshold): children.append(i) return children, [None for _ in children] # None because this graph doesn't have cut ids diff --git a/src/compas_slicer/print_organization/interpolation_print_organizer.py b/src/compas_slicer/print_organization/interpolation_print_organizer.py index 3ced988e..ccea0026 100644 --- a/src/compas_slicer/print_organization/interpolation_print_organizer.py +++ b/src/compas_slicer/print_organization/interpolation_print_organizer.py @@ -59,7 +59,7 @@ def topological_sorting(self): other parts it lies on, and which other parts lie on it.""" avg_layer_height = get_param(self.parameters, key='avg_layer_height', defaults_type='layers') self.topo_sort_graph = topo_sort.SegmentsDirectedGraph(self.slicer.mesh, self.vertical_layers, - 10 * avg_layer_height, DATA_PATH=self.DATA_PATH) + 4 * avg_layer_height, DATA_PATH=self.DATA_PATH) def create_base_boundaries(self): """ Creates one BaseBoundary per vertical_layer.""" diff --git a/src/compas_slicer/slicers/interpolation_slicer.py b/src/compas_slicer/slicers/interpolation_slicer.py index b8411d6b..0f48f79a 100644 --- a/src/compas_slicer/slicers/interpolation_slicer.py +++ b/src/compas_slicer/slicers/interpolation_slicer.py @@ -46,8 +46,7 @@ def generate_paths(self): params_list = get_interpolation_parameters_list(n) logger.info('%d paths will be generated' % n) - max_dist = get_param(self.parameters, key='vertical_layers_max_centroid_dist', defaults_type='layers') - vertical_layers_manager = VerticalLayersManager(max_dist, avg_layer_height) + vertical_layers_manager = VerticalLayersManager(avg_layer_height) # create paths + layers with progressbar.ProgressBar(max_value=len(params_list)) as bar: From b77f7c7c73627fe732c0aee07416881d645dbdf4 Mon Sep 17 00:00:00 2001 From: Ioanna Mitropoulou Date: Sat, 18 Feb 2023 09:56:22 +0100 Subject: [PATCH 2/5] Removed checks if igl is installed --- scripts/planar_slicing_igl.py | 2 +- src/compas_slicer/post_processing/simplify_paths_rdp.py | 2 +- .../pre_processing/preprocessing_utils/geodesics.py | 4 ++-- src/compas_slicer/utilities/utils.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/planar_slicing_igl.py b/scripts/planar_slicing_igl.py index 50a8fa4e..884db952 100644 --- a/scripts/planar_slicing_igl.py +++ b/scripts/planar_slicing_igl.py @@ -36,7 +36,7 @@ def create_planar_paths_igl(mesh, n): The mesh to be sliced n: number of contours """ - utils.check_package_is_installed('igl') + # utils.check_package_is_installed('igl') import igl v, f = mesh.to_vertices_and_faces() diff --git a/src/compas_slicer/post_processing/simplify_paths_rdp.py b/src/compas_slicer/post_processing/simplify_paths_rdp.py index 8d3937af..e2511ef4 100644 --- a/src/compas_slicer/post_processing/simplify_paths_rdp.py +++ b/src/compas_slicer/post_processing/simplify_paths_rdp.py @@ -55,7 +55,7 @@ def simplify_paths_rdp_igl(slicer, threshold): Low threshold removes few points, high threshold removes many points. """ try: - utils.check_package_is_installed('igl') + # utils.check_package_is_installed('igl') logger.info("Paths simplification rdp - igl") remaining_pts_num = 0 diff --git a/src/compas_slicer/pre_processing/preprocessing_utils/geodesics.py b/src/compas_slicer/pre_processing/preprocessing_utils/geodesics.py index 18d553e9..d7c23d5f 100644 --- a/src/compas_slicer/pre_processing/preprocessing_utils/geodesics.py +++ b/src/compas_slicer/pre_processing/preprocessing_utils/geodesics.py @@ -21,7 +21,7 @@ def get_igl_EXACT_geodesic_distances(mesh, vertices_start): mesh: :class: 'compas.datastructures.Mesh' vertices_start: list, int """ - utils.check_package_is_installed('igl') + # utils.check_package_is_installed('igl') import igl v, f = mesh.to_vertices_and_faces() @@ -61,7 +61,7 @@ class GeodesicsSolver: """ def __init__(self, mesh, OUTPUT_PATH): - utils.check_package_is_installed('igl') + # utils.check_package_is_installed('igl') import igl logger.info('GeodesicsSolver') diff --git a/src/compas_slicer/utilities/utils.py b/src/compas_slicer/utilities/utils.py index eaf8a9b0..09ee04f8 100644 --- a/src/compas_slicer/utilities/utils.py +++ b/src/compas_slicer/utilities/utils.py @@ -402,7 +402,7 @@ def get_mesh_cotmatrix_igl(mesh, fix_boundaries=True): :class: 'scipy.sparse.csr_matrix' sparse matrix (dimensions: #V x #V), laplace operator, each row i corresponding to v(i, :) """ - check_package_is_installed('igl') + # check_package_is_installed('igl') import igl v, f = mesh.to_vertices_and_faces() C = igl.cotmatrix(np.array(v), np.array(f)) @@ -431,7 +431,7 @@ def get_mesh_cotans_igl(mesh): :class: 'np.array' Dimensions: F by 3 list of 1/2*cotangents corresponding angles """ - check_package_is_installed('igl') + # check_package_is_installed('igl') import igl v, f = mesh.to_vertices_and_faces() return igl.cotmatrix_entries(np.array(v), np.array(f)) From cfc49345ec3d665497ab3321564d32e70a85a0de Mon Sep 17 00:00:00 2001 From: Ioanna Mitropoulou Date: Sun, 14 May 2023 20:06:39 +0200 Subject: [PATCH 3/5] Removed environment.yml --- environment.yml | 14 -------------- examples/2_curved_slicing/ex2_curved_slicing.py | 6 +++--- requirements.txt | 3 ++- 3 files changed, 5 insertions(+), 18 deletions(-) delete mode 100644 environment.yml diff --git a/environment.yml b/environment.yml deleted file mode 100644 index 03a75a78..00000000 --- a/environment.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: compas_slicer -channels: - - conda-forge - -dependencies: - - python - - pip - - compas>=1.0.0 - - networkx - - numpy - - progressbar2>=3.53 - - pyclipper>=1.2.0 - - rdp>=0.8 - - igl diff --git a/examples/2_curved_slicing/ex2_curved_slicing.py b/examples/2_curved_slicing/ex2_curved_slicing.py index bf959be7..f8fcba46 100644 --- a/examples/2_curved_slicing/ex2_curved_slicing.py +++ b/examples/2_curved_slicing/ex2_curved_slicing.py @@ -33,7 +33,7 @@ def main(): 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 = 3.0 + avg_layer_height = 2.0 parameters = { 'avg_layer_height': avg_layer_height, # controls number of curves that will be generated @@ -50,8 +50,8 @@ def main(): slicer = InterpolationSlicer(mesh, preprocessor, parameters) slicer.slice_model() # compute_norm_of_gradient contours - simplify_paths_rdp_igl(slicer, threshold=0.5) - seams_smooth(slicer, smooth_distance=4) + simplify_paths_rdp_igl(slicer, threshold=0.25) + seams_smooth(slicer, smooth_distance=3) slicer.printout_info() utils.save_to_json(slicer.to_data(), OUTPUT_PATH, 'curved_slicer.json') diff --git a/requirements.txt b/requirements.txt index 5c5a74c8..22607f11 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ networkx>=2.5 numpy progressbar2>=3.53 pyclipper>=1.2.0 -rdp>=0.8 \ No newline at end of file +rdp>=0.8 +libigl>=2.4.1 \ No newline at end of file From c8fe02c45ef05905b988d4ce4721770af765bf19 Mon Sep 17 00:00:00 2001 From: ioannam Date: Sun, 14 May 2023 20:13:47 +0200 Subject: [PATCH 4/5] Brought back environment.yml --- CHANGELOG.rst | 2 +- environment.yml | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 environment.yml diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 39874e9a..1af1623a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -15,7 +15,7 @@ Unreleased **Changed** **Fixed** -* Fixed bug in sorting to vertical layers +* Fixed bug in sorting to vertical layers **Deprecated** diff --git a/environment.yml b/environment.yml new file mode 100644 index 00000000..03c38fc2 --- /dev/null +++ b/environment.yml @@ -0,0 +1,14 @@ +name compas_slicer +channels + - conda-forge + +dependencies + - python + - pip + - compas=1.0.0 + - networkx + - numpy + - progressbar2=3.53 + - pyclipper=1.2.0 + - rdp=0.8 + - igl \ No newline at end of file From 1191abf3ef937a2ec191fed40914bb8d14f7f313 Mon Sep 17 00:00:00 2001 From: ioannam Date: Sun, 14 May 2023 20:16:24 +0200 Subject: [PATCH 5/5] Removed igl from env --- environment.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/environment.yml b/environment.yml index 03c38fc2..f5baf1b0 100644 --- a/environment.yml +++ b/environment.yml @@ -10,5 +10,4 @@ dependencies - numpy - progressbar2=3.53 - pyclipper=1.2.0 - - rdp=0.8 - - igl \ No newline at end of file + - rdp=0.8 \ No newline at end of file