Developer documentation
Version 3.0.3-105-gd3941f44
neighbourhood3D.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 __adapter_neighbourhood_h__
18#define __adapter_neighbourhood_h__
19
20#include "image.h"
21#include "adapter/base.h"
22
23namespace MR
24{
25 namespace Adapter {
26
27 template <class ImageType>
29 public Base<NeighbourhoodCoord<ImageType>,ImageType>
31 public:
32
33 using base_type = Base<NeighbourhoodCoord<ImageType>, ImageType>;
34 using value_type = typename ImageType::value_type;
35
36 using base_type::name;
37 using base_type::spacing;
38
39
40 template <class VectorType>
41 NeighbourhoodCoord (const ImageType& original, const VectorType& extent, const Iterator& iter) :
42 base_type (original),
43 iter_ (iter),
44 transform_ (original.transform()) {
45
46 assert (extent.size() == ndim());
47 from_.resize(original.ndim());
48 size_.resize(original.ndim());
49 for (size_t i = 0; i < ndim(); ++i){
50 from_[i] = (iter_.index(i)-extent[i] < 0) ? 0 : iter_.index(i)-extent[i];
51 size_[i] = (from_[i] + extent[i] >= original.size(i)) ? original.size(i) - from_[i] -1 : extent[i];
52 assert (from_[n] + size_[n] < original.size(n));
53 }
54
55 // for (size_t n = 0; n < ndim(); ++n)
56 // if (from_[n] + size_[n] > original.size(n))
57 // throw Exception ("FIXME: dimensions requested for NeighbourhoodCoord adapter are out of bounds!");
58
59 for (size_t j = 0; j < 3; ++j)
60 for (size_t i = 0; i < 3; ++i)
61 transform_(i,3) += from_[j] * spacing(j) * transform_(i,j);
62 }
63
64 void reset () {
65 for (size_t n = 0; n < ndim(); ++n)
66 set_pos (n, 0);
67 }
68
69 size_t ndim () const { return size_.size(); }
70 ssize_t size (size_t axis) const { return size_ [axis]; }
71 const transform_type& transform() const { return transform_; }
72
73 ssize_t get_index (size_t axis) const { return parent().index(axis)-from_[axis]; }
74 void move_index (size_t axis, ssize_t increment) { parent().index(axis) += increment; }
75
76 protected:
77 using base_type::parent;
81 };
82
83 }
84}
85
86#endif
87
88
a dummy image to iterate over, useful for multi-threaded looping.
Definition: iterator.h:29
const ssize_t & index(size_t axis) const
Definition: iterator.h:43
MR::default_type value_type
Definition: typedefs.h:33
Definition: base.h:24
Eigen::Transform< default_type, 3, Eigen::AffineCompact > transform_type
the type for the affine transform of an image:
Definition: types.h:234
int axis
#define MEMALIGN(...)
Definition: types.h:185
const std::string name
Definition: thread.h:108