proj home

Files   Classes   Functions   Hierarchy  

spiralindex3D< T > Class Template Reference

Spiral in 3D moving along the z-axis. More...

#include <spiralindex.h>

Collaboration diagram for spiralindex3D< T >:

List of all members.

Public Member Functions

 spiralindex3D (T const _rows, T const _columns, T const _rectanglelength, boolc anticlockwise=true)
 Define a 3D matrix.
 ~spiralindex3D ()
 Memory cleanup.
void reset ()
 Reset the iterator.
boolc operator! () const
 Is the iterator valid?
void pos (T &row, T &col, T &z) const
 The current position as a 3D indexed point.
void pos (T &k2) const
 The current position as an index from the start.
void operator++ ()
 Increment the iterator.

Public Attributes

T const rows
 The number of rows.
T const columns
 The number of columns.
T const rectanglelength
 The length from the x-y plane.


Detailed Description

template<typename T = int>
class spiralindex3D< T >

Spiral in 3D moving along the z-axis.

This is a interator though a 3D matrix. Every elements neighbors are next to each other in the iteration.

The reverse iterator may be implemented in the future, as well as a matrix without the full indexes as the last slice is not full, similar to snakeindex.

Definition at line 93 of file spiralindex.h.


Constructor & Destructor Documentation

template<typename T >
spiralindex3D< T >::spiralindex3D ( T const   _rows,
T const   _columns,
T const   _rectanglelength,
boolc  anticlockwise = true 
) [inline]

Define a 3D matrix.

Definition at line 201 of file spiralindex.h.

References spiralindex< T >::indexsequence().

00207   : rows(_rows), columns(_columns),
00208   rectanglelength(_rectanglelength)
00209 {
00210   assert(rows>0);
00211   assert(columns>0);
00212 
00213   square0 = new T[rows*columns];
00214   square1 = square0 + rows*columns;
00215   spiralindex<T> spi(rows,columns,anticlockwise);
00216   spi.indexsequence(square0);
00217 
00218 /*
00219 cout << "square" << endl;
00220 for (int i=0; i<rows*columns; ++i)
00221   cout << square0[i] << " ";
00222 cout << endl << endl;
00223 */
00224 }

template<typename T >
spiralindex3D< T >::~spiralindex3D (  )  [inline]

Memory cleanup.

Definition at line 193 of file spiralindex.h.

00194 {
00195   delete[] square0;
00196 }


Member Function Documentation

template<typename T = int>
boolc spiralindex3D< T >::operator! (  )  const [inline]

Is the iterator valid?

Definition at line 129 of file spiralindex.h.

References spiralindex3D< T >::rectanglelength.

00130     { if (zcount<rectanglelength) return true; return false; }

template<typename T >
void spiralindex3D< T >::operator++ (  )  [inline]

Increment the iterator.

Definition at line 156 of file spiralindex.h.

00157 {
00158   ++icount;
00159 
00160   // Reverse spiral incrementation.
00161   if ((zcount % 2)==1)
00162   {
00163     --squarei;
00164     if (squarei+1==square0)
00165     {
00166       ++zcount;
00167       icount=0;
00168       ++squarei;
00169     }
00170 
00171     return;
00172   }
00173 
00174   ++squarei;
00175   if (squarei==square1)
00176   {
00177     ++zcount;
00178     icount=0;
00179     --squarei;
00180   }
00181 }

template<typename T = int>
void spiralindex3D< T >::pos ( T k2  )  const [inline]

The current position as an index from the start.

Definition at line 134 of file spiralindex.h.

References spiralindex3D< T >::columns, and spiralindex3D< T >::rows.

00135     { k2 = zcount*rows*columns + icount; }

template<typename T >
void spiralindex3D< T >::pos ( T row,
T col,
T z 
) const [inline]

The current position as a 3D indexed point.

Definition at line 147 of file spiralindex.h.

References spiralindex3D< T >::columns.

Referenced by spiralindextest::test03(), and spiralindextest::test04().

00148 {
00149   T k(*squarei);
00150   col = k % columns;
00151   row = (k-col)/columns;
00152   z = zcount;
00153 }

template<typename T >
void spiralindex3D< T >::reset (  )  [inline]

Reset the iterator.

Definition at line 185 of file spiralindex.h.

Referenced by spiralindextest::test03(), and spiralindextest::test04().

00186 {
00187   icount=0;
00188   zcount=0;
00189   squarei = square0;
00190 }


Member Data Documentation

template<typename T = int>
T const spiralindex3D< T >::columns

The number of columns.

Definition at line 111 of file spiralindex.h.

Referenced by spiralindex3D< T >::pos().

template<typename T = int>
T const spiralindex3D< T >::rectanglelength

The length from the x-y plane.

Definition at line 113 of file spiralindex.h.

Referenced by spiralindex3D< T >::operator!().

template<typename T = int>
T const spiralindex3D< T >::rows

The number of rows.

Definition at line 109 of file spiralindex.h.

Referenced by spiralindex3D< T >::pos().


The documentation for this class was generated from the following file:

Generated on Fri Mar 4 00:50:18 2011 for Chelton Evans Source by  doxygen 1.5.8