Developer Documentation
Iterators and their usage

Overview

OpenFlipper comes with some build in iterators which are defined in PluginFunctions.hh .These iterators can be used to iterate over the objects in the current scene. They are described in the following sections.

ObjectIterator

The PluginFunctions::ObjectIterator iterates over all objects that have a visible representation in the scene (Meshes, Points, Lights, Skeletons, ...). If you also want to iterate over invisible objects (like groups) use the BaseObjectIterator. You can restrict it to source(PluginFunctions::SOURCE_OBJECTS) and target(PluginFunctions::TARGET_OBJECTS) objects or iterate over all objects (PluginFunctions::ALL_OBJECTS).

Additionally you can specify the DataType that will be returned by the iterator ( e.g. DATA_TRIANGLE_MESH, DATA_POLY_MESH ). The DataType can also be combined such that all specified types will be returned:

The type for iterating over all objects is: DATA_ALL.

Here is a simple example how you can use the iterator to get all target triangle meshes.

o_it != PluginFunctions::objectsEnd(); ++o_it) {
// Get the corresponding mesh object.
// Get the corresponding mesh.
TriMesh* mesh = PluginFunctions::triMesh(*o_it);
}

Second example how you can use the iterator to get all source skeletons.

o_it != PluginFunctions::objectsEnd(); ++o_it) {
// Get the corresponding mesh object.
// Get the corresponding mesh.
Skeleton* skeleton = PluginFunctions::skeleton(*o_it);
}

If you combine data types or iterate over all objects you need to check the DataType

o_it != PluginFunctions::objectsEnd(); ++o_it) {
// Check if this is a skeleton
if ( o_it->dataType(DATA_SKELETON) ) {
// Get the corresponding mesh object.
// Get the corresponding mesh.
Skeleton* skeleton = PluginFunctions::skeleton(*o_it);
} else if ( o_it->dataType(DATA_TRIANGLE_MESH) ) {
// Get the corresponding mesh object.
// Get the corresponding mesh.
TriMesh* mesh = PluginFunctions::triMesh(*o_it);
}
}

BaseObjectIterator

The PluginFunctions::BaseObjectIterator works like the ObjectIterator, but also returns objects that do not have a visible representation in the scene. A simple example is given in the following code:

unsigned int count = 0;
// Iterate over all objects of type DATA_GROUP and count them
o_it != PluginFunctions::objectsEnd(); ++o_it)
++count;