55#include < nanobind/stl/tuple.h>
66#include < nanobind/stl/vector.h>
77
8+ #include " core/blender.cuh"
9+ #include " core/camera.cuh"
810#include " core/confidence.cuh"
911#include " core/fmb.cuh"
1012#include " core/geometry.cuh"
13+ #include " core/image.cuh"
1114#include " core/utils.cuh"
1215
1316namespace nb = nanobind;
1417
1518template <typename T, MemoryLocation location>
1619void bind_array2d (nb::module_& m, const char * name);
20+ template <MemoryLocation location>
21+ void bind_image (nb::module_& m, const char * name);
22+ template <MemoryLocation location>
23+ void bind_image_view (nb::module_& m, const char * name);
1724
1825NB_MODULE (_genmetaballs_bindings, m) {
1926
@@ -82,18 +89,53 @@ NB_MODULE(_genmetaballs_bindings, m) {
8289 .def_rw (" start" , &Ray::start)
8390 .def_rw (" direction" , &Ray::direction);
8491
92+ /*
93+ * Camera module bindings
94+ */
95+ nb::module_ camera = m.def_submodule (" camera" , " Camera intrinsics and extrinsics" );
96+ nb::class_<Intrinsics>(camera, " Intrinsics" )
97+ .def (nb::init<uint32_t , uint32_t , float , float , float , float >(), nb::arg (" height" ),
98+ nb::arg (" width" ), nb::arg (" fx" ), nb::arg (" fy" ), nb::arg (" cx" ), nb::arg (" cy" ))
99+ .def_ro (" height" , &Intrinsics::height)
100+ .def_ro (" width" , &Intrinsics::width)
101+ .def_ro (" fx" , &Intrinsics::fx)
102+ .def_ro (" fy" , &Intrinsics::fy)
103+ .def_ro (" cx" , &Intrinsics::cx)
104+ .def_ro (" cy" , &Intrinsics::cy)
105+ .def (" get_ray_direction" , &Intrinsics::get_ray_direction,
106+ " Get the direction of the ray going through pixel (px, py) in camera frame" ,
107+ nb::arg (" px" ), nb::arg (" py" ));
108+
109+ /*
110+ * Image module bindings
111+ */
112+ nb::module_ image = m.def_submodule (" image" , " Image data structure for GenMetaballs" );
113+ bind_image_view<MemoryLocation::HOST>(image, " CPUImageView" );
114+ bind_image<MemoryLocation::HOST>(image, " CPUImage" );
115+ bind_image_view<MemoryLocation::DEVICE>(image, " GPUImageView" );
116+ bind_image<MemoryLocation::DEVICE>(image, " GPUImage" );
117+
85118 /*
86119 * Confidence module bindings
87120 */
88121
89122 nb::module_ confidence = m.def_submodule (" confidence" );
90123 nb::class_<ZeroParameterConfidence>(confidence, " ZeroParameterConfidence" )
91124 .def (nb::init<>())
92- .def (" get_confidence" , &ZeroParameterConfidence::get_confidence);
125+ .def (" get_confidence" , &ZeroParameterConfidence::get_confidence, nb::arg (" sumexpd" ),
126+ " Get the confidence value for a given sumexpd" )
127+ .def (" __repr__" ,
128+ [](const ZeroParameterConfidence& c) { return nb::str (" ZeroParameterConfidence()" ); });
93129
94130 nb::class_<TwoParameterConfidence>(confidence, " TwoParameterConfidence" )
95131 .def (nb::init<float , float >())
96- .def (" get_confidence" , &TwoParameterConfidence::get_confidence);
132+ .def_ro (" beta4" , &TwoParameterConfidence::beta4)
133+ .def_ro (" beta5" , &TwoParameterConfidence::beta5)
134+ .def (" get_confidence" , &TwoParameterConfidence::get_confidence, nb::arg (" sumexpd" ),
135+ " Get the confidence value for a given sumexpd" )
136+ .def (" __repr__" , [](const TwoParameterConfidence& c) {
137+ return nb::str (" TwoParameterConfidence(beta4={}, beta5={})" ).format (c.beta4 , c.beta5 );
138+ });
97139
98140 /*
99141 * Utils module bindings
@@ -102,6 +144,32 @@ NB_MODULE(_genmetaballs_bindings, m) {
102144 nb::module_ utils = m.def_submodule (" utils" );
103145 utils.def (" sigmoid" , sigmoid, nb::arg (" x" ), " Compute the sigmoid function: 1 / (1 + exp(-x))" );
104146
147+ // blender submodule
148+ nb::module_ blender = m.def_submodule (" blender" );
149+ nb::class_<FourParameterBlender>(blender, " FourParameterBlender" )
150+ .def (nb::init<float , float , float , float >())
151+ .def_ro (" beta1" , &FourParameterBlender::beta1)
152+ .def_ro (" beta2" , &FourParameterBlender::beta2)
153+ .def_ro (" beta3" , &FourParameterBlender::beta3)
154+ .def_ro (" eta" , &FourParameterBlender::eta)
155+ .def (" blend" , &FourParameterBlender::blend, nb::arg (" t" ), nb::arg (" d" ),
156+ " Blend two values with (t,d)" )
157+ .def (" __repr__" , [](const FourParameterBlender& b) {
158+ return nb::str (" FourParameterBlender(beta1={}, beta2={}, beta3={}, eta={})" )
159+ .format (b.beta1 , b.beta2 , b.beta3 , b.eta );
160+ });
161+
162+ nb::class_<ThreeParameterBlender>(blender, " ThreeParameterBlender" )
163+ .def (nb::init<float , float , float >())
164+ .def_ro (" beta1" , &ThreeParameterBlender::beta1)
165+ .def_ro (" beta2" , &ThreeParameterBlender::beta2)
166+ .def_ro (" eta" , &ThreeParameterBlender::eta)
167+ .def (" blend" , &ThreeParameterBlender::blend, nb::arg (" t" ), nb::arg (" d" ),
168+ " Blend two values with (t,d)" )
169+ .def (" __repr__" , [](const ThreeParameterBlender& b) {
170+ return nb::str (" ThreeParameterBlender(beta1={}, beta2={}, eta={})" )
171+ .format (b.beta1 , b.beta2 , b.eta );
172+ });
105173 bind_array2d<float , MemoryLocation::HOST>(utils, " CPUFloatArray2D" );
106174 bind_array2d<float , MemoryLocation::DEVICE>(utils, " GPUFloatArray2D" );
107175
@@ -137,3 +205,30 @@ void bind_array2d(nb::module_& m, const char* name) {
137205 .def_prop_ro (" ndim" , &Array2D<T, location>::ndim)
138206 .def_prop_ro (" size" , &Array2D<T, location>::size);
139207}
208+
209+ template <MemoryLocation location>
210+ void bind_image_view (nb::module_& m, const char * name) {
211+ nb::class_<ImageView<location>>(m, name)
212+ .def (nb::init<const Array2D<float , location>&, const Array2D<float , location>&>(),
213+ nb::arg (" confidence" ), nb::arg (" depth" ))
214+ .def_prop_ro (" confidence" , [](const ImageView<location>& view) { return view.confidence ; })
215+ .def_prop_ro (" depth" , [](const ImageView<location>& view) { return view.depth ; })
216+ .def_prop_ro (" num_rows" , &ImageView<location>::num_rows)
217+ .def_prop_ro (" num_cols" , &ImageView<location>::num_cols)
218+ .def (" __repr__" , [=](const ImageView<location>& view) {
219+ return nb::str (" {}(height={}, width={})" )
220+ .format (name, view.num_rows (), view.num_cols ());
221+ });
222+ }
223+
224+ template <MemoryLocation location>
225+ void bind_image (nb::module_& m, const char * name) {
226+ nb::class_<Image<location>>(m, name)
227+ .def (nb::init<uint32_t , uint32_t >(), nb::arg (" height" ), nb::arg (" width" ))
228+ .def_prop_ro (" num_rows" , &Image<location>::num_rows)
229+ .def_prop_ro (" num_cols" , &Image<location>::num_cols)
230+ .def (" as_view" , &Image<location>::as_view, " Get a view of the image data as ImageView" )
231+ .def (" __repr__" , [=](const Image<location>& img) {
232+ return nb::str (" {}(height={}, width={})" ).format (name, img.num_rows (), img.num_cols ());
233+ });
234+ }
0 commit comments