Subversion Repositories seema-scanner

Rev

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