Adding Utility box application

This commit is contained in:
James Alliban
2014-01-14 15:12:43 +00:00
parent dcc9f9ef68
commit 3f3094efa5
47 changed files with 971 additions and 960 deletions
+24 -45
View File
@@ -6,10 +6,7 @@ void DataManager::setup()
{
app = (testApp*)ofGetAppPtr();
newData.resize(2);
//isPublisher0DataReceived = false;
//isPublisher1DataReceived = false;
newData.resize(30);
setupSpacebrew();
@@ -25,9 +22,9 @@ void DataManager::setupSpacebrew()
for (int i = 0; i < 30; i++)
{
spacebrew.addSubscribe(ofToString(i), Spacebrew::TYPE_STRING);
spacebrew.addSubscribe("utility_" + ofToString(i), Spacebrew::TYPE_STRING);
}
spacebrew.connect( host, name, description );
spacebrew.connect(host, name, description);
// listen to spacebrew events
Spacebrew::addListener(this, spacebrew);
@@ -40,40 +37,27 @@ void DataManager::update()
{
if (ofGetFrameNum() % (int)simulationSpeed == 0)
{
DataObject dataObject0;
dataObject0.info = "Some text to describe the data\nSome more text\nOne more line";
dataObject0.value = ofNoise(newData.size() * perlinXScale, ofGetElapsedTimef() * perlinYScale);
dataObject0.min = 0;
dataObject0.max = 1;
vector<DataObject> dataObjects;
for (int i = 0; i < 30; i++)
{
DataObject dataObject;
dataObject.info = "Some text to describe the data\nSome more text\nOne more line";
dataObject.value = ofNoise(newData.size() * perlinXScale, (ofGetElapsedTimef() + (i * 756)) * perlinYScale);
dataObject.min = 0;
dataObject.max = 1;
//printf("dataObject0.value = %f \n", dataObject0.value);
dataObjects.push_back(dataObject);
}
newData[0] = dataObject0;
DataObject dataObject1;
dataObject1.info = "Some descriptive text\nSome more\nLittle bit more\nLast one";
dataObject1.value = ofNoise((newData.size() + 500) * perlinXScale, (ofGetElapsedTimef() + 1000) * perlinYScale);
dataObject1.min = 0;
dataObject1.max = 1;
newData[1] = dataObject1;
app->scene.activeGraph->addNewData(newData);
app->scene.addNewData(dataObjects);
}
}
else
{
/*if (isPublisher0DataReceived && isPublisher1DataReceived)
{
isPublisher0DataReceived = false;
isPublisher1DataReceived = false;
app->scene.addNewData(newData);
}*/
//sendDataSpeed = app->scene.activeGraph->sendDataSpeed;
if (ofGetElapsedTimef() >= nextDataSendTime + app->scene.activeGraph->sendDataSpeed)
if (ofGetElapsedTimef() >= nextDataSendTime + sendDataSpeed)
{
nextDataSendTime += app->scene.activeGraph->sendDataSpeed;
nextDataSendTime += sendDataSpeed;
app->scene.addNewData(newData);
}
}
@@ -82,10 +66,6 @@ void DataManager::update()
void DataManager::draw()
{
ofPushStyle();
ofSetColor(255, 0, 0);
ofCircle(sin(ofGetElapsedTimef() * 0.5) * 300 + 300, 100, 20);
ofPopStyle();
}
@@ -127,16 +107,15 @@ void DataManager::onMessage( Spacebrew::Message & m )
}
if (m.name == publisher0Name)
for (int i = 0; i < 30; i++)
{
//isPublisher0DataReceived = true;
newData[0] = dataObject;
}
else if (m.name == publisher1Name)
{
//isPublisher1DataReceived = true;
newData[1] = dataObject;
}
if (m.name == "utility_" + ofToString(i))
{
printf("adding %s to dataObject %i\n", m.name.c_str(), i);
//isPublisher0DataReceived = true;
newData[i] = dataObject;
}
}
}
+2
View File
@@ -27,10 +27,12 @@ class DataManager
void draw();
vector<string> explode( const string &delimiter, const string &str);
// listen to spacebrew Messages
void onMessage( Spacebrew::Message & m );
testApp* app;
float sendDataSpeed;
int appId;
+27 -176
View File
@@ -8,7 +8,7 @@
#include "GUI.h"
#include "testApp.h"
#include "AbstractGraph.h"
#include "Graph.h"
void GUI::setup()
{
@@ -19,12 +19,8 @@ void GUI::setup()
addKeyboardShortcutsGUI();
addGraphGlobalGUI();
addBarGraphDesignGUI();
addBodyGraphDesignGUI();
addSeparateBodyGraphDesignGUI();
addGraphDesignGUI();
addGraphSimulationGUI();
addBackgroundGUI();
addHUDTextGUI();
addVariousGUI();
setGUIColour();
@@ -36,6 +32,8 @@ bool GUI::getVisible()
return GUIManager::getVisible();
}
void GUI::addKeyboardShortcutsGUI()
{
string title = "KEYBOARD SHORTCUTS";
@@ -66,99 +64,42 @@ void GUI::addGraphGlobalGUI()
gui->addRadio("Graph Selection", graphNames, OFX_UI_ORIENTATION_VERTICAL, dim*2, dim*2);
gui->addSpacer(length, 1);
gui->addRangeSlider("Graph X begin/end (percent)", 0, 1, &AbstractGraph::minGraphPercent, &AbstractGraph::maxGraphPercent, length, dim);
gui->addRangeSlider("Graph X begin/end (percent)", 0, 1, &Graph::minGraphPercent, &Graph::maxGraphPercent, length, dim);
gui->addLabel("GRAPH TEXT");
gui->addSpacer(length, 1);
gui->addSlider("Size", 5, 50, &app->scene.graphTextSize, length, dim);
gui->addSlider("Red", 0, 255, &app->scene.graphTextColour[0], length, dim);
gui->addSlider("Green", 0, 255, &app->scene.graphTextColour[1], length, dim);
gui->addSlider("Blue", 0, 255, &app->scene.graphTextColour[2], length, dim);
gui->addSlider("Alpha", 0, 255, &app->scene.graphTextColour[3], length, dim);
// gui->addLabel("GRAPH TEXT");
//gui->addSpacer(length, 1);
//gui->addSlider("Size", 5, 50, &app->scene.graphTextSize, length, dim);
//gui->addSlider("Red", 0, 255, &app->scene.graphTextColour[0], length, dim);
//gui->addSlider("Green", 0, 255, &app->scene.graphTextColour[1], length, dim);
//gui->addSlider("Blue", 0, 255, &app->scene.graphTextColour[2], length, dim);
//gui->addSlider("Alpha", 0, 255, &app->scene.graphTextColour[3], length, dim);
ofAddListener(gui->newGUIEvent, this, &GUI::graphGlobalGUIEvent);
finaliseCanvas(gui, true);
}
void GUI::addBarGraphDesignGUI()
void GUI::addGraphDesignGUI()
{
string title = "BAR GRAPH DESIGN";
string title = "GRAPH DESIGN";
ofxUICanvas* gui = getNewGUI(title);
gui->addSlider("Graph Item X Gap", 5, 50, &app->scene.barGraph.graphItemXGap, length, dim);
gui->addSlider("BarWidth", 2, 50, &app->scene.barGraph.barWidth, length, dim);
gui->addSlider("Graph Height Max", 0, 1, &app->scene.barGraph.graphHeightMax, length, dim);
gui->addSlider("Data send speed (seconds)", 0.1, 20, &app->scene.barGraph.sendDataSpeed, length, dim);
gui->addToggle("Toggle Draw Lines", &Graph::isDrawLines, toggleDim, toggleDim);
gui->addSlider("Graph Item X Gap", 0.1, 2, &Graph::graphItemXGap, length, dim);
gui->addSlider("Line width", 1, 20, &Graph::lineWidth, length, dim);
gui->addSlider("Graph Width max", 1, 300, &Graph::maxGraphWidth, length, dim);
gui->addSlider("Graph Height Max", 0, 100, &Graph::graphHeightMax, length, dim);
gui->addSlider("Graph bottom end (percent)", 0, 20, &Graph::graphEndPercent, length, dim);
gui->addSlider("Data send speed (seconds)", 0.1, 20, &app->dataManager.sendDataSpeed, length, dim);
gui->addSpacer(length, 1);
gui->addSlider("Data0 red", 0, 255, &app->scene.barGraph.col0[0], length, dim);
gui->addSlider("Data0 green", 0, 255, &app->scene.barGraph.col0[1], length, dim);
gui->addSlider("Data0 blue", 0, 255, &app->scene.barGraph.col0[2], length, dim);
gui->addSlider("Data0 alpha", 0, 255, &app->scene.barGraph.col0[3], length, dim);
gui->addSpacer(length, 1);
gui->addSlider("Data1 red", 0, 255, &app->scene.barGraph.col1[0], length, dim);
gui->addSlider("Data1 green", 0, 255, &app->scene.barGraph.col1[1], length, dim);
gui->addSlider("Data1 blue", 0, 255, &app->scene.barGraph.col1[2], length, dim);
gui->addSlider("Data1 alpha", 0, 255, &app->scene.barGraph.col1[3], length, dim);
finaliseCanvas(gui, true);
}
void GUI::addBodyGraphDesignGUI()
{
string title = "BODY GRAPH DESIGN";
ofxUICanvas* gui = getNewGUI(title);
gui->addToggle("Toggle Draw Body", &app->scene.bodyGraph.isDrawBody, toggleDim, toggleDim);
gui->addToggle("Toggle Draw Lines", &app->scene.bodyGraph.isDrawLines, toggleDim, toggleDim);
gui->addSlider("Graph Item X Gap", 5, 50, &app->scene.bodyGraph.graphItemXGap, length, dim);
gui->addSlider("Line width", 1, 50, &app->scene.bodyGraph.lineWidth, length, dim);
gui->addSlider("Graph Height Max", 0, 1, &app->scene.bodyGraph.graphHeightMax, length, dim);
gui->addSlider("Data send speed (seconds)", 0.1, 20, &app->scene.bodyGraph.sendDataSpeed, length, dim);
gui->addSpacer(length, 1);
gui->addSlider("Data0 red", 0, 255, &app->scene.bodyGraph.col0[0], length, dim);
gui->addSlider("Data0 green", 0, 255, &app->scene.bodyGraph.col0[1], length, dim);
gui->addSlider("Data0 blue", 0, 255, &app->scene.bodyGraph.col0[2], length, dim);
gui->addSlider("Data0 alpha", 0, 255, &app->scene.bodyGraph.col0[3], length, dim);
//gui->addSpacer(length, 1);
//gui->addSlider("Data0 red", 0, 255, &app->scene.graphManager.col0[0], length, dim);
//gui->addSlider("Data0 green", 0, 255, &app->scene.graph.col0[1], length, dim);
//gui->addSlider("Data0 blue", 0, 255, &app->scene.graph.col0[2], length, dim);
//gui->addSlider("Data0 alpha", 0, 255, &app->scene.graph.col0[3], length, dim);
gui->addSpacer(length, 1);
gui->addSlider("Data1 red", 0, 255, &app->scene.bodyGraph.col1[0], length, dim);
gui->addSlider("Data1 green", 0, 255, &app->scene.bodyGraph.col1[1], length, dim);
gui->addSlider("Data1 blue", 0, 255, &app->scene.bodyGraph.col1[2], length, dim);
gui->addSlider("Data1 alpha", 0, 255, &app->scene.bodyGraph.col1[3], length, dim);
finaliseCanvas(gui, true);
}
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", 0, 1, &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);
}
@@ -178,74 +119,6 @@ void GUI::addGraphSimulationGUI()
}
void GUI::addBackgroundGUI()
{
string title = "BACKGROUND";
ofxUICanvas* gui = getNewGUI(title);
gui->addToggle("Toggle Video Visibility", &app->scene.isVideoVisible, toggleDim, toggleDim);
gui->addToggle("Toggle Image Visibility", &app->scene.isImageVisible, toggleDim, toggleDim);
gui->addSlider("Video/Image Width Percent", 0, 2, &app->scene.videoWidthPercentage, length, dim);
gui->addSlider("Video/Image Height Percent", 0, 2, &app->scene.videoHeightPercentage, length, dim);
gui->addLabel("VIDEO IMAGE SETTINGS");
gui->addSlider("Brightness", 0, 2, &app->scene.brightness, length, dim);
gui->addSlider("Contrast", 0, 2, &app->scene.contrast, length, dim);
gui->addSlider("Saturation", 0, 2, &app->scene.saturation, length, dim);
gui->addSlider("Red", 0, 2, &app->scene.red, length, dim);
gui->addSlider("Green", 0, 2, &app->scene.green, length, dim);
gui->addSlider("Blue", 0, 2, &app->scene.blue, length, dim);
gui->addSlider("Alpha", 0, 2, &app->scene.alpha, length, dim);
gui->addSpacer(length, 1);
gui->addLabel("HUD BACKGROUND SETTINGS");
gui->addSlider("Red .", 0, 255, &app->scene.hudColour[0], length, dim);
gui->addSlider("Green .", 0, 255, &app->scene.hudColour[1], length, dim);
gui->addSlider("Blue .", 0, 255, &app->scene.hudColour[2], length, dim);
gui->addSlider("Alpha .", 0, 255, &app->scene.hudColour[3], length, dim);
gui->addSlider("Hole Width Percent", 0, 2, &app->scene.hudHoleWidthPercentage, length, dim);
gui->addSlider("Hole Height Percent", 0, 2, &app->scene.hudHoleHeightPercentage, length, dim);
gui->addSlider("Circle Point Size", 0, 100, &app->scene.circlePointSize, length, dim);
gui->addLabel("CROSSHAIRS SETTINGS");
gui->addSlider("Line Width", 0, 10, &app->scene.crosshairLineWidth, length, dim);
gui->addSlider("Alpha ..", 0, 255, &app->scene.crosshairAlpha, length, dim);
gui->addSlider("Circle Size", 0, 100, &app->scene.crosshairCircleSize, length, dim);
ofAddListener(gui->newGUIEvent, this, &GUI::variousGUIEvent);
finaliseCanvas(gui, true);
}
void GUI::addHUDTextGUI()
{
string title = "HUD TEXT";
ofxUICanvas* gui = getNewGUI(title);
gui->addSlider("X Margin", 0, 500, &app->scene.xMargin, length, dim);
gui->addSlider("Y Margin", 0, 500, &app->scene.yMargin, length, dim);
gui->addSlider("Y Margin Bottom Offset", 0, 300, &app->scene.yMarginBottomOffset, length, dim);
gui->addSlider("Line Length", 50, 500, &app->scene.lineLength, length, dim);
gui->addSlider("Line Spacing", 0, 10, &app->scene.lineSpacing, length, dim);
gui->addSlider("Text Size", 10, 100, &app->scene.textSize, length, dim);
gui->addSlider("Value average amount", 2, 150, &app->scene.averageAmount, length, dim);
gui->addSpacer(length, 1);
gui->addSlider("Red", 0, 255, &app->scene.textColour[0], length, dim);
gui->addSlider("Green", 0, 255, &app->scene.textColour[1], length, dim);
gui->addSlider("Blue", 0, 255, &app->scene.textColour[2], length, dim);
gui->addSlider("Alpha", 0, 255, &app->scene.textColour[3], length, dim);
gui->addSpacer(length, 1);
gui->addLabel("COLOUR KEY");
gui->addSlider("Top Colour Box Y Offset", -300, 300, &app->scene.topColourBoxXOffset, length, dim);
gui->addSlider("Bottom Colour Box Y Offset", -300, 300, &app->scene.bottomColourBoxXOffset, length, dim);
gui->addSlider("Colour Box Thickness", 1, 50, &app->scene.colourBoxThickness, length, dim);
ofAddListener(gui->newGUIEvent, this, &GUI::variousGUIEvent);
finaliseCanvas(gui, true);
}
void GUI::addVariousGUI()
@@ -269,28 +142,6 @@ void GUI::addVariousGUI()
void GUI::graphGlobalGUIEvent(ofxUIEventArgs &e)
{
string name = e.widget->getName();
ofxUIToggle *toggle = (ofxUIToggle *) e.widget;
if (name == "Bar graph")
{
//ofxUIToggle *toggle = (ofxUIToggle *) e.widget;
if (toggle->getValue()) app->scene.activeGraph = &app->scene.barGraph;
}
else if (name == "Solid Body graph")
{
printf("------------------- Solid Body graph\n");
if (toggle->getValue()) app->scene.activeGraph = &app->scene.bodyGraph;
}
else if (name == "Separate Body graph")
{
printf("------------------- Line fade graph\n");
if (toggle->getValue()) app->scene.activeGraph = &app->scene.separateBodyGraph;
}
}
+3 -7
View File
@@ -13,7 +13,7 @@
class testApp;
class GUI : GUIManager
class GUI : public GUIManager
{
public:
virtual void setup();
@@ -21,19 +21,15 @@ public:
void addKeyboardShortcutsGUI();
void addGraphGlobalGUI();
void addBarGraphDesignGUI();
void addBodyGraphDesignGUI();
void addSeparateBodyGraphDesignGUI();
void addGraphDesignGUI();
void addGraphSimulationGUI();
void addBackgroundGUI();
void addHUDTextGUI();
void addVariousGUI();
void graphGlobalGUIEvent(ofxUIEventArgs &e);
void variousGUIEvent(ofxUIEventArgs &e);
testApp* app;
vector<string> publishers;
};
+1 -1
View File
@@ -28,7 +28,7 @@ public:
ofColor color;
protected:
//protected:
virtual void buildTopBarGUI();
virtual ofxUICanvas* getNewGUI(string title);
+1 -1
View File
@@ -31,7 +31,6 @@ void testApp::update()
dataManager.update();
scene.update();
//if (gui.isVisible())
}
@@ -63,4 +62,5 @@ void testApp::keyPressed(int key)
void testApp::windowResized(int w, int h)
{
scene.setViewport();
}
+18 -197
View File
@@ -11,231 +11,54 @@
void Scene::setup()
{
vidGrabber.initGrabber(1280, 720);
vidGrabber.setDesiredFrameRate(30);
bgImg.loadImage("images/tanks.jpg");
rgbShader.load("shaders/RGBShader");
barGraph.setup();
bodyGraph.setup();
separateBodyGraph.setup();
graphManager.setup();
camera.setDistance(100);
text.loadFont("fonts/Roboto-Light.ttf", 8);
setViewport();
}
void Scene::update()
{
vidGrabber.update();
activeGraph->update();
graphManager.update(camera.getPosition());
}
void Scene::draw()
{
drawVideo();
activeGraph->draw();
drawGraphValues();
drawCrosshairs();
drawHUDBG();
drawHUDCopy();
drawHUDColourBars();
}
ofBackground(0);
void Scene::drawVideo()
{
rgbShader.begin();
rgbShader.setUniform1f("brightness", brightness);
rgbShader.setUniform1f("contrast", contrast);
rgbShader.setUniform1f("saturation", saturation);
rgbShader.setUniform1f("red", red);
rgbShader.setUniform1f("green", green);
rgbShader.setUniform1f("blue", blue);
rgbShader.setUniform1f("alpha", alpha);
camera.begin(viewport);
float vidW = ofGetWidth() * videoWidthPercentage;
float vidH = ofGetHeight() * videoHeightPercentage;
ofPushMatrix();
ofTranslate((ofGetWidth() - vidW) * 0.5, (ofGetHeight() - vidH) * 0.5);
if (isVideoVisible)
vidGrabber.draw(0, 0, vidW, vidH);
if (isImageVisible)
bgImg.draw(0, 0, vidW, vidH);
ofRotateZ(90);
ofSetColor(255, 100);
ofDrawGridPlane(60, 10, false);
ofPopMatrix();
rgbShader.end();
}
graphManager.draw();
void Scene::drawGraphValues()
{
if (activeGraph->publisher0Data.size() < 2) return;
ofPoint val0 = activeGraph->currentPub0Point;
ofPoint val1 = activeGraph->currentPub1Point;
ofPushStyle();
text.setAlignment(FTGL_ALIGN_LEFT);
ofSetColor(graphTextColour[0], graphTextColour[1], graphTextColour[2], graphTextColour[3]);
text.setSize(graphTextSize);
text.drawString(ofToString(activeGraph->publisher0Data.back().value), val0.x + 10, val0.y);
text.drawString(ofToString(activeGraph->publisher1Data.back().value), val1.x + 10, val1.y);
ofPopStyle();
}
void Scene::drawCrosshairs()
{
ofPushStyle();
ofSetLineWidth(crosshairLineWidth);
ofSetColor(hudColour[0], hudColour[1], hudColour[2], crosshairAlpha);
ofLine(ofGetWidth() * 0.5, 0, ofGetWidth() * 0.5, ofGetHeight()); // vert
ofLine(0, ofGetHeight() * 0.5, ofGetWidth(), ofGetHeight() * 0.5); // horz
ofCircle(ofGetWidth() * 0.5, ofGetHeight() * 0.5, crosshairCircleSize);
ofPopStyle();
}
void Scene::drawHUDBG()
{
ofPushStyle();
ofSetColor(hudColour[0], hudColour[1], hudColour[2], hudColour[3]);
ofBeginShape();
ofVertex(0, 0);
ofVertex(ofGetWidth(), 0);
ofVertex(ofGetWidth(), ofGetHeight());
ofVertex(0, ofGetHeight());
ofNextContour(true);
float radiusW = (ofGetWidth() * 0.5) * hudHoleWidthPercentage;
float radiusH = (ofGetHeight() * 0.5) * hudHoleHeightPercentage;
for (int i = 0; i < (int)circlePointSize; i++)
{
float x = (ofGetWidth() * 0.5) + cos(((float)i / (int)circlePointSize) * TWO_PI) * radiusW;
float y = (ofGetHeight() * 0.5) + sin(((float)i / (int)circlePointSize) * TWO_PI) * radiusH;
ofVertex(x, y);
}
ofEndShape(true);
ofPopStyle();
ofFill();
}
void Scene::drawHUDCopy()
{
text.setLineLength(lineLength);
text.setLineSpacing(lineSpacing);
text.setSize(textSize);
drawTextBox(tlStr, "TOP LEFT");
drawTextBox(trStr, "TOP RIGHT");
vector<DataObject> *p0Data = &activeGraph->publisher0Data;
vector<DataObject> *p1Data = &activeGraph->publisher1Data;
int amountToAverage = MIN(p0Data->size(), averageAmount);
if (p0Data->size() > 2)
{
float average0 = 0;
for (int i = 0; i < (int)amountToAverage; i++)
average0 += p0Data->at(p0Data->size() - i - 1).value;
average0 /= (int)amountToAverage;
// (p0Data->back() + p0Data->at(p0Data->size() - 2) + p0Data->at(p0Data->size() - 2))
blStr = "Increase: " + ofToString(p0Data->back().value - p0Data->at(p0Data->size() - 2).value) + "\n" +
"Current Value: " + ofToString(p0Data->back().value) + "\n" +
"Running average: " + ofToString(average0);
drawTextBox(blStr, "BOTTOM LEFT");
float average1 = 0;
for (int i = 0; i < (int)amountToAverage; i++)
average1 += p1Data->at(p1Data->size() - i - 1).value;
average1 /= (int)amountToAverage;
brStr = "Increase: " + ofToString(p1Data->back().value - p1Data->at(p1Data->size() - 2).value) + "\n" +
"Current Value: " + ofToString(p1Data->back().value) + "\n" +
"Running average: " + ofToString(average1);
drawTextBox(brStr, "BOTTOM RIGHT");
}
}
void Scene::drawTextBox(string copy, string align)
{
ofPushStyle();
ofSetColor(textColour[0], textColour[1], textColour[2], textColour[3]);
ofPushMatrix();
if (align == "TOP LEFT")
{
text.setAlignment(FTGL_ALIGN_LEFT);
ofTranslate(xMargin, yMargin);
}
else if (align == "TOP RIGHT")
{
text.setAlignment(FTGL_ALIGN_RIGHT);
ofTranslate(ofGetWidth() - xMargin - lineLength, yMargin);
}
else if (align == "BOTTOM LEFT")
{
ofTranslate(xMargin, ofGetHeight() - yMargin - yMarginBottomOffset);
text.setAlignment(FTGL_ALIGN_LEFT);
}
if (align == "BOTTOM RIGHT")
{
text.setAlignment(FTGL_ALIGN_RIGHT);
ofTranslate(ofGetWidth() - xMargin - lineLength, ofGetHeight() - yMargin - yMarginBottomOffset);
}
text.drawString(copy, 0, 0);
//printf("%s text.getXHeight() = %f\n", align.c_str(), text.getStringBoundingBox(copy, xMargin, yMargin));
ofPopMatrix();
ofPopStyle();
camera.end();
}
void Scene::drawHUDColourBars()
void Scene::setViewport()
{
ofPushStyle();
ofSetColor(activeGraph->col0[0], activeGraph->col0[1], activeGraph->col0[2], activeGraph->col0[3]);
ofRect(xMargin, yMargin + topColourBoxXOffset, lineLength, colourBoxThickness);
ofSetColor(activeGraph->col0[0], activeGraph->col0[1], activeGraph->col0[2], activeGraph->col0[3]);
ofRect(xMargin, ofGetHeight() - yMargin - yMarginBottomOffset + bottomColourBoxXOffset, lineLength, colourBoxThickness);
ofSetColor(activeGraph->col1[0], activeGraph->col1[1], activeGraph->col1[2], activeGraph->col1[3]);
ofRect(ofGetWidth() - xMargin - lineLength, yMargin + topColourBoxXOffset, lineLength, colourBoxThickness);
ofSetColor(activeGraph->col1[0], activeGraph->col1[1], activeGraph->col1[2], activeGraph->col1[3]);
ofRect(ofGetWidth() - xMargin - lineLength, ofGetHeight() - yMargin - yMarginBottomOffset + bottomColourBoxXOffset, lineLength, colourBoxThickness);
ofPopStyle();
viewport = ofRectangle(0, 0, ofGetWidth(), ofGetHeight());
}
void Scene::addNewData(vector<DataObject> newData)
{
barGraph.addNewData(newData);
bodyGraph.addNewData(newData);
separateBodyGraph.addNewData(newData);
graphManager.addNewData(newData);
tlStr = newData[0].info + "\n" + ofToString(newData[0].value);
trStr = newData[1].info + "\n" + ofToString(newData[1].value);
//tlStr = newData[0].info + "\n" + ofToString(newData[0].value);
//trStr = newData[1].info + "\n" + ofToString(newData[1].value);
millisAtLastData = ofGetElapsedTimeMillis();
//millisAtLastData = ofGetElapsedTimeMillis();
}
@@ -247,7 +70,5 @@ void Scene::keyPressed(int key)
void Scene::clearGraphData()
{
barGraph.clear();
bodyGraph.clear();
separateBodyGraph.clear();
graphManager.clearGraphData();
}
+8 -67
View File
@@ -9,11 +9,10 @@
#pragma once
#include "ofMain.h"
#include "BarGraph.h"
#include "BodyGraph.h"
#include "SeparateBodyGraph.h"
#include "Graph.h"
#include "DataManager.h"
#include "ofxFTGL.h"
#include "GraphManager.h"
class testApp;
@@ -23,76 +22,18 @@ public:
void setup();
void update();
void draw();
void drawVideo();
void drawGraphValues();
void drawCrosshairs();
void drawHUDBG();
void drawHUDCopy();
void drawHUDColourBars();
void setViewport();
void drawTextBox(string copy, string align);
void addNewData(vector<DataObject> newData);
void clearGraphData();
void keyPressed(int key);
BarGraph barGraph;
BodyGraph bodyGraph;
SeparateBodyGraph separateBodyGraph;
ofShader rgbShader;
ofVideoGrabber vidGrabber;
ofImage bgImg;
GraphManager graphManager;
ofEasyCam camera;
ofRectangle viewport;
ofxFTGLSimpleLayout text;
AbstractGraph* activeGraph;
// video image vars
float brightness;
float contrast;
float saturation;
float red;
float green;
float blue;
float alpha;
float videoWidthPercentage;
float videoHeightPercentage;
bool isVideoVisible;
bool isImageVisible;
// graph text
float graphTextColour[4];
float graphTextSize;
// crosshairs
float crosshairLineWidth;
float crosshairAlpha;
float crosshairCircleSize;
// HUD background vars
float hudColour[4];
float circlePointSize;
float hudHoleWidthPercentage;
float hudHoleHeightPercentage;
// text vars
float xMargin;
float yMargin;
float yMarginBottomOffset;
float lineLength;
float lineSpacing;
float textSize;
float textColour[4];
string tlStr;
string trStr;
string blStr;
string brStr;
long millisAtLastData;
float averageAmount;
// text colour boxes
float topColourBoxXOffset;
float bottomColourBoxXOffset;
float colourBoxThickness;
};
@@ -8,8 +8,7 @@
#include "AbstractGraph.h"
float AbstractGraph::minGraphPercent;
float AbstractGraph::maxGraphPercent;
void AbstractGraph::setup()
{
@@ -19,7 +18,6 @@ void AbstractGraph::setup()
void AbstractGraph::update()
{
maxData = (ofGetWidth() * (AbstractGraph::maxGraphPercent - AbstractGraph::minGraphPercent)) / graphItemXGap;
}
@@ -32,19 +30,7 @@ void AbstractGraph::draw()
void AbstractGraph::addNewData(vector<DataObject> newData)
{
publisher0Data.push_back(newData[0]);
publisher1Data.push_back(newData[1]);
while (publisher0Data.size() > maxData && publisher0Data.size() > maxData)
{
publisher0Data.erase(publisher0Data.begin());
publisher1Data.erase(publisher1Data.begin());
}
}
void AbstractGraph::clear()
{
publisher0Data.clear();
publisher1Data.clear();
}
@@ -21,24 +21,6 @@ public:
virtual void addNewData(vector<DataObject> newData);
void clear();
vector<DataObject> publisher0Data;
vector<DataObject> publisher1Data;
int maxData; // calculated from graphWidth and graphItemXGap
static float minGraphPercent;
static float maxGraphPercent;
ofPoint currentPub0Point;
ofPoint currentPub1Point;
float graphItemXGap;
float graphHeightMax;
float col0[4];
float col1[4];
string graphName;
float sendDataSpeed;
};
+145
View File
@@ -0,0 +1,145 @@
//
// Created by James Alliban on 11/01/2014.
//
//
#include "Graph.h"
#include "testApp.h"
float Graph::minGraphPercent;
float Graph::maxGraphPercent;
float Graph::maxGraphWidth;
bool Graph::isDrawLines;
float Graph::graphItemXGap;
float Graph::lineWidth;
float Graph::graphHeightMax;
float Graph::graphEndPercent;
Graph::Graph(int _graphID)
{
app = (testApp*)ofGetAppPtr();
graphID = _graphID;
}
void Graph::update(ofVec3f activeCamPos)
{
ofVec3f camPos = activeCamPos;
centre = ofVec3f(0.1, 0.1, ofMap(graphID, 0, 29, -50, 50));
distToCam = sqrt(double(ABS(camPos.x - centre.x) * ABS(camPos.x - centre.x) * ABS(camPos.x - centre.x) +
ABS(camPos.y - centre.y) * ABS(camPos.y - centre.y) * ABS(camPos.y - centre.y) +
ABS(camPos.z - centre.z) * ABS(camPos.z - centre.z) * ABS(camPos.z - centre.z)));
maxData = maxGraphWidth / graphItemXGap;
}
void Graph::draw()
{
if (app->gui.isVisible)
{
float timePerScreenfull = (float)maxData * app->dataManager.sendDataSpeed;
ofDrawBitmapString("Time to fill screen:" + ofToString(timePerScreenfull), 500, 150);
}
if (publisher0Data.size() > 1)
{
ofMesh body0 = getMesh(publisher0Data, col0);
if (body0.getVertices().size() > 2)
{
currentPub0Point = ofPoint(body0.getVertex(body0.getVertices().size() - 2).x, body0.getVertex(body0.getVertices().size() - 2).y);
}
float xOffset = 0;
float outputMin = 0;
float outputMax = graphHeightMax;
// draw lines
ofPushStyle();
ofPolyline poly0;
for (int i = 0; i < publisher0Data.size() - 1; i++)
{
if (i < publisher0Data.size() - 1)
{
ofSetLineWidth(lineWidth);
poly0.addVertex(ofVec3f(
i * graphItemXGap - (maxGraphWidth * 0.5),
ofMap(publisher0Data[i].value, publisher0Data[i].min, publisher0Data[i].max, outputMin, outputMax),
centre.z));
}
}
//ofVec3f(
// i * graphItemXGap - (maxGraphWidth * 0.5),
// ofMap(publisherData[i].value, publisherData[i].min, publisherData[i].max, outputMin, outputMax),
// 0)
ofVec2f centroid0 = poly0.getCentroid2D();
float av0;
for (int i = 0; i < poly0.size(); i++)
av0 += poly0[i].y;
av0 /= poly0.size();
int lineAlpha = 255;
if (!isDrawLines) lineAlpha = 0;
body0.drawFaces();
//body0.drawWireframe();
//ofSetColor(col0[0],col0[1],col0[2], lineAlpha);
//poly0.draw();
ofPopStyle();
}
}
ofMesh Graph::getMesh(vector<DataObject> publisherData, float* col)
{
ofMesh bodyMesh;
float xOffset = 0;
float outputMin = 0;
float outputMax = 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 - (maxGraphWidth * 0.5),
ofMap(publisherData[i].value, publisherData[i].min, publisherData[i].max, outputMin, outputMax),
centre.z));
bodyMesh.addVertex(ofVec3f(
i * graphItemXGap - (maxGraphWidth * 0.5),
0,
centre.z));
ofColor tempCol = ofColor(ofMap(graphID, 0, 29, 0, 255), ofMap(graphID, 0, 29, 255, 0), ofMap(graphID, 0, 29, 150, 50), 255);
bodyMesh.addColor(tempCol);
bodyMesh.addColor(ofColor(tempCol.r, tempCol.g, tempCol.b, 0));
//bodyMesh.addColor(ofColor(col[0],col[1],col[2], 255));
//bodyMesh.addColor(ofColor(col[0],col[1],col[2], 0));
}
return bodyMesh;
}
void Graph::addNewData(DataObject newData)
{
publisher0Data.push_back(newData);
while (publisher0Data.size() > maxData && publisher0Data.size() > maxData)
publisher0Data.erase(publisher0Data.begin());
}
void Graph::clear()
{
publisher0Data.clear();
}
+52
View File
@@ -0,0 +1,52 @@
#pragma once
#include "ofMain.h"
#include "DataManager.h"
class testApp;
class Graph
{
public:
Graph(int _graphID);
void update(ofVec3f ativeCamPos);
void draw();
void addNewData(DataObject newData);
ofMesh getMesh(vector<DataObject> publisherData, float* col);
void clear();
testApp *app;
int graphID;
vector<DataObject> publisher0Data;
int maxData; // calculated from graphWidth and graphItemXGap
//ofFbo
static float minGraphPercent;
static float maxGraphPercent;
static float maxGraphWidth;
static bool isDrawLines;
static float graphItemXGap;
static float lineWidth;
static float graphHeightMax;
static float graphEndPercent;
//float minGraphPercent;
//float maxGraphPercent;
//float maxGraphWidth;
//bool isDrawLines;
//float graphItemXGap;
//float lineWidth;
//float graphHeightMax;
//float graphEndPercent;
ofPoint currentPub0Point;
float col0[4];
float distToCam;
ofVec3f centre;
};
@@ -0,0 +1,55 @@
#include "GraphManager.h"
void GraphManager::setup()
{
for (int i = 0; i < 30; i++)
{
Graph *graph = new Graph(i);
//graph.setup(i);
graphs.push_back(graph);
}
}
void GraphManager::update(ofVec3f ativeCamPos)
{
for (int i = 0; i < graphs.size(); i++)
{
Graph *graph = graphs[i];
graph->update(ativeCamPos);
}
std::sort(graphs.begin(), graphs.end(), compareGraphByDistToCam());
}
void GraphManager::draw()
{
for (int i = 0; i < graphs.size(); i++)
{
Graph *graph = graphs[i];
graph->draw();
}
}
void GraphManager::addNewData(vector<DataObject> newData)
{
for (int i = 0; i < graphs.size(); i++)
{
Graph *graph = graphs[i];
graph->addNewData(newData[i]);
}
}
void GraphManager::clearGraphData()
{
for (int i = 0; i < graphs.size(); i++)
{
Graph *graph = graphs[i];
graph->clear();
}
}
@@ -0,0 +1,21 @@
#include "ofMain.h"
#include "DataManager.h"
#include "Graph.h"
struct compareGraphByDistToCam
{
bool operator() (const Graph* lhs, const Graph* rhs) { return lhs->distToCam > rhs->distToCam; }
};
class GraphManager
{
public:
void setup();
void update(ofVec3f ativeCamPos);
void draw();
void addNewData(vector<DataObject> newData);
void clearGraphData();
vector<Graph*> graphs;
};
@@ -1,143 +0,0 @@
//
// 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)
{
ofMesh body0 = getMesh(publisher0Data, col0);
ofMesh body1 = getMesh(publisher1Data, col1);
if (body0.getVertices().size() > 2)
{
currentPub0Point = ofPoint(body0.getVertex(body0.getVertices().size() - 2).x, body0.getVertex(body0.getVertices().size() - 2).y);
currentPub1Point = ofPoint(body0.getVertex(body1.getVertices().size() - 2).x, body1.getVertex(body1.getVertices().size() - 2).y);
}
float xOffset = ofGetWidth() * AbstractGraph::minGraphPercent;
float outputMin = (ofGetHeight() * 0.5) - ((ofGetHeight() * 0.5) * graphHeightMax);
float outputMax = (ofGetHeight() * 0.5) + ((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();
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();
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();
}
ofPopStyle();
}
}
ofMesh SeparateBodyGraph::getMesh(vector<DataObject> publisherData, float* col)
{
ofMesh bodyMesh;
float xOffset = ofGetWidth() * AbstractGraph::minGraphPercent;
float outputMin = (ofGetHeight() * 0.5) - ((ofGetHeight() * 0.5) * graphHeightMax);
float outputMax = (ofGetHeight() * 0.5) + ((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);
}
@@ -1,24 +0,0 @@
#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;
};