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/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.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/Widget.h> 00034 #include <QtCore/QMutex> 00035 #include <ICLUtils/Point32f.h> 00036 #include <ICLUtils/Rect32f.h> 00037 #include <ICLMath/FixedMatrix.h> 00038 #include <ICLUtils/VisualizationDescription.h> 00039 00040 namespace icl{ 00042 namespace core{ class ImgBase; } 00045 namespace qt{ 00047 class GLPaintEngine; 00050 00051 00141 class ICLDrawWidget : public ICLWidget { 00142 template<class T> 00143 static inline void icl_given_type_has_no_int_index_operator(const T &t){ 00144 t[0]; 00145 } 00146 00147 public: 00149 enum Sym {symRect,symCross,symPlus,symTriangle,symCircle}; 00150 00152 ICLDrawWidget(QWidget *parent=0); 00153 00155 ~ICLDrawWidget(); 00156 00158 00161 void setAutoResetQueue(bool on); 00162 00164 00166 void resetQueue(); 00167 00168 #if 0 00169 00170 00177 ICL_DEPRECATED void lock(){}//m_oCommandMutex.lock();} 00178 00180 ICL_DEPRECATED void unlock(){}//{m_oCommandMutex.unlock();} 00181 #endif 00182 00184 00185 void abs(); 00186 00188 void rel(); 00189 00191 00198 void image(core::ImgBase *image, float x, float y, float w, float h); 00199 00201 inline void image(core::ImgBase *image, const utils::Rect &r){ 00202 this->image(image,r.x,r.y,r.width,r.height); 00203 } 00204 00206 00215 void image(const core::ImgBase *image, const float a[2], const float b[2], 00216 const float c[2], const float d[2]); 00217 00219 00224 void text(std::string text, float x, float y, float w, float h, float fontsize=10); 00225 00227 /* The given fontsize paramter defines the font-size in screen pixels. 00228 <b>Important: if the given fontsize is negative, its absolute value is used 00229 but the font size unit is image pixels instead of screen-pixels </b> 00230 */ 00231 void text(const std::string &text, float x, float y, float fontsize=10){ 00232 this->text(text,x,y,-1,-1,fontsize); 00233 } 00234 00236 void text(const std::string &text, const utils::Point32f &p, float fontsize=10){ 00237 this->text(text,p.x,p.y,-1,-1,fontsize); 00238 } 00239 00241 void point(float x, float y); 00242 00244 void point(const utils::Point &p){ 00245 this->point(p.x,p.y); 00246 } 00247 00249 void point(const utils::Point32f &p){ 00250 this->point(p.x,p.y); 00251 } 00252 00254 template<class VectorType> 00255 void point(const VectorType &p){ 00256 icl_given_type_has_no_int_index_operator(p); 00257 this->point(p[0],p[1]); 00258 } 00259 00261 00264 void points(const std::vector<utils::Point> &pts, int xfac=1, int yfac=1); 00265 00267 void points(const std::vector<utils::Point32f> &pts); 00268 00270 template<class VectorType> 00271 void point(const std::vector<VectorType> &points){ 00272 icl_given_type_has_no_int_index_operator(points[0]); 00273 std::vector<utils::Point32f> tmp(points.size()); 00274 for(unsigned int i=0;i<points.size();++i) tmp[i] = utils::Point32f(points[i][0],points[i][1]); 00275 this->points(tmp); 00276 } 00277 00278 00280 00283 void linestrip(const std::vector<utils::Point> &pts, bool closeLoop=true, int xfac=1, int yfac=1); 00284 00286 void linestrip(const std::vector<utils::Point32f> &pts, bool closeLoop=true); 00287 00288 00290 void line(float x1, float y1, float x2, float y2); 00291 00293 void line(const utils::Point32f &a, const utils::Point32f &b); 00294 00296 template<class VectorTypeA, class VectorTypeB> 00297 void line(const VectorTypeA &a, const VectorTypeB &b){ 00298 icl_given_type_has_no_int_index_operator(a); 00299 icl_given_type_has_no_int_index_operator(b); 00300 this->line(a[0],a[1],b[0],b[1]); 00301 } 00302 00304 void arrow(float ax, float ay, float bx, float by, float capsize=10); 00305 00307 void arrow(const utils::Point32f &a, const utils::Point32f &b, float capsize=10); 00308 00310 void rect(float x, float y, float w, float h); 00311 00313 void rect(const utils::Rect32f &r); 00314 00316 void rect(const utils::Rect &r); 00317 00319 void triangle(float x1, float y1, float x2, float y2, float x3, float y3); 00320 00322 void triangle(const utils::Point32f &a, const utils::Point32f &b, const utils::Point32f &c); 00323 00325 void quad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4); 00326 00328 void quad(const utils::Point32f &a, const utils::Point32f &b, const utils::Point32f &c, const utils::Point32f &d); 00329 00331 void ellipse(float x, float y, float w, float h); 00332 00334 void ellipse(const utils::Rect &r); 00335 00337 void ellipse(const utils::Rect32f &r); 00338 00340 void circle(float cx, float cy, float r); 00341 00343 void circle(const utils::Point32f ¢er, float radius); 00344 00346 void polygon(const std::vector<utils::Point32f> &ps); 00347 00349 void polygon(const std::vector<utils::Point> &ps); 00350 00352 void grid(const utils::Point32f *points, int nx, int ny, bool rowMajor=true); 00353 00355 00356 void sym(float x, float y, Sym s); 00357 00359 void sym(const utils::Point32f &p, Sym s){ 00360 sym(p.x,p.y,s); 00361 } 00362 00364 00378 void sym(float x, float y, char sym){ 00379 if(sym == 'r') this->sym(x,y,symRect); 00380 else if(sym == '+') this->sym(x,y,symPlus); 00381 else if(sym == 't') this->sym(x,y,symTriangle); 00382 else if(sym == 'o') this->sym(x,y,symCircle); 00383 else this->sym(x,y,symCross); 00384 } 00385 00387 void sym(const utils::Point32f &p, char sym){ 00388 this->sym(p.x,p.y,sym); 00389 } 00390 00392 void symsize(float w, float h=-1); // if h==-1, h = w; 00393 00395 void linewidth(float w); 00396 00398 void pointsize(float s); 00399 00401 00405 void color(float r, float g, float b, float alpha = 255); 00406 00408 00412 void fill(float r, float g, float b, float alpha = 255); 00413 00415 template<class T, unsigned int COLS> 00416 inline void color(const math::FixedMatrix<T,COLS,3/COLS> &v){ 00417 color((float)v[0],(float)v[1],(float)v[2]); 00418 } 00419 00421 template<class T, unsigned int COLS> 00422 inline void color(const math::FixedMatrix<T,COLS,4/COLS> &v){ 00423 color((float)v[0],(float)v[1],(float)v[2],(float)v[3]); 00424 } 00425 00427 template<class T, unsigned int COLS> 00428 inline void fill(const math::FixedMatrix<T,COLS,3/COLS> &v){ 00429 fill((float)v[0],(float)v[1],(float)v[2]); 00430 } 00431 00433 template<class T, unsigned int COLS> 00434 inline void fill(const math::FixedMatrix<T,COLS,4/COLS> &v){ 00435 fill((float)v[0],(float)v[1],(float)v[2],(float)v[3]); 00436 } 00437 00439 void nocolor(); 00440 00442 void nofill(); 00443 00445 00446 void draw(const utils::VisualizationDescription &d); 00447 00449 virtual void customPaintEvent(PaintEngine *e); 00450 00452 virtual void initializeCustomPaintEvent(PaintEngine *e); 00453 00455 virtual void finishCustomPaintEvent(PaintEngine *e); 00456 00457 00459 class State; 00460 00462 class DrawCommand; 00463 00464 protected: 00465 00467 virtual void swapQueues(); 00468 00470 00471 std::vector<DrawCommand*> *m_queues[2]; 00472 00474 State *m_poState; 00475 00477 QMutex m_oCommandMutex; 00478 00480 bool m_autoResetQueue; 00481 }; 00482 } // namespace qt 00483 } 00484