diff --git a/of/Active Tripod/Active_Tripod.vcxproj b/of/Active Tripod/Active_Tripod.vcxproj index 22e3020..253b3d6 100644 --- a/of/Active Tripod/Active_Tripod.vcxproj +++ b/of/Active Tripod/Active_Tripod.vcxproj @@ -112,6 +112,7 @@ + @@ -190,6 +191,7 @@ + diff --git a/of/Active Tripod/Active_Tripod.vcxproj.filters b/of/Active Tripod/Active_Tripod.vcxproj.filters index 6a65e08..5d435a6 100644 --- a/of/Active Tripod/Active_Tripod.vcxproj.filters +++ b/of/Active Tripod/Active_Tripod.vcxproj.filters @@ -76,6 +76,9 @@ src\visual\graph + + src\visual\graph + @@ -374,6 +377,9 @@ src\visual\graph + + src\visual\graph + diff --git a/of/Active Tripod/bin/Active_Tripod.lib b/of/Active Tripod/bin/Active_Tripod.lib index d300a21..84da758 100644 Binary files a/of/Active Tripod/bin/Active_Tripod.lib and b/of/Active Tripod/bin/Active_Tripod.lib differ diff --git a/of/Active Tripod/bin/data/GUI/GRAPH GLOBALguiPagesettings.xml b/of/Active Tripod/bin/data/GUI/GRAPH GLOBALguiPagesettings.xml index c6f6fce..c2835ce 100644 --- a/of/Active Tripod/bin/data/GUI/GRAPH GLOBALguiPagesettings.xml +++ b/of/Active Tripod/bin/data/GUI/GRAPH GLOBALguiPagesettings.xml @@ -1,7 +1,7 @@ 2 Bar graph - 1 + 0 2 @@ -10,8 +10,8 @@ 2 - Line fade graph - 0 + Separate Body graph + 1 6 diff --git a/of/Active Tripod/bin/data/GUI/SEPARATE BODY GRAPH DESIGNguiPagesettings.xml b/of/Active Tripod/bin/data/GUI/SEPARATE BODY GRAPH DESIGNguiPagesettings.xml new file mode 100644 index 0000000..7b88529 --- /dev/null +++ b/of/Active Tripod/bin/data/GUI/SEPARATE BODY GRAPH DESIGNguiPagesettings.xml @@ -0,0 +1,70 @@ + + 2 + Toggle Draw Lines + 1 + + + 4 + Graph Item X Gap + 6.480263233 + + + 4 + Line width + 5.190789700 + + + 4 + Graph Height Max + 325.000000000 + + + 4 + Graph bottom end (percent) + 0.875000000 + + + 4 + Data send speed (seconds) + 3.045723677 + + + 4 + Data0 red + 0.000000000 + + + 4 + Data0 green + 72.138153076 + + + 4 + Data0 blue + 164.407897949 + + + 4 + Data0 alpha + 179.506576538 + + + 4 + Data1 red + 187.894729614 + + + 4 + Data1 green + 46.134868622 + + + 4 + Data1 blue + 32.713817596 + + + 4 + Data1 alpha + 187.894729614 + diff --git a/of/Active Tripod/src/data/DataManager.cpp b/of/Active Tripod/src/data/DataManager.cpp index 3181095..9209d60 100644 --- a/of/Active Tripod/src/data/DataManager.cpp +++ b/of/Active Tripod/src/data/DataManager.cpp @@ -47,7 +47,6 @@ void DataManager::setupSpacebrew() void DataManager::update() { - if (isDataSimulated) { if (ofGetFrameNum() % (int)simulationSpeed == 0) @@ -118,22 +117,22 @@ void DataManager::onMessage( Spacebrew::Message & m ) { if (data[i].substr(0, 5) == "info:") { - printf("- - info = %s\n", data[i].substr(5, -1).c_str()); + //printf("- - info = %s\n", data[i].substr(5, -1).c_str()); dataObject.info = data[i].substr(5, -1).c_str(); } if (data[i].substr(0, 6) == "value:") { - printf("- - value = %s\n", data[i].substr(6, -1).c_str()); + //printf("- - value = %s\n", data[i].substr(6, -1).c_str()); dataObject.value = ofToFloat(data[i].substr(6, -1).c_str()); } if (data[i].substr(0, 4) == "min:") { - printf("- - min = %s\n", data[i].substr(4, -1).c_str()); + //printf("- - min = %s\n", data[i].substr(4, -1).c_str()); dataObject.min = ofToFloat(data[i].substr(4, -1).c_str()); } if (data[i].substr(0, 4) == "max:") { - printf("- - max = %s\n", data[i].substr(4, -1).c_str()); + //printf("- - max = %s\n", data[i].substr(4, -1).c_str()); dataObject.max = ofToFloat(data[i].substr(4, -1).c_str()); } } diff --git a/of/Active Tripod/src/gui/GUI.cpp b/of/Active Tripod/src/gui/GUI.cpp index a5687b1..7840194 100644 --- a/of/Active Tripod/src/gui/GUI.cpp +++ b/of/Active Tripod/src/gui/GUI.cpp @@ -21,6 +21,7 @@ void GUI::setup() addGraphGlobalGUI(); addBarGraphDesignGUI(); addBodyGraphDesignGUI(); + addSeparateBodyGraphDesignGUI(); addGraphSimulationGUI(); addBackgroundGUI(); addHUDTextGUI(); @@ -59,7 +60,7 @@ void GUI::addGraphGlobalGUI() vector graphNames; graphNames.push_back("Bar graph"); graphNames.push_back("Solid Body graph"); - graphNames.push_back("Line fade graph"); + graphNames.push_back("Separate Body graph"); gui->addRadio("Graph Selection", graphNames, OFX_UI_ORIENTATION_VERTICAL, dim*2, dim*2); @@ -127,6 +128,34 @@ void GUI::addBodyGraphDesignGUI() } +void GUI::addSeparateBodyGraphDesignGUI() +{ + string title = "SEPARATE BODY GRAPH DESIGN"; + ofxUICanvas* gui = getNewGUI(title); + + gui->addToggle("Toggle Draw Lines", &app->scene.separateBodyGraph.isDrawLines, toggleDim, toggleDim); + gui->addSlider("Graph Item X Gap", 5, 50, &app->scene.separateBodyGraph.graphItemXGap, length, dim); + gui->addSlider("Line width", 1, 50, &app->scene.separateBodyGraph.lineWidth, length, dim); + gui->addSlider("Graph Height Max", 100, 1000, &app->scene.separateBodyGraph.graphHeightMax, length, dim); + gui->addSlider("Graph bottom end (percent)", 0, 2, &app->scene.separateBodyGraph.graphEndPercent, length, dim); + gui->addSlider("Data send speed (seconds)", 0.1, 20, &app->scene.separateBodyGraph.sendDataSpeed, length, dim); + + gui->addSpacer(length, 1); + gui->addSlider("Data0 red", 0, 255, &app->scene.separateBodyGraph.col0[0], length, dim); + gui->addSlider("Data0 green", 0, 255, &app->scene.separateBodyGraph.col0[1], length, dim); + gui->addSlider("Data0 blue", 0, 255, &app->scene.separateBodyGraph.col0[2], length, dim); + gui->addSlider("Data0 alpha", 0, 255, &app->scene.separateBodyGraph.col0[3], length, dim); + + gui->addSpacer(length, 1); + gui->addSlider("Data1 red", 0, 255, &app->scene.separateBodyGraph.col1[0], length, dim); + gui->addSlider("Data1 green", 0, 255, &app->scene.separateBodyGraph.col1[1], length, dim); + gui->addSlider("Data1 blue", 0, 255, &app->scene.separateBodyGraph.col1[2], length, dim); + gui->addSlider("Data1 alpha", 0, 255, &app->scene.separateBodyGraph.col1[3], length, dim); + + finaliseCanvas(gui, true); +} + + void GUI::addGraphSimulationGUI() { string title = "SIMULATION"; @@ -243,10 +272,10 @@ void GUI::graphGlobalGUIEvent(ofxUIEventArgs &e) printf("------------------- Solid Body graph\n"); if (toggle->getValue()) app->scene.activeGraph = &app->scene.bodyGraph; } - else if (name == "Line fade graph") + else if (name == "Separate Body graph") { printf("------------------- Line fade graph\n"); - //app->scene.activeGraph = &app->scene.lineGraph; + if (toggle->getValue()) app->scene.activeGraph = &app->scene.separateBodyGraph; } } diff --git a/of/Active Tripod/src/gui/GUI.h b/of/Active Tripod/src/gui/GUI.h index cacd433..3a14c7e 100644 --- a/of/Active Tripod/src/gui/GUI.h +++ b/of/Active Tripod/src/gui/GUI.h @@ -23,6 +23,7 @@ public: void addGraphGlobalGUI(); void addBarGraphDesignGUI(); void addBodyGraphDesignGUI(); + void addSeparateBodyGraphDesignGUI(); void addGraphSimulationGUI(); void addBackgroundGUI(); void addHUDTextGUI(); diff --git a/of/Active Tripod/src/testApp.cpp b/of/Active Tripod/src/testApp.cpp index 45a161b..2a19e9e 100644 --- a/of/Active Tripod/src/testApp.cpp +++ b/of/Active Tripod/src/testApp.cpp @@ -2,12 +2,10 @@ // TODO // ==== -// - Make system to slow down data - The screen should show 15-20 minutes worth of data -// - Make 3rd graph - separate fade // - Crosshairs in HUD // - Create graph animation system +// - make maxGraphHeight percentage instead of pixels // - Create a single config file to be loaded from online location. It will contain IP address and host name -// - Add 'clear all data' button to UI // - If min or max values change - clear graph - ask bout this // //-------------------------------------------------------------- diff --git a/of/Active Tripod/src/visual/Scene.cpp b/of/Active Tripod/src/visual/Scene.cpp index ebfb0dc..9a134ad 100644 --- a/of/Active Tripod/src/visual/Scene.cpp +++ b/of/Active Tripod/src/visual/Scene.cpp @@ -18,6 +18,7 @@ void Scene::setup() rgbShader.load("shaders/RGBShader"); barGraph.setup(); bodyGraph.setup(); + separateBodyGraph.setup(); text.loadFont("fonts/Roboto-Light.ttf", 8); } @@ -197,6 +198,7 @@ void Scene::addNewData(vector newData) { barGraph.addNewData(newData); bodyGraph.addNewData(newData); + separateBodyGraph.addNewData(newData); tlStr = newData[0].info + "\n" + ofToString(newData[0].value); trStr = newData[1].info + "\n" + ofToString(newData[1].value); @@ -215,4 +217,5 @@ void Scene::clearGraphData() { barGraph.clear(); bodyGraph.clear(); + separateBodyGraph.clear(); } \ No newline at end of file diff --git a/of/Active Tripod/src/visual/Scene.h b/of/Active Tripod/src/visual/Scene.h index 062c44c..dd91036 100644 --- a/of/Active Tripod/src/visual/Scene.h +++ b/of/Active Tripod/src/visual/Scene.h @@ -11,6 +11,7 @@ #include "ofMain.h" #include "BarGraph.h" #include "BodyGraph.h" +#include "SeparateBodyGraph.h" #include "DataManager.h" #include "ofxFTGL.h" @@ -34,6 +35,8 @@ public: BarGraph barGraph; BodyGraph bodyGraph; + SeparateBodyGraph separateBodyGraph; + ofShader rgbShader; ofVideoGrabber vidGrabber; ofImage bgImg; diff --git a/of/Active Tripod/src/visual/graph/AbstractGraph.cpp b/of/Active Tripod/src/visual/graph/AbstractGraph.cpp index 1d744e3..82bc22a 100644 --- a/of/Active Tripod/src/visual/graph/AbstractGraph.cpp +++ b/of/Active Tripod/src/visual/graph/AbstractGraph.cpp @@ -20,7 +20,6 @@ void AbstractGraph::setup() void AbstractGraph::update() { maxData = (ofGetWidth() * (AbstractGraph::maxGraphPercent - AbstractGraph::minGraphPercent)) / graphItemXGap; - printf("ofGetWidth():%i, maxData:%i, graphItemXGap:%f, screen active:%f \n", ofGetWidth(), maxData, graphItemXGap, (AbstractGraph::maxGraphPercent - AbstractGraph::minGraphPercent)); } diff --git a/of/Active Tripod/src/visual/graph/SeparateBodyGraph.cpp b/of/Active Tripod/src/visual/graph/SeparateBodyGraph.cpp new file mode 100644 index 0000000..fd72e02 --- /dev/null +++ b/of/Active Tripod/src/visual/graph/SeparateBodyGraph.cpp @@ -0,0 +1,171 @@ +// +// Created by James Alliban on 11/01/2014. +// +// + +#include "SeparateBodyGraph.h" +#include "testApp.h" + + +void SeparateBodyGraph::setup() +{ + AbstractGraph::setup(); + app = (testApp*)ofGetAppPtr(); + graphName = "SEPARATE_BODY"; +} + + +void SeparateBodyGraph::update() +{ + AbstractGraph::update(); +} + + +void SeparateBodyGraph::draw() +{ + if (app->gui.getVisible()) + { + float timePerScreenfull = (float)maxData * sendDataSpeed; + ofDrawBitmapString("Time to fill screen:" + ofToString(timePerScreenfull), 500, 150); + } + + if (publisher0Data.size() > 1) + { + //for (int i = 0; i < publisher0Data.size() - 1; i++) + //{ + // ofPushStyle(); + // ofSetColor(255, 0, 0); + // ofCircle(i * graphItemXGap, publisher0Data[i], 5); + // ofSetColor(0, 255, 0); + // ofCircle(i * graphItemXGap, publisher1Data[i], 5); + // ofPopStyle(); + //} + + + + ofMesh body0 = getMesh(publisher0Data, col0); + ofMesh body1 = getMesh(publisher1Data, col1); + + + + + float xOffset = ofGetWidth() * AbstractGraph::minGraphPercent; + float outputMin = (ofGetHeight() * 0.5) - graphHeightMax; + float outputMax = (ofGetHeight() * 0.5) + graphHeightMax; + + + // draw lines + ofPushStyle(); + ofPolyline poly0; + ofPolyline poly1; + for (int i = 0; i < publisher0Data.size() - 1; i++) + { + if (i < publisher0Data.size() - 1) + { + ofSetLineWidth(lineWidth); + poly0.addVertex(ofPoint( + i * graphItemXGap + xOffset, + ofMap(publisher0Data[i].value, publisher0Data[i].min, publisher0Data[i].max, outputMin, outputMax))); + + + poly1.addVertex(ofPoint( + i * graphItemXGap + xOffset, + ofMap(publisher1Data[i].value, publisher1Data[i].min, publisher1Data[i].max, outputMin, outputMax))); + } + } + + + + ofVec2f centroid0 = poly0.getCentroid2D(); + ofVec2f centroid1 = poly1.getCentroid2D(); + + printf("centroid0.y:%f, centroid1.y:%f\n", centroid0.y, centroid1.y); + + float av0; + float av1; + + for (int i = 0; i < poly0.size(); i++) + { + av0 += poly0[i].y; + av1 += poly1[i].y; + } + av0 /= poly0.size(); + av1 /= poly1.size(); + + printf("av0:%f, av1:%f\n", av0, av1); + + int lineAlpha = 255; + if (!isDrawLines) lineAlpha = 0; + + if (av0 < av1) + { + body0.drawFaces(); + ofSetColor(col0[0],col0[1],col0[2], lineAlpha); + poly0.draw(); + + body1.drawFaces(); + ofSetColor(col1[0],col1[1],col1[2], lineAlpha); + poly1.draw(); + } + else + { + body1.drawFaces(); + ofSetColor(col1[0],col1[1],col1[2], lineAlpha); + poly1.draw(); + + body0.drawFaces(); + ofSetColor(col0[0],col0[1],col0[2], lineAlpha); + poly0.draw(); + } + + if (isDrawLines) + { + if (av0 > av1) + { + + + } + else + { + + + } + } + + ofPopStyle(); + } +} + + +ofMesh SeparateBodyGraph::getMesh(vector publisherData, float* col) +{ + ofMesh bodyMesh; + float xOffset = ofGetWidth() * AbstractGraph::minGraphPercent; + float outputMin = (ofGetHeight() * 0.5) - graphHeightMax; + float outputMax = (ofGetHeight() * 0.5) + graphHeightMax; + + // draw main part of graph (xOffset) + bodyMesh.setMode(OF_PRIMITIVE_TRIANGLE_STRIP); + for (int i = 0; i < publisherData.size() - 1; i++) + { + bodyMesh.addVertex(ofVec3f( + i * graphItemXGap + xOffset, + ofMap(publisherData[i].value, publisherData[i].min, publisherData[i].max, outputMin, outputMax), + 0)); + bodyMesh.addVertex(ofVec3f( + i * graphItemXGap + xOffset, + ofGetHeight() * graphEndPercent, + 0)); + + bodyMesh.addColor(ofColor(col[0],col[1],col[2], col[3])); + bodyMesh.addColor(ofColor(col[0],col[1],col[2], 0)); + } + return bodyMesh; +} + + + +void SeparateBodyGraph::addNewData(vector newData) +{ + AbstractGraph::addNewData(newData); +} \ No newline at end of file diff --git a/of/Active Tripod/src/visual/graph/SeparateBodyGraph.h b/of/Active Tripod/src/visual/graph/SeparateBodyGraph.h new file mode 100644 index 0000000..21a3ebb --- /dev/null +++ b/of/Active Tripod/src/visual/graph/SeparateBodyGraph.h @@ -0,0 +1,24 @@ + +#pragma once + +#include "ofMain.h" +#include "AbstractGraph.h" + +class testApp; + +class SeparateBodyGraph : public AbstractGraph +{ +public: + void setup(); + virtual void update(); + virtual void draw(); + virtual void addNewData(vector newData); + ofMesh getMesh(vector publisherData, float* col); + + testApp *app; + + float lineWidth; + + bool isDrawLines; + float graphEndPercent; +}; \ No newline at end of file