28 : dims(num_dims), fun_name(
func)
47 double calc(
const double *x)
const 60 val = res.
at<
double>(0);
91 s.
set(
"fun", fun_name);
105 return makePtr<MatlabFunction>(
106 s.
at(
"dims").toInt(),
107 s.
at(
"fun").toString());
130 int id = rhs[0].toInt();
131 string method(rhs[1].toString());
134 if (method ==
"new") {
135 nargchk(nrhs>=2 && (nrhs%2)==0 && nlhs<=1);
138 TermCriteria termcrit(TermCriteria::MAX_ITER+TermCriteria::EPS, 5000, 1e-6);
139 for (
int i=2; i<nrhs; i+=2) {
140 string key(rhs[i].toString());
141 if (key ==
"Function")
143 else if (key ==
"InitStep")
144 initStep = rhs[i+1].toMat(
CV_64F);
145 else if (key ==
"TermCriteria")
146 termcrit = rhs[i+1].toTermCriteria();
149 "Unrecognized option %s", key.
c_str());
161 if (method ==
"delete") {
166 else if (method ==
"clear") {
170 else if (method ==
"load") {
171 nargchk(nrhs>=3 && (nrhs%2)==1 && nlhs==0);
173 bool loadFromString =
false;
174 for (
int i=3; i<nrhs; i+=2) {
175 string key(rhs[i].toString());
176 if (key ==
"ObjName")
177 objname = rhs[i+1].toString();
178 else if (key ==
"FromString")
179 loadFromString = rhs[i+1].toBool();
182 "Unrecognized option %s", key.
c_str());
184 obj_[id] = (loadFromString ?
185 Algorithm::loadFromString<DownhillSolver>(rhs[2].toString(), objname) :
186 Algorithm::load<DownhillSolver>(rhs[2].toString(), objname));
188 else if (method ==
"save") {
190 obj->
save(rhs[2].toString());
192 else if (method ==
"empty") {
196 else if (method ==
"getDefaultName") {
200 else if (method ==
"minimize") {
208 else if (method ==
"get") {
210 string prop(rhs[2].toString());
211 if (prop ==
"Function") {
214 (f.dynamicCast<MatlabFunction>())->toStruct();
216 else if (prop ==
"InitStep") {
221 else if (prop ==
"TermCriteria")
225 "Unrecognized property %s", prop.
c_str());
227 else if (method ==
"set") {
229 string prop(rhs[2].toString());
230 if (prop ==
"Function")
232 else if (prop ==
"InitStep")
234 else if (prop ==
"TermCriteria")
238 "Unrecognized property %s", prop.
c_str());
242 "Unrecognized operation %s", method.
c_str());
mwSize numel() const
Number of elements in an array.
virtual Ptr< Function > getFunction() const=0
T at(mwIndex index) const
Template for numeric array element accessor.
virtual void setTermCriteria(const TermCriteria &termcrit)=0
LIBMWMEX_API_EXTERN_C void mexLock(void)
Lock a MEX-function so that it cannot be cleared from memory.
MatlabFunction(int num_dims, const string &func)
Constructor.
virtual double minimize(InputOutputArray x)=0
map< int, Ptr< DownhillSolver > > obj_
Object container.
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C void mxDestroyArray(mxArray *pa)
mxArray destructor
bool isDouble() const
Determine whether mxArray represents data as double-precision, floating-point numbers.
static Ptr< MatlabFunction > create(const MxArray &s)
Factory function.
struct mxArray_tag mxArray
Forward declaration for mxArray.
void set(mwIndex index, const T &value)
Template for numeric array element write accessor.
virtual void setInitStep(InputArray step)=0
double calc(const double *x) const
Evaluates MATLAB objective function.
string func
name of MATLAB function to evaluate (custom face detector)
Represents objective function being optimized, implemented as a MATLAB file.
bool isComplex() const
Determine whether data is complex.
virtual TermCriteria getTermCriteria() const=0
LIBMWMEX_API_EXTERN_C void mexErrMsgIdAndTxt(const char *identifier, const char *err_msg,...)
Issue formatted error message with corresponding error identifier and return to MATLAB prompt...
LIBMWMEX_API_EXTERN_C void mexUnlock(void)
Unlock a locked MEX-function so that it can be cleared from memory.
int last_id
Last object id to allocate.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/output arguments number check.
MxArray toStruct() const
Convert object to MxArray.
static MxArray Struct(const char **fields=NULL, int nfields=0, mwSize m=1, mwSize n=1)
Create a new struct array.
bool isStruct() const
Determine whether input is structure array.
virtual void setFunction(const Ptr< Function > &f)=0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
int getDims() const
Return number of dimensions.
virtual String getDefaultName() const
Global constant definitions.
virtual void getInitStep(OutputArray step) const=0
virtual void save(const String &filename) const
virtual bool empty() const
LIBMWMEX_API_EXTERN_C int mexCallMATLAB(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[], const char *fcn_name)
call MATLAB function
void create(int arows, int acols, int atype, Target target=ARRAY_BUFFER, bool autoRelease=false)