Skip to content

Commit 47b8ff0

Browse files
authored
Deprecates physicsnemo.utils.mesh.py (#1487)
* Adds DeprecationWarning on module. * Changelog update for deprecations
1 parent 74c91f9 commit 47b8ff0

File tree

6 files changed

+56
-4
lines changed

6 files changed

+56
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525

2626
### Deprecated
2727

28+
- `physicsnemo.utils.mesh` is deprecated and will be removed in v2.2.0. For
29+
isosurface extraction, use `physicsnemo.mesh.generate.marching_cubes` instead
30+
of `sdf_to_stl`. For VTP/OBJ/STL file conversion (`combine_vtp_files`,
31+
`convert_tesselated_files_in_directory`), use VTK or PyVista directly.
32+
2833
### Removed
2934

3035
### Fixed

physicsnemo/core/version_check.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,6 @@ def _format_install_hint(
193193
"scikit-learn",
194194
direct_install="scikit-learn",
195195
),
196-
"scikit-image": _format_install_hint( # To be removed with utils/mesh/
197-
"scikit-image",
198-
direct_install="scikit-image",
199-
),
200196
# Data format packages
201197
"xarray": _format_install_hint(
202198
"xarray",

physicsnemo/utils/mesh/combine_vtp_files.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# limitations under the License.
1616

1717
import importlib
18+
import warnings
1819
from typing import List
1920

2021
from physicsnemo.core.version_check import check_version_spec
@@ -36,6 +37,13 @@ def combine_vtp_files(input_files: List[str], output_file: str) -> None:
3637
- input_files (list[str]): List of paths to the input VTP files to be combined.
3738
- output_file (str): Path to save the combined VTP file.
3839
"""
40+
warnings.warn(
41+
"combine_vtp_files is deprecated and will be removed in v2.2.0. "
42+
"Use PyVista instead: "
43+
"pyvista.merge([pyvista.read(f) for f in files]).save(output_file)",
44+
DeprecationWarning,
45+
stacklevel=2,
46+
)
3947
reader = vtkXMLPolyDataReader()
4048
append = vtkAppendPolyData()
4149

@@ -56,6 +64,13 @@ def combine_vtp_files(input_files: List[str], output_file: str) -> None:
5664
else:
5765

5866
def combine_vtp_files(*args, **kwargs):
67+
warnings.warn(
68+
"combine_vtp_files is deprecated and will be removed in v2.2.0. "
69+
"Use PyVista instead: "
70+
"pyvista.merge([pyvista.read(f) for f in files]).save(output_file)",
71+
DeprecationWarning,
72+
stacklevel=2,
73+
)
5974
raise RuntimeError(
6075
"combine_vtp_files: VTK is not available, please install vtk with `pip install vtk`"
6176
)

physicsnemo/utils/mesh/convert_file_formats.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import importlib
1818
import os
19+
import warnings
1920

2021
from physicsnemo.core.version_check import check_version_spec
2122

@@ -74,6 +75,14 @@ def convert_tesselated_files_in_directory(conversion_type, input_dir, output_dir
7475
- input_dir (str): Path to the directory containing input files.
7576
- output_dir (str): Path to the directory to save the converted files.
7677
"""
78+
warnings.warn(
79+
"convert_tesselated_files_in_directory is deprecated and will be "
80+
"removed in v2.2.0. Use PyVista for format conversion: "
81+
"pyvista.read(input_file).save(output_file) supports OBJ, VTP, "
82+
"and STL formats.",
83+
DeprecationWarning,
84+
stacklevel=2,
85+
)
7786

7887
if conversion_type == "obj2vtp":
7988
src_ext = ".obj"
@@ -113,4 +122,12 @@ def convert_vtp_to_stl(*args, **kwargs):
113122
raise_vtk_not_available()
114123

115124
def convert_tesselated_files_in_directory(*args, **kwargs):
125+
warnings.warn(
126+
"convert_tesselated_files_in_directory is deprecated and will be "
127+
"removed in v2.2.0. Use PyVista for format conversion: "
128+
"pyvista.read(input_file).save(output_file) supports OBJ, VTP, "
129+
"and STL formats.",
130+
DeprecationWarning,
131+
stacklevel=2,
132+
)
116133
raise_vtk_not_available()

physicsnemo/utils/mesh/generate_stl.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# ruff: noqa: F401
1818

1919
import importlib
20+
import warnings
2021

2122
import numpy as np
2223
import warp as wp
@@ -52,6 +53,14 @@ def sdf_to_stl(
5253
filename : str, optional
5354
Filename for output stl file, by default "output_stl.stl"
5455
"""
56+
warnings.warn(
57+
"sdf_to_stl is deprecated and will be removed in v2.2.0. "
58+
"Use physicsnemo.mesh.generate.marching_cubes instead, which "
59+
"returns a Mesh object. To save as STL: "
60+
"marching_cubes(field).to_pyvista().save('output.stl')",
61+
DeprecationWarning,
62+
stacklevel=2,
63+
)
5564
if backend == "warp":
5665
# Warp MarchingCubes.surface() requires wp.float32; coerce if caller passed float64
5766
field = np.asarray(field, dtype=np.float32)
@@ -98,6 +107,14 @@ def sdf_to_stl(
98107
else:
99108

100109
def sdf_to_stl(*args, **kwargs):
110+
warnings.warn(
111+
"sdf_to_stl is deprecated and will be removed in v2.2.0. "
112+
"Use physicsnemo.mesh.generate.marching_cubes instead, which "
113+
"returns a Mesh object. To save as STL: "
114+
"marching_cubes(field).to_pyvista().save('output.stl')",
115+
DeprecationWarning,
116+
stacklevel=2,
117+
)
101118
raise RuntimeError(
102119
"STL is not available, please install stl with `pip install stl`"
103120
)

test/utils/test_mesh_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def sphere_stl(tmp_path):
4949

5050

5151
@requires_module(["vtk", "warp", "stl"])
52+
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
5253
def test_mesh_utils(tmp_path, pytestconfig):
5354
"""Tests the utility for combining VTP files and converting tesselated files."""
5455

@@ -184,6 +185,7 @@ def _create_random_obj_mesh(num_vertices: int, num_faces: int, dir: str) -> None
184185

185186
@requires_module(["warp", "skimage", "stl", "pyvista"])
186187
@pytest.mark.parametrize("backend", ["warp", "skimage"])
188+
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
187189
def test_stl_gen(pytestconfig, backend, sphere_stl, tmp_path):
188190
from stl import mesh
189191

0 commit comments

Comments
 (0)