Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
7ca1fb16
"git@developer.sourcefind.cn:OpenDAS/dgl.git" did not exist on "b740c3f0ba2e89f2bdb6fb26393ac004c2f1ef48"
Commit
7ca1fb16
authored
Aug 29, 2016
by
Davis King
Browse files
Added support for binding classes to MATLAB.
parent
091d441c
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
548 additions
and
60 deletions
+548
-60
dlib/matlab/CMakeLists.txt
dlib/matlab/CMakeLists.txt
+1
-0
dlib/matlab/mex_example_class.cpp
dlib/matlab/mex_example_class.cpp
+72
-0
dlib/matlab/mex_wrapper.cpp
dlib/matlab/mex_wrapper.cpp
+475
-60
No files found.
dlib/matlab/CMakeLists.txt
View file @
7ca1fb16
...
@@ -13,4 +13,5 @@ include(../cmake)
...
@@ -13,4 +13,5 @@ include(../cmake)
add_mex_function
(
example_mex_function dlib
)
add_mex_function
(
example_mex_function dlib
)
add_mex_function
(
example_mex_callback dlib
)
add_mex_function
(
example_mex_callback dlib
)
add_mex_function
(
example_mex_struct dlib
)
add_mex_function
(
example_mex_struct dlib
)
add_mex_function
(
mex_example_class dlib
)
dlib/matlab/mex_example_class.cpp
0 → 100644
View file @
7ca1fb16
// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
/*
This mex file will create a MATLAB function called mex_example_class. If you call it
with no arguments it will output the MATLAB .m code to create a MATLAB wrapper class.
Paste that code into a .m file. Then you will be able to work with this C++ class
directly in MATLAB.
*/
#include <iostream>
#include <dlib/matrix.h>
using
namespace
std
;
using
namespace
dlib
;
class
example_class
{
public:
// The class must have a default constructor. It's also the only kind of constructor
// you can call from MATLAB.
example_class
()
{
xx
.
set_size
(
3
,
2
);
xx
=
1
;
}
// The rest of the member functions that you want to bind have to return void and
// generally have the same syntax limitations as regular mex funcitons.
void
do_stuff
(
const
matrix_colmajor
&
x
)
{
cout
<<
"in do_stuff"
<<
endl
;
cout
<<
x
<<
endl
;
xx
=
x
;
}
void
do_other_stuff
(
int
x
)
{
cout
<<
"in do_other_stuff"
<<
endl
;
cout
<<
"x: "
<<
x
<<
endl
;
}
void
print_state
()
{
cout
<<
xx
<<
endl
;
}
// saveobj() and load_obj() are special functions. If you provide these then you will
// be able to save() and load() your objects using MATLAB's built in object
// serialization.
void
saveobj
(
matrix_colmajor
&
state
)
{
// save this object's state to state.
state
=
xx
;
}
void
load_obj
(
const
matrix_colmajor
&
state
)
{
xx
=
state
;
}
private:
matrix_colmajor
xx
;
};
// Just tell the mex wrapper the name of your class and list the methods you want to bind.
#define MEX_CLASS_NAME example_class
#define MEX_CLASS_METHODS do_stuff, do_other_stuff, print_state, saveobj, load_obj
#include "mex_wrapper.cpp"
dlib/matlab/mex_wrapper.cpp
View file @
7ca1fb16
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment