17 map<int,Ptr<SVD> > obj_;
27 void mexFunction(
int nlhs, mxArray *plhs[],
int nrhs,
const mxArray *prhs[])
33 vector<MxArray> rhs(prhs, prhs+nrhs);
34 int id = rhs[0].toInt();
35 string method(rhs[1].toString());
38 if (method ==
"new") {
40 obj_[++last_id] = makePtr<SVD>();
44 else if (method ==
"backSubst_static") {
46 Mat w(rhs[2].toMat()),
51 SVD::backSubst(w, u, vt, src, dst);
55 else if (method ==
"solveZ_static") {
57 Mat src(rhs[2].toMat()), dst;
58 SVD::solveZ(src, dst);
62 else if (method ==
"compute_static") {
63 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs<=3);
65 for (
int i=3; i<nrhs; i+=2) {
66 string key(rhs[i].toString());
68 flags = rhs[i+1].toInt();
69 else if (key==
"ModifyA")
70 UPDATE_FLAG(flags, rhs[i+1].toBool(), SVD::MODIFY_A);
73 else if (key==
"FullUV")
74 UPDATE_FLAG(flags, rhs[i+1].toBool(), SVD::FULL_UV);
76 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized option");
78 Mat src(rhs[2].toMat()), w, u, vt;
79 SVD::compute(src, w, u, vt, flags);
89 Ptr<SVD> obj = obj_[id];
90 if (method ==
"delete") {
94 else if (method ==
"compute") {
95 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
97 for (
int i=3; i<nrhs; i+=2) {
98 string key(rhs[i].toString());
100 flags = rhs[i+1].toInt();
101 else if (key==
"ModifyA")
102 UPDATE_FLAG(flags, rhs[i+1].toBool(), SVD::MODIFY_A);
103 else if (key==
"NoUV")
105 else if (key==
"FullUV")
106 UPDATE_FLAG(flags, rhs[i+1].toBool(), SVD::FULL_UV);
108 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized option");
110 Mat src(rhs[2].toMat());
111 obj->operator()(src, flags);
113 else if (method ==
"backSubst") {
115 Mat src(rhs[2].toMat()), dst;
116 obj->backSubst(src, dst);
119 else if (method ==
"get") {
121 string prop(rhs[2].toString());
124 else if (prop ==
"vt")
126 else if (prop ==
"w")
129 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized option");
131 else if (method ==
"set") {
133 string prop(rhs[2].toString());
135 obj->u = rhs[3].toMat();
136 else if (prop ==
"vt")
137 obj->vt = rhs[3].toMat();
138 else if (prop ==
"w")
139 obj->w = rhs[3].toMat();
141 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized option");
144 mexErrMsgIdAndTxt(
"mexopencv:error",
"Unrecognized operation");
#define UPDATE_FLAG(NUM, TF, BIT)
set or clear a bit in flag depending on bool value
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/ouput arguments number check.
Global constant definitions.