Subversion Repositories seema-scanner

Rev

Rev 3 | Rev 74 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3 Rev 28
1
#include "mex.h"
1
#include "mex.h"
2
#include "class_handle.hpp"
2
#include "class_handle.hpp"
3
 
3
 
4
// Output printf statements in the Matlab workspace
4
// Output printf statements in the Matlab workspace
5
#define printf mexPrintf
5
#define printf mexPrintf
6
 
6
 
7
// The class that we are interfacing to
7
// The class that we are interfacing to
8
#include "Camera.h"
8
#include "Camera.h"
9
 
9
 
10
using namespace std;
10
using namespace std;
11
 
11
 
12
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
12
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
-
 
13
    
-
 
14
    mexPrintf("nlhs: %d , nrhs: %d\n", nlhs, nrhs);
13
{	
15
    
14
    // Get the command string
16
    // Get the command string
15
    char cmd[64];
17
    char cmd[64];
16
	if (nrhs < 1 || mxGetString(prhs[0], cmd, sizeof(cmd)))
18
	if (nrhs < 1 || mxGetString(prhs[0], cmd, sizeof(cmd)))
17
		mexErrMsgTxt("First input should be a command string less than 64 characters long.");
19
		mexErrMsgTxt("First input should be a command string less than 64 characters long.");
18
    
20
    
19
    // Static methods
21
    // Static methods
20
    // InterfaceCameraList
22
    // InterfaceCameraList
21
    if (!strcmp("GetInterfaceCameraList", cmd)) {
23
    if (!strcmp("GetInterfaceCameraList", cmd)) {
22
        // Call the method
24
        // Call the method
23
        vector< vector<CameraInfo> > interfaceCameraList;
25
        vector< vector<CameraInfo> > interfaceCameraList;
24
        interfaceCameraList = Camera::GetInterfaceCameraList();
26
        interfaceCameraList = Camera::GetInterfaceCameraList();
25
        unsigned int nCameras = 0;
27
        unsigned int nCameras = 0;
26
        for(unsigned int i=0; i<interfaceCameraList.size(); i++)
28
        for(unsigned int i=0; i<interfaceCameraList.size(); i++)
27
            nCameras += interfaceCameraList[i].size();
29
            nCameras += interfaceCameraList[i].size();
28
        const char* fieldNames[] = {"interfaceNum", "cameraNum", "vendor","model"};
30
        const char* fieldNames[] = {"interfaceNum", "cameraNum", "vendor","model"};
29
        plhs[0] = mxCreateStructMatrix(1, nCameras, 4, fieldNames);
31
        plhs[0] = mxCreateStructMatrix(1, nCameras, 4, fieldNames);
30
        unsigned int iCamera = 0;
32
        unsigned int iCamera = 0;
31
        for (unsigned int i=0; i<interfaceCameraList.size(); i++) {
33
        for (unsigned int i=0; i<interfaceCameraList.size(); i++) {
32
            for (unsigned int j=0; j<interfaceCameraList[i].size(); j++) {
34
            for (unsigned int j=0; j<interfaceCameraList[i].size(); j++) {
33
                mxSetFieldByNumber(plhs[0], iCamera, 0, mxCreateDoubleScalar(i));
35
                mxSetFieldByNumber(plhs[0], iCamera, 0, mxCreateDoubleScalar(i));
34
                mxSetFieldByNumber(plhs[0], iCamera, 1, mxCreateDoubleScalar(j));
36
                mxSetFieldByNumber(plhs[0], iCamera, 1, mxCreateDoubleScalar(j));
35
                mxSetFieldByNumber(plhs[0], iCamera, 2, mxCreateString(interfaceCameraList[i][j].vendor.c_str()));
37
                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()));
38
                mxSetFieldByNumber(plhs[0], iCamera, 3, mxCreateString(interfaceCameraList[i][j].model.c_str()));
37
                iCamera++;
39
                iCamera++;
38
            }
40
            }
39
        }
41
        }
40
        return;
42
        return;
41
    }
43
    }
42
    
44
    
43
    // New Camera
45
    // New Camera
44
    if (!strcmp("NewCamera", cmd)) {
46
    if (!strcmp("NewCamera", cmd)) {
45
        // Check parameters
47
        // Check parameters
46
        if (nlhs != 1)
48
        if (nlhs != 1)
47
            mexErrMsgTxt("newCamera: One output expected.");
49
            mexErrMsgTxt("newCamera: One output expected.");
48
        if (nrhs < 3)
50
        if (nrhs < 3)
49
            mexErrMsgTxt("newCamera: Expected interface and screen number argument.");
51
            mexErrMsgTxt("newCamera: Expected interface and camera number argument.");
50
        unsigned int interfaceNum = (unsigned int)mxGetScalar(prhs[1]);
52
        unsigned int interfaceNum = (unsigned int)mxGetScalar(prhs[1]);
51
        unsigned int camNum = (unsigned int)mxGetScalar(prhs[2]);
53
        unsigned int camNum = (unsigned int)mxGetScalar(prhs[2]);
52
        // Return a handle to a new C++ instance
54
        // Return a handle to a new C++ instance
53
        plhs[0] = convertPtr2Mat<Camera>(Camera::NewCamera(interfaceNum, camNum));
55
        plhs[0] = convertPtr2Mat<Camera>(Camera::NewCamera(interfaceNum, camNum, triggerModeSoftware));
54
        return;
56
        return;
55
    }
57
    }
56
    
58
    
57
    // Class methods
59
    // Class methods
58
    // Check if there is a second input, which should be the class instance handle
60
    // Check if there is a second input, which should be the class instance handle
59
    if (nrhs < 2)
61
    if (nrhs < 2)
60
		mexErrMsgTxt("Second input should be a class instance handle.");
62
		mexErrMsgTxt("Second input should be a class instance handle.");
61
    
63
    
62
    // Delete
64
    // Delete
63
    if (!strcmp("delete", cmd)) {
65
    if (!strcmp("delete", cmd)) {
64
        // Destroy the C++ object
66
        // Destroy the C++ object
65
        destroyObject<Camera>(prhs[1]);
67
        destroyObject<Camera>(prhs[1]);
66
        // Warn if other commands were ignored
68
        // Warn if other commands were ignored
67
        if (nlhs != 0 || nrhs != 2)
69
        if (nlhs != 0 || nrhs != 2)
68
            mexWarnMsgTxt("Delete: Unexpected arguments ignored.");
70
            mexWarnMsgTxt("Delete: Unexpected arguments ignored.");
69
        return;
71
        return;
70
    }
72
    }
71
    
73
    
72
    // Get the class instance pointer from the second input
74
    // Get the class instance pointer from the second input
73
    Camera *Camera_instance = convertMat2Ptr<Camera>(prhs[1]);
75
    Camera *Camera_instance = convertMat2Ptr<Camera>(prhs[1]);
74
    
76
    
-
 
77
	// Call the various class methods
-
 
78
    // startCapture
-
 
79
    if (!strcmp("startCapture", cmd)) {
-
 
80
        // Check parameters
-
 
81
        if (nlhs > 0 || nrhs > 2)
-
 
82
            mexErrMsgTxt("startCapture: Unexpected arguments.");
-
 
83
        // Call the method
-
 
84
        Camera_instance->startCapture();
-
 
85
        return;
-
 
86
    }
-
 
87
    
-
 
88
	// Call the various class methods
-
 
89
    // stopCapture
-
 
90
    if (!strcmp("stopCapture", cmd)) {
-
 
91
        // Check parameters
-
 
92
        if (nlhs > 0 || nrhs > 2)
-
 
93
            mexErrMsgTxt("stopCapture: Unexpected arguments.");
-
 
94
        // Call the method
-
 
95
        Camera_instance->stopCapture();
-
 
96
        return;
-
 
97
    }
-
 
98
    
-
 
99
	// trigger
-
 
100
    if (!strcmp("trigger", cmd)) {
-
 
101
        // Check parameters
-
 
102
        if (nlhs > 0 || nrhs > 2)
-
 
103
            mexErrMsgTxt("trigger: Unexpected arguments.");
-
 
104
        // Call the method
-
 
105
        Camera_instance->trigger();
-
 
106
        return;
-
 
107
    }
-
 
108
    
75
    // Call the various class methods
109
    // Call the various class methods
76
    // getSingleFrame
110
    // getFrame
77
    if (!strcmp("getSingleFrame", cmd)) {
111
    if (!strcmp("getFrame", cmd)) {
78
        // Check parameters
112
        // Check parameters
79
        if (nlhs < 1 || nrhs > 2)
113
        if (nlhs < 1 || nrhs > 2)
80
            mexErrMsgTxt("getSingleFrame: Unexpected arguments.");
114
            mexErrMsgTxt("getFrame: Unexpected arguments.");
81
        // Call the method
115
        // Call the method
82
        CameraFrame frame = Camera_instance->getSingleFrame();
116
        CameraFrame frame = Camera_instance->getFrame();
-
 
117
        // receive frame data in permuted dimensional order
-
 
118
        int dims[] = {frame.channels, frame.width, frame.height};
83
        plhs[0] = mxCreateNumericMatrix(frame.width, frame.height, mxUINT8_CLASS, mxREAL);
119
        plhs[0] = mxCreateNumericArray(3, dims, mxUINT8_CLASS, mxREAL);
84
        memcpy(mxGetData(plhs[0]), frame.memory, frame.height*frame.width);
120
        memcpy(mxGetData(plhs[0]), frame.memory, frame.height*frame.width*frame.channels);
85
        //Camera_instance->unlockFrame();
-
 
86
        return;
121
        return;
87
    }
122
    }
88
//    // Test
-
 
89
//    if (!strcmp("test", cmd)) {
-
 
90
//        // Check parameters
-
 
91
//        if (nlhs < 0 || nrhs < 2)
-
 
92
//            mexErrMsgTxt("Test: Unexpected arguments.");
-
 
93
//        // Call the method
-
 
94
//        PatternProjector_instance->test();
-
 
95
//        return;
-
 
96
//    }
-
 
97
    
123
    
98
    // Got here, so command not recognized
124
    // Got here, so command not recognized
99
    mexErrMsgTxt("Command not recognized.");
125
    mexErrMsgTxt("Command not recognized.");
100
}
126
}
101
 
127