robust_pose.cpp
Go to the documentation of this file.
1 // Author: Thomas Pintaric <pintaric@ims.tuwien.ac.at>
2 
3 #include <vector>
4 #include "../rpp.h"
5 #include "../rpp_types.h"
6 #include "../rpp_vecmat.h"
7 #include "mex.h"
8 
9 using namespace rpp;
10 
11 void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
12 {
13  const mxArray *model_p, *iprts_p;
14  double *model_v, *iprts_v, *R_v, *t_v, *e_v;
15 
16  model_p = prhs[0];
17  iprts_p = prhs[1];
18  model_v = mxGetPr(model_p);
19  iprts_v = mxGetPr(iprts_p);
20 
21  if(mxGetN(model_p) != mxGetN(iprts_p))
22  {
23  mexErrMsgTxt("size(model) ~= size(iprts)");
24  return;
25  }
26  if((mxGetM(model_p) != 3) || (mxGetM(iprts_p) != 3))
27  {
28  mexErrMsgTxt("[model] and [iprts] must be 3-by-N matrices");
29  return;
30  }
31 
32 
33  unsigned int n = mxGetN(model_p);
34  vec3_array model;
35  vec3_array iprts;
36 
37  model.resize(n);
38  iprts.resize(n);
39 
40  unsigned int j=0;
41  for(unsigned int i=0; i<n; i++)
42  {
43  vec3_t _vm,_vi;
44  vec3_assign(_vm,(real_t)model_v[j],(real_t)model_v[j+1],(real_t)model_v[j+2]);
45  vec3_assign(_vi,(real_t)iprts_v[j],(real_t)iprts_v[j+1],(real_t)iprts_v[j+2]);
46  j += 3;
47  model[i] = _vm;
48  iprts[i] = _vi;
49  }
50 
52  options.epsilon = (float)DEFAULT_EPSILON;
53  options.tol = (float)DEFAULT_TOL;
54  mat33_set_all_zeros(options.initR);
55 
56  real_t err;
57  vec3_t t;
58  mat33_t R;
59 
60  robust_pose(err,R,t,model,iprts,options);
61 
62  plhs[0] = mxCreateDoubleMatrix(3, 3, mxREAL);
63  R_v = mxGetPr(plhs[0]);
64 
65  R_v[0] = R.m[0][0]; R_v[1] = R.m[1][0]; R_v[2] = R.m[2][0];
66  R_v[3] = R.m[0][1]; R_v[4] = R.m[1][1]; R_v[5] = R.m[2][1];
67  R_v[6] = R.m[0][2]; R_v[7] = R.m[1][2]; R_v[8] = R.m[2][2];
68 
69  plhs[1] = mxCreateDoubleMatrix(3, 1, mxREAL);
70  t_v = mxGetPr(plhs[1]);
71 
72  t_v[0] = t.v[0];
73  t_v[1] = t.v[1];
74  t_v[2] = t.v[2];
75 
76  plhs[2] = mxCreateDoubleMatrix(1, 1, mxREAL);
77  e_v = mxGetPr(plhs[2]);
78  e_v[0] = (double)err;
79 
80  return;
81 }
real_t epsilon
Definition: rpp_types.h:107
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Definition: robust_pose.cpp:11
Definition: rpp.cpp:55
std::vector< vec3_t > vec3_array
Definition: rpp_types.h:71
options
#define DEFAULT_TOL
Definition: rpp_const.h:63
#define DEFAULT_EPSILON
Definition: rpp_const.h:64
void mat33_set_all_zeros(mat33_t &m)
Definition: rpp_vecmat.cpp:595
double real_t
Definition: rpp_types.h:64
mat33_t initR
Definition: rpp_types.h:105
void robust_pose(real_t &err, mat33_t &R, vec3_t &t, const vec3_array &_model, const vec3_array &_iprts, const options_t _options)
Definition: rpp.cpp:741
void vec3_assign(vec3_t &v, const real_t x, const real_t y, const real_t z)
Definition: rpp_vecmat.cpp:297


tuw_artoolkitplus
Author(s): Markus Bader
autogenerated on Sun Sep 4 2016 03:24:33