Merging 'master' into 'wrap'
commit
92ce0703bb
|
@ -1,5 +1,6 @@
|
|||
# Utilities to help with wrapping.
|
||||
|
||||
# Use CMake's find_package to find the version of Python installed.
|
||||
macro(get_python_version)
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
|
||||
# Use older version of cmake's find_python
|
||||
|
@ -13,19 +14,6 @@ macro(get_python_version)
|
|||
|
||||
find_package(PythonLibs ${PYTHON_VERSION_STRING})
|
||||
|
||||
set(Python_VERSION_MAJOR
|
||||
${PYTHON_VERSION_MAJOR}
|
||||
CACHE INTERNAL "")
|
||||
set(Python_VERSION_MINOR
|
||||
${PYTHON_VERSION_MINOR}
|
||||
CACHE INTERNAL "")
|
||||
set(Python_VERSION_PATCH
|
||||
${PYTHON_VERSION_PATCH}
|
||||
CACHE INTERNAL "")
|
||||
set(Python_EXECUTABLE
|
||||
${PYTHON_EXECUTABLE}
|
||||
CACHE INTERNAL "")
|
||||
|
||||
else()
|
||||
# Get info about the Python interpreter
|
||||
# https://cmake.org/cmake/help/latest/module/FindPython.html#module:FindPython
|
||||
|
@ -37,6 +25,26 @@ macro(get_python_version)
|
|||
"Cannot find Python interpreter. Please install Python>=3.5.")
|
||||
endif()
|
||||
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# Depending on the version of CMake, ensure all the appropriate variables are set.
|
||||
macro(configure_python_variables)
|
||||
if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
|
||||
set(Python_VERSION_MAJOR
|
||||
${PYTHON_VERSION_MAJOR}
|
||||
CACHE INTERNAL "")
|
||||
set(Python_VERSION_MINOR
|
||||
${PYTHON_VERSION_MINOR}
|
||||
CACHE INTERNAL "")
|
||||
set(Python_VERSION_PATCH
|
||||
${PYTHON_VERSION_PATCH}
|
||||
CACHE INTERNAL "")
|
||||
set(Python_EXECUTABLE
|
||||
${PYTHON_EXECUTABLE}
|
||||
CACHE PATH "")
|
||||
|
||||
else()
|
||||
# Set both sets of variables
|
||||
set(PYTHON_VERSION_MAJOR
|
||||
${Python_VERSION_MAJOR}
|
||||
|
@ -49,7 +57,7 @@ macro(get_python_version)
|
|||
CACHE INTERNAL "")
|
||||
set(PYTHON_EXECUTABLE
|
||||
${Python_EXECUTABLE}
|
||||
CACHE INTERNAL "")
|
||||
CACHE PATH "")
|
||||
|
||||
endif()
|
||||
endmacro()
|
||||
|
@ -85,4 +93,7 @@ macro(gtwrap_get_python_version WRAP_PYTHON_VERSION)
|
|||
EXACT)
|
||||
endif()
|
||||
|
||||
# (Always) Configure the variables once we find the python package
|
||||
configure_python_variables()
|
||||
|
||||
endmacro()
|
||||
|
|
|
@ -7,10 +7,10 @@ endif()
|
|||
|
||||
# Get the Python version
|
||||
include(GtwrapUtils)
|
||||
message(status "Checking Python Version")
|
||||
message(STATUS "Checking Python Version")
|
||||
gtwrap_get_python_version(${WRAP_PYTHON_VERSION})
|
||||
|
||||
message(status "Setting Python version for wrapper")
|
||||
message(STATUS "Setting Python version for wrapper")
|
||||
set(PYBIND11_PYTHON_VERSION ${WRAP_PYTHON_VERSION})
|
||||
|
||||
# User-friendly Pybind11 wrapping and installing function.
|
||||
|
|
|
@ -206,7 +206,7 @@ class InstantiatedMethod(parser.Method):
|
|||
"""
|
||||
We can only instantiate template methods with a single template parameter.
|
||||
"""
|
||||
def __init__(self, original, instantiations=''):
|
||||
def __init__(self, original, instantiations: List[parser.Typename]=''):
|
||||
self.original = original
|
||||
self.instantiations = instantiations
|
||||
self.template = ''
|
||||
|
@ -246,11 +246,9 @@ class InstantiatedMethod(parser.Method):
|
|||
def to_cpp(self):
|
||||
"""Generate the C++ code for wrapping."""
|
||||
if self.original.template:
|
||||
instantiation_list = [
|
||||
# Get the fully qualified name
|
||||
"::".join(x.namespaces + [x.name])
|
||||
for x in self.instantiations
|
||||
]
|
||||
# to_cpp will handle all the namespacing and templating
|
||||
instantiation_list = [x.to_cpp() for x in self.instantiations]
|
||||
# now can simply combine the instantiations, separated by commas
|
||||
ret = "{}<{}>".format(self.original.name,
|
||||
",".join(instantiation_list))
|
||||
else:
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
%class NonlinearFactorGraph, see Doxygen page for details
|
||||
%at https://gtsam.org/doxygen/
|
||||
%
|
||||
%-------Methods-------
|
||||
%addPriorPinholeCameraCal3Bundler(size_t key, PinholeCamera<Cal3Bundler> prior, Base noiseModel) : returns void
|
||||
%
|
||||
classdef NonlinearFactorGraph < handle
|
||||
properties
|
||||
ptr_gtsamNonlinearFactorGraph = 0
|
||||
end
|
||||
methods
|
||||
function obj = NonlinearFactorGraph(varargin)
|
||||
if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682)
|
||||
my_ptr = varargin{2};
|
||||
special_cases_wrapper(0, my_ptr);
|
||||
else
|
||||
error('Arguments do not match any overload of gtsam.NonlinearFactorGraph constructor');
|
||||
end
|
||||
obj.ptr_gtsamNonlinearFactorGraph = my_ptr;
|
||||
end
|
||||
|
||||
function delete(obj)
|
||||
special_cases_wrapper(1, obj.ptr_gtsamNonlinearFactorGraph);
|
||||
end
|
||||
|
||||
function display(obj), obj.print(''); end
|
||||
%DISPLAY Calls print on the object
|
||||
function disp(obj), obj.display; end
|
||||
%DISP Calls print on the object
|
||||
function varargout = addPriorPinholeCameraCal3Bundler(this, varargin)
|
||||
% ADDPRIORPINHOLECAMERACAL3BUNDLER usage: addPriorPinholeCameraCal3Bundler(size_t key, PinholeCamera<Cal3Bundler> prior, Base noiseModel) : returns void
|
||||
% Doxygen can be found at https://gtsam.org/doxygen/
|
||||
if length(varargin) == 3 && isa(varargin{1},'numeric') && isa(varargin{2},'gtsam.PinholeCameraCal3Bundler') && isa(varargin{3},'gtsam.noiseModel.Base')
|
||||
special_cases_wrapper(2, this, varargin{:});
|
||||
return
|
||||
end
|
||||
error('Arguments do not match any overload of function gtsam.NonlinearFactorGraph.addPriorPinholeCameraCal3Bundler');
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
methods(Static = true)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,31 @@
|
|||
%class PinholeCameraCal3Bundler, see Doxygen page for details
|
||||
%at https://gtsam.org/doxygen/
|
||||
%
|
||||
classdef PinholeCameraCal3Bundler < handle
|
||||
properties
|
||||
ptr_gtsamPinholeCameraCal3Bundler = 0
|
||||
end
|
||||
methods
|
||||
function obj = PinholeCameraCal3Bundler(varargin)
|
||||
if nargin == 2 && isa(varargin{1}, 'uint64') && varargin{1} == uint64(5139824614673773682)
|
||||
my_ptr = varargin{2};
|
||||
special_cases_wrapper(3, my_ptr);
|
||||
else
|
||||
error('Arguments do not match any overload of gtsam.PinholeCameraCal3Bundler constructor');
|
||||
end
|
||||
obj.ptr_gtsamPinholeCameraCal3Bundler = my_ptr;
|
||||
end
|
||||
|
||||
function delete(obj)
|
||||
special_cases_wrapper(4, obj.ptr_gtsamPinholeCameraCal3Bundler);
|
||||
end
|
||||
|
||||
function display(obj), obj.print(''); end
|
||||
%DISPLAY Calls print on the object
|
||||
function disp(obj), obj.display; end
|
||||
%DISP Calls print on the object
|
||||
end
|
||||
|
||||
methods(Static = true)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,340 @@
|
|||
#include <gtwrap/matlab.h>
|
||||
#include <map>
|
||||
|
||||
#include <boost/archive/text_iarchive.hpp>
|
||||
#include <boost/archive/text_oarchive.hpp>
|
||||
#include <boost/serialization/export.hpp>
|
||||
|
||||
#include <folder/path/to/Test.h>
|
||||
#include <gtsam/geometry/Cal3Bundler.h>
|
||||
#include <gtsam/geometry/Point2.h>
|
||||
#include <gtsam/geometry/Point3.h>
|
||||
#include <path/to/ns1.h>
|
||||
#include <path/to/ns1/ClassB.h>
|
||||
#include <path/to/ns2.h>
|
||||
#include <path/to/ns2/ClassA.h>
|
||||
#include <path/to/ns3.h>
|
||||
|
||||
typedef Fun<double> FunDouble;
|
||||
typedef PrimitiveRef<double> PrimitiveRefDouble;
|
||||
typedef MyVector<3> MyVector3;
|
||||
typedef MyVector<12> MyVector12;
|
||||
typedef MultipleTemplates<int, double> MultipleTemplatesIntDouble;
|
||||
typedef MultipleTemplates<int, float> MultipleTemplatesIntFloat;
|
||||
typedef MyFactor<gtsam::Pose2, gtsam::Matrix> MyFactorPosePoint2;
|
||||
typedef MyTemplate<gtsam::Point2> MyTemplatePoint2;
|
||||
typedef MyTemplate<gtsam::Matrix> MyTemplateMatrix;
|
||||
typedef gtsam::PinholeCamera<gtsam::Cal3Bundler> PinholeCameraCal3Bundler;
|
||||
|
||||
BOOST_CLASS_EXPORT_GUID(gtsam::Point2, "gtsamPoint2");
|
||||
BOOST_CLASS_EXPORT_GUID(gtsam::Point3, "gtsamPoint3");
|
||||
|
||||
typedef std::set<boost::shared_ptr<FunRange>*> Collector_FunRange;
|
||||
static Collector_FunRange collector_FunRange;
|
||||
typedef std::set<boost::shared_ptr<FunDouble>*> Collector_FunDouble;
|
||||
static Collector_FunDouble collector_FunDouble;
|
||||
typedef std::set<boost::shared_ptr<Test>*> Collector_Test;
|
||||
static Collector_Test collector_Test;
|
||||
typedef std::set<boost::shared_ptr<PrimitiveRefDouble>*> Collector_PrimitiveRefDouble;
|
||||
static Collector_PrimitiveRefDouble collector_PrimitiveRefDouble;
|
||||
typedef std::set<boost::shared_ptr<MyVector3>*> Collector_MyVector3;
|
||||
static Collector_MyVector3 collector_MyVector3;
|
||||
typedef std::set<boost::shared_ptr<MyVector12>*> Collector_MyVector12;
|
||||
static Collector_MyVector12 collector_MyVector12;
|
||||
typedef std::set<boost::shared_ptr<MultipleTemplatesIntDouble>*> Collector_MultipleTemplatesIntDouble;
|
||||
static Collector_MultipleTemplatesIntDouble collector_MultipleTemplatesIntDouble;
|
||||
typedef std::set<boost::shared_ptr<MultipleTemplatesIntFloat>*> Collector_MultipleTemplatesIntFloat;
|
||||
static Collector_MultipleTemplatesIntFloat collector_MultipleTemplatesIntFloat;
|
||||
typedef std::set<boost::shared_ptr<MyFactorPosePoint2>*> Collector_MyFactorPosePoint2;
|
||||
static Collector_MyFactorPosePoint2 collector_MyFactorPosePoint2;
|
||||
typedef std::set<boost::shared_ptr<gtsam::Point2>*> Collector_gtsamPoint2;
|
||||
static Collector_gtsamPoint2 collector_gtsamPoint2;
|
||||
typedef std::set<boost::shared_ptr<gtsam::Point3>*> Collector_gtsamPoint3;
|
||||
static Collector_gtsamPoint3 collector_gtsamPoint3;
|
||||
typedef std::set<boost::shared_ptr<MyBase>*> Collector_MyBase;
|
||||
static Collector_MyBase collector_MyBase;
|
||||
typedef std::set<boost::shared_ptr<MyTemplatePoint2>*> Collector_MyTemplatePoint2;
|
||||
static Collector_MyTemplatePoint2 collector_MyTemplatePoint2;
|
||||
typedef std::set<boost::shared_ptr<MyTemplateMatrix>*> Collector_MyTemplateMatrix;
|
||||
static Collector_MyTemplateMatrix collector_MyTemplateMatrix;
|
||||
typedef std::set<boost::shared_ptr<ns1::ClassA>*> Collector_ns1ClassA;
|
||||
static Collector_ns1ClassA collector_ns1ClassA;
|
||||
typedef std::set<boost::shared_ptr<ns1::ClassB>*> Collector_ns1ClassB;
|
||||
static Collector_ns1ClassB collector_ns1ClassB;
|
||||
typedef std::set<boost::shared_ptr<ns2::ClassA>*> Collector_ns2ClassA;
|
||||
static Collector_ns2ClassA collector_ns2ClassA;
|
||||
typedef std::set<boost::shared_ptr<ns2::ns3::ClassB>*> Collector_ns2ns3ClassB;
|
||||
static Collector_ns2ns3ClassB collector_ns2ns3ClassB;
|
||||
typedef std::set<boost::shared_ptr<ns2::ClassC>*> Collector_ns2ClassC;
|
||||
static Collector_ns2ClassC collector_ns2ClassC;
|
||||
typedef std::set<boost::shared_ptr<ClassD>*> Collector_ClassD;
|
||||
static Collector_ClassD collector_ClassD;
|
||||
typedef std::set<boost::shared_ptr<gtsam::NonlinearFactorGraph>*> Collector_gtsamNonlinearFactorGraph;
|
||||
static Collector_gtsamNonlinearFactorGraph collector_gtsamNonlinearFactorGraph;
|
||||
typedef std::set<boost::shared_ptr<PinholeCameraCal3Bundler>*> Collector_gtsamPinholeCameraCal3Bundler;
|
||||
static Collector_gtsamPinholeCameraCal3Bundler collector_gtsamPinholeCameraCal3Bundler;
|
||||
|
||||
void _deleteAllObjects()
|
||||
{
|
||||
mstream mout;
|
||||
std::streambuf *outbuf = std::cout.rdbuf(&mout);
|
||||
|
||||
bool anyDeleted = false;
|
||||
{ for(Collector_FunRange::iterator iter = collector_FunRange.begin();
|
||||
iter != collector_FunRange.end(); ) {
|
||||
delete *iter;
|
||||
collector_FunRange.erase(iter++);
|
||||
anyDeleted = true;
|
||||
} }
|
||||
{ for(Collector_FunDouble::iterator iter = collector_FunDouble.begin();
|
||||
iter != collector_FunDouble.end(); ) {
|
||||
delete *iter;
|
||||
collector_FunDouble.erase(iter++);
|
||||
anyDeleted = true;
|
||||
} }
|
||||
{ for(Collector_Test::iterator iter = collector_Test.begin();
|
||||
iter != collector_Test.end(); ) {
|
||||
delete *iter;
|
||||
collector_Test.erase(iter++);
|
||||
anyDeleted = true;
|
||||
} }
|
||||
{ for(Collector_PrimitiveRefDouble::iterator iter = collector_PrimitiveRefDouble.begin();
|
||||
iter != collector_PrimitiveRefDouble.end(); ) {
|
||||
delete *iter;
|
||||
collector_PrimitiveRefDouble.erase(iter++);
|
||||
anyDeleted = true;
|
||||
} }
|
||||
{ for(Collector_MyVector3::iterator iter = collector_MyVector3.begin();
|
||||
iter != collector_MyVector3.end(); ) {
|
||||
delete *iter;
|
||||
collector_MyVector3.erase(iter++);
|
||||
anyDeleted = true;
|
||||
} }
|
||||
{ for(Collector_MyVector12::iterator iter = collector_MyVector12.begin();
|
||||
iter != collector_MyVector12.end(); ) {
|
||||
delete *iter;
|
||||
collector_MyVector12.erase(iter++);
|
||||
anyDeleted = true;
|
||||
} }
|
||||
{ for(Collector_MultipleTemplatesIntDouble::iterator iter = collector_MultipleTemplatesIntDouble.begin();
|
||||
iter != collector_MultipleTemplatesIntDouble.end(); ) {
|
||||
delete *iter;
|
||||
collector_MultipleTemplatesIntDouble.erase(iter++);
|
||||
anyDeleted = true;
|
||||
} }
|
||||
{ for(Collector_MultipleTemplatesIntFloat::iterator iter = collector_MultipleTemplatesIntFloat.begin();
|
||||
iter != collector_MultipleTemplatesIntFloat.end(); ) {
|
||||
delete *iter;
|
||||
collector_MultipleTemplatesIntFloat.erase(iter++);
|
||||
anyDeleted = true;
|
||||
} }
|
||||
{ for(Collector_MyFactorPosePoint2::iterator iter = collector_MyFactorPosePoint2.begin();
|
||||
iter != collector_MyFactorPosePoint2.end(); ) {
|
||||
delete *iter;
|
||||
collector_MyFactorPosePoint2.erase(iter++);
|
||||
anyDeleted = true;
|
||||
} }
|
||||
{ for(Collector_gtsamPoint2::iterator iter = collector_gtsamPoint2.begin();
|
||||
iter != collector_gtsamPoint2.end(); ) {
|
||||
delete *iter;
|
||||
collector_gtsamPoint2.erase(iter++);
|
||||
anyDeleted = true;
|
||||
} }
|
||||
{ for(Collector_gtsamPoint3::iterator iter = collector_gtsamPoint3.begin();
|
||||
iter != collector_gtsamPoint3.end(); ) {
|
||||
delete *iter;
|
||||
collector_gtsamPoint3.erase(iter++);
|
||||
anyDeleted = true;
|
||||
} }
|
||||
{ for(Collector_MyBase::iterator iter = collector_MyBase.begin();
|
||||
iter != collector_MyBase.end(); ) {
|
||||
delete *iter;
|
||||
collector_MyBase.erase(iter++);
|
||||
anyDeleted = true;
|
||||
} }
|
||||
{ for(Collector_MyTemplatePoint2::iterator iter = collector_MyTemplatePoint2.begin();
|
||||
iter != collector_MyTemplatePoint2.end(); ) {
|
||||
delete *iter;
|
||||
collector_MyTemplatePoint2.erase(iter++);
|
||||
anyDeleted = true;
|
||||
} }
|
||||
{ for(Collector_MyTemplateMatrix::iterator iter = collector_MyTemplateMatrix.begin();
|
||||
iter != collector_MyTemplateMatrix.end(); ) {
|
||||
delete *iter;
|
||||
collector_MyTemplateMatrix.erase(iter++);
|
||||
anyDeleted = true;
|
||||
} }
|
||||
{ for(Collector_ns1ClassA::iterator iter = collector_ns1ClassA.begin();
|
||||
iter != collector_ns1ClassA.end(); ) {
|
||||
delete *iter;
|
||||
collector_ns1ClassA.erase(iter++);
|
||||
anyDeleted = true;
|
||||
} }
|
||||
{ for(Collector_ns1ClassB::iterator iter = collector_ns1ClassB.begin();
|
||||
iter != collector_ns1ClassB.end(); ) {
|
||||
delete *iter;
|
||||
collector_ns1ClassB.erase(iter++);
|
||||
anyDeleted = true;
|
||||
} }
|
||||
{ for(Collector_ns2ClassA::iterator iter = collector_ns2ClassA.begin();
|
||||
iter != collector_ns2ClassA.end(); ) {
|
||||
delete *iter;
|
||||
collector_ns2ClassA.erase(iter++);
|
||||
anyDeleted = true;
|
||||
} }
|
||||
{ for(Collector_ns2ns3ClassB::iterator iter = collector_ns2ns3ClassB.begin();
|
||||
iter != collector_ns2ns3ClassB.end(); ) {
|
||||
delete *iter;
|
||||
collector_ns2ns3ClassB.erase(iter++);
|
||||
anyDeleted = true;
|
||||
} }
|
||||
{ for(Collector_ns2ClassC::iterator iter = collector_ns2ClassC.begin();
|
||||
iter != collector_ns2ClassC.end(); ) {
|
||||
delete *iter;
|
||||
collector_ns2ClassC.erase(iter++);
|
||||
anyDeleted = true;
|
||||
} }
|
||||
{ for(Collector_ClassD::iterator iter = collector_ClassD.begin();
|
||||
iter != collector_ClassD.end(); ) {
|
||||
delete *iter;
|
||||
collector_ClassD.erase(iter++);
|
||||
anyDeleted = true;
|
||||
} }
|
||||
{ for(Collector_gtsamNonlinearFactorGraph::iterator iter = collector_gtsamNonlinearFactorGraph.begin();
|
||||
iter != collector_gtsamNonlinearFactorGraph.end(); ) {
|
||||
delete *iter;
|
||||
collector_gtsamNonlinearFactorGraph.erase(iter++);
|
||||
anyDeleted = true;
|
||||
} }
|
||||
{ for(Collector_gtsamPinholeCameraCal3Bundler::iterator iter = collector_gtsamPinholeCameraCal3Bundler.begin();
|
||||
iter != collector_gtsamPinholeCameraCal3Bundler.end(); ) {
|
||||
delete *iter;
|
||||
collector_gtsamPinholeCameraCal3Bundler.erase(iter++);
|
||||
anyDeleted = true;
|
||||
} }
|
||||
if(anyDeleted)
|
||||
cout <<
|
||||
"WARNING: Wrap modules with variables in the workspace have been reloaded due to\n"
|
||||
"calling destructors, call 'clear all' again if you plan to now recompile a wrap\n"
|
||||
"module, so that your recompiled module is used instead of the old one." << endl;
|
||||
std::cout.rdbuf(outbuf);
|
||||
}
|
||||
|
||||
void _special_cases_RTTIRegister() {
|
||||
const mxArray *alreadyCreated = mexGetVariablePtr("global", "gtsam_special_cases_rttiRegistry_created");
|
||||
if(!alreadyCreated) {
|
||||
std::map<std::string, std::string> types;
|
||||
types.insert(std::make_pair(typeid(MyBase).name(), "MyBase"));
|
||||
types.insert(std::make_pair(typeid(MyTemplatePoint2).name(), "MyTemplatePoint2"));
|
||||
types.insert(std::make_pair(typeid(MyTemplateMatrix).name(), "MyTemplateMatrix"));
|
||||
|
||||
mxArray *registry = mexGetVariable("global", "gtsamwrap_rttiRegistry");
|
||||
if(!registry)
|
||||
registry = mxCreateStructMatrix(1, 1, 0, NULL);
|
||||
typedef std::pair<std::string, std::string> StringPair;
|
||||
for(const StringPair& rtti_matlab: types) {
|
||||
int fieldId = mxAddField(registry, rtti_matlab.first.c_str());
|
||||
if(fieldId < 0)
|
||||
mexErrMsgTxt("gtsam wrap: Error indexing RTTI types, inheritance will not work correctly");
|
||||
mxArray *matlabName = mxCreateString(rtti_matlab.second.c_str());
|
||||
mxSetFieldByNumber(registry, 0, fieldId, matlabName);
|
||||
}
|
||||
if(mexPutVariable("global", "gtsamwrap_rttiRegistry", registry) != 0)
|
||||
mexErrMsgTxt("gtsam wrap: Error indexing RTTI types, inheritance will not work correctly");
|
||||
mxDestroyArray(registry);
|
||||
|
||||
mxArray *newAlreadyCreated = mxCreateNumericMatrix(0, 0, mxINT8_CLASS, mxREAL);
|
||||
if(mexPutVariable("global", "gtsam_geometry_rttiRegistry_created", newAlreadyCreated) != 0)
|
||||
mexErrMsgTxt("gtsam wrap: Error indexing RTTI types, inheritance will not work correctly");
|
||||
mxDestroyArray(newAlreadyCreated);
|
||||
}
|
||||
}
|
||||
|
||||
void gtsamNonlinearFactorGraph_collectorInsertAndMakeBase_0(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||
{
|
||||
mexAtExit(&_deleteAllObjects);
|
||||
typedef boost::shared_ptr<gtsam::NonlinearFactorGraph> Shared;
|
||||
|
||||
Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0]));
|
||||
collector_gtsamNonlinearFactorGraph.insert(self);
|
||||
}
|
||||
|
||||
void gtsamNonlinearFactorGraph_deconstructor_1(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||
{
|
||||
typedef boost::shared_ptr<gtsam::NonlinearFactorGraph> Shared;
|
||||
checkArguments("delete_gtsamNonlinearFactorGraph",nargout,nargin,1);
|
||||
Shared *self = *reinterpret_cast<Shared**>(mxGetData(in[0]));
|
||||
Collector_gtsamNonlinearFactorGraph::iterator item;
|
||||
item = collector_gtsamNonlinearFactorGraph.find(self);
|
||||
if(item != collector_gtsamNonlinearFactorGraph.end()) {
|
||||
delete self;
|
||||
collector_gtsamNonlinearFactorGraph.erase(item);
|
||||
}
|
||||
}
|
||||
|
||||
void gtsamNonlinearFactorGraph_addPrior_2(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||
{
|
||||
checkArguments("addPriorPinholeCameraCal3Bundler",nargout,nargin-1,3);
|
||||
auto obj = unwrap_shared_ptr<gtsam::NonlinearFactorGraph>(in[0], "ptr_gtsamNonlinearFactorGraph");
|
||||
size_t key = unwrap< size_t >(in[1]);
|
||||
gtsam::PinholeCamera<gtsam::Cal3Bundler>& prior = *unwrap_shared_ptr< gtsam::PinholeCamera<gtsam::Cal3Bundler> >(in[2], "ptr_gtsamPinholeCameraCal3Bundler");
|
||||
boost::shared_ptr<gtsam::noiseModel::Base> noiseModel = unwrap_shared_ptr< gtsam::noiseModel::Base >(in[3], "ptr_gtsamnoiseModelBase");
|
||||
obj->addPrior<gtsam::PinholeCamera<gtsam::Cal3Bundler>>(key,prior,noiseModel);
|
||||
}
|
||||
|
||||
void gtsamPinholeCameraCal3Bundler_collectorInsertAndMakeBase_3(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||
{
|
||||
mexAtExit(&_deleteAllObjects);
|
||||
typedef boost::shared_ptr<gtsam::PinholeCamera<gtsam::Cal3Bundler>> Shared;
|
||||
|
||||
Shared *self = *reinterpret_cast<Shared**> (mxGetData(in[0]));
|
||||
collector_gtsamPinholeCameraCal3Bundler.insert(self);
|
||||
}
|
||||
|
||||
void gtsamPinholeCameraCal3Bundler_deconstructor_4(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||
{
|
||||
typedef boost::shared_ptr<gtsam::PinholeCamera<gtsam::Cal3Bundler>> Shared;
|
||||
checkArguments("delete_gtsamPinholeCameraCal3Bundler",nargout,nargin,1);
|
||||
Shared *self = *reinterpret_cast<Shared**>(mxGetData(in[0]));
|
||||
Collector_gtsamPinholeCameraCal3Bundler::iterator item;
|
||||
item = collector_gtsamPinholeCameraCal3Bundler.find(self);
|
||||
if(item != collector_gtsamPinholeCameraCal3Bundler.end()) {
|
||||
delete self;
|
||||
collector_gtsamPinholeCameraCal3Bundler.erase(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
|
||||
{
|
||||
mstream mout;
|
||||
std::streambuf *outbuf = std::cout.rdbuf(&mout);
|
||||
|
||||
_special_cases_RTTIRegister();
|
||||
|
||||
int id = unwrap<int>(in[0]);
|
||||
|
||||
try {
|
||||
switch(id) {
|
||||
case 0:
|
||||
gtsamNonlinearFactorGraph_collectorInsertAndMakeBase_0(nargout, out, nargin-1, in+1);
|
||||
break;
|
||||
case 1:
|
||||
gtsamNonlinearFactorGraph_deconstructor_1(nargout, out, nargin-1, in+1);
|
||||
break;
|
||||
case 2:
|
||||
gtsamNonlinearFactorGraph_addPrior_2(nargout, out, nargin-1, in+1);
|
||||
break;
|
||||
case 3:
|
||||
gtsamPinholeCameraCal3Bundler_collectorInsertAndMakeBase_3(nargout, out, nargin-1, in+1);
|
||||
break;
|
||||
case 4:
|
||||
gtsamPinholeCameraCal3Bundler_deconstructor_4(nargout, out, nargin-1, in+1);
|
||||
break;
|
||||
}
|
||||
} catch(const std::exception& e) {
|
||||
mexErrMsgTxt(("Exception from gtsam:\n" + std::string(e.what()) + "\n").c_str());
|
||||
}
|
||||
|
||||
std::cout.rdbuf(outbuf);
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
|
||||
|
||||
#include <pybind11/eigen.h>
|
||||
#include <pybind11/stl_bind.h>
|
||||
#include <pybind11/pybind11.h>
|
||||
#include "gtsam/nonlinear/utilities.h" // for RedirectCout.
|
||||
|
||||
#include "gtsam/geometry/Cal3Bundler.h"
|
||||
|
||||
#include "wrap/serialization.h"
|
||||
#include <boost/serialization/export.hpp>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
PYBIND11_MODULE(special_cases_py, m_) {
|
||||
m_.doc() = "pybind11 wrapper of special_cases_py";
|
||||
|
||||
pybind11::module m_gtsam = m_.def_submodule("gtsam", "gtsam submodule");
|
||||
|
||||
py::class_<gtsam::NonlinearFactorGraph, std::shared_ptr<gtsam::NonlinearFactorGraph>>(m_gtsam, "NonlinearFactorGraph")
|
||||
.def("addPriorPinholeCameraCal3Bundler",[](gtsam::NonlinearFactorGraph* self, size_t key, const gtsam::PinholeCamera<gtsam::Cal3Bundler>& prior, const std::shared_ptr<gtsam::noiseModel::Base>& noiseModel){ self->addPrior<gtsam::PinholeCamera<gtsam::Cal3Bundler>>(key, prior, noiseModel);}, py::arg("key"), py::arg("prior"), py::arg("noiseModel"));
|
||||
|
||||
py::class_<gtsam::PinholeCamera<gtsam::Cal3Bundler>, std::shared_ptr<gtsam::PinholeCamera<gtsam::Cal3Bundler>>>(m_gtsam, "PinholeCameraCal3Bundler");
|
||||
|
||||
|
||||
#include "python/specializations.h"
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
// Check for templated class as template argument for method!
|
||||
namespace gtsam {
|
||||
|
||||
#include <gtsam/geometry/Cal3Bundler.h>
|
||||
|
||||
class Cal3Bundler;
|
||||
|
||||
template<CALIBRATION>
|
||||
class PinholeCamera {};
|
||||
typedef gtsam::PinholeCamera<gtsam::Cal3Bundler> PinholeCameraCal3Bundler;
|
||||
|
||||
class NonlinearFactorGraph {
|
||||
template<T = {gtsam::PinholeCamera<gtsam::Cal3Bundler>}>
|
||||
void addPrior(size_t key, const T& prior, const gtsam::noiseModel::Base* noiseModel);
|
||||
};
|
||||
|
||||
}
|
|
@ -36,7 +36,7 @@ class TestWrap(unittest.TestCase):
|
|||
logger.remove() # remove the default sink
|
||||
logger.add(sys.stderr, format="{time} {level} {message}", level="INFO")
|
||||
|
||||
def generate_content(self, cc_content, path=''):
|
||||
def generate_content(self, cc_content, path=MATLAB_ACTUAL_DIR):
|
||||
"""Generate files and folders from matlab wrapper content.
|
||||
|
||||
Keyword arguments:
|
||||
|
@ -45,9 +45,6 @@ class TestWrap(unittest.TestCase):
|
|||
(folder_name, [(file_name, file_content)])
|
||||
path -- the path to the files parent folder within the main folder
|
||||
"""
|
||||
if path == '':
|
||||
path = self.MATLAB_ACTUAL_DIR
|
||||
|
||||
for c in cc_content:
|
||||
if isinstance(c, list):
|
||||
if len(c) == 0:
|
||||
|
@ -275,6 +272,39 @@ class TestWrap(unittest.TestCase):
|
|||
for file in files:
|
||||
self.compare_and_diff(file)
|
||||
|
||||
def test_special_cases(self):
|
||||
"""
|
||||
Tests for some unique, non-trivial features.
|
||||
"""
|
||||
with open(osp.join(self.INTERFACE_DIR, 'special_cases.i'), 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
if not osp.exists(self.MATLAB_ACTUAL_DIR):
|
||||
os.mkdir(self.MATLAB_ACTUAL_DIR)
|
||||
|
||||
module = parser.Module.parseString(content)
|
||||
|
||||
instantiator.instantiate_namespace_inplace(module)
|
||||
|
||||
wrapper = MatlabWrapper(
|
||||
module=module,
|
||||
module_name='special_cases',
|
||||
top_module_namespace=['gtsam'],
|
||||
ignore_classes=[''],
|
||||
)
|
||||
|
||||
cc_content = wrapper.wrap()
|
||||
|
||||
self.generate_content(cc_content)
|
||||
|
||||
files = [
|
||||
'special_cases_wrapper.cpp',
|
||||
'+gtsam/PinholeCameraCal3Bundler.m',
|
||||
'+gtsam/NonlinearFactorGraph.m',
|
||||
]
|
||||
|
||||
for file in files:
|
||||
self.compare_and_diff(file)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -134,6 +134,18 @@ class TestWrap(unittest.TestCase):
|
|||
|
||||
self.compare_and_diff('namespaces_pybind.cpp', output)
|
||||
|
||||
def test_special_cases(self):
|
||||
"""
|
||||
Tests for some unique, non-trivial features.
|
||||
"""
|
||||
with open(osp.join(self.INTERFACE_DIR, 'special_cases.i'), 'r') as f:
|
||||
content = f.read()
|
||||
|
||||
output = self.wrap_content(content, 'special_cases_py',
|
||||
self.PYTHON_ACTUAL_DIR)
|
||||
|
||||
self.compare_and_diff('special_cases_pybind.cpp', output)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue