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