1 #include <gtwrap/matlab.h>
28 std::streambuf *outbuf = std::cout.rdbuf(&mout);
30 bool anyDeleted =
false;
70 "WARNING: Wrap modules with variables in the workspace have been reloaded due to\n"
71 "calling destructors, call 'clear all' again if you plan to now recompile a wrap\n"
72 "module, so that your recompiled module is used instead of the old one." << endl;
73 std::cout.rdbuf(outbuf);
77 const mxArray *alreadyCreated = mexGetVariablePtr(
"global",
"gtsam_inheritance_rttiRegistry_created");
79 std::map<std::string, std::string> types;
81 types.insert(std::make_pair(
typeid(MyBase).
name(),
"MyBase"));
84 types.insert(std::make_pair(
typeid(
MyTemplateA).
name(),
"MyTemplateA"));
85 types.insert(std::make_pair(
typeid(ForwardKinematicsFactor).
name(),
"ForwardKinematicsFactor"));
89 mxArray *registry = mexGetVariable(
"global",
"gtsamwrap_rttiRegistry");
91 registry = mxCreateStructMatrix(1, 1, 0,
NULL);
92 typedef std::pair<std::string, std::string> StringPair;
93 for(
const StringPair& rtti_matlab: types) {
94 int fieldId = mxAddField(registry, rtti_matlab.first.c_str());
96 mexErrMsgTxt(
"gtsam wrap: Error indexing RTTI types, inheritance will not work correctly");
98 mxArray *matlabName = mxCreateString(rtti_matlab.second.c_str());
99 mxSetFieldByNumber(registry, 0, fieldId, matlabName);
101 if(mexPutVariable(
"global",
"gtsamwrap_rttiRegistry", registry) != 0) {
102 mexErrMsgTxt(
"gtsam wrap: Error indexing RTTI types, inheritance will not work correctly");
104 mxDestroyArray(registry);
106 mxArray *newAlreadyCreated = mxCreateNumericMatrix(0, 0, mxINT8_CLASS, mxREAL);
107 if(mexPutVariable(
"global",
"gtsam_inheritance_rttiRegistry_created", newAlreadyCreated) != 0) {
108 mexErrMsgTxt(
"gtsam wrap: Error indexing RTTI types, inheritance will not work correctly");
110 mxDestroyArray(newAlreadyCreated);
117 typedef std::shared_ptr<MyBase> Shared;
119 Shared *
self = *
reinterpret_cast<Shared**
> (mxGetData(in[0]));
125 typedef std::shared_ptr<MyBase> Shared;
126 std::shared_ptr<void> *asVoid = *
reinterpret_cast<std::shared_ptr<void>**
> (mxGetData(in[0]));
128 Shared *
self =
new Shared(std::static_pointer_cast<MyBase>(*asVoid));
129 *
reinterpret_cast<Shared**
>(mxGetData(
out[0])) =
self;
134 typedef std::shared_ptr<MyBase> Shared;
136 Shared *
self = *
reinterpret_cast<Shared**
>(mxGetData(in[0]));
137 Collector_MyBase::iterator item;
148 typedef std::shared_ptr<MyTemplate<gtsam::Point2>> Shared;
150 Shared *
self = *
reinterpret_cast<Shared**
> (mxGetData(in[0]));
153 typedef std::shared_ptr<MyBase> SharedBase;
155 *
reinterpret_cast<SharedBase**
>(mxGetData(
out[0])) =
new SharedBase(*
self);
160 typedef std::shared_ptr<MyTemplate<gtsam::Point2>> Shared;
161 std::shared_ptr<void> *asVoid = *
reinterpret_cast<std::shared_ptr<void>**
> (mxGetData(in[0]));
163 Shared *
self =
new Shared(std::static_pointer_cast<MyTemplate<gtsam::Point2>>(*asVoid));
164 *
reinterpret_cast<Shared**
>(mxGetData(
out[0])) =
self;
170 typedef std::shared_ptr<MyTemplate<gtsam::Point2>> Shared;
172 Shared *
self =
new Shared(
new MyTemplate<gtsam::Point2>());
175 *
reinterpret_cast<Shared**
> (mxGetData(
out[0])) =
self;
177 typedef std::shared_ptr<MyBase> SharedBase;
179 *
reinterpret_cast<SharedBase**
>(mxGetData(
out[1])) =
new SharedBase(*
self);
184 typedef std::shared_ptr<MyTemplate<gtsam::Point2>> Shared;
186 Shared *
self = *
reinterpret_cast<Shared**
>(mxGetData(in[0]));
187 Collector_MyTemplatePoint2::iterator item;
198 auto obj = unwrap_shared_ptr<MyTemplate<gtsam::Point2>>(in[0],
"ptr_MyTemplatePoint2");
200 obj->accept_T(
value);
206 auto obj = unwrap_shared_ptr<MyTemplate<gtsam::Point2>>(in[0],
"ptr_MyTemplatePoint2");
208 obj->accept_Tptr(
value);
214 auto obj = unwrap_shared_ptr<MyTemplate<gtsam::Point2>>(in[0],
"ptr_MyTemplatePoint2");
215 auto pairResult = obj->create_MixedPtrs();
216 out[0] = wrap< Point2 >(pairResult.first);
218 std::shared_ptr<Point2> shared(pairResult.second);
226 auto obj = unwrap_shared_ptr<MyTemplate<gtsam::Point2>>(in[0],
"ptr_MyTemplatePoint2");
227 auto pairResult = obj->create_ptrs();
229 std::shared_ptr<Point2> shared(pairResult.first);
233 std::shared_ptr<Point2> shared(pairResult.second);
241 auto obj = unwrap_shared_ptr<MyTemplate<gtsam::Point2>>(in[0],
"ptr_MyTemplatePoint2");
243 out[0] = wrap< Point2 >(obj->return_T(
value));
249 auto obj = unwrap_shared_ptr<MyTemplate<gtsam::Point2>>(in[0],
"ptr_MyTemplatePoint2");
252 std::shared_ptr<Point2> shared(obj->return_Tptr(
value));
260 auto obj = unwrap_shared_ptr<MyTemplate<gtsam::Point2>>(in[0],
"ptr_MyTemplatePoint2");
261 Point2 p1 = unwrap< Point2 >(in[1]);
262 Point2 p2 = unwrap< Point2 >(in[2]);
263 auto pairResult = obj->return_ptrs(
p1,
p2);
265 std::shared_ptr<Point2> shared(pairResult.first);
269 std::shared_ptr<Point2> shared(pairResult.second);
277 auto obj = unwrap_shared_ptr<MyTemplate<gtsam::Point2>>(in[0],
"ptr_MyTemplatePoint2");
278 Matrix t = unwrap< Matrix >(in[1]);
285 auto obj = unwrap_shared_ptr<MyTemplate<gtsam::Point2>>(in[0],
"ptr_MyTemplatePoint2");
286 Point2 t = unwrap< Point2 >(in[1]);
293 auto obj = unwrap_shared_ptr<MyTemplate<gtsam::Point2>>(in[0],
"ptr_MyTemplatePoint2");
294 Point3 t = unwrap< Point3 >(in[1]);
301 auto obj = unwrap_shared_ptr<MyTemplate<gtsam::Point2>>(in[0],
"ptr_MyTemplatePoint2");
302 Vector t = unwrap< Vector >(in[1]);
308 checkArguments(
"MyTemplate<gtsam::Point2>.Level",nargout,nargin,1);
309 Point2 K = unwrap< Point2 >(in[0]);
316 typedef std::shared_ptr<MyTemplate<gtsam::Matrix>> Shared;
318 Shared *
self = *
reinterpret_cast<Shared**
> (mxGetData(in[0]));
321 typedef std::shared_ptr<MyBase> SharedBase;
323 *
reinterpret_cast<SharedBase**
>(mxGetData(
out[0])) =
new SharedBase(*
self);
328 typedef std::shared_ptr<MyTemplate<gtsam::Matrix>> Shared;
329 std::shared_ptr<void> *asVoid = *
reinterpret_cast<std::shared_ptr<void>**
> (mxGetData(in[0]));
331 Shared *
self =
new Shared(std::static_pointer_cast<MyTemplate<gtsam::Matrix>>(*asVoid));
332 *
reinterpret_cast<Shared**
>(mxGetData(
out[0])) =
self;
338 typedef std::shared_ptr<MyTemplate<gtsam::Matrix>> Shared;
340 Shared *
self =
new Shared(
new MyTemplate<gtsam::Matrix>());
343 *
reinterpret_cast<Shared**
> (mxGetData(
out[0])) =
self;
345 typedef std::shared_ptr<MyBase> SharedBase;
347 *
reinterpret_cast<SharedBase**
>(mxGetData(
out[1])) =
new SharedBase(*
self);
352 typedef std::shared_ptr<MyTemplate<gtsam::Matrix>> Shared;
354 Shared *
self = *
reinterpret_cast<Shared**
>(mxGetData(in[0]));
355 Collector_MyTemplateMatrix::iterator item;
366 auto obj = unwrap_shared_ptr<MyTemplate<gtsam::Matrix>>(in[0],
"ptr_MyTemplateMatrix");
368 obj->accept_T(
value);
374 auto obj = unwrap_shared_ptr<MyTemplate<gtsam::Matrix>>(in[0],
"ptr_MyTemplateMatrix");
376 obj->accept_Tptr(
value);
382 auto obj = unwrap_shared_ptr<MyTemplate<gtsam::Matrix>>(in[0],
"ptr_MyTemplateMatrix");
383 auto pairResult = obj->create_MixedPtrs();
384 out[0] = wrap< Matrix >(pairResult.first);
386 std::shared_ptr<Matrix> shared(pairResult.second);
394 auto obj = unwrap_shared_ptr<MyTemplate<gtsam::Matrix>>(in[0],
"ptr_MyTemplateMatrix");
395 auto pairResult = obj->create_ptrs();
397 std::shared_ptr<Matrix> shared(pairResult.first);
401 std::shared_ptr<Matrix> shared(pairResult.second);
409 auto obj = unwrap_shared_ptr<MyTemplate<gtsam::Matrix>>(in[0],
"ptr_MyTemplateMatrix");
411 out[0] = wrap< Matrix >(obj->return_T(
value));
417 auto obj = unwrap_shared_ptr<MyTemplate<gtsam::Matrix>>(in[0],
"ptr_MyTemplateMatrix");
420 std::shared_ptr<Matrix> shared(obj->return_Tptr(
value));
428 auto obj = unwrap_shared_ptr<MyTemplate<gtsam::Matrix>>(in[0],
"ptr_MyTemplateMatrix");
429 Matrix p1 = unwrap< Matrix >(in[1]);
430 Matrix p2 = unwrap< Matrix >(in[2]);
431 auto pairResult = obj->return_ptrs(
p1,
p2);
433 std::shared_ptr<Matrix> shared(pairResult.first);
437 std::shared_ptr<Matrix> shared(pairResult.second);
445 auto obj = unwrap_shared_ptr<MyTemplate<gtsam::Matrix>>(in[0],
"ptr_MyTemplateMatrix");
446 Matrix t = unwrap< Matrix >(in[1]);
453 auto obj = unwrap_shared_ptr<MyTemplate<gtsam::Matrix>>(in[0],
"ptr_MyTemplateMatrix");
454 Point2 t = unwrap< Point2 >(in[1]);
461 auto obj = unwrap_shared_ptr<MyTemplate<gtsam::Matrix>>(in[0],
"ptr_MyTemplateMatrix");
462 Point3 t = unwrap< Point3 >(in[1]);
469 auto obj = unwrap_shared_ptr<MyTemplate<gtsam::Matrix>>(in[0],
"ptr_MyTemplateMatrix");
470 Vector t = unwrap< Vector >(in[1]);
476 checkArguments(
"MyTemplate<gtsam::Matrix>.Level",nargout,nargin,1);
477 Matrix K = unwrap< Matrix >(in[0]);
484 typedef std::shared_ptr<MyTemplate<A>> Shared;
486 Shared *
self = *
reinterpret_cast<Shared**
> (mxGetData(in[0]));
489 typedef std::shared_ptr<MyBase> SharedBase;
491 *
reinterpret_cast<SharedBase**
>(mxGetData(
out[0])) =
new SharedBase(*
self);
496 typedef std::shared_ptr<MyTemplate<A>> Shared;
497 std::shared_ptr<void> *asVoid = *
reinterpret_cast<std::shared_ptr<void>**
> (mxGetData(in[0]));
499 Shared *
self =
new Shared(std::static_pointer_cast<MyTemplate<A>>(*asVoid));
500 *
reinterpret_cast<Shared**
>(mxGetData(
out[0])) =
self;
506 typedef std::shared_ptr<MyTemplate<A>> Shared;
508 Shared *
self =
new Shared(
new MyTemplate<A>());
511 *
reinterpret_cast<Shared**
> (mxGetData(
out[0])) =
self;
513 typedef std::shared_ptr<MyBase> SharedBase;
515 *
reinterpret_cast<SharedBase**
>(mxGetData(
out[1])) =
new SharedBase(*
self);
520 typedef std::shared_ptr<MyTemplate<A>> Shared;
522 Shared *
self = *
reinterpret_cast<Shared**
>(mxGetData(in[0]));
523 Collector_MyTemplateA::iterator item;
534 auto obj = unwrap_shared_ptr<MyTemplate<A>>(in[0],
"ptr_MyTemplateA");
535 A&
value = *unwrap_shared_ptr< A >(in[1],
"ptr_A");
536 obj->accept_T(
value);
542 auto obj = unwrap_shared_ptr<MyTemplate<A>>(in[0],
"ptr_MyTemplateA");
543 std::shared_ptr<A>
value = unwrap_shared_ptr< A >(in[1],
"ptr_A");
544 obj->accept_Tptr(
value);
550 auto obj = unwrap_shared_ptr<MyTemplate<A>>(in[0],
"ptr_MyTemplateA");
551 auto pairResult = obj->create_MixedPtrs();
559 auto obj = unwrap_shared_ptr<MyTemplate<A>>(in[0],
"ptr_MyTemplateA");
560 auto pairResult = obj->create_ptrs();
568 auto obj = unwrap_shared_ptr<MyTemplate<A>>(in[0],
"ptr_MyTemplateA");
569 A*
value = unwrap_ptr< A >(in[1],
"ptr_A");
576 auto obj = unwrap_shared_ptr<MyTemplate<A>>(in[0],
"ptr_MyTemplateA");
577 std::shared_ptr<A>
value = unwrap_shared_ptr< A >(in[1],
"ptr_A");
584 auto obj = unwrap_shared_ptr<MyTemplate<A>>(in[0],
"ptr_MyTemplateA");
585 std::shared_ptr<A>
p1 = unwrap_shared_ptr< A >(in[1],
"ptr_A");
586 std::shared_ptr<A>
p2 = unwrap_shared_ptr< A >(in[2],
"ptr_A");
587 auto pairResult = obj->return_ptrs(
p1,
p2);
595 auto obj = unwrap_shared_ptr<MyTemplate<A>>(in[0],
"ptr_MyTemplateA");
596 Matrix t = unwrap< Matrix >(in[1]);
603 auto obj = unwrap_shared_ptr<MyTemplate<A>>(in[0],
"ptr_MyTemplateA");
604 Point2 t = unwrap< Point2 >(in[1]);
611 auto obj = unwrap_shared_ptr<MyTemplate<A>>(in[0],
"ptr_MyTemplateA");
612 Point3 t = unwrap< Point3 >(in[1]);
619 auto obj = unwrap_shared_ptr<MyTemplate<A>>(in[0],
"ptr_MyTemplateA");
620 Vector t = unwrap< Vector >(in[1]);
627 A&
K = *unwrap_shared_ptr< A >(in[0],
"ptr_A");
634 typedef std::shared_ptr<ForwardKinematicsFactor> Shared;
636 Shared *
self = *
reinterpret_cast<Shared**
> (mxGetData(in[0]));
639 typedef std::shared_ptr<gtsam::BetweenFactor<gtsam::Pose3>> SharedBase;
641 *
reinterpret_cast<SharedBase**
>(mxGetData(
out[0])) =
new SharedBase(*
self);
646 typedef std::shared_ptr<ForwardKinematicsFactor> Shared;
647 std::shared_ptr<void> *asVoid = *
reinterpret_cast<std::shared_ptr<void>**
> (mxGetData(in[0]));
649 Shared *
self =
new Shared(std::static_pointer_cast<ForwardKinematicsFactor>(*asVoid));
650 *
reinterpret_cast<Shared**
>(mxGetData(
out[0])) =
self;
655 typedef std::shared_ptr<ForwardKinematicsFactor> Shared;
656 checkArguments(
"delete_ForwardKinematicsFactor",nargout,nargin,1);
657 Shared *
self = *
reinterpret_cast<Shared**
>(mxGetData(in[0]));
658 Collector_ForwardKinematicsFactor::iterator item;
669 typedef std::shared_ptr<ParentHasTemplate<double>> Shared;
671 Shared *
self = *
reinterpret_cast<Shared**
> (mxGetData(in[0]));
674 typedef std::shared_ptr<MyTemplate<double>> SharedBase;
676 *
reinterpret_cast<SharedBase**
>(mxGetData(
out[0])) =
new SharedBase(*
self);
681 typedef std::shared_ptr<ParentHasTemplate<double>> Shared;
682 std::shared_ptr<void> *asVoid = *
reinterpret_cast<std::shared_ptr<void>**
> (mxGetData(in[0]));
684 Shared *
self =
new Shared(std::static_pointer_cast<ParentHasTemplate<double>>(*asVoid));
685 *
reinterpret_cast<Shared**
>(mxGetData(
out[0])) =
self;
690 typedef std::shared_ptr<ParentHasTemplate<double>> Shared;
691 checkArguments(
"delete_ParentHasTemplateDouble",nargout,nargin,1);
692 Shared *
self = *
reinterpret_cast<Shared**
>(mxGetData(in[0]));
693 Collector_ParentHasTemplateDouble::iterator item;
705 std::streambuf *outbuf = std::cout.rdbuf(&mout);
885 }
catch(
const std::exception&
e) {
886 mexErrMsgTxt((
"Exception from gtsam:\n" + std::string(
e.what()) +
"\n").c_str());
889 std::cout.rdbuf(outbuf);