Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Showing
with 2952 additions and 0 deletions
//
// BarChart.hpp
// RapidVisualizerOSC
//
// Created by James on 09/11/2017.
//
//
#ifndef BarChart_hpp
#define BarChart_hpp
#include <stdio.h>
#include "RealTimeGraph.hpp"
class BarChart : public RealTimeGraph
{
public:
BarChart ( GraphState* state ) : RealTimeGraph (state)
{
//
}
~BarChart ( void )
{
//
}
void updateRep ( void )
{
//
}
void drawSubGraph ( std::string subLabel, DataContainer<std::vector<double>>& data, ofRectangle subLabelRect )
{
double
minIn = 0,
minOut = 0,
maxOut = -subLabelRect.height,
startPosY = subLabelRect.height,
barSize = subLabelRect.width/data.labelData.size(),
separation = barSize/16,
halfSeparation = separation/2;
bool drawZeroSep = false;
if (data.minValue < 0)
{ // Add negative part
startPosY = subLabelRect.height/2;
minIn = -data.maxValue;
minOut = subLabelRect.height/2;
maxOut /= 2;
drawZeroSep = true;
}
for (uint32_t i = 0; i < data.labelData.size(); ++i)
{
double output = mapVals(data.labelData[i], minIn, data.maxValue, minOut, maxOut );
ofSetColor (graphColor);
ofFill();
ofDrawRectangle(subLabelRect.x + barSize * i + halfSeparation, subLabelRect.y + startPosY, barSize - separation, output );
}
if (drawZeroSep)
{
ofSetLineWidth(1.25);
ofSetColor (175,150,150);
ofDrawLine(subLabelRect.x, subLabelRect.y + startPosY,
subLabelRect.x + subLabelRect.width, subLabelRect.y + startPosY);
}
}
void update ( void )
{
//
}
};
#endif /* BarChart_hpp */
//
// Graph.hpp
// RapidVisualizerOSC
//
// Created by James on 09/11/2017.
//
//
#ifndef Graph_h
#define Graph_h
#include <string>
#include <vector>
#include <list>
#include "ofMain.h"
#include "ofxGui.h"
// TODO: add namespace, move funcs and struct to other header(s)
enum class TextAlignment {
LEFT,
CENTER,
RIGHT
};
static inline void drawTextLabel ( std::string label, ofVec2f position, ofColor labelBackgroundColor, ofColor stringColor, TextAlignment alignment, bool drawAbove )
{
uint32_t strLenPix = label.length()*8;
switch (alignment) {
case TextAlignment::LEFT:
// No exception
break;
case TextAlignment::CENTER:
position.x -= strLenPix / 2;
break;
case TextAlignment::RIGHT:
position.x -= strLenPix;
break;
default:
break;
}
ofSetColor (labelBackgroundColor);
ofRectangle bmpStringRect(position.x - 2,
position.y + ((drawAbove) ? -4 : 12) + 2,
strLenPix + 4, -12);
ofDrawRectangle(bmpStringRect);
ofSetColor (stringColor);
ofDrawBitmapString(label, position.x, position.y + ((drawAbove) ? -4 : 12));
}
static inline double mapVals ( double x, double in_min, double in_max, double out_min, double out_max )
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
template <typename T>
struct DataContainer {
T labelData;
double minValue = 0.0;
double maxValue = 1.0;
uint32_t iteratorPos = 0;
//ofColor graphColor;
void updateMinMax ( void )
{
auto mm = std::minmax_element(labelData.begin(), labelData.end());
double min = labelData[std::distance(labelData.begin(), mm.first)];
double max = labelData[std::distance(labelData.begin(), mm.second)];
if (min < minValue)
minValue = min;
if (max > maxValue)
maxValue = max;
if (fabs(min) > maxValue)
maxValue = fabs(min);
}
};
class Graph {
public:
enum graphLayout {
GRAPHS_STACKED,
GRAPHS_VERTICAL
};
struct GraphState {
std::string label;
graphLayout layout = graphLayout::GRAPHS_STACKED;
bool hasHistory = false;
ofRectangle positionAndSize;
uint32_t historySize;
};
Graph ( GraphState* state )
: state(state)
{
graphColor = ofColor(24, 219, 92);
textColor = ofColor(255, 157, 117);
}
virtual ~Graph ( void )
{
}
virtual void updateRep ( void ) = 0; // update representation
virtual void addData ( std::string subLabel, std::vector<double>& data ) = 0;
virtual void reset ( void ) = 0;
virtual void update ( void ) = 0;
virtual void draw ( void ) = 0;
virtual uint32_t getNumSubGraphs ( void ) const = 0;
protected:
GraphState *state = nullptr;
ofColor graphColor;
ofColor textColor;
};
#endif /* Graph_h */
//
// LineGraph.hpp
// RapidVisualizerOSC
//
// Created by James on 09/11/2017.
//
//
#ifndef LineGraph_h
#define LineGraph_h
#include <stdio.h>
#include "RealTimeGraph.hpp"
class LineGraph : public RealTimeGraph
{
public:
LineGraph ( GraphState* state ) : RealTimeGraph (state)
{
//
}
~LineGraph ( void )
{
//
}
void updateRep ( void )
{
//
}
void drawSubGraph ( std::string subLabel, DataContainer<std::vector<double>>& data, ofRectangle subLabelRect )
{
double
minIn = 0,
minOut = 0,
maxOut = -subLabelRect.height,
startPosY = subLabelRect.height,
pointDistance = subLabelRect.width/data.labelData.size(),
separation = pointDistance/2;
//halfSeparation = separation/2;
bool drawZeroSep = false;
if (data.minValue < 0)
{ // Add negative part
startPosY = subLabelRect.height/2;
minIn = -data.maxValue;
minOut = subLabelRect.height/2;
maxOut /= 2;
drawZeroSep = true;
}
ofBeginShape();
ofFill();
ofVertex(subLabelRect.x, subLabelRect.y + startPosY);
double output = mapVals(data.labelData[0], minIn, data.maxValue, minOut, maxOut );
ofVertex(subLabelRect.x, subLabelRect.y + startPosY + output);
for (uint32_t i = 0; i < data.labelData.size(); ++i)
{
output = mapVals(data.labelData[i], minIn, data.maxValue, minOut, maxOut );
ofSetColor (graphColor);
ofVertex(subLabelRect.x + pointDistance * i + separation, subLabelRect.y + startPosY + output);
//ofDrawRectangle(subLabelRect.x + barSize * i + halfSeparation, subLabelRect.y + startPosY, barSize - separation, output );
}
output = mapVals(data.labelData[data.labelData.size()-1], minIn, data.maxValue, minOut, maxOut );
ofVertex(subLabelRect.x + subLabelRect.width, subLabelRect.y + startPosY + output);
ofVertex(subLabelRect.x + subLabelRect.width, subLabelRect.y + startPosY);
ofEndShape();
if (drawZeroSep)
{
ofSetLineWidth(1.25);
ofSetColor (175,150,150);
ofDrawLine(subLabelRect.x, subLabelRect.y + startPosY,
subLabelRect.x + subLabelRect.width, subLabelRect.y + startPosY);
}
}
void update ( void )
{
//
}
};
#endif /* LineGraph_h */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.