-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathstreamSplitter.cpp
More file actions
executable file
·167 lines (137 loc) · 5.04 KB
/
streamSplitter.cpp
File metadata and controls
executable file
·167 lines (137 loc) · 5.04 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
* streamSplitter.cpp
* Proton
*
* Created by Kenrick Kin on 2/3/12.
*
*/
#include <iostream>
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include "Pt/Gesture.h"
#include "Pt/TouchProcessor.h"
#include "Pt/TouchSymbol.h"
#include "Pt/TuioListener.h"
#include "Pt/TransitionTable.h"
#include "Pt/Utils.h"
#include "KKAttributeGenerator.h"
#include "LeftRightSplitStreamAttributeGenerator.h"
double pXLeft = -0.5;
double pYLeft = 0;
double pXRight = 0.5;
double pYRight = 0;
static bool _verbose = true;
void twoTouchCallback0(const std::vector<PtTouchSymbols *> &touchStream)
{
if(_verbose)
printf("TWO TOUCH CALLBACK 0!\n");
}
void twoTouchCallback1(const std::vector<PtTouchSymbols *> &touchStream)
{
if(_verbose)
printf("TWO TOUCH CALLBACK 1!\n");
}
void oneTouchLeftCallback(const std::vector<PtTouchSymbols *> &touchStream)
{
if(_verbose)
printf("ONE TOUCH LEFT CALLBACK!\n");
PtTouchSymbols *lastFrame = touchStream[touchStream.size()-1];
PtTuioTouchSymbol *tS = static_cast<PtTuioTouchSymbol*>((*lastFrame)[lastFrame->size()-1]);
pXLeft = tS->tuioCursor()->getX()*2-1;
pYLeft = (1-tS->tuioCursor()->getY())*2-1;
glutPostRedisplay();
}
void oneTouchRightCallback(const std::vector<PtTouchSymbols *> &touchStream)
{
if(_verbose)
printf("ONE TOUCH RIGHT CALLBACK!\n");
PtTouchSymbols *lastFrame = touchStream[touchStream.size()-1];
PtTuioTouchSymbol *tS = static_cast<PtTuioTouchSymbol*>((*lastFrame)[lastFrame->size()-1]);
pXRight = tS->tuioCursor()->getX()*2-1;
pYRight = (1-tS->tuioCursor()->getY())*2-1;
glutPostRedisplay();
}
double halfConfidenceCalculator(const std::vector<PtTouchSymbols *> &touchStream)
{
return 0.5;
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_QUADS);
glColor3f(1.0f,0.0f,0.0f);
glVertex2f(pXLeft-0.2, pYLeft-0.2);
glVertex2f(pXLeft+0.2, pYLeft-0.2);
glVertex2f(pXLeft+0.2, pYLeft+0.2);
glVertex2f(pXLeft-0.2, pYLeft+0.2);
glColor3f(0.0f,0.0f,1.0f);
glVertex2f(pXRight-0.2, pYRight-0.2);
glVertex2f(pXRight+0.2, pYRight-0.2);
glVertex2f(pXRight+0.2, pYRight+0.2);
glVertex2f(pXRight-0.2, pYRight+0.2);
glEnd();
glutSwapBuffers();
}
void idle(void)
{
//glutPostRedisplay();
}
void reshape(GLint width, GLint height)
{
glViewport(0, 0, width, height);
}
int main (int argc, char** argv)
{
glutInit (&argc, argv);
glutInitWindowSize (512, 512);
glutInitDisplayMode ( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow ("Stream Splitter");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
// creating a two-touch regular expression
PtTouchSymbols regexp;
convertStringToTouchSymbolRegularExpression(std::string("D0:KK_(M0:KK_)*D1:KK_(M0:KK_|M1:KK_)*(U0:KK_(M1:KK_)*U1:KK_|U1:KK_(M0:KK_)*U0:KK_)"), std::string("_"), regexp);
addTriggerToIthTouchSymbol(®exp, 0, 1);
addTriggerToIthTouchSymbol(®exp, 1, 3);
// creating the two-touch gesture with two callbacks that do nothing
PtGesture *gesture1 = new PtGesture(regexp);
gesture1->setName(std::string("TWO_TOUCH"));
gesture1->addCallback(twoTouchCallback0);
gesture1->addCallback(twoTouchCallback1);
clearRegexp(®exp);
// creating a one-touch regular expression
convertStringToTouchSymbolRegularExpression(std::string("D0:KK_(M0:KK_)*U0:KK_"), std::string("_"), regexp);
addTriggerToIthTouchSymbol(®exp, 0, 1);
// creating the one-touch gesture
PtGesture *gesture2 = new PtGesture(regexp);
gesture2->setName(std::string("ONE_TOUCH_LEFT"));
gesture2->addCallback(oneTouchLeftCallback);
PtGesture *gesture3 = new PtGesture(regexp);
gesture3->setName(std::string("ONE_TOUCH_RIGHT"));
//gesture3->addCallback(oneTouchRightCallback, halfConfidenceCalculator);
gesture3->addCallback(oneTouchRightCallback);
clearRegexp(®exp);
// create a PtTouchProcesser with two gesture matchers
PtTouchProcessor touchProcessor(2);
// first matcher gets gesture1 and gesture2
touchProcessor.addGesture(gesture1, 0);
touchProcessor.addGesture(gesture2, 0);
// second matcher gets gesture3
touchProcessor.addGesture(gesture3, 1);
// each matcher will only execute the callback with the highest confidence score
//touchProcessor.setExecuteBestGesture(true, 0);
//touchProcessor.setExecuteBestGesture(true, 1);
// assigns a KKAttributeGenerator to gesture matchers at indices 0 and 1
touchProcessor.addAttributeGenerator(new KKAttributeGenerator(), 0);
touchProcessor.addAttributeGenerator(new KKAttributeGenerator(), 1);
// adds a split stream attribute generator to split the stream by left and right halves of the screen
touchProcessor.setSplitStreamAttributeGenerator(new LeftRightSplitStreamAttributeGenerator());
// create TUIO listener on port 3333
PtTuioListener listener(3333, &touchProcessor);
glutMainLoop();
return 0;
}