DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
SHCoefficientsRotate.cxx
Go to the documentation of this file.
1 
18 #include "utl.h"
21 #include "SHCoefficientsRotateCLP.h"
22 
23 
24 
25 int
26 main(int argc, char *argv[])
27 {
28  // GenerateCLP
29  PARSE_ARGS;
30 
31  utlException(_InputFile=="" || _OutputFile=="", "no input or no output!");
32 
33  // Time Probe
34  itk::TimeProbe clock;
35 
36  // Input and Output Image Types
37  typedef itk::VectorImage<double, 3> ImageType;
38  ImageType::Pointer shImage, shRotatedImage;
39 
40  itk::ReadImage<ImageType>(_InputFile, shImage);
41  // int dimension = shImage->GetNumberOfComponentsPerPixel();
42 
44  RotateFilterType::Pointer rotateFilter = RotateFilterType::New();
45 
46  utlException(_VectorFromTo.size()!=4 && _VectorFromTo.size()!=6, "wrong size! _VectorFromTo.size()="<<_VectorFromTo.size());
47  RotateFilterType::VectorType vFrom(3), vTo(3);
48  if (_VectorFromTo.size()==6)
49  {
50  for ( int i = 0; i < 3; i += 1 )
51  vFrom[i] = _VectorFromTo[i];
52  for ( int i = 0; i < 3; i += 1 )
53  vTo[i] = _VectorFromTo[i+3];
54  vFrom /= vFrom.GetTwoNorm();
55  vTo /= vFrom.GetTwoNorm();
56  }
57  else
58  {
59  vFrom[0]=vTo[0]=1.0;
60  vFrom[1]=_VectorFromTo[0]*M_PI/180.0, vFrom[2]=_VectorFromTo[1]*M_PI/180.0;
61  vTo[1]=_VectorFromTo[2]*M_PI/180.0, vTo[2]=_VectorFromTo[3]*M_PI/180.0;
62  utl::spherical2Cartesian(vFrom[0], vFrom[1], vFrom[2]);
63  utl::spherical2Cartesian(vTo[0], vTo[1], vTo[2]);
64  }
65 
66  utl::PrintUtlVector(vFrom, "vFrom");
67  utl::PrintUtlVector(vTo, "vTo");
68 
69  RotateFilterType::MatrixType rotationMatrix(3,3);
70  utl::RotationMatrixFromUnitNormVectors<RotateFilterType::VectorType, RotateFilterType::MatrixType >(vFrom, vTo, rotationMatrix);
71  utl::PrintUtlMatrix(rotationMatrix, "rotationMatrix");
72 
73  rotateFilter->SetInput(shImage);
74  rotateFilter->SetRotationMatrix(rotationMatrix);
75  // rotateFilter->InPlaceOn();
76  if (_NumberOfThreads>0)
77  rotateFilter->SetNumberOfThreads(_NumberOfThreads);
78  clock.Start();
79  rotateFilter->Update();
80  clock.Stop();
81  std::cout << clock.GetMean() << "s elapsed" << std::endl;
82 
83  shRotatedImage = rotateFilter->GetOutput();
84 
85  itk::SaveImage<ImageType>(shRotatedImage, _OutputFile);
86 
87 }
int main(int argc, char *argv[])
helper functions specifically used in dmritool
void PrintUtlMatrix(const NDArray< T, 2 > &mat, const std::string &str="", const char *separate=" ", std::ostream &os=std::cout)
#define utlException(cond, expout)
Definition: utlCoreMacro.h:548
void spherical2Cartesian(const T r, const T theta, const T phi, T &x, T &y, T &z)
Definition: utlCore.h:1602
#define M_PI
Definition: utlCoreMacro.h:57
Rotate SH coefficient to all input pixels.
void PrintUtlVector(const NDArray< T, 1 > &vec, const std::string &str="", const char *separate=" ", std::ostream &os=std::cout, bool showStats=true)