DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
mexSTD.h
Go to the documentation of this file.
1 
18 #ifndef __mexSTD_h
19 #define __mexSTD_h
20 
21 #include <mex.h>
22 #include "mexutils.h"
23 #include "utlCoreMacro.h"
24 
25 namespace utl
26 {
27 
28 template <class T>
29 inline void
30 GetSTDVectorFromMXArray ( const mxArray* pr, std::vector<T>* vec )
31 {
32  const mwSize* dims = mxGetDimensions(pr);
33  int row = static_cast<int>(dims[0]);
34  int column = static_cast<int>(dims[1]);
35 
36  double * data = mxGetPr(pr);
37 
38  if (row==1)
39  {
40  vec->resize(column);
41  for ( int i = 0; i < column; i += 1 )
42  (*vec)[i] = data[i];
43  }
44  else if (column==1)
45  {
46  vec->resize(row);
47  for ( int i = 0; i < row; i += 1 )
48  (*vec)[i] = data[i];
49  }
50  else
51  utlException(true, "the matrix should be a vector");
52 }
53 
55 template <class T>
56 inline void
57 GetMXArrayFromSTDVector ( const std::vector<T>* vec, mxArray*& pr )
58 {
59  utlException (!vec || (vec && vec->size()==0), "the vector is null");
60 
61  int row = vec->size();
62  int column = 1;
63 
64  pr = CreateMatrix<double>(row, 1);
65  double * data = mxGetPr(pr);
66  for ( int i = 0; i < row; i += 1 )
67  data[i] = (*vec)[i];
68 }
69 
70 }
71 
72 #endif
73 
#define utlException(cond, expout)
Definition: utlCoreMacro.h:548
void GetMXArrayFromSTDVector(const std::vector< T > *vec, mxArray *&pr)
Definition: mexSTD.h:57
mxArray * CreateMatrix< double >(int m, int n)
Create a m x n double matrix.
Definition: mexutils.h:139
int mwSize
Definition: utils.h:38
Definition: utl.h:90
Contains miscellaneous functions for mex files. utl functions for mex code. Some codes are from spams...
macros for utlCore
void GetSTDVectorFromMXArray(const mxArray *pr, std::vector< T > *vec)
Definition: mexSTD.h:30