35 const int nlhs,
const int nrhs)
37 utlGlobalException(!utl::mexCheckType<T>(prhs[2]),
"type of argument 2 is not consistent");
39 int shRank = mxGetScalar(prhs[0]);
40 int raRank = mxGetScalar(prhs[1]);
42 const mwSize* dimsOrientation = mxGetDimensions(prhs[2]);
43 int row =
static_cast<int>(dimsOrientation[0]);
44 int column =
static_cast<int>(dimsOrientation[1]);
48 utlException (column!=3,
"orientation matrix should have 3 columns (x,y,z)");
50 utl_shared_ptr<MatrixType > qOrientationMatrix(
new MatrixType(row, column));
54 const mwSize* dimsBVectors = mxGetDimensions(prhs[3]);
55 int rowB =
static_cast<int>(dimsBVectors[0]);
56 int columnB =
static_cast<int>(dimsBVectors[1]);
59 utlException(columnB!=1 && rowB!=1,
"orientation matrix should have 1 column or 1 row");
60 utlException((columnB==1 && rowB!=row) || (rowB==1 && columnB!=column),
"orientation matrix and B vector should have the same number of rows");
62 utl_shared_ptr<std::vector<double> > bVector (
new std::vector<double>());
66 typedef double PrecisionType;
69 typename SPFIFilterBaseType::Pointer spfiFilter = SPFIFilterBaseType::New();
70 spfiFilter->GetSamplingSchemeQSpace()->SetBVector(bVector);
71 spfiFilter->GetSamplingSchemeQSpace()->SetOrientationsSpherical(qOrientationMatrix);
72 spfiFilter->SetSHRank(shRank);
73 spfiFilter->SetRadialRank(raRank);
74 bool originalBasis =
true;
77 utlGlobalException(mxGetClassID(prhs[4])!=mxSTRUCT_CLASS,
"the fifth input has to be a struct");
79 spfiFilter->GetSamplingSchemeQSpace()->SetTau(tau);
81 T scale = utl::GetScalarStructDef<T>(prhs[4],
"scale", -1.0);
83 spfiFilter->SetBasisScale(scale);
85 originalBasis = utl::GetScalarStructDef<bool>(prhs[4],
"original",
true);
89 utl_shared_ptr<MatrixType > basisMatrix (
new MatrixType());
91 spfiFilter->ComputeBasisMatrix();
92 basisMatrix = spfiFilter->GetBasisMatrix();
105 int n_b_sh = (shRank+1)*(shRank+2)/2;
106 int n_b_ra = raRank + 1;
108 MatrixType basisMatrixIndependent;
110 spfiFilter->ComputeRadialVectorForE0InBasis();
111 utl_shared_ptr<std::vector<double> > R_n_0_vec = spfiFilter->GetGn0();
112 basisMatrixIndependent.ReSize(basisMatrix->Rows(), n_b_sh*(n_b_ra-1));
115 for (
int i = 0; i < raRank; i += 1 )
117 for (
int j = 0; j < n_b_sh; j += 1 )
119 for (
int ss = 0; ss < basisMatrixIndependent.Rows(); ss += 1 )
121 basisMatrixIndependent(ss,i*n_b_sh+j) = (*basisMatrix)(ss,(i+1)*n_b_sh+j) - (*R_n_0_vec)[i+1]/(*R_n_0_vec)[0] * (*basisMatrix)(ss,j);
134 int nrhs,
const mxArray *prhs[])
142 callFunction<double>(plhs,prhs,nlhs,nrhs);
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
helper functions specifically used in dmritool
#define utlException(cond, expout)
NDArray< T, 2 > CartesianToSpherical(const NDArray< T, 2 > &in)
void GetMXArrayFromUtlMatrix(const NDArray< T, 2 > *mat, mxArray *&pr)
#define utlGlobalException(cond, expout)
Contains miscellaneous functions for mex files. utl functions for mex code. Some codes are from spams...
void callFunction(mxArray *plhs[], const mxArray *prhs[], const int nlhs, const int nrhs)
estimate the coefficients in SPF model
void GetUtlMatrixFromMXArray(const mxArray *pr, NDArray< T, 2 > *mat)
itk::VectorImage< ScalarType, 3 > VectorImageType
void GetSTDVectorFromMXArray(const mxArray *pr, std::vector< T > *vec)