DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
OrientationStatistics.cxx
Go to the documentation of this file.
1 
18 #include "OrientationStatisticsCLP.h"
19 #include "itkSamplingScheme3D.h"
20 
21 #include "utl.h"
22 
23 inline double
24 processOrientation ( const itk::SamplingScheme3D<double>::Pointer scheme, const bool _Asymmetric )
25 {
26  typedef itk::SamplingScheme3D<double> SamplingType;
27  // scheme->Print(std::cout<<"scheme");
28 
29  int size = scheme->GetNumberOfSamples();
30  std::cout << "size = " << size << std::endl << std::flush;
31 
32  int numberUniqueSamples=0, numberAntipodalSamples=0, numberRepeatedSamples=0;
33  scheme->GetNumbers(numberUniqueSamples, numberAntipodalSamples, numberRepeatedSamples);
34  std::cout << numberUniqueSamples << " unique samples, " << numberAntipodalSamples << " antipodal samples, " << numberRepeatedSamples << " repeated samples." << std::endl << std::flush;
35 
36  std::vector<double> angleVec = scheme->CalculateMinDistance(!_Asymmetric);
37  std::vector<double> stats = utl::GetContainerStats(angleVec.begin(), angleVec.end());
38  std::cout << "minimal angle = " << stats[0]*180.0/M_PI << ", radian=" << stats[0] << " (covering radius)" << std::endl << std::flush;
39  std::cout << "maximal angle = " << stats[1]*180.0/M_PI << ", radian=" << stats[1] << std::endl << std::flush;
40  std::cout << "mean angle = " << stats[2]*180.0/M_PI << std::endl << std::flush;
41  std::cout << "std angle = " << stats[3]*180.0/M_PI << std::endl << std::flush;
42 
43  double ud2 = SamplingType::CalculateMinDistanceUpperBound(2*size);
44  double ud = SamplingType::CalculateMinDistanceUpperBound(size);
45  std::cout << "upper bound ("<< 2*size <<" points) = " << ud2*180/M_PI << ", radian=" << ud2 << std::endl << std::flush;
46  std::cout << "upper bound ("<< size <<" points) = " << ud*180/M_PI << ", radian=" << ud << std::endl << std::flush;
47 
48  if (numberRepeatedSamples==0)
49  {
50  // double isSymmetric = numberAntipodalSamples==0 && !_Asymmetric;
51 
52  double electrostaticEnergy = scheme->CalculateElectrostaticEnergy(2.0, !_Asymmetric);
53  std::cout << "electrostaticEnergy (order=2) = " << electrostaticEnergy << std::endl << std::flush;
54  electrostaticEnergy = scheme->CalculateElectrostaticEnergy(1.0, !_Asymmetric);
55  std::cout << "electrostaticEnergy (order=1) = " << electrostaticEnergy << std::endl << std::flush;
56 
57  double packing_density = scheme->CalculatePackingDensity(!_Asymmetric);
58  std::cout << "Spherical packing density = " << packing_density << std::endl << std::flush;
59  }
60 
61  return stats[0];
62 }
63 
69 int
70 main (int argc, char const* argv[])
71 {
72  PARSE_ARGS;
73 
74  typedef itk::SamplingScheme3D<double> SamplingType;
75  SamplingType::Pointer schemeAll = SamplingType::New();
76 
77  double cost=0;
78  for ( int i = 0; i < _InputOrientationFile.size(); i += 1 )
79  {
80  std::cout << "file: " << _InputOrientationFile[i] << std::endl << std::flush;
81  SamplingType::Pointer scheme = SamplingType::New();
82  scheme->ReadOrientationFile(_InputOrientationFile[i]);
83  // scheme->Print(std::cout<<"scheme=");
84  cost += _Weight/_InputOrientationFile.size() * processOrientation(scheme,_Asymmetric);
85  std::cout << std::endl << std::flush;
86  if (_Combine && _InputOrientationFile.size()>1)
87  {
88  for ( int j = 0; j < scheme->size(); j += 1 )
89  schemeAll->AppendOrientation((*scheme)[j]);
90  }
91  }
92 
93  if (_Combine && _InputOrientationFile.size()>1)
94  {
95  std::cout << "Combine " << _InputOrientationFile.size() << " orientations" << std::endl << std::flush;
96  cost += (1-_Weight) * processOrientation(schemeAll,_Asymmetric);
97  }
98 
99  std::cout << "Spherical code cost function = " << cost << std::endl << std::flush;
100 
101  return 0;
102 }
void GetNumbers(int &numberUniqueSamples, int &numberAntipodalSamples, int &numberRepeatedSamples) const
double processOrientation(const itk::SamplingScheme3D< double >::Pointer scheme, const bool _Asymmetric)
helper functions specifically used in dmritool
std::vector< double > GetContainerStats(IteratorType v1, IteratorType v2)
Definition: utlCore.h:921
double CalculateElectrostaticEnergy(const double order=2.0, const bool isNormalize=true, const bool countHalf=true) const
int main(int argc, char const *argv[])
obtain energies, minimal angles from a given set of orientations
unsigned int GetNumberOfSamples() const
#define M_PI
Definition: utlCoreMacro.h:57
this class describes sampling in a 3D space (Q space or R space).
SmartPointer< Self > Pointer
double CalculateMinDistance(const unsigned int index, const bool isSymmetric=true) const
double CalculatePackingDensity(const bool isSymmetric=true) const