1 |
jakw |
1 |
#include "mex.h"
|
|
|
2 |
#include "class_handle.hpp"
|
|
|
3 |
|
|
|
4 |
// Output printf statements in the Matlab workspace
|
|
|
5 |
#define printf mexPrintf
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
// The class that we are interfacing to
|
3 |
jakw |
9 |
#include "ProjectorOpenGL.h"
|
|
|
10 |
#include "OpenGLContext.h"
|
1 |
jakw |
11 |
|
|
|
12 |
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
|
|
13 |
{
|
|
|
14 |
// Get the command string
|
|
|
15 |
char cmd[64];
|
|
|
16 |
if (nrhs < 1 || mxGetString(prhs[0], cmd, sizeof(cmd)))
|
|
|
17 |
mexErrMsgTxt("First input should be a command string less than 64 characters long.");
|
|
|
18 |
|
|
|
19 |
// Static methods
|
71 |
jakw |
20 |
// GetScreenInfo
|
1 |
jakw |
21 |
if (!strcmp("GetScreenInfo", cmd)) {
|
|
|
22 |
// Call the method
|
|
|
23 |
std::vector<ScreenInfo> screenInfo;
|
3 |
jakw |
24 |
screenInfo = OpenGLContext::GetScreenInfo();
|
71 |
jakw |
25 |
mexPrintf("%i", screenInfo.size());
|
1 |
jakw |
26 |
const char* fieldNames[] = {"screenNum","resX","resY"};
|
|
|
27 |
plhs[0] = mxCreateStructMatrix(1, screenInfo.size(), 3, fieldNames);
|
|
|
28 |
for (unsigned int i=0; i<screenInfo.size(); i++) {
|
|
|
29 |
mxSetFieldByNumber(plhs[0], i, 0, mxCreateDoubleScalar(i));
|
|
|
30 |
mxSetFieldByNumber(plhs[0], i, 1, mxCreateDoubleScalar(screenInfo[i].resX));
|
|
|
31 |
mxSetFieldByNumber(plhs[0], i, 2, mxCreateDoubleScalar(screenInfo[i].resY));
|
|
|
32 |
}
|
|
|
33 |
return;
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
// New
|
|
|
37 |
if (!strcmp("new", cmd)) {
|
|
|
38 |
// Check parameters
|
|
|
39 |
if (nlhs != 1)
|
|
|
40 |
mexErrMsgTxt("New: One output expected.");
|
|
|
41 |
if (nrhs < 2)
|
|
|
42 |
mexErrMsgTxt("New: Expected screen number argument.");
|
|
|
43 |
unsigned int screenNum = (unsigned int)mxGetScalar(prhs[1]);
|
|
|
44 |
// Return a handle to a new C++ instance
|
3 |
jakw |
45 |
plhs[0] = convertPtr2Mat<ProjectorOpenGL>(new ProjectorOpenGL(screenNum));
|
1 |
jakw |
46 |
return;
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
// Check if there is a second input, which should be the class instance handle
|
|
|
50 |
if (nrhs < 2)
|
|
|
51 |
mexErrMsgTxt("Second input should be a class instance handle.");
|
|
|
52 |
|
|
|
53 |
// Delete
|
|
|
54 |
if (!strcmp("delete", cmd)) {
|
|
|
55 |
// Destroy the C++ object
|
28 |
jakw |
56 |
destroyObject<ProjectorOpenGL>(prhs[1]);
|
1 |
jakw |
57 |
// Warn if other commands were ignored
|
|
|
58 |
if (nlhs != 0 || nrhs != 2)
|
|
|
59 |
mexWarnMsgTxt("Delete: Unexpected arguments ignored.");
|
|
|
60 |
return;
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
// Get the class instance pointer from the second input
|
28 |
jakw |
64 |
ProjectorOpenGL *Projector_instance = convertMat2Ptr<ProjectorOpenGL>(prhs[1]);
|
1 |
jakw |
65 |
|
|
|
66 |
// Call the various class methods
|
|
|
67 |
// DisplayTexture
|
|
|
68 |
if (!strcmp("displayTexture", cmd)) {
|
|
|
69 |
// Check parameters
|
|
|
70 |
if (nlhs < 0 || nrhs < 5)
|
|
|
71 |
mexErrMsgTxt("DisplayTexture: Unexpected arguments.");
|
|
|
72 |
// Call the method
|
|
|
73 |
unsigned char *tex = (unsigned char*)mxGetData(prhs[2]);
|
|
|
74 |
unsigned int width = (unsigned int)mxGetScalar(prhs[3]);
|
|
|
75 |
unsigned int height = (unsigned int)mxGetScalar(prhs[4]);
|
|
|
76 |
Projector_instance->displayTexture(tex, width, height);
|
|
|
77 |
return;
|
|
|
78 |
}
|
|
|
79 |
// DisplayWhite
|
|
|
80 |
if (!strcmp("displayWhite", cmd)) {
|
|
|
81 |
// Check parameters
|
|
|
82 |
if (nlhs < 0 || nrhs < 1)
|
|
|
83 |
mexErrMsgTxt("Test: Unexpected arguments.");
|
|
|
84 |
// Call the method
|
|
|
85 |
Projector_instance->displayWhite();
|
|
|
86 |
return;
|
|
|
87 |
}
|
|
|
88 |
// DisplayBlack
|
|
|
89 |
if (!strcmp("displayBlack", cmd)) {
|
|
|
90 |
// Check parameters
|
|
|
91 |
if (nlhs < 0 || nrhs < 1)
|
|
|
92 |
mexErrMsgTxt("Test: Unexpected arguments.");
|
|
|
93 |
// Call the method
|
|
|
94 |
Projector_instance->displayBlack();
|
|
|
95 |
return;
|
|
|
96 |
}
|
|
|
97 |
// Got here, so command not recognized
|
|
|
98 |
mexErrMsgTxt("Command not recognized.");
|
|
|
99 |
}
|