New graph type in place - Separate Body Graph
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ void GUI::setup()
|
||||
addGraphGlobalGUI();
|
||||
addBarGraphDesignGUI();
|
||||
addBodyGraphDesignGUI();
|
||||
addSeparateBodyGraphDesignGUI();
|
||||
addGraphSimulationGUI();
|
||||
addBackgroundGUI();
|
||||
addHUDTextGUI();
|
||||
@@ -59,7 +60,7 @@ void GUI::addGraphGlobalGUI()
|
||||
vector<string> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ public:
|
||||
void addGraphGlobalGUI();
|
||||
void addBarGraphDesignGUI();
|
||||
void addBodyGraphDesignGUI();
|
||||
void addSeparateBodyGraphDesignGUI();
|
||||
void addGraphSimulationGUI();
|
||||
void addBackgroundGUI();
|
||||
void addHUDTextGUI();
|
||||
|
||||
@@ -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
|
||||
//
|
||||
//--------------------------------------------------------------
|
||||
|
||||
@@ -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<DataObject> 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();
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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<DataObject> 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<DataObject> newData)
|
||||
{
|
||||
AbstractGraph::addNewData(newData);
|
||||
}
|
||||
@@ -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<DataObject> newData);
|
||||
ofMesh getMesh(vector<DataObject> publisherData, float* col);
|
||||
|
||||
testApp *app;
|
||||
|
||||
float lineWidth;
|
||||
|
||||
bool isDrawLines;
|
||||
float graphEndPercent;
|
||||
};
|
||||
Reference in New Issue
Block a user