16 template <
class GradientType,
class BValueScalarType>
20 m_GradientFileName =
"";
21 m_BValueBaseString =
"";
23 m_B0ValueThreshold = 0;
24 m_TotalNumberOfDirections = 0;
29 m_GradientIndependentNormalization =
true;
33 template <
class GradientType,
class BValueScalarType>
41 std::vector <bool> resVal(m_TotalNumberOfDirections,
false);
43 for (
unsigned int i = 0;i < m_TotalNumberOfDirections;++i)
45 if (m_BValues[i] <= m_B0ValueThreshold)
52 template <
class GradientType,
class BValueScalarType>
63 template <
class GradientType,
class BValueScalarType>
74 template <
class GradientType,
class BValueScalarType>
82 return m_GradientStrengths;
85 template <
class GradientType,
class BValueScalarType>
93 return m_TotalNumberOfDirections;
96 template <
class GradientType,
class BValueScalarType>
104 int startIndex = m_GradientFileName.size() - 6;
108 std::string testExt = m_GradientFileName.substr(startIndex);
109 if (testExt.find(
"bvec") != std::string::npos)
110 this->ReadGradientsFromBVecFile();
112 this->ReadGradientsFromTextFile();
114 if (m_BValueBaseString !=
"")
119 for (
unsigned int i = 0;i < m_TotalNumberOfDirections;++i)
125 for (
unsigned int j = 0;j < 3;++j)
126 m_Gradients[i][j] = 0;
132 if (!m_GradientIndependentNormalization)
137 if (!m_GradientIndependentNormalization)
138 m_BValues[i] *= norm;
143 m_GradientStrengths.resize(m_TotalNumberOfDirections);
144 for (
unsigned int i = 0;i < m_TotalNumberOfDirections;++i)
151 template <
class GradientType,
class BValueScalarType>
156 std::ifstream gradFile(m_GradientFileName.c_str());
157 m_TotalNumberOfDirections = 0;
159 if (!gradFile.is_open())
160 throw itk::ExceptionObject(__FILE__, __LINE__,
"Could not open gradient file as a bvec file",ITK_LOCATION);
163 std::vector < std::vector <double> > trVecs(3);
165 for (
unsigned int i = 0;i < 3;++i)
170 throw itk::ExceptionObject(__FILE__, __LINE__,
"BVec file is missing data",ITK_LOCATION);
175 std::getline(gradFile,workStr);
176 }
while((workStr ==
"")&&(!gradFile.eof()));
178 workStr.erase(workStr.find_last_not_of(
" \n\r\t")+1);
180 std::istringstream iss(workStr);
181 std::string shortStr;
185 trVecs[i].push_back(std::stod(shortStr));
190 m_TotalNumberOfDirections = trVecs[0].size();
192 m_Gradients.resize(m_TotalNumberOfDirections);
193 for (
unsigned int i = 0;i < m_TotalNumberOfDirections;++i)
195 this->InitializeEmptyGradient(m_Gradients[i]);
196 for (
unsigned int j = 0;j < 3;++j)
197 m_Gradients[i][j] = trVecs[j][i];
203 template <
class GradientType,
class BValueScalarType>
208 std::ifstream gradFile(m_GradientFileName.c_str());
209 m_TotalNumberOfDirections = 0;
211 if (!gradFile.is_open())
213 throw itk::ExceptionObject(__FILE__, __LINE__,
"Could not open gradient file as a text file",ITK_LOCATION);
216 GradientType gradTmp;
217 this->InitializeEmptyGradient(gradTmp);
220 while (!gradFile.eof())
223 gradFile.getline(tmpStr,2048);
225 if (strcmp(tmpStr,
"") == 0)
229 std::stringstream tmpStrStream(tmpStr);
230 tmpStrStream >> a0 >> a1 >> a2;
236 m_Gradients.push_back(gradTmp);
239 m_TotalNumberOfDirections = m_Gradients.size();
244 template <
class GradientType,
class BValueScalarType>
249 m_BValues.resize(m_TotalNumberOfDirections);
251 std::ifstream bvalFile(m_BValueBaseString.c_str());
253 if (!bvalFile.is_open())
255 for (
unsigned int i = 0;i < m_TotalNumberOfDirections;++i)
256 m_BValues[i] = std::stod(m_BValueBaseString);
261 int startIndex = m_BValueBaseString.size() - 6;
265 std::string testExt = m_BValueBaseString.substr(startIndex);
266 if (testExt.find(
"bval") != testExt.size())
270 std::getline(bvalFile,workStr);
271 }
while((workStr ==
"")&&(!bvalFile.eof()));
273 workStr.erase(workStr.find_last_not_of(
" \n\r\t")+1);
275 std::istringstream iss(workStr);
276 std::string shortStr;
281 m_BValues[i] = std::stod(shortStr);
289 while (!bvalFile.eof())
292 bvalFile.getline(tmpStr,2048);
294 if (strcmp(tmpStr,
"") == 0)
297 m_BValues[i] = std::stod(tmpStr);
double GetGradientStrengthFromBValue(double bValue, double smallDelta, double bigDelta)
Given b-value in s/mm^2 and deltas in s, computes gradient strength in T/mm.
std::vector< BValueScalarType > BValueVectorType
double ComputeNorm(const VectorType &v)
std::vector< bool > GetB0Directions()
const double DiffusionBigDelta
Default big delta value (classical values)
GradientVectorType & GetGradients()
const double DiffusionSmallDelta
Default small delta value (classical values)
std::vector< GradientType > GradientVectorType
BValueVectorType & GetGradientStrengths()
void Normalize(const VectorType &v, const unsigned int NDimension, VectorType &resVec)
BValueVectorType & GetBValues()
unsigned int GetTotalNumberOfDirections()