Skip to content

Commit

Permalink
Merge pull request #167 from compas-dev/fixes
Browse files Browse the repository at this point in the history
Fixes
  • Loading branch information
ioannaMitropoulou authored May 14, 2023
2 parents dd8a7e5 + 1191abf commit 7b04f11
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 29 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Unreleased
**Changed**

**Fixed**
* Fixed bug in sorting to vertical layers
* Fixed bug in sorting to vertical layers

**Deprecated**

Expand Down
15 changes: 7 additions & 8 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
name: compas_slicer
channels:
name compas_slicer
channels
- conda-forge

dependencies:
dependencies
- python
- pip
- compas>=1.0.0
- compas=1.0.0
- networkx
- numpy
- progressbar2>=3.53
- pyclipper>=1.2.0
- rdp>=0.8
- igl
- progressbar2=3.53
- pyclipper=1.2.0
- rdp=0.8
6 changes: 3 additions & 3 deletions examples/2_curved_slicing/ex2_curved_slicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ networkx>=2.5
numpy
progressbar2>=3.53
pyclipper>=1.2.0
rdp>=0.8
rdp>=0.8
libigl>=2.4.1
2 changes: 1 addition & 1 deletion scripts/planar_slicing_igl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
9 changes: 3 additions & 6 deletions src/compas_slicer/geometry/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/compas_slicer/parameters/defaults_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion src/compas_slicer/post_processing/simplify_paths_rdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
3 changes: 1 addition & 2 deletions src/compas_slicer/slicers/interpolation_slicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions src/compas_slicer/utilities/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 7b04f11

Please sign in to comment.