Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Working DistortablePlane (switch to ofxPolyPlane)

  • Loading branch information...
commit 1b9267ce38cd0c4d6076eb526e3a702473c7b4c8 1 parent 53af785
@elliotwoods authored
View
24 ofxPolyfitExample-VideoDistort/src/DistortablePlane.cpp
@@ -6,7 +6,7 @@
#include "DistortablePlane.h"
DistortablePlane::DistortablePlane() :
-radius(10.0f) {
+radius(15.0f) {
this->source = 0;
this->shift = false;
@@ -35,16 +35,25 @@ void DistortablePlane::draw() {
}
if (this->calibrateMode) {
+ ofPushStyle();
+ ofNoFill();
+ ofEnableAlphaBlending();
+
+ ofSetColor(255, 255, 255, 50);
mesh.drawWireframe();
+ ofSetColor(255, 255, 255);
pfitDataPointf point;
for (point = calibration.begin(); point != calibration.end(); ++point) {
+
if (selection == point)
- ofFill();
+ ofSetLineWidth(3.0f);
else
- ofNoFill();
+ ofSetLineWidth(1.0f);
+
ofCircle(point.getOutput()[0], point.getOutput()[1], radius);
}
+ ofPopStyle();
}
}
@@ -59,6 +68,14 @@ void DistortablePlane::setCalibrateMode(const bool calibrateMode) {
this->calibrateMode = calibrateMode;
}
+bool DistortablePlane::getCalibrateMode() const {
+ return this->calibrateMode;
+}
+
+bool DistortablePlane::toggleCalibrateMode() {
+ this->calibrateMode ^= true;
+}
+
void DistortablePlane::setGridResolution(int resolution) {
if (resolution < 2) {
@@ -216,6 +233,7 @@ void DistortablePlane::mouseDragged(ofMouseEventArgs &args) {
void DistortablePlane::load(string filename) {
this->calibration.load(filename);
+ this->updateGrid();
}
void DistortablePlane::save(string filename) {
View
6 ofxPolyfitExample-VideoDistort/src/DistortablePlane.h
@@ -15,7 +15,11 @@ class DistortablePlane {
void draw();
void setSource(ofBaseHasTexture & source);
+
void setCalibrateMode(const bool calibrateMode);
+ bool getCalibrateMode() const;
+ bool toggleCalibrateMode();
+
void setGridResolution(int resolution);
//remember to call this if you change the video's resolution, or control points
@@ -42,12 +46,12 @@ class DistortablePlane {
protected:
ofxPolyFit fit;
ofMesh mesh;
- ofRectangle defaultBounds;
ofBaseHasTexture * source;
bool calibrateMode;
int gridResolution;
+ ofRectangle defaultBounds;
const float radius;
bool hit;
View
32 ofxPolyfitExample-VideoDistort/src/testApp.cpp
@@ -10,6 +10,7 @@ void testApp::setup(){
plane.setSource(video);
plane.setCalibrateMode(true);
+ plane.load("warp.bin");
}
//--------------------------------------------------------------
@@ -21,20 +22,31 @@ void testApp::update(){
void testApp::draw(){
plane.draw();
- int y = 20;
- ofDrawBitmapString("Use the handles to warp and move the video", 20, y+=10);
- ofDrawBitmapString("[SPACE] = toggle calibration mode", 20, y+=10);
- ofDrawBitmapString("Use mouse to select points and warp the video", 20, y+=10);
- ofDrawBitmapString("[TAB] = select points", 20, y+=10);
- ofDrawBitmapString("[UP]/[DOWN]/[LEFT]/RIGHT = move the selected point", 20, y+=10);
- ofDrawBitmapString("[SHIFT] + arrow key = move the selected point faster", 20, y+=10);
- ofDrawBitmapString("[r] = reset calibration", 20, y+=10);
-
+ if (plane.getCalibrateMode()) {
+ int y = 20;
+ ofDrawBitmapString("Use the handles to warp and move the video", 20, y+=15);
+ ofDrawBitmapString("[SPACE] = toggle calibration mode", 20, y+=10);
+ ofDrawBitmapString("Use mouse to select points and warp the video", 20, y+=15);
+ ofDrawBitmapString("[TAB] = select points", 20, y+=15);
+ ofDrawBitmapString("[UP]/[DOWN]/[LEFT]/RIGHT = move the selected point", 20, y+=15);
+ ofDrawBitmapString("[SHIFT] + arrow key = move the selected point faster", 20, y+=15);
+ ofDrawBitmapString("[r] = reset calibration", 20, y+=15);
+ }
}
//--------------------------------------------------------------
void testApp::keyPressed (int key){
-
+ if (key == ' ') {
+ plane.toggleCalibrateMode();
+ if (plane.getCalibrateMode())
+ ofBackground(50);
+ else
+ ofBackground(0);
+ }
+ if (key == 's')
+ plane.save("warp.bin");
+ if (key == 'l')
+ plane.load("warp.bin");
}
//--------------------------------------------------------------
Please sign in to comment.
Something went wrong with that request. Please try again.