OpenWalnut  1.5.0dev
WDataSetRawHARDI.cpp
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 #include <memory>
26 #include <string>
27 #include <vector>
28 
29 #include "../common/WAssert.h"
30 #include "WDataSetRawHARDI.h"
31 #include "WDataSetSingle.h"
32 
33 // prototype instance as singleton
34 std::shared_ptr< WPrototyped > WDataSetRawHARDI::m_prototype = std::shared_ptr< WPrototyped >();
35 
36 void WDataSetRawHARDI::init( std::shared_ptr< WValueSetBase > newValueSet,
37  std::shared_ptr< WGrid > newGrid,
38  std::shared_ptr< std::vector< WVector3d > > newGradients )
39 {
40  WAssert( newValueSet, "No value set given." );
41  WAssert( newGrid, "No grid given." );
42  WAssert( newGradients, "No gradients given." );
43  WAssert( newValueSet->size() == newGrid->size(), "Number of voxel entries unequal number of positions in grid." );
44  WAssert( newValueSet->order() != newGradients->size(), "Number of gradients unequal number of entries in value set." );
46 }
47 
48 WDataSetRawHARDI::WDataSetRawHARDI( std::shared_ptr< WValueSetBase > newValueSet,
49  std::shared_ptr< WGrid > newGrid,
50  std::shared_ptr< std::vector< WVector3d > > newGradients,
51  double diffusionBValue )
52  : WDataSetSingle( newValueSet, newGrid ), m_gradients( newGradients ), m_diffusionBValues( new std::vector< float >( 1, diffusionBValue ) )
53 {
54  init( newValueSet, newGrid, newGradients );
55 }
56 
57 WDataSetRawHARDI::WDataSetRawHARDI( std::shared_ptr< WValueSetBase > newValueSet,
58  std::shared_ptr< WGrid > newGrid,
59  std::shared_ptr< std::vector< WVector3d > > newGradients,
60  std::shared_ptr< std::vector< float > > diffusionBValues )
61  : WDataSetSingle( newValueSet, newGrid ), m_gradients( newGradients ), m_diffusionBValues( diffusionBValues )
62 {
63  WAssert( diffusionBValues, "No b-values given." );
64  init( newValueSet, newGrid, newGradients );
65 }
66 
68 {
69  std::vector< size_t > validIndices;
70  for( size_t i = 0; i < m_gradients->size(); ++i )
71  {
72  const WVector3d& grad = ( *m_gradients )[ i ];
73  if( ( grad[ 0 ] != 0.0 ) || ( grad[ 1 ] != 0.0 ) || ( grad[ 2 ] != 0.0 ) )
74  {
75  m_nonZeroGradientIndexes.push_back( i );
76  }
77  else
78  {
79  m_zeroGradientIndexes.push_back( i );
80  }
81  }
82 }
83 
85  : WDataSetSingle()
86 {
87 }
88 
90 {
91 }
92 
93 WDataSetSingle::SPtr WDataSetRawHARDI::clone( std::shared_ptr< WValueSetBase > newValueSet, std::shared_ptr< WGrid > newGrid ) const
94 {
95  return WDataSetSingle::SPtr( new WDataSetRawHARDI( newValueSet, newGrid, m_gradients, getDiffusionBValues() ) );
96 }
97 
98 WDataSetSingle::SPtr WDataSetRawHARDI::clone( std::shared_ptr< WValueSetBase > newValueSet ) const
99 {
101 }
102 
103 WDataSetSingle::SPtr WDataSetRawHARDI::clone( std::shared_ptr< WGrid > newGrid ) const
104 {
106 }
107 
109 {
111 }
112 
113 std::shared_ptr< WPrototyped > WDataSetRawHARDI::getPrototype()
114 {
115  if( !m_prototype )
116  {
117  m_prototype = std::shared_ptr< WPrototyped >( new WDataSetRawHARDI() );
118  }
119 
120  return m_prototype;
121 }
122 
123 const WVector3d& WDataSetRawHARDI::getGradient( size_t index ) const
124 {
125 #ifdef DEBUG
126  return m_gradients->at( index );
127 #else
128  return (*m_gradients)[ index ];
129 #endif
130 }
131 
132 std::shared_ptr< std::vector< WVector3d > > WDataSetRawHARDI::getOrientations() const
133 {
134  return m_gradients;
135 }
136 
138 {
139  WAssert( ( *m_diffusionBValues ).size() == 1, "There is more then one diffusion b-value!" );
140  return ( *m_diffusionBValues )[ 0 ];
141 }
142 
143 std::shared_ptr< std::vector< float > > WDataSetRawHARDI::getDiffusionBValues() const
144 {
145  return m_diffusionBValues;
146 }
147 
149 {
150  return m_gradients->size();
151 }
152 
153 const std::string WDataSetRawHARDI::getName() const
154 {
155  return "WDataSetRawHARDI";
156 }
157 
158 const std::string WDataSetRawHARDI::getDescription() const
159 {
160  return "Contains HARDI measurements.";
161 }
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.
virtual ~WDataSetRawHARDI()
Destroys this DataSet instance.
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 > getValueSet() const
std::shared_ptr< WGrid > getGrid() const
std::shared_ptr< WDataSetSingle > SPtr
Convenience typedef for a std::shared_ptr.