25 const int nlhs,
const int nrhs)
27 utlGlobalException(mxGetClassID(prhs[0])!=mxCHAR_CLASS,
"the first input has to be a string");
28 utlGlobalException(nrhs==2 && mxGetClassID(prhs[1])!=mxSTRUCT_CLASS,
"the second input has to be a struct");
34 bool normalize = utl::GetScalarStructDef<bool>(nrhs==2?prhs[1]:NULL,
"normalize",
true);
35 bool correctDWI = utl::GetScalarStructDef<bool>(nrhs==2?prhs[1]:NULL,
"correctDWI",
true);
36 bool warn = utl::GetScalarStructDef<bool>(nrhs==2?prhs[1]:NULL,
"warn",
true);
37 double bThreshold = utl::GetScalarStructDef<bool>(nrhs==2?prhs[1]:NULL,
"bThreshold",-1);
41 typename DWIReaderType::Pointer dwiReader = DWIReaderType::New();
43 dwiReader->SetConfigurationFile(dwiFile);
44 dwiReader->SetNormalizeDWI(normalize);
47 dwiReader->GetSamplingSchemeQSpace()->SetBThresholdSingleShell(bThreshold);
49 dwiReader->SetCorrectDWIValues(correctDWI);
50 dwiReader->SetShowWarnings(warn);
52 typedef itk::Image<T,3> Image3DType;
53 typename Image3DType::Pointer b0Image = Image3DType::New();
59 dwiReader->SetB0Image(b0Image);
65 typename VectorImageType::Pointer dwiImage = dwiReader->GetOutput();
69 utl_shared_ptr<std::vector<double> > bVec = dwiReader->GetSamplingSchemeQSpace()->GetBVector();
70 utl::GetMXArrayFromSTDVector<double>(bVec.get(), plhs[1]);
72 utl_shared_ptr<utl::NDArray<double,2> > grad = dwiReader->GetSamplingSchemeQSpace()->GetOrientationsCartesian();
73 utl::GetMXArrayFromUtlMatrix<double>(grad.get(), plhs[2]);
77 typename Image3DType::Pointer b0Image = dwiReader->GetB0Image();
84 int nrhs,
const mxArray *prhs[])
86 utl_shared_ptr<std::vector<double> > grad(
new std::vector<double>());
96 callFunction<double>(plhs,prhs,nlhs,nrhs);
mxArray * GetArrayStruct(const mxArray *pr_struct, const char *name)
helper functions specifically used in dmritool
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
void GetMXArrayFromITKVectorImage(const SmartPointer< VectorImage< T, VImageDimension > > &image, mxArray *&pr)
void callFunction(mxArray *plhs[], const mxArray *prhs[], const int nlhs, const int nrhs)
#define utlGlobalException(cond, expout)
Load gradient file, b values and DWI files (with optional index file)
void GetString(const mxArray *pr, std::string &str)
void GetMXArrayFromITKImage(const SmartPointer< Image< T, VImageDimension > > &image, mxArray *&pr)
itk::VectorImage< ScalarType, 3 > VectorImageType
void GetITKImageFromMXArray(const mxArray *pr, SmartPointer< Image< T, VImageDimension > > &image)