@@ -20,7 +20,7 @@ namespace pyigl
2020 tree.init (V,Ele);
2121 }
2222 template <typename AABB>
23- nb::object find (
23+ auto find (
2424 AABB &tree,
2525 const nb::DRef<const Eigen::MatrixXN> &V,
2626 const nb::DRef<const Eigen::MatrixXI> &Ele,
@@ -33,80 +33,61 @@ namespace pyigl
3333 }
3434 std::vector<int > vec_int = tree.find (V,Ele,q,first);
3535 std::vector<Integer> vec (vec_int.begin (),vec_int.end ());
36- if (first)
37- {
38- return vec.size () ? nb::cast (vec[0 ]) : nb::none ();
39- }else
40- {
41- return nb::cast (std::move (vec));
42- }
36+ return vec;
4337 }
4438
4539 template <typename AABB>
46- nb::object squared_distance (
40+ auto squared_distance (
4741 AABB &tree,
4842 const nb::DRef<const Eigen::MatrixXN> &V,
4943 const nb::DRef<const Eigen::MatrixXI> &Ele,
50- const nb::DRef<const Eigen::MatrixXN> &P,
51- const bool return_I,
52- const bool return_C)
44+ const nb::DRef<const Eigen::MatrixXN> &P)
5345 {
5446 Eigen::VectorXN sqrD;
5547 Eigen::VectorXI I;
5648 Eigen::MatrixXN C;
5749 tree.squared_distance (V,Ele,P,sqrD,I,C);
58- if (return_I && return_C)
59- {
60- return nb::make_tuple (sqrD,I,C);
61- }else if (return_I)
62- {
63- return nb::make_tuple (sqrD,I);
64- }else if (return_C)
65- {
66- return nb::make_tuple (sqrD,C);
67- }
68- return nb::cast (std::move (sqrD));
50+ return std::make_tuple (sqrD,I,C);
6951 }
7052
7153 template <typename AABB>
72- nb::object intersect_ray (
54+ auto intersect_ray_first (
7355 AABB &tree,
7456 const nb::DRef<const Eigen::MatrixXN> &V,
7557 const nb::DRef<const Eigen::MatrixXI> &Ele,
7658 const nb::DRef<const Eigen::MatrixXN> &orig,
7759 const nb::DRef<const Eigen::MatrixXN> &dir,
78- const Numeric min_t ,
79- const bool first)
60+ const Numeric min_t )
8061 {
81- if (first)
82- {
62+ Eigen::VectorXI I;
63+ Eigen::VectorXN T;
64+ Eigen::MatrixXN UV;
65+ tree.intersect_ray (V,Ele,orig,dir,min_t ,I,T,UV);
66+ return std::make_tuple (I,T,UV);
67+ }
8368
84- Eigen::VectorXI I;
85- Eigen::VectorXN T;
86- Eigen::MatrixXN UV;
87- tree.intersect_ray (V,Ele,orig,dir,min_t ,I,T,UV);
88- return nb::make_tuple (I,T,UV);
89- }else
69+ template <typename AABB>
70+ auto intersect_ray (
71+ AABB &tree,
72+ const nb::DRef<const Eigen::MatrixXN> &V,
73+ const nb::DRef<const Eigen::MatrixXI> &Ele,
74+ const nb::DRef<const Eigen::MatrixXN> &orig,
75+ const nb::DRef<const Eigen::MatrixXN> &dir)
76+ {
77+ std::vector<std::vector<igl::Hit<Numeric>>> hits;
78+ tree.intersect_ray (V,Ele,orig,dir,hits);
79+ std::vector<std::vector<std::tuple<Integer,Numeric,Numeric,Numeric>>> out;
80+ for (const auto &hit : hits)
9081 {
91- if (std::isfinite (min_t ))
92- {
93- throw std::runtime_error (" intersect_ray: min_t only supported for first=true" );
94- }
95- std::vector<std::vector<igl::Hit<Numeric>>> hits;
96- tree.intersect_ray (V,Ele,orig,dir,hits);
97- std::vector<std::vector<std::tuple<Integer,Numeric,Numeric,Numeric>>> out;
98- for (const auto &hit : hits)
82+ std::vector<std::tuple<Integer,Numeric,Numeric,Numeric>> hit_out;
83+ for (const auto &h : hit)
9984 {
100- std::vector<std::tuple<Integer,Numeric,Numeric,Numeric>> hit_out;
101- for (const auto &h : hit)
102- {
103- hit_out.push_back (std::make_tuple (h.id ,h.t ,h.u ,h.v ));
104- }
105- out.push_back (hit_out);
85+ hit_out.push_back (std::make_tuple (h.id ,h.t ,h.u ,h.v ));
10686 }
107-
108- return nb::cast (std::move (out));
87+ out.push_back (hit_out);
10988 }
89+
90+ return out;
11091 }
11192}
11293
@@ -118,8 +99,9 @@ void bind_AABB(nb::module_ &m)
11899 .def (nb::init<>())
119100 .def (" init" , &pyigl::init<AABBN3>, " V" _a, " Ele" _a)
120101 .def (" find" , &pyigl::find<AABBN3>, " V" _a, " Ele" _a, " q" _a, " first" _a=false )
121- .def (" squared_distance" , &pyigl::squared_distance<AABBN3>, " V" _a, " Ele" _a, " P" _a, " return_I" _a=false ," return_C" _a=false )
122- .def (" intersect_ray" ,&pyigl::intersect_ray<AABBN3>, " V" _a, " Ele" _a, " orig" _a, " dir" _a, " min_t" _a=std::numeric_limits<Numeric>::infinity (), " first" _a=false )
102+ .def (" squared_distance" , &pyigl::squared_distance<AABBN3>, " V" _a, " Ele" _a, " P" _a)
103+ .def (" intersect_ray_first" ,&pyigl::intersect_ray_first<AABBN3>, " V" _a, " Ele" _a, " orig" _a, " dir" _a, " min_t" _a=std::numeric_limits<Numeric>::infinity ())
104+ .def (" intersect_ray" ,&pyigl::intersect_ray<AABBN3>, " V" _a, " Ele" _a, " orig" _a, " dir" _a)
123105 ;
124106}
125107
0 commit comments