Skip to content

Commit

Permalink
Merge pull request #11 from mitmedialab/previews
Browse files Browse the repository at this point in the history
Improved previews
  • Loading branch information
jdub233 authored Apr 28, 2024
2 parents 757fe70 + b98262b commit 849511e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/Applications/KinectHandWavy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,13 @@ void KinectHandWavy::drawPreviewMaskRectangle() {

// Draw a semi-transparent rectangle over each of the three the actuated sections.
void KinectHandWavy::drawPreviewActuatedSections() {

// Get the width in inches of the the full transform surface (need to cast shape display manager object first).
float transformWidth = ((TransformIOManager*)m_CustomShapeDisplayManager)->m_Transform_W;

// Get the actuated section dimensions from the CustomShapeDisplayManager
float pixelsPerInch = m_kinectManager->m_mask.getWidth() / 104.75 ; // <-- this is a problem, the transform width (104.75) needs to be available from the apps.
float pixelsPerInch = m_kinectManager->m_mask.getWidth() / transformWidth;

std::vector<ofRectangle> sections = m_CustomShapeDisplayManager->createSections(pixelsPerInch);

// Create a frame buffer with the same dimensions as the cropped signal.
Expand Down
42 changes: 38 additions & 4 deletions src/Applications/VideoPlayerApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ void VideoPlayerApp::updateHeights() {

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

//ofPixels onlyPinPixels = m_CustomShapeDisplayManager->getPinPixelsOnly(m_videoPixels);


// Pass the current video frame to the shape display manager to get the actuated pixels.
ofPixels livePixels = m_CustomShapeDisplayManager->cropToActiveSurface(m_videoPixels);

Expand All @@ -45,8 +43,44 @@ void VideoPlayerApp::updateHeights() {
}

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

// Draw the preview of the actuated pixels sections.
drawSectionPreviewFrameBuffer(30, 300, 544, 128);
}

void VideoPlayerApp::drawSectionPreviewFrameBuffer(int x, int y, int width, int height) {
// Get the width in inches of the the full transform surface.
float transformWidth = ((TransformIOManager*)m_CustomShapeDisplayManager)->m_Transform_W;

// Calculate the pixels per inch conversion rate.
float pixelsPerInch = video.getWidth() / transformWidth;

// Create the actuated pixel sections.
std::vector<ofRectangle> sections = m_CustomShapeDisplayManager->createSections(pixelsPerInch);

// Create a frame buffer for the preview with the same dimensions as the video.
ofFbo previewFrameBuffer;
previewFrameBuffer.allocate(video.getWidth(), video.getHeight(), GL_RGBA); // GL_RGBA for transparency

// Begin drawing into the frame buffer
previewFrameBuffer.begin();
ofClear(0, 0, 0, 0); // Clear the buffer with transparent black

// Draw the rectangles into the frame buffer
for (int i = 0; i < sections.size(); i++) {
ofRectangle section = sections[i];

ofSetColor(100,100,255,200);
ofDrawRectangle(section);
}

// End drawing into the frame buffer
previewFrameBuffer.end();

// Draw the frame buffer at the same position and scale as the video
previewFrameBuffer.draw(x, y, width, height);
}

string VideoPlayerApp::appInstructionsText() {
Expand Down
2 changes: 2 additions & 0 deletions src/Applications/VideoPlayerApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class VideoPlayerApp : public Application {
void setup();
void update(float dt);
void drawGraphicsForShapeDisplay(int x, int y, int width, int height);
void drawSectionPreviewFrameBuffer(int x, int y, int width, int height);

string appInstructionsText();
void keyPressed(int key);

Expand Down

0 comments on commit 849511e

Please sign in to comment.