summaryrefslogtreecommitdiff
path: root/05_pointcloud/src
diff options
context:
space:
mode:
authorTim Redfern <tim@eclectronics.org>2013-06-17 15:32:14 +0100
committerTim Redfern <tim@eclectronics.org>2013-06-17 15:32:14 +0100
commit2395f29308fb424eaf9b9ebb08022568a117b0f0 (patch)
treeca81402f792a1118b027ae0ad415e73659ff998b /05_pointcloud/src
parent51df1cfbacd02cd362c82141a161f2fe859b8431 (diff)
back to user pointclouds
Diffstat (limited to '05_pointcloud/src')
-rw-r--r--05_pointcloud/src/main.cpp17
-rw-r--r--05_pointcloud/src/testApp.cpp281
-rw-r--r--05_pointcloud/src/testApp.h56
3 files changed, 354 insertions, 0 deletions
diff --git a/05_pointcloud/src/main.cpp b/05_pointcloud/src/main.cpp
new file mode 100644
index 0000000..f0d25bb
--- /dev/null
+++ b/05_pointcloud/src/main.cpp
@@ -0,0 +1,17 @@
+
+#include "testApp.h"
+#include "ofMain.h"
+#include "ofAppGlutWindow.h"
+
+//========================================================================
+int main( ){
+
+ ofAppGlutWindow window;
+ ofSetupOpenGL(&window, 1200,800, OF_WINDOW); // <-------- setup the GL context
+
+ // this kicks off the running of my app
+ // can be OF_WINDOW or OF_FULLSCREEN
+ // pass in width and height too:
+ ofRunApp( new testApp());
+
+}
diff --git a/05_pointcloud/src/testApp.cpp b/05_pointcloud/src/testApp.cpp
new file mode 100644
index 0000000..6532b57
--- /dev/null
+++ b/05_pointcloud/src/testApp.cpp
@@ -0,0 +1,281 @@
+#include "testApp.h"
+
+//--------------------------------------------------------------
+void testApp::setup() {
+
+ ofSetLogLevel(OF_LOG_NOTICE);
+
+ verdana.loadFont(ofToDataPath("verdana.ttf"), 10);
+
+ playing=0;
+ numDevices=2;
+
+ string filename="TRSS_nesbitt_recordings.xml";
+
+ if( !XML.loadFile(filename) ){
+ printf("unable to load recordings, check data/ folder\n");
+ }else{
+ if(XML.pushTag("TRSS")) {
+ int num=XML.getNumTags("rec");
+ if(num) {
+ for (int i=0;i<num;i++) {
+ record rec;
+ rec.data.push_back(XML.getAttribute("rec","left","",i));
+ rec.data.push_back(XML.getAttribute("rec","right","",i));
+ rec.audio=XML.getAttribute("rec","audio","",i);
+ recs.push_back(rec);
+ }
+ }
+ else printf("no recordings!\n");
+ }
+ }
+ ofxOpenNIUser user;
+ user.setUseMaskTexture(true);
+ user.setUsePointCloud(true);
+ user.setPointCloudDrawSize(2); // this is the size of the glPoint that will be drawn for the point cloud
+ user.setPointCloudResolution(2); // this is the step size between points for the cloud -> eg., this sets it to every second point
+
+ for (int deviceID = 0; deviceID < numDevices; deviceID++){
+
+ //openNIPlayers[deviceID].stop();
+ openNIPlayers[deviceID].setup(true);
+ openNIPlayers[deviceID].addUserGenerator();
+ openNIPlayers[deviceID].setRegister(true);
+ openNIPlayers[deviceID].start();
+ openNIPlayers[deviceID].setBaseUserClass(user);
+ //openNIPlayers[deviceID].startPlayer(ofToDataPath(recs[playing][deviceID]));
+ }
+ soundplayer.setLoop(false);
+ startPlayers();
+
+ //ofSetFrameRate(25.0f);
+ offset=0.0f;
+ drawmovies=false;drawcloud=true;
+ frame=0;
+}
+
+void testApp::startPlayers(){
+ for (int deviceID = 0; deviceID < numDevices; deviceID++){
+ //openNIPlayers[deviceID].stop();
+ //openNIPlayers[deviceID].setup(false);
+ //openNIPlayers[deviceID].start();
+ openNIPlayers[deviceID].startPlayer(ofToDataPath(recs[playing].data[deviceID]));
+ openNIPlayers[deviceID].setSpeed(0.01f);
+ //openNIPlayers[deviceID].setPaused(true);
+
+
+ soundplayer.stop();
+
+ if (recs[playing].audio!=""){
+ soundplayer.loadSound(recs[playing].audio);
+ soundplayer.play();
+ soundplayer.setPosition(offset);
+ }
+ }
+}
+
+//--------------------------------------------------------------
+void testApp::update(){
+ for (int deviceID = 0; deviceID < numDevices; deviceID++){
+ openNIPlayers[deviceID].setFrame(frame);
+ openNIPlayers[deviceID].update();
+ }
+}
+
+//--------------------------------------------------------------
+void testApp::draw(){
+ ofBackground(50, 50, 50);
+ ofSetColor(255, 255, 255);
+
+
+
+ //glEnable(GL_PROGRAM_POINT_SIZE);
+ //glEnable(GL_POINT_SMOOTH);
+ //glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
+
+ //glPointSize(12.0f);
+
+
+
+ for (int deviceID = 0; deviceID < numDevices; deviceID++){
+
+ if (drawmovies) {
+ ofTranslate(0, deviceID * 400);
+ //openNIPlayers[deviceID].drawDebug();
+ openNIPlayers[deviceID].drawDepth(50, 0,520,390);
+ openNIPlayers[deviceID].drawImage(600, 0,520,390);
+ }
+
+ //construct points
+ //glBegin(GL_POINTS);
+ //how to find buffer size?
+ /*
+ XnStatus xn::DepthGenerator::ConvertProjectiveToRealWorld ( XnUInt32 nCount,
+ const XnPoint3D aProjective[],
+ XnPoint3D aRealWorld[]
+ )
+ */
+
+ if (drawcloud) {
+
+ cam.begin();
+
+ ofPushMatrix();
+ ofRotate(0,1,0,180);
+ ofTranslate(0,0,1500);
+
+
+
+
+ ofDrawAxis(100);
+
+ int count;
+ const XnDepthPixel* depthmap=openNIPlayers[deviceID].getDepthGenerator().GetDepthMap();
+ int range=2500;
+
+ int dmw=openNIPlayers[deviceID].getWidth();
+
+ for (int i=0;i<openNIPlayers[deviceID].getWidth();i+=2) {
+
+ glBegin(GL_LINES);
+
+ for (int j=0;j<openNIPlayers[deviceID].getHeight();j+=2) {
+
+
+
+ ofPoint p= openNIPlayers[deviceID].projectiveToWorld(ofPoint(i,j,(float)depthmap[j*dmw+i]));
+ //ofPoint p= projectiveToWorld(ofPoint(i,j,(float)depthmap[j*dmw+i]));
+
+ if (p.z == 0 || p.z>range) continue; // gets rid of background -> still a bit weird if userID > 0... //&& isCPBkgnd
+ //ofColor color = kinect->getColorAt(x,y); //userID);
+ //if (col) glColor4ub((unsigned char)color.r, (unsigned char)color.g, (unsigned char)color.b, (unsigned char)color.a);
+ // else
+
+
+ glColor4ub((unsigned char)255, (unsigned char)255, (unsigned char)255, (unsigned char)255);
+ glVertex3f(p.x, p.y, p.z);
+ //if (i==320&&j==160) cerr<<"world point: "<<p.x<<","<<p.y<<","<<p.z<<endl;
+ }
+
+ glEnd();
+ }
+
+
+ //export for fast/ switchable playback
+ //figure out how to line up (could be one off)
+ //export frame and find matching coords
+ //manually find positions
+ //calculate offset
+ //audio sync
+ //gui
+ //audio analysis
+ //sfx for point cloud
+
+ //
+
+ ofPopMatrix();
+
+ cam.end();
+
+ glDisable(GL_PROGRAM_POINT_SIZE);
+
+ }
+ }
+
+ ofSetColor(255, 255, 255);
+ string msg = "MILLIS: " + ofToString(ofGetElapsedTimeMillis());
+ msg += "\nFPS: " + ofToString(ofGetFrameRate());
+ msg += "\noffset: "+ofToString(offset);
+ verdana.drawString(msg, 10, 10);
+}
+
+//--------------------------------------------------------------
+void testApp::exit(){
+ for (int deviceID = 0; deviceID < numDevices; deviceID++){
+ openNIPlayers[deviceID].stop();
+ }
+}
+
+//--------------------------------------------------------------
+void testApp::keyPressed(int key){
+ bool changed=false;
+ switch (key) {
+ case ',':
+ if (playing==0) playing=recs.size();
+ playing--;
+ changed=true;
+ break;
+ case '.':
+ playing=(playing+1)%recs.size();
+ changed=true;
+ break;
+ case 'z':
+ offset+=.025;
+ break;
+ case 'x':
+ offset-=.025;
+ break;
+ case 'q':
+ drawmovies=!drawmovies;
+ break;
+ case 'w':
+ drawcloud=!drawcloud;
+ break;
+ case 'a':
+ frame--;
+ if (frame<0) frame=openNIPlayers[0].getTotalNumFrames()-1;
+ break;
+ case 's':
+ frame=((frame+1)%openNIPlayers[0].getTotalNumFrames());
+ break;
+ }
+ if (changed) startPlayers();
+
+ /* why do this?
+ switch (key) {
+ case 't':
+ for (int deviceID = 0; deviceID < numDevices; deviceID++){
+ openNIRecorders[deviceID].toggleRegister();
+ }
+ break;
+ case 'x':
+ for (int deviceID = 0; deviceID < numDevices; deviceID++){
+ openNIRecorders[deviceID].stop();
+ }
+ break;
+ default:
+ break;
+ }
+ */
+}
+
+//--------------------------------------------------------------
+void testApp::keyReleased(int key){
+
+}
+
+//--------------------------------------------------------------
+void testApp::mouseMoved(int x, int y ){
+
+}
+
+//--------------------------------------------------------------
+void testApp::mouseDragged(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void testApp::mousePressed(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void testApp::mouseReleased(int x, int y, int button){
+
+}
+
+//--------------------------------------------------------------
+void testApp::windowResized(int w, int h){
+
+}
+
diff --git a/05_pointcloud/src/testApp.h b/05_pointcloud/src/testApp.h
new file mode 100644
index 0000000..67cd4dc
--- /dev/null
+++ b/05_pointcloud/src/testApp.h
@@ -0,0 +1,56 @@
+#ifndef _TEST_APP
+#define _TEST_APP
+
+#include "ofxOpenNI.h"
+#include "ofMain.h"
+#include "ofxXmlSettings.h"
+#include "ofxMayaCam.h"
+
+#define MAX_DEVICES 2
+
+struct record{
+ vector<string> data;
+ string audio;
+};
+
+class testApp : public ofBaseApp{
+
+public:
+ void setup();
+ void update();
+ void draw();
+ void exit();
+
+ void keyPressed (int key);
+ void keyReleased(int key);
+ void mouseMoved(int x, int y );
+ void mouseDragged(int x, int y, int button);
+ void mousePressed(int x, int y, int button);
+ void mouseReleased(int x, int y, int button);
+ void windowResized(int w, int h);
+
+ void startPlayers();
+
+ int numDevices;
+ ofxOpenNI openNIPlayers[MAX_DEVICES];
+
+ int playing;
+
+ ofTrueTypeFont verdana;
+
+ ofxXmlSettings XML;
+
+ vector<record> recs;
+
+ ofSoundPlayer soundplayer;
+
+ float offset;
+
+ ofxMayaCam cam;
+
+ bool drawmovies,drawcloud;
+ int frame;
+
+};
+
+#endif