Developer documentation
Version 3.0.3-105-gd3941f44
loop.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 __fixel_loop_h__
18#define __fixel_loop_h__
19
20#include "fixel/types.h"
22
23namespace MR
24{
25 namespace Fixel {
26
27
28 namespace {
29 struct set_offset { NOMEMALIGN
30 FORCE_INLINE set_offset (index_type offset) : offset (offset) { }
31 template <class DataType>
32 FORCE_INLINE void operator() (DataType& data) { data.index(0) = offset; }
34 };
35
36 struct inc_fixel { NOMEMALIGN
37 template <class DataType>
38 FORCE_INLINE void operator() (DataType& data) { ++data.index(0); }
39 };
40 }
41
45
46 template <class... DataType>
47 struct Run { NOMEMALIGN
51 const std::tuple<DataType&...> data;
52 FORCE_INLINE Run (const index_type num_fixels, const index_type offset, const std::tuple<DataType&...>& data) :
54 apply (set_offset (offset), data);
55 }
56 FORCE_INLINE operator bool() const { return fixel_index < num_fixels; }
57 FORCE_INLINE void operator++() { apply (inc_fixel (), data); fixel_index++; }
58 FORCE_INLINE void operator++(int) const { operator++(); }
59 };
60
61 template <class... DataType>
62 FORCE_INLINE Run<DataType...> operator() (DataType&... data) const { return { num_fixels, offset, std::tie (data...) }; }
63
64 };
65
66 template <class IndexType>
67 FORCE_INLINE LoopFixelsInVoxel
68 Loop (IndexType& index) {
69 index.index(3) = 0;
70 index_type num_fixels = index.value();
71 index.index(3) = 1;
72 index_type offset = index.value();
73 return { num_fixels, offset };
74 }
75 }
76}
77
78#endif
index_type offset
Definition: loop.h:33
#define NOMEMALIGN
Definition: memory.h:22
FORCE_INLINE LoopFixelsInVoxel Loop(IndexType &index)
Definition: loop.h:68
uint32_t index_type
Definition: types.h:25
Definition: base.h:24
void apply(F &&f, T &&t)
invoke f(x) for each entry in t
Definition: apply.h:82
size_t index
#define FORCE_INLINE
Definition: types.h:156
FORCE_INLINE Run(const index_type num_fixels, const index_type offset, const std::tuple< DataType &... > &data)
Definition: loop.h:52
FORCE_INLINE void operator++(int) const
Definition: loop.h:58
NOMEMALIGN const index_type num_fixels
Definition: loop.h:48
const index_type offset
Definition: loop.h:49
const std::tuple< DataType &... > data
Definition: loop.h:51
FORCE_INLINE void operator++()
Definition: loop.h:57
const index_type offset
Definition: loop.h:44
NOMEMALIGN const index_type num_fixels
Definition: loop.h:43
FORCE_INLINE Run< DataType... > operator()(DataType &... data) const
Definition: loop.h:62