Peano
Loading...
Searching...
No Matches
Index.h
Go to the documentation of this file.
1// This file is part of the Peano project. For conditions of distribution and
2// use, please see the copyright notice at www.peano-framework.org
3#pragma once
4
5#include <iostream>
6#include <sstream>
7#include <vector>
8
9namespace toolbox {
10 namespace curvi {
11 class Index {
12 public:
13 static std::vector<int> getIndexRange(int start, int size) {
14 std::vector<int> range;
15 for (int i = start; i < start + size; i++) {
16 range.push_back(i);
17 }
18 return range;
19 }
20
21
22 static std::vector<double> getRange(int start, int size, double dx, double ox = 0) {
23 std::vector<int> index_range = getIndexRange(start, size);
24 std::vector<double> range;
25 for (int i : index_range) {
26 range.push_back(i * dx + ox);
27 }
28 return range;
29 }
30 };
31
32 class idx2 {
33 public:
34 idx2(int a_J, int a_I):
35 J_(a_J),
36 I_(a_I) {
37 if (a_J <= 0 || a_I <= 0) {
38 std::stringstream ss;
39 ss << "Can't initialze index with 0 offset: " << a_J << " " << a_I;
40 throw std::domain_error(ss.str());
41 }
42 };
43
44 int operator()(int j, int i) const {
45 if (j < 0 || j > J_) {
46 std::stringstream ss;
47 ss << "J: " << j << " out of scope : " << J_ << std::endl;
48 throw std::domain_error(ss.str());
49 }
50 return j * I_ + i;
51 };
52
53 private:
54 int I_;
55 int J_;
56 };
57
58 class idx3 {
59 public:
60 idx3(int a_K, int a_J, int a_I):
61 K_(a_K),
62 J_(a_J),
63 I_(a_I) {
64 if (a_K <= 0 || a_J <= 0 || a_I <= 0) {
65 std::stringstream ss;
66 ss << "Can't initialze index with 0 offset: " << a_K << " " << a_J << " " << a_I;
67 throw std::domain_error(ss.str());
68 }
69 };
70
71 int operator()(int k, int j, int i) const {
72
73 if (i < 0 || i > I_) {
74 std::stringstream ss;
75 ss << "I: " << i << " out of scope : " << I_ << std::endl;
76 throw std::domain_error(ss.str());
77 }
78
79 if (j < 0 || j > J_) {
80 std::stringstream ss;
81 ss << "J: " << j << " out of scope : " << J_ << std::endl;
82 throw std::domain_error(ss.str());
83 }
84
85 if (k < 0 || k > K_) {
86 std::stringstream ss;
87 ss << "K: " << k << " out of scope : " << K_ << std::endl;
88 throw std::domain_error(ss.str());
89 }
90
91 return k * J_ * I_ + j * I_ + i;
92 };
93
94 private:
95 int I_;
96 int J_;
97 int K_;
98 };
99
100 class idx4 {
101 public:
102 idx4(int a_L, int a_K, int a_J, int a_I):
103 L_(a_L),
104 K_(a_K),
105 J_(a_J),
106 I_(a_I) {};
107
108 int operator()(int l, int k, int j, int i) const {
109
110
111 if (i < 0 || i > I_) {
112 std::stringstream ss;
113 ss << "I: " << i << " out of scope : " << I_ << std::endl;
114 throw std::domain_error(ss.str());
115 }
116
117 if (j < 0 || j > J_) {
118 std::stringstream ss;
119 ss << "J: " << j << " out of scope : " << J_ << std::endl;
120 throw std::domain_error(ss.str());
121 }
122
123 if (k < 0 || k > K_) {
124 std::stringstream ss;
125 ss << "K: " << k << " out of scope : " << K_ << std::endl;
126 throw std::domain_error(ss.str());
127 }
128
129 if (l < 0 || l > L_) {
130 std::stringstream ss;
131 ss << "L: " << l << " out of scope : " << L_ << std::endl;
132 throw std::domain_error(ss.str());
133 }
134 return l * K_ * J_ * I_ + k * J_ * I_ + j * I_ + i;
135 };
136
137 private:
138 int I_;
139 int J_;
140 int K_;
141 int L_;
142 };
143
144
145 class idx6 {
146 public:
147 idx6(int a_N, int a_M, int a_L, int a_K, int a_J, int a_I):
148 N_(a_N),
149 M_(a_M),
150 L_(a_L),
151 K_(a_K),
152 J_(a_J),
153 I_(a_I) {};
154
155 int operator()(int n, int m, int l, int k, int j, int i) const {
156
157 if (i < 0 || i > I_) {
158 std::stringstream ss;
159 ss << "I: " << i << " out of scope : " << I_ << std::endl;
160 throw std::domain_error(ss.str());
161 }
162
163 if (j < 0 || j > J_) {
164 std::stringstream ss;
165 ss << "J: " << j << " out of scope : " << J_ << std::endl;
166 throw std::domain_error(ss.str());
167 }
168
169 if (k < 0 || k > K_) {
170 std::stringstream ss;
171 ss << "K: " << k << " out of scope : " << K_ << std::endl;
172 throw std::domain_error(ss.str());
173 }
174
175 if (l < 0 || l > L_) {
176 std::stringstream ss;
177 ss << "L: " << l << " out of scope : " << L_ << std::endl;
178 throw std::domain_error(ss.str());
179 }
180
181 if (m < 0 || m > M_) {
182 std::stringstream ss;
183 ss << "M: " << m << " out of scope : " << M_ << std::endl;
184 throw std::domain_error(ss.str());
185 }
186
187 if (n < 0 || n > N_) {
188 std::stringstream ss;
189 ss << "N: " << n << " out of scope : " << N_ << std::endl;
190 throw std::domain_error(ss.str());
191 }
192
193 return n * M_ * L_ * K_ * J_ * I_ + m * L_ * K_ * J_ * I_ + l * K_ * J_ * I_ + k * J_ * I_ + j * I_ + i;
194 };
195
196 private:
197 int I_;
198 int J_;
199 int K_;
200 int L_;
201 int M_;
202 int N_;
203 };
204
205 class idx7 {
206 public:
207 idx7(int a_O, int a_N, int a_M, int a_L, int a_K, int a_J, int a_I):
208 O_(a_O),
209 N_(a_N),
210 M_(a_M),
211 L_(a_L),
212 K_(a_K),
213 J_(a_J),
214 I_(a_I) {};
215
216 int operator()(int o, int n, int m, int l, int k, int j, int i) const {
217
218 if (i < 0 || i > I_) {
219 std::stringstream ss;
220 ss << "I: " << i << " out of scope : " << I_ << std::endl;
221 throw std::domain_error(ss.str());
222 }
223
224 if (j < 0 || j > J_) {
225 std::stringstream ss;
226 ss << "J: " << j << " out of scope : " << J_ << std::endl;
227 throw std::domain_error(ss.str());
228 }
229
230 if (k < 0 || k > K_) {
231 std::stringstream ss;
232 ss << "K: " << k << " out of scope : " << K_ << std::endl;
233 throw std::domain_error(ss.str());
234 }
235
236 if (l < 0 || l > L_) {
237 std::stringstream ss;
238 ss << "L: " << l << " out of scope : " << L_ << std::endl;
239 throw std::domain_error(ss.str());
240 }
241
242 if (m < 0 || m > M_) {
243 std::stringstream ss;
244 ss << "M: " << m << " out of scope : " << M_ << std::endl;
245 throw std::domain_error(ss.str());
246 }
247
248 if (n < 0 || n > N_) {
249 std::stringstream ss;
250 ss << "N: " << n << " out of scope : " << N_ << std::endl;
251 throw std::domain_error(ss.str());
252 }
253
254 if (o < 0 || o > O_) {
255 std::stringstream ss;
256 ss << "O: " << o << " out of scope : " << O_ << std::endl;
257 throw std::domain_error(ss.str());
258 }
259
260 return o * N_ * M_ * L_ * K_ * J_ * I_ + n * M_ * L_ * K_ * J_ * I_ + m * L_ * K_ * J_ * I_ + l * K_ * J_ * I_
261 + k * J_ * I_ + j * I_ + i;
262 };
263
264 private:
265 int I_;
266 int J_;
267 int K_;
268 int L_;
269 int M_;
270 int N_;
271 int O_;
272 };
273 } // namespace curvi
274} // namespace toolbox
static std::vector< int > getIndexRange(int start, int size)
Definition Index.h:13
static std::vector< double > getRange(int start, int size, double dx, double ox=0)
Definition Index.h:22
idx2(int a_J, int a_I)
Definition Index.h:34
int operator()(int j, int i) const
Definition Index.h:44
idx3(int a_K, int a_J, int a_I)
Definition Index.h:60
int operator()(int k, int j, int i) const
Definition Index.h:71
idx4(int a_L, int a_K, int a_J, int a_I)
Definition Index.h:102
int operator()(int l, int k, int j, int i) const
Definition Index.h:108
idx6(int a_N, int a_M, int a_L, int a_K, int a_J, int a_I)
Definition Index.h:147
int operator()(int n, int m, int l, int k, int j, int i) const
Definition Index.h:155
int operator()(int o, int n, int m, int l, int k, int j, int i) const
Definition Index.h:216
idx7(int a_O, int a_N, int a_M, int a_L, int a_K, int a_J, int a_I)
Definition Index.h:207