Developer Documentation
Loading...
Searching...
No Matches
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:

#define DATA_POLY_MESH
Definition PolyMesh.hh:59
#define DATA_TRIANGLE_MESH
Predefined datatypes.
Definition DataTypes.hh:83

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.
}
Type for a MeshObject containing a triangle mesh.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
TriMeshObject * triMeshObject(BaseObjectData *_object)
Cast an BaseObject to a TriMeshObject if possible.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.
const QStringList TARGET_OBJECTS("target")
Iterable object range.

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);
}
#define DATA_SKELETON
Definition Skeleton.hh:64
SkeletonObject * skeletonObject(BaseObjectData *_object)
Cast an BaseObject to a SkeletonObject if possible.
Skeleton * skeleton(BaseObjectData *_object)
Get a skeleton from an object.
const QStringList SOURCE_OBJECTS("source")
Iterable object range.

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.
}
}
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
const QStringList ALL_OBJECTS
Iterable object range.

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;
const DataType DATA_GROUP(1)
Items used for Grouping.
Core Data Iterator used to iterate over all objects (Including groups)