#include <RslPlugin.h>
Public Member Functions | |
RslArrayIter (const RslArg *arg) | |
Construct an array iterator from an argument. | |
RslArrayIter (const T *data, int length, const RslContext *ctx) | |
Construct a uniform array iterator for user-provided data. | |
T * | operator * () |
Dereference this iterator, yielding a pointer to the start of the array. | |
T & | operator[] (int x) |
The array index operator can be used to access individual array members. | |
RslArrayIter< T > & | operator++ () |
Increment this iterator to point to the array for the next active point. | |
RslArrayIter< T > | operator++ (int) |
Post-increment this iterator. | |
bool | IsVarying () const |
Returns true if the iterator is varying. | |
int | GetLength () const |
Returns the array length. | |
int | GetCapacity () const |
Returns the array capacity. | |
template<> | |
RslArrayIter< RtMatrix > & | operator++ () |
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.
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 int averageColor(RslContext* rslContext, int argc, const RslArg** argv) { assert(argv[0]->IsColor()); assert(argv[1]->IsColor() && argv[1]->IsArray()); RslColorIter result(argv[0]); RslColorArrayIter colors(argv[1]); int numColors = colors.GetLength(); int n = argv[0]->NumValues(); for (int i = 0; i < n; ++i) { RtColor avg = {0.0f, 0.0f, 0.0f}; for (int j = 0; j < numColors; ++j) { // Note that we index the array iterator using operator[]. 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; // Increment iterators ++result; ++colors; } return 0; }
|
Construct an array iterator from an argument.
|
|
Construct a uniform array iterator for user-provided data. This is useful for optional arguments with default values. |
|
Returns the array capacity.
|
|
Returns the array length.
|
|
Returns true if the iterator is varying. Note that uniform iterators need not be incremented (although it does no harm). |
|
Dereference this iterator, yielding a pointer to the start of the array.
|
|
|
|
Post-increment this iterator. Returns a copy of the iterator prior to incrementing, so it's not terribly efficient. The dummy integer argument is the standard C++ way of distinguishing between pre- and post-increment operators. |
|
Increment this iterator to point to the array for the next active point. An internal acceleration structure makes this a constant-time operation. |
|
The array index operator can be used to access individual array members.
|