00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef _Graph_h_
00011 #define _Graph_h_
00012
00013 #include <QtGui/QKeyEvent>
00014 #include <QtGui/QPainter>
00015 #include <QtGui/QWidget>
00016 #include <QtGui/QStatusBar>
00017 #include <iostream>
00018 #include <vector>
00019 #include "GrapherExpr.h"
00020
00021 static const int divs=1;
00022
00024 class Graph:public QWidget
00025 {
00026 Q_OBJECT;
00027 public:
00028 enum OperationCode{NONE=0,FIND_MIN,FIND_MAX,FIND_ROOT};
00029 private:
00030
00031 std::vector<GrapherExpr*>& exprs;
00032 float logBase;
00033
00035 OperationCode operationCode;
00037 int functionIndex;
00039 double boundStart;
00041 double boundEnd;
00043 double rootX,rootY;
00045 bool rootShow;
00047 bool minShow;
00049 int lastcx,lastcy;
00051 bool dragging;
00053 bool scaling;
00055 QStatusBar* status;
00056
00057 public:
00058 Graph(QStatusBar* status,std::vector<GrapherExpr*>& exprs);
00059 protected:
00061 float xmin,xmax,ymin,ymax;
00063 float fit(float t,float src0,float src1,float dest0,float dest1);
00065 void drawX(QPainter& painter,int power,bool label=false);
00067 void drawY(QPainter& painter,int power,bool label=false);
00069 void paintEvent(QPaintEvent * );
00071 void plotNew(QPainter& painter,int funcId);
00072
00073 void mousePressEvent(QMouseEvent* event);
00074 void mouseMoveEvent(QMouseEvent* event);
00075 void mouseReleaseEvent(QMouseEvent* event);
00076
00078 void xform(float x,float y,float& cx,float& cy);
00080 void xforminv(float cx,float cy,float& x,float& y);
00081 public:
00083 void scheduleRoot(const OperationCode operationCode_in,const int functionIndex_in);
00084 private:
00086 void solveRoot(const int function,double xInitial);
00088 double golden(const int function,double xmin,double xcenter,double xmax,bool solveMax=false,double tolerance=1e-5);
00090 void solveMin(const int function,double xmin,double xmax,bool solveMax=false);
00092 void solveMax(const int function,double xmin,double xmax);
00093 public slots:
00095 void redraw();
00096 };
00097
00098
00099 #endif