Files Classes Functions Hierarchy
#include <spiralindex.h>
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. | |
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.
| 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 }
| spiralindex3D< T >::~spiralindex3D | ( | ) | [inline] |
| 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; }
| 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 }
| 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.
| 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 }
| void spiralindex3D< T >::reset | ( | ) | [inline] |
Reset the iterator.
Definition at line 185 of file spiralindex.h.
Referenced by spiralindextest::test03(), and spiralindextest::test04().
| T const spiralindex3D< T >::columns |
The number of columns.
Definition at line 111 of file spiralindex.h.
Referenced by spiralindex3D< T >::pos().
| 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!().
| T const spiralindex3D< T >::rows |
The number of rows.
Definition at line 109 of file spiralindex.h.
Referenced by spiralindex3D< T >::pos().
1.5.8