Skip to content

Commit 1aa1dbd

Browse files
authored
Merge pull request #9 from robinthibaut/main
Silence logs and light refactoring
2 parents 3b784c7 + b291e03 commit 1aa1dbd

12 files changed

Lines changed: 482 additions & 461 deletions

File tree

CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,18 @@ include_directories(${CMAKE_SOURCE_DIR}/src)
2626
find_package(pybind11 REQUIRED)
2727

2828
# Add the Python module
29-
add_library(loop_cgal MODULE
29+
add_library(_loop_cgal MODULE
3030
loop_cgal/bindings.cpp
3131
src/clip.cpp
3232
src/mesh.cpp
3333
src/meshutils.cpp
34+
src/globals.cpp
3435

3536
)
36-
target_link_libraries(loop_cgal PRIVATE pybind11::module CGAL::CGAL)
37-
target_include_directories(loop_cgal PRIVATE ${CMAKE_SOURCE_DIR}/src)
38-
set_target_properties(loop_cgal PROPERTIES PREFIX "" SUFFIX ".so")
37+
target_link_libraries(_loop_cgal PRIVATE pybind11::module CGAL::CGAL)
38+
target_include_directories(_loop_cgal PRIVATE ${CMAKE_SOURCE_DIR}/src)
39+
set_target_properties(_loop_cgal PROPERTIES PREFIX "" SUFFIX ".so")
3940
# Install the Python module to the correct location
40-
install(TARGETS loop_cgal
41+
install(TARGETS _loop_cgal
4142
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/loop_cgal
4243
)

examples/clip_v2.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
import numpy as np
33
import pyvista as pv
44
from LoopStructural.datatypes import BoundingBox
5+
loop_cgal.set_verbose(True)
6+
print(loop_cgal.verbose) # Should print True
57
def test():
68
bb = BoundingBox(np.zeros(3), np.ones(3))
79
grid = bb.structured_grid().vtk()
8-
print(grid)
910
grid["scalars"] = grid.points[:,0]
1011
surface = grid.contour([.5])
1112
surface_1_tri = surface.faces.reshape(-1, 4)[:, 1:].copy()
@@ -18,12 +19,9 @@ def test():
1819
# surface_cgal.remesh(target_edge_length=0.02, verbose=True,protect_constraints=True, relax_constraints=False, number_of_iterations=1,split_long_edges=False)
1920
surface_cgal_2 = loop_cgal.TriMesh(surface_2)
2021
# surface_cgal_2.remesh(target_edge_length=0.02, verbose=True,protect_constraints=True, relax_constraints=False, number_of_iterations=1,split_long_edges=False)
21-
print("clipping 1")
22-
surface_cgal.cut_with_surface(surface_cgal_2,verbose=True, preserve_intersection=False, preserve_intersection_clipper=False)
22+
surface_cgal.cut_with_surface(surface_cgal_2, preserve_intersection=False, preserve_intersection_clipper=False)
2323

24-
print("reverse face orientation")
2524
surface_cgal_2.reverse_face_orientation()
26-
print("clipping 3")
2725
surface_cgal_3 = loop_cgal.TriMesh(surface)
2826
# surface_cgal_3.remesh(target_edge_length=0.02, verbose=True,protect_constraints=True, relax_constraints=False, number_of_iterations=1,split_long_edges=False)
2927
surface_cgal_3.cut_with_surface(surface_cgal_2)

loop_cgal/__init__.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
from .loop_cgal import clip_surface, NumpyMesh, NumpyPlane, clip_plane, corefine_mesh
2-
from .loop_cgal import TriMesh as _TriMesh
3-
import pyvista as pv
4-
import numpy as np
1+
from __future__ import annotations
2+
53
from typing import Tuple
64

5+
import numpy as np
6+
import pyvista as pv
7+
8+
from ._loop_cgal import NumpyMesh, NumpyPlane, clip_plane, clip_surface, corefine_mesh
9+
from ._loop_cgal import TriMesh as _TriMesh
10+
from ._loop_cgal import verbose
11+
from ._loop_cgal import set_verbose as set_verbose
712
class TriMesh(_TriMesh):
813
"""
914
A class for handling triangular meshes using CGAL.
@@ -17,7 +22,7 @@ def __init__(self, surface: pv.PolyData):
1722

1823
def to_pyvista(self, area_threshold: float = 1e-6, # this is the area threshold for the faces, if the area is smaller than this it will be removed
1924
duplicate_vertex_threshold: float = 1e-4, # this is the threshold for duplicate vertices
20-
verbose: bool = False) -> pv.PolyData:
25+
) -> pv.PolyData:
2126
"""
2227
Convert the TriMesh to a pyvista PolyData object.
2328
@@ -26,7 +31,7 @@ def to_pyvista(self, area_threshold: float = 1e-6, # this is the area threshold
2631
pyvista.PolyData
2732
The converted PolyData object.
2833
"""
29-
np_mesh = self.save(area_threshold, duplicate_vertex_threshold, verbose)
34+
np_mesh = self.save(area_threshold, duplicate_vertex_threshold)
3035
vertices = np.array(np_mesh.vertices).copy()
3136
triangles = np.array(np_mesh.triangles).copy()
3237
return pv.PolyData.from_regular_faces(vertices, triangles)
@@ -43,7 +48,6 @@ def clip_pyvista_polydata_with_plane(
4348
area_threshold: float = 0.0001,
4449
protect_constraints: bool = False,
4550
relax_constraints: bool = True,
46-
verbose: bool = False,
4751
) -> pv.PolyData:
4852
"""
4953
Clip a pyvista PolyData object with a plane using the CGAL library.
@@ -68,8 +72,7 @@ def clip_pyvista_polydata_with_plane(
6872
The threshold for merging duplicate vertices, by default 0.001
6973
area_threshold : float, optional
7074
The area threshold for removing small faces, by default 0.0001
71-
verbose : bool, optional
72-
Whether to print verbose output, by default False
75+
7376
Returns
7477
-------
7578
pyvista.PolyData
@@ -94,7 +97,6 @@ def clip_pyvista_polydata_with_plane(
9497
area_threshold=area_threshold,
9598
protect_constraints=protect_constraints,
9699
relax_constraints=relax_constraints,
97-
verbose=verbose,
98100
)
99101
return pv.PolyData.from_regular_faces(mesh.vertices, mesh.triangles)
100102

@@ -110,7 +112,6 @@ def clip_pyvista_polydata(
110112
area_threshold: float = 0.0001,
111113
protect_constraints: bool = False,
112114
relax_constraints: bool = True,
113-
verbose: bool = False,
114115
) -> pv.PolyData:
115116
"""
116117
Clip two pyvista PolyData objects using the CGAL library.
@@ -146,11 +147,8 @@ def clip_pyvista_polydata(
146147
area_threshold=area_threshold,
147148
protect_constraints=protect_constraints,
148149
relax_constraints=relax_constraints,
149-
verbose=verbose,
150150
)
151-
out = pv.PolyData.from_regular_faces(mesh.vertices, mesh.triangles)
152-
153-
return out
151+
return pv.PolyData.from_regular_faces(mesh.vertices, mesh.triangles)
154152

155153

156154
def corefine_pyvista_polydata(
@@ -162,7 +160,6 @@ def corefine_pyvista_polydata(
162160
number_of_iterations: int = 10,
163161
protect_constraints: bool = True,
164162
relax_constraints: bool = True,
165-
verbose: bool = False,
166163
) -> Tuple[pv.PolyData, pv.PolyData]:
167164
"""
168165
Corefine two pyvista PolyData objects using the CGAL library.
@@ -197,7 +194,6 @@ def corefine_pyvista_polydata(
197194
number_of_iterations=number_of_iterations,
198195
relax_constraints=relax_constraints,
199196
protect_constraints=protect_constraints,
200-
verbose=verbose,
201197
)
202198
return (
203199
pv.PolyData.from_regular_faces(tm1.vertices, tm1.triangles),

loop_cgal/bindings.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
#include "clip.h" // Include the API implementation
55
#include "mesh.h"
66
#include "numpymesh.h"
7-
7+
#include "globals.h" // Include the global verbose flag
88
namespace py = pybind11;
99

10-
PYBIND11_MODULE(loop_cgal, m)
10+
PYBIND11_MODULE(_loop_cgal, m)
1111
{
12-
12+
m.attr("verbose") = &LoopCGAL::verbose; // Expose the global verbose flag
13+
m.def("set_verbose", &LoopCGAL::set_verbose, "Set the verbose flag");
1314
m.def("clip_surface", &clip_surface, py::arg("tm"), py::arg("clipper"),
1415
py::arg("target_edge_length") = 10.0,
1516
py::arg("remesh_before_clipping") = true,
@@ -49,18 +50,15 @@ PYBIND11_MODULE(loop_cgal, m)
4950
.def(py::init<const pybind11::array_t<double> &, const pybind11::array_t<int> &>(),
5051
py::arg("vertices"), py::arg("triangles"))
5152
.def("cut_with_surface", &TriMesh::cutWithSurface, py::arg("surface"),
52-
py::arg("verbose") = false,
5353
py::arg("preserve_intersection") = false,
5454
py::arg("preserve_intersection_clipper") = false)
5555
.def("remesh", &TriMesh::remesh, py::arg("split_long_edges") = true,
56-
py::arg("verbose") = false,
5756
py::arg("target_edge_length") = 10.0,
5857
py::arg("number_of_iterations") = 3,
5958
py::arg("protect_constraints") = true,
6059
py::arg("relax_constraints") = false)
6160
.def("save", &TriMesh::save, py::arg("area_threshold") = 1e-6,
62-
py::arg("duplicate_vertex_threshold") = 1e-6,
63-
py::arg("verbose") = false)
61+
py::arg("duplicate_vertex_threshold") = 1e-6)
6462
.def("reverse_face_orientation", &TriMesh::reverseFaceOrientation,
6563
"Reverse the face orientation of the mesh.")
6664
.def("add_fixed_edges", &TriMesh::add_fixed_edges,

0 commit comments

Comments
 (0)