template<typename T>
class RslArrayIter< T >
An iterator for array arguments. The length of an array is always uniform, and it can be obtained either from the iterator or the RslArg.
We recommend indexing an array iterator using operator[] rather than dereferencing the iterator. Dereferencing the iterator returns a pointer to the first array element, and indexing errors can arise if that pointer is not declared with the correct type. Also in API version 6, the layout of array data in memory has been transposed for improved cache performance. To avoid runtime errors in existing code, the dereference operator for array iterators has been conditionally disabled. It can be re-enabled by defining the RSL_ALLOW_ARRAY_DEREF flag.
Here is an example that demonstrates how arrays are typically used. It is a plugin function that computes the average value in an array of colors. Note the colors might be varying, so a doubly nested loop is required.
RSLEXPORT
assert(argv[0]->IsColor());
assert(argv[1]->IsColor() && argv[1]->IsArray());
RslColorIter result(argv[0]);
RslColorArrayIter colors(argv[1]);
int numColors = colors.GetLength();
for (int i = 0; i < n; ++i) {
RtColor avg = {0.0f, 0.0f, 0.0f};
for (int j = 0; j < numColors; ++j) {
RtColor& c = colors[j];
avg[0] += c[0];
avg[1] += c[1];
avg[2] += c[2];
}
(*result)[0] = avg[0] / numColors;
(*result)[1] = avg[1] / numColors;
(*result)[2] = avg[2] / numColors;
++result;
++colors;
}
return 0;
}