Subversion Repositories seema-scanner

Rev

Rev 28 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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