Image Component Library (ICL)
PlotWidget.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLQt/src/ICLQt/PlotWidget.h **
10 ** Module : ICLQt **
11 ** Authors: Christof Elbrechter **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/CompatMacros.h>
34 #include <ICLUtils/Array2D.h>
36 #include <ICLMath/FixedVector.h>
38 
39 namespace icl{
40  namespace qt{
41 
43 
158  struct Data;
159  Data *m_data;
160 
161  public:
162 
164 
165  PlotWidget(QWidget *parent=0);
166 
168  ~PlotWidget();
169 
171  inline void lock() { LowLevelPlotWidget::lock(); }
172 
174  inline void unlock() { LowLevelPlotWidget::unlock(); }
175 
177  virtual void clear();
178 
180  inline void reset() { clear(); }
181 
183  void label(const std::string &primitiveLabel);
184 
186  inline void nolabel() { label(""); }
187 
189  void color(int r, int g, int b, int a=255);
190 
192 
193  template<class VectorType>
194  inline void color(const VectorType &c){
195  color(c[0],c[1],c[2],c[3]);
196  }
197 
199  inline void nocolor(){ color(0,0,0,0); }
200 
202 
204  void pen(const QPen &pen);
205 
207 
208  void fill(int r, int g, int b, int a=255);
209 
210 
212 
213  template<class VectorType>
214  inline void fill(const VectorType &c){
215  fill(c[0],c[1],c[2],c[3]);
216  }
218  inline void nofill() { fill(0,0,0,0); }
219 
221 
225  void brush(const QBrush &brush);
226 
228 
229  void sym(char s);
230 
232 
233  inline void sym(char s, int symsize){
234  sym(s);
235  this->symsize(symsize);
236  }
237 
239  inline void nosym() { sym(' '); }
240 
242  void linewidth(float width);
243 
245  void symsize(float size);
246 
247 
249 
259  template<class T> ICLQt_API
260  void scatter(const T *xs, const T *ys, int num, int xStride = 1, int yStride=1, bool connect=false);
261 
263  inline void scatter(const std::vector<utils::Point32f> &ps, bool connect=false){
264  scatter(&ps[0].x, &ps[0].y, ps.size(), 2, 2, connect);
265  }
266 
268  inline void scatter(const std::vector<utils::Point> &ps, bool connect=false){
269  scatter(&ps[0].x, &ps[0].y, ps.size(), 2, 2, connect);
270  }
271 
273  template<class T>
274  inline void scatter(const math::FixedMatrix<T,1,2> *ps, int num, bool connect=false){
275  scatter(&ps[0][0],&ps[0][1], num, 2, 2, connect);
276  }
277 
278  template<class T>
279  inline void scatter(const math::FixedMatrix<T,2,1> *ps, int num, bool connect=false){
280  scatter(&ps[0][0],&ps[0][1], num, 2, 2, connect);
281  }
282 
284  inline void scatter(const std::vector<math::FixedColVector<float,2> >&ps, bool connect=false){
285  scatter((const math::FixedMatrix<float,2,1>*)ps.data(),ps.size(),connect);
286  }
287 
289 
293  template<class T> ICLQt_API
294  void series(const T *data, int num, int stride=1);
295 
297  template<class T>
298  inline void series(const std::vector<T> &data){
299  series(data.data(), data.size(), 1);
300  }
301 
303 
304  struct SeriesBuffer : public std::vector<float>{
305  explicit SeriesBuffer(int size=0):std::vector<float>(size){}
306  inline void push(float f){
307  for(size_t i=1; i< size();++i){
308  this->operator[](i-1) = this->operator[](i);
309  }
310  this->back() = f;
311  }
313  inline SeriesBuffer &operator<<(float f){
314  push(f);
315  return *this;
316  }
317 
318  };
319 
321 
325  template<class T> ICLQt_API
326  void bars(const T *data, int num, int stride=1);
327 
329  template<class T>
330  inline void bars(const std::vector<T> &data){
331  bars(data.data(), data.size(), 1);
332  }
333 
335  void line(const utils::Point32f &a, const utils::Point32f &b);
336 
338  inline void line(float x1, float y1, float x2, float y2){
339  line(utils::Point32f(x1,y1),utils::Point32f(x2,y2));
340  }
341 
343  void linestrip(const std::vector<utils::Point32f> &ps, bool closedLoop=true);
344 
346  void linestrip(const std::vector<utils::Point> &ps, bool closedLoop=true);
347 
349  void linestrip(const utils::Point32f *ps, int num, bool closedLoop=true);
350 
352  void linestrip(const utils::Point *ps, int num, bool closedLoop=true);
353 
355  void linestrip(const float *xs, const float *ys, int num, bool closedLoop=true, int stride = 1);
356 
358  void rect(const utils::Point32f &ul, const utils::Point32f &lr);
359 
361  void rect(const utils::Rect &r);
362 
364  void rect(const utils::Rect32f &r);
365 
367  void rect(float x, float y, float w, float h);
368 
370  void circle(const utils::Point32f &c, float r);
371 
373  void circle(float cx, float cy, float r);
374 
376 
377  void text(float x, float y, const std::string &text);
378 
380 
381  void text(const utils::Point32f &p, const std::string &text);
382 
384  void grid(int nX, int nY, const float *xs, const float *ys, int stride=1);
385 
387  void grid(const utils::Array2D<utils::Point> &data);
388 
391  grid(data.getWidth(), data.getHeight(), &data(0,0).x, &data(0,0).y, 2);
392  }
393 
395  inline void grid(int nX, int nY, const float *xys){
396  grid(nX,nY,xys, xys+1,2);
397  }
398 
400  inline void grid(int nX, int nY, const utils::Point *ps){
401  grid(utils::Array2D<utils::Point>(nX,nY,const_cast<utils::Point*>(ps),false));
402  }
403 
405  inline void grid(int nX, int nY, const utils::Point32f *ps){
406  grid(nX, nY, &ps[0].x, &ps[0].y, 2);
407  }
408 
410  inline void grid(int nX, int nY, const std::vector<utils::Point32f> &ps){
411  grid(nX, nY, &ps[0].x, &ps[0].y, 2);
412  }
413 
415  inline void grid(int nX, int nY, const std::vector<utils::Point> &ps){
416  grid(utils::Array2D<utils::Point>(nX,nY, const_cast<utils::Point*>(ps.data()), false));
417  }
418 
420  inline void grid(int nX, int nY, const std::vector<float> &xys){
421  grid(nX, nY, xys.data(), xys.data()+1,2);
422  }
423 
425  inline void grid(int nX, int nY, const std::vector<float> &xs, const std::vector<float> &ys){
426  grid(nX, nY, xs.data(), ys.data());
427  }
428 
430 
431  void draw(const utils::VisualizationDescription &d);
432 
434 
438  void title(const std::string &title){
439  setPropertyValue("labels.diagramm",title);
440  }
441 
443  void xlabel(const std::string &xlabel){
444  setPropertyValue("labels.x-axis",xlabel);
445  }
446 
448  void ylabel(const std::string &ylabel){
449  setPropertyValue("labels.y-axis",ylabel);
450  }
451 
452  };
453  } // namespace qt
454 }
455 
Easy to use widget component for 2D data visualization.
Definition: PlotWidget.h:157
void fill(const VectorType &c)
convenience macro for types that provide and index operator []
Definition: PlotWidget.h:214
void grid(int nX, int nY, const utils::Point32f *ps)
draws a grid-annoation
Definition: PlotWidget.h:405
void nosym()
resets the symbol to ' ' which means no symbols are shown
Definition: PlotWidget.h:239
Powerful and highly flexible matrix class implementation.
Definition: FixedMatrix.h:172
void scatter(const math::FixedMatrix< T, 1, 2 > *ps, int num, bool connect=false)
adds a scatter plot from given set of of fixed vectors
Definition: PlotWidget.h:274
undocument this line if you encounter any issues!
Definition: Any.h:37
void reset()
synonym for clear()
Definition: PlotWidget.h:180
void grid(int nX, int nY, const std::vector< float > &xs, const std::vector< float > &ys)
draws a grid-annoation
Definition: PlotWidget.h:425
void nocolor()
sets a fully transparent line color
Definition: PlotWidget.h:199
void grid(int nX, int nY, const std::vector< utils::Point > &ps)
draws a grid-annoation
Definition: PlotWidget.h:415
void scatter(const std::vector< math::FixedColVector< float, 2 > > &ps, bool connect=false)
adds a scatter plot from given vector of fixed vectors
Definition: PlotWidget.h:284
void grid(int nX, int nY, const float *xys)
draws a grid-annoation
Definition: PlotWidget.h:395
ICLQt_API void text(ImgQ &image, int x, int y, const string &text)
renders a text into an image (only available with Qt-Support)
Data * m_data
internal data structure
Definition: PlotWidget.h:158
void scatter(const std::vector< utils::Point > &ps, bool connect=false)
adds a scatter plot from given vector of points
Definition: PlotWidget.h:268
void scatter(const math::FixedMatrix< T, 2, 1 > *ps, int num, bool connect=false)
Definition: PlotWidget.h:279
void nolabel()
calls label("")
Definition: PlotWidget.h:186
ICLQt_API void line(ImgQ &image, int x1, int y1, int x2, int y2)
draws a line into an image
void bars(const std::vector< T > &data)
adds bar plot data from given std::vector
Definition: PlotWidget.h:330
void grid(const utils::Array2D< utils::Point32f > &data)
draws a grid-annoation
Definition: PlotWidget.h:390
void title(const std::string &title)
sets the diagram title
Definition: PlotWidget.h:438
Floating point precision implementation of the Rect class.
Definition: Rect32f.h:45
ICLQt_API ImgROI data(ImgQ &r)
creates full ROI ROI-struct
ICLQt_API void linestrip(ImgQ &image, const std::vector< utils::Point > &pts, bool closeLoop=true)
draws a strip of connected lines
ICLQt_API ImgQ label(const ImgQ &image, const string &text)
labels an image in the upper left corner (only available with Qt-Support)
Utility structure for easier series plots.
Definition: PlotWidget.h:304
ICLQt_API void fill(float r, float g=-1, float b=-1, float alpha=255)
sets the current fill color to given r,g,b,alpha value
void sym(char s, int symsize)
sets the current symbol and the symbol size
Definition: PlotWidget.h:233
void line(float x1, float y1, float x2, float y2)
draws a line annotation given 4 coordinates
Definition: PlotWidget.h:338
void nofill()
sets a fully transparent fill color
Definition: PlotWidget.h:218
SeriesBuffer(int size=0)
Definition: PlotWidget.h:305
void xlabel(const std::string &xlabel)
sets the x-axis label
Definition: PlotWidget.h:443
void grid(int nX, int nY, const std::vector< utils::Point32f > &ps)
draws a grid-annoation
Definition: PlotWidget.h:410
void unlock() const
unlocks drawing / data updates in subclasses
void lock() const
locks drawing / data updates in subclasses
Abstract class for visualization tasks.
Definition: VisualizationDescription.h:73
void ylabel(const std::string &ylabel)
sets the y-axis label
Definition: PlotWidget.h:448
Single precission 3D Vectors Point class of the ICL.
Definition: Point32f.h:41
Simple 2D-Array class that provides shallow copy per default.
Definition: Array2D.h:61
void grid(int nX, int nY, const utils::Point *ps)
draws a grid-annoation
Definition: PlotWidget.h:400
#define ICLQt_API
Definition: CompatMacros.h:178
void unlock()
unlocks the draw queue
Definition: PlotWidget.h:174
Point class of the ICL used e.g. for the Images ROI offset.
Definition: Point.h:58
ICLQt_API void color(float r, float g=-1, float b=-1, float alpha=255)
sets the current color to given r,g,b,alpha value
void lock()
locks the draw queue
Definition: PlotWidget.h:171
ICLQt_API void circle(ImgQ &image, int x, int y, int r)
renders a filled circle into an image
void color(const VectorType &c)
convenience macro for types that provide and index operator []
Definition: PlotWidget.h:194
ICLQt_API void rect(ImgQ &image, int x, int y, int w, int h, int rounding=0)
draws a rect into an image
SeriesBuffer & operator<<(float f)
equivalent to push
Definition: PlotWidget.h:313
Rectangle class of the ICL used e.g. for the Images ROI-rect.
Definition: Rect.h:95
void grid(int nX, int nY, const std::vector< float > &xys)
draws a grid-annoation
Definition: PlotWidget.h:420
void scatter(const std::vector< utils::Point32f > &ps, bool connect=false)
adds a scatter plot from given vector of points
Definition: PlotWidget.h:263
void series(const std::vector< T > &data)
adds series data from given std::vector
Definition: PlotWidget.h:298
void push(float f)
Definition: PlotWidget.h:306
Default AbstractPlotWidget implementation for plotting different kinds of data.
Definition: LowLevelPlotWidget.h:246