Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include ofxKinect addon #2

Open
wants to merge 27 commits into
base: kinectbranch
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d04cb1f
:bug: fix mqtt app name
jdub233 Aug 19, 2022
e2ff1b0
declare the video app in the app manager
jdub233 Aug 19, 2022
bfc4ed8
:sparkles: basic video app implementation
jdub233 Aug 19, 2022
4b65574
run the video app setup method
jdub233 Aug 19, 2022
2d791af
:video_camera: add escher mode video
jdub233 Aug 19, 2022
32cf343
project settings
jdub233 Aug 19, 2022
0bfff69
grab the frame pixels and iterate over them
jdub233 Aug 20, 2022
5923b99
:package: xcode group reference for addons
jdub233 Aug 28, 2022
145e400
:package: including ofxKinect should work
jdub233 Aug 28, 2022
2c99e91
:alembic: temp kinect include
jdub233 Aug 28, 2022
b52d3f9
rough pixel filtering code
jdub233 Oct 6, 2022
05ccd58
get video working
Oct 12, 2022
dd39eb5
:pencil: Doc comments
jdub233 Oct 16, 2022
b4e1210
:fire: remove debug
Oct 16, 2022
df0290d
use m_videoPixels instead of plz
Oct 16, 2022
2b1221c
remove m_blockWidth property
jdub233 Oct 18, 2022
aeb2763
remove debug
jdub233 Oct 18, 2022
291b692
rename unwrapped to flattened
jdub233 Oct 18, 2022
78fa7b0
:pencil: add comment
jdub233 Oct 18, 2022
900e44e
Merge pull request #3 from mitmedialab/video-app-pixels
jdub233 Oct 18, 2022
a9f23fa
merge video app from main branch
jdub233 Oct 18, 2022
843942f
initial kinect manager
Oct 18, 2022
f151497
add pbxproj
Oct 18, 2022
f46671e
fixes
jdub233 Oct 19, 2022
a910a6c
:truck: move kinect manager files
Dec 8, 2022
3e82f43
instantiate the kinect manager
Dec 8, 2022
18dc83d
update kinect manager references
Dec 8, 2022
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
Binary file added bin/data/escher-5-slow.mov
Binary file not shown.
243 changes: 241 additions & 2 deletions neoForm.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/AppManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,27 @@ void AppManager::setup(){
// initialize shape display and set up helper objects
setupShapeDisplayManagement();

// setup external devices (e.g., kinect)
kinectManager = new KinectManager();

// zero timeOfLastUpdate tracker
timeOfLastUpdate = elapsedTimeInSeconds();

// set up applications
mqttApp = new MqttTransmissionApp();
applications["mqttTransmission"] = mqttApp;

videoPlayerApp = new VideoPlayerApp();
applications["videoPlayer"] = videoPlayerApp;
videoPlayerApp->setup();

// set up debugging application
// and the debugging apps, too
axisCheckerApp = new AxisCheckerApp();
applications["axisChecker"] = axisCheckerApp;

kinectDebugApp = new KinectDebugApp();
applications["kinectDebug"] = kinectDebugApp;
// give applications read access to input data
for (map<string, Application *>::iterator iter = applications.begin(); iter != applications.end(); iter++) {
Application *app = iter->second;
Expand Down Expand Up @@ -240,6 +249,10 @@ void AppManager::keyPressed(int key) {
setCurrentApplication("mqttTransmission");
} else if (key == '2') {
setCurrentApplication("axisChecker");
} else if (key == '3') {
setCurrentApplication("videoPlayer");
} else if (key == '4') {
setCurrentApplication("kinectDebug");
}

// forward unreserved keys to the application
Expand Down
16 changes: 16 additions & 0 deletions src/AppManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,23 @@
#include "ShapeIOManager.hpp"
#include "TransformIOManager.hpp"

// External Device Managers
#include "KinectManager.hpp"

// major classes
#include "Application.hpp"

// debugging applications
#include "AxisCheckerApp.hpp"

#include "KinectDebugApp.hpp"

// mqtt application
#include "MqttTransmissionApp.hpp"

// static applications
#include "VideoPlayerApp.hpp"

class AppManager : public ofBaseApp {

public:
Expand Down Expand Up @@ -58,16 +66,24 @@ class AppManager : public ofBaseApp {
// interfaces to the peripherals
ShapeIOManager *shapeIOManager;

// external devices
KinectManager *kinectManager;

// applications
map<string, Application *> applications;
Application *currentApplication;

// debugging applications
AxisCheckerApp *axisCheckerApp;
KinectDebugApp *kinectDebugApp;

// mqtt application
MqttTransmissionApp *mqttApp;

// static applications
VideoPlayerApp *videoPlayerApp;


// program state
bool paused = false;
double timeOfLastUpdate = -1;
Expand Down
1 change: 1 addition & 0 deletions src/Applications/DebuggingApps/AxisCheckerApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include <stdio.h>
#include "Application.hpp"
#include "KinectManager.hpp"


class AxisCheckerApp : public Application {
Expand Down
17 changes: 17 additions & 0 deletions src/Applications/DebuggingApps/KinectDebugApp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// KinectDebugApp.cpp
// neoForm
//
// Created by admin on 10/18/22.
//

#include "KinectDebugApp.hpp"

void KinectDebugApp::update(float dt) {
cout << "we updatin";
}

void KinectDebugApp::drawGraphicsForShapeDisplay(int x, int y, int width, int height){
cout << "they see us rollin, they hatin";
}

27 changes: 27 additions & 0 deletions src/Applications/DebuggingApps/KinectDebugApp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// KinectDebugApp.hpp
// neoForm
//
// Created by admin on 10/18/22.
//

#ifndef KinectDebugApp_hpp
#define KinectDebugApp_hpp

#include <stdio.h>
#include "Application.hpp"
#include "KinectManager.hpp"

class KinectDebugApp : public Application{
public:
// KinectDebugApp();
// ~KinectDebugApp();

void update(float dt);
void drawGraphicsForShapeDisplay(int x, int y, int width, int height);

// near and far boundary values for depth data captured, specified in millimeters
//pair<int, int> getDepthInputBoundaries();
};

#endif /* KinectDebugApp_hpp */
2 changes: 1 addition & 1 deletion src/Applications/MqttTransmissionApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MqttTransmissionApp : public Application {
string appInstructionsText();
void keyPressed(int key);

string getName() {return "Axis Checker";};
string getName() {return "Mqtt Transmission";};

// commands for mqtt
ofxMQTT client;
Expand Down
119 changes: 119 additions & 0 deletions src/Applications/VideoPlayerApp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
//
// VideoPlayerApp.cpp
// neoForm
//
// Created by Jonathan Williams on 8/17/22.
//

#include "VideoPlayerApp.hpp"

void VideoPlayerApp::setup() {
setupTransformedPixelMap();
video.load("escher-5-slow.mov");
video.play();
}

void VideoPlayerApp::update(float dt) {
video.update();
updateHeights();
}

void VideoPlayerApp::updateHeights() {
// Get pixel values from the video and map them to pin heights here.
// m_videoPixels is the stored pixels from the current video frame, stored in this app header.
m_videoPixels = video.getPixels();

// Grayscale ensures that there is only one brightness value per pixel (instead of three channel RGB).
m_videoPixels.setImageType(OF_IMAGE_GRAYSCALE);

for (int x = 0; x < SHAPE_DISPLAY_SIZE_X; x++) {

for (int y = 0; y < SHAPE_DISPLAY_SIZE_Y; y++) {

// This takes the 2 dimensional coordinates and turns them into a one dimensional index for the flattened array.
int flattenedIndex = heightsForShapeDisplay.getPixelIndex(x, y);

// This takes the 1 dimensional index for the pin, and grabs the corresponding index from the uncorrected video pixel array.
heightsForShapeDisplay[flattenedIndex] = m_videoPixels[m_videoToTransformIndicies[flattenedIndex]];
}
}
}

void VideoPlayerApp::drawGraphicsForShapeDisplay(int x, int y, int width, int height) {
// Draw the video file.
video.draw(30, 300, 544, 128);
}

string VideoPlayerApp::appInstructionsText() {
string instructions = (string) "Plays video files";

return instructions;
}


// Given an x coordinate from the video (102 pixels wide),
// We chop in into 6 segments
// Segments that are used for actuation are 2, 4, 6
// Other segments are not used by TRANSFORM
// so 102 divided into 6 segments, means each segment is 17 pixels wide
// + 5 pixels on each border
// The returned block number is the number of the block where the
// video pixel input to the function ends up.
// blocks 1,3,5, useless
// blocks 2,4,6 used in transform
int VideoPlayerApp::calculateBlockNumber(int x_pixel_coord){
//note: int divison returns a truncated result that looks like a floor:
// 1/2 would return 0, 4/2.5 would return 1
int blockNum = ((x_pixel_coord+5)/16)+1;

return blockNum;
}

// Once block has been established, the
// x coordinate of the video pixel, and the block number are input to this function.
// If its a useless block, (1, 3, or 5), made 0, will never be shown
// If it is in a useful block (2,4,6), x_pixel coordinate will be translated into
// x coordinate on the TRANSFORM pin.
int VideoPlayerApp::calculateWithinBlockX(int blockNumber, int x_pixel_coord){
int blockDead = blockNumber%2;

// Find actual location on TRANSFORM grid from video
// NOTE TRANSFORM display is 48 pixels wide.
// NOTE video pixels are 102 wide with 5 pixel buffer on left side. (hence 107 below)
// right side also has a 5 pixel buffer, but doesn't matter for our caculation
int TRANSFORM_x = (int)((48.0/107.0)*(float)(x_pixel_coord+5));

if (blockDead){
//we discard the dead block
TRANSFORM_x = 0;
}

return TRANSFORM_x;
}

// Runs only once on initialization.
// Fills the m_videoToTransformIndicies array with a map between flattened TRANSFORM pin numbers
// and flattened video pixels.
// m_videoToTransformIndicies(flattened TRANSFORM pixel index) = (flattened video pixel index)
// To assign TRANSFORM pixel video pixels values in the update, do something like
// (pseudocode) ==> TRANSFORM_Pin_Height(pin1) = m_video_toTransformIndicies(pin1);
void VideoPlayerApp::setupTransformedPixelMap(){
int counter = 0;

// Iterate over all pixels in the video frame.
for (int y = 0; y < 24; y++) {
for (int x = 0; x < 102; x++) {
int blockAliveXCoord = calculateWithinBlockX(calculateBlockNumber(x),x);

if (blockAliveXCoord){
m_videoToTransformIndicies[counter] = 102*y+x;
counter++;
cout << "one made it \n";
}
}
}
}

void VideoPlayerApp::keyPressed(int key) {
// no-op
}
39 changes: 39 additions & 0 deletions src/Applications/VideoPlayerApp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// VideoPlayerApp.hpp
// neoForm
//
// Created by Jonathan Williams on 8/17/22.
//

#ifndef VideoPlayerApp_hpp
#define VideoPlayerApp_hpp

#include <stdio.h>
#include "Application.hpp"

class VideoPlayerApp : public Application {
public:
void setup();
void update(float dt);
void drawGraphicsForShapeDisplay(int x, int y, int width, int height);
string appInstructionsText();
void keyPressed(int key);

string getName() {return "Video Player";}

private:
void updateHeights();
ofVideoPlayer video;
int calculateBlockNumber(int x_pixel_coord);
int calculateWithinBlockX(int blockNumber, int x_pixel_coord);
void setupTransformedPixelMap();

int m_videoToTransformIndicies[1152];
int m_videoPixelSize = 2448;

ofPixels m_videoPixels;


};

#endif /* VideoPlayerApp_hpp */
8 changes: 0 additions & 8 deletions src/ExternalDeviceManagers/KinectManager.cpp

This file was deleted.

13 changes: 0 additions & 13 deletions src/ExternalDeviceManagers/KinectManager.hpp

This file was deleted.

Loading