Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Working DistortablePlane (switch to ofxPolyPlane)

  • Loading branch information...
commit 1b9267ce38cd0c4d6076eb526e3a702473c7b4c8 1 parent 53af785
Elliot Woods authored
24 ofxPolyfitExample-VideoDistort/src/DistortablePlane.cpp
@@ -6,7 +6,7 @@
6 6 #include "DistortablePlane.h"
7 7
8 8 DistortablePlane::DistortablePlane() :
9   -radius(10.0f) {
  9 +radius(15.0f) {
10 10
11 11 this->source = 0;
12 12 this->shift = false;
@@ -35,16 +35,25 @@ void DistortablePlane::draw() {
35 35 }
36 36
37 37 if (this->calibrateMode) {
  38 + ofPushStyle();
  39 + ofNoFill();
  40 + ofEnableAlphaBlending();
  41 +
  42 + ofSetColor(255, 255, 255, 50);
38 43 mesh.drawWireframe();
  44 + ofSetColor(255, 255, 255);
39 45
40 46 pfitDataPointf point;
41 47 for (point = calibration.begin(); point != calibration.end(); ++point) {
  48 +
42 49 if (selection == point)
43   - ofFill();
  50 + ofSetLineWidth(3.0f);
44 51 else
45   - ofNoFill();
  52 + ofSetLineWidth(1.0f);
  53 +
46 54 ofCircle(point.getOutput()[0], point.getOutput()[1], radius);
47 55 }
  56 + ofPopStyle();
48 57 }
49 58 }
50 59
@@ -59,6 +68,14 @@ void DistortablePlane::setCalibrateMode(const bool calibrateMode) {
59 68 this->calibrateMode = calibrateMode;
60 69 }
61 70
  71 +bool DistortablePlane::getCalibrateMode() const {
  72 + return this->calibrateMode;
  73 +}
  74 +
  75 +bool DistortablePlane::toggleCalibrateMode() {
  76 + this->calibrateMode ^= true;
  77 +}
  78 +
62 79 void DistortablePlane::setGridResolution(int resolution) {
63 80
64 81 if (resolution < 2) {
@@ -216,6 +233,7 @@ void DistortablePlane::mouseDragged(ofMouseEventArgs &args) {
216 233
217 234 void DistortablePlane::load(string filename) {
218 235 this->calibration.load(filename);
  236 + this->updateGrid();
219 237 }
220 238
221 239 void DistortablePlane::save(string filename) {
6 ofxPolyfitExample-VideoDistort/src/DistortablePlane.h
@@ -15,7 +15,11 @@ class DistortablePlane {
15 15 void draw();
16 16
17 17 void setSource(ofBaseHasTexture & source);
  18 +
18 19 void setCalibrateMode(const bool calibrateMode);
  20 + bool getCalibrateMode() const;
  21 + bool toggleCalibrateMode();
  22 +
19 23 void setGridResolution(int resolution);
20 24
21 25 //remember to call this if you change the video's resolution, or control points
@@ -42,12 +46,12 @@ class DistortablePlane {
42 46 protected:
43 47 ofxPolyFit fit;
44 48 ofMesh mesh;
45   - ofRectangle defaultBounds;
46 49
47 50 ofBaseHasTexture * source;
48 51
49 52 bool calibrateMode;
50 53 int gridResolution;
  54 + ofRectangle defaultBounds;
51 55
52 56 const float radius;
53 57 bool hit;
32 ofxPolyfitExample-VideoDistort/src/testApp.cpp
@@ -10,6 +10,7 @@ void testApp::setup(){
10 10
11 11 plane.setSource(video);
12 12 plane.setCalibrateMode(true);
  13 + plane.load("warp.bin");
13 14 }
14 15
15 16 //--------------------------------------------------------------
@@ -21,20 +22,31 @@ void testApp::update(){
21 22 void testApp::draw(){
22 23 plane.draw();
23 24
24   - int y = 20;
25   - ofDrawBitmapString("Use the handles to warp and move the video", 20, y+=10);
26   - ofDrawBitmapString("[SPACE] = toggle calibration mode", 20, y+=10);
27   - ofDrawBitmapString("Use mouse to select points and warp the video", 20, y+=10);
28   - ofDrawBitmapString("[TAB] = select points", 20, y+=10);
29   - ofDrawBitmapString("[UP]/[DOWN]/[LEFT]/RIGHT = move the selected point", 20, y+=10);
30   - ofDrawBitmapString("[SHIFT] + arrow key = move the selected point faster", 20, y+=10);
31   - ofDrawBitmapString("[r] = reset calibration", 20, y+=10);
32   -
  25 + if (plane.getCalibrateMode()) {
  26 + int y = 20;
  27 + ofDrawBitmapString("Use the handles to warp and move the video", 20, y+=15);
  28 + ofDrawBitmapString("[SPACE] = toggle calibration mode", 20, y+=10);
  29 + ofDrawBitmapString("Use mouse to select points and warp the video", 20, y+=15);
  30 + ofDrawBitmapString("[TAB] = select points", 20, y+=15);
  31 + ofDrawBitmapString("[UP]/[DOWN]/[LEFT]/RIGHT = move the selected point", 20, y+=15);
  32 + ofDrawBitmapString("[SHIFT] + arrow key = move the selected point faster", 20, y+=15);
  33 + ofDrawBitmapString("[r] = reset calibration", 20, y+=15);
  34 + }
33 35 }
34 36
35 37 //--------------------------------------------------------------
36 38 void testApp::keyPressed (int key){
37   -
  39 + if (key == ' ') {
  40 + plane.toggleCalibrateMode();
  41 + if (plane.getCalibrateMode())
  42 + ofBackground(50);
  43 + else
  44 + ofBackground(0);
  45 + }
  46 + if (key == 's')
  47 + plane.save("warp.bin");
  48 + if (key == 'l')
  49 + plane.load("warp.bin");
38 50 }
39 51
40 52 //--------------------------------------------------------------

0 comments on commit 1b9267c

Please sign in to comment.
Something went wrong with that request. Please try again.