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 |
// The class that we are interfacing to
|
|
|
8 |
#include "Camera.h"
|
|
|
9 |
|
|
|
10 |
using namespace std;
|
|
|
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
|
|
|
20 |
// InterfaceCameraList
|
|
|
21 |
if (!strcmp("GetInterfaceCameraList", cmd)) {
|
|
|
22 |
// Call the method
|
|
|
23 |
vector< vector<CameraInfo> > interfaceCameraList;
|
|
|
24 |
interfaceCameraList = Camera::GetInterfaceCameraList();
|
|
|
25 |
unsigned int nCameras = 0;
|
|
|
26 |
for(unsigned int i=0; i<interfaceCameraList.size(); i++)
|
|
|
27 |
nCameras += interfaceCameraList[i].size();
|
|
|
28 |
const char* fieldNames[] = {"interfaceNum", "cameraNum", "vendor","model"};
|
|
|
29 |
plhs[0] = mxCreateStructMatrix(1, nCameras, 4, fieldNames);
|
|
|
30 |
unsigned int iCamera = 0;
|
|
|
31 |
for (unsigned int i=0; i<interfaceCameraList.size(); i++) {
|
|
|
32 |
for (unsigned int j=0; j<interfaceCameraList[i].size(); j++) {
|
|
|
33 |
mxSetFieldByNumber(plhs[0], iCamera, 0, mxCreateDoubleScalar(i));
|
|
|
34 |
mxSetFieldByNumber(plhs[0], iCamera, 1, mxCreateDoubleScalar(j));
|
|
|
35 |
mxSetFieldByNumber(plhs[0], iCamera, 2, mxCreateString(interfaceCameraList[i][j].vendor.c_str()));
|
|
|
36 |
mxSetFieldByNumber(plhs[0], iCamera, 3, mxCreateString(interfaceCameraList[i][j].model.c_str()));
|
|
|
37 |
iCamera++;
|
|
|
38 |
}
|
|
|
39 |
}
|
|
|
40 |
return;
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
// New Camera
|
|
|
44 |
if (!strcmp("NewCamera", cmd)) {
|
|
|
45 |
// Check parameters
|
|
|
46 |
if (nlhs != 1)
|
|
|
47 |
mexErrMsgTxt("newCamera: One output expected.");
|
|
|
48 |
if (nrhs < 3)
|
|
|
49 |
mexErrMsgTxt("newCamera: Expected interface and screen number argument.");
|
|
|
50 |
unsigned int interfaceNum = (unsigned int)mxGetScalar(prhs[1]);
|
|
|
51 |
unsigned int camNum = (unsigned int)mxGetScalar(prhs[2]);
|
|
|
52 |
// Return a handle to a new C++ instance
|
|
|
53 |
plhs[0] = convertPtr2Mat<Camera>(Camera::NewCamera(interfaceNum, camNum));
|
|
|
54 |
return;
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
// Class methods
|
|
|
58 |
// Check if there is a second input, which should be the class instance handle
|
|
|
59 |
if (nrhs < 2)
|
|
|
60 |
mexErrMsgTxt("Second input should be a class instance handle.");
|
|
|
61 |
|
|
|
62 |
// Delete
|
|
|
63 |
if (!strcmp("delete", cmd)) {
|
|
|
64 |
// Destroy the C++ object
|
|
|
65 |
destroyObject<Camera>(prhs[1]);
|
|
|
66 |
// Warn if other commands were ignored
|
|
|
67 |
if (nlhs != 0 || nrhs != 2)
|
|
|
68 |
mexWarnMsgTxt("Delete: Unexpected arguments ignored.");
|
|
|
69 |
return;
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
// Get the class instance pointer from the second input
|
|
|
73 |
Camera *Camera_instance = convertMat2Ptr<Camera>(prhs[1]);
|
|
|
74 |
|
|
|
75 |
// Call the various class methods
|
|
|
76 |
// getSingleFrame
|
|
|
77 |
if (!strcmp("getSingleFrame", cmd)) {
|
|
|
78 |
// Check parameters
|
|
|
79 |
if (nlhs < 1 || nrhs > 2)
|
|
|
80 |
mexErrMsgTxt("getSingleFrame: Unexpected arguments.");
|
|
|
81 |
// Call the method
|
|
|
82 |
CameraFrame frame = Camera_instance->getSingleFrame();
|
|
|
83 |
plhs[0] = mxCreateNumericMatrix(frame.width, frame.height, mxUINT8_CLASS, 0);
|
|
|
84 |
memcpy(mxGetData(plhs[0]), frame.memory, frame.height*frame.width);
|
|
|
85 |
//Camera_instance->unlockFrame();
|
|
|
86 |
return;
|
|
|
87 |
}
|
|
|
88 |
// // SetGamma
|
|
|
89 |
// if (!strcmp("SetGamma", cmd)) {
|
|
|
90 |
// // Check parameters
|
|
|
91 |
// if (nlhs < 0 || nrhs < 2)
|
|
|
92 |
// mexErrMsgTxt("SetGamma: Unexpected arguments.");
|
|
|
93 |
// // Call the method
|
|
|
94 |
// float gamma = (float)mxGetScalar(prhs[2]);
|
|
|
95 |
// nProjector_instance->SetGamma(gamma);
|
|
|
96 |
// return;
|
|
|
97 |
// }
|
|
|
98 |
// // Test
|
|
|
99 |
// if (!strcmp("test", cmd)) {
|
|
|
100 |
// // Check parameters
|
|
|
101 |
// if (nlhs < 0 || nrhs < 2)
|
|
|
102 |
// mexErrMsgTxt("Test: Unexpected arguments.");
|
|
|
103 |
// // Call the method
|
|
|
104 |
// PatternProjector_instance->test();
|
|
|
105 |
// return;
|
|
|
106 |
// }
|
|
|
107 |
|
|
|
108 |
// Got here, so command not recognized
|
|
|
109 |
mexErrMsgTxt("Command not recognized.");
|
|
|
110 |
}
|