Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/ofxBase3DVideo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*==============================================================================

Copyright (c) 2010, 2011 ofxKinect Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

==============================================================================*/
#pragma once

/// \class ofxBase3DVideo
///
/// a base class for 3D video devices
class ofxBase3DVideo: public ofBaseVideo {

public:

/// get the pixels of the most recent depth frame
virtual unsigned char* getDepthPixels()=0;

/// get the distance in millimeters to a given point as a float array
virtual float* getDistancePixels()=0;

/// get the grayscale depth texture
virtual ofTexture& getDepthTextureReference()=0;
};
39 changes: 38 additions & 1 deletion src/ofxOpenNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ void ofxOpenNI::stop(){
depthTexture.clear();
depthPixels[0].clear();
depthPixels[1].clear();
distancePixels.clear();

cout << LOG_NAME << ": releasing image texture & pixels" << endl;
imageTexture.clear();
Expand All @@ -377,6 +378,14 @@ void ofxOpenNI::stop(){
cout << LOG_NAME << ": full stopped" << endl;
}

void ofxOpenNI::close() {
stop();
}

bool ofxOpenNI::isFrameNew() {
return isNewFrame();
}

//--------------------------------------------------------------
void ofxOpenNI::stopCommon(){
ofxOpenNIScopedLock scopedLock(bIsThreaded, mutex);
Expand Down Expand Up @@ -999,6 +1008,8 @@ void ofxOpenNI::allocateDepthBuffers(){
depthPixels[0].allocate(width, height, OF_IMAGE_COLOR_ALPHA);
depthPixels[1].allocate(width, height, OF_IMAGE_COLOR_ALPHA);
backgroundPixels.allocate(getWidth(), getHeight(), OF_IMAGE_COLOR_ALPHA);
distancePixels.allocate(width, height, 1);
distancePixels.set(0);
currentDepthPixels = &depthPixels[0];
backDepthPixels = &depthPixels[1];
if(bUseTexture) depthTexture.allocate(width, height, GL_RGBA);
Expand Down Expand Up @@ -1372,6 +1383,9 @@ void ofxOpenNI::updateDepthPixels(){
unsigned char * texture = backDepthPixels->getPixels() + y * g_DepthMD.XRes() * 4 + g_DepthMD.XOffset() * 4;
for (int x = 0; x < g_DepthMD.XRes(); x++, depth++, texture += 4){

float* pDistancePixels = distancePixels.getPixels();
pDistancePixels[x+y*g_DepthMD.XRes()] = *depth;

ofColor depthColor;

// bool bUseSubtraction = false;
Expand Down Expand Up @@ -2580,7 +2594,8 @@ bool ofxOpenNI::isNewFrame(){
*************************************************************/

//--------------------------------------------------------------
ofPixels& ofxOpenNI::getDepthPixels(){

ofPixels& ofxOpenNI::getDepthPixelsRef(){
ofxOpenNIScopedLock scopedLock(bIsThreaded, mutex);
if(bUseBackBuffer){
return *currentDepthPixels;
Expand All @@ -2589,6 +2604,10 @@ ofPixels& ofxOpenNI::getDepthPixels(){
}
}

unsigned char* ofxOpenNI::getDepthPixels(){
return getDepthPixelsRef().getPixels();
}

//--------------------------------------------------------------
ofShortPixels& ofxOpenNI::getDepthRawPixels(){
//ofxOpenNIScopedLock scopedLock(bIsThreaded, mutex);
Expand All @@ -2613,6 +2632,24 @@ ofPixels& ofxOpenNI::getImagePixels(){
}
}

ofPixels& ofxOpenNI::getPixelsRef() {
return getImagePixels();
}

unsigned char* ofxOpenNI::getPixels() {
return getImagePixels().getPixels();
}

ofFloatPixels& ofxOpenNI::getDistancePixelsRef() {
return distancePixels;
}

float* ofxOpenNI::getDistancePixels() {
return distancePixels.getPixels();
}



//--------------------------------------------------------------
ofTexture& ofxOpenNI::getDepthTextureReference(){
//ofxOpenNIScopedLock scopedLock(bIsThreaded, mutex);
Expand Down
21 changes: 19 additions & 2 deletions src/ofxOpenNI.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ static int instanceCount = -1;
#include "ofxOpenNITypes.h"
#include "ofxOpenNIUtils.h"

#include "ofxBase3DVideo.h"

using namespace xn;

class ofxOpenNI : public ofThread {
class ofxOpenNI : public ofThread, public ofxBase3DVideo {

public:

Expand Down Expand Up @@ -270,7 +272,7 @@ class ofxOpenNI : public ofThread {
void setSync(bool b);
bool getSync();

ofPixels& getDepthPixels();
ofPixels& getDepthPixelsRef();
ofShortPixels& getDepthRawPixels();
ofPixels& getImagePixels();

Expand Down Expand Up @@ -310,6 +312,19 @@ class ofxOpenNI : public ofThread {
ofEvent<ofxOpenNIGestureEvent> gestureEvent;
ofEvent<ofxOpenNIHandEvent> handEvent;

// Functions to implement interfaces ofBaseVideo and ofxBase3DVideo
void close();
bool isFrameNew();
unsigned char* getPixels();
ofPixels& getPixelsRef();

unsigned char* getDepthPixels();
ofFloatPixels& getDistancePixelsRef();
float* getDistancePixels();




protected:

void threadedFunction();
Expand Down Expand Up @@ -410,6 +425,8 @@ class ofxOpenNI : public ofThread {
ofShortPixels* currentDepthRawPixels;
ofShortPixels backgroundPixels;

ofFloatPixels distancePixels;

const XnDepthPixel* backgroundDepthPixels;

// image
Expand Down