Skip to content

Commit 3cb3db8

Browse files
committed
Basic AABB support; in_element; (req C++17)
1 parent e2e75c1 commit 3cb3db8

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ endfunction()
8989
pyigl_include("copyleft" "cgal")
9090

9191

92-
add_library(pyigl_classes MODULE classes/classes.cpp)
92+
file(GLOB PYIGL_CLASSES_SOURCES classes/*.cpp)
93+
add_library(pyigl_classes MODULE ${PYIGL_CLASSES_SOURCES})
94+
# std::variant
95+
target_compile_features(pyigl_classes PRIVATE cxx_std_17)
9396
target_link_libraries(pyigl_classes PRIVATE npe igl::core)
9497
target_link_libraries(pyigl_classes PRIVATE pybind11::module)
9598
set_target_properties(pyigl_classes PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}" SUFFIX "${PYTHON_MODULE_EXTENSION}")

classes/classes.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@
99

1010
namespace py = pybind11;
1111

12+
// Forward declaration
13+
template <int DIM>
14+
void init_AABB(py::module_ &);
15+
1216
PYBIND11_MODULE(pyigl_classes, m)
1317
{
18+
init_AABB<2>(m);
19+
init_AABB<3>(m);
20+
1421
py::class_<igl::ARAPData>(m, "ARAP")
1522
.def(py::init([](Eigen::MatrixXd &v, Eigen::MatrixXi &f, int dim, Eigen::MatrixXi &b,
1623
const int energy_type, const bool with_dynamics, const double h, const double ym, const int max_iter) {

tests/test_basic.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,5 +2468,40 @@ def test_flip_edge(self):
24682468
emap.dtype == self.f1.dtype)
24692469
self.assertTrue(np.array(ue2e).dtype == self.f1.dtype)
24702470

2471+
def test_AABB(self):
2472+
tree = igl.AABB_f64_3()
2473+
tree.init(self.v1,self.f1)
2474+
bc = igl.barycenter(self.v1,self.f1)
2475+
sqrD = tree.squared_distance(self.v1,self.f1,bc)
2476+
self.assertTrue(sqrD.shape[0] == bc.shape[0])
2477+
self.assertTrue(np.max(sqrD) <= 1e-16)
2478+
sqrD,I,C = tree.squared_distance(self.v1,self.f1,bc,return_index=True,return_closest_point=True)
2479+
self.assertTrue(sqrD.shape[0] == bc.shape[0])
2480+
self.assertTrue(I.shape[0] == bc.shape[0])
2481+
self.assertTrue(C.shape == bc.shape)
2482+
2483+
def test_in_element_3(self):
2484+
V = np.array([ [0.,0,0], [1,0,0], [0,1,0], [0,0,1], [1,1,1]],dtype='float64')
2485+
T = np.array([[0,1,2,3],[4,3,2,1]],dtype='int32')
2486+
Q = np.array([[0.1,0.1,0.1],[0.9,0.9,0.9]],dtype='float64')
2487+
tree = igl.AABB_f64_3()
2488+
tree.init(V,T)
2489+
I = igl.in_element_3(V,T,Q,tree)
2490+
self.assertTrue(I.shape[0] == Q.shape[0])
2491+
self.assertTrue(I[0] == 0)
2492+
self.assertTrue(I[1] == 1)
2493+
2494+
def test_in_element_2(self):
2495+
V = np.array([ [0.,0], [1,0], [0,1], [1,1]],dtype='float64')
2496+
F = np.array([[0,1,2],[2,1,3]],'int32')
2497+
Q = np.array([[0.1,0.1],[0.9,0.9]],dtype='float64')
2498+
tree = igl.AABB_f64_2()
2499+
tree.init(V,F)
2500+
I = igl.in_element_2(V,F,Q,tree)
2501+
self.assertTrue(I.shape[0] == Q.shape[0])
2502+
self.assertTrue(I[0] == 0)
2503+
self.assertTrue(I[1] == 1)
2504+
2505+
24712506
if __name__ == '__main__':
24722507
unittest.main()

0 commit comments

Comments
 (0)