2013-09-02 22:16:46 +08:00
|
|
|
/*
|
2013-06-22 13:55:48 +08:00
|
|
|
* compose
|
|
|
|
* compose a function call
|
2013-07-03 07:42:37 +08:00
|
|
|
* This macro takes as input a Method object and composes
|
2013-06-22 13:55:48 +08:00
|
|
|
* a function call by inspecting the types and argument names
|
|
|
|
*/
|
|
|
|
{% macro compose(fun) %}
|
|
|
|
{# ----------- Return type ------------- #}
|
2013-07-03 07:42:37 +08:00
|
|
|
{%- if not fun.rtp|void and not fun.constructor -%} retval = {% endif -%}
|
|
|
|
{%- if fun.constructor -%}{{fun.clss}} obj = {% endif -%}
|
|
|
|
{%- if fun.clss and not fun.constructor -%}inst.{%- else -%} cv:: {%- endif -%}
|
2013-06-23 03:38:40 +08:00
|
|
|
{{fun.name}}(
|
2013-06-22 13:55:48 +08:00
|
|
|
{#- ----------- Required ------------- -#}
|
2013-09-02 22:16:46 +08:00
|
|
|
{%- for arg in fun.req -%}
|
2013-06-22 13:55:48 +08:00
|
|
|
{%- if arg.ref == '*' -%}&{%- endif -%}
|
2013-09-02 22:16:46 +08:00
|
|
|
{{arg.name}}
|
2013-06-22 08:33:24 +08:00
|
|
|
{%- if not loop.last %}, {% endif %}
|
|
|
|
{% endfor %}
|
2013-06-22 13:55:48 +08:00
|
|
|
{#- ----------- Optional ------------- -#}
|
2013-06-22 08:33:24 +08:00
|
|
|
{% if fun.req and fun.opt %}, {% endif %}
|
2013-09-02 22:16:46 +08:00
|
|
|
{%- for opt in fun.opt -%}
|
2013-06-22 13:55:48 +08:00
|
|
|
{%- if opt.ref == '*' -%}&{%- endif -%}
|
2013-09-02 22:16:46 +08:00
|
|
|
{{opt.name}}
|
2013-06-22 08:33:24 +08:00
|
|
|
{%- if not loop.last -%}, {% endif %}
|
|
|
|
{%- endfor -%}
|
|
|
|
);
|
|
|
|
{%- endmacro %}
|
|
|
|
|
|
|
|
|
2013-09-02 22:16:46 +08:00
|
|
|
/*
|
2013-08-06 19:16:38 +08:00
|
|
|
* composeMatlab
|
|
|
|
* compose a Matlab function call
|
|
|
|
* This macro takes as input a Method object and composes
|
|
|
|
* a Matlab function call by inspecting the types and argument names
|
|
|
|
*/
|
|
|
|
{% macro composeMatlab(fun) %}
|
|
|
|
{# ----------- Return type ------------- #}
|
|
|
|
{%- if fun|noutputs > 1 -%}[{% endif -%}
|
|
|
|
{%- if not fun.rtp|void -%}LVALUE{% endif -%}
|
|
|
|
{%- if not fun.rtp|void and fun|noutputs > 1 -%},{% endif -%}
|
|
|
|
{# ------------- Outputs ------------- -#}
|
|
|
|
{%- for arg in fun.req|outputs + fun.opt|outputs -%}
|
|
|
|
{{arg.name}}
|
|
|
|
{%- if arg.I -%}_out{%- endif -%}
|
|
|
|
{%- if not loop.last %}, {% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
{%- if fun|noutputs > 1 -%}]{% endif -%}
|
|
|
|
{%- if fun|noutputs %} = {% endif -%}
|
|
|
|
cv.{{fun.name}}(
|
|
|
|
{#- ------------ Inputs -------------- -#}
|
|
|
|
{%- for arg in fun.req|inputs + fun.opt|inputs -%}
|
|
|
|
{{arg.name}}
|
|
|
|
{%- if arg.O -%}_in{%- endif -%}
|
|
|
|
{%- if not loop.last %}, {% endif -%}
|
|
|
|
{% endfor -%}
|
|
|
|
);
|
|
|
|
{%- endmacro %}
|
|
|
|
|
|
|
|
|
2013-08-30 13:06:57 +08:00
|
|
|
/*
|
|
|
|
* composeVariant
|
|
|
|
* compose a variant call for the ArgumentParser
|
|
|
|
*/
|
|
|
|
{% macro composeVariant(fun) %}
|
|
|
|
addVariant("{{ fun.name }}", {{ fun.req|inputs|length }}, {{ fun.opt|inputs|length }}
|
|
|
|
{%- if fun.opt|inputs|length %}, {% endif -%}
|
|
|
|
{%- for arg in fun.opt|inputs -%}
|
|
|
|
"{{arg.name}}"
|
|
|
|
{%- if not loop.last %}, {% endif -%}
|
|
|
|
{% endfor -%}
|
|
|
|
)
|
|
|
|
{%- endmacro %}
|
|
|
|
|
|
|
|
|
2013-07-03 07:42:37 +08:00
|
|
|
/*
|
|
|
|
* composeWithExceptionHandler
|
|
|
|
* compose a function call wrapped in exception traps
|
|
|
|
* This macro takes an input a Method object and composes a function
|
|
|
|
* call through the compose() macro, then wraps the return in traps
|
|
|
|
* for cv::Exceptions, std::exceptions, and all generic exceptions
|
|
|
|
* and returns a useful error message to the Matlab interpreter
|
|
|
|
*/
|
|
|
|
{%- macro composeWithExceptionHandler(fun) -%}
|
|
|
|
// call the opencv function
|
|
|
|
// [out =] namespace.fun(src1, ..., srcn, dst1, ..., dstn, opt1, ..., optn);
|
|
|
|
try {
|
|
|
|
{{ compose(fun) }}
|
|
|
|
} catch(cv::Exception& e) {
|
|
|
|
error(std::string("cv::exception caught: ").append(e.what()).c_str());
|
|
|
|
} catch(std::exception& e) {
|
|
|
|
error(std::string("std::exception caught: ").append(e.what()).c_str());
|
|
|
|
} catch(...) {
|
|
|
|
error("Uncaught exception occurred in {{fun.name}}");
|
|
|
|
}
|
|
|
|
{%- endmacro %}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* handleInputs
|
|
|
|
* unpack input arguments from the Bridge
|
|
|
|
* Given an input Bridge object, this unpacks the object from the Bridge and
|
|
|
|
* casts them into the correct type
|
|
|
|
*/
|
|
|
|
{%- macro handleInputs(fun) %}
|
|
|
|
|
|
|
|
{% if fun|ninputs or (fun|noutputs and not fun.constructor) %}
|
2013-06-22 08:33:24 +08:00
|
|
|
// unpack the arguments
|
2013-06-22 13:55:48 +08:00
|
|
|
{# ----------- Inputs ------------- #}
|
2013-06-22 08:33:24 +08:00
|
|
|
{% for arg in fun.req|inputs %}
|
2013-06-23 14:26:27 +08:00
|
|
|
{{arg.tp}} {{arg.name}} = inputs[{{ loop.index0 }}].to{{arg.tp|toUpperCamelCase}}();
|
2013-06-22 08:33:24 +08:00
|
|
|
{% endfor %}
|
|
|
|
{% for opt in fun.opt|inputs %}
|
2013-08-30 14:10:32 +08:00
|
|
|
{{opt.tp}} {{opt.name}} = inputs[{{loop.index0 + fun.req|inputs|length}}].empty() ? {% if opt.ref == '*' -%} {{opt.tp}}() {%- else -%} {{opt.default}} {%- endif %} : inputs[{{loop.index0 + fun.req|inputs|length}}].to{{opt.tp|toUpperCamelCase}}();
|
2013-06-22 08:33:24 +08:00
|
|
|
{% endfor %}
|
2013-06-22 13:55:48 +08:00
|
|
|
{# ----------- Outputs ------------ #}
|
|
|
|
{% for arg in fun.req|only|outputs %}
|
2013-06-22 08:33:24 +08:00
|
|
|
{{arg.tp}} {{arg.name}};
|
|
|
|
{% endfor %}
|
2013-06-22 13:55:48 +08:00
|
|
|
{% for opt in fun.opt|only|outputs %}
|
2013-06-22 08:33:24 +08:00
|
|
|
{{opt.tp}} {{opt.name}};
|
|
|
|
{% endfor %}
|
2013-07-03 07:42:37 +08:00
|
|
|
{% if not fun.rtp|void and not fun.constructor %}
|
2013-06-23 03:38:40 +08:00
|
|
|
{{fun.rtp}} retval;
|
|
|
|
{% endif %}
|
2013-06-30 05:24:53 +08:00
|
|
|
{% endif %}
|
2013-06-22 08:33:24 +08:00
|
|
|
|
2013-07-03 07:42:37 +08:00
|
|
|
{%- endmacro %}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* handleOutputs
|
|
|
|
* pack outputs into the bridge
|
|
|
|
* Given a set of outputs, this methods assigns them into the bridge for
|
|
|
|
* return to the calling method
|
|
|
|
*/
|
|
|
|
{%- macro handleOutputs(fun) %}
|
2013-06-22 08:33:24 +08:00
|
|
|
|
2013-06-30 05:24:53 +08:00
|
|
|
{% if fun|noutputs %}
|
2013-06-22 08:33:24 +08:00
|
|
|
// assign the outputs into the bridge
|
2013-07-03 07:42:37 +08:00
|
|
|
{% if not fun.rtp|void and not fun.constructor %}
|
2013-06-22 13:55:48 +08:00
|
|
|
outputs[0] = retval;
|
|
|
|
{% endif %}
|
2013-06-22 08:33:24 +08:00
|
|
|
{% for arg in fun.req|outputs %}
|
2013-06-22 13:55:48 +08:00
|
|
|
outputs[{{loop.index0 + fun.rtp|void|not}}] = {{arg.name}};
|
2013-06-22 08:33:24 +08:00
|
|
|
{% endfor %}
|
|
|
|
{% for opt in fun.opt|outputs %}
|
2013-06-22 13:55:48 +08:00
|
|
|
outputs[{{loop.index0 + fun.rtp|void|not + fun.req|outputs|length}}] = {{opt.name}};
|
2013-06-22 08:33:24 +08:00
|
|
|
{% endfor %}
|
2013-06-30 05:24:53 +08:00
|
|
|
{% endif %}
|
2013-07-03 07:42:37 +08:00
|
|
|
{%- endmacro %}
|