Developer documentation
Version 3.0.3-105-gd3941f44
iterator.h
Go to the documentation of this file.
1/* Copyright (c) 2008-2022 the MRtrix3 contributors.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 *
7 * Covered Software is provided under this License on an "as is"
8 * basis, without warranty of any kind, either expressed, implied, or
9 * statutory, including, without limitation, warranties that the
10 * Covered Software is free of defects, merchantable, fit for a
11 * particular purpose or non-infringing.
12 * See the Mozilla Public License v. 2.0 for more details.
13 *
14 * For more details, see http://www.mrtrix.org/.
15 */
16
17#ifndef __algo_iterator_h__
18#define __algo_iterator_h__
19
20#include "types.h"
21
22namespace MR
23{
24
30 public:
31 Iterator() = delete;
32 template <class InfoType>
33 Iterator (const InfoType& S) :
34 d (S.ndim()),
35 p (S.ndim(), 0) {
36 for (size_t i = 0; i < S.ndim(); ++i)
37 d[i] = S.size(i);
38 }
39
40 size_t ndim () const { return d.size(); }
41 ssize_t size (size_t axis) const { return d[axis]; }
42
43 const ssize_t& index (size_t axis) const { return p[axis]; }
44 ssize_t& index (size_t axis) { return p[axis]; }
45
46 friend std::ostream& operator<< (std::ostream& stream, const Iterator& V) {
47 stream << "iterator, position [ ";
48 for (size_t n = 0; n < V.ndim(); ++n)
49 stream << V.index(n) << " ";
50 stream << "]";
51 return stream;
52 }
53
54 private:
55 vector<ssize_t> d, p;
56
57 void value () const { assert (0); }
58 };
59
61}
62
63#endif
64
65
66
a dummy image to iterate over, useful for multi-threaded looping.
Definition: iterator.h:29
ssize_t & index(size_t axis)
Definition: iterator.h:44
size_t ndim() const
Definition: iterator.h:40
ssize_t size(size_t axis) const
Definition: iterator.h:41
Iterator(const InfoType &S)
Definition: iterator.h:33
Iterator()=delete
const ssize_t & index(size_t axis) const
Definition: iterator.h:43
friend std::ostream & operator<<(std::ostream &stream, const Iterator &V)
Definition: iterator.h:46
#define NOMEMALIGN
Definition: memory.h:22
Definition: base.h:24
Eigen::MatrixXd S
int axis