summaryrefslogtreecommitdiff
path: root/offsetProject/src/ofApp.cpp
blob: 7c5428ca041be2ea8fbfb68de21a01af95a590cb (plain)
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
#include "ofApp.h"

/*
so far so good, NOW

threading

parse response and identify new pictures
save pictures & metadata - rather than reloading each time?
local images format
do we need any metadata? I guess not other than to know the tag id
could save with the tag id as the name of file, simpler

how exactly do we parse or mipmap the images
do we worry about memory - I guess not

identify the images

image save- reload system (? even necessary ?)
camera + button
transitions

should the loader own the images?
should the whole image bank be locked while loading?
alternatively each image could have a lock? - threadedImage

or true mip map via drawsubsection?

start with a max size say 64 - should be 16k inc mip maps

graphics card has 2048MB
9% in use by ubuntu
117964 textures
I wonder is this faster with shared memory..

load app
get list of images in defined folder
load them and create mip maps
store indexed by file stub

start thread
when a new image comes in
load and create mip maps

how to store pictures
threaded loader works away in the background
when a new picture comes in 

a data structure which is part of the threaded object
each image contains a mutex to enable the threaded object to be accessed
the instagram id is just used to match against incoming - there needs to be the pattern matching algorithm

how to draw pictures
need to search the db for pictures of a certain colour

*/
//--------------------------------------------------------------
void ofApp::setup() {
	ofSetLogLevel(OF_LOG_WARNING);
		
	ofSetFrameRate(60);

	kinect.setRegistration(true); 
	kinect.init();
	kinect.open();
	colourImage.allocate(kinect.width, kinect.height);
	depthImage.allocate(kinect.width, kinect.height);
	farThreshold = 70;
	angle = 0;
	kinect.setCameraTiltAngle(angle);
	kinect.enableDepthNearValueWhite(true);
	kinect.setDepthClipping(0,4000);

	store.start();
	
	mode=MODE_COLOURTILES;

	fullscreen=false;
}

//--------------------------------------------------------------
void ofApp::update() {
	
	ofSetWindowTitle(ofToString(ofGetFrameRate()));
	
	kinect.update();
	
	// there is a new frame and we are connected
	if(kinect.isFrameNew()) {
		
		depthImage.setFromPixels(kinect.getDepthPixels(), kinect.width, kinect.height);
		colourImage.setFromPixels(kinect.getPixels(), kinect.width, kinect.height);
		
		depthImage.threshold(farThreshold);

		//threshold needs to be multiplied by the original
		depthImage2.setFromPixels(kinect.getDepthPixels(), kinect.width, kinect.height);
		depthImage*=depthImage2;

		//depthImage.extend(extend_w,extend_h);
		//colourImage.extend(extend_w,extend_h);

		int h=ceil(ofGetHeight()/MAX_TILE_SIZE);
		int w=(h*4)/3;
		depthImage.resize(w,h);
		colourImage.resize(w,h);
		
		// mark pixels and texture dirty
		depthImage.flagImageChanged();
		colourImage.flagImageChanged();

		/*
		ofxCvColorImage *prevCol=&colourImage;
		ofxCvGrayscaleImage *prevDepth=&depthImage;


		for (int i=0;i<colourTiles.size();i++){
			colourTiles[i].scaleIntoMe(*prevCol);
			depthTiles[i].scaleIntoMe(*prevDepth);
			prevCol=&colourTiles[i];
			prevDepth=&depthTiles[i];

			colourTiles[i].flagImageChanged();
			depthTiles[i].flagImageChanged();
		}
		*/
	}

	store.update();
	
	
}



//--------------------------------------------------------------
void ofApp::draw() {

	ofBackground(0,0,0);

	ofSetColor(255, 255, 255);

	int w,xstart,ystart,kinexstart;

	switch(mode){
		case MODE_COLOURTILES:
			//store.draw();
			xstart=(ofGetWidth()/2)-((colourImage.getHeight()/2)*MAX_TILE_SIZE);
			ystart=(ofGetHeight()/2)-((colourImage.getHeight()/2)*MAX_TILE_SIZE);
			kinexstart=(colourImage.getWidth()/2)-(colourImage.getHeight()/2);
			ofPushMatrix();
				ofTranslate(xstart,ystart);
				w=colourImage.getWidth();
				for (int i=0;i<depthImage.getHeight();i++){
					for (int j=0;j<depthImage.getHeight();j++){
						uint8_t* ppt=&colourImage.getPixels()[(j*w+(w-(i+kinexstart)))*3];
						store.get_image(ofColor(ppt[0],ppt[1],ppt[2])).draw(i*MAX_TILE_SIZE,j*MAX_TILE_SIZE);
						//ofSetColor(ppt[0],ppt[1],ppt[2]);
						//ofRect(i*MAX_TILE_SIZE,j*MAX_TILE_SIZE,MAX_TILE_SIZE,MAX_TILE_SIZE);
					}
				}
			ofPopMatrix();
			break;

		case MODE_DEPTH:

			depthImage.draw(0,0,ofGetWidth(),ofGetHeight());
			break;

		case MODE_COMPONENTS:

			depthImage.draw(0,0, 640,480);
			colourImage.draw(640,0, 640,480);
			break;
	}
    
}



//--------------------------------------------------------------
void ofApp::exit() {

	
}

//--------------------------------------------------------------
void ofApp::keyPressed (int key) {
	switch (key) {
			
		case '>':
		case '.':
			farThreshold ++;
			if (farThreshold > 255) farThreshold = 255;
			break;
			
		case '<':
		case ',':
			farThreshold --;
			if (farThreshold < 0) farThreshold = 0;
			break;
			
			
		case 'w':
			kinect.enableDepthNearValueWhite(!kinect.isDepthNearValueWhite());
			break;
			
		case 'o':
			kinect.setCameraTiltAngle(angle); // go back to prev tilt
			kinect.open();
			break;
			
		case 'c':
			kinect.setCameraTiltAngle(0); // zero the tilt
			kinect.close();
			break;
			
		case '1':
			kinect.setLed(ofxKinect::LED_GREEN);
			break;
			
		case '2':
			kinect.setLed(ofxKinect::LED_YELLOW);
			break;
			
		case '3':
			kinect.setLed(ofxKinect::LED_RED);
			break;
			
		case '4':
			kinect.setLed(ofxKinect::LED_BLINK_GREEN);
			break;
			
		case '5':
			kinect.setLed(ofxKinect::LED_BLINK_YELLOW_RED);
			break;
			
		case '0':
			kinect.setLed(ofxKinect::LED_OFF);
			break;
			
		case OF_KEY_UP:
			angle++;
			if(angle>30) angle=30;
			kinect.setCameraTiltAngle(angle);
			break;
			
		case OF_KEY_DOWN:
			angle--;
			if(angle<-30) angle=-30;
			kinect.setCameraTiltAngle(angle);
			break;
		
		case OF_KEY_LEFT:
			mode--;
			if (mode<0) mode=NUM_MODES-1;
			break;

		case OF_KEY_RIGHT:
			mode=(mode+1)%NUM_MODES;
			break;

		case ' ':
			fullscreen=!fullscreen;
			ofSetFullscreen(fullscreen);
			break;

	}
}

//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button)
{}

//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button)
{}

//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button)
{}

//--------------------------------------------------------------
void ofApp::windowResized(int w, int h)
{}