Skip to content

Commit

Permalink
Merge pull request #147 from compas-dev/igl_functions
Browse files Browse the repository at this point in the history
Igl functions
  • Loading branch information
ioannaMitropoulou authored Jul 30, 2021
2 parents e44a382 + c1bf22d commit 2f46d42
Show file tree
Hide file tree
Showing 22 changed files with 264 additions and 129 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Unreleased

**Added**
* Documentation updates
* rdp libigl function

**Changed**

Expand Down
10 changes: 5 additions & 5 deletions docs/examples/01_planar_slicing_simple.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The first step is to import the required functions:
from compas_slicer.slicers import PlanarSlicer
from compas_slicer.post_processing import generate_brim
from compas_slicer.post_processing import generate_raft
from compas_slicer.post_processing import simplify_paths_rdp
from compas_slicer.post_processing import simplify_paths_rdp_igl
from compas_slicer.post_processing import seams_smooth
from compas_slicer.print_organization import PlanarPrintOrganizer
from compas_slicer.print_organization import set_extruder_toggle
Expand Down Expand Up @@ -106,14 +106,14 @@ that are offset from the bottom layer, to improve adhesion to the build plate
raft_layers=1)
Depending on the amount of faces that your input mesh has, a very large amount of
points can be generated. ``simplify_paths_rdp`` is a function that removes points
points can be generated. ``simplify_paths_rdp`` or ``simplify_paths_rdp_igl`` are functions that remove points
that do not have a high impact on the final shape of the polyline. Increase the
threshold value to remove more points, decrease it to remove less. For more
information on how the algorithm works see: `Ramer–Douglas–Peucker algorithm <https://en.wikipedia.org/wiki/Ramer-Douglas-Peucker_algorithm>`_

.. code-block:: python
simplify_paths_rdp(slicer, threshold=0.6)
simplify_paths_rdp_igl(slicer, threshold=0.6)
Currently the 'seam' between different layers of our shape is a 'hard seam',
the printer would move up almost vertically to move to the next layer.
Expand Down Expand Up @@ -213,7 +213,7 @@ The completed final script can be found below:
from compas_slicer.slicers import PlanarSlicer
from compas_slicer.post_processing import generate_brim
from compas_slicer.post_processing import generate_raft
from compas_slicer.post_processing import simplify_paths_rdp
from compas_slicer.post_processing import simplify_paths_rdp_igl
from compas_slicer.post_processing import seams_smooth
from compas_slicer.print_organization import PlanarPrintOrganizer
from compas_slicer.print_organization import set_extruder_toggle
Expand Down Expand Up @@ -277,7 +277,7 @@ The completed final script can be found below:
# 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.6)
simplify_paths_rdp_igl(slicer, threshold=0.6)
# ==========================================================================
# Smooth the seams between layers
Expand Down
8 changes: 4 additions & 4 deletions docs/examples/02_curved_slicing_simple.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Imports and initialization
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.post_processing import simplify_paths_rdp_igl
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
Expand Down Expand Up @@ -104,7 +104,7 @@ options are available for all slicers.
# post processing
generate_brim(slicer, layer_width=3.0, number_of_brim_offsets=5)
seams_smooth(slicer, smooth_distance=10)
simplify_paths_rdp(slicer, threshold=1.0)
simplify_paths_rdp_igl(slicer, threshold=1.0)
slicer.printout_info()
utils.save_to_json(slicer.to_data(), OUTPUT_PATH, 'curved_slicer.json')
Expand Down Expand Up @@ -166,7 +166,7 @@ The completed final script can be found below:
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.post_processing import simplify_paths_rdp_igl
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
Expand Down Expand Up @@ -217,7 +217,7 @@ The completed final script can be found below:
generate_brim(slicer, layer_width=3.0, number_of_brim_offsets=5)
seams_smooth(slicer, smooth_distance=10)
simplify_paths_rdp(slicer, threshold=1.0)
simplify_paths_rdp_igl(slicer, threshold=0.5)
slicer.printout_info()
utils.save_to_json(slicer.to_data(), OUTPUT_PATH, 'curved_slicer.json')
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/03_planar_slicing_vertical_sorting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ the default method. The example below demonstrates how planar paths can be sorte
from compas_slicer.pre_processing import move_mesh_to_point
from compas_slicer.slicers import PlanarSlicer
from compas_slicer.post_processing import generate_brim
from compas_slicer.post_processing import simplify_paths_rdp
from compas_slicer.post_processing import simplify_paths_rdp_igl
from compas_slicer.post_processing import sort_into_vertical_layers
from compas_slicer.post_processing import reorder_vertical_layers
from compas_slicer.post_processing import seams_smooth
Expand Down Expand Up @@ -69,7 +69,7 @@ the default method. The example below demonstrates how planar paths can be sorte
# Post-processing
generate_brim(slicer, layer_width=3.0, number_of_brim_offsets=5)
simplify_paths_rdp(slicer, threshold=0.7)
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')
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/04_gcode_generation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ to materialize them in a typical desktop 3D printer. The gcode generation is sti
from compas_slicer.pre_processing import move_mesh_to_point
from compas_slicer.slicers import PlanarSlicer
from compas_slicer.post_processing import generate_brim
from compas_slicer.post_processing import simplify_paths_rdp
from compas_slicer.post_processing import simplify_paths_rdp_igl
from compas_slicer.post_processing import seams_smooth
from compas_slicer.print_organization import PlanarPrintOrganizer
from compas_slicer.print_organization import set_extruder_toggle
Expand Down Expand Up @@ -49,7 +49,7 @@ to materialize them in a typical desktop 3D printer. The gcode generation is sti
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(slicer, threshold=0.6)
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')
Expand Down
5 changes: 2 additions & 3 deletions docs/examples/05_non_planar_slicing_on_custom_base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ vertex of the mesh. In this case we create a scalar field with the distance of e
from compas.datastructures import Mesh
import os
import compas_slicer.utilities as slicer_utils
from compas_slicer.post_processing import simplify_paths_rdp
from compas_slicer.post_processing import simplify_paths_rdp_igl
from compas_slicer.slicers import ScalarFieldSlicer
import compas_slicer.utilities as utils
from compas_slicer.print_organization import ScalarFieldPrintOrganizer
Expand Down Expand Up @@ -57,11 +57,10 @@ vertex of the mesh. In this case we create a scalar field with the distance of e
# --- Slice model by generating contours of scalar field
slicer = ScalarFieldSlicer(mesh, u, no_of_isocurves=50)
slicer.slice_model()
# simplify_paths_rdp(slicer, threshold=0.3)
slicer_utils.save_to_json(slicer.to_data(), OUTPUT_PATH, 'isocontours.json') # save results to json
# --- Print organization calculations (i.e. generation of printpoints with fabrication-related information)
simplify_paths_rdp(slicer, threshold=0.3)
simplify_paths_rdp_igl(slicer, threshold=0.3)
print_organizer = ScalarFieldPrintOrganizer(slicer, parameters={}, DATA_PATH=DATA_PATH)
print_organizer.create_printpoints()
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/06_attributes_transfer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ barycentric coordinates.
from compas.geometry import Point, Vector, distance_point_plane, normalize_vector
from compas.datastructures import Mesh
import compas_slicer.utilities as slicer_utils
from compas_slicer.post_processing import simplify_paths_rdp
from compas_slicer.post_processing import simplify_paths_rdp_igl
from compas_slicer.slicers import PlanarSlicer
import compas_slicer.utilities.utils as utils
from compas_slicer.utilities.attributes_transfer import transfer_mesh_attributes_to_printpoints
Expand Down Expand Up @@ -77,7 +77,7 @@ barycentric coordinates.
# --------------- Slice mesh
slicer = PlanarSlicer(mesh, slicer_type="default", layer_height=5.0)
slicer.slice_model()
simplify_paths_rdp(slicer, threshold=1.0)
simplify_paths_rdp_igl(slicer, threshold=1.0)
slicer_utils.save_to_json(slicer.to_data(), OUTPUT_PATH, 'slicer_data.json')
# --------------- Create printpoints
Expand Down
14 changes: 14 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,17 @@ Make sure you are in the correct environment and type:
.. code-block:: bash
pip install numpy==1.19.3
Fractions error
-----------
.. code-block:: bash
ImportError: cannot import name 'gcd' from 'fractions' (C:\ProgramData\Anaconda3\envs\compas_slicer\lib\fractions.py)
This issue can be solved, as explained here: https://stackoverflow.com/questions/66174862/import-error-cant-import-name-gcd-from-fractions
by typing the following command (make sure you are in the correct environment)

.. code-block:: bash
conda install -c conda-forge networkx=2.5
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from compas_slicer.slicers import PlanarSlicer
from compas_slicer.post_processing import generate_brim
from compas_slicer.post_processing import generate_raft
from compas_slicer.post_processing import simplify_paths_rdp
from compas_slicer.post_processing import simplify_paths_rdp_igl
from compas_slicer.post_processing import seams_smooth
from compas_slicer.print_organization import PlanarPrintOrganizer
from compas_slicer.print_organization import set_extruder_toggle
Expand Down Expand Up @@ -72,7 +72,7 @@ def main():
# 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.6)
simplify_paths_rdp_igl(slicer, threshold=0.6)

# ==========================================================================
# Smooth the seams between layers
Expand Down
4 changes: 2 additions & 2 deletions examples/2_curved_slicing/ex2_curved_slicing_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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.post_processing import simplify_paths_rdp_igl
from compas_slicer.pre_processing import InterpolationSlicingPreprocessor
from compas_slicer.pre_processing import create_mesh_boundary_attributes
from compas_slicer.print_organization import InterpolationPrintOrganizer
Expand Down Expand Up @@ -86,7 +86,7 @@ def main():
generate_brim(slicer, layer_width=3.0, number_of_brim_offsets=5)

seams_smooth(slicer, smooth_distance=0.1)
simplify_paths_rdp(slicer, threshold=0.25)
simplify_paths_rdp_igl(slicer, threshold=0.25)
utils.save_to_json(slicer.to_data(), OUTPUT_PATH, 'curved_slicer_%d.json' % i)
slicers.append(slicer)

Expand Down
4 changes: 2 additions & 2 deletions examples/2_curved_slicing/ex2_curved_slicing_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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.post_processing import simplify_paths_rdp_igl
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
Expand Down Expand Up @@ -55,7 +55,7 @@ def main():
generate_brim(slicer, layer_width=3.0, number_of_brim_offsets=5)
seams_smooth(slicer, smooth_distance=10)

simplify_paths_rdp(slicer, threshold=1.0)
simplify_paths_rdp_igl(slicer, threshold=0.5)
slicer.printout_info()
utils.save_to_json(slicer.to_data(), OUTPUT_PATH, 'curved_slicer.json')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from compas_slicer.pre_processing import move_mesh_to_point
from compas_slicer.slicers import PlanarSlicer
from compas_slicer.post_processing import generate_brim
from compas_slicer.post_processing import simplify_paths_rdp
from compas_slicer.post_processing import simplify_paths_rdp_igl
from compas_slicer.post_processing import sort_into_vertical_layers
from compas_slicer.post_processing import reorder_vertical_layers
from compas_slicer.post_processing import seams_smooth
Expand Down Expand Up @@ -46,7 +46,7 @@ def main():

# Post-processing
generate_brim(slicer, layer_width=3.0, number_of_brim_offsets=5)
simplify_paths_rdp(slicer, threshold=0.7)
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')
Expand Down
4 changes: 2 additions & 2 deletions examples/4_gcode_generation/example_4_gcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from compas_slicer.pre_processing import move_mesh_to_point
from compas_slicer.slicers import PlanarSlicer
from compas_slicer.post_processing import generate_brim
from compas_slicer.post_processing import simplify_paths_rdp
from compas_slicer.post_processing import simplify_paths_rdp_igl
from compas_slicer.post_processing import seams_smooth
from compas_slicer.print_organization import PlanarPrintOrganizer
from compas_slicer.print_organization import set_extruder_toggle
Expand Down Expand Up @@ -37,7 +37,7 @@ def main():
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(slicer, threshold=0.6)
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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from compas.datastructures import Mesh
import os
import compas_slicer.utilities as slicer_utils
from compas_slicer.post_processing import simplify_paths_rdp
from compas_slicer.post_processing import simplify_paths_rdp_igl
from compas_slicer.slicers import ScalarFieldSlicer
import compas_slicer.utilities as utils
from compas_slicer.print_organization import ScalarFieldPrintOrganizer
Expand Down Expand Up @@ -42,7 +42,7 @@
slicer_utils.save_to_json(slicer.to_data(), OUTPUT_PATH, 'isocontours.json') # save results to json

# --- Print organization calculations (i.e. generation of printpoints with fabrication-related information)
simplify_paths_rdp(slicer, threshold=0.3)
simplify_paths_rdp_igl(slicer, threshold=0.3)
print_organizer = ScalarFieldPrintOrganizer(slicer, parameters={}, DATA_PATH=DATA_PATH)
print_organizer.create_printpoints()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from compas.geometry import Point, Vector, distance_point_plane, normalize_vector
from compas.datastructures import Mesh
import compas_slicer.utilities as slicer_utils
from compas_slicer.post_processing import simplify_paths_rdp
from compas_slicer.post_processing import simplify_paths_rdp_igl
from compas_slicer.slicers import PlanarSlicer
import compas_slicer.utilities.utils as utils
from compas_slicer.utilities.attributes_transfer import transfer_mesh_attributes_to_printpoints
Expand Down Expand Up @@ -55,7 +55,7 @@
# --------------- Slice mesh
slicer = PlanarSlicer(mesh, slicer_type="default", layer_height=5.0)
slicer.slice_model()
simplify_paths_rdp(slicer, threshold=1.0)
simplify_paths_rdp_igl(slicer, threshold=1.0)
slicer_utils.save_to_json(slicer.to_data(), OUTPUT_PATH, 'slicer_data.json')

# --------------- Create printpoints
Expand Down
Loading

0 comments on commit 2f46d42

Please sign in to comment.