Body and separate body graphs now animating
- Also, added option to disable min/max graph clearing to GUI
This commit is contained in:
@@ -23,9 +23,12 @@ void DataManager::setup()
|
||||
|
||||
//isPublisher0DataReceived = false;
|
||||
//isPublisher1DataReceived = false;
|
||||
|
||||
nameConcat = " dev";
|
||||
|
||||
setupSpacebrew();
|
||||
|
||||
|
||||
nextDataSendTime = 0.1;
|
||||
}
|
||||
|
||||
@@ -33,7 +36,7 @@ void DataManager::setup()
|
||||
void DataManager::setupSpacebrew()
|
||||
{
|
||||
string host = "54.194.189.129"; // Spacebrew::SPACEBREW_CLOUD; // "localhost";
|
||||
string name = "Active Tripod " + ofToString(appId);
|
||||
string name = "Active Tripod " + ofToString(appId) + nameConcat;
|
||||
string description = "Description goes here. Not sure why. Let me know if you see this and tell me if you need it";
|
||||
|
||||
spacebrew.addSubscribe(publisher0Name, Spacebrew::TYPE_STRING);
|
||||
|
||||
@@ -38,6 +38,8 @@ class DataManager
|
||||
|
||||
int appId;
|
||||
|
||||
string nameConcat;
|
||||
|
||||
// create your spacebrew object
|
||||
Spacebrew::Connection spacebrew;
|
||||
|
||||
|
||||
@@ -66,6 +66,9 @@ void GUI::addGraphGlobalGUI()
|
||||
|
||||
gui->addRadio("Graph Selection", graphNames, OFX_UI_ORIENTATION_VERTICAL, dim*2, dim*2);
|
||||
|
||||
gui->addSpacer(length, 1);
|
||||
gui->addToggle("Toggle New Min/Max clear", &app->scene.isClearOnNewMinMax, toggleDim, toggleDim);
|
||||
|
||||
gui->addSpacer(length, 1);
|
||||
gui->addRangeSlider("Graph X begin/end (percent)", 0, 1, &AbstractGraph::minGraphPercent, &AbstractGraph::maxGraphPercent, length, dim);
|
||||
|
||||
|
||||
@@ -22,7 +22,8 @@ void Scene::setup()
|
||||
|
||||
text.loadFont("fonts/Roboto-Light.ttf", 8);
|
||||
|
||||
isTestScrambleMinMaxData = false;
|
||||
//isTestScrambleMinMaxData = false;
|
||||
isClearOnNewMinMax = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,6 +79,12 @@ void Scene::drawGraphValues()
|
||||
|
||||
ofPoint val0 = activeGraph->currentPub0Point;
|
||||
ofPoint val1 = activeGraph->currentPub1Point;
|
||||
|
||||
if (activeGraph->graphName == "BODY" || activeGraph->graphName == "SEPARATE_BODY")
|
||||
{
|
||||
val0 = activeGraph->graphTextPnt0;
|
||||
val1 = activeGraph->graphTextPnt1;
|
||||
}
|
||||
|
||||
string stringVal0 = reduceDecimalCount(activeGraph->publisher0Data.back().stringValue, 4);
|
||||
string stringVal1 = reduceDecimalCount(activeGraph->publisher1Data.back().stringValue, 4);
|
||||
@@ -178,10 +185,8 @@ void Scene::drawHUDCopy()
|
||||
average0 += p0Data->at(p0Data->size() - i - 1).value;
|
||||
average0 /= amountToAverage;
|
||||
|
||||
printf("l average0:%llu\n", average0);
|
||||
string valueWithCommas = addCommasToNumberString(ofToString(average0));
|
||||
printf("l av valueWithCommas:%s\n", valueWithCommas.c_str());
|
||||
|
||||
|
||||
blStr = "Increase: " + ofToString(p0Data->back().value - p0Data->at(p0Data->size() - 2).value) + "\n" +
|
||||
"Current Value: " + stringVal0 + "\n" +
|
||||
"Running average: " + reduceDecimalCount(valueWithCommas, 4);
|
||||
@@ -194,10 +199,8 @@ void Scene::drawHUDCopy()
|
||||
average0 += p0Data->at(p0Data->size() - i - 1).value;
|
||||
average0 /= amountToAverage;
|
||||
|
||||
printf("f average0:%f\n", average0);
|
||||
string valueWithCommas = (average0 > 999) ? addCommasToNumberString(ofToString(average0)) : ofToString(average0);
|
||||
printf("f av valueWithCommas:%s\n", valueWithCommas.c_str());
|
||||
|
||||
|
||||
blStr = "Increase: " + ofToString(p0Data->back().value - p0Data->at(p0Data->size() - 2).value) + "\n" +
|
||||
"Current Value: " + stringVal0 + "\n" +
|
||||
"Running average: " + reduceDecimalCount(valueWithCommas, 4);
|
||||
@@ -212,10 +215,8 @@ void Scene::drawHUDCopy()
|
||||
average1 += p1Data->at(p1Data->size() - i - 1).value;
|
||||
average1 /= amountToAverage;
|
||||
|
||||
printf("l average0:%llu\n", average1);
|
||||
string valueWithCommas = addCommasToNumberString(ofToString(average1));
|
||||
printf("l av valueWithCommas:%s\n", valueWithCommas.c_str());
|
||||
|
||||
|
||||
brStr = "Increase: " + ofToString(p1Data->back().value - p1Data->at(p1Data->size() - 2).value) + "\n" +
|
||||
"Current Value: " + stringVal1 + "\n" +
|
||||
"Running average: " + reduceDecimalCount(valueWithCommas, 4);
|
||||
@@ -228,10 +229,8 @@ void Scene::drawHUDCopy()
|
||||
average1 += p1Data->at(p1Data->size() - i - 1).value;
|
||||
average1 /= amountToAverage;
|
||||
|
||||
printf("f average1:%f\n", average1);
|
||||
string valueWithCommas = (average1 > 999) ? addCommasToNumberString(ofToString(average1)) : ofToString(average1);
|
||||
printf("f av valueWithCommas:%s\n", valueWithCommas.c_str());
|
||||
|
||||
|
||||
brStr = "Increase: " + ofToString(p1Data->back().value - p1Data->at(p1Data->size() - 2).value) + "\n" +
|
||||
"Current Value: " + stringVal1 + "\n" +
|
||||
"Running average: " + reduceDecimalCount(valueWithCommas, 4);
|
||||
@@ -300,16 +299,19 @@ void Scene::drawHUDColourBars()
|
||||
|
||||
void Scene::addNewData(vector<DataObject> newData)
|
||||
{
|
||||
if (barGraph.publisher0Data.size() > 0)
|
||||
if (isClearOnNewMinMax)
|
||||
{
|
||||
if (newData[0].min != barGraph.publisher0Data.back().min ||
|
||||
newData[0].max != barGraph.publisher0Data.back().max ||
|
||||
newData[1].min != barGraph.publisher1Data.back().min ||
|
||||
newData[1].max != barGraph.publisher1Data.back().max)
|
||||
if (barGraph.publisher0Data.size() > 0)
|
||||
{
|
||||
barGraph.clear();
|
||||
bodyGraph.clear();
|
||||
separateBodyGraph.clear();
|
||||
if (newData[0].min != barGraph.publisher0Data.back().min ||
|
||||
newData[0].max != barGraph.publisher0Data.back().max ||
|
||||
newData[1].min != barGraph.publisher1Data.back().min ||
|
||||
newData[1].max != barGraph.publisher1Data.back().max)
|
||||
{
|
||||
barGraph.clear();
|
||||
bodyGraph.clear();
|
||||
separateBodyGraph.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -87,6 +87,8 @@ public:
|
||||
string brStr;
|
||||
float averageAmount;
|
||||
|
||||
bool isClearOnNewMinMax;
|
||||
|
||||
// text colour boxes
|
||||
float topColourBoxXOffset;
|
||||
float bottomColourBoxXOffset;
|
||||
|
||||
@@ -13,12 +13,14 @@ float AbstractGraph::maxGraphPercent;
|
||||
|
||||
void AbstractGraph::setup()
|
||||
{
|
||||
millisSinceLastPoint = 0;
|
||||
}
|
||||
|
||||
|
||||
void AbstractGraph::update()
|
||||
{
|
||||
maxData = (ofGetWidth() * (AbstractGraph::maxGraphPercent - AbstractGraph::minGraphPercent)) / graphItemXGap;
|
||||
normalisedTimeInc = ofMap(ofGetElapsedTimeMillis(), millisSinceLastPoint, millisSinceLastPoint + millisGap, 0, 1);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,9 +33,14 @@ void AbstractGraph::draw()
|
||||
|
||||
void AbstractGraph::addNewData(vector<DataObject> newData)
|
||||
{
|
||||
millisGap = ofGetElapsedTimeMillis() - millisSinceLastPoint;
|
||||
millisSinceLastPoint = ofGetElapsedTimeMillis();
|
||||
|
||||
|
||||
publisher0Data.push_back(newData[0]);
|
||||
publisher1Data.push_back(newData[1]);
|
||||
|
||||
|
||||
while (publisher0Data.size() > maxData && publisher0Data.size() > maxData)
|
||||
{
|
||||
publisher0Data.erase(publisher0Data.begin());
|
||||
|
||||
@@ -41,4 +41,16 @@ public:
|
||||
string graphName;
|
||||
float sendDataSpeed;
|
||||
|
||||
|
||||
float millisSinceLastPoint;
|
||||
float millisGap;
|
||||
//ofVec3f lastVecTarget0;
|
||||
//ofVec3f lastVecTarget1;
|
||||
float normalisedTimeInc;
|
||||
|
||||
ofPoint endPoint0;
|
||||
ofPoint endPoint1;
|
||||
|
||||
ofPoint graphTextPnt0;
|
||||
ofPoint graphTextPnt1;
|
||||
};
|
||||
@@ -30,6 +30,7 @@ void BodyGraph::draw()
|
||||
ofDrawBitmapString("Time to fill screen:" + ofToString(timePerScreenfull), 500, 150);
|
||||
}
|
||||
|
||||
|
||||
if (publisher0Data.size() > 1)
|
||||
{
|
||||
float xOffset = ofGetWidth() * AbstractGraph::minGraphPercent;
|
||||
@@ -41,32 +42,67 @@ void BodyGraph::draw()
|
||||
// draw main part of graph (xOffset)
|
||||
ofMesh body;
|
||||
body.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
|
||||
|
||||
for (int i = 0; i < publisher0Data.size() - 1; i++)
|
||||
{
|
||||
body.addVertex(ofVec3f(
|
||||
i * graphItemXGap + xOffset,
|
||||
ofMap(publisher0Data[i].value, publisher0Data[i].min, publisher0Data[i].max, outputMin, outputMax),
|
||||
0));
|
||||
body.addVertex(ofVec3f(
|
||||
i * graphItemXGap + xOffset,
|
||||
ofMap(publisher1Data[i].value, publisher1Data[i].min, publisher1Data[i].max, outputMin, outputMax),
|
||||
0));
|
||||
|
||||
if (i < publisher0Data.size() - 2)
|
||||
{
|
||||
body.addVertex(ofVec3f(
|
||||
i * graphItemXGap + xOffset,
|
||||
ofMap(publisher0Data[i].value, publisher0Data[i].min, publisher0Data[i].max, outputMin, outputMax),
|
||||
0));
|
||||
body.addVertex(ofVec3f(
|
||||
i * graphItemXGap + xOffset,
|
||||
ofMap(publisher1Data[i].value, publisher1Data[i].min, publisher1Data[i].max, outputMin, outputMax),
|
||||
0));
|
||||
}
|
||||
else
|
||||
{
|
||||
float targetY0 = ofMap(publisher0Data[i].value, publisher0Data[i].min, publisher0Data[i].max, outputMin, outputMax);
|
||||
float prevY0 = ofMap(publisher0Data[i-1].value, publisher0Data[i-1].min, publisher0Data[i-1].max, outputMin, outputMax);
|
||||
endPoint0.y = ofMap(normalisedTimeInc, 0, 1, prevY0, targetY0);
|
||||
|
||||
float targetY1 = ofMap(publisher1Data[i].value, publisher1Data[i].min, publisher1Data[i].max, outputMin, outputMax);
|
||||
float prevY1 = ofMap(publisher1Data[i-1].value, publisher1Data[i-1].min, publisher1Data[i-1].max, outputMin, outputMax);
|
||||
endPoint1.y = ofMap(normalisedTimeInc, 0, 1, prevY1, targetY1);
|
||||
|
||||
endPoint0.x = (i-1) * graphItemXGap + xOffset + (graphItemXGap * normalisedTimeInc);
|
||||
endPoint1.x = endPoint0.x;
|
||||
|
||||
body.addVertex(ofVec3f(
|
||||
endPoint0.x,
|
||||
endPoint0.y,
|
||||
0));
|
||||
body.addVertex(ofVec3f(
|
||||
endPoint1.x,
|
||||
endPoint1.y,
|
||||
0));
|
||||
}
|
||||
body.addColor(ofColor(col0[0],col0[1],col0[2], col0[3]));
|
||||
body.addColor(ofColor(col1[0],col1[1],col1[2], col1[3]));
|
||||
|
||||
if (i == publisher0Data.size() - 2)
|
||||
{
|
||||
currentPub0Point = ofPoint(i * graphItemXGap + xOffset,
|
||||
ofMap(publisher0Data[i].value, publisher0Data[i].min, publisher0Data[i].max, outputMin, outputMax));
|
||||
currentPub1Point = ofPoint(i * graphItemXGap + xOffset,
|
||||
ofMap(publisher1Data[i].value, publisher1Data[i].min, publisher1Data[i].max, outputMin, outputMax));
|
||||
currentPub0Point = body.getVertex(body.getVertices().size() - 2);
|
||||
currentPub1Point = body.getVertices().back();
|
||||
}
|
||||
}
|
||||
|
||||
ofPushMatrix();
|
||||
if (publisher0Data.size() >= maxData) ofTranslate(ofMap(normalisedTimeInc, 0, 1, 0, -graphItemXGap), 0);
|
||||
body.drawFaces();
|
||||
ofPopMatrix();
|
||||
}
|
||||
|
||||
graphTextPnt0 = currentPub0Point;
|
||||
graphTextPnt1 = currentPub1Point;
|
||||
|
||||
if (publisher0Data.size() >= maxData)
|
||||
{
|
||||
float meshXOffset = ofMap(normalisedTimeInc, 0, 1, 0, -graphItemXGap);
|
||||
graphTextPnt0.x += meshXOffset;
|
||||
graphTextPnt1.x += meshXOffset;
|
||||
}
|
||||
|
||||
if (isDrawLines)
|
||||
{
|
||||
@@ -78,22 +114,40 @@ void BodyGraph::draw()
|
||||
{
|
||||
if (i < publisher0Data.size() - 1)
|
||||
{
|
||||
poly0.addVertex(ofPoint(
|
||||
i * graphItemXGap + xOffset,
|
||||
ofMap(publisher0Data[i].value, publisher0Data[i].min, publisher0Data[i].max, outputMin, outputMax)));
|
||||
if (i < publisher0Data.size() - 2)
|
||||
{
|
||||
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)));
|
||||
poly1.addVertex(ofPoint(
|
||||
i * graphItemXGap + xOffset,
|
||||
ofMap(publisher1Data[i].value, publisher1Data[i].min, publisher1Data[i].max, outputMin, outputMax)));
|
||||
}
|
||||
else
|
||||
{
|
||||
poly0.addVertex(ofPoint(
|
||||
endPoint0.x,
|
||||
endPoint0.y));
|
||||
|
||||
|
||||
poly1.addVertex(ofPoint(
|
||||
endPoint1.x,
|
||||
endPoint1.y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ofSetLineWidth(lineWidth);
|
||||
ofPushMatrix();
|
||||
if (publisher0Data.size() >= maxData) ofTranslate(ofMap(normalisedTimeInc, 0, 1, 0, -graphItemXGap), 0);
|
||||
ofSetColor(col0[0],col0[1],col0[2], 255);
|
||||
poly0.draw();
|
||||
ofSetColor(col1[0],col1[1],col1[2], 255);
|
||||
poly1.draw();
|
||||
ofPopMatrix();
|
||||
ofPopStyle();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,19 +53,11 @@ void SeparateBodyGraph::draw()
|
||||
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)));
|
||||
poly0.addVertex(body0.getVertex(i*2));
|
||||
poly1.addVertex(body1.getVertex(i*2));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
ofVec2f centroid0 = poly0.getCentroid2D();
|
||||
ofVec2f centroid1 = poly1.getCentroid2D();
|
||||
|
||||
@@ -82,7 +74,19 @@ void SeparateBodyGraph::draw()
|
||||
|
||||
int lineAlpha = 255;
|
||||
if (!isDrawLines) lineAlpha = 0;
|
||||
|
||||
graphTextPnt0 = currentPub0Point;
|
||||
graphTextPnt1 = currentPub1Point;
|
||||
|
||||
ofPushMatrix();
|
||||
if (publisher0Data.size() >= maxData)
|
||||
{
|
||||
float meshXOffset = ofMap(normalisedTimeInc, 0, 1, 0, -graphItemXGap);
|
||||
ofTranslate(meshXOffset, 0);
|
||||
graphTextPnt0.x += meshXOffset;
|
||||
graphTextPnt1.x += meshXOffset;
|
||||
}
|
||||
|
||||
if (av0 < av1)
|
||||
{
|
||||
body0.drawFaces();
|
||||
@@ -103,6 +107,7 @@ void SeparateBodyGraph::draw()
|
||||
ofSetColor(col0[0],col0[1],col0[2], lineAlpha);
|
||||
poly0.draw();
|
||||
}
|
||||
ofPopMatrix();
|
||||
|
||||
ofPopStyle();
|
||||
}
|
||||
@@ -120,14 +125,34 @@ ofMesh SeparateBodyGraph::getMesh(vector<DataObject> publisherData, float* col)
|
||||
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));
|
||||
if (i < publisherData.size() - 2)
|
||||
{
|
||||
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));
|
||||
}
|
||||
else
|
||||
{
|
||||
float targetY0 = ofMap(publisherData[i].value, publisherData[i].min, publisherData[i].max, outputMin, outputMax);
|
||||
float prevY0 = ofMap(publisherData[i-1].value, publisherData[i-1].min, publisherData[i-1].max, outputMin, outputMax);
|
||||
endPoint0.y = ofMap(normalisedTimeInc, 0, 1, prevY0, targetY0);
|
||||
endPoint0.x = (i-1) * graphItemXGap + xOffset + (graphItemXGap * normalisedTimeInc);
|
||||
|
||||
bodyMesh.addVertex(ofVec3f(
|
||||
endPoint0.x,
|
||||
endPoint0.y,
|
||||
0));
|
||||
bodyMesh.addVertex(ofVec3f(
|
||||
endPoint0.x,
|
||||
ofGetHeight() * graphEndPercent,
|
||||
0));
|
||||
}
|
||||
|
||||
|
||||
bodyMesh.addColor(ofColor(col[0],col[1],col[2], col[3]));
|
||||
bodyMesh.addColor(ofColor(col[0],col[1],col[2], 0));
|
||||
|
||||
Reference in New Issue
Block a user