diff --git a/Frontend/GFXUtilities/ActionBubble.h b/Frontend/GFXUtilities/ActionBubble.h index 7cd4db3..98dd31b 100644 --- a/Frontend/GFXUtilities/ActionBubble.h +++ b/Frontend/GFXUtilities/ActionBubble.h @@ -17,6 +17,7 @@ #ifndef _RUACTIONBUBBLE #define _RUACTIONBUBBLE +#include "GraphablePoint.h" #include #include #include @@ -29,7 +30,7 @@ class gfxpp; class Point2; -class ActionBubble +class ActionBubble : public GraphablePoint { protected: @@ -62,6 +63,36 @@ class ActionBubble float getCost() const; int getQuantity() const; int getActionType() const; + + virtual double getX() const + { + return 0; + } + + virtual double getY() const + { + return 0; + } + + virtual void setX(double newX) + { + // + } + + virtual void setY(double newY) + { + // + } + + virtual double getMinY() const + { + return 0; + } + + virtual double getMaxY() const + { + return 0; + } }; #endif diff --git a/Frontend/GFXUtilities/Candle.h b/Frontend/GFXUtilities/Candle.h index 820abb5..190e7eb 100644 --- a/Frontend/GFXUtilities/Candle.h +++ b/Frontend/GFXUtilities/Candle.h @@ -17,6 +17,7 @@ #ifndef _GCANDLE #define _GCANDLE +#include "GraphablePoint.h" #include #include #include @@ -120,6 +121,26 @@ class Candle { return (getX() > c2.getX()); } + + virtual double getY() const + { + return getClose(); + } + + virtual void setY(double newY) + { + // + } + + virtual double getMinY() const + { + return getLow(); + } + + virtual double getMaxY() const + { + return getHigh(); + } }; #endif diff --git a/Frontend/GFXUtilities/Circle.h b/Frontend/GFXUtilities/Circle.h index 6d4de94..fc78dfa 100644 --- a/Frontend/GFXUtilities/Circle.h +++ b/Frontend/GFXUtilities/Circle.h @@ -17,6 +17,8 @@ #ifndef _RUCIRCLE #define _RUCIRCLE +#include "GraphablePoint.h" +#include "point2.h" #include #include #include @@ -29,7 +31,7 @@ class gfxpp; class Point2; -class Circle +class Circle : public GraphablePoint { protected: @@ -47,6 +49,37 @@ class Circle const Point2* getCenter() const; double getRadius() const; + + virtual double getX() const + { + return 0; + } + + virtual double getY() const + { + return 0; + } + + virtual void setX(double newX) + { + center->setX(newX); + } + + virtual void setY(double newY) + { + center->setY(newY); + } + + virtual double getMinY() const + { + return center->getY(); + } + + virtual double getMaxY() const + { + return center->getY(); + } + }; #endif diff --git a/Frontend/GFXUtilities/DrawNeuralNet.cpp b/Frontend/GFXUtilities/DrawNeuralNet.cpp index 13d6d28..6022746 100644 --- a/Frontend/GFXUtilities/DrawNeuralNet.cpp +++ b/Frontend/GFXUtilities/DrawNeuralNet.cpp @@ -98,7 +98,7 @@ void DrawNeuralNet::setWeights(shmea::GList weights) int neuron = 0; std::vector > newWeights; - for(int i = 0; i < weights.size(); ++i) + for(unsigned int i = 0; i < weights.size(); ++i) { if(weights[i].getType() == shmea::GType::FLOAT_TYPE) { diff --git a/Frontend/GFXUtilities/DrawNeuralNet.h b/Frontend/GFXUtilities/DrawNeuralNet.h index 5410cce..e8605ff 100644 --- a/Frontend/GFXUtilities/DrawNeuralNet.h +++ b/Frontend/GFXUtilities/DrawNeuralNet.h @@ -1,16 +1,18 @@ #ifndef _DRAWNEURALNET #define _DRAWNEURALNET -#include -#include +#include "GraphablePoint.h" #include "RULayerInfo.h" -#include #include "Backend/Database/GPointer.h" #include "Backend/Database/GList.h" #include "Backend/Database/GType.h" +#include +#include +#include + class gfxpp; -class DrawNeuralNet +class DrawNeuralNet : public GraphablePoint { protected: @@ -41,6 +43,35 @@ class DrawNeuralNet void displayNeuralNet(); + virtual double getX() const + { + return 0; + } + + virtual double getY() const + { + return 0; + } + + virtual void setX(double newX) + { + // + } + + virtual void setY(double newY) + { + // + } + + virtual double getMinY() const + { + return 0; + } + + virtual double getMaxY() const + { + return 0; + } diff --git a/Frontend/RUGraph/GraphableAttr.h b/Frontend/GFXUtilities/GraphablePoint.h similarity index 50% rename from Frontend/RUGraph/GraphableAttr.h rename to Frontend/GFXUtilities/GraphablePoint.h index 85997fc..9ee2a04 100644 --- a/Frontend/RUGraph/GraphableAttr.h +++ b/Frontend/GFXUtilities/GraphablePoint.h @@ -1,4 +1,4 @@ -// Copyright 2020 Robert Carneiro, Derek Meer, Matthew Tabak, Eric Lujan +// Copyright 2024 Robert Carneiro, Derek Meer, Matthew Tabak, Eric Lujan // // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and // associated documentation files (the "Software"), to deal in the Software without restriction, @@ -14,59 +14,26 @@ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -#ifndef _GRAPHABLEATTR_H -#define _GRAPHABLEATTR_H +#ifndef _GRAPHABLEPOINT +#define _GRAPHABLEPOINT -#include -#include -#include +#include +#include +#include #include #include -#include -#include -#include "../GFXUtilities/point2.h" -#include "../GFXUtilities/Candle.h" -#include "../Graphics/graphics.h" -#include "Backend/Database/GList.h" -#include "Backend/Database/standardizable.h" -class RUGraph; - -class GraphableAttr : public shmea::GStandardizable +class GraphablePoint { -protected: - RUGraph* parent; - bool xMode; - bool yMode; - SDL_Color lineColor; - public: + virtual double getX() const = 0; + virtual double getY() const = 0; - const static int TEXTURE_MAX_DIM = 16384; - - // constructors & destructor - GraphableAttr(); - GraphableAttr(RUGraph*, SDL_Color); - virtual ~GraphableAttr(); - - // gets - float getXMinModed() const; - float getXMaxModed() const; - float getYMinModed() const; - float getYMaxModed() const; - bool getXMode() const; - bool getYMode() const; - SDL_Color getColor() const; - - // sets - void setXMode(bool); - void setYMode(bool); - void setColor(SDL_Color); - virtual void clear(); + virtual void setX(double) = 0; + virtual void setY(double) = 0; - // render - virtual void draw(gfxpp*) = 0; - virtual void updateBackground(gfxpp*); + virtual double getMinY() const = 0; + virtual double getMaxY() const = 0; }; #endif diff --git a/Frontend/GFXUtilities/Horizontal_Line.h b/Frontend/GFXUtilities/Horizontal_Line.h index fcf2063..61f6dfd 100644 --- a/Frontend/GFXUtilities/Horizontal_Line.h +++ b/Frontend/GFXUtilities/Horizontal_Line.h @@ -17,6 +17,7 @@ #ifndef _GHORIZONTALLINE #define _GHORIZONTALLINE +#include "GraphablePoint.h" #include #include #include @@ -24,7 +25,7 @@ #include #include -class Horizontal_Line +class Horizontal_Line : public GraphablePoint { private: double y; @@ -93,6 +94,26 @@ class Horizontal_Line { return (getY() > c2.getY()); } + + virtual double getX() const + { + return 0; + } + + virtual void setX(double newX) + { + // + } + + virtual double getMinY() const + { + return getY(); + } + + virtual double getMaxY() const + { + return getY(); + } }; #endif diff --git a/Frontend/GFXUtilities/point2.cpp b/Frontend/GFXUtilities/point2.cpp index 763007c..2ff156a 100644 --- a/Frontend/GFXUtilities/point2.cpp +++ b/Frontend/GFXUtilities/point2.cpp @@ -80,17 +80,3 @@ void Point2::normalize() x /= len; y /= len; } - -shmea::GList Point2::toXVectorData() const -{ - shmea::GList xData; - xData.addFloat(getX()); - return xData; -} - -shmea::GList Point2::toYVectorData() const -{ - shmea::GList yData; - yData.addFloat(getY()); - return yData; -} diff --git a/Frontend/GFXUtilities/point2.h b/Frontend/GFXUtilities/point2.h index 2c7ef27..dba19fa 100644 --- a/Frontend/GFXUtilities/point2.h +++ b/Frontend/GFXUtilities/point2.h @@ -17,15 +17,15 @@ #ifndef _GPOINT2 #define _GPOINT2 +#include "GraphablePoint.h" #include #include #include #include #include #include -#include "Backend/Database/StandItem.h" -class Point2 : public shmea::StandItem +class Point2 : public GraphablePoint { private: double x, y; @@ -46,8 +46,6 @@ class Point2 : public shmea::StandItem void setX(double); void setY(double); void normalize(); - virtual shmea::GList toXVectorData() const; - virtual shmea::GList toYVectorData() const; // operators inline Point2 operator+(Point2 v) @@ -106,6 +104,16 @@ class Point2 : public shmea::StandItem { return (getX() > c2.getX()); } + + virtual double getMinY() const + { + return getY(); + } + + virtual double getMaxY() const + { + return getY(); + } }; #endif diff --git a/Frontend/RUGraph/ActionBubbleGraphable.cpp b/Frontend/RUGraph/ActionBubbleGraphable.cpp index 4549094..5dcdf11 100644 --- a/Frontend/RUGraph/ActionBubbleGraphable.cpp +++ b/Frontend/RUGraph/ActionBubbleGraphable.cpp @@ -17,6 +17,8 @@ #include "Graphable.h" #include "RUGraph.h" #include "../GFXUtilities/ActionBubble.h" +#include "../GFXUtilities/point2.h" +#include "../GFXUtilities/Candle.h" template <> void Graphable::computeAxisRanges(bool additionOptimization) diff --git a/Frontend/RUGraph/CMakeLists.txt b/Frontend/RUGraph/CMakeLists.txt index 5bd9631..889fdb2 100644 --- a/Frontend/RUGraph/CMakeLists.txt +++ b/Frontend/RUGraph/CMakeLists.txt @@ -6,8 +6,6 @@ set(GraphGUI_src_files EllipseGraphable.cpp ActionBubbleGraphable.cpp NeuralNetGraphable.cpp - GraphableAttr.cpp - GraphableAttr.h HLineGraphable.cpp Graphable.h RUGraph.cpp diff --git a/Frontend/RUGraph/CandleGraphable.cpp b/Frontend/RUGraph/CandleGraphable.cpp index 53de9c6..19a4c02 100644 --- a/Frontend/RUGraph/CandleGraphable.cpp +++ b/Frontend/RUGraph/CandleGraphable.cpp @@ -16,6 +16,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "Graphable.h" #include "RUGraph.h" +#include "../GFXUtilities/Candle.h" template <> void Graphable::computeAxisRanges(bool additionOptimization) diff --git a/Frontend/RUGraph/CircleGraphable.cpp b/Frontend/RUGraph/CircleGraphable.cpp index abc32a0..04d6c65 100644 --- a/Frontend/RUGraph/CircleGraphable.cpp +++ b/Frontend/RUGraph/CircleGraphable.cpp @@ -17,6 +17,7 @@ #include "Graphable.h" #include "RUGraph.h" #include "../GFXUtilities/Circle.h" +#include "../GFXUtilities/point2.h" template <> void Graphable::computeAxisRanges(bool additionOptimization) diff --git a/Frontend/RUGraph/GeneralGraphable.h b/Frontend/RUGraph/GeneralGraphable.h index 7bc24ab..f18d725 100644 --- a/Frontend/RUGraph/GeneralGraphable.h +++ b/Frontend/RUGraph/GeneralGraphable.h @@ -60,9 +60,9 @@ class GeneralGraphable // } - GraphableModel(RUGraph* newGraph, SDL_Color newColor) + GraphableModel(RUGraph* newGraph) { - g = new Graphable(newGraph, newColor); + g = new Graphable(newGraph); } void set(const std::vector& newPoints) @@ -132,9 +132,9 @@ class GeneralGraphable } template< typename T> - GeneralGraphable(RUGraph* newGraph, SDL_Color newColor, T t) // Explicit templates on consctuctors do not work + GeneralGraphable(RUGraph* newGraph, T t) // Explicit templates on consctuctors do not work { - object = new GraphableModel(newGraph, newColor); + object = new GraphableModel(newGraph); } template< typename T> diff --git a/Frontend/RUGraph/Graphable.h b/Frontend/RUGraph/Graphable.h index e3fb794..8b6e46c 100644 --- a/Frontend/RUGraph/Graphable.h +++ b/Frontend/RUGraph/Graphable.h @@ -24,16 +24,23 @@ #include #include #include -#include "GraphableAttr.h" +#include +#include +#include "../GFXUtilities/GraphablePoint.h" +#include "../GItems/RUColors.h" +#include "../Graphics/graphics.h" +#include "Backend/Database/standardizable.h" class RUGraph; template -class Graphable : public GraphableAttr +class Graphable : public shmea::GStandardizable { private: + RUGraph* parent; std::vector points; bool visible; + SDL_Color lineColor; public: @@ -43,16 +50,19 @@ class Graphable : public GraphableAttr // constructors & destructor Graphable(); - Graphable(RUGraph*, SDL_Color); + Graphable(RUGraph*); virtual ~Graphable(); unsigned int size() const; unsigned int normalizedSize() const; bool isVisible() const; + SDL_Color getColor() const; void setVisible(bool); + void setColor(SDL_Color); void add(const T*, bool = true); void set(const std::vector&); virtual void clear(); + void updateBackground(gfxpp*); // render virtual void draw(gfxpp*); @@ -60,8 +70,9 @@ class Graphable : public GraphableAttr }; template -Graphable::Graphable(RUGraph* newParent, SDL_Color newColor) : GraphableAttr(newParent, newColor) +Graphable::Graphable(RUGraph* newParent) { + parent = newParent; visible = true; } @@ -69,6 +80,7 @@ template Graphable::Graphable() { // + parent = NULL; } template @@ -95,12 +107,24 @@ bool Graphable::isVisible() const return visible; } +template +SDL_Color Graphable::getColor() const +{ + return lineColor; +} + template void Graphable::setVisible(bool newVisible) { visible = newVisible; } +template +void Graphable::setColor(SDL_Color newColor) +{ + lineColor = newColor; +} + template void Graphable::set(const std::vector& newPoints) { @@ -153,9 +177,263 @@ void Graphable::clear() points.erase(points.begin() + i); } + parent = NULL; points.clear(); normalizedPoints.clear(); visible = false; + lineColor = RUColors::DEFAULT_COLOR_LINE; +} + +/*template +void Graphable::computeAxisRanges(bool additionOptimization) +{ + if (!parent) + return; + + if (points.empty()) + return; + + redoRange = !additionOptimization; + if(additionOptimization) + { + // Is the latest y not within the current range? + float yMax = points[points.size()-1]->getYMax(); + float yMin = points[points.size()-1]->getYMin(); + if ((yMin < getYMin()) || (yMax > getYMax())) + redoRange = true; + } + + //redoRange = true; + unsigned int i = 0; + //if(redoRange) + //i = points.size()-1; + for (; i < points.size(); ++i) + { + T* c = points[points.size()-1]; + float x_pt = c->getX(); + float y_max = c->getYMax(); + float y_min = c->getYMin(); + + setXMax(x_pt); + setXMin(x_pt); + setYMax(y_max); + setYMin(y_min); + } + + // Set the parents + parent->setXMin(getXMin()); + parent->setXMax(getXMax()); + parent->setYMin(getYMin()); + parent->setYMax(getYMax()); + + //printf("T-PRE[%s]: %f:%f\n", parent->getName().c_str(), getXMax(), getXMin()); + + //==============================================Normalize the points============================================== + + unsigned int agg = parent->getAggregate(); + float xRange = (float)points.size() / (float)agg; + float yRange = getYMax() - getYMin(); + if(points.size() % agg) + ++xRange; + + // Scales coordinates based on graph size and data range. + float pointXGap = ((float)parent->getWidth()) / xRange; + float pointYGap = ((float)parent->getHeight()) / yRange; + if(isinf(pointXGap)) + { + normalizedPoints.clear(); + return; + } + + // Size up the normalized points vec + while(normalizedPoints.size() < xRange) + { + T* newCandle = new T(); + normalizedPoints.push_back(newCandle); + } + + while(normalizedPoints.size() > xRange) + { + normalizedPoints.erase(normalizedPoints.begin()+normalizedPoints.size()-1); + } + + //Get a head start? + i = 0; + //if(!redoRange) + //i = points.size()-1; + + // Aggregate helpers + unsigned int aggCounter = 0; + float aggOpenValue = 0.0f; + float aggCloseValue = 0.0f; + float aggHighValue = 0.0f; + float aggLowValue = 0.0f; + + unsigned int normalCounter = 0; + for (; i < points.size(); ++i) + { + // First point would be drawn at x = 0, so we need to add (pointXGap / 2) + // so that the bar can be drawn left and right. + float newOpenValue = (points[i]->getOpen() - getYMin()) * pointYGap; + float newCloseValue = (points[i]->getClose() - getYMin()) * pointYGap; + float newHighValue = (points[i]->getHigh() - getYMin()) * pointYGap; + float newLowValue = (points[i]->getLow() - getYMin()) * pointYGap; + + // Time to Aggreagate + ++aggCounter; + aggCloseValue=newCloseValue; + if(aggCounter == 1) + { + aggOpenValue=newOpenValue; + aggHighValue=newHighValue; + aggLowValue=newLowValue; + } + + // Set high and low of aggregate + if(newHighValue > aggHighValue) + aggHighValue=newHighValue; + if(newLowValue < aggLowValue) + aggLowValue=newLowValue; + + // Are we done aggregating data yet? + if((aggCounter < agg) && (i < points.size()-1)) + continue; + + // Our aggregated T + //float newXValue = ((i/agg) * pointXGap); + //float newXValue = i * pointXGap + (pointXGap / 2); + float newXValue = ((i/agg) * pointXGap)+ (pointXGap / 2); + normalizedPoints[normalCounter]->setX(parent->getAxisOriginX() + newXValue); + normalizedPoints[normalCounter]->setOpen(parent->getAxisOriginY() + (float)parent->getHeight() - aggOpenValue); + normalizedPoints[normalCounter]->setClose(parent->getAxisOriginY() + (float)parent->getHeight() - aggCloseValue); + normalizedPoints[normalCounter]->setHigh(parent->getAxisOriginY() + (float)parent->getHeight() - aggHighValue); + normalizedPoints[normalCounter]->setLow(parent->getAxisOriginY() + (float)parent->getHeight() - aggLowValue); + + // The draw container + ++normalCounter; + + // Reset the agg helpers + aggCounter = 0; + aggOpenValue = 0.0f; + aggCloseValue = 0.0f; + aggHighValue = 0.0f; + aggLowValue = 0.0f; + } + + parent->requireDrawUpdate(); +}*/ + +template +void Graphable::updateBackground(gfxpp* cGfx) +{ + if(!cGfx) + return; + + // draw the line + draw(cGfx); + //parent->requireDrawUpdate(); + + redoRange = false; +} + +template +void Graphable::computeAxisRanges(bool additionOptimization) +{ + if (!parent) + return; + + if (points.empty()) + return; + + redoRange = !additionOptimization; + if (additionOptimization) + { + // Check if the latest y is not within the current range + float yMax = points.back()->getMaxY(); + float yMin = points.back()->getMinY(); + if ((yMin < getYMin()) || (yMax > getYMax())) + redoRange = true; + } + + unsigned int i = 0; + if (redoRange) + { + for (; i < points.size(); ++i) + { + T* pt = points[i]; + float x_pt = pt->getX(); + float y_max = pt->getMaxY(); + float y_min = pt->getMinY(); + + setXMax(x_pt); + setXMin(x_pt); + setYMax(y_max); + setYMin(y_min); + } + } + + // Set the parent's range + parent->setXMin(getXMin()); + parent->setXMax(getXMax()); + parent->setYMin(getYMin()); + parent->setYMax(getYMax()); + + //==============================================Normalize the points============================================== + + unsigned int agg = parent->getAggregate(); + float xRange = static_cast(points.size()) / static_cast(agg); + float yRange = getYMax() - getYMin(); + if (points.size() % agg) + ++xRange; + + float pointXGap = static_cast(parent->getWidth()) / xRange; + float pointYGap = static_cast(parent->getHeight()) / yRange; + if (isinf(pointXGap)) + { + normalizedPoints.clear(); + return; + } + + // Size up the normalized points vector + while (normalizedPoints.size() < xRange) + { + normalizedPoints.push_back(new T()); + } + + while (normalizedPoints.size() > xRange) + { + normalizedPoints.pop_back(); + //normalizedPoints.erase(normalizedPoints.begin()+normalizedPoints.size()-1); + } + + i = 0; + unsigned int aggCounter = 0; + float aggValue = 0.0f; + unsigned int normalCounter = 0; + + for (; i < points.size(); ++i) + { + float newYValue = (points[i]->getMaxY() - getYMin()) * pointYGap; + + ++aggCounter; + aggValue = newYValue; + + if ((aggCounter < agg) && (i < points.size() - 1)) + { + continue; + } + + //float newXValue = normalCounter * pointXGap; + float newXValue = ((i/agg) * pointXGap)+ (pointXGap / 2); + normalizedPoints[normalCounter]->setX(parent->getAxisOriginX() + newXValue); + normalizedPoints[normalCounter]->setY(parent->getAxisOriginY() + static_cast(parent->getHeight()) - aggValue); + + ++normalCounter; + aggCounter = 0; + aggValue = 0.0f; + } + + parent->requireDrawUpdate(); } #endif diff --git a/Frontend/RUGraph/GraphableAttr.cpp b/Frontend/RUGraph/GraphableAttr.cpp deleted file mode 100644 index f14eb8f..0000000 --- a/Frontend/RUGraph/GraphableAttr.cpp +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2020 Robert Carneiro, Derek Meer, Matthew Tabak, Eric Lujan -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and -// associated documentation files (the "Software"), to deal in the Software without restriction, -// including without limitation the rights to use, copy, modify, merge, publish, distribute, -// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all copies or -// substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT -// NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -#include "GraphableAttr.h" -#include "RUGraph.h" - -GraphableAttr::GraphableAttr() -{ - parent = NULL; - setColor(RUColors::DEFAULT_COLOR_LINE); - xMode = false; // is local - yMode = false; // is local -} - -GraphableAttr::GraphableAttr(RUGraph* newParent, SDL_Color newColor) -{ - parent = newParent; - setColor(newColor); - xMode = false; // is local - yMode = false; // is local -} - -GraphableAttr::~GraphableAttr() -{ - clear(); -} - -float GraphableAttr::getXMinModed() const -{ - if(!parent) - return 0.0f; - - if(xMode) - return getXMin(); - - return parent->getXMin(); -} - -float GraphableAttr::getXMaxModed() const -{ - if(!parent) - return 0.0f; - - if(xMode) - return getXMax(); - - return parent->getXMax(); -} - -float GraphableAttr::getYMinModed() const -{ - if(!parent) - return 0.0f; - - if(yMode) - return getYMin(); - - return parent->getYMin(); -} - -float GraphableAttr::getYMaxModed() const -{ - if(!parent) - return 0.0f; - - if(yMode) - return getYMax(); - - return parent->getYMax(); -} - -bool GraphableAttr::getXMode() const -{ - return xMode; -} - -bool GraphableAttr::getYMode() const -{ - return yMode; -} - -SDL_Color GraphableAttr::getColor() const -{ - return lineColor; -} - -void GraphableAttr::setXMode(bool newLocalXMode) -{ - xMode = newLocalXMode; -} - -void GraphableAttr::setYMode(bool newLocalYMode) -{ - yMode = newLocalYMode; -} - -void GraphableAttr::setColor(SDL_Color newColor) -{ - lineColor = newColor; -} - -void GraphableAttr::clear() -{ - parent = NULL; - xMode = false; - yMode = false; -} - -void GraphableAttr::updateBackground(gfxpp* cGfx) -{ - if(!cGfx) - return; - - // draw the line - draw(cGfx); - //parent->requireDrawUpdate(); - - redoRange = false; -} diff --git a/Frontend/RUGraph/LineGraphable.cpp b/Frontend/RUGraph/LineGraphable.cpp index 4bad0ff..6ccbe8a 100644 --- a/Frontend/RUGraph/LineGraphable.cpp +++ b/Frontend/RUGraph/LineGraphable.cpp @@ -16,116 +16,10 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "Graphable.h" #include "RUGraph.h" +#include "../GFXUtilities/point2.h" //TODO: Separate Scalar1D from Point2D and implement this add fncality -template <> -void Graphable::computeAxisRanges(bool additionOptimization) -{ - if (!parent) - return; - - if (points.empty()) - return; - - redoRange = !additionOptimization; - if(additionOptimization) - { - // Is the latest y not within the current range? - float cY = points[points.size()-1]->getY(); - if((cY < getYMin()) || (cY > getYMax())) - redoRange = true; - } - - //redoRange = true; - unsigned int i = 0; - //if(redoRange) - //i = points.size()-1; - for (; i < points.size(); ++i) - { - Point2* pt = points[i]; - float x_pt = pt->getX(); - float y_pt = pt->getY(); - - setXMax(x_pt); - setXMin(x_pt); - setYMax(y_pt); - setYMin(y_pt); - } - - // Set the parents - parent->setXMin(getXMin()); - parent->setXMax(getXMax()); - parent->setYMin(getYMin()); - parent->setYMax(getYMax()); - - //==============================================Normalize the points============================================== - - unsigned int agg = parent->getAggregate(); - float xRange = (float)points.size() / (float)agg; - float yRange = getYMax() - getYMin(); - if(points.size() % agg) - ++xRange; - - float pointXGap = ((float)parent->getWidth()) / xRange; - //printf("Line[%s]: xRange;pointXGap: %f; %f\n", parent->getName().c_str(), xRange, pointXGap); - float pointYGap = ((float)parent->getHeight()) / yRange; - if(isinf(pointXGap)) - { - normalizedPoints.clear(); - return; - } - - // Size up the normalized points vec - while(normalizedPoints.size() < xRange) - { - Point2* newPoint = new Point2(); - normalizedPoints.push_back(newPoint); - } - - while(normalizedPoints.size() > xRange) - { - normalizedPoints.erase(normalizedPoints.begin()+normalizedPoints.size()-1); - } - - i = 0; - //if(!redoRange) - //i = points.size()-1; - - // Aggregate helpers - unsigned int aggCounter = 0; - float aggValue = 0.0f; - - unsigned int normalCounter = 0; - for (; i < points.size(); ++i) - { - float newYValue = (points[i]->getY() - getYMin()) * pointYGap; - - // Time to Aggreagate - ++aggCounter; - aggValue=newYValue; - - // Are we done aggregating data yet? - if((aggCounter < agg) && (i < points.size()-1)) - continue; - - // Our aggregated points - float newXValue = (normalCounter * pointXGap); - //float newXValue = i * pointXGap; - normalizedPoints[normalCounter]->setX(parent->getAxisOriginX() + newXValue); - normalizedPoints[normalCounter]->setY(parent->getAxisOriginY() + (float)parent->getHeight() - aggValue); - - // The draw container - ++normalCounter; - - // Reset the agg helpers - aggCounter = 0; - aggValue = 0.0f; - } - - parent->requireDrawUpdate(); -} - template <> void Graphable::draw(gfxpp* cGfx) { diff --git a/Frontend/RUGraph/NeuralNetGraphable.cpp b/Frontend/RUGraph/NeuralNetGraphable.cpp index 9c2a26e..9fc14ef 100644 --- a/Frontend/RUGraph/NeuralNetGraphable.cpp +++ b/Frontend/RUGraph/NeuralNetGraphable.cpp @@ -2,6 +2,7 @@ #include "RUGraph.h" #include "../GFXUtilities/DrawNeuralNet.h" #include +#include "../GFXUtilities/point2.h" template <> void Graphable::computeAxisRanges(bool additionOptimization) diff --git a/Frontend/RUGraph/RUGraph.h b/Frontend/RUGraph/RUGraph.h index 70cd44a..e004931 100644 --- a/Frontend/RUGraph/RUGraph.h +++ b/Frontend/RUGraph/RUGraph.h @@ -185,9 +185,10 @@ void RUGraph::set(const shmea::GString& label, const std::vector& graphPoint } else { - newPlotter = new GeneralGraphable(this, lineColor, T()); + newPlotter = new GeneralGraphable(this, T()); if (!newPlotter) return; + newPlotter->setColor(lineColor); graphables[label] = newPlotter; if (!graphables[label]) return;