DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
SamplingSchemeDistance.cxx
Go to the documentation of this file.
1 
18 #include "SamplingSchemeDistanceCLP.h"
19 #include "utl.h"
20 
21 #include <vnl/vnl_matrix.h>
22 
26 int
27 main (int argc, char const* argv[])
28 {
29  PARSE_ARGS;
30 
31  typedef utl::NDArray<double,2> MatrixType;
32  typedef utl_shared_ptr<MatrixType> MatrixPointer;
33  MatrixPointer grad1, grad2;
34  grad1 = utl::ReadGrad<double>(_InputFile1, DIRECTION_NODUPLICATE, CARTESIAN_TO_CARTESIAN);
35  grad2 = utl::ReadGrad<double>(_InputFile2, DIRECTION_NODUPLICATE, CARTESIAN_TO_CARTESIAN);
36 
37  utlGlobalException(grad1->Rows()!=grad2->Rows(), "two file should have the same number of rows");
38 
39  // utl::PrintUtlMatrix(*grad1, "grad1");
40  // utl::PrintUtlMatrix(*grad2, "grad2");
41  int N = grad1->Rows();
42  double maxDist=-1, distTmp=-1;
43  int iMax=-1, jMax=-1;
44  MatrixType dist(N,N,0.0);
46  for ( int i = 0; i < N; i += 1 )
47  {
48  v1 = grad1->GetRow(i);
49  // std::cout << "v1 = " << v1 << std::endl << std::flush;
51  int j = 0, jj=-1;
52  for ( ; j < N; j += 1 )
53  {
54  v2 = grad2->GetRow(j);
55  double tmp = utl::min( utl::ToVector<double>(v1-v2)->GetTwoNorm(), utl::ToVector<double>(v1+v2)->GetTwoNorm() );
56  dist(i,j) = tmp;
57  dist(j,i) = tmp;
58  if (tmp < distTmp)
59  {
60  distTmp = tmp;
61  jj = j;
62  }
63  // utlPrintVar4(true, i, j, tmp, distTmp);
64  }
65  if (distTmp > maxDist)
66  {
67  maxDist = distTmp;
68  iMax = i;
69  jMax = jj;
70  }
71  utlPrintVar3(_DebugArg.isSet(), i, distTmp, maxDist);
72  utlPrintVar2(_DebugArg.isSet(), iMax, jMax);
73  }
74 
75  std::cout << "maximal Euclidean distance = " << maxDist << ", angular distance = " << std::acos(1-maxDist*maxDist*0.5)/M_PI*180 << " degree, between the " << iMax+1 << "-th sample ["<< utl::UtlVectorToStdVector(grad1->GetRow(iMax)) <<"] in file " << _InputFile1 <<
76  " and the " << jMax+1 << "-th sample [" << utl::UtlVectorToStdVector(grad2->GetRow(jMax)) << "] in file " << _InputFile2 << std::endl << std::flush;
77 
78  return 0;
79 }
helper functions specifically used in dmritool
#define utlPrintVar3(cond, var1, var2, var3)
Definition: utlCoreMacro.h:558
const T & max(const T &a, const T &b)
Return the maximum between a and b.
Definition: utlCore.h:263
const T & min(const T &a, const T &b)
Return the minimum between a and b.
Definition: utlCore.h:257
#define M_PI
Definition: utlCoreMacro.h:57
#define utlGlobalException(cond, expout)
Definition: utlCoreMacro.h:372
#define utlPrintVar2(cond, var1, var2)
Definition: utlCoreMacro.h:557
std::vector< T > UtlVectorToStdVector(const NDArray< T, 1 > &vec)
int main(int argc, char const *argv[])
calculate the distances between to sampling schemes