Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
DrawWidget.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/DrawWidget.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/VisualizationDescription.h>
00035 #include <ICLUtils/Point32f.h>
00036 #include <ICLUtils/Rect32f.h>
00037 #include <ICLMath/FixedMatrix.h>
00038 #include <ICLQt/Widget.h>
00039 #include <QtCore/QMutex>
00040 
00041 namespace icl{
00043   namespace core{ class ImgBase; }
00046   namespace qt{
00048     class GLPaintEngine;
00051 
00052 
00142     class ICLQt_API ICLDrawWidget : public ICLWidget {
00143       template<class T> 
00144       static inline void icl_given_type_has_no_int_index_operator(const T &t){
00145         t[0];
00146       }
00147 
00148       public:
00150       enum Sym {symRect,symCross,symPlus,symTriangle,symCircle};
00151     
00153       ICLDrawWidget(QWidget *parent=0);
00154 
00156       ~ICLDrawWidget();
00157 
00159 
00162       void setAutoResetQueue(bool on);
00163     
00165 
00167       void resetQueue();
00168     
00169 #if 0
00170 
00171 
00178       ICL_DEPRECATED void lock(){}//m_oCommandMutex.lock();}
00179 
00181       ICL_DEPRECATED void unlock(){}//{m_oCommandMutex.unlock();}
00182 #endif
00183 
00185 
00186       void abs();
00187     
00189       void rel();
00190     
00192 
00199       void image(core::ImgBase *image, float x, float y, float w, float h);
00200     
00202       inline void image(core::ImgBase *image, const utils::Rect &r){
00203         this->image(image,r.x,r.y,r.width,r.height);
00204       }
00205     
00207 
00216       void image(const core::ImgBase *image, const float a[2], const float b[2],
00217                  const float c[2], const float d[2]);
00218     
00220 
00225       void text(std::string text, float x, float y, float w, float h, float fontsize=10);
00226 
00228       /*    The given fontsize paramter defines the font-size in screen pixels.
00229           <b>Important: if the given fontsize is negative, its absolute value is used
00230           but the font size unit is image pixels instead of screen-pixels </b>
00231           */
00232       void text(const std::string &text, float x, float y, float fontsize=10){
00233         this->text(text,x,y,-1,-1,fontsize);
00234       }
00235     
00237       void text(const std::string &text, const utils::Point32f &p, float fontsize=10){
00238         this->text(text,p.x,p.y,-1,-1,fontsize);
00239       }
00240 
00242       void point(float x, float y); 
00243 
00245       void point(const utils::Point &p){
00246         this->point(p.x,p.y);
00247       }
00248 
00250       void point(const utils::Point32f &p){
00251         this->point(p.x,p.y);
00252       }
00253 
00255       template<class VectorType>
00256       void point(const VectorType &p){
00257         icl_given_type_has_no_int_index_operator(p);
00258         this->point(p[0],p[1]);
00259       }
00260     
00262 
00265       void points(const std::vector<utils::Point> &pts, int xfac=1, int yfac=1);
00266 
00268       void points(const std::vector<utils::Point32f> &pts);
00269     
00271       template<class VectorType>
00272       void point(const std::vector<VectorType> &points){
00273         icl_given_type_has_no_int_index_operator(points[0]);
00274         std::vector<utils::Point32f> tmp(points.size());
00275         for(unsigned int i=0;i<points.size();++i) tmp[i] = utils::Point32f(points[i][0],points[i][1]);
00276         this->points(tmp);
00277       }
00278     
00279     
00281 
00284       void linestrip(const std::vector<utils::Point> &pts, bool closeLoop=true, int xfac=1, int yfac=1);
00285 
00287       void linestrip(const std::vector<utils::Point32f> &pts, bool closeLoop=true);
00288     
00289     
00291       void line(float x1, float y1, float x2, float y2);
00292     
00294       void line(const utils::Point32f &a, const utils::Point32f &b);
00295 
00297       template<class VectorTypeA, class VectorTypeB>
00298       void line(const VectorTypeA &a, const VectorTypeB &b){
00299         icl_given_type_has_no_int_index_operator(a);
00300         icl_given_type_has_no_int_index_operator(b);
00301         this->line(a[0],a[1],b[0],b[1]);
00302       }
00303 
00305       void arrow(float ax, float ay, float bx, float by, float capsize=10);
00306     
00308       void arrow(const utils::Point32f &a, const utils::Point32f &b, float capsize=10);
00309     
00311       void rect(float x, float y, float w, float h);
00312 
00314       void rect(const utils::Rect32f &r);
00315 
00317       void rect(const utils::Rect &r);
00318 
00320       void triangle(float x1, float y1, float x2, float y2, float x3, float y3); 
00321     
00323       void triangle(const utils::Point32f &a, const utils::Point32f &b, const utils::Point32f &c);
00324     
00326       void quad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4); 
00327 
00329       void quad(const utils::Point32f &a, const utils::Point32f &b, const utils::Point32f &c, const utils::Point32f &d);
00330 
00332       void ellipse(float x, float y, float w, float h);
00333     
00335       void ellipse(const utils::Rect &r);
00336     
00338       void ellipse(const utils::Rect32f &r);
00339     
00341       void circle(float cx, float cy, float r);
00342     
00344       void circle(const utils::Point32f &center, float radius);
00345     
00347       void polygon(const std::vector<utils::Point32f> &ps);
00348 
00350       void polygon(const std::vector<utils::Point> &ps);
00351 
00353       void grid(const utils::Point32f *points, int nx, int ny, bool rowMajor=true);
00354 
00356 
00357       void sym(float x, float y, Sym s);
00358 
00360       void sym(const utils::Point32f &p, Sym s){
00361         sym(p.x,p.y,s);
00362       }
00363     
00365 
00379       void sym(float x, float y, char sym){
00380         if(sym == 'r') this->sym(x,y,symRect);
00381         else if(sym == '+') this->sym(x,y,symPlus);
00382         else if(sym == 't') this->sym(x,y,symTriangle);
00383         else if(sym == 'o') this->sym(x,y,symCircle);
00384         else this->sym(x,y,symCross);
00385       }
00386 
00388       void sym(const utils::Point32f &p, char sym){
00389         this->sym(p.x,p.y,sym);
00390       }
00391     
00393       void symsize(float w, float h=-1); // if h==-1, h = w;
00394 
00396       void linewidth(float w);
00397 
00399       void pointsize(float s);
00400     
00402 
00406       void color(float r, float g, float b, float alpha = 255);
00407     
00409 
00413       void fill(float r, float g, float b, float alpha = 255);
00414 
00416       template<class T, unsigned int COLS>
00417       inline void color(const math::FixedMatrix<T,COLS,3/COLS> &v){
00418         color((float)v[0],(float)v[1],(float)v[2]);
00419       }
00420 
00422       template<class T, unsigned int COLS>
00423       inline void color(const math::FixedMatrix<T,COLS,4/COLS> &v){
00424         color((float)v[0],(float)v[1],(float)v[2],(float)v[3]);
00425       }
00426 
00428       template<class T, unsigned int COLS>
00429       inline void fill(const math::FixedMatrix<T,COLS,3/COLS> &v){
00430         fill((float)v[0],(float)v[1],(float)v[2]);
00431       }
00432 
00434       template<class T, unsigned int COLS>
00435       inline void fill(const math::FixedMatrix<T,COLS,4/COLS> &v){
00436         fill((float)v[0],(float)v[1],(float)v[2],(float)v[3]);
00437       }
00438     
00440       void nocolor();
00441     
00443       void nofill();
00444 
00446 
00447       void draw(const utils::VisualizationDescription &d);
00448       
00450       virtual void customPaintEvent(PaintEngine *e);
00451 
00453       virtual void initializeCustomPaintEvent(PaintEngine *e);
00454 
00456       virtual void finishCustomPaintEvent(PaintEngine *e);
00457 
00458     
00460       class State;
00461 
00463       class DrawCommand;
00464 
00465       protected:    
00466 
00468       virtual void swapQueues();
00469 
00471 
00472       std::vector<DrawCommand*> *m_queues[2];
00473 
00475       State *m_poState;
00476 
00478       QMutex m_oCommandMutex;
00479     
00481       bool m_autoResetQueue;
00482     };
00483   } // namespace qt
00484 }
00485 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines