OpenNI 2.0
C++ API Conventions

Classes vs. Structs

In general, classes are preferred, along with getX() / setX() methods. This allows extending the API in the future without breaking compatibility. In cases of "super-primitives" (like openni::RGB888Pixel), structs are used.

Return Values from Methods

Arguments to Methods

Object Lifetime

Some objects have their lifetime goverened by the user. For example, a openni::VideoStream is created using the create() method and destroyed by calling destroy(). In those cases, it is important that they get destroyed in the right order. For example, if you create a openni::VideoStream on a specific openni::Device, don't close the device before destroying that video stream. In the same manner, all openni::VideoFrameRef objects should be released before destroying the stream, and all OpenNI objects should be destroyed before calling openni::OpenNI::shutdown().

Other objects are not created by the user, but are actually members of other objects. For example, calling openni::Device::getDeviceInfo() returns a reference to a openni::DeviceInfo object. Note that once the openni::Device object that was used gets closed, the openni::DeviceInfo reference is no longer valid. Do not try to use it to access methods of the openni::DeviceInfo object.

Arrays

Some methods return an array of items. We created a very simple template class, openni::Array, which only holds the pointer to the underlying C array and the number of elements in that array. Once the array has been released, the elements are no longer accessible. Do not keep a pointer to a specific item in the array and use it after releasing it.