Skip to content

Commit 62d0925

Browse files
committed
cleaned before tag
1 parent 072f48d commit 62d0925

13 files changed

+145
-101
lines changed

.github/workflows/github-actions.yml

+41-9
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,29 @@ on:
88
- main
99
- 'releases/**'
1010
jobs:
11-
build:
11+
ruff-lint:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Set up Python
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: '3.10'
19+
- name: Install dependencies
20+
run: |
21+
python -m pip install --upgrade pip
22+
pip install -r requirements.txt
23+
- name: Lint with Ruff
24+
run: |
25+
pip install ruff
26+
ruff --format=github --target-version=py37 .
27+
continue-on-error: true
28+
29+
pytest:
1230
runs-on: ubuntu-latest
1331
strategy:
1432
matrix:
1533
python-version: ["3.9", "3.10"]
16-
1734
steps:
1835
- uses: actions/checkout@v3
1936
- name: Set up Python ${{ matrix.python-version }}
@@ -25,15 +42,30 @@ jobs:
2542
python -m pip install --upgrade pip
2643
pip install -r requirements-dev.txt
2744
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
28-
- name: Lint with flake8
45+
46+
- name: Test coverage pytest
2947
run: |
30-
# stop the build if there are Python syntax errors or undefined names
31-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
32-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
33-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
48+
pytest --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
49+
continue-on-error: true
50+
3451
- name: Test with pytest
3552
run: |
3653
pytest
37-
- name: Test coverage pytest
54+
55+
build-package:
56+
runs-on: ubuntu-latest
57+
strategy:
58+
matrix:
59+
python-version: ["3.9", "3.10"]
60+
steps:
61+
- uses: actions/checkout@v3
62+
- name: Set up Python ${{ matrix.python-version }}
63+
uses: actions/setup-python@v4
64+
with:
65+
python-version: ${{ matrix.python-version }}
66+
- name: Install dependencies
3867
run: |
39-
pytest --junitxml=junit/test-results.xml --cov=com --cov-report=xml --cov-report=html
68+
python -m pip install --upgrade pip
69+
pip install build
70+
- name: Build package
71+
run: python -m build

docs/source/conf.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
# Add any Sphinx extension module names here, as strings. They can be
3232
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3333
# ones.
34+
import sphinx_rtd_theme
35+
36+
import irregular_object_packing
37+
3438
extensions = [
3539
"sphinx.ext.autodoc",
3640
"sphinx.ext.autosummary",
@@ -75,7 +79,6 @@
7579
# |version| and |release|, also used in various other places throughout the
7680
# built documents.
7781
#
78-
import irregular_object_packing
7982

8083
# The short X.Y version.
8184
version = irregular_object_packing.__version__
@@ -107,7 +110,6 @@
107110
# a list of builtin themes.
108111
#
109112
html_theme = "sphinx_rtd_theme"
110-
import sphinx_rtd_theme
111113

112114
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
113115

irregular_object_packing/packing/chordal_axis_transform.py

+4
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,10 @@ def main():
495495
plotter.add_arrows(np.array(centerpoints), np.array(normal), mag=0.5, color="y")
496496

497497
plotter.add_mesh(cat_boxes[box_idx], show_edges=True, color="r", opacity=0.7)
498+
for i in range(len(boxes)):
499+
if i != box_idx:
500+
plotter.add_mesh(cat_boxes[i], show_edges=True, color="yellow", opacity=0.3)
501+
498502
# plotter.add_mesh(cat_boxes[1], show_edges=True, color="orange", opacity=0.5)
499503
plot_boxes = [box1, box2, box3, box4]
500504
for box in plot_boxes:

irregular_object_packing/packing/growth_based_optimisation.py

+72-77
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
# %%
22
from dataclasses import dataclass
3-
from importlib import reload
4-
from time import sleep, time
3+
from time import sleep
54

6-
import matplotlib.pyplot as plt
75
import numpy as np
86
import pandas as pd
97
import pyvista as pv
108
import trimesh
11-
from IPython.display import HTML, display
129
from pyvista import PolyData
1310
from scipy.optimize import minimize
1411
from tqdm.auto import tqdm
1512

16-
import irregular_object_packing.packing.plots as plots
1713
from irregular_object_packing.mesh.collision import (
1814
compute_all_collisions,
1915
compute_container_violations,
@@ -37,7 +33,6 @@
3733
IterationData,
3834
OptimizerData,
3935
)
40-
from irregular_object_packing.tools.profile import pprofile
4136

4237
# pv.set_jupyter_backend("panel")
4338
LOG_LVL_ERROR = 0
@@ -453,105 +448,105 @@ def simple_shapes_setup() -> "Optimizer":
453448
# optimizer.setup()s
454449
# %%
455450

451+
# # # %%
452+
# # optimizer = Optimizer.simple_shapes_setup()
453+
# optimizer = Optimizer.default_setup()
454+
# optimizer.setup()
456455
# # %%
457-
# optimizer = Optimizer.simple_shapes_setup()
458-
optimizer = Optimizer.default_setup()
459-
optimizer.setup()
460-
# %%
461-
optimizer.run()
456+
# optimizer.run()
462457

463-
# %%
458+
# # %%
464459

465-
reload(plots)
466-
save_path = f"../dump/collisions_{time()}"
467-
plots.generate_gif(optimizer , save_path + ".gif")
468-
# %%
460+
# reload(plots)
461+
# save_path = f"../dump/scale_fix_{time()}"
462+
# plots.generate_gif(optimizer , save_path + ".gif")
463+
# # %%
469464

470-
display(HTML(f'<img src="{save_path}.gif"/>'))
465+
# display(HTML(f'<img src="{save_path}.gif"/>'))
471466

472-
# %%
467+
# # %%
473468

474-
reload(plots)
469+
# reload(plots)
475470

476471

477-
def plot_step(optimizer, step):
478-
plotter = pv.Plotter()
479-
meshes, cat_meshes, container = optimizer.recreate_scene(step)
480-
plots.plot_simulation_scene(plotter, meshes, cat_meshes, container, c_kwargs={"show_edges": True, "edge_color": "purple"})
481-
plotter.add_text(optimizer.status(step).table_str, position="upper_left")
472+
# def plot_step(optimizer, step):
473+
# plotter = pv.Plotter()
474+
# meshes, cat_meshes, container = optimizer.recreate_scene(step)
475+
# plots.plot_simulation_scene(plotter, meshes, cat_meshes, container, c_kwargs={"show_edges": True, "edge_color": "purple"})
476+
# plotter.add_text(optimizer.status(step).table_str, position="upper_left")
482477

483-
plotter.show()
484-
return plotter
478+
# plotter.show()
479+
# return plotter
485480

486481

487-
plot_step(optimizer, 33)
482+
# plot_step(optimizer, 33)
488483

489484

490-
# %%
491-
obj_i, step = 6, 31
492-
meshes_before, meshes_after, cat_meshes, container = optimizer.recreate_scene(step)
493-
# plots.plot_step_comparison(
494-
# optimizer.mesh_before,
495-
# optimizer.mesh_after(step, obj_i),
496-
# optimizer.cat_mesh(step, obj_i),
497-
# # other_meshes=optimizer.violating_meshes(step),
485+
# # %%
486+
# obj_i, step = 6, 31
487+
# meshes_before, meshes_after, cat_meshes, container = optimizer.recreate_scene(step)
488+
# # plots.plot_step_comparison(
489+
# # optimizer.mesh_before,
490+
# # optimizer.mesh_after(step, obj_i),
491+
# # optimizer.cat_mesh(step, obj_i),
492+
# # # other_meshes=optimizer.violating_meshes(step),
493+
# # )
494+
# # %%
495+
# reload(plots)
496+
# obj_i = 6
497+
# plotter = plots.plot_step_single(
498+
# meshes_before[obj_i], cat_meshes[obj_i], container=container, cat_opacity=0.7, mesh_opacity=1 , clipped=True, title="cat overlap",
499+
# c_kwargs={"show_edges": True, "edge_color": "purple", "show_vertices": True, "point_size": 10},
500+
# m_kwargs={"show_edges": True, "show_vertices": True, "point_size": 10, },
501+
# cat_kwargs={"show_edges": True, "show_vertices": True, "point_size": 5, },
498502
# )
499-
# %%
500-
reload(plots)
501-
obj_i = 6
502-
plotter = plots.plot_step_single(
503-
meshes_before[obj_i], cat_meshes[obj_i], container=container, cat_opacity=0.7, mesh_opacity=1 , clipped=True, title="cat overlap",
504-
c_kwargs={"show_edges": True, "edge_color": "purple", "show_vertices": True, "point_size": 10},
505-
m_kwargs={"show_edges": True, "show_vertices": True, "point_size": 10, },
506-
cat_kwargs={"show_edges": True, "show_vertices": True, "point_size": 5, },
507-
)
508503

509-
# %%
510-
# store cat mesh in file
511-
obj_i, step = 10, 5
512-
issue_name = f"cat_penetrate_{int(time())}"
513-
cat_mesh = optimizer.cat_mesh(step, obj_i)
514-
cat_filename = f"cat[o{obj_i}i{step}].stl"
515-
obj_filename = f"obj[o{obj_i}i{step}].stl"
516-
mkdir(f"../dump/issue_reports/{issue_name}")
517-
folder_dir = f"../dump/issue_reports/{issue_name}/"
518-
cat_mesh.save(folder_dir + cat_filename)
519-
meshes[obj_i].save(folder_dir + obj_filename)
520-
# %%
504+
# # %%
505+
# # store cat mesh in file
506+
# obj_i, step = 10, 5
507+
# issue_name = f"cat_penetrate_{int(time())}"
508+
# cat_mesh = optimizer.cat_mesh(step, obj_i)
509+
# cat_filename = f"cat[o{obj_i}i{step}].stl"
510+
# obj_filename = f"obj[o{obj_i}i{step}].stl"
511+
# mkdir(f"../dump/issue_reports/{issue_name}")
512+
# folder_dir = f"../dump/issue_reports/{issue_name}/"
513+
# cat_mesh.save(folder_dir + cat_filename)
514+
# meshes[obj_i].save(folder_dir + obj_filename)
515+
# # %%
521516

522-
# %%
517+
# # %%
523518

524-
tetmesh, filtered_tetmesh, _ = optimizer.reconstruct_delaunay(step)
525-
tetmesh.save(folder_dir + f"tetmesh[i{step}].vtk")
526-
filtered_tetmesh.save(folder_dir + f"filtered_tetmesh[i{step}].vtk")
519+
# tetmesh, filtered_tetmesh, _ = optimizer.reconstruct_delaunay(step)
520+
# tetmesh.save(folder_dir + f"tetmesh[i{step}].vtk")
521+
# filtered_tetmesh.save(folder_dir + f"filtered_tetmesh[i{step}].vtk")
527522

528523

529-
# %%
524+
# # %%
530525

531526

532-
@pprofile
533-
def profile_optimizer():
534-
optimizer.run()
527+
# @pprofile
528+
# def profile_optimizer():
529+
# optimizer.run()
535530

536531

537-
profile_optimizer()
538-
# # %%
532+
# profile_optimizer()
533+
# # # %%
539534

540535

541-
# %%
536+
# # %%
542537

543538

544-
fig, ax = plt.subplots()
539+
# fig, ax = plt.subplots()
545540

546-
a = [0.05, 0.15, 0.25]
547-
b = [0.1, 0.2, 0.3, 0.5]
541+
# a = [0.05, 0.15, 0.25]
542+
# b = [0.1, 0.2, 0.3, 0.5]
548543

549-
x = np.linspace(0, 1, 100)
544+
# x = np.linspace(0, 1, 100)
550545

551-
for ai in a:
552-
for bi in b:
553-
print(f"{ai} {bi}`")
554-
ax.plot(mesh_simplification_condition(x, ai, bi), label=f"a:{ai:.2f}, b:{bi:.2f}")
555-
ax.legend()
546+
# for ai in a:
547+
# for bi in b:
548+
# print(f"{ai} {bi}`")
549+
# ax.plot(mesh_simplification_condition(x, ai, bi), label=f"a:{ai:.2f}, b:{bi:.2f}")
550+
# ax.legend()
556551

557-
# %%
552+
# # %%

irregular_object_packing/packing/plots.py

+19-8
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def create_plot(
2828
# object_mesh = pv.PolyData(object_meshes[i])
2929
object_mesh = pv.wrap(object_meshes[i])
3030
# object_mesh.transform(np.eye(4), object_locations[i])
31-
plotter.add_mesh(object_mesh.decimate(0.1), color="r", opacity=0.7)
31+
plotter.add_mesh(object_mesh.decimate(0.1), color="r", opacity=0.7) # noqa E501
3232

3333
plotter.add_mesh(object_cells[i], color="y", opacity=0.3)
3434

@@ -118,6 +118,13 @@ def plot_step_comparison(
118118
return plotter
119119

120120

121+
def none_to_dict(obj):
122+
if obj is None:
123+
return {}
124+
else:
125+
return obj
126+
127+
121128
def plot_step_single(
122129
mesh,
123130
cat_cell_mesh_1,
@@ -127,8 +134,10 @@ def plot_step_single(
127134
plotter=None,
128135
clipped=False,
129136
title="Title",
130-
c_kwargs={}, m_kwargs={}, cat_kwargs={},
137+
c_kwargs=None, m_kwargs=None, cat_kwargs=None,
131138
):
139+
c_kwargs, m_kwargs, cat_kwargs = [none_to_dict(d) for d in [c_kwargs, m_kwargs, cat_kwargs]]
140+
132141
if plotter is None:
133142
plotter = pv.Plotter()
134143

@@ -219,7 +228,7 @@ def create_packed_scene(
219228
new_mesh = new_mesh.scale(mesh_scale)
220229
new_mesh = new_mesh.translate(coord)
221230

222-
colors.append(trimesh.visual.random_color())
231+
colors.append(trimesh.visual.random_color()) # noqa E501
223232
objects.append(new_mesh)
224233

225234
plotter = pv.Plotter()
@@ -230,8 +239,10 @@ def create_packed_scene(
230239
return plotter
231240

232241

233-
def plot_simulation_scene(plotter, meshes, cat_meshes, container, c_kwargs={}, m_kwargs={}, cat_kwargs={},
242+
def plot_simulation_scene(plotter, meshes, cat_meshes, container, c_kwargs=None, m_kwargs=None, cat_kwargs=None,
234243
):
244+
c_kwargs, m_kwargs, cat_kwargs = [none_to_dict(d) for d in [c_kwargs, m_kwargs, cat_kwargs]]
245+
235246
for i in range(len(meshes)):
236247
try:
237248
plotter.add_mesh(meshes[i], opacity=0.95, color="red", cmap='bwr', scalars="collisions", **m_kwargs)
@@ -247,10 +258,10 @@ def generate_gif(optimizer, save_path, title="Optimization"):
247258
plotter.open_gif(save_path)
248259
plotter.add_title(title)
249260

250-
meshes, cat_meshes, container = optimizer.recreate_scene(0)
261+
_, after_meshes, cat_meshes, container = optimizer.recreate_scene(0)
251262
for i in range(0, optimizer.idx):
252-
prev_meshes = meshes
253-
meshes, cat_meshes, container = optimizer.recreate_scene(i)
263+
prev_meshes = after_meshes
264+
_, after_meshes, cat_meshes, container = optimizer.recreate_scene(i)
254265
plotter.clear()
255266
plot_simulation_scene(plotter, prev_meshes, cat_meshes, container)
256267

@@ -260,7 +271,7 @@ def generate_gif(optimizer, save_path, title="Optimization"):
260271
plotter.write_frame()
261272
plotter.clear()
262273

263-
plot_simulation_scene(plotter, meshes, cat_meshes, container)
274+
plot_simulation_scene(plotter, after_meshes, cat_meshes, container)
264275
plotter.add_text(f"step {i}", position="upper_right")
265276
plotter.add_text(optimizer.status(i).table_str, position="upper_left")
266277
plotter.write_frame()

0 commit comments

Comments
 (0)