OpenWalnut  1.3.1
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 <string>
29 #include <vector>
30 
31 #include "WDataSetSingle.h"
32 #include "../common/math/linearAlgebra/WLinearAlgebra.h"
33 
34 
35 /**
36  * This data set type contains raw HARDI and its gradients.
37  * \ingroup dataHandler
38  */
39 class WDataSetRawHARDI : public WDataSetSingle // NOLINT
40 {
41 public:
42  /**
43  * Constructs an instance out of:
44  * - an appropriate value set with a vector of measure values for each voxel,
45  * - a grid and
46  * - the gradients used during the measurement of the different values.
47  *
48  * \param newValueSet the vector value set to use
49  * \param newGrid the grid which maps world space to the value set
50  * \param newGradients the Gradients of the
51  * \param diffusionBValue Strength of the gradient
52  */
53  WDataSetRawHARDI( boost::shared_ptr< WValueSetBase > newValueSet,
54  boost::shared_ptr< WGrid > newGrid,
55  boost::shared_ptr< std::vector< WVector3d > > newGradients,
56  double diffusionBValue = 1.0 );
57 
58  /**
59  * Construct an empty and unusable instance. This is needed for the prototype mechanism.
60  */
62 
63  /**
64  * Destroys this DataSet instance
65  */
66  virtual ~WDataSetRawHARDI();
67 
68  /**
69  * 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
70  * want to keep the dynamic type of your dataset even if you just have a WDataSetSingle.
71  *
72  * \param newValueSet the new valueset.
73  *
74  * \return the clone
75  */
76  virtual WDataSetSingle::SPtr clone( boost::shared_ptr< WValueSetBase > newValueSet ) const;
77 
78  /**
79  * 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
80  * want to keep the dynamic type of your dataset even if you just have a WDataSetSingle.
81  *
82  * \param newGrid the new grid.
83  *
84  * \return the clone
85  */
86  virtual WDataSetSingle::SPtr clone( boost::shared_ptr< WGrid > newGrid ) const;
87 
88  /**
89  * Creates a copy (clone) of this instance. Unlike copy construction, this is a very useful function if you
90  * want to keep the dynamic type of your dataset even if you just have a WDataSetSingle.
91  *
92  * \return the clone
93  */
94  virtual WDataSetSingle::SPtr clone() const;
95 
96  /**
97  * Returns a prototype instantiated with the true type of the deriving class.
98  *
99  * \return the prototype.
100  */
101  static boost::shared_ptr< WPrototyped > getPrototype();
102 
103  /**
104  * Returns the gradient for the index.
105  *
106  * \return gradient of measurement
107  *
108  * \param index
109  */
110  const WVector3d& getGradient( size_t index ) const;
111 
112  /**
113  * Returns the count of measurements per voxel, which is equal to the count of the used gradients.
114  *
115  * \return measurements per voxel
116  */
117  std::size_t getNumberOfMeasurements() const;
118 
119  /**
120  * Gets the name of this prototype.
121  *
122  * \return the name.
123  */
124  virtual const std::string getName() const;
125 
126  /**
127  * Gets the description for this prototype.
128  *
129  * \return the description
130  */
131  virtual const std::string getDescription() const;
132 
133  /**
134  * Get the orientations.
135  *
136  * \return A vector of orientations.
137  */
138  std::vector< WVector3d > const& getOrientations() const;
139 
140  /**
141  * Get the indexes of zero gradients.
142  *
143  * \return Returns the indexes for the which gradient is zero.
144  */
145  std::vector< size_t > const& getZeroGradientIndexes() const;
146 
147  /**
148  * Get the indexes of non-zero gradients.
149  *
150  * \return Returns the indexes for the which gradient is non-zero.
151  */
152  std::vector< size_t > const& getNonZeroGradientIndexes() const;
153 
154  /**
155  * Returns only the measurements for which the gradient was non-zero.
156  *
157  * \param index the index of the voxel.
158  *
159  * \return non-zero gradient signals
160  */
161  template< typename T > WValue< T > getNonZeroGradientSignals( size_t index ) const;
162 
163  /**
164  * Returns the \e b-value of the diffusion.
165  *
166  * \return b-value as double
167  */
168  double getDiffusionBValue() const;
169 
170 protected:
171  /**
172  * The prototype as singleton.
173  */
174  static boost::shared_ptr< WPrototyped > m_prototype;
175 
176 private:
177  /**
178  * Build indexes for the zero and non-zero gradients.
179  */
180  void buildGradientIndexes();
181 
182  boost::shared_ptr< std::vector< WVector3d > > m_gradients; //!< Gradients of measurements
183  /**
184  * Strength (b-value) of the so-called magnetic diffusion gradient.
185  */
187 
188  /**
189  * The indexes for the which gradient is zero.
190  */
191  std::vector< size_t > m_zeroGradientIndexes;
192 
193  /**
194  * The indexes for the which gradient is non-zero.
195  */
196  std::vector< size_t > m_nonZeroGradientIndexes;
197 };
198 
199 inline std::vector< size_t > const& WDataSetRawHARDI::getZeroGradientIndexes() const
200 {
201  return m_zeroGradientIndexes;
202 }
203 
204 inline std::vector< size_t > const& WDataSetRawHARDI::getNonZeroGradientIndexes() const
205 {
207 }
208 
209 template< typename T > WValue< T > WDataSetRawHARDI::getNonZeroGradientSignals( size_t index ) const
210 {
211  WValue< T > result( m_nonZeroGradientIndexes.size() );
212  size_t idx = 0;
213  boost::shared_ptr< WValueSet< T > > vs = boost::dynamic_pointer_cast< WValueSet< T > >( m_valueSet );
214  WValue< T > signal( vs->getWValue( index ) );
215  for( std::vector< size_t >::const_iterator cit = m_nonZeroGradientIndexes.begin(); cit != m_nonZeroGradientIndexes.end(); ++cit )
216  {
217  result[ idx ] = signal[ *cit ];
218  ++idx;
219  }
220  return result;
221 }
222 
223 
224 #endif // WDATASETRAWHARDI_H