Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
032a8bf6
Commit
032a8bf6
authored
Aug 29, 2016
by
Davis King
Browse files
Options
Browse Files
Download
Plain Diff
merged
parents
d8a23c87
7ca1fb16
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
0 deletions
+73
-0
CMakeLists.txt
dlib/matlab/CMakeLists.txt
+1
-0
mex_example_class.cpp
dlib/matlab/mex_example_class.cpp
+72
-0
mex_wrapper.cpp
dlib/matlab/mex_wrapper.cpp
+0
-0
No files found.
dlib/matlab/CMakeLists.txt
View file @
032a8bf6
...
...
@@ -13,4 +13,5 @@ include(../cmake)
add_mex_function
(
example_mex_function dlib
)
add_mex_function
(
example_mex_callback 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 @
032a8bf6
// 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 @
032a8bf6
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