Skip to content

Commit fae8b66

Browse files
committed
update implot3d ([Bundle] PlotSurface - add a version whose API is easier to port)
1 parent 7073c68 commit fae8b66

3 files changed

Lines changed: 48 additions & 20 deletions

File tree

bindings/imgui_bundle/implot3d/__init__.pyi

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,22 +639,46 @@ def plot_quad(
639639
) -> None:
640640
pass
641641

642-
# IMPLOT3D_TMP void PlotSurface(const char* label_id, const T* xs, const T* ys, const T* zs, int x_count, int y_count, double scale_min = 0.0, double scale_max = 0.0, ImPlot3DSurfaceFlags flags = 0, int offset = 0, int stride = sizeof(T)); /* original C++ signature */
642+
# [ADAPT_IMGUI_BUNDLE]
643+
# #ifdef IMGUI_BUNDLE_PYTHON_API
644+
#
645+
# A version of PlotSurface whose API is easier to port to Python
646+
# (params xs_count, ys_count and zs_count are removed in the Python API, but are used in the bindings code generation)
647+
648+
# IMPLOT3D_TMP void PlotSurface( /* original C++ signature */
649+
# const char* label_id,
650+
# const T* xs, int xs_count,
651+
# const T* ys, int ys_count,
652+
# const T* zs, int zs_count,
653+
# int x_count, int y_count,
654+
# double scale_min = 0.0, double scale_max = 0.0,
655+
# ImPlot3DSurfaceFlags flags = 0,
656+
# int offset = 0,
657+
# int stride = sizeof(T));
643658
def plot_surface(
644659
label_id: str,
645660
xs: np.ndarray,
646661
ys: np.ndarray,
647662
zs: np.ndarray,
663+
x_count: int,
648664
y_count: int,
649665
scale_min: float = 0.0,
650666
scale_max: float = 0.0,
651667
flags: SurfaceFlags = 0,
652668
offset: int = 0,
653669
stride: int = -1,
654670
) -> None:
655-
"""Plot the surface defined by a grid of vertices. The grid is defined by the x and y arrays, and the z array contains the height of each vertex. A total of x_count * y_count vertices are expected for each array. Leave #scale_min and #scale_max both at 0 for automatic color scaling, or set them to a predefined range."""
671+
"""Plot the surface defined by a grid of vertices. The grid is defined by the x and y arrays,
672+
and the z array contains the height of each vertex.
673+
A total of x_count * y_count vertices are expected for each array.
674+
Leave #scale_min and #scale_max both at 0 for automatic color scaling, or set them to a predefined range.
675+
"""
656676
pass
657677

678+
# #endif
679+
#
680+
# [/ADAPT_IMGUI_BUNDLE]
681+
658682
# IMPLOT3D_API void PlotMesh(const char* label_id, const ImPlot3DPoint* vtx, const unsigned int* idx, int vtx_count, int idx_count, ImPlot3DMeshFlags flags = 0); /* original C++ signature */
659683
def plot_mesh(label_id: str, vtx: Point, idx: int, vtx_count: int, idx_count: int, flags: MeshFlags = 0) -> None:
660684
pass

external/implot3d/bindings/pybind_implot3d.cpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -701,11 +701,13 @@ void py_init_module_implot3d(nb::module_& m)
701701

702702
PlotQuad_adapt_c_buffers(label_id, xs, ys, zs, flags, offset, stride);
703703
}, nb::arg("label_id"), nb::arg("xs"), nb::arg("ys"), nb::arg("zs"), nb::arg("flags") = 0, nb::arg("offset") = 0, nb::arg("stride") = -1);
704+
// #ifdef IMGUI_BUNDLE_PYTHON_API
705+
//
704706

705707
m.def("plot_surface",
706-
[](const char * label_id, const nb::ndarray<> & xs, const nb::ndarray<> & ys, const nb::ndarray<> & zs, int y_count, double scale_min = 0.0, double scale_max = 0.0, ImPlot3DSurfaceFlags flags = 0, int offset = 0, int stride = -1)
708+
[](const char * label_id, const nb::ndarray<> & xs, const nb::ndarray<> & ys, const nb::ndarray<> & zs, int x_count, int y_count, double scale_min = 0.0, double scale_max = 0.0, ImPlot3DSurfaceFlags flags = 0, int offset = 0, int stride = -1)
707709
{
708-
auto PlotSurface_adapt_c_buffers = [](const char * label_id, const nb::ndarray<> & xs, const nb::ndarray<> & ys, const nb::ndarray<> & zs, int y_count, double scale_min = 0.0, double scale_max = 0.0, ImPlot3DSurfaceFlags flags = 0, int offset = 0, int stride = -1)
710+
auto PlotSurface_adapt_c_buffers = [](const char * label_id, const nb::ndarray<> & xs, const nb::ndarray<> & ys, const nb::ndarray<> & zs, int x_count, int y_count, double scale_min = 0.0, double scale_max = 0.0, ImPlot3DSurfaceFlags flags = 0, int offset = 0, int stride = -1)
709711
{
710712
// Check if the array is 1D and C-contiguous
711713
if (! (xs.ndim() == 1 && xs.stride(0) == 1))
@@ -762,38 +764,40 @@ void py_init_module_implot3d(nb::module_& m)
762764

763765
// call the correct template version by casting
764766
if (zs_type == 'B')
765-
ImPlot3D::PlotSurface(label_id, static_cast<const uint8_t *>(xs_from_pyarray), static_cast<const uint8_t *>(ys_from_pyarray), static_cast<const uint8_t *>(zs_from_pyarray), static_cast<int>(zs_count), y_count, scale_min, scale_max, flags, offset, zs_stride);
767+
ImPlot3D::PlotSurface(label_id, static_cast<const uint8_t *>(xs_from_pyarray), static_cast<int>(xs_count), static_cast<const uint8_t *>(ys_from_pyarray), static_cast<int>(ys_count), static_cast<const uint8_t *>(zs_from_pyarray), static_cast<int>(zs_count), x_count, y_count, scale_min, scale_max, flags, offset, zs_stride);
766768
else if (zs_type == 'b')
767-
ImPlot3D::PlotSurface(label_id, static_cast<const int8_t *>(xs_from_pyarray), static_cast<const int8_t *>(ys_from_pyarray), static_cast<const int8_t *>(zs_from_pyarray), static_cast<int>(zs_count), y_count, scale_min, scale_max, flags, offset, zs_stride);
769+
ImPlot3D::PlotSurface(label_id, static_cast<const int8_t *>(xs_from_pyarray), static_cast<int>(xs_count), static_cast<const int8_t *>(ys_from_pyarray), static_cast<int>(ys_count), static_cast<const int8_t *>(zs_from_pyarray), static_cast<int>(zs_count), x_count, y_count, scale_min, scale_max, flags, offset, zs_stride);
768770
else if (zs_type == 'H')
769-
ImPlot3D::PlotSurface(label_id, static_cast<const uint16_t *>(xs_from_pyarray), static_cast<const uint16_t *>(ys_from_pyarray), static_cast<const uint16_t *>(zs_from_pyarray), static_cast<int>(zs_count), y_count, scale_min, scale_max, flags, offset, zs_stride);
771+
ImPlot3D::PlotSurface(label_id, static_cast<const uint16_t *>(xs_from_pyarray), static_cast<int>(xs_count), static_cast<const uint16_t *>(ys_from_pyarray), static_cast<int>(ys_count), static_cast<const uint16_t *>(zs_from_pyarray), static_cast<int>(zs_count), x_count, y_count, scale_min, scale_max, flags, offset, zs_stride);
770772
else if (zs_type == 'h')
771-
ImPlot3D::PlotSurface(label_id, static_cast<const int16_t *>(xs_from_pyarray), static_cast<const int16_t *>(ys_from_pyarray), static_cast<const int16_t *>(zs_from_pyarray), static_cast<int>(zs_count), y_count, scale_min, scale_max, flags, offset, zs_stride);
773+
ImPlot3D::PlotSurface(label_id, static_cast<const int16_t *>(xs_from_pyarray), static_cast<int>(xs_count), static_cast<const int16_t *>(ys_from_pyarray), static_cast<int>(ys_count), static_cast<const int16_t *>(zs_from_pyarray), static_cast<int>(zs_count), x_count, y_count, scale_min, scale_max, flags, offset, zs_stride);
772774
else if (zs_type == 'I')
773-
ImPlot3D::PlotSurface(label_id, static_cast<const uint32_t *>(xs_from_pyarray), static_cast<const uint32_t *>(ys_from_pyarray), static_cast<const uint32_t *>(zs_from_pyarray), static_cast<int>(zs_count), y_count, scale_min, scale_max, flags, offset, zs_stride);
775+
ImPlot3D::PlotSurface(label_id, static_cast<const uint32_t *>(xs_from_pyarray), static_cast<int>(xs_count), static_cast<const uint32_t *>(ys_from_pyarray), static_cast<int>(ys_count), static_cast<const uint32_t *>(zs_from_pyarray), static_cast<int>(zs_count), x_count, y_count, scale_min, scale_max, flags, offset, zs_stride);
774776
else if (zs_type == 'i')
775-
ImPlot3D::PlotSurface(label_id, static_cast<const int32_t *>(xs_from_pyarray), static_cast<const int32_t *>(ys_from_pyarray), static_cast<const int32_t *>(zs_from_pyarray), static_cast<int>(zs_count), y_count, scale_min, scale_max, flags, offset, zs_stride);
777+
ImPlot3D::PlotSurface(label_id, static_cast<const int32_t *>(xs_from_pyarray), static_cast<int>(xs_count), static_cast<const int32_t *>(ys_from_pyarray), static_cast<int>(ys_count), static_cast<const int32_t *>(zs_from_pyarray), static_cast<int>(zs_count), x_count, y_count, scale_min, scale_max, flags, offset, zs_stride);
776778
else if (zs_type == 'L')
777-
ImPlot3D::PlotSurface(label_id, static_cast<const np_uint_l *>(xs_from_pyarray), static_cast<const np_uint_l *>(ys_from_pyarray), static_cast<const np_uint_l *>(zs_from_pyarray), static_cast<int>(zs_count), y_count, scale_min, scale_max, flags, offset, zs_stride);
779+
ImPlot3D::PlotSurface(label_id, static_cast<const np_uint_l *>(xs_from_pyarray), static_cast<int>(xs_count), static_cast<const np_uint_l *>(ys_from_pyarray), static_cast<int>(ys_count), static_cast<const np_uint_l *>(zs_from_pyarray), static_cast<int>(zs_count), x_count, y_count, scale_min, scale_max, flags, offset, zs_stride);
778780
else if (zs_type == 'l')
779-
ImPlot3D::PlotSurface(label_id, static_cast<const np_int_l *>(xs_from_pyarray), static_cast<const np_int_l *>(ys_from_pyarray), static_cast<const np_int_l *>(zs_from_pyarray), static_cast<int>(zs_count), y_count, scale_min, scale_max, flags, offset, zs_stride);
781+
ImPlot3D::PlotSurface(label_id, static_cast<const np_int_l *>(xs_from_pyarray), static_cast<int>(xs_count), static_cast<const np_int_l *>(ys_from_pyarray), static_cast<int>(ys_count), static_cast<const np_int_l *>(zs_from_pyarray), static_cast<int>(zs_count), x_count, y_count, scale_min, scale_max, flags, offset, zs_stride);
780782
else if (zs_type == 'f')
781-
ImPlot3D::PlotSurface(label_id, static_cast<const float *>(xs_from_pyarray), static_cast<const float *>(ys_from_pyarray), static_cast<const float *>(zs_from_pyarray), static_cast<int>(zs_count), y_count, scale_min, scale_max, flags, offset, zs_stride);
783+
ImPlot3D::PlotSurface(label_id, static_cast<const float *>(xs_from_pyarray), static_cast<int>(xs_count), static_cast<const float *>(ys_from_pyarray), static_cast<int>(ys_count), static_cast<const float *>(zs_from_pyarray), static_cast<int>(zs_count), x_count, y_count, scale_min, scale_max, flags, offset, zs_stride);
782784
else if (zs_type == 'd')
783-
ImPlot3D::PlotSurface(label_id, static_cast<const double *>(xs_from_pyarray), static_cast<const double *>(ys_from_pyarray), static_cast<const double *>(zs_from_pyarray), static_cast<int>(zs_count), y_count, scale_min, scale_max, flags, offset, zs_stride);
785+
ImPlot3D::PlotSurface(label_id, static_cast<const double *>(xs_from_pyarray), static_cast<int>(xs_count), static_cast<const double *>(ys_from_pyarray), static_cast<int>(ys_count), static_cast<const double *>(zs_from_pyarray), static_cast<int>(zs_count), x_count, y_count, scale_min, scale_max, flags, offset, zs_stride);
784786
else if (zs_type == 'g')
785-
ImPlot3D::PlotSurface(label_id, static_cast<const long double *>(xs_from_pyarray), static_cast<const long double *>(ys_from_pyarray), static_cast<const long double *>(zs_from_pyarray), static_cast<int>(zs_count), y_count, scale_min, scale_max, flags, offset, zs_stride);
787+
ImPlot3D::PlotSurface(label_id, static_cast<const long double *>(xs_from_pyarray), static_cast<int>(xs_count), static_cast<const long double *>(ys_from_pyarray), static_cast<int>(ys_count), static_cast<const long double *>(zs_from_pyarray), static_cast<int>(zs_count), x_count, y_count, scale_min, scale_max, flags, offset, zs_stride);
786788
else if (zs_type == 'q')
787-
ImPlot3D::PlotSurface(label_id, static_cast<const long long *>(xs_from_pyarray), static_cast<const long long *>(ys_from_pyarray), static_cast<const long long *>(zs_from_pyarray), static_cast<int>(zs_count), y_count, scale_min, scale_max, flags, offset, zs_stride);
789+
ImPlot3D::PlotSurface(label_id, static_cast<const long long *>(xs_from_pyarray), static_cast<int>(xs_count), static_cast<const long long *>(ys_from_pyarray), static_cast<int>(ys_count), static_cast<const long long *>(zs_from_pyarray), static_cast<int>(zs_count), x_count, y_count, scale_min, scale_max, flags, offset, zs_stride);
788790
// If we reach this point, the array type is not supported!
789791
else
790792
throw std::runtime_error(std::string("Bad array type ('") + zs_type + "') for param zs");
791793
};
792794

793-
PlotSurface_adapt_c_buffers(label_id, xs, ys, zs, y_count, scale_min, scale_max, flags, offset, stride);
795+
PlotSurface_adapt_c_buffers(label_id, xs, ys, zs, x_count, y_count, scale_min, scale_max, flags, offset, stride);
794796
},
795-
nb::arg("label_id"), nb::arg("xs"), nb::arg("ys"), nb::arg("zs"), nb::arg("y_count"), nb::arg("scale_min") = 0.0, nb::arg("scale_max") = 0.0, nb::arg("flags") = 0, nb::arg("offset") = 0, nb::arg("stride") = -1,
796-
"Plot the surface defined by a grid of vertices. The grid is defined by the x and y arrays, and the z array contains the height of each vertex. A total of x_count * y_count vertices are expected for each array. Leave #scale_min and #scale_max both at 0 for automatic color scaling, or set them to a predefined range.");
797+
nb::arg("label_id"), nb::arg("xs"), nb::arg("ys"), nb::arg("zs"), nb::arg("x_count"), nb::arg("y_count"), nb::arg("scale_min") = 0.0, nb::arg("scale_max") = 0.0, nb::arg("flags") = 0, nb::arg("offset") = 0, nb::arg("stride") = -1,
798+
" Plot the surface defined by a grid of vertices. The grid is defined by the x and y arrays,\n and the z array contains the height of each vertex.\n A total of x_count * y_count vertices are expected for each array.\n Leave #scale_min and #scale_max both at 0 for automatic color scaling, or set them to a predefined range.");
799+
// #endif
800+
//
797801

798802
m.def("plot_mesh",
799803
ImPlot3D::PlotMesh, nb::arg("label_id"), nb::arg("vtx"), nb::arg("idx"), nb::arg("vtx_count"), nb::arg("idx_count"), nb::arg("flags") = 0);

external/implot3d/implot3d

0 commit comments

Comments
 (0)