DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkSamplingSchemeQSpaceWriter.hxx
Go to the documentation of this file.
1 
20 #ifndef __itkSamplingSchemeQSpaceWriter_hxx
21 #define __itkSamplingSchemeQSpaceWriter_hxx
22 
24 #include "utl.h"
25 
26 namespace itk
27 {
28 
29 template <class TSamplingType>
32 {
33  m_BFile="";
34  m_OrientationFile="";
35  m_Sampling = NULL;
36 
37  m_SaveSingleShell = false;
38  m_SaveAllShellsInOneFile = true;
39 }
40 
41 
42 template <class TSamplingType>
43 void
45 ::PrintSelf(std::ostream& os, Indent indent) const
46 {
47  Superclass::PrintSelf(os, indent);
48 
49  os << indent << "m_BFile: " << m_BFile << std::endl;
50  os << indent << "m_OrientationFile: " << m_OrientationFile << std::endl;
51  os << indent << "m_SaveSingleShell: " << m_SaveSingleShell << std::endl;
52  os << indent << "m_SaveAllShellsInOneFile: " << m_SaveAllShellsInOneFile << std::endl;
53  m_Sampling->Print(os<< indent << "m_Sampling\n");
54 }
55 
56 template <class TSamplingType>
57 void
60 {
61  utlGlobalException(!m_Sampling, "need to set m_Sampling");
62  utlGlobalException(!m_SaveSingleShell && !m_SaveAllShellsInOneFile, "need to set m_SaveSingleShell or m_SaveAllShellsInOneFile");
63  utlGlobalException(m_OrientationFile=="", "need to set m_OrientationFile");
64 
65  if (m_SaveAllShellsInOneFile)
66  {
67  typename SamplingType::MatrixPointer orientationMatrix = m_Sampling->GetOrientationsCartesian();
68  std::cout << "save all orientations to " << m_OrientationFile << std::endl << std::flush;
69  orientationMatrix->Save(m_OrientationFile);
70  if (m_BFile!="")
71  {
72  typename SamplingType::STDVectorPointer bVector = m_Sampling->GetBVector();
73  std::cout << "save all bValues to " << m_BFile << std::endl << std::flush;
74  utl::SaveVector(*bVector, m_BFile);
75  }
76  }
77 
78  if (m_SaveSingleShell)
79  {
80  unsigned int numberOfShells = m_Sampling->GetNumberOfShells();
81  utlGlobalException(numberOfShells==0, "need to set IndicesInShells in m_Sampling");
82 
83  typename SamplingType::MatrixPointer orientationMatrix;
84  typename SamplingType::STDVectorPointer bVector;
85  std::string realBFile, realOrientationFile, bExt, orientationExt, bNoExt, orientationNoExt, indexStr;
86  if (m_BFile!="")
87  utl::GetFileExtension(m_BFile, bExt, bNoExt);
88  utl::GetFileExtension(m_OrientationFile, orientationExt, orientationNoExt);
89 
90  for ( int i = 0; i < numberOfShells; i += 1 )
91  {
92  bVector = m_Sampling->GetBVectorInShell(i);
93  if (bVector->size()>0)
94  {
95  // m_Sampling has m_BVector
96  double sum=0;
97  for ( unsigned int j = 0; j < bVector->size(); j += 1 )
98  sum += bVector->operator[](j);
99  sum /= (double)bVector->size();
100  int meanInt = (int)(sum);
101  indexStr = utl::ConvertNumberToString(meanInt);
102  }
103  else
104  {
105  // m_Sampling has no m_BVector
106  indexStr = "shell" + utl::ConvertNumberToString(i+1);
107  }
108  if (m_BFile!="")
109  {
110  realBFile = bNoExt + "_" + indexStr + "." + bExt;
111  utl::SaveVector(*bVector, realBFile);
112  std::cout << "save b values in shell " << i+1 << " to " << realOrientationFile << std::endl << std::flush;
113  }
114  orientationMatrix = m_Sampling->GetOrientationsCartesianInShell(i);
115  realOrientationFile = orientationNoExt + "_" + indexStr + "." + orientationExt;
116  std::cout << "save orientations in shell " << i+1 << " to " << realOrientationFile << std::endl << std::flush;
117  orientationMatrix->Save(realOrientationFile);
118  }
119  }
120 }
121 
122 }
123 
124 
125 #endif
126 
void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
void SaveVector(const VectorType &vv, const int NSize, const std::string &vectorStr, const bool is_save_number=false)
Definition: utlCore.h:1213
helper functions specifically used in dmritool
std::string ConvertNumberToString(const T value, const int precision=6)
Definition: utlCore.h:740
#define utlGlobalException(cond, expout)
Definition: utlCoreMacro.h:372
void GetFileExtension(const std::string &fileNameAbsolute, std::string &ext, std::string &fileNoExt)
Definition: utlCore.h:559