Merge pull request #7476 from abratchik:java.wrapper.fix.3.1

pull/7496/head
Alexander Alekhin 8 years ago
commit 1ae27eb696
  1. 14
      modules/features2d/misc/java/src/cpp/features2d_manual.hpp
  2. 31
      modules/java/generator/gen_java.py

@ -89,7 +89,7 @@ public:
//supported: FAST STAR SIFT SURF ORB MSER GFTT HARRIS BRISK AKAZE Grid(XXXX) Pyramid(XXXX) Dynamic(XXXX)
//not supported: SimpleBlob, Dense
CV_WRAP static javaFeatureDetector* create( int detectorType )
CV_WRAP static Ptr<javaFeatureDetector> create( int detectorType )
{
//String name;
if (detectorType > DYNAMICDETECTOR)
@ -156,7 +156,7 @@ public:
break;
}
return new javaFeatureDetector(fd);
return makePtr<javaFeatureDetector>(fd);
}
CV_WRAP void write( const String& fileName ) const
@ -171,10 +171,11 @@ public:
wrapped->read(fs.root());
}
private:
javaFeatureDetector(Ptr<FeatureDetector> _wrapped) : wrapped(_wrapped)
{}
private:
Ptr<FeatureDetector> wrapped;
};
@ -222,7 +223,7 @@ public:
//supported SIFT, SURF, ORB, BRIEF, BRISK, FREAK, AKAZE, Opponent(XXXX)
//not supported: Calonder
CV_WRAP static javaDescriptorExtractor* create( int extractorType )
CV_WRAP static Ptr<javaDescriptorExtractor> create( int extractorType )
{
//String name;
@ -261,7 +262,7 @@ public:
break;
}
return new javaDescriptorExtractor(de);
return makePtr<javaDescriptorExtractor>(de);
}
CV_WRAP void write( const String& fileName ) const
@ -276,10 +277,11 @@ public:
wrapped->read(fs.root());
}
private:
javaDescriptorExtractor(Ptr<DescriptorExtractor> _wrapped) : wrapped(_wrapped)
{}
private:
Ptr<DescriptorExtractor> wrapped;
};

@ -783,6 +783,7 @@ class ClassInfo(GeneralInfo):
self.imports = set()
self.props= []
self.jname = self.name
self.smart = None # True if class stores Ptr<T>* instead of T* in nativeObj field
self.j_code = None # java code stream
self.jn_code = None # jni code stream
self.cpp_code = None # cpp code stream
@ -994,7 +995,7 @@ class JavaWrapperGenerator(object):
if classinfo.base:
classinfo.addImports(classinfo.base)
type_dict["Ptr_"+name] = \
{ "j_type" : name,
{ "j_type" : classinfo.jname,
"jn_type" : "long", "jn_args" : (("__int64", ".nativeObj"),),
"jni_name" : "Ptr<"+classinfo.fullName(isCPP=True)+">(("+classinfo.fullName(isCPP=True)+"*)%(n)s_nativeObj)", "jni_type" : "jlong",
"suffix" : "J" }
@ -1397,10 +1398,10 @@ class JavaWrapperGenerator(object):
elif fi.static:
cvname = fi.fullName(isCPP=True)
else:
cvname = ("me->" if not self.isSmartClass(fi.classname) else "(*me)->") + name
cvname = ("me->" if not self.isSmartClass(ci) else "(*me)->") + name
c_prologue.append(\
"%(cls)s* me = (%(cls)s*) self; //TODO: check for NULL" \
% { "cls" : self.smartWrap(fi.classname, fi.fullClass(isCPP=True))} \
% { "cls" : self.smartWrap(ci, fi.fullClass(isCPP=True))} \
)
cvargs = []
for a in args:
@ -1546,7 +1547,7 @@ JNIEXPORT void JNICALL Java_org_opencv_%(module)s_%(j_cls)s_delete
delete (%(cls)s*) self;
}
""" % {"module" : module.replace('_', '_1'), "cls" : self.smartWrap(ci.name, ci.fullName(isCPP=True)), "j_cls" : ci.jname.replace('_', '_1')}
""" % {"module" : module.replace('_', '_1'), "cls" : self.smartWrap(ci, ci.fullName(isCPP=True)), "j_cls" : ci.jname.replace('_', '_1')}
)
def getClass(self, classname):
@ -1556,17 +1557,31 @@ JNIEXPORT void JNICALL Java_org_opencv_%(module)s_%(j_cls)s_delete
name = classname or self.Module
return name in self.classes
def isSmartClass(self, classname):
def isSmartClass(self, ci):
'''
Check if class stores Ptr<T>* instead of T* in nativeObj field
'''
return self.isWrapped(classname)
if ci.smart != None:
return ci.smart
# if parents are smart (we hope) then children are!
# if not we believe the class is smart if it has "create" method
ci.smart = False
if ci.base:
ci.smart = True
else:
for fi in ci.methods:
if fi.name == "create":
ci.smart = True
break
return ci.smart
def smartWrap(self, name, fullname):
def smartWrap(self, ci, fullname):
'''
Wraps fullname with Ptr<> if needed
'''
if self.isSmartClass(name):
if self.isSmartClass(ci):
return "Ptr<" + fullname + ">"
return fullname

Loading…
Cancel
Save