NPL
Neurological Programs and Libraries
iterators.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2014 Micah C Chambers (micahc.vt@gmail.com)
3  *
4  * NPL is free software: you can redistribute it and/or modify it under the
5  * terms of the BSD 2-Clause License available in LICENSE or at
6  * http://opensource.org/licenses/BSD-2-Clause
7  *
8  * @file iterators.h Iterators for images. Each is templated by the type that
9  * the pixels are viewed as (rather than the actual stored pixel type).
10  *
11  *****************************************************************************/
12 
13 #ifndef ITERATOR_H
14 #define ITERATOR_H
15 
16 #include <stdexcept>
17 #include <memory>
18 #include "ndarray.h"
19 #include "slicer.h"
20 #include "npltypes.h"
21 
22 namespace npl {
23 
24 
60 template <typename T = double>
61 class FlatIter
62 {
63 public:
68  FlatIter() {};
69 
70  FlatIter(std::shared_ptr<NDArray> in)
71  {
72  setArray(in);
73  };
74 
76  {
77  parent = in;
78  m_linpos = 0;
79  switch(in->type()) {
80  case UINT8:
81  castget = castgetStatic<uint8_t>;
82  castset = castsetStatic<uint8_t>;
83  break;
84  case INT8:
85  castget = castgetStatic<int8_t>;
86  castset = castsetStatic<int8_t>;
87  break;
88  case UINT16:
89  castget = castgetStatic<uint16_t>;
90  castset = castsetStatic<uint16_t>;
91  break;
92  case INT16:
93  castget = castgetStatic<int16_t>;
94  castset = castsetStatic<int16_t>;
95  break;
96  case UINT32:
97  castget = castgetStatic<uint32_t>;
98  castset = castsetStatic<uint32_t>;
99  break;
100  case INT32:
101  castget = castgetStatic<int32_t>;
102  castset = castsetStatic<int32_t>;
103  break;
104  case UINT64:
105  castget = castgetStatic<uint64_t>;
106  castset = castsetStatic<uint64_t>;
107  break;
108  case INT64:
109  castget = castgetStatic<int64_t>;
110  castset = castsetStatic<int64_t>;
111  break;
112  case FLOAT32:
113  castget = castgetStatic<float>;
114  castset = castsetStatic<float>;
115  break;
116  case FLOAT64:
117  castget = castgetStatic<double>;
118  castset = castsetStatic<double>;
119  break;
120  case FLOAT128:
121  castget = castgetStatic<long double>;
122  castset = castsetStatic<long double>;
123  break;
124  case COMPLEX64:
125  castget = castgetStatic<cfloat_t>;
126  castset = castsetStatic<cfloat_t>;
127  break;
128  case COMPLEX128:
129  castget = castgetStatic<cdouble_t>;
130  castset = castsetStatic<cdouble_t>;
131  break;
132  case COMPLEX256:
133  castget = castgetStatic<cquad_t>;
134  castset = castsetStatic<cquad_t>;
135  break;
136  case RGB24:
137  castget = castgetStatic<rgb_t>;
138  castset = castsetStatic<rgb_t>;
139  break;
140  case RGBA32:
141  castget = castgetStatic<rgba_t>;
142  castset = castsetStatic<rgba_t>;
143  break;
144  default:
145  case UNKNOWN_TYPE:
146  castget = castgetStatic<uint8_t>;
147  castset = castsetStatic<uint8_t>;
148  throw std::invalid_argument("Unknown type to FlatIter");
149  break;
150  }
151  }
152 
159  {
160  ++m_linpos;
161  return *this;
162  };
163 
170  {
171  --m_linpos;
172  return *this;
173  };
174 
180  T operator*() const
181  {
182  auto ptr = parent->__getAddr(m_linpos);
183  assert(ptr >= this->parent->__getAddr(0) &&
184  ptr < this->parent->__getAddr(this->parent->elements()));
185  return castget(ptr);
186  };
187 
193  T get() const
194  {
195  auto ptr = parent->__getAddr(m_linpos);
196  assert(ptr >= this->parent->__getAddr(0) &&
197  ptr < this->parent->__getAddr(this->parent->elements()));
198  return castget(ptr);
199  };
200 
206  void set(T v) const
207  {
208  auto ptr = parent->__getAddr(m_linpos);
209  assert(ptr >= this->parent->__getAddr(0) &&
210  ptr < this->parent->__getAddr(this->parent->elements()));
211  castset(ptr, v);
212  };
213 
217  void goBegin() { m_linpos=0; };
218 
222  void goEnd() { m_linpos=parent->elements(); };
223 
227  bool isEnd() const { return m_linpos==parent->elements(); };
228 
232  bool eof() const { return m_linpos==parent->elements(); };
233 
237  bool isBegin() const { return m_linpos == 0; };
238 
246  bool operator==(const FlatIter& other) const
247  {
248  return parent == other.parent && m_linpos == other.m_linpos;
249  };
250 
258  bool operator!=(const FlatIter& other) const
259  {
260  return parent != other.parent || this->m_linpos != other.m_linpos;
261  };
262 
271  bool operator<(const FlatIter& other) const
272  {
273  return parent == other.parent && m_linpos < other.m_linpos;
274  };
275 
284  bool operator>(const FlatIter& other) const
285  {
286  return parent == other.parent && m_linpos > other.m_linpos;
287  };
288 
297  bool operator<=(const FlatIter& other) const
298  {
299  return parent == other.parent && m_linpos <= other.m_linpos;
300  };
301 
310  bool operator>=(const FlatIter& other) const
311  {
312  return parent == other.parent && m_linpos >= other.m_linpos;
313  };
314 
315 private:
316  template <typename U>
317  static T castgetStatic(void* ptr)
318  {
319  return (T)(*((U*)ptr));
320  };
321 
322  template <typename U>
323  static void castsetStatic(void* ptr, const T& val)
324  {
325  (*((U*)ptr)) = (U)val;
326  };
327 
328 
329  std::shared_ptr<NDArray> parent;
330 
331  T (*castget)(void* ptr);
332  void (*castset)(void* ptr, const T& v);
333 
334  int64_t m_linpos;
335 };
336 
344 template <typename T = double>
346 {
347 public:
353 
354  FlatConstIter(std::shared_ptr<const NDArray> in)
355  {
356  setArray(in);
357  };
358 
360  {
361  parent = in;
362  m_linpos = 0;
363  switch(in->type()) {
364  case UINT8:
365  castget = castgetStatic<uint8_t>;
366  break;
367  case INT8:
368  castget = castgetStatic<int8_t>;
369  break;
370  case UINT16:
371  castget = castgetStatic<uint16_t>;
372  break;
373  case INT16:
374  castget = castgetStatic<int16_t>;
375  break;
376  case UINT32:
377  castget = castgetStatic<uint32_t>;
378  break;
379  case INT32:
380  castget = castgetStatic<int32_t>;
381  break;
382  case UINT64:
383  castget = castgetStatic<uint64_t>;
384  break;
385  case INT64:
386  castget = castgetStatic<int64_t>;
387  break;
388  case FLOAT32:
389  castget = castgetStatic<float>;
390  break;
391  case FLOAT64:
392  castget = castgetStatic<double>;
393  break;
394  case FLOAT128:
395  castget = castgetStatic<long double>;
396  break;
397  case COMPLEX64:
398  castget = castgetStatic<cfloat_t>;
399  break;
400  case COMPLEX128:
401  castget = castgetStatic<cdouble_t>;
402  break;
403  case COMPLEX256:
404  castget = castgetStatic<cquad_t>;
405  break;
406  case RGB24:
407  castget = castgetStatic<rgb_t>;
408  break;
409  case RGBA32:
410  castget = castgetStatic<rgba_t>;
411  break;
412  case UNKNOWN_TYPE:
413  default:
414  castget = castgetStatic<uint8_t>;
415  throw std::invalid_argument("Unknown type to FlatIter");
416  break;
417  }
418  }
419 
426  {
427  ++m_linpos;
428  return *this;
429  };
430 
437  {
438  --m_linpos;
439  return *this;
440  };
441 
447  T operator*() const
448  {
449  auto ptr = parent->__getAddr(m_linpos);
450  assert(ptr >= this->parent->__getAddr(0) &&
451  ptr < this->parent->__getAddr(this->parent->elements()));
452  return castget(ptr);
453  };
454 
460  T get() const
461  {
462  auto ptr = parent->__getAddr(m_linpos);
463  assert(ptr >= this->parent->__getAddr(0) &&
464  ptr < this->parent->__getAddr(this->parent->elements()));
465  return castget(ptr);
466  };
467 
471  void goBegin() { m_linpos=0; };
472 
476  void goEnd() { m_linpos=parent->elements(); };
477 
481  bool isEnd() const { return m_linpos==parent->elements(); };
482 
486  bool eof() const { return m_linpos==parent->elements(); };
487 
491  bool isBegin() const { return m_linpos == 0; };
492 
500  bool operator==(const FlatConstIter& other) const
501  {
502  return parent == other.parent && m_linpos == other.m_linpos;
503  };
504 
512  bool operator!=(const FlatConstIter& other) const
513  {
514  return parent != other.parent || this->m_linpos != other.m_linpos;
515  };
516 
525  bool operator<(const FlatConstIter& other) const
526  {
527  return parent == other.parent && m_linpos < other.m_linpos;
528  };
529 
538  bool operator>(const FlatConstIter& other) const
539  {
540  return parent == other.parent && m_linpos > other.m_linpos;
541  };
542 
551  bool operator<=(const FlatConstIter& other) const
552  {
553  return parent == other.parent && m_linpos <= other.m_linpos;
554  };
555 
564  bool operator>=(const FlatConstIter& other) const
565  {
566  return parent == other.parent && m_linpos >= other.m_linpos;
567  };
568 
569 private:
570  template <typename U>
571  static T castgetStatic(void* ptr)
572  {
573  return (T)(*((U*)ptr));
574  };
575 
576  std::shared_ptr<const NDArray> parent;
577 
578  T (*castget)(void* ptr);
579 
580  int64_t m_linpos;
581 };
582 
583 
589 template <typename T = double>
590 class NDConstIter : public Slicer
591 {
592 public:
598 
599  NDConstIter(std::shared_ptr<const NDArray> in)
600  {
601  setArray(in);
602  };
603 
605  {
606  setDim(in->ndim(), in->dim());
607  parent = in;
608  switch(in->type()) {
609  case UINT8:
610  castget = castgetStatic<uint8_t>;
611  break;
612  case INT8:
613  castget = castgetStatic<int8_t>;
614  break;
615  case UINT16:
616  castget = castgetStatic<uint16_t>;
617  break;
618  case INT16:
619  castget = castgetStatic<int16_t>;
620  break;
621  case UINT32:
622  castget = castgetStatic<uint32_t>;
623  break;
624  case INT32:
625  castget = castgetStatic<int32_t>;
626  break;
627  case UINT64:
628  castget = castgetStatic<uint64_t>;
629  break;
630  case INT64:
631  castget = castgetStatic<int64_t>;
632  break;
633  case FLOAT32:
634  castget = castgetStatic<float>;
635  break;
636  case FLOAT64:
637  castget = castgetStatic<double>;
638  break;
639  case FLOAT128:
640  castget = castgetStatic<long double>;
641  break;
642  case COMPLEX64:
643  castget = castgetStatic<cfloat_t>;
644  break;
645  case COMPLEX128:
646  castget = castgetStatic<cdouble_t>;
647  break;
648  case COMPLEX256:
649  castget = castgetStatic<cquad_t>;
650  break;
651  case RGB24:
652  castget = castgetStatic<rgb_t>;
653  break;
654  case RGBA32:
655  castget = castgetStatic<rgba_t>;
656  break;
657  case UNKNOWN_TYPE:
658  default:
659  castget = castgetStatic<uint8_t>;
660  throw std::invalid_argument("Unknown type to NDConstIter");
661  break;
662  }
663  };
664 
671  {
673  return *this;
674  };
675 
682  {
684  return *this;
685  };
686 
692  T operator*() const
693  {
694  auto ptr = parent->__getAddr(Slicer::operator*());
695  assert(ptr >= this->parent->__getAddr(0) &&
696  ptr < this->parent->__getAddr(this->parent->elements()));
697  return castget(ptr);
698  };
699 
705  T get() const
706  {
707  auto ptr = parent->__getAddr(Slicer::operator*());
708  assert(ptr >= this->parent->__getAddr(0) &&
709  ptr < this->parent->__getAddr(this->parent->elements()));
710  return castget(ptr);
711  };
712 
716  void goBegin() { Slicer::goBegin(); };
717 
721  void goEnd() { Slicer::goEnd(); };
722 
726  bool isEnd() const { return Slicer::isEnd(); };
727 
731  bool eof() const { return Slicer::isEnd(); };
732 
736  bool isBegin() const { return Slicer::isBegin(); };
737 
745  bool operator==(const NDConstIter& other) const
746  {
747  return parent == other.parent && m_linpos == other.m_linpos;
748  };
749 
757  bool operator!=(const NDConstIter& other) const
758  {
759  return parent != other.parent || this->m_linpos != other.m_linpos;
760  };
761 
770  bool operator<(const NDConstIter& other) const
771  {
772  if(parent != other.parent)
773  return false;
774 
775  for(size_t dd=0; dd<this->m_dim; dd++) {
776  if(this->m_pos[dd] < other.m_pos[dd])
777  return true;
778  }
779 
780  return false;
781  };
782 
791  bool operator>(const NDConstIter& other) const
792  {
793  if(parent != other.parent)
794  return false;
795 
796  for(size_t dd=0; dd<this->m_dim; dd++) {
797  if(this->m_pos[dd] > other.m_pos[dd])
798  return true;
799  }
800 
801  return false;
802  };
803 
812  bool operator<=(const NDConstIter& other) const
813  {
814  if(parent != other.parent)
815  return false;
816 
817  if(*this == other)
818  return true;
819 
820  return *this < other;
821  };
822 
831  bool operator>=(const NDConstIter& other) const
832  {
833  if(parent != other.parent)
834  return false;
835 
836  if(*this == other)
837  return true;
838 
839  return *this > other;
840  };
841 
842 private:
843  template <typename U>
844  static T castgetStatic(void* ptr)
845  {
846  return (T)(*((U*)ptr));
847  };
848 
849  std::shared_ptr<const NDArray> parent;
850 
851  T (*castget)(void* ptr);
852 };
853 
859 template <typename T = double>
860 class NDIter : public Slicer
861 {
862 public:
867  NDIter() {};
868 
869  NDIter(std::shared_ptr<NDArray> in)
870  {
871  setArray(in);
872  };
873 
875  {
876  parent = in;
877  setDim(in->ndim(), in->dim());
878  switch(in->type()) {
879  case UINT8:
880  castget = castgetStatic<uint8_t>;
881  castset = castsetStatic<uint8_t>;
882  break;
883  case INT8:
884  castget = castgetStatic<int8_t>;
885  castset = castsetStatic<int8_t>;
886  break;
887  case UINT16:
888  castget = castgetStatic<uint16_t>;
889  castset = castsetStatic<uint16_t>;
890  break;
891  case INT16:
892  castget = castgetStatic<int16_t>;
893  castset = castsetStatic<int16_t>;
894  break;
895  case UINT32:
896  castget = castgetStatic<uint32_t>;
897  castset = castsetStatic<uint32_t>;
898  break;
899  case INT32:
900  castget = castgetStatic<int32_t>;
901  castset = castsetStatic<int32_t>;
902  break;
903  case UINT64:
904  castget = castgetStatic<uint64_t>;
905  castset = castsetStatic<uint64_t>;
906  break;
907  case INT64:
908  castget = castgetStatic<int64_t>;
909  castset = castsetStatic<int64_t>;
910  break;
911  case FLOAT32:
912  castget = castgetStatic<float>;
913  castset = castsetStatic<float>;
914  break;
915  case FLOAT64:
916  castget = castgetStatic<double>;
917  castset = castsetStatic<double>;
918  break;
919  case FLOAT128:
920  castget = castgetStatic<long double>;
921  castset = castsetStatic<long double>;
922  break;
923  case COMPLEX64:
924  castget = castgetStatic<cfloat_t>;
925  castset = castsetStatic<cfloat_t>;
926  break;
927  case COMPLEX128:
928  castget = castgetStatic<cdouble_t>;
929  castset = castsetStatic<cdouble_t>;
930  break;
931  case COMPLEX256:
932  castget = castgetStatic<cquad_t>;
933  castset = castsetStatic<cquad_t>;
934  break;
935  case RGB24:
936  castget = castgetStatic<rgb_t>;
937  castset = castsetStatic<rgb_t>;
938  break;
939  case RGBA32:
940  castget = castgetStatic<rgba_t>;
941  castset = castsetStatic<rgba_t>;
942  break;
943  default:
944  case UNKNOWN_TYPE:
945  castget = castgetStatic<uint8_t>;
946  castset = castsetStatic<uint8_t>;
947  throw std::invalid_argument("Unknown type to NDIter");
948  break;
949  }
950  };
951 
958  {
960  return *this;
961  };
962 
969  {
971  return *this;
972  };
973 
979  T operator*() const
980  {
981  auto ptr = parent->__getAddr(Slicer::operator*());
982  assert(ptr >= this->parent->__getAddr(0) &&
983  ptr < this->parent->__getAddr(this->parent->elements()));
984  return castget(ptr);
985  };
986 
992  T get() const
993  {
994  auto ptr = parent->__getAddr(Slicer::operator*());
995  assert(ptr >= this->parent->__getAddr(0) &&
996  ptr < this->parent->__getAddr(this->parent->elements()));
997  return castget(ptr);
998  };
999 
1005  void set(T v)
1006  {
1007  auto ptr = parent->__getAddr(Slicer::operator*());
1008  assert(ptr >= this->parent->__getAddr(0) &&
1009  ptr < this->parent->__getAddr(this->parent->elements()));
1010  this->castset(ptr, v);
1011  };
1012 
1016  void goBegin() { Slicer::goBegin(); };
1017 
1021  void goEnd() { Slicer::goEnd(); };
1022 
1026  bool isEnd() const { return Slicer::isEnd(); };
1027 
1031  bool eof() const { return Slicer::isEnd(); };
1032 
1036  bool isBegin() const { return Slicer::isBegin(); };
1037 
1045  bool operator==(const NDIter& other) const
1046  {
1047  return parent == other.parent && m_linpos == other.m_linpos;
1048  };
1049 
1057  bool operator!=(const NDIter& other) const
1058  {
1059  return parent != other.parent || this->m_linpos != other.m_linpos;
1060  };
1061 
1070  bool operator<(const NDIter& other) const
1071  {
1072  if(parent != other.parent)
1073  return false;
1074 
1075  for(size_t dd=0; dd<this->m_dim; dd++) {
1076  if(this->m_pos[dd] < other.m_pos[dd])
1077  return true;
1078  }
1079 
1080  return false;
1081  };
1082 
1091  bool operator>(const NDIter& other) const
1092  {
1093  if(parent != other.parent)
1094  return false;
1095 
1096  for(size_t dd=0; dd<this->m_dim; dd++) {
1097  if(this->m_pos[dd] > other.m_pos[dd])
1098  return true;
1099  }
1100 
1101  return false;
1102  };
1103 
1112  bool operator<=(const NDIter& other) const
1113  {
1114  if(parent != other.parent)
1115  return false;
1116 
1117  if(*this == other)
1118  return true;
1119 
1120  return *this < other;
1121  };
1122 
1131  bool operator>=(const NDIter& other) const
1132  {
1133  if(parent != other.parent)
1134  return false;
1135 
1136  if(*this == other)
1137  return true;
1138 
1139  return *this > other;
1140  };
1141 
1142 private:
1143  template <typename U>
1144  static T castgetStatic(void* ptr)
1145  {
1146  return (T)(*((U*)ptr));
1147  };
1148 
1149  template <typename U>
1150  static void castsetStatic(void* ptr, const T& val)
1151  {
1152  (*((U*)ptr)) = (U)val;
1153  };
1154 
1155 
1156  std::shared_ptr<NDArray> parent;
1157 
1158  T (*castget)(void* ptr);
1159  void (*castset)(void* ptr, const T& val);
1160 };
1161 
1168 template<class T> using OrderIter = NDIter<T>;
1169 
1176 template<class T> using OrderConstIter = NDConstIter<T>;
1177 
1205 template <typename T = double>
1207 {
1208 public:
1209 
1215 
1216  ChunkConstIter(std::shared_ptr<const NDArray> in)
1217  {
1218  setArray(in);
1219  };
1220 
1222  {
1223  setDim(in->ndim(), in->dim());
1224  parent = in;
1225  switch(in->type()) {
1226  case UINT8:
1227  castget = castgetStatic<uint8_t>;
1228  break;
1229  case INT8:
1230  castget = castgetStatic<int8_t>;
1231  break;
1232  case UINT16:
1233  castget = castgetStatic<uint16_t>;
1234  break;
1235  case INT16:
1236  castget = castgetStatic<int16_t>;
1237  break;
1238  case UINT32:
1239  castget = castgetStatic<uint32_t>;
1240  break;
1241  case INT32:
1242  castget = castgetStatic<int32_t>;
1243  break;
1244  case UINT64:
1245  castget = castgetStatic<uint64_t>;
1246  break;
1247  case INT64:
1248  castget = castgetStatic<int64_t>;
1249  break;
1250  case FLOAT32:
1251  castget = castgetStatic<float>;
1252  break;
1253  case FLOAT64:
1254  castget = castgetStatic<double>;
1255  break;
1256  case FLOAT128:
1257  castget = castgetStatic<long double>;
1258  break;
1259  case COMPLEX64:
1260  castget = castgetStatic<cfloat_t>;
1261  break;
1262  case COMPLEX128:
1263  castget = castgetStatic<cdouble_t>;
1264  break;
1265  case COMPLEX256:
1266  castget = castgetStatic<cquad_t>;
1267  break;
1268  case RGB24:
1269  castget = castgetStatic<rgb_t>;
1270  break;
1271  case RGBA32:
1272  castget = castgetStatic<rgba_t>;
1273  break;
1274  case UNKNOWN_TYPE:
1275  default:
1276  castget = castgetStatic<uint8_t>;
1277  throw std::invalid_argument("Unknown type to ChunkConstIter");
1278  break;
1279  }
1280  };
1281 
1288  {
1290  return *this;
1291  };
1292 
1299  {
1301  return *this;
1302  };
1303 
1310  {
1312  return *this;
1313  };
1314 
1321  {
1323  return *this;
1324  };
1325 
1331  T operator*() const
1332  {
1333  auto ptr = parent->__getAddr(ChunkSlicer::operator*());
1334  assert(ptr >= this->parent->__getAddr(0) &&
1335  ptr < this->parent->__getAddr(this->parent->elements()));
1336  return castget(ptr);
1337  };
1338 
1344  T get() const
1345  {
1346  auto ptr = parent->__getAddr(ChunkSlicer::operator*());
1347  assert(ptr >= this->parent->__getAddr(0) &&
1348  ptr < this->parent->__getAddr(this->parent->elements()));
1349  return castget(ptr);
1350  };
1351 
1356 
1360  void goEnd() { ChunkSlicer::goEnd(); };
1361 
1365  bool isEnd() const { return ChunkSlicer::isEnd(); };
1366 
1370  bool eof() const { return ChunkSlicer::isEnd(); };
1371 
1375  bool isBegin() const { return ChunkSlicer::isBegin(); };
1376 
1384  bool operator==(const ChunkConstIter& other) const
1385  {
1386  return parent == other.parent && m_linpos == other.m_linpos;
1387  };
1388 
1396  bool operator!=(const ChunkConstIter& other) const
1397  {
1398  return parent != other.parent || this->m_linpos != other.m_linpos;
1399  };
1400 
1409  bool operator<(const ChunkConstIter& other) const
1410  {
1411  if(parent != other.parent)
1412  return false;
1413 
1414  for(size_t dd=0; dd<this->m_dim; dd++) {
1415  if(this->m_pos[dd] < other.m_pos[dd])
1416  return true;
1417  }
1418 
1419  return false;
1420  };
1421 
1430  bool operator>(const ChunkConstIter& other) const
1431  {
1432  if(parent != other.parent)
1433  return false;
1434 
1435  for(size_t dd=0; dd<this->m_dim; dd++) {
1436  if(this->m_pos[dd] > other.m_pos[dd])
1437  return true;
1438  }
1439 
1440  return false;
1441  };
1442 
1451  bool operator<=(const ChunkConstIter& other) const
1452  {
1453  if(parent != other.parent)
1454  return false;
1455 
1456  if(*this == other)
1457  return true;
1458 
1459  return *this < other;
1460  };
1461 
1470  bool operator>=(const ChunkConstIter& other) const
1471  {
1472  if(parent != other.parent)
1473  return false;
1474 
1475  if(*this == other)
1476  return true;
1477 
1478  return *this > other;
1479  };
1480 
1481 private:
1482  template <typename U>
1483  static T castgetStatic(void* ptr)
1484  {
1485  return (T)(*((U*)ptr));
1486  };
1487 
1488  std::shared_ptr<const NDArray> parent;
1489 
1490  T (*castget)(void* ptr);
1491 };
1492 
1493 
1519 template <typename T = double>
1520 class ChunkIter : public ChunkSlicer
1521 {
1522 public:
1523 
1529 
1530  ChunkIter(std::shared_ptr<NDArray> in)
1531  {
1532  setArray(in);
1533  };
1534 
1536  {
1537  parent = in;
1538  setDim(in->ndim(), in->dim());
1539  switch(in->type()) {
1540  case UINT8:
1541  castget = castgetStatic<uint8_t>;
1542  castset = castsetStatic<uint8_t>;
1543  break;
1544  case INT8:
1545  castget = castgetStatic<int8_t>;
1546  castset = castsetStatic<int8_t>;
1547  break;
1548  case UINT16:
1549  castget = castgetStatic<uint16_t>;
1550  castset = castsetStatic<uint16_t>;
1551  break;
1552  case INT16:
1553  castget = castgetStatic<int16_t>;
1554  castset = castsetStatic<int16_t>;
1555  break;
1556  case UINT32:
1557  castget = castgetStatic<uint32_t>;
1558  castset = castsetStatic<uint32_t>;
1559  break;
1560  case INT32:
1561  castget = castgetStatic<int32_t>;
1562  castset = castsetStatic<int32_t>;
1563  break;
1564  case UINT64:
1565  castget = castgetStatic<uint64_t>;
1566  castset = castsetStatic<uint64_t>;
1567  break;
1568  case INT64:
1569  castget = castgetStatic<int64_t>;
1570  castset = castsetStatic<int64_t>;
1571  break;
1572  case FLOAT32:
1573  castget = castgetStatic<float>;
1574  castset = castsetStatic<float>;
1575  break;
1576  case FLOAT64:
1577  castget = castgetStatic<double>;
1578  castset = castsetStatic<double>;
1579  break;
1580  case FLOAT128:
1581  castget = castgetStatic<long double>;
1582  castset = castsetStatic<long double>;
1583  break;
1584  case COMPLEX64:
1585  castget = castgetStatic<cfloat_t>;
1586  castset = castsetStatic<cfloat_t>;
1587  break;
1588  case COMPLEX128:
1589  castget = castgetStatic<cdouble_t>;
1590  castset = castsetStatic<cdouble_t>;
1591  break;
1592  case COMPLEX256:
1593  castget = castgetStatic<cquad_t>;
1594  castset = castsetStatic<cquad_t>;
1595  break;
1596  case RGB24:
1597  castget = castgetStatic<rgb_t>;
1598  castset = castsetStatic<rgb_t>;
1599  break;
1600  case RGBA32:
1601  castget = castgetStatic<rgba_t>;
1602  castset = castsetStatic<rgba_t>;
1603  break;
1604  default:
1605  case UNKNOWN_TYPE:
1606  castget = castgetStatic<uint8_t>;
1607  castset = castsetStatic<uint8_t>;
1608  throw std::invalid_argument("Unknown type to ChunkIter");
1609  break;
1610  }
1611  };
1612 
1619  {
1621  return *this;
1622  };
1623 
1630  {
1632  return *this;
1633  };
1634 
1641  {
1643  return *this;
1644  };
1645 
1652  {
1654  return *this;
1655  };
1656 
1662  T operator*() const
1663  {
1664  auto ptr = parent->__getAddr(ChunkSlicer::operator*());
1665  assert(ptr >= this->parent->__getAddr(0) &&
1666  ptr < this->parent->__getAddr(this->parent->elements()));
1667  return castget(ptr);
1668  };
1669 
1675  T get() const
1676  {
1677  auto ptr = parent->__getAddr(ChunkSlicer::operator*());
1678  assert(ptr >= this->parent->__getAddr(0) &&
1679  ptr < this->parent->__getAddr(this->parent->elements()));
1680  return castget(ptr);
1681  };
1682 
1688  void set(T v)
1689  {
1690  auto ptr = parent->__getAddr(ChunkSlicer::operator*());
1691  assert(ptr >= this->parent->__getAddr(0) &&
1692  ptr < this->parent->__getAddr(this->parent->elements()));
1693  this->castset(ptr, v);
1694  };
1695 
1700 
1704  void goEnd() { ChunkSlicer::goEnd(); };
1705 
1709  bool isEnd() const { return ChunkSlicer::isEnd(); };
1710 
1714  bool eof() const { return ChunkSlicer::isEnd(); };
1715 
1719  bool isBegin() const { return ChunkSlicer::isBegin(); };
1720 
1728  bool operator==(const ChunkIter& other) const
1729  {
1730  return parent == other.parent && m_linpos == other.m_linpos;
1731  };
1732 
1740  bool operator!=(const ChunkIter& other) const
1741  {
1742  return parent != other.parent || this->m_linpos != other.m_linpos;
1743  };
1744 
1753  bool operator<(const ChunkIter& other) const
1754  {
1755  if(parent != other.parent)
1756  return false;
1757 
1758  for(size_t dd=0; dd<this->m_dim; dd++) {
1759  if(this->m_pos[dd] < other.m_pos[dd])
1760  return true;
1761  }
1762 
1763  return false;
1764  };
1765 
1774  bool operator>(const ChunkIter& other) const
1775  {
1776  if(parent != other.parent)
1777  return false;
1778 
1779  for(size_t dd=0; dd<this->m_dim; dd++) {
1780  if(this->m_pos[dd] > other.m_pos[dd])
1781  return true;
1782  }
1783 
1784  return false;
1785  };
1786 
1795  bool operator<=(const ChunkIter& other) const
1796  {
1797  if(parent != other.parent)
1798  return false;
1799 
1800  if(*this == other)
1801  return true;
1802 
1803  return *this < other;
1804  };
1805 
1814  bool operator>=(const ChunkIter& other) const
1815  {
1816  if(parent != other.parent)
1817  return false;
1818 
1819  if(*this == other)
1820  return true;
1821 
1822  return *this > other;
1823  };
1824 
1825 private:
1826  template <typename U>
1827  static T castgetStatic(void* ptr)
1828  {
1829  return (T)(*((U*)ptr));
1830  };
1831 
1832  template <typename U>
1833  static void castsetStatic(void* ptr, const T& val)
1834  {
1835  (*((U*)ptr)) = (U)val;
1836  };
1837 
1838 
1839  std::shared_ptr<NDArray> parent;
1840 
1841  T (*castget)(void* ptr);
1842  void (*castset)(void* ptr, const T& val);
1843 };
1844 
1845 
1846 
1847 
1870 template <typename T = double>
1871 class KernelIter : public KSlicer
1872 {
1873 public:
1874 
1880 
1881  KernelIter(std::shared_ptr<const NDArray> in)
1882  {
1883  setArray(in);
1884  };
1885 
1887  {
1888  setDim(in->ndim(), in->dim());
1889  parent = in;
1890  switch(in->type()) {
1891  case UINT8:
1892  castget = castgetStatic<uint8_t>;
1893  break;
1894  case INT8:
1895  castget = castgetStatic<int8_t>;
1896  break;
1897  case UINT16:
1898  castget = castgetStatic<uint16_t>;
1899  break;
1900  case INT16:
1901  castget = castgetStatic<int16_t>;
1902  break;
1903  case UINT32:
1904  castget = castgetStatic<uint32_t>;
1905  break;
1906  case INT32:
1907  castget = castgetStatic<int32_t>;
1908  break;
1909  case UINT64:
1910  castget = castgetStatic<uint64_t>;
1911  break;
1912  case INT64:
1913  castget = castgetStatic<int64_t>;
1914  break;
1915  case FLOAT32:
1916  castget = castgetStatic<float>;
1917  break;
1918  case FLOAT64:
1919  castget = castgetStatic<double>;
1920  break;
1921  case FLOAT128:
1922  castget = castgetStatic<long double>;
1923  break;
1924  case COMPLEX64:
1925  castget = castgetStatic<cfloat_t>;
1926  break;
1927  case COMPLEX128:
1928  castget = castgetStatic<cdouble_t>;
1929  break;
1930  case COMPLEX256:
1931  castget = castgetStatic<cquad_t>;
1932  break;
1933  case RGB24:
1934  castget = castgetStatic<rgb_t>;
1935  break;
1936  case RGBA32:
1937  castget = castgetStatic<rgba_t>;
1938  break;
1939  case UNKNOWN_TYPE:
1940  default:
1941  castget = castgetStatic<uint8_t>;
1942  throw std::invalid_argument("Unknown type to NDConstIter");
1943  break;
1944  }
1945  };
1946 
1953  {
1955  return *this;
1956  };
1957 
1964  {
1966  return *this;
1967  };
1968 
1974  T operator*() const
1975  {
1976  auto ptr = parent->__getAddr(KSlicer::operator*());
1977  assert(ptr >= this->parent->__getAddr(0) &&
1978  ptr < this->parent->__getAddr(this->parent->elements()));
1979  return castget(ptr);
1980  };
1981 
1987  T getC() const
1988  {
1989  auto ptr = parent->__getAddr(KSlicer::getC());
1990  assert(ptr >= this->parent->__getAddr(0) &&
1991  ptr < this->parent->__getAddr(this->parent->elements()));
1992  return castget(ptr);
1993  };
1994 
2001  T getK(int64_t k) const
2002  {
2003  auto ptr = parent->__getAddr(KSlicer::getK(k));
2004  assert(ptr >= this->parent->__getAddr(0) &&
2005  ptr < this->parent->__getAddr(this->parent->elements()));
2006  return castget(ptr);
2007  };
2008 
2015  T operator[](int64_t k) const
2016  {
2017  auto ptr = parent->__getAddr(KSlicer::getK(k));
2018  assert(ptr >= this->parent->__getAddr(0) &&
2019  ptr < this->parent->__getAddr(this->parent->elements()));
2020  return castget(ptr);
2021  };
2022 
2030  bool operator==(const KernelIter& other) const
2031  {
2032  return parent == other.parent && m_linpos == other.m_linpos;
2033  };
2034 
2042  bool operator!=(const KernelIter& other) const
2043  {
2044  return parent != other.parent || this->m_linpos != other.m_linpos;
2045  };
2046 
2055  bool operator<(const KernelIter& other) const
2056  {
2057  if(parent != other.parent)
2058  return false;
2059 
2060  for(size_t dd=0; dd<this->m_dim; dd++) {
2061  if(this->m_pos[dd] < other.m_pos[dd])
2062  return true;
2063  }
2064 
2065  return false;
2066  };
2067 
2076  bool operator>(const KernelIter& other) const
2077  {
2078  if(parent != other.parent)
2079  return false;
2080 
2081  for(size_t dd=0; dd<this->m_dim; dd++) {
2082  if(this->m_pos[dd] > other.m_pos[dd])
2083  return true;
2084  }
2085 
2086  return false;
2087  };
2088 
2097  bool operator<=(const KernelIter& other) const
2098  {
2099  if(parent != other.parent)
2100  return false;
2101 
2102  if(*this == other)
2103  return true;
2104 
2105  return *this < other;
2106  };
2107 
2116  bool operator>=(const KernelIter& other) const
2117  {
2118  if(parent != other.parent)
2119  return false;
2120 
2121  if(*this == other)
2122  return true;
2123 
2124  return *this > other;
2125  };
2126 
2127 private:
2128  template <typename U>
2129  static T castgetStatic(void* ptr)
2130  {
2131  return (T)(*((U*)ptr));
2132  };
2133 
2134  std::shared_ptr<const NDArray> parent;
2135 
2136  T (*castget)(void* ptr);
2137 };
2138 
2148 template <typename T = double>
2149 class Vector3DIter : public Slicer
2150 {
2151 public:
2152 
2158 
2159  Vector3DIter(std::shared_ptr<NDArray> in)
2160  {
2161  setArray(in);
2162  };
2163 
2165  {
2166  setDim(in->ndim(), in->dim());
2167  parent = in;
2168 
2169  // iterate through the first 3 dimensions
2170  std::vector<std::pair<int64_t,int64_t>> roi(in->ndim());
2171  for(size_t ii=0; ii<3 && ii<in->ndim(); ii++) {
2172  roi[ii].first = 0;
2173  roi[ii].second = in->dim(ii)-1;
2174  }
2175 
2176  // don't iterate in higher dimensions
2177  for(size_t ii=3; ii<in->ndim(); ii++) {
2178  roi[ii].first = 0;
2179  roi[ii].second = 0;
2180  }
2181  this->setROI(roi);
2182 
2183  switch(in->type()) {
2184  case UINT8:
2185  castget = castgetStatic<uint8_t>;
2186  castset = castsetStatic<uint8_t>;
2187  break;
2188  case INT8:
2189  castget = castgetStatic<int8_t>;
2190  castset = castsetStatic<int8_t>;
2191  break;
2192  case UINT16:
2193  castget = castgetStatic<uint16_t>;
2194  castset = castsetStatic<uint16_t>;
2195  break;
2196  case INT16:
2197  castget = castgetStatic<int16_t>;
2198  castset = castsetStatic<int16_t>;
2199  break;
2200  case UINT32:
2201  castget = castgetStatic<uint32_t>;
2202  castset = castsetStatic<uint32_t>;
2203  break;
2204  case INT32:
2205  castget = castgetStatic<int32_t>;
2206  castset = castsetStatic<int32_t>;
2207  break;
2208  case UINT64:
2209  castget = castgetStatic<uint64_t>;
2210  castset = castsetStatic<uint64_t>;
2211  break;
2212  case INT64:
2213  castget = castgetStatic<int64_t>;
2214  castset = castsetStatic<int64_t>;
2215  break;
2216  case FLOAT32:
2217  castget = castgetStatic<float>;
2218  castset = castsetStatic<float>;
2219  break;
2220  case FLOAT64:
2221  castget = castgetStatic<double>;
2222  castset = castsetStatic<double>;
2223  break;
2224  case FLOAT128:
2225  castget = castgetStatic<long double>;
2226  castset = castsetStatic<long double>;
2227  break;
2228  case COMPLEX64:
2229  castget = castgetStatic<cfloat_t>;
2230  castset = castsetStatic<cfloat_t>;
2231  break;
2232  case COMPLEX128:
2233  castget = castgetStatic<cdouble_t>;
2234  castset = castsetStatic<cdouble_t>;
2235  break;
2236  case COMPLEX256:
2237  castget = castgetStatic<cquad_t>;
2238  castset = castsetStatic<cquad_t>;
2239  break;
2240  case RGB24:
2241  castget = castgetStatic<rgb_t>;
2242  castset = castsetStatic<rgb_t>;
2243  break;
2244  case RGBA32:
2245  castget = castgetStatic<rgba_t>;
2246  castset = castsetStatic<rgba_t>;
2247  break;
2248  default:
2249  case UNKNOWN_TYPE:
2250  castget = castgetStatic<uint8_t>;
2251  castset = castsetStatic<uint8_t>;
2252  throw std::invalid_argument("Unknown type to NDIter");
2253  break;
2254  }
2255  };
2256 
2263  {
2265  return *this;
2266  };
2267 
2274  {
2276  return *this;
2277  };
2278 
2284  T operator*() const
2285  {
2286  auto ptr = parent->__getAddr(Slicer::operator*());
2287  assert(ptr >= this->parent->__getAddr(0) &&
2288  ptr < this->parent->__getAddr(this->parent->elements()));
2289  return castget(ptr);
2290  };
2291 
2297  T get(int64_t i = 0) const
2298  {
2299  auto ptr = parent->__getAddr(Slicer::operator*()+i);
2300  assert(ptr >= this->parent->__getAddr(0) &&
2301  ptr < this->parent->__getAddr(this->parent->elements()));
2302  return castget(ptr);
2303  };
2304 
2310  T operator[](int64_t i) const
2311  {
2312  auto ptr = parent->__getAddr(Slicer::operator*()+i);
2313  assert(ptr >= this->parent->__getAddr(0) &&
2314  ptr < this->parent->__getAddr(this->parent->elements()));
2315  return castget(ptr);
2316  };
2317 
2322  void set(int64_t i, T v)
2323  {
2324  auto ptr = parent->__getAddr(Slicer::operator*()+i);
2325  assert(ptr >= this->parent->__getAddr(0) &&
2326  ptr < this->parent->__getAddr(this->parent->elements()));
2327  this->castset(ptr, v);
2328  };
2329 
2334  void set(T v)
2335  {
2336  auto ptr = parent->__getAddr(Slicer::operator*());
2337  assert(ptr >= this->parent->__getAddr(0) &&
2338  ptr < this->parent->__getAddr(this->parent->elements()));
2339  this->castset(ptr, v);
2340  };
2341 
2345  void goBegin() { Slicer::goBegin(); };
2346 
2350  void goEnd() { Slicer::goEnd(); };
2351 
2355  bool isEnd() const { return Slicer::isEnd(); };
2356 
2360  bool eof() const { return Slicer::isEnd(); };
2361 
2365  bool isBegin() const { return Slicer::isBegin(); };
2366 
2374  bool operator==(const Vector3DIter& other) const
2375  {
2376  return parent == other.parent && m_linpos == other.m_linpos;
2377  };
2378 
2386  bool operator!=(const Vector3DIter& other) const
2387  {
2388  return parent != other.parent || this->m_linpos != other.m_linpos;
2389  };
2390 
2399  bool operator<(const Vector3DIter& other) const
2400  {
2401  if(parent != other.parent)
2402  return false;
2403 
2404  for(size_t dd=0; dd<this->m_dim; dd++) {
2405  if(this->m_pos[dd] < other.m_pos[dd])
2406  return true;
2407  }
2408 
2409  return false;
2410  };
2411 
2420  bool operator>(const Vector3DIter& other) const
2421  {
2422  if(parent != other.parent)
2423  return false;
2424 
2425  for(size_t dd=0; dd<this->m_dim; dd++) {
2426  if(this->m_pos[dd] > other.m_pos[dd])
2427  return true;
2428  }
2429 
2430  return false;
2431  };
2432 
2441  bool operator<=(const Vector3DIter& other) const
2442  {
2443  if(parent != other.parent)
2444  return false;
2445 
2446  if(*this == other)
2447  return true;
2448 
2449  return *this < other;
2450  };
2451 
2460  bool operator>=(const Vector3DIter& other) const
2461  {
2462  if(parent != other.parent)
2463  return false;
2464 
2465  if(*this == other)
2466  return true;
2467 
2468  return *this > other;
2469  };
2470 
2471  size_t tlen() const { return this->parent->tlen(); };
2472 
2473 private:
2474  template <typename U>
2475  static T castgetStatic(void* ptr)
2476  {
2477  return (T)(*((U*)ptr));
2478  };
2479 
2480  template <typename U>
2481  static void castsetStatic(void* ptr, const T& val)
2482  {
2483  (*((U*)ptr)) = (U)val;
2484  };
2485 
2486 
2487  std::shared_ptr<NDArray> parent;
2488 
2489  T (*castget)(void* ptr);
2490  void (*castset)(void* ptr, const T& val);
2491 };
2492 
2502 template <typename T = double>
2504 {
2505 public:
2506 
2512 
2513  Vector3DConstIter(std::shared_ptr<const NDArray> in)
2514  {
2515  setArray(in);
2516  };
2517 
2519  {
2520  setDim(in->ndim(), in->dim());
2521  parent = in;
2522 
2523  // iterate through the first 3 dimensions
2524  std::vector<std::pair<int64_t,int64_t>> roi(in->ndim());
2525  for(size_t ii=0; ii<3 && ii<in->ndim(); ii++) {
2526  roi[ii].first = 0;
2527  roi[ii].second = in->dim(ii)-1;
2528  }
2529 
2530  // don't iterate in higher dimensions
2531  for(size_t ii=3; ii<in->ndim(); ii++) {
2532  roi[ii].first = 0;
2533  roi[ii].second = 0;
2534  }
2535  this->setROI(roi);
2536 
2537  switch(in->type()) {
2538  case UINT8:
2539  castget = castgetStatic<uint8_t>;
2540  break;
2541  case INT8:
2542  castget = castgetStatic<int8_t>;
2543  break;
2544  case UINT16:
2545  castget = castgetStatic<uint16_t>;
2546  break;
2547  case INT16:
2548  castget = castgetStatic<int16_t>;
2549  break;
2550  case UINT32:
2551  castget = castgetStatic<uint32_t>;
2552  break;
2553  case INT32:
2554  castget = castgetStatic<int32_t>;
2555  break;
2556  case UINT64:
2557  castget = castgetStatic<uint64_t>;
2558  break;
2559  case INT64:
2560  castget = castgetStatic<int64_t>;
2561  break;
2562  case FLOAT32:
2563  castget = castgetStatic<float>;
2564  break;
2565  case FLOAT64:
2566  castget = castgetStatic<double>;
2567  break;
2568  case FLOAT128:
2569  castget = castgetStatic<long double>;
2570  break;
2571  case COMPLEX64:
2572  castget = castgetStatic<cfloat_t>;
2573  break;
2574  case COMPLEX128:
2575  castget = castgetStatic<cdouble_t>;
2576  break;
2577  case COMPLEX256:
2578  castget = castgetStatic<cquad_t>;
2579  break;
2580  case RGB24:
2581  castget = castgetStatic<rgb_t>;
2582  break;
2583  case RGBA32:
2584  castget = castgetStatic<rgba_t>;
2585  break;
2586  default:
2587  case UNKNOWN_TYPE:
2588  castget = castgetStatic<uint8_t>;
2589  throw std::invalid_argument("Unknown type to NDIter");
2590  break;
2591  }
2592  };
2593 
2600  {
2602  return *this;
2603  };
2604 
2611  {
2613  return *this;
2614  };
2615 
2621  T operator*() const
2622  {
2623  auto ptr = parent->__getAddr(Slicer::operator*());
2624  assert(ptr >= this->parent->__getAddr(0) &&
2625  ptr < this->parent->__getAddr(this->parent->elements()));
2626  return castget(ptr);
2627  };
2628 
2634  T get(int64_t i = 0) const
2635  {
2636  auto ptr = parent->__getAddr(Slicer::operator*()+i);
2637  assert(ptr >= this->parent->__getAddr(0) &&
2638  ptr < this->parent->__getAddr(this->parent->elements()));
2639  return castget(ptr);
2640  };
2641 
2647  T operator[](int64_t i) const
2648  {
2649  auto ptr = parent->__getAddr(Slicer::operator*()+i);
2650  assert(ptr >= this->parent->__getAddr(0) &&
2651  ptr < this->parent->__getAddr(this->parent->elements()));
2652  return castget(ptr);
2653  };
2654 
2658  void goBegin() { Slicer::goBegin(); };
2659 
2663  void goEnd() { Slicer::goEnd(); };
2664 
2668  bool isEnd() const { return Slicer::isEnd(); };
2669 
2673  bool eof() const { return Slicer::isEnd(); };
2674 
2678  bool isBegin() const { return Slicer::isBegin(); };
2679 
2687  bool operator==(const Vector3DConstIter& other) const
2688  {
2689  return parent == other.parent && m_linpos == other.m_linpos;
2690  };
2691 
2699  bool operator!=(const Vector3DConstIter& other) const
2700  {
2701  return parent != other.parent || this->m_linpos != other.m_linpos;
2702  };
2703 
2712  bool operator<(const Vector3DConstIter& other) const
2713  {
2714  if(parent != other.parent)
2715  return false;
2716 
2717  for(size_t dd=0; dd<this->m_dim; dd++) {
2718  if(this->m_pos[dd] < other.m_pos[dd])
2719  return true;
2720  }
2721 
2722  return false;
2723  };
2724 
2733  bool operator>(const Vector3DConstIter& other) const
2734  {
2735  if(parent != other.parent)
2736  return false;
2737 
2738  for(size_t dd=0; dd<this->m_dim; dd++) {
2739  if(this->m_pos[dd] > other.m_pos[dd])
2740  return true;
2741  }
2742 
2743  return false;
2744  };
2745 
2754  bool operator<=(const Vector3DConstIter& other) const
2755  {
2756  if(parent != other.parent)
2757  return false;
2758 
2759  if(*this == other)
2760  return true;
2761 
2762  return *this < other;
2763  };
2764 
2773  bool operator>=(const Vector3DConstIter& other) const
2774  {
2775  if(parent != other.parent)
2776  return false;
2777 
2778  if(*this == other)
2779  return true;
2780 
2781  return *this > other;
2782  };
2783 
2784  size_t tlen() const { return this->parent->tlen(); };
2785 
2786 private:
2787  template <typename U>
2788  static T castgetStatic(void* ptr)
2789  {
2790  return (T)(*((U*)ptr));
2791  };
2792 
2793  std::shared_ptr<const NDArray> parent;
2794 
2795  T (*castget)(void* ptr);
2796 };
2797 
2800 }
2801 
2802 #endif //ITERATOR_H
KSlicer & operator--()
Prefix negative iterator. Iterates in the order dictatored by the dimension order passsed during cons...
FlatIter & operator--()
Prefix decrement operator.
Definition: iterators.h:169
void goBegin()
Go to beginning of iteration.
Definition: iterators.h:2658
bool operator>=(const ChunkConstIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is the s...
Definition: iterators.h:1470
void setArray(ptr< const NDArray > in)
Definition: iterators.h:359
ChunkSlicer & nextChunk()
Proceed to the next chunk (if there is one).
bool operator<=(const KernelIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is the s...
Definition: iterators.h:2097
void goEnd()
Go to end of iteration.
Definition: iterators.h:222
bool operator>=(const ChunkIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is the s...
Definition: iterators.h:1814
bool operator>=(const KernelIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is the s...
Definition: iterators.h:2116
bool operator==(const ChunkConstIter &other) const
Whether the position and parent are the same as another.
Definition: iterators.h:1384
Definition: accessors.h:29
Flat iterator iterator for NDArray. No information is kept about the current index. Just goes through all data. This casts the output to the type specified using T.
Definition: iterators.h:345
bool operator>=(const NDIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is the s...
Definition: iterators.h:1131
bool operator<(const Vector3DIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is befor...
Definition: iterators.h:2399
bool operator>=(const Vector3DConstIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is the s...
Definition: iterators.h:2773
FlatIter & operator++()
Prefix increment operator.
Definition: iterators.h:158
void setROI(size_t len, const size_t *roisize, const int64_t *roistart=NULL)
Sets the region of interest, with lower bound of 0. During iteration or any motion the position will ...
void set(int64_t i, T v)
Set the value at the ith element of thevector.
Definition: iterators.h:2322
void setArray(ptr< const NDArray > in)
Definition: iterators.h:1886
void setDim(size_t ndim, const size_t *dim)
Updates dimensions of target nd array.
T operator*() const
Dereference operator.
Definition: iterators.h:1331
bool isEnd() const
Are we one past the last element?
Definition: iterators.h:726
bool operator==(const FlatIter &other) const
Whether the position and parent are the same as another.
Definition: iterators.h:246
void goBegin()
Go to beginning of iteration.
Definition: iterators.h:471
bool operator!=(const KernelIter &other) const
Whether the position and parent are different from another.
Definition: iterators.h:2042
bool isBegin() const
Are we at the first element.
Definition: iterators.h:2365
ChunkSlicer & operator--()
Prefix negative iterator. Iterates in the order dictatored by the dimension order passsed during cons...
void set(T v)
Dereference operator.
Definition: iterators.h:1005
std::vector< int64_t > m_pos
Definition: slicer.h:802
bool eof() const
Are we one past the last element?
Definition: iterators.h:731
FlatConstIter()
Default constructor. Note, this will segfault if you don't use setArray to set the target NDArray/Ima...
Definition: iterators.h:352
bool isBegin() const
Are we at the begining of iteration?
Definition: slicer.h:75
bool isBegin() const
Are we at the first element.
Definition: iterators.h:1375
bool operator>(const FlatIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is after...
Definition: iterators.h:284
FlatConstIter & operator--()
Prefix decrement operator.
Definition: iterators.h:436
bool isEnd() const
Are we one past the last element?
Definition: iterators.h:1365
KernelIter & operator--()
Prefix decrement operator.
Definition: iterators.h:1963
Vector3DConstIter(std::shared_ptr< const NDArray > in)
Definition: iterators.h:2513
bool operator>(const Vector3DConstIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is after...
Definition: iterators.h:2733
std::vector< int64_t > m_linpos
Definition: slicer.h:1216
bool eof() const
Are we one past the last element?
Definition: iterators.h:232
Vector3DConstIter & operator--()
Prefix decrement operator.
Definition: iterators.h:2610
NDConstIter & operator++()
Prefix increment operator.
Definition: iterators.h:670
std::vector< size_t > m_dim
Definition: slicer.h:811
bool operator>(const NDIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is after...
Definition: iterators.h:1091
NDIter & operator--()
Prefix decrement operator.
Definition: iterators.h:968
FlatConstIter & operator++()
Prefix increment operator.
Definition: iterators.h:425
This class is used to step through an ND array in order of dimensions, but unlike Slicer it breaks th...
Definition: slicer.h:378
KernelIter & operator++()
Prefix increment operator.
Definition: iterators.h:1952
bool operator==(const NDIter &other) const
Whether the position and parent are the same as another.
Definition: iterators.h:1045
bool isEnd() const
Are we one past the last element?
Definition: iterators.h:1709
void goEnd()
Go to end of iteration.
Definition: iterators.h:2663
bool isEnd() const
Are we one past the last element?
Definition: iterators.h:1026
bool operator>(const ChunkConstIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is after...
Definition: iterators.h:1430
bool eof() const
Are we one past the last element?
Definition: iterators.h:1370
NDIter & operator++()
Prefix increment operator.
Definition: iterators.h:957
bool operator<=(const NDConstIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is the s...
Definition: iterators.h:812
T operator*() const
Dereference operator.
Definition: iterators.h:2621
Vector3DConstIter()
Default constructor. Note, this will segfault if you don't use setArray to set the target NDArray/Ima...
Definition: iterators.h:2511
ChunkConstIter()
Default constructor. Note, this will segfault if you don't use setArray to set the target NDArray/Ima...
Definition: iterators.h:1214
bool operator>(const FlatConstIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is after...
Definition: iterators.h:538
bool operator==(const NDConstIter &other) const
Whether the position and parent are the same as another.
Definition: iterators.h:745
ChunkConstIter & operator--()
Prefix decrement operator.
Definition: iterators.h:1298
Vector3DIter()
Default constructor. Note, this will segfault if you don't use setArray to set the target NDArray/Ima...
Definition: iterators.h:2157
void setArray(ptr< const NDArray > in)
Definition: iterators.h:2518
bool operator>=(const Vector3DIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is the s...
Definition: iterators.h:2460
This class is used to iterate through an 3D array, where each point then has has multiple higher dime...
Definition: iterators.h:2149
ChunkConstIter & operator++()
Prefix increment operator.
Definition: iterators.h:1287
bool operator!=(const ChunkConstIter &other) const
Whether the position and parent are different from another.
Definition: iterators.h:1396
ChunkIter()
Default constructor. Note, this will segfault if you don't use setArray to set the target NDArray/Ima...
Definition: iterators.h:1528
T operator[](int64_t i) const
Get value at ith element of vector.
Definition: iterators.h:2310
bool operator>=(const FlatIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is the s...
Definition: iterators.h:310
void setArray(ptr< NDArray > in)
Definition: iterators.h:2164
bool operator==(const FlatConstIter &other) const
Whether the position and parent are the same as another.
Definition: iterators.h:500
bool operator<(const KernelIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is befor...
Definition: iterators.h:2055
KernelIter()
Default constructor. Note, this will segfault if you don't use setArray to set the target NDArray/Ima...
Definition: iterators.h:1879
T operator*() const
Dereference operator, get center pixel value.
Definition: iterators.h:1974
KSlicer & operator++()
Prefix iterator. Iterates in the order dictatored by the dimension order passsed during construction ...
void goEnd()
Go to end of iteration.
Definition: iterators.h:1021
void goEnd()
Go to end of iteration.
Definition: iterators.h:1360
This class is used to iterate through an N-Dimensional array.
Definition: iterators.h:1520
void setArray(ptr< NDArray > in)
Definition: iterators.h:874
std::vector< int64_t > m_pos
Definition: slicer.h:346
bool operator>(const Vector3DIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is after...
Definition: iterators.h:2420
void set(T v) const
Dereference operator.
Definition: iterators.h:206
int64_t getC() const
Get image linear index of center.
Definition: slicer.h:1054
NDConstIter(std::shared_ptr< const NDArray > in)
Definition: iterators.h:599
bool isBegin() const
Are we at the first element.
Definition: iterators.h:491
bool operator!=(const NDIter &other) const
Whether the position and parent are different from another.
Definition: iterators.h:1057
bool operator<(const NDIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is befor...
Definition: iterators.h:1070
FlatConstIter(std::shared_ptr< const NDArray > in)
Definition: iterators.h:354
Vector3DIter & operator++()
Prefix increment operator.
Definition: iterators.h:2262
void goBegin()
Go to beginning of iteration.
Definition: iterators.h:1016
NDIter(std::shared_ptr< NDArray > in)
Definition: iterators.h:869
void goBegin()
Go to beginning of iteration.
Definition: iterators.h:716
bool operator<(const FlatIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is befor...
Definition: iterators.h:271
ChunkIter(std::shared_ptr< NDArray > in)
Definition: iterators.h:1530
bool operator!=(const NDConstIter &other) const
Whether the position and parent are different from another.
Definition: iterators.h:757
bool isEnd() const
Are we at the end of iteration? Note that this will be 1 past the end, as typically is done in c++...
Definition: slicer.h:431
void setDim(size_t ndim, const size_t *dim)
All around intializer. Sets all internal variables.
T getC() const
Same as dereference operator, get center pixel value.
Definition: iterators.h:1987
This class is used to slice an image in along a dimension, and to step an arbitrary direction in an i...
Definition: slicer.h:836
bool isBegin() const
Are we at the first element.
Definition: iterators.h:237
bool isBegin() const
Are we at the first element.
Definition: iterators.h:736
void goEnd()
Go to end of iteration.
Definition: iterators.h:2350
Iterator for an image, that allows for easy access to the neighbors of the current element/pixel...
Definition: iterators.h:1871
bool isEnd() const
Are we one past the last element?
Definition: iterators.h:2668
T operator*() const
Dereference operator.
Definition: iterators.h:2284
ChunkSlicer & prevChunk()
Return to the previous chunk (if there is one).
ChunkSlicer & operator++()
Prefix iterator. Iterates in the order dictatored by the dimension order passsed during construction ...
bool operator==(const KernelIter &other) const
Whether the position and parent are the same as another.
Definition: iterators.h:2030
bool operator!=(const ChunkIter &other) const
Whether the position and parent are different from another.
Definition: iterators.h:1740
void setArray(ptr< NDArray > in)
Definition: iterators.h:1535
bool operator<=(const ChunkIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is the s...
Definition: iterators.h:1795
bool operator<(const ChunkConstIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is befor...
Definition: iterators.h:1409
void goBegin()
Go to beginning of iteration.
Definition: iterators.h:2345
size_t m_linpos
Definition: slicer.h:334
T operator*() const
Dereference operator.
Definition: iterators.h:180
bool isBegin() const
Are we at the begining of iteration?
Definition: slicer.h:423
bool isEnd() const
Are we one past the last element?
Definition: iterators.h:227
void goEnd()
Jump to the end of iteration.
bool isBegin() const
Are we at the first element.
Definition: iterators.h:2678
ChunkIter & prevChunk()
Prefix decrement operator.
Definition: iterators.h:1651
T operator[](int64_t i) const
Get value at ith element of vector.
Definition: iterators.h:2647
bool operator<=(const Vector3DConstIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is the s...
Definition: iterators.h:2754
KernelIter(std::shared_ptr< const NDArray > in)
Definition: iterators.h:1881
bool isBegin() const
Are we at the first element.
Definition: iterators.h:1719
void goBegin()
Go to beginning of iteration.
Definition: iterators.h:217
void setArray(ptr< NDArray > in)
Definition: iterators.h:75
Slicer & operator--()
Prefix negative iterator. Iterates in the order dictatored by the dimension order passsed during cons...
T operator*() const
Dereference operator.
Definition: iterators.h:692
NDIter()
Default constructor. Note, this will segfault if you don't use setArray to set the target NDArray/Ima...
Definition: iterators.h:867
ChunkIter & nextChunk()
NextChunk.
Definition: iterators.h:1640
bool eof() const
Are we one past the last element?
Definition: iterators.h:1031
bool isEnd() const
Are we at the end of iteration? Note that this will be 1 past the end, as typically is done in c++...
Definition: slicer.h:83
bool eof() const
Are we one past the last element?
Definition: iterators.h:2673
std::shared_ptr< T > ptr
Make the shared_ptr name shorter...
Definition: npltypes.h:42
bool operator>(const KernelIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is after...
Definition: iterators.h:2076
void goEnd()
Jump to the end of the last chunk.
void goBegin()
Are we at the begining of iteration?
bool operator==(const Vector3DConstIter &other) const
Whether the position and parent are the same as another.
Definition: iterators.h:2687
bool operator<(const FlatConstIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is befor...
Definition: iterators.h:525
Vector3DConstIter & operator++()
Prefix increment operator.
Definition: iterators.h:2599
bool operator<=(const NDIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is the s...
Definition: iterators.h:1112
bool eof() const
Are we one past the last element?
Definition: iterators.h:2360
FlatIter(std::shared_ptr< NDArray > in)
Definition: iterators.h:70
bool operator<(const NDConstIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is befor...
Definition: iterators.h:770
size_t tlen() const
Definition: iterators.h:2471
bool eof() const
Are we one past the last element?
Definition: iterators.h:1714
bool operator!=(const FlatConstIter &other) const
Whether the position and parent are different from another.
Definition: iterators.h:512
bool isBegin() const
Are we at the first element.
Definition: iterators.h:1036
NDConstIter & operator--()
Prefix decrement operator.
Definition: iterators.h:681
bool isEnd() const
Are we one past the last element?
Definition: iterators.h:2355
Vector3DIter & operator--()
Prefix decrement operator.
Definition: iterators.h:2273
void goBegin()
Go to beginning of iteration.
Definition: iterators.h:1355
bool isEnd() const
Are we one past the last element?
Definition: iterators.h:481
bool operator>=(const NDConstIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is the s...
Definition: iterators.h:831
void goEnd()
Go to end of iteration.
Definition: iterators.h:721
bool operator>=(const FlatConstIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is the s...
Definition: iterators.h:564
void setArray(ptr< const NDArray > in)
Definition: iterators.h:1221
ChunkConstIter & prevChunk()
Prefix decrement operator.
Definition: iterators.h:1320
size_t m_linpos
Definition: slicer.h:801
Constant iterator for NDArray. Typical usage calls for NDConstIter it(array); it++; *it...
Definition: iterators.h:590
bool operator<(const Vector3DConstIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is befor...
Definition: iterators.h:2712
This class is used to step through an ND array in order of dimensions. Order may be any size from 0 t...
Definition: slicer.h:31
ChunkIter & operator--()
Prefix decrement operator.
Definition: iterators.h:1629
bool operator==(const ChunkIter &other) const
Whether the position and parent are the same as another.
Definition: iterators.h:1728
Constant iterator for NDArray. This is slightly different from order iterator in that the ROI may be ...
Definition: iterators.h:1206
ChunkConstIter & nextChunk()
Prefix increment operator.
Definition: iterators.h:1309
bool operator!=(const FlatIter &other) const
Whether the position and parent are different from another.
Definition: iterators.h:258
T operator*() const
Dereference operator.
Definition: iterators.h:447
bool operator<(const ChunkIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is befor...
Definition: iterators.h:1753
Vector3DIter(std::shared_ptr< NDArray > in)
Definition: iterators.h:2159
bool operator<=(const ChunkConstIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is the s...
Definition: iterators.h:1451
void setDim(size_t ndim, const size_t *dim)
Sets the dimensionality of iteration, and the dimensions of the image.
T getK(int64_t k) const
Dereference (get) the pixel at the k'th offset position. To figure out WHERE this pixel is in relatio...
Definition: iterators.h:2001
void goEnd()
Go to end of iteration.
Definition: iterators.h:1704
This class is used to iterate through an 3D array, where each point then has has multiple higher dime...
Definition: iterators.h:2503
void setArray(ptr< const NDArray > in)
Definition: iterators.h:604
bool operator<=(const Vector3DIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is the s...
Definition: iterators.h:2441
bool operator>(const NDConstIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is after...
Definition: iterators.h:791
std::vector< int64_t * > m_pos
Definition: slicer.h:1214
void goEnd()
Go to end of iteration.
Definition: iterators.h:476
bool operator==(const Vector3DIter &other) const
Whether the position and parent are the same as another.
Definition: iterators.h:2374
bool operator>(const ChunkIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is after...
Definition: iterators.h:1774
void goBegin()
Go to the very beginning for the first chunk.
NDConstIter()
Default constructor. Note, this will segfault if you don't use setArray to set the target NDArray/Ima...
Definition: iterators.h:597
T operator[](int64_t k) const
Dereference (get) the pixel at the k'th offset position. To figure out WHERE this pixel is in relatio...
Definition: iterators.h:2015
Slicer & operator++()
Prefix iterator. Iterates in the order dictatored by the dimension order passsed during construction ...
void set(T v)
Dereference operator.
Definition: iterators.h:1688
bool operator!=(const Vector3DConstIter &other) const
Whether the position and parent are different from another.
Definition: iterators.h:2699
bool eof() const
Are we one past the last element?
Definition: iterators.h:486
FlatIter()
Default constructor. Note, this will segfault if you don't use setArray to set the target NDArray/Ima...
Definition: iterators.h:68
int64_t getK(int64_t kit) const
Get index of i'th kernel (center-offset) element. Note that values outside the image will not be retu...
Definition: slicer.h:1093
std::vector< size_t > m_dim
Definition: slicer.h:352
ChunkIter & operator++()
Prefix increment operator.
Definition: iterators.h:1618
T operator*() const
Dereference operator.
Definition: iterators.h:1662
bool operator<=(const FlatIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is the s...
Definition: iterators.h:297
ChunkConstIter(std::shared_ptr< const NDArray > in)
Definition: iterators.h:1216
void set(T v)
Set the value at the 0th element of the vector.
Definition: iterators.h:2334
Flat iterator for NDArray. No information is kept about the current ND index. Just goes through all d...
Definition: iterators.h:61
bool operator!=(const Vector3DIter &other) const
Whether the position and parent are different from another.
Definition: iterators.h:2386
void goBegin()
Go to beginning of iteration.
Definition: iterators.h:1699
T operator*() const
Dereference operator.
Definition: iterators.h:979
This class is used to iterate through an N-Dimensional array.
Definition: iterators.h:860
bool operator<=(const FlatConstIter &other) const
If the parents are different then false, if they are the same, returns whether this iterator is the s...
Definition: iterators.h:551
size_t tlen() const
Definition: iterators.h:2784