Subversion Repositories seema-scanner

Rev

Rev 28 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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