Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions nanovdb/nanovdb/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ nanobind_add_module(nanovdb_python NB_STATIC
PyGridHandle.cc
PyGridStats.cc
PyGridValidator.cc
PyHostBuffer.cc
PyIO.cc
PyMath.cc
PyNanoToOpenVDB.cc
Expand All @@ -31,7 +30,6 @@ nanobind_add_module(nanovdb_python NB_STATIC
PyTools.cc
PyTree.cc
PyVoxelBlockManager.cc
cuda/PyDeviceBuffer.cc
cuda/PyDeviceGridHandle.cu
cuda/PyPointsToGrid.cu
cuda/PySampleFromVoxels.cu
Expand Down
7 changes: 1 addition & 6 deletions nanovdb/nanovdb/python/NanoVDBModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@

#include <sstream>

#include "cuda/PyDeviceBuffer.h"
#include "PyBuildGrid.h"
#include "PyGridHandle.h"
#include "PyHostBuffer.h"
#include "PyIO.h"
#include "PyMath.h"
#include "PyTools.h"
Expand Down Expand Up @@ -1189,8 +1187,7 @@ NB_MODULE(nanovdb, m)
defineAccessor<T>(m, #Suffix "ReadAccessor");
#include "BuildTypes.def"

// Host-side NodeManagerHandle + module-scope createNodeManager.
defineNodeManagerHandle(m);
// Module-scope createNodeManager (returns the typed NodeManager).
defineCreateNodeManager(m);

// PointAccessor variants — PointIndex grids carry uint32 indices,
Expand All @@ -1214,11 +1211,9 @@ NB_MODULE(nanovdb, m)
"channel of an IndexGrid or OnIndexGrid, dispatching on the "
"channel's recorded dataType. The accessor keeps the grid alive.");

defineHostBuffer(m);
defineHostGridHandle(m);

#ifdef NANOVDB_USE_CUDA
defineDeviceBuffer(m);
defineDeviceGridHandle(m);
#endif

Expand Down
22 changes: 21 additions & 1 deletion nanovdb/nanovdb/python/PyGridHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ template<typename BufferT> nb::class_<nanovdb::GridHandle<BufferT>> defineGridHa
return nb::class_<nanovdb::GridHandle<BufferT>>(m, name,
"Owns a buffer holding one or more serialized NanoVDB grids. "
"Construct via nanovdb.tools.create* factories or nanovdb.io.readGrid(s); "
"access individual grids via handle.grid(n).")
"access individual grids via handle.grid(n), handle[i], or iteration.")
.def(nb::init<>(),
"Construct an empty handle. Use the nanovdb.tools.create* "
"factories or nanovdb.io.readGrid(s) instead in normal use.")
Expand Down Expand Up @@ -124,6 +124,26 @@ template<typename BufferT> nb::class_<nanovdb::GridHandle<BufferT>> defineGridHa
"Return the n-th grid as a typed Grid subclass selected by "
"gridType(n), or None if the BuildT is not bound in Python. "
"The returned grid keeps this handle alive.")
.def("__len__", &nanovdb::GridHandle<BufferT>::gridCount,
"Number of grids stored in this handle (same as gridCount()).")
.def(
"__getitem__",
[](nb::handle py_handle, Py_ssize_t i) {
auto& handle = nb::cast<nanovdb::GridHandle<BufferT>&>(py_handle);
const Py_ssize_t count = static_cast<Py_ssize_t>(handle.gridCount());
if (i < 0) i += count;
if (i < 0 || i >= count)
throw nb::index_error("GridHandle index out of range [-gridCount(), gridCount()).");
return pyHostGrid<BufferT>(py_handle, static_cast<uint32_t>(i));
},
nb::arg("i"),
nb::keep_alive<0, 1>(),
"handle[i] -> the i-th grid as a typed Grid subclass (same "
"dispatch as grid(n)); negative indices count from the end. "
"Raises IndexError when out of range, which also makes handles "
"iterable via the sequence protocol (`for grid in handle`). "
"Grids whose BuildT is not bound in Python are returned as "
"None, matching grid(n).")
.def("isPadded", &nanovdb::GridHandle<BufferT>::isPadded,
"True iff this handle's buffer is aligned past the natural "
"GridData alignment (used by the I/O code path).")
Expand Down
20 changes: 0 additions & 20 deletions nanovdb/nanovdb/python/PyHostBuffer.cc

This file was deleted.

16 changes: 0 additions & 16 deletions nanovdb/nanovdb/python/PyHostBuffer.h

This file was deleted.

28 changes: 16 additions & 12 deletions nanovdb/nanovdb/python/PyIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ template<typename BufferT> void defineReadWriteGrid(nb::module_& m)
"Return a FileGridMetaDataVector describing every grid stored in the .nvdb file.");
}

template<typename BufferT> nb::list readGrids(const std::string& fileName, int verbose, const BufferT& buffer)
template<typename BufferT> nb::list readGrids(const std::string& fileName, int verbose)
{
auto handles = nanovdb::io::readGrids(fileName, verbose, buffer);
auto handles = nanovdb::io::readGrids<BufferT>(fileName, verbose);
nb::list handleList;
for (size_t i = 0; i < handles.size(); ++i) {
handleList.append(std::move(handles[i]));
Expand Down Expand Up @@ -123,20 +123,22 @@ void defineHostReadWriteGrid(nb::module_& m)
m.def("writeGrids", &writeGrids<BufferT>, "fileName"_a, "handles"_a, "codec"_a = io::Codec::NONE, "verbose"_a = 0,
"Write every GridHandle in the handles list to the .nvdb file at fileName.");
m.def("readGrid",
nb::overload_cast<const std::string&, int, int, const BufferT&>(&io::template readGrid<BufferT>),
[](const std::string& fileName, int n, int verbose) {
return io::template readGrid<BufferT>(fileName, n, verbose);
},
"fileName"_a,
"n"_a = 0,
"verbose"_a = 0,
"buffer"_a = BufferT(),
"Read the n-th grid from the .nvdb file at fileName into a fresh GridHandle.");
m.def("readGrid",
nb::overload_cast<const std::string&, const std::string&, int, const BufferT&>(&io::template readGrid<BufferT>),
[](const std::string& fileName, const std::string& gridName, int verbose) {
return io::template readGrid<BufferT>(fileName, gridName, verbose);
},
"fileName"_a,
"gridName"_a,
"verbose"_a = 0,
"buffer"_a = BufferT(),
"Read the grid named gridName from the .nvdb file at fileName into a fresh GridHandle.");
m.def("readGrids", &readGrids<BufferT>, "fileName"_a, "verbose"_a = 0, "buffer"_a = BufferT(),
m.def("readGrids", &readGrids<BufferT>, "fileName"_a, "verbose"_a = 0,
"Read every grid from the .nvdb file at fileName, returning a list of GridHandles.");
}

Expand All @@ -156,20 +158,22 @@ void defineDeviceReadWriteGrid(nb::module_& m)
m.def("deviceWriteGrids", &writeGrids<BufferT>, "fileName"_a, "handles"_a, "codec"_a = io::Codec::NONE, "verbose"_a = 0,
"Write every device-backed GridHandle in handles to the .nvdb file at fileName.");
m.def("deviceReadGrid",
nb::overload_cast<const std::string&, int, int, const BufferT&>(&io::template readGrid<BufferT>),
[](const std::string& fileName, int n, int verbose) {
return io::template readGrid<BufferT>(fileName, n, verbose);
},
"fileName"_a,
"n"_a = 0,
"verbose"_a = 0,
"buffer"_a = BufferT(),
"Read the n-th grid from the .nvdb file at fileName into a fresh DeviceGridHandle.");
m.def("deviceReadGrid",
nb::overload_cast<const std::string&, const std::string&, int, const BufferT&>(&io::template readGrid<BufferT>),
[](const std::string& fileName, const std::string& gridName, int verbose) {
return io::template readGrid<BufferT>(fileName, gridName, verbose);
},
"fileName"_a,
"gridName"_a,
"verbose"_a = 0,
"buffer"_a = BufferT(),
"Read the grid named gridName from the .nvdb file at fileName into a fresh DeviceGridHandle.");
m.def("deviceReadGrids", &readGrids<BufferT>, "fileName"_a, "verbose"_a = 0, "buffer"_a = BufferT(),
m.def("deviceReadGrids", &readGrids<BufferT>, "fileName"_a, "verbose"_a = 0,
"Read every grid from the .nvdb file at fileName into device-backed handles.");
}
#endif
Expand Down
Loading
Loading