Image Component Library (ICL)
DrawWidget.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/DrawWidget.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>
35 #include <ICLUtils/Point32f.h>
36 #include <ICLUtils/Rect32f.h>
37 #include <ICLMath/FixedMatrix.h>
38 #include <ICLQt/Widget.h>
39 #include <QtCore/QMutex>
40 
41 namespace icl{
43  namespace core{ class ImgBase; }
46  namespace qt{
48  class GLPaintEngine;
51 
143  template<class T>
144  static inline void icl_given_type_has_no_int_index_operator(const T &t){
145  t[0];
146  }
147 
148  public:
150  enum Sym {symRect,symCross,symPlus,symTriangle,symCircle};
151 
153  ICLDrawWidget(QWidget *parent=0);
154 
156  ~ICLDrawWidget();
157 
159 
162  void setAutoResetQueue(bool on);
163 
165 
167  void resetQueue();
168 
169 #if 0
170 
178  ICL_DEPRECATED void lock(){}//m_oCommandMutex.lock();}
179 
181  ICL_DEPRECATED void unlock(){}//{m_oCommandMutex.unlock();}
182 #endif
183 
185 
186  void abs();
187 
189  void rel();
190 
192 
199  void image(core::ImgBase *image, float x, float y, float w, float h);
200 
202  inline void image(core::ImgBase *image, const utils::Rect &r){
203  this->image(image,r.x,r.y,r.width,r.height);
204  }
205 
207 
216  void image(const core::ImgBase *image, const float a[2], const float b[2],
217  const float c[2], const float d[2]);
218 
220 
225  void text(std::string text, float x, float y, float w, float h, float fontsize=10);
226 
228  /* The given fontsize paramter defines the font-size in screen pixels.
229  <b>Important: if the given fontsize is negative, its absolute value is used
230  but the font size unit is image pixels instead of screen-pixels </b>
231  */
232  void text(const std::string &text, float x, float y, float fontsize=10){
233  this->text(text,x,y,-1,-1,fontsize);
234  }
235 
237  void text(const std::string &text, const utils::Point32f &p, float fontsize=10){
238  this->text(text,p.x,p.y,-1,-1,fontsize);
239  }
240 
242  void point(float x, float y);
243 
245  void point(const utils::Point &p){
246  this->point(p.x,p.y);
247  }
248 
250  void point(const utils::Point32f &p){
251  this->point(p.x,p.y);
252  }
253 
255  template<class VectorType>
256  void point(const VectorType &p){
257  icl_given_type_has_no_int_index_operator(p);
258  this->point(p[0],p[1]);
259  }
260 
262 
265  void points(const std::vector<utils::Point> &pts, int xfac=1, int yfac=1);
266 
268  void points(const std::vector<utils::Point32f> &pts);
269 
271  template<class VectorType>
272  void point(const std::vector<VectorType> &points){
273  icl_given_type_has_no_int_index_operator(points[0]);
274  std::vector<utils::Point32f> tmp(points.size());
275  for(unsigned int i=0;i<points.size();++i) tmp[i] = utils::Point32f(points[i][0],points[i][1]);
276  this->points(tmp);
277  }
278 
279 
281 
284  void linestrip(const std::vector<utils::Point> &pts, bool closeLoop=true, int xfac=1, int yfac=1);
285 
287  void linestrip(const std::vector<utils::Point32f> &pts, bool closeLoop=true);
288 
289 
291  void line(float x1, float y1, float x2, float y2);
292 
294  void line(const utils::Point32f &a, const utils::Point32f &b);
295 
297  template<class VectorTypeA, class VectorTypeB>
298  void line(const VectorTypeA &a, const VectorTypeB &b){
299  icl_given_type_has_no_int_index_operator(a);
300  icl_given_type_has_no_int_index_operator(b);
301  this->line(a[0],a[1],b[0],b[1]);
302  }
303 
305  void arrow(float ax, float ay, float bx, float by, float capsize=10);
306 
308  void arrow(const utils::Point32f &a, const utils::Point32f &b, float capsize=10);
309 
311  void rect(float x, float y, float w, float h);
312 
314  void rect(const utils::Rect32f &r);
315 
317  void rect(const utils::Rect &r);
318 
320  void triangle(float x1, float y1, float x2, float y2, float x3, float y3);
321 
323  void triangle(const utils::Point32f &a, const utils::Point32f &b, const utils::Point32f &c);
324 
326  void quad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4);
327 
329  void quad(const utils::Point32f &a, const utils::Point32f &b, const utils::Point32f &c, const utils::Point32f &d);
330 
332  void ellipse(float x, float y, float w, float h);
333 
335  void ellipse(const utils::Rect &r);
336 
338  void ellipse(const utils::Rect32f &r);
339 
341  void circle(float cx, float cy, float r);
342 
344  void circle(const utils::Point32f &center, float radius);
345 
347  void polygon(const std::vector<utils::Point32f> &ps);
348 
350  void polygon(const std::vector<utils::Point> &ps);
351 
353  void grid(const utils::Point32f *points, int nx, int ny, bool rowMajor=true);
354 
356 
357  void sym(float x, float y, Sym s);
358 
360  void sym(const utils::Point32f &p, Sym s){
361  sym(p.x,p.y,s);
362  }
363 
365 
379  void sym(float x, float y, char sym){
380  if(sym == 'r') this->sym(x,y,symRect);
381  else if(sym == '+') this->sym(x,y,symPlus);
382  else if(sym == 't') this->sym(x,y,symTriangle);
383  else if(sym == 'o') this->sym(x,y,symCircle);
384  else this->sym(x,y,symCross);
385  }
386 
388  void sym(const utils::Point32f &p, char sym){
389  this->sym(p.x,p.y,sym);
390  }
391 
393  void symsize(float w, float h=-1); // if h==-1, h = w;
394 
396  void linewidth(float w);
397 
399  void pointsize(float s);
400 
402 
403  void textangle(float angleDeg);
404 
406 
408  void fontsize(float size);
409 
411 
415  void color(float r, float g, float b, float alpha = 255);
416 
418 
422  void fill(float r, float g, float b, float alpha = 255);
423 
425  template<class T, unsigned int COLS>
427  color((float)v[0],(float)v[1],(float)v[2]);
428  }
429 
431  template<class T, unsigned int COLS>
433  color((float)v[0],(float)v[1],(float)v[2],(float)v[3]);
434  }
435 
437  template<class T, unsigned int COLS>
438  inline void fill(const math::FixedMatrix<T,COLS,3/COLS> &v){
439  fill((float)v[0],(float)v[1],(float)v[2]);
440  }
441 
443  template<class T, unsigned int COLS>
444  inline void fill(const math::FixedMatrix<T,COLS,4/COLS> &v){
445  fill((float)v[0],(float)v[1],(float)v[2],(float)v[3]);
446  }
447 
449  void nocolor();
450 
452  void nofill();
453 
455 
456  void draw(const utils::VisualizationDescription &d);
457 
459  virtual void customPaintEvent(PaintEngine *e);
460 
462  virtual void initializeCustomPaintEvent(PaintEngine *e);
463 
465  virtual void finishCustomPaintEvent(PaintEngine *e);
466 
467 
469  class State;
470 
472  class DrawCommand;
473 
474  protected:
475 
477  virtual void swapQueues();
478 
480 
481  std::vector<DrawCommand*> *m_queues[2];
482 
485 
488 
491  };
492  } // namespace qt
493 }
494 
For a state log panel.
Definition: GUIComponents.h:322
void point(const utils::Point32f &p)
convenience wrapper for utils::Point32f types
Definition: DrawWidget.h:250
ICLQt_API void polygon(ImgQ &image, const std::vector< utils::Point > &corners)
draws a polygon (constructed out of linestrips
Powerful and highly flexible matrix class implementation.
Definition: FixedMatrix.h:172
undocument this line if you encounter any issues!
Definition: Any.h:37
ICLQt_API void triangle(ImgQ &image, int x1, int y1, int x2, int y2, int x3, int y3)
draws a triangle into an image
Class for openGL-based image visualization components.
Definition: Widget.h:66
void fill(const math::FixedMatrix< T, COLS, 4/COLS > &v)
utility template method that allows to pass 4D vectors as fill color
Definition: DrawWidget.h:444
ICLQt_API void fontsize(int size)
sets up current fontsize (only available with Qt-Support)
float y
y position of this point
Definition: Point32f.h:48
void text(const std::string &text, const utils::Point32f &p, float fontsize=10)
draws the text at given position p
Definition: DrawWidget.h:237
void point(const std::vector< VectorType > &points)
convenience wrapper for arbitrary types, that provide an index operator [int]
Definition: DrawWidget.h:272
void line(const VectorTypeA &a, const VectorTypeB &b)
convenience wrapper for arbitrary types, that provide an index operator [int]
Definition: DrawWidget.h:298
ICLQt_API void text(ImgQ &image, int x, int y, const string &text)
renders a text into an image (only available with Qt-Support)
Definition: DrawWidget.h:150
ICLQt_API void line(ImgQ &image, int x1, int y1, int x2, int y2)
draws a line into an image
Sym
enum used for specification of predefined symbols
Definition: DrawWidget.h:150
void fill(const math::FixedMatrix< T, COLS, 3/COLS > &v)
utility template method that allows to pass 3D vectors as fill color
Definition: DrawWidget.h:438
Floating point precision implementation of the Rect class.
Definition: Rect32f.h:45
ICLQt_API void linestrip(ImgQ &image, const std::vector< utils::Point > &pts, bool closeLoop=true)
draws a strip of connected lines
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 color(const math::FixedMatrix< T, COLS, 4/COLS > &v)
utility template method that allows to pass 4D vectors as colors
Definition: DrawWidget.h:432
QMutex m_oCommandMutex
utils::Mutex for a thread save event queue
Definition: DrawWidget.h:487
ICLQt_API ImgQ abs(const ImgQ &image)
calls abs ( each pixel)
Extended Image visualization widget, with a drawing state machine interface.
Definition: DrawWidget.h:142
#define ICL_DEPRECATED
Definition: Macros.h:249
bool m_autoResetQueue
internal flag
Definition: DrawWidget.h:490
void color(const math::FixedMatrix< T, COLS, 3/COLS > &v)
utility template method that allows to pass 3D vectors as colors
Definition: DrawWidget.h:426
void sym(const utils::Point32f &p, char sym)
convenicence wrapper for sym(float,flota,char)
Definition: DrawWidget.h:388
void image(core::ImgBase *image, const utils::Rect &r)
convenience function for image using an image rect
Definition: DrawWidget.h:202
void text(const std::string &text, float x, float y, float fontsize=10)
draws text at given x, y location with given fontsize
Definition: DrawWidget.h:232
void sym(float x, float y, char sym)
this is a convenience function for sym(float,float,Sym)
Definition: DrawWidget.h:379
Abstract class for visualization tasks.
Definition: VisualizationDescription.h:73
Single precission 3D Vectors Point class of the ICL.
Definition: Point32f.h:41
#define ICLQt_API
Definition: CompatMacros.h:178
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 sym(const utils::Point32f &p, Sym s)
convenience wrapper for sym(float,float,Sym)
Definition: DrawWidget.h:360
void point(const VectorType &p)
convenience wrapper for arbitrary types, that provide an index operator [int]
Definition: DrawWidget.h:256
float x
x position of this point
Definition: Point32f.h:45
pure virtual Paint engine interface
Definition: PaintEngine.h:49
ICLQt_API void circle(ImgQ &image, int x, int y, int r)
renders a filled circle into an image
void point(const utils::Point &p)
convenience wrapper for utils::Point types
Definition: DrawWidget.h:245
ICLQt_API void rect(ImgQ &image, int x, int y, int w, int h, int rounding=0)
draws a rect into an image
Rectangle class of the ICL used e.g. for the Images ROI-rect.
Definition: Rect.h:95
ImgBase is the Image-Interface class that provides save access to underlying Img-template .
Definition: ImgBase.h:131
static void icl_given_type_has_no_int_index_operator(const T &t)
Definition: DrawWidget.h:144
State * m_poState
Data of the "State Machine".
Definition: DrawWidget.h:484