-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathProjectMesh2ImageImpl.cpp
More file actions
executable file
·120 lines (87 loc) · 3.35 KB
/
ProjectMesh2ImageImpl.cpp
File metadata and controls
executable file
·120 lines (87 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*******************************************************************************
ProjectMesh2ImageImpl.cpp: implementation of the offscreen projection of a mesh
onto an image.
example:
LabeledImageA = ProjectMesh2ImageImpl(FaceM, VertexM, CamParamSA, channelModFactor, ...
ScreenSizeV, zoomFactor, ZNearFarV)
*******************************************************************************/
#include <mex.h>
#include <math.h>
#include "OffscreenGL.h"
#include "OffscreenCommon.h"
void getLabeledImages(
// input
double *FM, int fNum, double *VM, int vNum, const mxArray *CamParamSA, double *ScreenSizeV, int zoomFactor,
unsigned int channelModFactor, double *ZNearFarV,
// output
mxArray *LabeledImageA
)
{
int imageNum, i;
GLuint batchList;
mxArray *currentCamParamS;
GLubyte *imageBuffer;
int bufferDims[3];
unsigned int *LabeledImage;
imageBuffer = (GLubyte *) mxMalloc(ScreenSizeV[0] * ScreenSizeV[1] * COLOR_MODULATE_CHANNEL * zoomFactor * zoomFactor);
imageNum = mxGetM(CamParamSA);
batchList = createDisplayList(FM, fNum, VM, vNum, channelModFactor);
printf("Facet Number: %d, Vertex Number: %d\nProjecting images: \n", fNum, vNum);
for (i = 0; i < imageNum; i++) {
printf(" %d ", i);
if (i % 10 == 9) {
printf("\n");
}
currentCamParamS = mxGetCell(CamParamSA, i);
mxArray* imSizeArray = mxGetField(currentCamParamS, 0, "imSizeV");
double* imSizeV;
if (imSizeArray != NULL) {
imSizeV = mxGetPr(imSizeArray);
} else {
imSizeV = ScreenSizeV;
}
cameraSetup(currentCamParamS, ZNearFarV[0], ZNearFarV[1], imSizeV[0], imSizeV[1], zoomFactor);
drawPatch(batchList, imageBuffer, imSizeV[0], imSizeV[1], zoomFactor);
bufferDims[0] = imSizeV[0] * zoomFactor;
bufferDims[1] = imSizeV[1] * zoomFactor;
mxSetCell(LabeledImageA, i, mxCreateNumericArray(2, bufferDims, mxUINT32_CLASS, mxREAL));
LabeledImage = (unsigned int *) mxGetData(mxGetCell(LabeledImageA, i));
colorDemodulation(imageBuffer, channelModFactor, NULL, imSizeV[0], imSizeV[1], zoomFactor, LabeledImage);
}
mxFree(imageBuffer);
// Relase the display list.
if (batchList) {
glDeleteLists(batchList, 1);
batchList = 0;
}
printf("Done\n");
}
/* The gateway routine */
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
int output1Size[1];
double *FM = mxGetPr(prhs[0]);
int fNum = mxGetM(prhs[0]);
double *VM = mxGetPr(prhs[1]);
int vNum = mxGetM(prhs[1]);
const mxArray *CamParamSA = prhs[2];
unsigned int channelModFactor = (unsigned int)mxGetScalar(prhs[3]);
double *ScreenSizeV = mxGetPr(prhs[4]);
double zoomFactor = mxGetScalar(prhs[5]);
double *zNearFarV = mxGetPr(prhs[6]);
const int *dims;
mxArray *LabeledImageA;
OffscreenGL offscreenGL((int)(ScreenSizeV[0] * zoomFactor), (int)(ScreenSizeV[1] * zoomFactor));
if (nlhs == 1) {
output1Size[0] = mxGetM(CamParamSA);
plhs[0] = mxCreateCellArray(1, output1Size);
LabeledImageA = plhs[0];
if (offscreenGL.RGB8Setup()) {
mexPrintf("OpenGLCanvas setup Successful\n");
getLabeledImages(FM, fNum, VM, vNum, CamParamSA, ScreenSizeV, zoomFactor,
channelModFactor, zNearFarV, LabeledImageA);
} else {
mexPrintf("OpenGLCanvas setup failed\n");
}
}
}