Image Component Library (ICL)
|
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.LGPL ** 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 <ICLUtils/CompatMacros.h> 00034 #include <ICLUtils/Array2D.h> 00035 #include <ICLUtils/VisualizationDescription.h> 00036 #include <ICLMath/FixedVector.h> 00037 #include <ICLQt/LowLevelPlotWidget.h> 00038 00039 namespace icl{ 00040 namespace qt{ 00041 00043 00157 class ICLQt_API PlotWidget : public LowLevelPlotWidget{ 00158 struct Data; 00159 Data *m_data; 00160 00161 public: 00162 00164 00165 PlotWidget(QWidget *parent=0); 00166 00168 ~PlotWidget(); 00169 00171 inline void lock() { LowLevelPlotWidget::lock(); } 00172 00174 inline void unlock() { LowLevelPlotWidget::unlock(); } 00175 00177 virtual void clear(); 00178 00180 inline void reset() { clear(); } 00181 00183 void label(const std::string &primitiveLabel); 00184 00186 inline void nolabel() { label(""); } 00187 00189 void color(int r, int g, int b, int a=255); 00190 00192 00193 template<class VectorType> 00194 inline void color(const VectorType &c){ 00195 color(c[0],c[1],c[2],c[3]); 00196 } 00197 00199 inline void nocolor(){ color(0,0,0,0); } 00200 00202 00204 void pen(const QPen &pen); 00205 00207 00208 void fill(int r, int g, int b, int a=255); 00209 00210 00212 00213 template<class VectorType> 00214 inline void fill(const VectorType &c){ 00215 fill(c[0],c[1],c[2],c[3]); 00216 } 00218 inline void nofill() { fill(0,0,0,0); } 00219 00221 00225 void brush(const QBrush &brush); 00226 00228 00229 void sym(char s); 00230 00232 00233 inline void sym(char s, int symsize){ 00234 sym(s); 00235 this->symsize(symsize); 00236 } 00237 00239 inline void nosym() { sym(' '); } 00240 00242 void linewidth(float width); 00243 00245 void symsize(float size); 00246 00247 00249 00259 template<class T> ICLQt_API 00260 void scatter(const T *xs, const T *ys, int num, int xStride = 1, int yStride=1, bool connect=false); 00261 00263 inline void scatter(const std::vector<utils::Point32f> &ps, bool connect=false){ 00264 scatter(&ps[0].x, &ps[0].y, ps.size(), 2, 2, connect); 00265 } 00266 00268 inline void scatter(const std::vector<utils::Point> &ps, bool connect=false){ 00269 scatter(&ps[0].x, &ps[0].y, ps.size(), 2, 2, connect); 00270 } 00271 00273 template<class T> 00274 inline void scatter(const math::FixedMatrix<T,1,2> *ps, int num, bool connect=false){ 00275 scatter(&ps[0][0],&ps[0][1], num, 2, 2, connect); 00276 } 00277 00278 template<class T> 00279 inline void scatter(const math::FixedMatrix<T,2,1> *ps, int num, bool connect=false){ 00280 scatter(&ps[0][0],&ps[0][1], num, 2, 2, connect); 00281 } 00282 00284 inline void scatter(const std::vector<math::FixedColVector<float,2> >&ps, bool connect=false){ 00285 scatter((const math::FixedMatrix<float,2,1>*)ps.data(),ps.size(),connect); 00286 } 00287 00289 00293 template<class T> ICLQt_API 00294 void series(const T *data, int num, int stride=1); 00295 00297 template<class T> 00298 inline void series(const std::vector<T> &data){ 00299 series(data.data(), data.size(), 1); 00300 } 00301 00303 00304 struct SeriesBuffer : public std::vector<float>{ 00305 explicit SeriesBuffer(int size=0):std::vector<float>(size){} 00306 inline void push(float f){ 00307 for(size_t i=1; i< size();++i){ 00308 this->operator[](i-1) = this->operator[](i); 00309 } 00310 this->back() = f; 00311 } 00313 inline SeriesBuffer &operator<<(float f){ 00314 push(f); 00315 return *this; 00316 } 00317 00318 }; 00319 00321 00325 template<class T> ICLQt_API 00326 void bars(const T *data, int num, int stride=1); 00327 00329 template<class T> 00330 inline void bars(const std::vector<T> &data){ 00331 bars(data.data(), data.size(), 1); 00332 } 00333 00335 void line(const utils::Point32f &a, const utils::Point32f &b); 00336 00338 inline void line(float x1, float y1, float x2, float y2){ 00339 line(utils::Point32f(x1,y1),utils::Point32f(x2,y2)); 00340 } 00341 00343 void linestrip(const std::vector<utils::Point32f> &ps, bool closedLoop=true); 00344 00346 void linestrip(const std::vector<utils::Point> &ps, bool closedLoop=true); 00347 00349 void linestrip(const utils::Point32f *ps, int num, bool closedLoop=true); 00350 00352 void linestrip(const utils::Point *ps, int num, bool closedLoop=true); 00353 00355 void linestrip(const float *xs, const float *ys, int num, bool closedLoop=true, int stride = 1); 00356 00358 void rect(const utils::Point32f &ul, const utils::Point32f &lr); 00359 00361 void rect(const utils::Rect &r); 00362 00364 void rect(const utils::Rect32f &r); 00365 00367 void rect(float x, float y, float w, float h); 00368 00370 void circle(const utils::Point32f &c, float r); 00371 00373 void circle(float cx, float cy, float r); 00374 00376 00377 void text(float x, float y, const std::string &text); 00378 00380 00381 void text(const utils::Point32f &p, const std::string &text); 00382 00384 void grid(int nX, int nY, const float *xs, const float *ys, int stride=1); 00385 00387 void grid(const utils::Array2D<utils::Point> &data); 00388 00390 inline void grid(const utils::Array2D<utils::Point32f> &data){ 00391 grid(data.getWidth(), data.getHeight(), &data(0,0).x, &data(0,0).y, 2); 00392 } 00393 00395 inline void grid(int nX, int nY, const float *xys){ 00396 grid(nX,nY,xys, xys+1,2); 00397 } 00398 00400 inline void grid(int nX, int nY, const utils::Point *ps){ 00401 grid(utils::Array2D<utils::Point>(nX,nY,const_cast<utils::Point*>(ps),false)); 00402 } 00403 00405 inline void grid(int nX, int nY, const utils::Point32f *ps){ 00406 grid(nX, nY, &ps[0].x, &ps[0].y, 2); 00407 } 00408 00410 inline void grid(int nX, int nY, const std::vector<utils::Point32f> &ps){ 00411 grid(nX, nY, &ps[0].x, &ps[0].y, 2); 00412 } 00413 00415 inline void grid(int nX, int nY, const std::vector<utils::Point> &ps){ 00416 grid(utils::Array2D<utils::Point>(nX,nY, const_cast<utils::Point*>(ps.data()), false)); 00417 } 00418 00420 inline void grid(int nX, int nY, const std::vector<float> &xys){ 00421 grid(nX, nY, xys.data(), xys.data()+1,2); 00422 } 00423 00425 inline void grid(int nX, int nY, const std::vector<float> &xs, const std::vector<float> &ys){ 00426 grid(nX, nY, xs.data(), ys.data()); 00427 } 00428 00430 00431 void draw(const utils::VisualizationDescription &d); 00432 00434 00438 void title(const std::string &title){ 00439 setPropertyValue("labels.diagramm",title); 00440 } 00441 00443 void xlabel(const std::string &xlabel){ 00444 setPropertyValue("labels.x-axis",xlabel); 00445 } 00446 00448 void ylabel(const std::string &ylabel){ 00449 setPropertyValue("labels.y-axis",ylabel); 00450 } 00451 00452 }; 00453 } // namespace qt 00454 } 00455