summaryrefslogtreecommitdiff
path: root/gui/src
diff options
context:
space:
mode:
Diffstat (limited to 'gui/src')
-rw-r--r--gui/src/lineTransformer.cpp117
-rw-r--r--gui/src/lineTransformer.h17
-rw-r--r--gui/src/main.cpp42
-rw-r--r--gui/src/ofApp.cpp172
-rw-r--r--gui/src/ofApp.h38
5 files changed, 386 insertions, 0 deletions
diff --git a/gui/src/lineTransformer.cpp b/gui/src/lineTransformer.cpp
new file mode 100644
index 0000000..bf237d7
--- /dev/null
+++ b/gui/src/lineTransformer.cpp
@@ -0,0 +1,117 @@
+#include "lineTransformer.h"
+
+void lineTransformer::drawWarpFrame(glm::vec2 warpframe[4]){
+ ofSetColor(255,255,255);
+ ofNoFill();
+ for (int i=0;i<4;i++){
+ ofDrawCircle(warpframe[i],25);
+ ofDrawLine(warpframe[i],warpframe[(i+1)%4]);
+ }
+}
+
+void lineTransformer::gaussianElimination(float * input, int n)
+{
+ auto i = 0;
+ auto j = 0;
+ auto m = n - 1;
+
+ while (i < m && j < n)
+ {
+ auto iMax = i;
+ for (auto k = i + 1; k < m; ++k)
+ {
+ if (fabs(input[k * n + j]) > fabs(input[iMax * n + j]))
+ {
+ iMax = k;
+ }
+ }
+
+ if (input[iMax * n + j] != 0)
+ {
+ if (i != iMax)
+ {
+ for (auto k = 0; k < n; ++k)
+ {
+ auto ikIn = input[i * n + k];
+ input[i * n + k] = input[iMax * n + k];
+ input[iMax * n + k] = ikIn;
+ }
+ }
+
+ float ijIn = input[i * n + j];
+ for (auto k = 0; k < n; ++k)
+ {
+ input[i * n + k] /= ijIn;
+ }
+
+ for (auto u = i + 1; u < m; ++u)
+ {
+ auto ujIn = input[u * n + j];
+ for (auto k = 0; k < n; ++k)
+ {
+ input[u * n + k] -= ujIn * input[i * n + k];
+ }
+ }
+
+ ++i;
+ }
+ ++j;
+ }
+
+ for (auto i = m - 2; i >= 0; --i)
+ {
+ for (auto j = i + 1; j < n - 1; ++j)
+ {
+ input[i * n + m] -= input[i * n + j] * input[j * n + m];
+ }
+ }
+}
+
+glm::mat4 lineTransformer::getPerspectiveTransformMatrix(const glm::vec2 src[4], const glm::vec2 dst[4])
+{
+ float p[8][9] =
+ {
+ { -src[0][0], -src[0][1], -1, 0, 0, 0, src[0][0] * dst[0][0], src[0][1] * dst[0][0], -dst[0][0] }, // h11
+ { 0, 0, 0, -src[0][0], -src[0][1], -1, src[0][0] * dst[0][1], src[0][1] * dst[0][1], -dst[0][1] }, // h12
+ { -src[1][0], -src[1][1], -1, 0, 0, 0, src[1][0] * dst[1][0], src[1][1] * dst[1][0], -dst[1][0] }, // h13
+ { 0, 0, 0, -src[1][0], -src[1][1], -1, src[1][0] * dst[1][1], src[1][1] * dst[1][1], -dst[1][1] }, // h21
+ { -src[2][0], -src[2][1], -1, 0, 0, 0, src[2][0] * dst[2][0], src[2][1] * dst[2][0], -dst[2][0] }, // h22
+ { 0, 0, 0, -src[2][0], -src[2][1], -1, src[2][0] * dst[2][1], src[2][1] * dst[2][1], -dst[2][1] }, // h23
+ { -src[3][0], -src[3][1], -1, 0, 0, 0, src[3][0] * dst[3][0], src[3][1] * dst[3][0], -dst[3][0] }, // h31
+ { 0, 0, 0, -src[3][0], -src[3][1], -1, src[3][0] * dst[3][1], src[3][1] * dst[3][1], -dst[3][1] }, // h32
+ };
+
+ gaussianElimination(&p[0][0], 9);
+
+ return glm::mat4(p[0][8], p[3][8], 0, p[6][8],
+ p[1][8], p[4][8], 0, p[7][8],
+ 0, 0, 1, 0,
+ p[2][8], p[5][8], 0, 1);
+}
+
+ofPolyline lineTransformer::polyLineTransform(const ofPolyline& poly, ofMatrix4x4 xform){
+ ofPolyline tempPoly;
+ for (auto& p:poly){
+ tempPoly.addVertex(ofVec3f(p)*xform);
+ }
+ return tempPoly;
+}
+
+ofPolyline lineTransformer::makePolygon(int num,float diam){
+ ofPolyline poly;
+ float step=PI*2/num;
+ for (int i=0;i<=num;i++){
+ poly.addVertex(cos(step*i)*diam,sin(step*i)*diam);
+ }
+ return poly;
+}
+
+void lineTransformer::drawPoly(ofPolyline poly,float x,float y){
+ glPushMatrix();
+ ofTranslate(x,y);
+ poly.draw();
+ for (int i=0;i<poly.size();i++){
+ ofDrawBitmapString(poly.getDegreesAtIndex(i),poly[i].x+10,poly[i].y+10,0);
+ }
+ glPopMatrix();
+}
diff --git a/gui/src/lineTransformer.h b/gui/src/lineTransformer.h
new file mode 100644
index 0000000..8268b81
--- /dev/null
+++ b/gui/src/lineTransformer.h
@@ -0,0 +1,17 @@
+#pragma once
+
+#include "ofMain.h"
+
+class lineTransformer {
+
+ public:
+ lineTransformer(){
+ }
+ void static drawWarpFrame(glm::vec2 warpframe[4]);
+ void static gaussianElimination(float * input, int n);
+ glm::mat4 static getPerspectiveTransformMatrix(const glm::vec2 src[4], const glm::vec2 dst[4]);
+ ofPolyline static polyLineTransform(const ofPolyline& poly, ofMatrix4x4 xform);
+ ofPolyline static makePolygon(int num,float diam);
+ void static drawPoly(ofPolyline poly,float x,float y);
+
+}; \ No newline at end of file
diff --git a/gui/src/main.cpp b/gui/src/main.cpp
new file mode 100644
index 0000000..ed7e18f
--- /dev/null
+++ b/gui/src/main.cpp
@@ -0,0 +1,42 @@
+#include "ofMain.h"
+#include "ofApp.h"
+
+
+//========================================================================
+int main(int argc, char *argv[]){
+
+
+ ofGLFWWindowSettings settings;
+
+ settings.width = 600;
+ settings.height = 1200;
+ settings.setPosition(ofVec2f(0,0));
+ settings.resizable = true;
+
+ //settings.decorated = false; //doesn't suppress FS title bar
+ shared_ptr<ofAppBaseWindow> guiWindow = ofCreateWindow(settings);
+ guiWindow->setVerticalSync(false);
+
+ // share OpenGL resources with other windows
+ settings.shareContextWith = guiWindow;
+ settings.decorated = true;
+
+ settings.width = 1200;
+ settings.height = 900 ;
+ settings.setPosition(ofVec2f(1700,0));
+ settings.resizable = false;
+
+ shared_ptr<ofAppBaseWindow> mainWindow = ofCreateWindow(settings);
+ mainWindow->setVerticalSync(false);
+
+ shared_ptr<ofApp> mainApp(new ofApp);
+ //mainApp->setupGui();
+
+ ofAddListener(guiWindow->events().draw,mainApp.get(),&ofApp::drawGui);
+ ofAddListener(guiWindow->events().windowResized,mainApp.get(),&ofApp::guiWindowResized);
+ ofAddListener(guiWindow->events().keyPressed,mainApp.get(),&ofApp::guiKeyPressed);
+
+ ofRunApp(mainWindow, mainApp);
+ ofRunMainLoop();
+}
+ \ No newline at end of file
diff --git a/gui/src/ofApp.cpp b/gui/src/ofApp.cpp
new file mode 100644
index 0000000..100c107
--- /dev/null
+++ b/gui/src/ofApp.cpp
@@ -0,0 +1,172 @@
+#include "ofApp.h"
+#include "glew.h"
+
+
+//--------------------------------------------------------------
+void ofApp::setup(){
+ warpframe[0]=glm::vec2(0,0);
+ warpframe[1]=glm::vec2(ofGetWidth(),0);
+ warpframe[2]=glm::vec2(ofGetWidth(),ofGetHeight());
+ warpframe[3]=glm::vec2(0,ofGetHeight());
+ select_warpframe=-1;
+ bDrawFrame=false;
+}
+
+//--------------------------------------------------------------
+void ofApp::update(){
+
+
+}
+
+void ofApp::updateGui(ofEventArgs & args){
+
+
+}
+
+
+//--------------------------------------------------------------
+void ofApp::drawGui(ofEventArgs & args){
+ ofBackground(0);
+
+}
+
+void ofApp::draw(){
+ ofBackground(0);
+ //composite output window
+
+ ofSetColor(255,255,255);
+
+ ofMatrix4x4 m = ofMatrix4x4::newIdentityMatrix();
+ m.rotateRad(ofGetElapsedTimef(),0,0,1);
+ m.translate(ofGetWidth()/2,ofGetHeight()/2,0);
+
+ glm::vec2 src[]={
+ glm::vec2(0,0),
+ glm::vec2(ofGetWidth(),0),
+ glm::vec2(ofGetWidth(),ofGetHeight()),
+ glm::vec2(0,ofGetHeight())
+ };
+
+ ofMatrix4x4 warp =lineTransformer::getPerspectiveTransformMatrix(src,warpframe);
+
+ //drawPoly(polyLineTransform(makePolygon(4,200),m),200,200);
+ //drawPoly(polyLineTransform(makePolygon(5,200),m),-200,200);
+ //drawPoly(polyLineTransform(makePolygon(6,200),m),-200,-200);
+
+ lineTransformer::drawPoly(
+ lineTransformer::polyLineTransform(
+ lineTransformer::polyLineTransform(
+ lineTransformer::makePolygon(6,200)
+ ,m)
+ ,warp)
+ ,0,0);
+
+ if (bDrawFrame){
+ lineTransformer::drawWarpFrame(warpframe);
+ }
+
+}
+
+//--------------------------------------------------------------
+void ofApp::exit() {
+
+}
+
+
+
+//--------------------------------------------------------------
+void ofApp::keyPressed(ofKeyEventArgs &args){
+
+ if (args.key==OF_KEY_COMMAND){
+ commandPressed=true;
+ }
+
+ switch(args.key){
+ case 'w':{
+ bDrawFrame=!bDrawFrame;
+ break;
+ }
+ case OF_KEY_COMMAND:{
+ commandPressed=true;
+ }
+ }
+
+
+}
+
+void ofApp::guiKeyPressed(ofKeyEventArgs &args){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::keyReleased(int key){
+ if (key==OF_KEY_COMMAND){
+ commandPressed=false;
+ }
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseMoved(int x, int y ){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseDragged(int x, int y, int button){
+ if (select_warpframe>-1){
+ warpframe[select_warpframe]=glm::vec2(x,y);
+ }
+}
+
+//--------------------------------------------------------------
+void ofApp::mousePressed(int x, int y, int button){
+ for (int i=0;i<4;i++){
+ if (ofPoint(x,y).distance(warpframe[i])<25){
+ select_warpframe=i;
+ }
+ }
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseReleased(int x, int y, int button){
+ select_warpframe=-1;
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseEntered(int x, int y){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseExited(int x, int y){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::windowResized(int w, int h){
+
+}
+
+void ofApp::guiWindowResized(ofResizeEventArgs &resizeargs){
+
+}
+
+
+//--------------------------------------------------------------
+void ofApp::dragEvent(ofDragInfo dragInfo){
+ //std::string filenames;
+
+ //for (auto f = dragInfo.files.begin(); f != dragInfo.files.end(); f++){
+ // if (f!=dragInfo.files.begin()){
+ // filenames=filenames+", ";
+ // }
+ // filenames=filenames+*f;
+
+ // if (dragInfo.position.y<200){
+ // sets[0].addfiles(dragInfo.files); //,dragInfo.position);
+ // }
+ // else sets[1].addfiles(dragInfo.files); //,dragInfo.position);
+
+
+ //}
+
+}
diff --git a/gui/src/ofApp.h b/gui/src/ofApp.h
new file mode 100644
index 0000000..d28f393
--- /dev/null
+++ b/gui/src/ofApp.h
@@ -0,0 +1,38 @@
+#pragma once
+
+#include "ofMain.h"
+#include "lineTransformer.h"
+
+class ofApp: public ofBaseApp {
+
+ public:
+ void setup();
+ void update();
+ void updateGui(ofEventArgs & args);
+ void draw();
+ void exit();
+
+ void drawGui(ofEventArgs & args);
+ void guiKeyPressed(ofKeyEventArgs & args);
+
+ void keyPressed(ofKeyEventArgs &keyargs);
+ void keyReleased(int key);
+ void mouseMoved(int x, int y );
+ void mouseDragged(int x, int y, int button);
+ void mousePressed(int x, int y, int button);
+ void mouseReleased(int x, int y, int button);
+ void mouseEntered(int x, int y);
+ void mouseExited(int x, int y);
+ void windowResized(int w, int h);
+ void dragEvent(ofDragInfo dragInfo);
+
+ void guiWindowResized(ofResizeEventArgs &resizeargs);
+
+ bool commandPressed;
+
+
+ glm::vec2 warpframe[4];
+ int select_warpframe;
+ bool bDrawFrame;
+
+};