root / trunk / tbeta / Windows / addons / ofxTBeta / gui.h @ 45

View | Annotate | Download (16 KB)

1
#ifndef __GUI_DEFINITION
2
#define __GUI_DEFINITION
3
4
#include "TBetaBase.h"
5
6
TBetaBase  *appPtr;
7
8
void TBetaBase ::setupGUI()
9
{
10
        appPtr = this;
11
12
        //if(!gui->buildFromXml(OFXGUI_XML))
13
        //{
14
                //panel border color
15
                gui->mGlobals->mBorderColor.r = 0;
16
                gui->mGlobals->mBorderColor.g = 0;
17
                gui->mGlobals->mBorderColor.b = 0;
18
                gui->mGlobals->mBorderColor.a = .3;
19
                //panel color
20
                gui->mGlobals->mCoverColor.r = 1;
21
                gui->mGlobals->mCoverColor.g = 1;
22
                gui->mGlobals->mCoverColor.b = 1;
23
                gui->mGlobals->mCoverColor.a = .4;
24
                //control outline color
25
                gui->mGlobals->mFrameColor.r = 0;
26
                gui->mGlobals->mFrameColor.g = 0;
27
                gui->mGlobals->mFrameColor.b = 0;
28
                gui->mGlobals->mFrameColor.a = .3;
29
                //text color
30
                gui->mGlobals->mTextColor.r = 0;
31
                gui->mGlobals->mTextColor.g = 0;
32
                gui->mGlobals->mTextColor.b = 0;
33
                gui->mGlobals->mTextColor.a = 1;
34
                //button color
35
                gui->mGlobals->mButtonColor.r = .9;
36
                gui->mGlobals->mButtonColor.g = 1;
37
                gui->mGlobals->mButtonColor.b = 0;
38
                gui->mGlobals->mButtonColor.a = .8;
39
                //slider tip color
40
                gui->mGlobals->mHandleColor.r = 0;
41
                gui->mGlobals->mHandleColor.g = 0;
42
                gui->mGlobals->mHandleColor.b = 0;
43
                //slider color
44
                gui->mGlobals->mSliderColor.r = 1;
45
                gui->mGlobals->mSliderColor.g = 0;
46
                gui->mGlobals->mSliderColor.b = 0;
47
                gui->mGlobals->mSliderColor.a = .8;
48
49
50
51
52
                ofxGuiPanel* propPanel = gui->addPanel(appPtr->propertiesPanel, "Source Properties", 735, 10, 12, OFXGUI_PANEL_SPACING);
53
                propPanel->addButton(appPtr->propertiesPanel_settings, "Camera Settings (v)", OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, kofxGui_Button_Off, kofxGui_Button_Trigger, "");
54
                propPanel->addButton(appPtr->propertiesPanel_flipV, "Flip Vertical (j)", OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, kofxGui_Button_Off, kofxGui_Button_Switch, "");
55
                propPanel->addButton(appPtr->propertiesPanel_flipH, "Flip Horizontal (h)", OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, kofxGui_Button_Off, kofxGui_Button_Switch, "");
56
                propPanel->mObjWidth = 200;
57
58
                ofxGuiPanel* gPanel = gui->addPanel(appPtr->gpuPanel, "GPU Properties", 735, 114, OFXGUI_PANEL_BORDER, OFXGUI_PANEL_SPACING);
59
                gPanel->addButton(appPtr->gpuPanel_use, "GPU Mode (g)", OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, kofxGui_Button_Off, kofxGui_Button_Switch, "");
60
                gPanel->mObjWidth = 200;
61
62
                ofxGuiPanel* oPanel = gui->addPanel(appPtr->optionPanel, "Communication", 735, 177, OFXGUI_PANEL_BORDER, OFXGUI_PANEL_SPACING);
63
                oPanel->addButton(appPtr->optionPanel_tuio, "Send TUIO (t)", OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, kofxGui_Button_Off, kofxGui_Button_Switch, "");
64
                oPanel->mObjWidth = 200;
65
66
                ofxGuiPanel* cPanel = gui->addPanel(appPtr->calibrationPanel, "Calibration", 735, 240, OFXGUI_PANEL_BORDER, OFXGUI_PANEL_SPACING);
67
                cPanel->addButton(appPtr->calibrationPanel_calibrate, "Enter Calibration (c)", OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, kofxGui_Button_Off, kofxGui_Button_Trigger, "");
68
                cPanel->mObjWidth = 200;
69
70
                ofxGuiPanel* panel2 = gui->addPanel(appPtr->savePanel, "files", 735, 303, OFXGUI_PANEL_BORDER, OFXGUI_PANEL_SPACING);
71
                //savePanel->addFiles(kParameter_File, "files", 110, OFXGUI_FILES_HEIGHT, "", "", "xml");
72
                panel2->addButton(appPtr->kParameter_SaveXml, "Save Settings (s)", OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, kofxGui_Button_Off, kofxGui_Button_Trigger, "");
73
                panel2->mObjWidth = 200;
74
75
                //Tracked Image
76
                ofxGuiPanel* trackPanel = gui->addPanel(appPtr->trackedPanel, "Tracked Image", 386, 270, OFXGUI_PANEL_BORDER, OFXGUI_PANEL_SPACING);
77
                trackPanel->addButton(appPtr->trackedPanel_outlines, "Show Outlines (o)", OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, kofxGui_Button_Off, kofxGui_Button_Switch, "");
78
                trackPanel->addButton(appPtr->trackedPanel_ids, "Show IDs (i)", OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, kofxGui_Button_Off, kofxGui_Button_Switch, "");
79
                trackPanel->addSlider(appPtr->trackedPanel_threshold, "Threshold (a/z)", 300, 13, 0.0f, 255.0f, threshold, kofxGui_Display_Int, 0);
80
                trackPanel->mObjHeight = 85;
81
                trackPanel->mObjWidth = 319;
82
                trackPanel->mObjects[1]->mObjX = 130;
83
                trackPanel->mObjects[1]->mObjY = 32;
84
                trackPanel->mObjects[2]->mObjY = 52;
85
86
                //Source Image
87
                ofxGuiPanel* srcPanel = gui->addPanel(appPtr->sourcePanel, "Source Image", 41, 270, OFXGUI_PANEL_BORDER, OFXGUI_PANEL_SPACING);
88
                srcPanel->addButton(appPtr->sourcePanel_cam, "Use Camera", OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, kofxGui_Button_Off, kofxGui_Button_Switch, "");
89
                srcPanel->addButton(appPtr->sourcePanel_previousCam, "Previous Camera", OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, kofxGui_Button_Off, kofxGui_Button_Trigger, "");
90
                srcPanel->addButton(appPtr->sourcePanel_nextCam, "Next Camera", OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, kofxGui_Button_Off, kofxGui_Button_Trigger, "");
91
                srcPanel->addButton(appPtr->sourcePanel_video, "Use Video", OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, kofxGui_Button_Off, kofxGui_Button_Switch, "");
92
                srcPanel->mObjHeight = 85;
93
                srcPanel->mObjWidth = 319;
94
                srcPanel->mObjects[1]->mObjX = 100;
95
                srcPanel->mObjects[1]->mObjY = 32;
96
                srcPanel->mObjects[2]->mObjX = 214;
97
                srcPanel->mObjects[2]->mObjY = 32;
98
                srcPanel->mObjects[3]->mObjY = 55;
99
                srcPanel->adjustToNewContent(100, 0);
100
101
                //Background Image
102
                ofxGuiPanel* bkPanel1 = gui->addPanel(appPtr->backgroundPanel, "Background", 86, 487, 10, 7);
103
                bkPanel1->addButton(backgroundPanel_remove, "Remove BG (b)", 10, 10, kofxGui_Button_Off, kofxGui_Button_Trigger, "");
104
                bkPanel1->addButton(backgroundPanel_dynamic, "Dynamic Subtract", 10, 10, kofxGui_Button_Off, kofxGui_Button_Switch, "");
105
                bkPanel1->mObjWidth = 127;
106
                bkPanel1->mObjHeight = 65;
107
108
                //Smooth Image
109
                ofxGuiPanel* sPanel = gui->addPanel(appPtr->smoothPanel, "Smooth", 236, 487, 10, 7);
110
                sPanel->addButton(smoothPanel_use, "", 12, 12, kofxGui_Button_Off, kofxGui_Button_Switch, "");
111
                sPanel->addSlider(smoothPanel_smooth, "Smooth", 110, 13, 0.0f, 15.0f, smooth, kofxGui_Display_Int, 0);
112
                sPanel->mObjects[0]->mObjX = 105;
113
                sPanel->mObjects[0]->mObjY = 10;
114
                sPanel->mObjects[1]->mObjY = 30;
115
                sPanel->mObjWidth = 127;
116
                sPanel->mObjHeight = 65;
117
118
                //Highpass Image
119
                ofxGuiPanel* hpPanel = gui->addPanel(appPtr->highpassPanel, "Highpass", 386, 487, OFXGUI_PANEL_BORDER, 7);
120
                hpPanel->addButton(highpassPanel_use, "", 12, 12, kofxGui_Button_Off, kofxGui_Button_Switch, "");
121
                hpPanel->addSlider(highpassPanel_blur, "Blur", 110, 13, 0.0f, 200.0f, highpassBlur, kofxGui_Display_Int, 0);
122
                hpPanel->addSlider(highpassPanel_noise, "Noise", 110, 13, 0.0f, 30.0f, highpassNoise, kofxGui_Display_Int, 0);
123
                hpPanel->mObjects[0]->mObjX = 105;
124
                hpPanel->mObjects[0]->mObjY = 10;
125
                hpPanel->mObjects[1]->mObjY = 30;
126
                hpPanel->mObjects[2]->mObjY = 60;
127
                hpPanel->mObjWidth = 127;
128
                hpPanel->mObjHeight = 95;
129
130
131
                //Amplify Image
132
                ofxGuiPanel* ampPanel = gui->addPanel(appPtr->amplifyPanel, "Amplify", 536, 487, OFXGUI_PANEL_BORDER, 7);
133
                ampPanel->addButton(amplifyPanel_use, "", 12, 12, kofxGui_Button_Off, kofxGui_Button_Switch, "");
134
                ampPanel->addSlider(amplifyPanel_amp, "Amplify", 110, 13, 0.0f, 300.0f, highpassAmp, kofxGui_Display_Int, 0);
135
                ampPanel->mObjects[0]->mObjX = 105;
136
                ampPanel->mObjects[0]->mObjY = 10;
137
                ampPanel->mObjects[1]->mObjY = 30;
138
                ampPanel->mObjWidth = 127;
139
                ampPanel->mObjHeight = 65;
140
141
                //do update while inactive
142
                gui->forceUpdate(false);
143
                gui->activate(true);
144
        //}
145
                /****************************
146
                * Set GUI values on startup
147
                ****************************/
148
                gui->update(appPtr->propertiesPanel_flipV, kofxGui_Set_Bool, &appPtr->bVerticalMirror, sizeof(bool));
149
                gui->update(appPtr->propertiesPanel_flipH, kofxGui_Set_Bool, &appPtr->bHorizontalMirror, sizeof(bool));
150
                gui->update(appPtr->trackedPanel_outlines, kofxGui_Set_Bool, &appPtr->bDrawOutlines, sizeof(bool));
151
                gui->update(appPtr->trackedPanel_ids, kofxGui_Set_Bool, &appPtr->bShowLabels, sizeof(bool));
152
                //Source
153
                gui->update(appPtr->sourcePanel_cam, kofxGui_Set_Bool, &appPtr->bcamera, sizeof(bool));
154
                if(!bcamera){
155
                bool bvideo = true;
156
                gui->update(appPtr->sourcePanel_video, kofxGui_Set_Bool, &bvideo, sizeof(bool));
157
                }
158
                //Calibration
159
                gui->update(appPtr->calibrationPanel_calibrate, kofxGui_Set_Bool, &appPtr->bCalibration, sizeof(bool));
160
                //Dynamic Background
161
                gui->update(appPtr->backgroundPanel_dynamic, kofxGui_Set_Bool, &appPtr->bDynamicBG, sizeof(bool));
162
                //Smooth
163
                gui->update(appPtr->smoothPanel_use, kofxGui_Set_Bool, &appPtr->bSmooth, sizeof(bool));
164
                gui->update(appPtr->smoothPanel_smooth, kofxGui_Set_Bool, &appPtr->smooth, sizeof(float));
165
                //Highpass
166
                gui->update(appPtr->highpassPanel_use, kofxGui_Set_Bool, &appPtr->bHighpass, sizeof(bool));
167
                gui->update(appPtr->highpassPanel_blur, kofxGui_Set_Bool, &appPtr->highpassBlur, sizeof(float));
168
                gui->update(appPtr->highpassPanel_noise, kofxGui_Set_Bool, &appPtr->highpassNoise, sizeof(float));
169
                //Amplify
170
                gui->update(appPtr->amplifyPanel_use, kofxGui_Set_Bool, &appPtr->bAmplify, sizeof(bool));
171
                gui->update(appPtr->amplifyPanel_amp, kofxGui_Set_Bool, &appPtr->highpassAmp, sizeof(float));
172
                //Threshold
173
                gui->update(appPtr->trackedPanel_threshold, kofxGui_Set_Bool, &appPtr->threshold, sizeof(float));
174
                //Send TUIO
175
                gui->update(appPtr->optionPanel_tuio, kofxGui_Set_Bool, &appPtr->bTUIOMode, sizeof(bool));
176
                //GPU Mode
177
                gui->update(appPtr->gpuPanel_use, kofxGui_Set_Bool, &appPtr->bGPUMode, sizeof(bool));
178
}
179
180
void TBetaBase ::handleGui(int parameterId, int task, void* data, int length)
181
{
182
        if(activeInput)
183
        {
184
                switch(parameterId)
185
                {
186
                        case sourcePanel_cam:
187
                                if(length == sizeof(bool))
188
                                {
189
                                        if(*(bool*)data)
190
                                        {
191
                                                if(!bcamera){
192
                                                        activeInput = false; //this stops the app from doing everything when changing source
193
                                                        bcamera = true;
194
                                                        vidGrabber.close();
195
                                                        vidGrabber.setDeviceID(deviceID);
196
                                                        vidGrabber.setVerbose(false);
197
                                                        camWidth = vidGrabber.width;
198
                                                        camHeight = vidGrabber.height;
199
                                                        vidGrabber.initGrabber(camWidth,camHeight);
200
201
//                                                        calibrate.setCamRes(camHeight, camWidth);
202
//                                                        calibrate.computeCameraToScreenMap();
203
204
                                                        //reset gpu textures and filters
205
                                                        resetGPUTextures();
206
207
                                                        processedImg.allocate(camWidth, camHeight); //Processed Image
208
                                                        processedImg.setUseTexture(false);
209
                                                        sourceImg.allocate(camWidth, camHeight);    //Source Image
210
                                                        sourceImg.setUseTexture(false);
211
                                                        grayImg.allocate(camWidth, camHeight);                //Gray Image
212
                                                        grayBg.allocate(camWidth, camHeight);                //Background Image
213
                                                        subtractBg.allocate(camWidth, camHeight);   //Background After subtraction
214
                                                        grayDiff.allocate(camWidth, camHeight);                //Difference Image between Background and Source
215
                                                        highpassImg.allocate(camWidth, camHeight);  //Highpass Image
216
                                                        ampImg.allocate(camWidth, camHeight);                //Amplify Image
217
                                                        fiLearn.allocate(camWidth, camHeight);                //ofxFloatImage used for simple dynamic background subtracti
218
                                                        pressureMap.allocate(camWidth, camHeight);        //Pressure Map Image
219
220
                                                        activeInput = true;                //set to active again
221
                                                        bLearnBakground = true; //recapture background
222
                                                        //Turn off the video button;
223
                                                        bool setBool = false;
224
                                                        gui->update(sourcePanel_video, kofxGui_Set_Bool, &setBool, length);
225
                                                }
226
                                        }
227
                                }
228
                                break;
229
                        case sourcePanel_video:
230
                                if(length == sizeof(bool))
231
                                {
232
                                        if(*(bool*)data)
233
                                        {
234
                                                if(bcamera){
235
                                                        activeInput = false; //this stops the app from doing everything when changing source
236
                                                        bcamera = false;
237
                                                        vidPlayer.loadMovie("test_videos/" + videoFileName);
238
                                                        vidPlayer.play();
239
                                                        printf("Video Mode\n");
240
                                                        camHeight = vidPlayer.height;
241
                                                        camWidth = vidPlayer.width;
242
243
//                                                        calibrate.setCamRes(camHeight, camWidth);
244
//                                                        calibrate.computeCameraToScreenMap();
245
246
                                                        //reset gpu textures and filters
247
                                                        resetGPUTextures();
248
249
                                                        processedImg.allocate(camWidth, camHeight); //Processed Image
250
                                                        processedImg.setUseTexture(false);
251
                                                        sourceImg.allocate(camWidth, camHeight);    //Source Image
252
                                                        sourceImg.setUseTexture(false);
253
                                                        grayImg.allocate(camWidth, camHeight);                //Gray Image
254
                                                        grayBg.allocate(camWidth, camHeight);                //Background Image
255
                                                        subtractBg.allocate(camWidth, camHeight);   //Background After subtraction
256
                                                        grayDiff.allocate(camWidth, camHeight);                //Difference Image between Background and Source
257
                                                        highpassImg.allocate(camWidth, camHeight);  //Highpass Image
258
                                                        ampImg.allocate(camWidth, camHeight);                //Amplify Image
259
                                                        fiLearn.allocate(camWidth, camHeight);                //ofxFloatImage used for simple dynamic background subtracti
260
                                                        pressureMap.allocate(camWidth, camHeight);        //Pressure Map Image
261
262
                                                        activeInput = true;
263
                                                        bLearnBakground = true;
264
                                                        //Turn off the camera button;
265
                                                        bool setBool = false;
266
                                                        gui->update(sourcePanel_cam, kofxGui_Set_Bool, &setBool, length);
267
                                                }
268
                                        }
269
                                }
270
                                break;
271
272
                        case sourcePanel_nextCam:
273
                                if(length == sizeof(bool))
274
                                {
275
                                        if(*(bool*)data)
276
                                        {
277
                                                activeInput = false; //this stops the app from doing everything when changing source
278
279
                                                deviceID += 1;
280
                                                if(deviceID >= vidGrabber.getDeviceCount()) {deviceID = vidGrabber.getDeviceCount();}
281
                                                else{
282
                                                        vidGrabber.close();
283
                                                        vidGrabber.setDeviceID(deviceID);
284
                                                        vidGrabber.setVerbose(true);
285
                                                        vidGrabber.initGrabber(camWidth,camHeight);
286
                                                        bLearnBakground = true;
287
                                                }
288
                                                activeInput = true;
289
                                        }
290
                                }
291
                                break;
292
                        case sourcePanel_previousCam:
293
                                if(length == sizeof(bool))
294
                                {
295
                                        if(*(bool*)data)
296
                                        {
297
                                                activeInput = false; //this stops the app from doing everything when changing source
298
299
                                                deviceID -= 1;
300
                                                if(deviceID < 0) deviceID = 0;
301
                                                else{
302
                                                        vidGrabber.close();
303
                                                        vidGrabber.setDeviceID(deviceID);
304
                                                        vidGrabber.setVerbose(true);
305
                                                        vidGrabber.initGrabber(camWidth,camHeight);
306
                                                        bLearnBakground = true;
307
                                                }
308
                                                activeInput = true;
309
                                        }
310
                                }
311
                                break;
312
313
                        case propertiesPanel_settings:
314
                                if(length == sizeof(bool))
315
                                {
316
                                        if(*(bool*)data && bcamera)
317
                                        {
318
                                                vidGrabber.videoSettings();
319
                                        }
320
                                }
321
                                break;
322
                        //Calibration
323
                        case calibrationPanel_calibrate:
324
                                        bCalibration = true;
325
                                        bFullscreen = true;
326
                                break;
327
                        //Source
328
                        case propertiesPanel_flipH:
329
                                if(length == sizeof(bool))
330
                                        bHorizontalMirror = *(bool*)data;
331
                                break;
332
                        case propertiesPanel_flipV:
333
                                if(length == sizeof(bool))
334
                                        bVerticalMirror = *(bool*)data;
335
                                break;
336
                        //GPU
337
                        case gpuPanel_use:
338
                                if(length == sizeof(bool))
339
                                        bGPUMode= *(bool*)data;
340
                                break;
341
                        //Communication
342
                        case optionPanel_tuio:
343
                                if(length == sizeof(bool))
344
                                        bTUIOMode = *(bool*)data;
345
                                        myTUIO.blobs.clear();
346
                                break;
347
                        //Background
348
                        case backgroundPanel_dynamic:
349
                                if(length == sizeof(bool))
350
                                        bDynamicBG = *(bool*)data;
351
                                break;
352
                        case backgroundPanel_remove:
353
                                if(length == sizeof(bool))
354
                                        bLearnBakground = *(bool*)data;
355
                                break;
356
                        //Highpass
357
                        case highpassPanel_use:
358
                                if(length == sizeof(bool))
359
                                        bHighpass = *(bool*)data;
360
                                break;
361
                        case highpassPanel_blur:
362
                                if(length == sizeof(float))
363
                                        highpassBlur = *(float*)data;
364
                                break;
365
                        case highpassPanel_noise:
366
                                if(length == sizeof(float))
367
                                        highpassNoise = *(float*)data;
368
                                break;
369
                        //Amplify
370
                        case amplifyPanel_use:
371
                                if(length == sizeof(bool))
372
                                        bAmplify = *(bool*)data;
373
                                break;
374
                        case amplifyPanel_amp:
375
                                if(length == sizeof(float))
376
                                        highpassAmp = *(float*)data;
377
                                break;
378
                        case trackedPanel_threshold:
379
                                if(length == sizeof(float))
380
                                        threshold = *(float*)data;
381
                                break;
382
                        case trackedPanel_outlines:
383
                                if(length == sizeof(bool))
384
                                        bDrawOutlines = *(bool*)data;
385
                                break;
386
                        case trackedPanel_ids:
387
                                if(length == sizeof(bool))
388
                                        bShowLabels = *(bool*)data;
389
                                break;
390
                        //smooth
391
                        case smoothPanel_smooth:
392
                                if(length == sizeof(float))
393
                                        smooth = *(float*)data;
394
                                break;
395
                        case smoothPanel_use:
396
                                if(length == sizeof(bool))
397
                                        bSmooth = *(bool*)data;
398
                                break;
399
                        //Save Settings
400
                        case kParameter_SaveXml:
401
                                if(length == sizeof(bool))
402
                                {
403
                                        if(*(bool*)data)
404
                                        {
405
                                                gui->saveToXml(OFXGUI_XML);
406
                                                saveConfiguration();
407
                                        }
408
                                }
409
                                break;
410
                        case kParameter_File:
411
                                if(length == sizeof(string))
412
                                {
413
                                        string file = *(string*)data;
414
                                        gui->buildFromXml(file);
415
                                }
416
                                break;
417
418
                }
419
        }
420
421
}
422
423
424
425
426
427
#endif //__GUI_DEFINITION
428