Skip to content

Commit

Permalink
update implot3d ([Bundle] PlotSurface - add a version whose API is ea…
Browse files Browse the repository at this point in the history
…sier to port)
  • Loading branch information
pthom committed Jan 2, 2025
1 parent 7073c68 commit fae8b66
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 20 deletions.
28 changes: 26 additions & 2 deletions bindings/imgui_bundle/implot3d/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -639,22 +639,46 @@ def plot_quad(
) -> None:
pass

# 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 */
# [ADAPT_IMGUI_BUNDLE]
# #ifdef IMGUI_BUNDLE_PYTHON_API
#
# A version of PlotSurface whose API is easier to port to Python
# (params xs_count, ys_count and zs_count are removed in the Python API, but are used in the bindings code generation)

# IMPLOT3D_TMP void PlotSurface( /* original C++ signature */
# const char* label_id,
# const T* xs, int xs_count,
# const T* ys, int ys_count,
# const T* zs, int zs_count,
# 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));
def plot_surface(
label_id: str,
xs: np.ndarray,
ys: np.ndarray,
zs: np.ndarray,
x_count: int,
y_count: int,
scale_min: float = 0.0,
scale_max: float = 0.0,
flags: SurfaceFlags = 0,
offset: int = 0,
stride: int = -1,
) -> None:
"""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."""
"""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.
"""
pass

# #endif
#
# [/ADAPT_IMGUI_BUNDLE]

# 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 */
def plot_mesh(label_id: str, vtx: Point, idx: int, vtx_count: int, idx_count: int, flags: MeshFlags = 0) -> None:
pass
Expand Down
38 changes: 21 additions & 17 deletions external/implot3d/bindings/pybind_implot3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,11 +701,13 @@ void py_init_module_implot3d(nb::module_& m)

PlotQuad_adapt_c_buffers(label_id, xs, ys, zs, flags, offset, stride);
}, 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);
// #ifdef IMGUI_BUNDLE_PYTHON_API
//

m.def("plot_surface",
[](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)
[](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)
{
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)
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)
{
// Check if the array is 1D and C-contiguous
if (! (xs.ndim() == 1 && xs.stride(0) == 1))
Expand Down Expand Up @@ -762,38 +764,40 @@ void py_init_module_implot3d(nb::module_& m)

// call the correct template version by casting
if (zs_type == 'B')
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);
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);
else if (zs_type == 'b')
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);
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);
else if (zs_type == 'H')
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);
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);
else if (zs_type == 'h')
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);
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);
else if (zs_type == 'I')
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);
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);
else if (zs_type == 'i')
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);
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);
else if (zs_type == 'L')
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);
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);
else if (zs_type == 'l')
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);
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);
else if (zs_type == 'f')
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);
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);
else if (zs_type == 'd')
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);
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);
else if (zs_type == 'g')
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);
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);
else if (zs_type == 'q')
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);
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);
// If we reach this point, the array type is not supported!
else
throw std::runtime_error(std::string("Bad array type ('") + zs_type + "') for param zs");
};

PlotSurface_adapt_c_buffers(label_id, xs, ys, zs, y_count, scale_min, scale_max, flags, offset, stride);
PlotSurface_adapt_c_buffers(label_id, xs, ys, zs, x_count, y_count, scale_min, scale_max, flags, offset, stride);
},
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,
"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.");
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,
" 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.");
// #endif
//

m.def("plot_mesh",
ImPlot3D::PlotMesh, nb::arg("label_id"), nb::arg("vtx"), nb::arg("idx"), nb::arg("vtx_count"), nb::arg("idx_count"), nb::arg("flags") = 0);
Expand Down
2 changes: 1 addition & 1 deletion external/implot3d/implot3d
Submodule implot3d updated 2 files
+23 −0 implot3d.h
+27 −0 implot3d_items.cpp

0 comments on commit fae8b66

Please sign in to comment.