33 if (node.
type() == FileNode::SEQ) {
34 size_t n = node.
size();
36 for (
size_t i=0; i<n; ++i) {
38 switch (elem.
type()) {
40 v[i] =
MxArray(static_cast<int>(elem));
43 v[i] =
MxArray(static_cast<double>(elem));
46 v[i] =
MxArray(static_cast<string>(elem));
49 MxArray y(static_cast<mxArray*>(NULL));
55 if (
isa(elem,
"opencv-matrix")) {
60 else if (
isa(elem,
"opencv-nd-matrix")) {
65 else if (
isa(elem,
"opencv-sparse-matrix")) {
81 else if (node.
type() == FileNode::MAP) {
85 string name(elem.
name());
92 switch (elem.
type()) {
94 x.
set(name, static_cast<int>(elem));
97 x.
set(name, static_cast<double>(elem));
100 x.
set(name, static_cast<string>(elem));
102 case FileNode::SEQ: {
103 MxArray y(static_cast<mxArray*>(NULL));
108 case FileNode::MAP: {
109 if (
isa(elem,
"opencv-matrix")) {
114 else if (
isa(elem,
"opencv-nd-matrix")) {
119 else if (
isa(elem,
"opencv-sparse-matrix")) {
152 if (n > 1) fs <<
"[";
154 if (!root) fs <<
"{";
159 if (!root) fs <<
"}";
161 if (n > 1) fs <<
"]";
176 if (x.
numel() == 1) {
212 string filename(rhs[0].toString());
216 ((nlhs > 1) ? FileStorage::MEMORY : 0));
232 ((nlhs > 0) ? FileStorage::MEMORY : 0));
235 if (nrhs==2 && rhs[1].isStruct() && rhs[1].numel()==1)
237 write(fs, rhs[1],
true);
240 string nodeName(FileStorage::getDefaultObjectName(filename));
246 for (
int i=0; i<nrhs-1; ++i)
247 cell.
set(i, rhs[i+1].clone());
248 s.
set(nodeName, cell);
void destroy()
Deallocate memory occupied by mxArray.
int toInt() const
Convert MxArray to int.
Identifies a numeric mxArray whose data is stored as the type specified in the MATLAB Primitive Types...
mwSize numel() const
Number of elements in an array.
T at(mwIndex index) const
Template for numeric array element accessor.
std::string toString() const
Convert MxArray to std::string.
FileNodeIterator end() const
FileNode root(int streamidx=0) const
virtual bool isOpened() const
Undetermined class. You cannot specify this category for an mxArray; however, if mxGetClassID cannot ...
Identifies a function handle mxArray.
struct mxArray_tag mxArray
Forward declaration for mxArray.
void set(mwIndex index, const T &value)
Template for numeric array element write accessor.
Identifies a numeric mxArray whose data is stored as the type specified in the MATLAB Primitive Types...
std::vector< std::string > fieldnames() const
Get field names of a struct array.
virtual String releaseAndGetString()
void read(const FileNode &fn, optflow::GPCTree::Node &node, optflow::GPCTree::Node)
Identifies a string mxArray, an mxArray whose data is represented as mxChar.
LIBMWMEX_API_EXTERN_C void mexErrMsgIdAndTxt(const char *identifier, const char *err_msg,...)
Issue formatted error message with corresponding error identifier and return to MATLAB prompt...
float toFloat() const
Convert MxArray to float.
bool isSparse() const
Determine whether input is sparse array.
mxArray object wrapper for data conversion and manipulation.
void nargchk(bool cond)
Alias for input/output arguments number check.
cv::SparseMat toSparseMat(int depth=CV_USRTYPE1) const
Convert double sparse MxArray to 2D single-channel cv::SparseMat.
static MxArray Struct(const char **fields=NULL, int nfields=0, mwSize m=1, mwSize n=1)
Create a new struct array.
static MxArray Cell(mwSize m=1, mwSize n=1)
Create a new cell array.
mxClassID
Enumeration corresponding to all the valid mxArray types.
std::vector< T > toVector() const
Convert MxArray to std::vector<T> of primitive types.
Global constant definitions.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Main entry called from Matlab.
void write(FileStorage &fs, const String &name, const optflow::GPCTree::Node &node)
Buffer clone(Target target=ARRAY_BUFFER, bool autoRelease=false) const
bool isa(const FileNode &node, const string &type_name)
Check if the node is of a user-defined type.
cv::Mat toMat(int depth=CV_USRTYPE1, bool transpose=true) const
Convert MxArray to cv::Mat.
Identifies a structure mxArray.
double toDouble() const
Convert MxArray to double.
Identifies a cell mxArray.
mxClassID classID() const
Class ID of mxArray.
FileNodeIterator begin() const