DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
mexGetSHBasisMatrix.cxx
Go to the documentation of this file.
1 
18 #include <cstdio>
19 #include <iostream>
20 #include <cstdlib>
21 
22 #include "mex.h"
23 #include "utl.h"
24 #include "mexutils.h"
25 #include "utlMEX.h"
26 
27 
28 template <typename T>
29  inline void callFunction(mxArray* plhs[], const mxArray* prhs[],
30  const int nlhs,const int nrhs)
31 {
32  utlGlobalException(!utl::mexCheckType<T>(prhs[1]),"type of argument 1 is not consistent");
33 
34  int order = mxGetScalar(prhs[0]);
35 
36  const mwSize* dimsOrientation = mxGetDimensions(prhs[1]);
37  int row = static_cast<int>(dimsOrientation[0]);
38  int column = static_cast<int>(dimsOrientation[1]);
39 
40  utlException(column!=3,"orientation matrix should have 3 columns (x,y,z)");
41 
42  utl::NDArray<T,2> orientationMatrix(row, column);
43  utl::GetUtlMatrixFromMXArray(prhs[1], &orientationMatrix);
44 
45  std::string mode = "cartesian";
46  if (nrhs==3)
47  {
48  utl::GetString(prhs[2], mode);
49  }
50 
51  utlException(mode!="cartesian" && mode!="spherical","type of argument 3 is not consistent");
52 
53  utl_shared_ptr<utl::NDArray<T,2> > BMatrix (new utl::NDArray<T,2>());
54  if (mode=="spherical")
55  {
56  BMatrix = utl::ComputeSHMatrix(order, orientationMatrix, SPHERICAL_TO_SPHERICAL);
57  }
58  else
59  {
60  BMatrix = utl::ComputeSHMatrix(order, orientationMatrix, CARTESIAN_TO_SPHERICAL);
61  }
62 
63  utl::GetMXArrayFromUtlMatrix(BMatrix.get(), plhs[0]);
64 
65  return;
66 }
67 
68 void mexFunction(int nlhs, mxArray *plhs[],
69  int nrhs, const mxArray *prhs[])
70 {
71  utlGlobalException(nrhs != 2 && nrhs != 3,"Bad number of inputs arguments");
72  utlGlobalException(nlhs != 1,"Bad number of outputs arguments");
73 
74  // if (mxGetClassID(prhs[1]) == mxSINGLE_CLASS)
75  // callFunction<float>(plhs,prhs,nlhs,nrhs);
76  // else
77  callFunction<double>(plhs,prhs,nlhs,nrhs);
78 }
79 
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
helper functions specifically used in dmritool
#define utlException(cond, expout)
Definition: utlCoreMacro.h:548
NDArray<T,2> is a row-major matrix.
Definition: utlMatrix.h:37
int mwSize
Definition: utils.h:38
std::shared_ptr< NDArray< T, 2 > > ComputeSHMatrix(const unsigned int rank, const NDArray< T, 2 > &grad, const int mode)
Definition: utl.h:171
void GetMXArrayFromUtlMatrix(const NDArray< T, 2 > *mat, mxArray *&pr)
Definition: utlMEX.h:50
void callFunction(mxArray *plhs[], const mxArray *prhs[], const int nlhs, const int nrhs)
#define utlGlobalException(cond, expout)
Definition: utlCoreMacro.h:372
Contains miscellaneous functions for mex files. utl functions for mex code. Some codes are from spams...
void GetString(const mxArray *pr, std::string &str)
Definition: mexutils.h:275
void GetUtlMatrixFromMXArray(const mxArray *pr, NDArray< T, 2 > *mat)
Definition: utlMEX.h:33