OpenVDB  2.0.0
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

 pyopenvdb
 

Functions

boost::python::object getPyObjectFromGrid (const openvdb::GridBase::Ptr &)
 Return a new Python object that holds the given OpenVDB grid. More...
 
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 &)
 Return a pointer to the OpenVDB grid held by the given Python object. 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.
* {
* grid = grid->deepCopyGrid();
*
* // Process the grid...
*
* // Wrap the processed grid in a PyObject.
* }
* } catch (openvdb::TypeError& e) {
* PyErr_Format(PyExc_TypeError, e.what());
* boost::python::throw_error_already_set();
* }
* return outObj;
* }
*
* BOOST_PYTHON_MODULE(mymodule)
* {
*
* // Definition of a Python function that processes pyOpenVDB grids
* boost::python::def(/*name=*/"processGrid", &processGrid, /*argname=*/"grid");
* }
*

Then, from Python,

* import openvdb
* import mymodule
*
* grid = openvdb.read('myGrid.vdb', 'MyGrid')
* grid = mymodule.processGrid(grid)
* openvdb.write('myProcessedGrid.vdb', [grid])
*