Go to the documentation of this file.
51 #define GTSAM_MAGIC_GAUSSIAN
54 #if defined(__LP64__) || defined(_WIN64)
56 #define mxUINT32OR64_CLASS mxUINT64_CLASS
58 #define mxUINT32OR64_CLASS mxUINT32_CLASS
79 mexErrMsgIdAndTxt(
"wrap:error",
str);
83 mwSize dims[1]; dims[0]=1;
84 return mxCreateNumericArray(1, dims, classid, mxREAL);
90 mexErrMsgIdAndTxt(
"wrap: not a scalar in ",
str);
97 virtual std::streamsize
xsputn(
const char *
s, std::streamsize
n) {
98 mexPrintf(
"%.*s",
n,
s);
103 mexPrintf(
"%.1s",&
c);
115 err <<
name <<
" expects " <<
expected <<
" arguments, not " << nargin;
117 error(err.str().c_str());
125 template <
typename Class>
127 error(
"wrap internal error: attempted wrap of invalid type");
135 return mxCreateString(
value.c_str());
181 return mxCreateDoubleScalar(
value);
187 mxArray *
result = mxCreateDoubleMatrix(
m, 1, mxREAL);
213 int m =
A.rows(),
n =
A.cols();
215 mexPrintf(
"wrap_Matrix called with A = \n",
m,
n);
218 mxArray *
result = mxCreateDoubleMatrix(
m,
n, mxREAL);
235 template <
typename T>
238 mxArray*
a = mxCreateDoubleMatrix(1, 1, mxREAL);
239 double*
data = mxGetPr(
a);
240 data[0] =
static_cast<double>(
x);
244 mexCallMATLAB(1, &
result, 1, &
a, classname.c_str());
255 template <
typename T>
257 error(
"wrap internal error: attempted unwrap of invalid type");
264 template <
typename T>
267 mxArray*
a = mxDuplicateArray(
array);
271 mexCallMATLAB(1, &a_int32, 1, &
a,
"int32");
274 int32_T*
value = (int32_T*)mxGetData(a_int32);
276 return static_cast<T>(*value);
285 if (
data==
NULL)
error(
"unwrap<string>: not a character array");
292 template <
typename T>
294 switch (mxGetClassID(
array)) {
301 return (
T) mxGetScalar(
array);
309 return myGetScalar<bool>(
array);
316 return myGetScalar<char>(
array);
323 return myGetScalar<unsigned char>(
array);
330 return myGetScalar<int>(
array);
337 return myGetScalar<size_t>(
array);
344 return myGetScalar<double>(
array);
351 if (mxIsDouble(
array)==
false ||
n!=1)
error(
"unwrap<vector>: not a vector");
353 mexPrintf(
"unwrap< gtsam::Vector > called with %dx%d argument\n",
m,
n);
355 double*
data = (
double*)mxGetData(
array);
368 if (mxIsDouble(
array)==
false ||
n!=1)
error(
"unwrap<vector>: not a vector");
370 mexPrintf(
"unwrap< gtsam::Vector > called with %dx%d argument\n",
m,
n);
372 double*
data = (
double*)mxGetData(
array);
385 if (mxIsDouble(
array)==
false ||
n!=1)
error(
"unwrap<vector>: not a vector");
387 mexPrintf(
"unwrap< gtsam::Vector > called with %dx%d argument\n",
m,
n);
389 double*
data = (
double*)mxGetData(
array);
402 if (mxIsDouble(
array)==
false)
error(
"unwrap<matrix>: not a matrix");
405 mexPrintf(
"unwrap< gtsam::Matrix > called with %dx%d argument\n",
m,
n);
407 double*
data = (
double*)mxGetData(
array);
430 mxArray*
create_object(
const std::string& classname,
void *pointer,
bool isVirtual,
const char *rttiName) {
435 input[0] = mxCreateNumericMatrix(1, 1, mxUINT64_CLASS, mxREAL);
439 *
reinterpret_cast<void**
>(mxGetData(input[1])) = pointer;
441 const char *derivedClassName;
443 const mxArray *rttiRegistry = mexGetVariablePtr(
"global",
"gtsamwrap_rttiRegistry");
446 "gtsam wrap: RTTI registry is missing - it could have been cleared from the workspace."
447 " You can issue 'clear all' to completely clear the workspace, and next time a wrapped object is"
448 " created the RTTI registry will be recreated.");
449 const mxArray *derivedNameMx = mxGetField(rttiRegistry, 0, rttiName);
452 "gtsam wrap: The derived class type " +
string(rttiName) +
" was not found in the RTTI registry. "
453 "Try calling 'clear all' twice consecutively - we have seen things not get unloaded properly the "
454 "first time. If this does not work, this may indicate an inconsistency in your wrap interface file. "
455 "The most likely cause for this is that a base class was marked virtual in the wrap interface "
456 "definition header file for gtsam or for your module, but a derived type was returned by a C++ "
457 "function and that derived type was not marked virtual (or was not specified in the wrap interface "
458 "definition header at all).").
c_str());
459 size_t strLen = mxGetN(derivedNameMx);
460 char *buf =
new char[strLen+1];
461 if(mxGetString(derivedNameMx, buf, strLen+1))
462 mexErrMsgTxt(
"gtsam wrap: Internal error reading RTTI table, try 'clear all' to clear your workspace and reinitialize the toolbox.");
463 derivedClassName = buf;
464 input[2] = mxCreateString(
"void");
467 derivedClassName = classname.c_str();
470 mexCallMATLAB(1,&
result, nargin, input, derivedClassName);
472 mxDestroyArray(input[0]);
473 mxDestroyArray(input[1]);
475 mxDestroyArray(input[2]);
476 delete[] derivedClassName;
486 template <
typename Class>
487 mxArray*
wrap_shared_ptr(std::shared_ptr< Class > shared_ptr,
const std::string& matlabName,
bool isVirtual) {
491 std::shared_ptr<void> void_ptr(shared_ptr);
494 std::shared_ptr<Class> *heapPtr =
new std::shared_ptr<Class>(shared_ptr);
500 template <
typename Class>
503 mxArray* mxh = mxGetProperty(obj,0, propertyName.c_str());
505 || mxGetM(mxh) != 1 || mxGetN(mxh) != 1)
error(
506 "Parameter is not an Shared type.");
508 std::shared_ptr<Class>* spp = *
reinterpret_cast<std::shared_ptr<Class>**
> (mxGetData(mxh));
512 template <
typename Class>
513 Class*
unwrap_ptr(
const mxArray* obj,
const string& propertyName) {
515 mxArray* mxh = mxGetProperty(obj,0, propertyName.c_str());
516 Class*
x =
reinterpret_cast<Class*
> (mxGetData(mxh));
mxArray * wrap< string >(const string &value)
Annotation for function names.
Class * unwrap_ptr(const mxArray *obj, const string &propertyName)
mxArray * wrap_Vector(const gtsam::Vector &v)
mxArray * wrap< unsigned char >(const unsigned char &value)
std::shared_ptr< Class > unwrap_shared_ptr(const mxArray *obj, const string &propertyName)
typedef and functions to augment Eigen's VectorXd
unsigned char unwrap< unsigned char >(const mxArray *array)
mxArray * wrap< double >(const double &value)
virtual int overflow(int c=EOF)
typedef and functions to augment Eigen's MatrixXd
T unwrap_enum(const mxArray *array)
Unwrap from matlab array to C++ enum type.
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
mxArray * wrap(const Class &value)
void checkScalar(const mxArray *array, const char *str)
mxArray * wrap< bool >(const bool &value)
T myGetScalar(const mxArray *array)
T unwrap(const mxArray *array)
Eigen::Triplet< double > T
gtsam::Point2 unwrap< gtsam::Point2 >(const mxArray *array)
gtsam::Matrix unwrap< gtsam::Matrix >(const mxArray *array)
gtsam::Vector unwrap< gtsam::Vector >(const mxArray *array)
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
#define mxUINT32OR64_CLASS
mxArray * wrap< char >(const char &value)
void print(const Matrix &A, const string &s, ostream &stream)
void checkArguments(const string &name, int nargout, int nargin, int expected)
size_t unwrap< size_t >(const mxArray *array)
int unwrap< int >(const mxArray *array)
mxArray * scalar(mxClassID classid)
virtual std::streamsize xsputn(const char *s, std::streamsize n)
char unwrap< char >(const mxArray *array)
mxArray * wrap_shared_ptr(std::shared_ptr< Class > shared_ptr, const std::string &matlabName, bool isVirtual)
mxArray * wrap< size_t >(const size_t &value)
mxArray * wrap_enum(const T x, const std::string &classname)
Wrap the C++ enum to Matlab mxArray.
void error(const char *str)
static const std::uint64_t ptr_constructor_key
bool unwrap< bool >(const mxArray *array)
mxArray * wrap_Matrix(const gtsam::Matrix &A)
const char * c_str(Args &&...args)
Array< int, Dynamic, 1 > v
string unwrap< string >(const mxArray *array)
unsigned __int64 uint64_t
mxArray * create_object(const std::string &classname, void *pointer, bool isVirtual, const char *rttiName)
double unwrap< double >(const mxArray *array)
mxArray * wrap< int >(const int &value)
gtsam::Point3 unwrap< gtsam::Point3 >(const mxArray *array)
gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:03:01