functions_wrapper.cpp
Go to the documentation of this file.
1 #include <gtwrap/matlab.h>
2 #include <map>
3 
4 #include <boost/archive/text_iarchive.hpp>
5 #include <boost/archive/text_oarchive.hpp>
6 #include <boost/serialization/export.hpp>
7 
8 #include <folder/path/to/Test.h>
9 
10 
11 typedef Fun<double> FunDouble;
12 typedef PrimitiveRef<double> PrimitiveRefDouble;
13 typedef MyVector<3> MyVector3;
14 typedef MyVector<12> MyVector12;
15 typedef MultipleTemplates<int, double> MultipleTemplatesIntDouble;
16 typedef MultipleTemplates<int, float> MultipleTemplatesIntFloat;
18 
19 
20 typedef std::set<boost::shared_ptr<FunRange>*> Collector_FunRange;
22 typedef std::set<boost::shared_ptr<FunDouble>*> Collector_FunDouble;
24 typedef std::set<boost::shared_ptr<Test>*> Collector_Test;
26 typedef std::set<boost::shared_ptr<PrimitiveRefDouble>*> Collector_PrimitiveRefDouble;
28 typedef std::set<boost::shared_ptr<MyVector3>*> Collector_MyVector3;
30 typedef std::set<boost::shared_ptr<MyVector12>*> Collector_MyVector12;
32 typedef std::set<boost::shared_ptr<MultipleTemplatesIntDouble>*> Collector_MultipleTemplatesIntDouble;
34 typedef std::set<boost::shared_ptr<MultipleTemplatesIntFloat>*> Collector_MultipleTemplatesIntFloat;
36 typedef std::set<boost::shared_ptr<MyFactorPosePoint2>*> Collector_MyFactorPosePoint2;
38 
40 {
41  mstream mout;
42  std::streambuf *outbuf = std::cout.rdbuf(&mout);
43 
44  bool anyDeleted = false;
45  { for(Collector_FunRange::iterator iter = collector_FunRange.begin();
46  iter != collector_FunRange.end(); ) {
47  delete *iter;
48  collector_FunRange.erase(iter++);
49  anyDeleted = true;
50  } }
51  { for(Collector_FunDouble::iterator iter = collector_FunDouble.begin();
52  iter != collector_FunDouble.end(); ) {
53  delete *iter;
54  collector_FunDouble.erase(iter++);
55  anyDeleted = true;
56  } }
57  { for(Collector_Test::iterator iter = collector_Test.begin();
58  iter != collector_Test.end(); ) {
59  delete *iter;
60  collector_Test.erase(iter++);
61  anyDeleted = true;
62  } }
63  { for(Collector_PrimitiveRefDouble::iterator iter = collector_PrimitiveRefDouble.begin();
65  delete *iter;
67  anyDeleted = true;
68  } }
69  { for(Collector_MyVector3::iterator iter = collector_MyVector3.begin();
70  iter != collector_MyVector3.end(); ) {
71  delete *iter;
72  collector_MyVector3.erase(iter++);
73  anyDeleted = true;
74  } }
75  { for(Collector_MyVector12::iterator iter = collector_MyVector12.begin();
76  iter != collector_MyVector12.end(); ) {
77  delete *iter;
78  collector_MyVector12.erase(iter++);
79  anyDeleted = true;
80  } }
81  { for(Collector_MultipleTemplatesIntDouble::iterator iter = collector_MultipleTemplatesIntDouble.begin();
83  delete *iter;
85  anyDeleted = true;
86  } }
87  { for(Collector_MultipleTemplatesIntFloat::iterator iter = collector_MultipleTemplatesIntFloat.begin();
89  delete *iter;
91  anyDeleted = true;
92  } }
93  { for(Collector_MyFactorPosePoint2::iterator iter = collector_MyFactorPosePoint2.begin();
95  delete *iter;
97  anyDeleted = true;
98  } }
99  if(anyDeleted)
100  cout <<
101  "WARNING: Wrap modules with variables in the workspace have been reloaded due to\n"
102  "calling destructors, call 'clear all' again if you plan to now recompile a wrap\n"
103  "module, so that your recompiled module is used instead of the old one." << endl;
104  std::cout.rdbuf(outbuf);
105 }
106 
108  const mxArray *alreadyCreated = mexGetVariablePtr("global", "gtsam_functions_rttiRegistry_created");
109  if(!alreadyCreated) {
110  std::map<std::string, std::string> types;
111 
112  mxArray *registry = mexGetVariable("global", "gtsamwrap_rttiRegistry");
113  if(!registry)
114  registry = mxCreateStructMatrix(1, 1, 0, NULL);
115  typedef std::pair<std::string, std::string> StringPair;
116  for(const StringPair& rtti_matlab: types) {
117  int fieldId = mxAddField(registry, rtti_matlab.first.c_str());
118  if(fieldId < 0)
119  mexErrMsgTxt("gtsam wrap: Error indexing RTTI types, inheritance will not work correctly");
120  mxArray *matlabName = mxCreateString(rtti_matlab.second.c_str());
121  mxSetFieldByNumber(registry, 0, fieldId, matlabName);
122  }
123  if(mexPutVariable("global", "gtsamwrap_rttiRegistry", registry) != 0)
124  mexErrMsgTxt("gtsam wrap: Error indexing RTTI types, inheritance will not work correctly");
125  mxDestroyArray(registry);
126 
127  mxArray *newAlreadyCreated = mxCreateNumericMatrix(0, 0, mxINT8_CLASS, mxREAL);
128  if(mexPutVariable("global", "gtsam_geometry_rttiRegistry_created", newAlreadyCreated) != 0)
129  mexErrMsgTxt("gtsam wrap: Error indexing RTTI types, inheritance will not work correctly");
130  mxDestroyArray(newAlreadyCreated);
131  }
132 }
133 
134 void load2D_0(int nargout, mxArray *out[], int nargin, const mxArray *in[])
135 {
136  checkArguments("load2D",nargout,nargin,5);
137  string filename = unwrap< string >(in[0]);
138  boost::shared_ptr<Test> model = unwrap_shared_ptr< Test >(in[1], "ptr_Test");
139  int maxID = unwrap< int >(in[2]);
140  bool addNoise = unwrap< bool >(in[3]);
141  bool smart = unwrap< bool >(in[4]);
142  auto pairResult = load2D(filename,model,maxID,addNoise,smart);
143  out[0] = wrap_shared_ptr(pairResult.first,"gtsam.NonlinearFactorGraph", false);
144  out[1] = wrap_shared_ptr(pairResult.second,"gtsam.Values", false);
145 }
146 void load2D_1(int nargout, mxArray *out[], int nargin, const mxArray *in[])
147 {
148  checkArguments("load2D",nargout,nargin,5);
149  string filename = unwrap< string >(in[0]);
150  boost::shared_ptr<gtsam::noiseModel::Diagonal> model = unwrap_shared_ptr< gtsam::noiseModel::Diagonal >(in[1], "ptr_gtsamnoiseModelDiagonal");
151  int maxID = unwrap< int >(in[2]);
152  bool addNoise = unwrap< bool >(in[3]);
153  bool smart = unwrap< bool >(in[4]);
154  auto pairResult = load2D(filename,model,maxID,addNoise,smart);
155  out[0] = wrap_shared_ptr(pairResult.first,"gtsam.NonlinearFactorGraph", false);
156  out[1] = wrap_shared_ptr(pairResult.second,"gtsam.Values", false);
157 }
158 void load2D_2(int nargout, mxArray *out[], int nargin, const mxArray *in[])
159 {
160  checkArguments("load2D",nargout,nargin,2);
161  string filename = unwrap< string >(in[0]);
162  boost::shared_ptr<gtsam::noiseModel::Diagonal> model = unwrap_shared_ptr< gtsam::noiseModel::Diagonal >(in[1], "ptr_gtsamnoiseModelDiagonal");
163  auto pairResult = load2D(filename,model);
164  out[0] = wrap_shared_ptr(pairResult.first,"gtsam.NonlinearFactorGraph", false);
165  out[1] = wrap_shared_ptr(pairResult.second,"gtsam.Values", false);
166 }
167 void aGlobalFunction_3(int nargout, mxArray *out[], int nargin, const mxArray *in[])
168 {
169  checkArguments("aGlobalFunction",nargout,nargin,0);
170  out[0] = wrap< Vector >(aGlobalFunction());
171 }
172 void overloadedGlobalFunction_4(int nargout, mxArray *out[], int nargin, const mxArray *in[])
173 {
174  checkArguments("overloadedGlobalFunction",nargout,nargin,1);
175  int a = unwrap< int >(in[0]);
176  out[0] = wrap< Vector >(overloadedGlobalFunction(a));
177 }
178 void overloadedGlobalFunction_5(int nargout, mxArray *out[], int nargin, const mxArray *in[])
179 {
180  checkArguments("overloadedGlobalFunction",nargout,nargin,2);
181  int a = unwrap< int >(in[0]);
182  double b = unwrap< double >(in[1]);
183  out[0] = wrap< Vector >(overloadedGlobalFunction(a,b));
184 }
185 void MultiTemplatedFunctionStringSize_tDouble_6(int nargout, mxArray *out[], int nargin, const mxArray *in[])
186 {
187  checkArguments("MultiTemplatedFunctionStringSize_tDouble",nargout,nargin,2);
188  T& x = *unwrap_shared_ptr< T >(in[0], "ptr_T");
189  size_t y = unwrap< size_t >(in[1]);
190  out[0] = wrap< double >(MultiTemplatedFunctionStringSize_tDouble(x,y));
191 }
192 void MultiTemplatedFunctionDoubleSize_tDouble_7(int nargout, mxArray *out[], int nargin, const mxArray *in[])
193 {
194  checkArguments("MultiTemplatedFunctionDoubleSize_tDouble",nargout,nargin,2);
195  T& x = *unwrap_shared_ptr< T >(in[0], "ptr_T");
196  size_t y = unwrap< size_t >(in[1]);
197  out[0] = wrap< double >(MultiTemplatedFunctionDoubleSize_tDouble(x,y));
198 }
199 void DefaultFuncInt_8(int nargout, mxArray *out[], int nargin, const mxArray *in[])
200 {
201  checkArguments("DefaultFuncInt",nargout,nargin,1);
202  int a = unwrap< int >(in[0]);
203  DefaultFuncInt(a);
204 }
205 void DefaultFuncString_9(int nargout, mxArray *out[], int nargin, const mxArray *in[])
206 {
207  checkArguments("DefaultFuncString",nargout,nargin,2);
208  string& s = *unwrap_shared_ptr< string >(in[0], "ptr_string");
209  string& name = *unwrap_shared_ptr< string >(in[1], "ptr_string");
210  DefaultFuncString(s,name);
211 }
212 void DefaultFuncObj_10(int nargout, mxArray *out[], int nargin, const mxArray *in[])
213 {
214  checkArguments("DefaultFuncObj",nargout,nargin,1);
215  gtsam::KeyFormatter& keyFormatter = *unwrap_shared_ptr< gtsam::KeyFormatter >(in[0], "ptr_gtsamKeyFormatter");
216  DefaultFuncObj(keyFormatter);
217 }
218 void TemplatedFunctionRot3_11(int nargout, mxArray *out[], int nargin, const mxArray *in[])
219 {
220  checkArguments("TemplatedFunctionRot3",nargout,nargin,1);
221  gtsam::Rot3& t = *unwrap_shared_ptr< gtsam::Rot3 >(in[0], "ptr_gtsamRot3");
222  TemplatedFunctionRot3(t);
223 }
224 
225 void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
226 {
227  mstream mout;
228  std::streambuf *outbuf = std::cout.rdbuf(&mout);
229 
231 
232  int id = unwrap<int>(in[0]);
233 
234  try {
235  switch(id) {
236  case 0:
237  load2D_0(nargout, out, nargin-1, in+1);
238  break;
239  case 1:
240  load2D_1(nargout, out, nargin-1, in+1);
241  break;
242  case 2:
243  load2D_2(nargout, out, nargin-1, in+1);
244  break;
245  case 3:
246  aGlobalFunction_3(nargout, out, nargin-1, in+1);
247  break;
248  case 4:
249  overloadedGlobalFunction_4(nargout, out, nargin-1, in+1);
250  break;
251  case 5:
252  overloadedGlobalFunction_5(nargout, out, nargin-1, in+1);
253  break;
254  case 6:
255  MultiTemplatedFunctionStringSize_tDouble_6(nargout, out, nargin-1, in+1);
256  break;
257  case 7:
258  MultiTemplatedFunctionDoubleSize_tDouble_7(nargout, out, nargin-1, in+1);
259  break;
260  case 8:
261  DefaultFuncInt_8(nargout, out, nargin-1, in+1);
262  break;
263  case 9:
264  DefaultFuncString_9(nargout, out, nargin-1, in+1);
265  break;
266  case 10:
267  DefaultFuncObj_10(nargout, out, nargin-1, in+1);
268  break;
269  case 11:
270  TemplatedFunctionRot3_11(nargout, out, nargin-1, in+1);
271  break;
272  }
273  } catch(const std::exception& e) {
274  mexErrMsgTxt(("Exception from gtsam:\n" + std::string(e.what()) + "\n").c_str());
275  }
276 
277  std::cout.rdbuf(outbuf);
278 }
int unwrap< int >(const mxArray *array)
Definition: matlab.h:295
MyVector< 12 > MyVector12
void DefaultFuncString_9(int nargout, mxArray *out[], int nargin, const mxArray *in[])
std::set< boost::shared_ptr< Test > * > Collector_Test
MyFactor< gtsam::Pose2, gtsam::Matrix > MyFactorPosePoint2
void mexFunction(int nargout, mxArray *out[], int nargin, const mxArray *in[])
static Collector_FunRange collector_FunRange
Scalar * y
Scalar * b
Definition: benchVecAdd.cpp:17
std::set< boost::shared_ptr< MultipleTemplatesIntDouble > * > Collector_MultipleTemplatesIntDouble
noiseModel::Diagonal::shared_ptr model
void checkArguments(const string &name, int nargout, int nargin, int expected)
Definition: matlab.h:116
GraphAndValues load2D(const string &filename, SharedNoiseModel model, size_t maxIndex, bool addNoise, bool smart, NoiseFormat noiseFormat, KernelFunctionType kernelFunctionType)
Definition: dataset.cpp:500
void _functions_RTTIRegister()
std::set< boost::shared_ptr< MyVector12 > * > Collector_MyVector12
MyVector< 3 > MyVector3
void overloadedGlobalFunction_4(int nargout, mxArray *out[], int nargin, const mxArray *in[])
string unwrap< string >(const mxArray *array)
Definition: matlab.h:250
iterator iter(handle obj)
Definition: pytypes.h:1547
std::set< boost::shared_ptr< PrimitiveRefDouble > * > Collector_PrimitiveRefDouble
std::set< boost::shared_ptr< MyFactorPosePoint2 > * > Collector_MyFactorPosePoint2
size_t unwrap< size_t >(const mxArray *array)
Definition: matlab.h:302
std::set< boost::shared_ptr< MyVector12 > * > Collector_MyVector12
MultipleTemplates< int, float > MultipleTemplatesIntFloat
mxArray * wrap_shared_ptr(boost::shared_ptr< Class > shared_ptr, const std::string &matlabName, bool isVirtual)
Definition: matlab.h:454
GeneralSFMFactor< SfmCamera, Point3 > MyFactor
std::set< boost::shared_ptr< MultipleTemplatesIntDouble > * > Collector_MultipleTemplatesIntDouble
void load2D_1(int nargout, mxArray *out[], int nargin, const mxArray *in[])
void aGlobalFunction_3(int nargout, mxArray *out[], int nargin, const mxArray *in[])
Array33i a
static Collector_MyVector3 collector_MyVector3
std::set< boost::shared_ptr< FunRange > * > Collector_FunRange
std::set< boost::shared_ptr< MultipleTemplatesIntFloat > * > Collector_MultipleTemplatesIntFloat
std::set< boost::shared_ptr< MyVector3 > * > Collector_MyVector3
double unwrap< double >(const mxArray *array)
Definition: matlab.h:309
std::set< boost::shared_ptr< MyFactorPosePoint2 > * > Collector_MyFactorPosePoint2
static Collector_PrimitiveRefDouble collector_PrimitiveRefDouble
void load2D_2(int nargout, mxArray *out[], int nargin, const mxArray *in[])
void _deleteAllObjects()
void TemplatedFunctionRot3_11(int nargout, mxArray *out[], int nargin, const mxArray *in[])
static Collector_MultipleTemplatesIntDouble collector_MultipleTemplatesIntDouble
static Collector_MultipleTemplatesIntFloat collector_MultipleTemplatesIntFloat
std::set< boost::shared_ptr< Test > * > Collector_Test
std::function< std::string(Key)> KeyFormatter
Typedef for a function to format a key, i.e. to convert it to a string.
Definition: Key.h:35
std::set< boost::shared_ptr< FunDouble > * > Collector_FunDouble
Array< double, 1, 3 > e(1./3., 0.5, 2.)
RealScalar s
std::set< boost::shared_ptr< MultipleTemplatesIntFloat > * > Collector_MultipleTemplatesIntFloat
std::set< boost::shared_ptr< PrimitiveRefDouble > * > Collector_PrimitiveRefDouble
Fun< double > FunDouble
std::set< boost::shared_ptr< FunDouble > * > Collector_FunDouble
#define NULL
Definition: ccolamd.c:609
void overloadedGlobalFunction_5(int nargout, mxArray *out[], int nargin, const mxArray *in[])
mxArray * wrap< double >(const double &value)
Definition: matlab.h:183
void MultiTemplatedFunctionStringSize_tDouble_6(int nargout, mxArray *out[], int nargin, const mxArray *in[])
std::set< boost::shared_ptr< MyVector3 > * > Collector_MyVector3
static Collector_Test collector_Test
std::set< boost::shared_ptr< FunRange > * > Collector_FunRange
void DefaultFuncInt_8(int nargout, mxArray *out[], int nargin, const mxArray *in[])
void load2D_0(int nargout, mxArray *out[], int nargin, const mxArray *in[])
MultipleTemplates< int, double > MultipleTemplatesIntDouble
static Collector_MyVector12 collector_MyVector12
void DefaultFuncObj_10(int nargout, mxArray *out[], int nargin, const mxArray *in[])
static Collector_MyFactorPosePoint2 collector_MyFactorPosePoint2
static Collector_FunDouble collector_FunDouble
void MultiTemplatedFunctionDoubleSize_tDouble_7(int nargout, mxArray *out[], int nargin, const mxArray *in[])
Annotation for function names.
Definition: attr.h:36
bool unwrap< bool >(const mxArray *array)
Definition: matlab.h:274
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: matlab.h:98
PrimitiveRef< double > PrimitiveRefDouble
Point2 t(10, 10)


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:42:05