summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xTRRSS_01_rec/src/main.cpp2
-rwxr-xr-xTRRSS_01_rec/src/testApp.cpp184
-rwxr-xr-xTRRSS_01_rec/src/testApp.h25
3 files changed, 168 insertions, 43 deletions
diff --git a/TRRSS_01_rec/src/main.cpp b/TRRSS_01_rec/src/main.cpp
index 1f1c3a1..de63c21 100755
--- a/TRRSS_01_rec/src/main.cpp
+++ b/TRRSS_01_rec/src/main.cpp
@@ -6,7 +6,7 @@
int main( ){
ofAppGlutWindow window;
- ofSetupOpenGL(ofxFensterManager::get(),1024,768, OF_WINDOW); //2048,768
+ ofSetupOpenGL(ofxFensterManager::get(),800,600, OF_WINDOW); //2048,768
//ofSetupOpenGL(&window, 1024,768, OF_WINDOW); // <-------- setup the GL context
//ofSetupOpenGL(&window, 1024,768, OF_WINDOW);
diff --git a/TRRSS_01_rec/src/testApp.cpp b/TRRSS_01_rec/src/testApp.cpp
index a052ccc..555118a 100755
--- a/TRRSS_01_rec/src/testApp.cpp
+++ b/TRRSS_01_rec/src/testApp.cpp
@@ -49,6 +49,9 @@ void unbindTex(ofTexture &tex) {
}
//--------------------------------------------------------------
void testApp::setup(){
+ isLive = true;
+ isRecording = false;
+
#ifdef NEWAPI
openNIDevice.setup(false);//FromXML("openni/config/ofxopenni_config.xml");
openNIDevice.setLogLevel(OF_LOG_VERBOSE);
@@ -75,14 +78,21 @@ void testApp::setup(){
#else
+ /*
recordContext.setup();
recordDepth.setup(&recordContext);
recordImage.setup(&recordContext);
recordUser.setup(&recordContext);
recordUser.setUseCloudPoints(true);
+ recordUser.setSmoothing(10.0f);
recordContext.toggleRegisterViewport();
+ */
#endif
+ setupRecording();
+ whichUser=&recordUser;
+ whichImage=&recordImage;
+
guiWin=new guiWindow();
ofxFenster* win=ofxFensterManager::get()->createFenster(0, 0, 200, 400, OF_WINDOW);
win->setWindowTitle("config");
@@ -90,16 +100,74 @@ void testApp::setup(){
guiWin->setup();
}
+void testApp::setupRecording(string _filename) {
+
+ bool isCloud=true;
+
+#if defined (TARGET_OSX) //|| defined(TARGET_LINUX) // only working on Mac/Linux at the moment (but on Linux you need to run as sudo...)
+ hardware.setup(); // libusb direct control of motor, LED and accelerometers
+ hardware.setLedOption(LED_OFF); // turn off the led just for yacks (or for live installation/performances ;-)
+#endif
+
+ recordContext.setup(); // all nodes created by code -> NOT using the xml config file at all
+ //recordContext.setupUsingXMLFile();
+ recordDepth.setup(&recordContext);
+ recordImage.setup(&recordContext);
+
+ recordUser.setup(&recordContext);
+ //recordUser.setSmoothing(filterFactor); // built in openni skeleton smoothing...
+ //recordUser.setUseMaskPixels(isMasking);
+ recordUser.setUseCloudPoints(isCloud);
+ recordUser.setMaxNumberOfUsers(2); // use this to set dynamic max number of users (NB: that a hard upper limit is defined by MAX_NUMBER_USERS in ofxUserGenerator)
+
+ recordContext.toggleRegisterViewport();
+ recordContext.toggleMirror();
+
+ oniRecorder.setup(&recordContext, ONI_STREAMING);
+ //oniRecorder.setup(&recordContext, ONI_CYCLIC, 60);
+ //read the warning in ofxOpenNIRecorder about memory usage with ONI_CYCLIC recording!!!
+
+}
+
+void testApp::setupPlayback(string _filename) {
+
+ bool isCloud=true;
+
+ playContext.shutdown();
+ playContext.setupUsingRecording(ofToDataPath(_filename));
+ playDepth.setup(&playContext);
+ playImage.setup(&playContext);
+
+ playUser.setup(&playContext);
+ //playUser.setSmoothing(filterFactor); // built in openni skeleton smoothing...
+ //playUser.setUseMaskPixels(isMasking);
+ playUser.setUseCloudPoints(isCloud);
+
+ playContext.toggleRegisterViewport();
+ playContext.toggleMirror();
+
+}
+
//--------------------------------------------------------------
void testApp::update(){
+ if (isLive) {
#ifdef NEWAPI
- openNIDevice.update();
+ openNIDevice.update();
#else
- recordContext.update();
- recordDepth.update();
- recordImage.update();
- recordUser.update();
+ recordContext.update();
+ recordDepth.update();
+ recordImage.update();
+ recordUser.update();
#endif
+ }
+ else {
+
+ playContext.update();
+ playDepth.update();
+ playImage.update();
+ playUser.update();
+ }
+ if (isRecording) oniRecorder.update();
}
//--------------------------------------------------------------
@@ -161,13 +229,14 @@ void testApp::draw(){
//bind texture recordImage
//get point data from recordDepth
//draw textured polys and allow manipulation
- float cloudWidth=1024.0f;
- float cloudHeight=768.0f;
+ float cloudWidth=ofGetWidth();
+ float cloudHeight=ofGetHeight();
ofPushMatrix();
- ofTranslate((1024/2)-(640/2),(768/2)-(480/2),-500);
+ ofTranslate((ofGetWidth()/2)-(640/2),(ofGetHeight()/2)-(480/2),800);
+ ofRotate(0.1,1,0.05,30);
//ofRotate(0,0,1,180);
- bindTex(recordImage.getTexture());
+
int step = 1;
if (guiWin->drawPoints) {
@@ -175,38 +244,38 @@ void testApp::draw(){
glEnable( GL_POINT_SMOOTH );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
- glPointSize( 6.0 );
+ glPointSize( guiWin->pointSize );
glBegin(GL_POINTS);
glColor3f( 1.0f, 1.0f, 1.0f );
- for(int y = step; y < 480; y += step) {
+ float spread=guiWin->distMax-guiWin->distMin;
- for(int x = step; x < 640; x += step) {
- ofPoint pos1 = recordUser.getWorldCoordinateAt(x-step, y-step, 0); //userID);
- ofPoint pos2 = recordUser.getWorldCoordinateAt(x, y-step, 0); //userID);
- ofPoint pos3 = recordUser.getWorldCoordinateAt(x-step, y, 0); //userID);
- ofPoint pos4 = recordUser.getWorldCoordinateAt(x, y, 0); //userID);
-
- if ((guiWin->distMin<pos1.z&&pos1.z<guiWin->distMax)&&
- (guiWin->distMin<pos2.z&&pos2.z<guiWin->distMax)&&
- (guiWin->distMin<pos3.z&&pos3.z<guiWin->distMax)&&
- (guiWin->distMin<pos4.z&&pos4.z<guiWin->distMax)) {
+ for(int y = step; y < 480; y += guiWin->drawStep) {
+
+ for(int x = step; x < 640; x += guiWin->drawStep) {
+ ofPoint pos4 = whichUser->getWorldCoordinateAt(x, y, 0); //userID);
- glVertex3f(pos4.x, pos4.y,pos4.z);
+ if (guiWin->distMin<pos4.z&&pos4.z<guiWin->distMax) {
+ float l=(pos4.z-guiWin->distMin)/spread;
+ glColor3f( l, l, l );
+
+ glVertex3f(pos4.x, pos4.y,-pos4.z);
}
}
- glEnd();
+
}
+ glEnd();
}
else {
- for(int y = step; y < 480; y += step) {
+ bindTex(whichImage->getTexture());
+ for(int y = step; y < 480; y += guiWin->drawStep) {
glBegin(GL_QUADS);
- for(int x = step; x < 640; x += step) {
- ofPoint pos1 = recordUser.getWorldCoordinateAt(x-step, y-step, 0); //userID);
- ofPoint pos2 = recordUser.getWorldCoordinateAt(x, y-step, 0); //userID);
- ofPoint pos3 = recordUser.getWorldCoordinateAt(x-step, y, 0); //userID);
- ofPoint pos4 = recordUser.getWorldCoordinateAt(x, y, 0); //userID);
+ for(int x = step; x < 640; x += guiWin->drawStep) {
+ ofPoint pos1 = whichUser->getWorldCoordinateAt(x-step, y-step, 0); //userID);
+ ofPoint pos2 = whichUser->getWorldCoordinateAt(x, y-step, 0); //userID);
+ ofPoint pos3 = whichUser->getWorldCoordinateAt(x-step, y, 0); //userID);
+ ofPoint pos4 = whichUser->getWorldCoordinateAt(x, y, 0); //userID);
if ((guiWin->distMin<pos1.z&&pos1.z<guiWin->distMax)&&
(guiWin->distMin<pos2.z&&pos2.z<guiWin->distMax)&&
@@ -214,23 +283,23 @@ void testApp::draw(){
(guiWin->distMin<pos4.z&&pos4.z<guiWin->distMax)) {
glTexCoord2f(((float)x-step)/640.0f,((float)y-step)/480.0f);
- glVertex3f(pos1.x, pos1.y,pos1.z);
+ glVertex3f(pos1.x, pos1.y,-pos1.z);
glTexCoord2f(((float)x)/640.0f,((float)y-step)/480.0f);
- glVertex3f(pos2.x, pos2.y,pos2.z);
+ glVertex3f(pos2.x, pos2.y,-pos2.z);
glTexCoord2f(((float)x)/640.0f,((float)y)/480.0f);
- glVertex3f(pos4.x, pos4.y,pos4.z);
+ glVertex3f(pos4.x, pos4.y,-pos4.z);
glTexCoord2f(((float)x-step)/640.0f,((float)y)/480.0f);
- glVertex3f(pos3.x, pos3.y,pos3.z);
+ glVertex3f(pos3.x, pos3.y,-pos3.z);
}
}
glEnd();
}
-
+ unbindTex(whichImage->getTexture());
}
ofPopMatrix();
- unbindTex(recordImage.getTexture());
+
//recordImage.draw(0, 0, ofGetWidth(),ofGetHeight());
@@ -249,9 +318,52 @@ void testApp::exit(){
#endif
}
+string testApp::generateFileName() {
+
+ string _root = "kinectRecord";
+
+ string _timestamp = ofToString(ofGetDay()) +
+ ofToString(ofGetMonth()) +
+ ofToString(ofGetYear()) +
+ ofToString(ofGetHours()) +
+ ofToString(ofGetMinutes()) +
+ ofToString(ofGetSeconds());
+
+ string _filename = (_root + _timestamp + ".oni");
+
+ return _filename;
+
+}
+
//--------------------------------------------------------------
void testApp::keyPressed(int key){
-
+ switch (key) {
+ case 's':
+ case 'S':
+ if (isRecording) {
+ oniRecorder.stopRecord();
+ isRecording = false;
+ break;
+ } else {
+ oniRecorder.startRecord(generateFileName());
+ isRecording = true;
+ break;
+ }
+ break;
+ case 'p':
+ case 'P':
+ if (oniRecorder.getCurrentFileName() != "" && !isRecording && isLive) {
+ setupPlayback(oniRecorder.getCurrentFileName());
+ isLive = false;
+ whichUser=&playUser;
+ whichImage=&playImage;
+ } else {
+ isLive = true;
+ whichUser=&recordUser;
+ whichImage=&recordImage;
+ }
+ break;
+ }
}
//--------------------------------------------------------------
diff --git a/TRRSS_01_rec/src/testApp.h b/TRRSS_01_rec/src/testApp.h
index 629ee98..225abc8 100755
--- a/TRRSS_01_rec/src/testApp.h
+++ b/TRRSS_01_rec/src/testApp.h
@@ -15,7 +15,7 @@
#include "ofxMayaCam.h"
-#define NEWAPI true
+//#define NEWAPI
class guiWindow;
@@ -37,15 +37,28 @@ class testApp : public ofxFensterListener{
void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg);
+ string generateFileName();
+ void setupRecording(string _filename = "");
+ void setupPlayback(string _filename);
+
+ ofxOpenNIRecorder oniRecorder;
+
+ bool isLive, isRecording;
+
#ifdef NEWAPI
ofxOpenNI openNIDevice;
void userEvent(ofxOpenNIUserEvent & event);
#else
- ofxOpenNIContext recordContext;
- ofxDepthGenerator recordDepth;
- ofxImageGenerator recordImage;
- ofxUserGenerator recordUser;
+
+
+ ofxOpenNIContext recordContext,playContext;
+ ofxDepthGenerator recordDepth,playDepth;
+ ofxImageGenerator recordImage,playImage;
+ ofxUserGenerator recordUser,playUser;
+
+ ofxImageGenerator *whichImage;
+ ofxUserGenerator *whichUser;
#endif
@@ -85,7 +98,7 @@ class guiWindow: public ofxFensterListener{
pointSize=2.0;
gui.add(pSize.setup("point size",pointSize,0.0,20.0,255));
insideOut=false;
- gui.add(iOut.setup("inside out",drawPoints));
+ gui.add(iOut.setup("inside out",insideOut));
}
void draw() { gui.draw(); }