Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
PlotWidget.h
Go to the documentation of this file.
00001 /********************************************************************
00002 **                Image Component Library (ICL)                    **
00003 **                                                                 **
00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld          **
00005 **                         Neuroinformatics Group                  **
00006 ** Website: www.iclcv.org and                                      **
00007 **          http://opensource.cit-ec.de/projects/icl               **
00008 **                                                                 **
00009 ** File   : ICLQt/src/ICLQt/PlotWidget.h                           **
00010 ** Module : ICLQt                                                  **
00011 ** Authors: Christof Elbrechter                                    **
00012 **                                                                 **
00013 **                                                                 **
00014 ** GNU LESSER GENERAL PUBLIC LICENSE                               **
00015 ** This file may be used under the terms of the GNU Lesser General **
00016 ** Public License version 3.0 as published by the                  **
00017 **                                                                 **
00018 ** Free Software Foundation and appearing in the file LICENSE.GPL  **
00019 ** included in the packaging of this file.  Please review the      **
00020 ** following information to ensure the license requirements will   **
00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt                **
00022 **                                                                 **
00023 ** The development of this software was supported by the           **
00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology.    **
00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche       **
00026 ** Forschungsgemeinschaft (DFG) in the context of the German       **
00027 ** Excellence Initiative.                                          **
00028 **                                                                 **
00029 ********************************************************************/
00030 
00031 #pragma once
00032 
00033 #include <ICLQt/LowLevelPlotWidget.h>
00034 #include <ICLMath/FixedVector.h>
00035 #include <ICLUtils/Array2D.h>
00036 #include <ICLUtils/VisualizationDescription.h>
00037 
00038 namespace icl{
00039   namespace qt{
00040     
00042 
00156     class PlotWidget : public LowLevelPlotWidget{
00157       struct Data;  
00158       Data *m_data; 
00159       
00160       public:
00161       
00163 
00164       PlotWidget(QWidget *parent=0);
00165       
00167       ~PlotWidget();
00168       
00170       inline void lock() { LowLevelPlotWidget::lock(); }
00171   
00173       inline void unlock() { LowLevelPlotWidget::unlock(); }
00174   
00176       virtual void clear();
00177    
00179       inline void reset() { clear(); }
00180       
00182       void label(const std::string &primitiveLabel);
00183       
00185       inline void nolabel() { label(""); }
00186       
00188       void color(int r, int g, int b, int a=255);
00189   
00191 
00192       template<class VectorType>
00193       inline void color(const VectorType &c){
00194         color(c[0],c[1],c[2],c[3]);
00195       }
00196       
00198       inline void nocolor(){ color(0,0,0,0); }
00199   
00201 
00203       void pen(const QPen &pen);
00204   
00206 
00207       void fill(int r, int g, int b, int a=255);
00208   
00209   
00211 
00212       template<class VectorType>
00213       inline void fill(const VectorType &c){
00214         fill(c[0],c[1],c[2],c[3]);
00215       }
00217       inline void nofill() { fill(0,0,0,0); }
00218       
00220 
00224       void brush(const QBrush &brush);
00225       
00227 
00228       void sym(char s);
00229       
00231 
00232       inline void sym(char s, int symsize){
00233         sym(s);
00234         this->symsize(symsize);
00235       }
00236       
00238       inline void nosym() { sym(' '); }
00239       
00241       void linewidth(float width);
00242       
00244       void symsize(float size);
00245       
00246       
00248 
00258       template<class T>
00259       void scatter(const T *xs, const T *ys, int num, int xStride = 1, int yStride=1, bool connect=false);
00260   
00262       inline void scatter(const std::vector<utils::Point32f> &ps, bool connect=false){
00263         scatter(&ps[0].x, &ps[0].y, ps.size(), 2, 2, connect);
00264       }
00265       
00267       inline void scatter(const std::vector<utils::Point> &ps, bool connect=false){
00268         scatter(&ps[0].x, &ps[0].y, ps.size(), 2, 2, connect);
00269       }
00270   
00272       template<class T>
00273       inline void scatter(const math::FixedMatrix<T,1,2> *ps, int num, bool connect=false){
00274         scatter(&ps[0][0],&ps[0][1], num, 2, 2, connect);
00275       }
00276 
00277       template<class T>
00278       inline void scatter(const math::FixedMatrix<T,2,1> *ps, int num, bool connect=false){
00279         scatter(&ps[0][0],&ps[0][1], num, 2, 2, connect);
00280       }
00281 
00283       inline void scatter(const std::vector<math::FixedColVector<float,2> >&ps, bool connect=false){
00284         scatter((const math::FixedMatrix<float,2,1>*)ps.data(),ps.size(),connect);
00285       }
00286 
00288 
00292       template<class T>
00293       void series(const T *data, int num, int stride=1);
00294       
00296       template<class T>
00297       inline void series(const std::vector<T> &data){
00298         series(data.data(), data.size(), 1);
00299       }
00300 
00302 
00303       struct SeriesBuffer : public std::vector<float>{
00304         explicit SeriesBuffer(int size=0):std::vector<float>(size){}
00305         inline void push(float f){
00306           for(size_t i=1; i< size();++i){
00307             this->operator[](i-1) = this->operator[](i);
00308           }
00309           this->back() = f;
00310         }
00312         inline SeriesBuffer &operator<<(float f){
00313           push(f);
00314           return *this;
00315         }
00316         
00317       };  
00318       
00320 
00324       template<class T>
00325       void bars(const T *data, int num, int stride=1);
00326       
00328       template<class T>
00329       inline void bars(const std::vector<T> &data){
00330         bars(data.data(), data.size(), 1);
00331       }
00332       
00334       void line(const utils::Point32f &a, const utils::Point32f &b);
00335       
00337       inline void line(float x1, float y1, float x2, float y2){
00338         line(utils::Point32f(x1,y1),utils::Point32f(x2,y2));
00339       }
00340   
00342       void linestrip(const std::vector<utils::Point32f> &ps, bool closedLoop=true);
00343   
00345       void linestrip(const std::vector<utils::Point> &ps, bool closedLoop=true);
00346   
00348       void linestrip(const utils::Point32f *ps, int num, bool closedLoop=true);
00349   
00351       void linestrip(const utils::Point *ps, int num, bool closedLoop=true);
00352   
00354       void linestrip(const float *xs, const float *ys, int num, bool closedLoop=true, int stride = 1);
00355   
00357       void rect(const utils::Point32f &ul, const utils::Point32f &lr);
00358   
00360       void rect(const utils::Rect &r);
00361   
00363       void rect(const utils::Rect32f &r);
00364   
00366       void rect(float x, float y, float w, float h);
00367   
00369       void circle(const utils::Point32f &c, float r);
00370   
00372       void circle(float cx, float cy, float r);
00373         
00375 
00376       void text(float x, float y, const std::string &text);
00377   
00379 
00380       void text(const utils::Point32f &p, const std::string &text);
00381   
00383       void grid(int nX, int nY, const float *xs, const float *ys, int stride=1);
00384   
00386       void grid(const utils::Array2D<utils::Point> &data);
00387       
00389       inline void grid(const utils::Array2D<utils::Point32f> &data){
00390         grid(data.getWidth(), data.getHeight(), &data(0,0).x, &data(0,0).y, 2);
00391       }
00392   
00394       inline void grid(int nX, int nY, const float *xys){
00395         grid(nX,nY,xys, xys+1,2);
00396       }
00397   
00399       inline void grid(int nX, int nY, const utils::Point *ps){
00400         grid(utils::Array2D<utils::Point>(nX,nY,const_cast<utils::Point*>(ps),false));
00401       }
00402   
00404       inline void grid(int nX, int nY, const utils::Point32f *ps){
00405         grid(nX, nY, &ps[0].x, &ps[0].y, 2);
00406       }
00407   
00409       inline void grid(int nX, int nY, const std::vector<utils::Point32f> &ps){
00410         grid(nX, nY, &ps[0].x, &ps[0].y, 2);
00411       }
00412   
00414       inline void grid(int nX, int nY, const std::vector<utils::Point> &ps){
00415         grid(utils::Array2D<utils::Point>(nX,nY, const_cast<utils::Point*>(ps.data()), false));    
00416       }
00417   
00419       inline void grid(int nX, int nY, const std::vector<float> &xys){
00420         grid(nX, nY, xys.data(), xys.data()+1,2);
00421       }
00422       
00424       inline void grid(int nX, int nY, const std::vector<float> &xs, const std::vector<float> &ys){
00425         grid(nX, nY, xs.data(), ys.data());
00426       }
00427       
00429 
00430       void draw(const utils::VisualizationDescription &d);
00431   
00433 
00437       void title(const std::string &title){
00438         setPropertyValue("labels.diagramm",title);
00439       }
00440       
00442       void xlabel(const std::string &xlabel){
00443         setPropertyValue("labels.x-axis",xlabel);
00444       }
00445   
00447       void ylabel(const std::string &ylabel){
00448         setPropertyValue("labels.y-axis",ylabel);
00449       }
00450       
00451     };
00452   } // namespace qt
00453 }
00454 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines