Previous: Indirection Cartesian product, Up: Indirection [Contents][Index]
You can also do indirection with a container of one-dimensional strips. This is useful when you want to manipulate some arbitrarily-shaped, well-connected subdomain of an array. By representing the subdomain as a list of strips, you allow Blitz++ to operate on vectors, rather than scattered points; this is much more efficient.
Strips are represented by objects of type RectDomain<N>, where
N is the dimensionality of the array. The RectDomain<N> class
can be used to represent any rectangular subdomain, but for indirection it
is only used to represent strips.
You create a strip by using this function:
RectDomain<N> strip(TinyVector<int,N> start,
int stripDimension, int ubound);
The start parameter is where the strip starts; stripDimension
is the dimension in which the strip runs; ubound is the last index
value for the strip. For example, to create a 2-dimensional strip from
(2,5) to (2,9), one would write:
TinyVector<int,2> start(2,5); RectDomain<2> myStrip = strip(start,secondDim,9);
Here is a more substantial example which creates a list of strips representing a circle subset of an array:
const int N = 7;
Array<int,2> A(N,N), B(N,N);
typedef TinyVector<int,2> coord;
A = 0;
B = 1;
double centre_i = (N-1)/2.0;
double centre_j = (N-1)/2.0;
double radius = 0.8 * N/2.0;
// circle will contain a list of strips which represent a circular
// subdomain.
list<RectDomain<2> > circle;
for (int i=0; i < N; ++i)
{
double jdist2 = pow2(radius) - pow2(i-centre_i);
if (jdist2 < 0.0)
continue;
int jdist = int(sqrt(jdist2));
coord startPos(i, int(centre_j - jdist));
circle.push_back(strip(startPos, secondDim, int(centre_j + jdist)));
}
// Set only those points in the circle subdomain to 1
A[circle] = B;
After this code, the A array contains:
0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 1 1 1 1 1 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0
Previous: Indirection Cartesian product, Up: Indirection [Contents][Index]