LoAdSG
iterator_neu.h
1#ifndef ITERATORNEU_H
2#define ITERATORNEU_H
3
4#include "celldimension.h"
5#include "../myMath/myMath.h"
6
7template<unsigned int N>
8struct PowerOfTwo {
9 static const unsigned int value = 2 * PowerOfTwo<N-1>::value;
10};
11
12template<>
13struct PowerOfTwo<0> {
14 static const unsigned int value = 1;
15};
16
17
18template <unsigned int N>
19struct TriangularNumber {
20 static const unsigned int value = N * (N + 1) / 2;
21};
22
23
24class RectangularIteratorCells {
25public:
26 RectangularIteratorCells(CellDimension& A_, CellDimension &B_);
27
28
29
30
31 CellDimension getCell() { return P; }
32
33 bool goon() { return weiter; }
34
35 void operator++();
36
37
38
39protected:
40 CellDimension A;
41 CellDimension B;
42 int level[DimensionSparseGrid];
43 CellDimension P;
44 bool weiter;
45
46};
47
48
49class CellIndexDirection{
50public:
51
52 CellIndexDirection(){
53 for(int d=0; d<DimensionSparseGrid; d++) directions[d]=Left;
54 };
55 void setDirection(int d, Direction dir){directions[d]=dir;}
56 Direction getDirection(int d){return directions[d];}
57private:
58 Direction directions[DimensionSparseGrid];
59};
60
61
62
63class CellIndexIterator{
64public:
65 CellIndexIterator(CellDimension* parent_){
66
67 IndexDimension centerOfCell;
68 for(int d=0; d< DimensionSparseGrid; d++){
69 level[d]= parent_->getDepth(d);
70 centerOfCell.replace(d, parent_->getIndex(d));
71 }
72
73 A = centerOfCell;
74 B = centerOfCell;
75 for(int d=0; d<DimensionSparseGrid; d++){
76 A = A.nextLeft(d,level[d]);
77 B = B.nextRight(d,level[d]);
78 level[d]--;
79 cellIndexDirection.setDirection(d,Left);
80 }
81
82 //CellIndexDirection cellIndexDirection_cp = cellIndexDirection;
83
84 //P=A;
85 //weiter = true;
86
87 //cellIndexDirection1 = new CellIndexDirection[number_indices];
88 //Indices = new IndexDimension[number_indices];
89 /*for(int i=0; i< number_indices;i++){
90 Indices[i]=P;
91 cellIndexDirection1[i] = cellIndexDirection;
92 operator++();
93 }*/
94
95 //cellIndexDirection = cellIndexDirection_cp;
96 P=A;
97 weiter=true;
98
99
100 };
101
102
103 CellIndexIterator(CellIndexIterator const &iterator_parent){
104 A = iterator_parent.A;
105 B = iterator_parent.B;
106 for(int d=0; d<DimensionSparseGrid; d++){
107 level[d]=iterator_parent.level[d];
108 cellIndexDirection.setDirection(d,iterator_parent.getCellIndexDirection().getDirection(d));
109 }
110
111 P=iterator_parent.P;
112 weiter = iterator_parent.weiter;
113
114
115 }
116
117/* CellIndexIterator(CellIndexIterator &iterator_parent, int iter_index){
118 A = iterator_parent.A;
119 B = iterator_parent.B;
120 for(int d=0; d<DimensionSparseGrid; d++){
121 level[d]=iterator_parent.level[d];
122 }
123
124
125 cellIndexDirection = iterator_parent.getCellIndexDirection(iter_index);
126 P=iterator_parent.getIndex(iter_index);
127
128 weiter = true;
129
130
131 }*/
132 CellIndexIterator(CellDimension* parent_, IndexDimension& indexDimension, Direction* dir){
133
134 IndexDimension centerOfCell;
135 for(int d=0; d< DimensionSparseGrid; d++){
136 level[d]= parent_->getDepth(d);
137 centerOfCell.replace(d, parent_->getIndex(d));
138 }
139
140 A = centerOfCell;
141 B = centerOfCell;
142 for(int d=0; d<DimensionSparseGrid; d++){
143 A = A.nextLeft(d,level[d]);
144 B = B.nextRight(d,level[d]);
145 level[d]--;
146
147
148 }
149 P=indexDimension;
150 weiter = true;
151
152
153
154 };
155
156 IndexDimension getIndex() {
157 //return Indices[current_i];
158 return P;
159 }
160
161 //IndexDimension getIndex(int i){return Indices[i];}
162
163 IndexDimension getIndexByBinary(int i){
164
165
166 bool binary[DimensionSparseGrid];
167
168 for (int d = DimensionSparseGrid - 1; d >= 0; --d) {
169 binary[d] = i & 1;
170 i >>= 1;
171 }
172
173 IndexDimension Index=A;
174 for(int d=0; d<DimensionSparseGrid; d++){
175 if(binary[d]){
176 Index = Index.nextRight(d,level[d]);
177 cellIndexDirection.setDirection(d,Right);
178 }else{
179 cellIndexDirection.setDirection(d,Left);
180 }
181 }
182 return Index;
183 }
184
185
186
187
188
189
190 CellIndexDirection getCellIndexDirection() const {return cellIndexDirection;}
191 //CellIndexDirection getCellIndexDirection(int i) const {return cellIndexDirection1[i];}
192
193 bool goon() {
194 return weiter; }
195
196 void operator++();
197
198
199
200
201private:
202
203
204 IndexDimension A;
205 IndexDimension B;
206 IndexDimension P;
207
208 int number_indices = PowerOfTwo<DimensionSparseGrid>::value;
209
210 bool weiter;
211 int level[DimensionSparseGrid];
212 //Direction directions[DimensionSparseGrid];
213 CellIndexDirection cellIndexDirection;
214 //CellIndexDirection cellIndexDirection1[PowerOfTwo<DimensionSparseGrid>::value];
215 //IndexDimension Indices[PowerOfTwo<DimensionSparseGrid>::value];
216
217};
218
219
220
221#endif