OpenVDB: openvdb/python/pyopenvdb.h File Reference

OpenVDB 10.0.1

Namespaces | Functions
pyopenvdb.h File Reference

Glue functions for access to pyOpenVDB objects from C++ code. More...

`#include <boost/python.hpp>`
`#include <openvdb/Grid.h>`

Go to the source code of this file.

## Namespaces
namespace | pyopenvdb

## Functions
openvdb::GridBase::Ptr | getGridFromPyObject (PyObject *)
| Return a pointer to the OpenVDB grid held by the given Python object. More...
openvdb::GridBase::Ptr | getGridFromPyObject (const boost::python::object &)
boost::python::object | getPyObjectFromGrid (const openvdb::GridBase::Ptr &)
| Return a new Python object that holds the given OpenVDB grid. More...

## Detailed Description

Glue functions for access to pyOpenVDB objects from C++ code.

Use these functions in your own Python function implementations to extract an OpenVDB grid from or wrap a grid in a `PyObject`. For example (using Boost.Python),

#include <openvdb.h>
#include <pyopenvdb.h>
#include <boost/python.hpp>
// Implementation of a Python function that processes pyOpenVDB grids
boost::python::object
processGrid(boost::python::object inObj)
{
boost::python::object outObj;
try {
// Extract an OpenVDB grid from the input argument.
if (openvdb::GridBase::Ptr grid =
pyopenvdb::getGridFromPyObject(inObj))
{
grid = grid->deepCopyGrid();
// Process the grid...
// Wrap the processed grid in a PyObject.
outObj = pyopenvdb::getPyObjectFromGrid(grid);
}
} catch (openvdb::TypeError& e) {
PyErr_Format(PyExc_TypeError, e.what());
boost::python::throw_error_already_set();
}
return outObj;
}
BOOST_PYTHON_MODULE(mymodule)
{
openvdb::initialize();
// Definition of a Python function that processes pyOpenVDB grids
boost::python::def(/*name=*/"processGrid", &processGrid, /*argname=*/"grid");
}
openvdb::v10_0::Exception::what
const char * what() const noexcept override
Definition: Exceptions.h:26
openvdb::v10_0::GridBase::Ptr
SharedPtr< GridBase > Ptr
Definition: Grid.h:80
openvdb::v10_0::TypeError
Definition: Exceptions.h:64
openvdb::v10_0::initialize
OPENVDB_IMPORT void initialize()
Global registration of native Grid, Transform, Metadata and Point attribute types....
pyopenvdb::getGridFromPyObject
openvdb::GridBase::Ptr getGridFromPyObject(PyObject *)
Return a pointer to the OpenVDB grid held by the given Python object.
pyopenvdb::getPyObjectFromGrid
boost::python::object getPyObjectFromGrid(const openvdb::GridBase::Ptr &)
Return a new Python object that holds the given OpenVDB grid.
openvdb.h
pyopenvdb.h
Glue functions for access to pyOpenVDB objects from C++ code.

Then, from Python,

import openvdb
import mymodule
grid = openvdb.read('myGrid.vdb', 'MyGrid')
grid = mymodule.processGrid(grid)
openvdb.write('myProcessedGrid.vdb', [grid])
openvdb
Definition: Exceptions.h:13