newimage
 
Loading...
Searching...
No Matches
positerators.h
1/* Templated iterators for the image storage class (which uses lazymanager)
2
3 Mark Jenkinson, FMRIB Image Analysis Group
4
5 Copyright (C) 2000 University of Oxford */
6
7/* CCOPYRIGHT */
8
9#if !defined(__positerators_h)
10#define __positerators_h
11
12#include <cstdlib>
13#include "lazy.h"
14#include <iostream>
15
16namespace NEWIMAGE {
17
18 //---------------------------------------------------------------------//
19
20 // Mutable, Forward Iterator
21
22 template <class T>
24 private:
25 T* iter;
26 LAZY::lazymanager* lazyptr;
27 int x;
28 int y;
29 int z;
30 int lx0;
31 int ly0;
32 int lz0;
33 int lx1;
34 int ly1;
35 int lz1;
36 int RowAdjust;
37 int SliceAdjust;
38
39 void calc_offsets(int rowoff, int sliceoff) {
40 RowAdjust = rowoff + (lx0 - lx1);
41 SliceAdjust = sliceoff + rowoff*(ly0 - ly1) + (lx0 - lx1);
42 }
43
44 public:
45 poslazyiterator() : lazyptr(0) { }
47 { this->operator=(source); }
48 poslazyiterator(T* sourceptr, LAZY::lazymanager* lazyp,
49 int xinit, int yinit, int zinit,
50 int x0, int y0, int z0, int x1, int y1, int z1,
51 int rowoff, int sliceoff) :
52 iter(sourceptr), lazyptr(lazyp), x(xinit), y(yinit), z(zinit),
53 lx0(x0), ly0(y0), lz0(z0), lx1(x1), ly1(y1), lz1(z1)
54 { calc_offsets(rowoff,sliceoff); }
55 ~poslazyiterator() { } // do nothing
56
57 inline const poslazyiterator<T> operator++(int)
58 { poslazyiterator<T> tmp=*this; ++(*this); return tmp; }
59 inline const poslazyiterator<T>& operator++() // prefix
60 { x++; if (x>lx1) { x=lx0; y++;
61 if (y>ly1) { y=ly0; z++; if (z>lz1) { ++iter; } // end condition
62 else { iter+=SliceAdjust; } }
63 else { iter+=RowAdjust; } }
64 else { ++iter;} return *this; }
65
66 inline bool operator==(const poslazyiterator<T>& it) const
67 { return iter == it.iter; }
68 inline bool operator!=(const poslazyiterator<T>& it) const
69 { return iter != it.iter; }
70
71 inline void getposition(int &rx, int &ry, int &rz) const
72 { rx= x; ry = y; rz = z; }
73 inline const int& getx() const { return x; }
74 inline const int& gety() const { return y; }
75 inline const int& getz() const { return z; }
76
77 inline const poslazyiterator<T>&
78 operator=(const poslazyiterator<T>& source)
79 { iter = source.iter; lazyptr = source.lazyptr;
80 lx0=source.lx0; ly0=source.ly0; lz0=source.lz0;
81 lx1=source.lx1; ly1=source.ly1; lz1=source.lz1;
82 x=source.x; y=source.y; z=source.z;
83 RowAdjust = source.RowAdjust; SliceAdjust = source.SliceAdjust;
84 return *this; }
85
86 inline T& operator*() const
87 { lazyptr->set_whole_cache_validity(false); return *iter;}
88 };
89
90
91 //---------------------------------------------------------------------//
92
93 // Constant, Forward Iterator
94
95 template <class T>
97 private:
98 T* iter;
99 int x;
100 int y;
101 int z;
102 int lx0;
103 int ly0;
104 int lz0;
105 int lx1;
106 int ly1;
107 int lz1;
108 int RowAdjust;
109 int SliceAdjust;
110
111 void calc_offsets(int rowoff, int sliceoff) {
112 RowAdjust = rowoff + (lx0 - lx1);
113 SliceAdjust = sliceoff + rowoff*(ly0 - ly1) + (lx0 - lx1);
114 }
115
116 public:
117 posconstiterator() { }
119 { this->operator=(source); }
120 posconstiterator(T* sourceptr,
121 int xinit, int yinit, int zinit,
122 int x0, int y0, int z0, int x1, int y1, int z1,
123 int rowoff, int sliceoff) :
124 iter(sourceptr), x(xinit), y(yinit), z(zinit),
125 lx0(x0), ly0(y0), lz0(z0), lx1(x1), ly1(y1), lz1(z1)
126 { calc_offsets(rowoff,sliceoff); }
127 ~posconstiterator() { } // do nothing
128
129 inline const posconstiterator<T> operator++(int)
130 { posconstiterator<T> tmp=*this; ++(*this); return tmp; }
131 inline const posconstiterator<T>& operator++() // prefix
132 { x++; if (x>lx1) { x=lx0; y++;
133 if (y>ly1) { y=ly0; z++; if (z>lz1) { ++iter; } // end condition
134 else { iter+=SliceAdjust; } }
135 else { iter+=RowAdjust; } }
136 else { ++iter;} return *this; }
137
138 inline bool operator==(const posconstiterator<T>& it) const
139 { return iter == it.iter; }
140 inline bool operator!=(const posconstiterator<T>& it) const
141 { return iter != it.iter; }
142
143 inline void getposition(int &rx, int &ry, int &rz) const
144 { rx= x; ry = y; rz = z; }
145 inline const int& getx() const { return x; }
146 inline const int& gety() const { return y; }
147 inline const int& getz() const { return z; }
148
149 inline const posconstiterator<T>&
150 operator=(const posconstiterator<T>& source)
151 { iter = source.iter;
152 lx0=source.lx0; ly0=source.ly0; lz0=source.lz0;
153 lx1=source.lx1; ly1=source.ly1; lz1=source.lz1;
154 x=source.x; y=source.y; z=source.z;
155 RowAdjust = source.RowAdjust; SliceAdjust = source.SliceAdjust;
156 return *this; }
157
158 inline const T& operator*() const { return *iter;}
159 };
160
161
162
163 //---------------------------------------------------------------------//
164
165} // end namespace
166
167#endif
Definition: lazy.h:50
Definition: positerators.h:96
Definition: positerators.h:23