Developer documentation
Version 3.0.3-105-gd3941f44
streamline.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 __dwi_tractography_streamline_h__
18#define __dwi_tractography_streamline_h__
19
20
21#include <limits>
22
23#include "types.h"
24
25
26namespace MR
27{
28 namespace DWI
29 {
30 namespace Tractography
31 {
32
33
34
35 // Base class for storing an index alongside either streamline vertex or track scalar data
36 //
39 public:
40 static constexpr size_t invalid = std::numeric_limits<size_t>::max();
41 DataIndex () : index (invalid) { }
42 DataIndex (const size_t i) : index (i) { }
43 DataIndex (const DataIndex& i) : index (i.index) { }
44 DataIndex (DataIndex&& i) : index (i.index) { i.index = invalid; }
45 DataIndex& operator= (const DataIndex& i) { index = i.index; return *this; }
46 DataIndex& operator= (DataIndex&& i) { index = i.index; i.index = invalid; return *this; }
47 void set_index (const size_t i) { index = i; }
48 size_t get_index() const { return index; }
49 void clear() { index = invalid; }
50 bool operator< (const DataIndex& i) const { return index < i.index; }
51 private:
52 size_t index;
53 };
54
55
56
57
58 // A class for track scalars
59 template <typename ValueType = float>
60 class TrackScalar : public vector<ValueType>, public DataIndex
62 public:
63 using value_type = ValueType;
65 TrackScalar () = default;
66 TrackScalar (const TrackScalar&) = default;
67 TrackScalar (TrackScalar&& that) :
68 vector<value_type> (std::move (that)),
69 DataIndex (std::move (that)) { }
70 TrackScalar& operator= (const TrackScalar& that) = default;
71 void clear() { vector<ValueType>::clear(); DataIndex::clear(); }
72 };
73
74
75
76
77 template <typename ValueType = float>
78 class Streamline : public vector<Eigen::Matrix<ValueType,3,1>>, public DataIndex
80 public:
81 using point_type = Eigen::Matrix<ValueType,3,1>;
82 using value_type = ValueType;
83
84 Streamline () : weight (1.0f) { }
85
86 Streamline (size_t size) :
87 vector<point_type> (size),
88 weight (value_type (1.0)) { }
89
90 Streamline (size_t size, const point_type& fill) :
91 vector<point_type> (size, fill),
92 weight (value_type (1.0)) { }
93
94 Streamline (const Streamline&) = default;
95 Streamline& operator= (const Streamline& that) = default;
96
97 Streamline (Streamline&& that) :
98 vector<point_type> (std::move (that)),
99 DataIndex (std::move (that)),
100 weight (that.weight) {
101 that.weight = 1.0f;
102 }
103
104 Streamline (const vector<point_type>& tck) :
105 vector<point_type> (tck),
106 DataIndex (),
107 weight (1.0) { }
108
109 Streamline& operator= (Streamline&& that)
110 {
111 vector<point_type>::operator= (std::move (that));
112 DataIndex::operator= (std::move (that));
113 weight = that.weight; that.weight = 0.0f;
114 return *this;
115 }
116
117
118 void clear()
119 {
122 weight = 1.0;
123 }
124
125 float calc_length() const;
126 float calc_length (const float step_size) const;
127
128 float weight;
129 };
130
131
132
133 template <typename PointType>
134 typename PointType::Scalar length (const vector<PointType>& tck)
135 {
136 if (tck.empty())
137 return std::numeric_limits<typename PointType::Scalar>::quiet_NaN();
138 typename PointType::Scalar value = typename PointType::Scalar(0);
139 for (size_t i = 1; i != tck.size(); ++i)
140 value += (tck[i] - tck[i-1]).norm();
141 return value;
142 }
143
144
145
146 }
147 }
148}
149
150
151#endif
152
Array & operator=(const MR::Helper::ConstRow< ImageType > &row)
Definition: array.h:25
void set_index(const size_t i)
Definition: streamline.h:47
DataIndex & operator=(const DataIndex &i)
Definition: streamline.h:45
DataIndex(const DataIndex &i)
Definition: streamline.h:43
static constexpr size_t invalid
Definition: streamline.h:40
bool operator<(const DataIndex &i) const
Definition: streamline.h:50
VectorType::Scalar value(const VectorType &coefs, typename VectorType::Scalar cos_elevation, typename VectorType::Scalar cos_azimuth, typename VectorType::Scalar sin_azimuth, int lmax)
Definition: SH.h:233
#define NOMEMALIGN
Definition: memory.h:22
typename Streamline<>::point_type point_type
Definition: resampling.h:40
PointType::Scalar length(const vector< PointType > &tck)
Definition: streamline.h:134
MR::default_type value_type
Definition: typedefs.h:33
Definition: base.h:24
#define MEMALIGN(...)
Definition: types.h:185