OpenWalnut  1.5.0dev
WDataSetRawHARDI.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WDATASETRAWHARDI_H
26 #define WDATASETRAWHARDI_H
27 
28 #include <memory>
29 #include <string>
30 #include <vector>
31 
32 #include "../common/math/linearAlgebra/WVectorFixed.h"
33 #include "WDataSetSingle.h"
34 
35 
36 /**
37  * This data set type contains raw HARDI and its gradients.
38  * \ingroup dataHandler
39  */
40 class WDataSetRawHARDI : public WDataSetSingle // NOLINT
41 {
42 public:
43  /**
44  * Constructs an instance out of:
45  * - an appropriate value set with a vector of measure values for each voxel,
46  * - a grid and
47  * - the gradients used during the measurement of the different values.
48  *
49  * \param newValueSet the vector value set to use
50  * \param newGrid the grid which maps world space to the value set
51  * \param newGradients the Gradients of the
52  * \param diffusionBValue Strength of the gradient
53  */
54  WDataSetRawHARDI( std::shared_ptr< WValueSetBase > newValueSet,
55  std::shared_ptr< WGrid > newGrid,
56  std::shared_ptr< std::vector< WVector3d > > newGradients,
57  double diffusionBValue = 1.0 );
58 
59  /**
60  * Constructs an instance out of:
61  * - an appropriate value set with a vector of measure values for each voxel,
62  * - a grid and
63  * - the gradients used during the measurement of the different values.
64  *
65  * \param newValueSet the vector value set to use
66  * \param newGrid the grid which maps world space to the value set
67  * \param newGradients the Gradients of the
68  * \param diffusionBValues Strength of the gradient for every gradient
69  */
70  WDataSetRawHARDI( std::shared_ptr< WValueSetBase > newValueSet,
71  std::shared_ptr< WGrid > newGrid,
72  std::shared_ptr< std::vector< WVector3d > > newGradients,
73  std::shared_ptr< std::vector< float > > diffusionBValues );
74 
75  /**
76  * Construct an empty and unusable instance. This is needed for the prototype mechanism.
77  */
79 
80  /**
81  * Destroys this DataSet instance
82  */
83  virtual ~WDataSetRawHARDI();
84 
85  /**
86  * Creates a copy (clone) of this instance but allows one to change the valueset. Unlike copy construction, this is a very useful function if you
87  * want to keep the dynamic type of your dataset.
88  *
89  * \param newValueSet the new valueset.
90  * \param newGrid the new grid.
91  *
92  * \return the clone
93  */
94  virtual WDataSetSingle::SPtr clone( std::shared_ptr< WValueSetBase > newValueSet, std::shared_ptr< WGrid > newGrid ) const;
95 
96 
97  /**
98  * Creates a copy (clone) of this instance but allows one to change the valueset. Unlike copy construction, this is a very useful function if you
99  * want to keep the dynamic type of your dataset even if you just have a WDataSetSingle.
100  *
101  * \param newValueSet the new valueset.
102  *
103  * \return the clone
104  */
105  virtual WDataSetSingle::SPtr clone( std::shared_ptr< WValueSetBase > newValueSet ) const;
106 
107  /**
108  * Creates a copy (clone) of this instance but allows one to change the grid. Unlike copy construction, this is a very useful function if you
109  * want to keep the dynamic type of your dataset even if you just have a WDataSetSingle.
110  *
111  * \param newGrid the new grid.
112  *
113  * \return the clone
114  */
115  virtual WDataSetSingle::SPtr clone( std::shared_ptr< WGrid > newGrid ) const;
116 
117  /**
118  * Creates a copy (clone) of this instance. Unlike copy construction, this is a very useful function if you
119  * want to keep the dynamic type of your dataset even if you just have a WDataSetSingle.
120  *
121  * \return the clone
122  */
123  virtual WDataSetSingle::SPtr clone() const;
124 
125  /**
126  * Returns a prototype instantiated with the true type of the deriving class.
127  *
128  * \return the prototype.
129  */
130  static std::shared_ptr< WPrototyped > getPrototype();
131 
132  /**
133  * Returns the gradient for the index.
134  *
135  * \return gradient of measurement
136  *
137  * \param index
138  */
139  const WVector3d& getGradient( size_t index ) const;
140 
141  /**
142  * Returns the count of measurements per voxel, which is equal to the count of the used gradients.
143  *
144  * \return measurements per voxel
145  */
146  std::size_t getNumberOfMeasurements() const;
147 
148  /**
149  * Gets the name of this prototype.
150  *
151  * \return the name.
152  */
153  virtual const std::string getName() const;
154 
155  /**
156  * Gets the description for this prototype.
157  *
158  * \return the description
159  */
160  virtual const std::string getDescription() const;
161 
162  /**
163  * Get the orientations.
164  *
165  * \return A vector of orientations.
166  */
167  std::shared_ptr< std::vector< WVector3d > > getOrientations() const;
168 
169  /**
170  * Get the indexes of zero gradients.
171  *
172  * \return Returns the indexes for the which gradient is zero.
173  */
174  std::vector< size_t > const& getZeroGradientIndexes() const;
175 
176  /**
177  * Get the indexes of non-zero gradients.
178  *
179  * \return Returns the indexes for the which gradient is non-zero.
180  */
181  std::vector< size_t > const& getNonZeroGradientIndexes() const;
182 
183  /**
184  * Returns only the measurements for which the gradient was non-zero.
185  *
186  * \param index the index of the voxel.
187  *
188  * \return non-zero gradient signals
189  */
190  template< typename T > WValue< T > getNonZeroGradientSignals( size_t index ) const;
191 
192  /**
193  * Returns the \e b-value of the diffusion.
194  *
195  * \return b-value as double
196  */
197  double getDiffusionBValue() const;
198 
199  /**
200  * Returns the \e b-values of the diffusion if there are different values.
201  *
202  * \return a vector of b-values
203  */
204  std::shared_ptr< std::vector< float > > getDiffusionBValues() const;
205 
206 protected:
207  /**
208  * The prototype as singleton.
209  */
210  static std::shared_ptr< WPrototyped > m_prototype;
211 
212 private:
213  /**
214  * Makes only such initialization which is common to all contructors.
215  *
216  * \param newValueSet The value set
217  * \param newGrid The grid
218  * \param newGradients The gradients
219  */
220  void init( std::shared_ptr< WValueSetBase > newValueSet,
221  std::shared_ptr< WGrid > newGrid,
222  std::shared_ptr< std::vector< WVector3d > > newGradients );
223  /**
224  * Build indexes for the zero and non-zero gradients.
225  */
226  void buildGradientIndexes();
227 
228  std::shared_ptr< std::vector< WVector3d > > m_gradients; //!< Gradients of measurements
229 
230  /**
231  * Strength (b-value) of the so-called magnetic diffusion gradient. The vector contains only
232  * one value, incase all gradients (except b0 images) share the same b-value.
233  */
234  std::shared_ptr< std::vector< float > > m_diffusionBValues;
235 
236  /**
237  * The indexes for the which gradient is zero.
238  */
239  std::vector< size_t > m_zeroGradientIndexes;
240 
241  /**
242  * The indexes for the which gradient is non-zero.
243  */
244  std::vector< size_t > m_nonZeroGradientIndexes;
245 };
246 
247 inline std::vector< size_t > const& WDataSetRawHARDI::getZeroGradientIndexes() const
248 {
249  return m_zeroGradientIndexes;
250 }
251 
252 inline std::vector< size_t > const& WDataSetRawHARDI::getNonZeroGradientIndexes() const
253 {
255 }
256 
257 template< typename T > WValue< T > WDataSetRawHARDI::getNonZeroGradientSignals( size_t index ) const
258 {
259  WValue< T > result( m_nonZeroGradientIndexes.size() );
260  size_t idx = 0;
261  std::shared_ptr< WValueSet< T > > vs = std::dynamic_pointer_cast< WValueSet< T > >( m_valueSet );
262  WValue< T > signal( vs->getWValue( index ) );
263  for( std::vector< size_t >::const_iterator cit = m_nonZeroGradientIndexes.begin(); cit != m_nonZeroGradientIndexes.end(); ++cit )
264  {
265  result[ idx ] = signal[ *cit ];
266  ++idx;
267  }
268  return result;
269 }
270 
271 
272 #endif // WDATASETRAWHARDI_H
This data set type contains raw HARDI and its gradients.
virtual const std::string getDescription() const
Gets the description for this prototype.
virtual const std::string getName() const
Gets the name of this prototype.
std::shared_ptr< std::vector< WVector3d > > m_gradients
Gradients of measurements.
std::vector< size_t > m_zeroGradientIndexes
The indexes for the which gradient is zero.
std::vector< size_t > const & getNonZeroGradientIndexes() const
Get the indexes of non-zero gradients.
virtual ~WDataSetRawHARDI()
Destroys this DataSet instance.
WValue< T > getNonZeroGradientSignals(size_t index) const
Returns only the measurements for which the gradient was non-zero.
std::vector< size_t > const & getZeroGradientIndexes() const
Get the indexes of zero gradients.
virtual WDataSetSingle::SPtr clone() const
Creates a copy (clone) of this instance.
std::shared_ptr< std::vector< float > > m_diffusionBValues
Strength (b-value) of the so-called magnetic diffusion gradient.
const WVector3d & getGradient(size_t index) const
Returns the gradient for the index.
void buildGradientIndexes()
Build indexes for the zero and non-zero gradients.
static std::shared_ptr< WPrototyped > m_prototype
The prototype as singleton.
std::vector< size_t > m_nonZeroGradientIndexes
The indexes for the which gradient is non-zero.
double getDiffusionBValue() const
Returns the b-value of the diffusion.
WDataSetRawHARDI()
Construct an empty and unusable instance.
std::shared_ptr< std::vector< float > > getDiffusionBValues() const
Returns the b-values of the diffusion if there are different values.
static std::shared_ptr< WPrototyped > getPrototype()
Returns a prototype instantiated with the true type of the deriving class.
std::shared_ptr< std::vector< WVector3d > > getOrientations() const
Get the orientations.
std::size_t getNumberOfMeasurements() const
Returns the count of measurements per voxel, which is equal to the count of the used gradients.
void init(std::shared_ptr< WValueSetBase > newValueSet, std::shared_ptr< WGrid > newGrid, std::shared_ptr< std::vector< WVector3d > > newGradients)
Makes only such initialization which is common to all contructors.
A data set consisting of a set of values based on a grid.
std::shared_ptr< WValueSetBase > m_valueSet
Stores the reference of the WValueSet of this DataSetSingle instance.
std::shared_ptr< WDataSetSingle > SPtr
Convenience typedef for a std::shared_ptr.
Base class for all higher level values like tensors, vectors, matrices and so on.
Definition: WValue.h:41