All OpenCV constants being exported into matlab class and C++ map templates
This commit is contained in:
parent
0b9ff11537
commit
e51bdbeb2d
@ -38,17 +38,22 @@ class MatlabWrapperGenerator(object):
|
|||||||
tclassm = jtemplate.get_template('template_class_base.m')
|
tclassm = jtemplate.get_template('template_class_base.m')
|
||||||
tclassc = jtemplate.get_template('template_class_base.cpp')
|
tclassc = jtemplate.get_template('template_class_base.cpp')
|
||||||
tdoc = jtemplate.get_template('template_doc_base.m')
|
tdoc = jtemplate.get_template('template_doc_base.m')
|
||||||
|
tconstc = jtemplate.get_template('template_map_base.cpp')
|
||||||
|
tconstm = jtemplate.get_template('template_map_base.m')
|
||||||
|
|
||||||
# create the build directory
|
# create the build directory
|
||||||
output_source_dir = output_dir+'/src'
|
output_source_dir = output_dir+'/src'
|
||||||
output_private_dir = output_source_dir+'/private'
|
output_private_dir = output_source_dir+'/private'
|
||||||
output_class_dir = output_dir+'/+cv'
|
output_class_dir = output_dir+'/+cv'
|
||||||
|
output_map_dir = output_dir+'/map'
|
||||||
if not os.path.isdir(output_source_dir):
|
if not os.path.isdir(output_source_dir):
|
||||||
os.mkdir(output_source_dir)
|
os.mkdir(output_source_dir)
|
||||||
if not os.path.isdir(output_private_dir):
|
if not os.path.isdir(output_private_dir):
|
||||||
os.mkdir(output_private_dir)
|
os.mkdir(output_private_dir)
|
||||||
if not os.path.isdir(output_class_dir):
|
if not os.path.isdir(output_class_dir):
|
||||||
os.mkdir(output_class_dir)
|
os.mkdir(output_class_dir)
|
||||||
|
if not os.path.isdir(output_map_dir):
|
||||||
|
os.mkdir(output_map_dir)
|
||||||
|
|
||||||
# populate templates
|
# populate templates
|
||||||
for namespace in parse_tree.namespaces:
|
for namespace in parse_tree.namespaces:
|
||||||
@ -68,6 +73,15 @@ class MatlabWrapperGenerator(object):
|
|||||||
with open(output_class_dir+'/'+clss.name+'.m', 'wb') as f:
|
with open(output_class_dir+'/'+clss.name+'.m', 'wb') as f:
|
||||||
f.write(populated)
|
f.write(populated)
|
||||||
|
|
||||||
|
# create a global constants lookup table
|
||||||
|
const = dict(constants(todict(parse_tree.namespaces)))
|
||||||
|
populatedc = tconstc.render(constants=const)
|
||||||
|
populatedm = tconstm.render(constants=const)
|
||||||
|
with open(output_map_dir+'/map.cpp', 'wb') as f:
|
||||||
|
f.write(populatedc)
|
||||||
|
with open(output_map_dir+'/map.m', 'wb') as f:
|
||||||
|
f.write(populatedm)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
@ -77,7 +91,7 @@ if __name__ == "__main__":
|
|||||||
sys.path.append(sys.argv[1])
|
sys.path.append(sys.argv[1])
|
||||||
from string import Template
|
from string import Template
|
||||||
from hdr_parser import CppHeaderParser
|
from hdr_parser import CppHeaderParser
|
||||||
from parse_tree import ParseTree, todict
|
from parse_tree import ParseTree, todict, constants
|
||||||
from filters import *
|
from filters import *
|
||||||
from jinja2 import Environment, PackageLoader
|
from jinja2 import Environment, PackageLoader
|
||||||
|
|
||||||
|
@ -172,7 +172,18 @@ class Constant(object):
|
|||||||
return ('const ' if self.const else '')+self.tp+self.ref+\
|
return ('const ' if self.const else '')+self.tp+self.ref+\
|
||||||
' '+self.name+('='+self.default if self.default else '')+';'
|
' '+self.name+('='+self.default if self.default else '')+';'
|
||||||
|
|
||||||
|
def constants(tree):
|
||||||
|
if isinstance(tree, dict) and 'constants' in tree and isinstance(tree['constants'], list):
|
||||||
|
for node in tree['constants']:
|
||||||
|
yield (node['name'], node['default'])
|
||||||
|
if isinstance(tree, dict):
|
||||||
|
for key, val in tree.items():
|
||||||
|
for gen in constants(val):
|
||||||
|
yield gen
|
||||||
|
if isinstance(tree, list):
|
||||||
|
for val in tree:
|
||||||
|
for gen in constants(val):
|
||||||
|
yield gen
|
||||||
|
|
||||||
def todict(obj, classkey=None):
|
def todict(obj, classkey=None):
|
||||||
if isinstance(obj, dict):
|
if isinstance(obj, dict):
|
||||||
|
11
modules/matlab/generator/templates/template_map_base.cpp
Normal file
11
modules/matlab/generator/templates/template_map_base.cpp
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#include <unordered_map>
|
||||||
|
#include <string>
|
||||||
|
#include <bridge>
|
||||||
|
|
||||||
|
typedef std::unordered_map Map;
|
||||||
|
|
||||||
|
Map<std::string, int> constants = {
|
||||||
|
{% for key, val in constants.items() %}
|
||||||
|
{ "{{key}}", {{val}} },
|
||||||
|
{% endfor %}
|
||||||
|
};
|
7
modules/matlab/generator/templates/template_map_base.m
Normal file
7
modules/matlab/generator/templates/template_map_base.m
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
classdef cv
|
||||||
|
properties (Constant = true)
|
||||||
|
{% for key, val in constants.items() %}
|
||||||
|
{{key}} = {{val}};
|
||||||
|
{% endfor %}
|
||||||
|
end
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user