Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
VisualizationDescription.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   : ICLUtils/src/ICLUtils/VisualizationDescription.h       **
00010 ** Module : ICLUtils                                               **
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/Any.h>
00035 #include <ICLUtils/Point32f.h>
00036 #include <ICLUtils/Rect32f.h>
00037 
00038 namespace icl{
00039   namespace utils{
00040     
00041 
00043 
00071     class VisualizationDescription{
00072       public:
00073       
00075       struct Part{
00077         inline Part(){}
00078         
00080         Part(char type, const Any &content):type(type),content(content){}
00081 
00083         char type;
00084         
00086         Any content;
00087       };
00088 
00090       struct Text{
00091         Point32f pos; 
00092         std::string text; 
00093 
00094         Text(){}
00095         
00097         Text(const Point32f &pos, const std::string &text):pos(pos),text(text){}
00098       };
00099       
00101       struct Color{
00103         union{
00104           icl8u comp[4];
00105           icl32s rgba; 
00106         };
00108         Color(){}
00109         
00111         Color(icl8u r, icl8u g, icl8u b, icl8u a=255){
00112           this->r() = r;
00113           this->g() = g;
00114           this->b() = b;
00115           this->a() = a;
00116         }
00118         inline icl8u &r() { return comp[0]; }
00119 
00121         inline icl8u &g() { return comp[1]; }
00122 
00124         inline icl8u &b() { return comp[2]; }
00125 
00127         inline icl8u &a() { return comp[3]; }
00128 
00130         inline const icl8u &r() const { return comp[0]; }
00131 
00133         inline const icl8u &g() const { return comp[1]; }
00134 
00136         inline const icl8u &b() const { return comp[2]; }
00137 
00139         inline const icl8u &a() const { return comp[3]; }
00140 
00141       };
00142       
00143       protected:
00144 
00146       std::vector<Part> parts;
00147       public:
00148       
00150       inline const std::vector<Part> &getParts() const { 
00151         return parts; 
00152       }
00153       
00155       inline void clear() { 
00156         parts.clear(); 
00157       }
00158       
00160       inline void addPart(const Part &part){
00161         parts.push_back(part);
00162       }
00164       inline void addPart(char c, const Any &content){
00165         addPart(Part(c,content));
00166       }
00167       
00169 
00170       VisualizationDescription &operator+=(const VisualizationDescription &other){
00171         size_t oldSize = parts.size();
00172         parts.resize(oldSize + other.parts.size());
00173         std::copy(other.parts.begin(),other.parts.end(),parts.begin()+oldSize);
00174         return *this;
00175       }
00176       
00178 
00179       VisualizationDescription operator+(const VisualizationDescription &other){
00180         VisualizationDescription sum;
00181         sum.parts.resize(parts.size()+other.parts.size());
00182         std::copy(parts.begin(),parts.end(),sum.parts.begin());
00183         std::copy(other.parts.begin(),other.parts.end(),sum.parts.begin()+parts.size());
00184         return sum;
00185       }
00186       
00188       void color(icl8u r, icl8u g, icl8u b);
00189 
00191       void color(icl8u r, icl8u g, icl8u b, icl8u a);
00192 
00194       void fill(icl8u r, icl8u g, icl8u b);
00195 
00197       void fill(icl8u r, icl8u g, icl8u b, icl8u a);
00198 
00200       inline void rect(icl32f x, icl32f y, icl32f width, icl32f height){
00201         addPart('r',Rect32f(x,y,width,height));
00202       }
00203 
00205       inline void rect(const Rect32f &r){
00206         addPart('r',r);
00207       }
00208 
00210       inline void ellipse(icl32f x, icl32f y, icl32f width, icl32f height){
00211         addPart('e',Rect32f(x,y,width,height));
00212       }
00213 
00215       inline void ellipse(const Rect32f &r){
00216         addPart('e',r);
00217       }
00218 
00220       inline void circle(icl32f cx, icl32f cy, icl32f radius){
00221         addPart('e',Rect32f(cx-radius,cy-radius,2*radius,2*radius));
00222       }
00223 
00225       inline void line(icl32f x1, icl32f y1, icl32f x2, icl32f y2){
00226         addPart('l',Rect32f(x1,y1,x2-x1,y2-y1));
00227       }
00228 
00230       inline void line(const Point32f &a, const Point32f &b){
00231         addPart('l',Rect32f(a.x,a.y,b.x-a.x,b.y-a.y));
00232       }
00233 
00235       inline void sym(char type, icl32f x, icl32f y){
00236         addPart(type,Point32f(x,y));
00237       }
00238       
00240       inline void sym(char type, const Point32f &p){
00241         addPart(type,p);
00242       }
00244 
00245       void text(icl32f x, icl32f y, const std::string &text);
00246       
00248 
00249       void text(const Point32f &pos, const std::string &text);
00250       
00252       void point(const Point32f &p){
00253         sym('.',p);
00254       }
00255       
00257       template<class Iterator>
00258       void points(Iterator begin, Iterator end){
00259         addPart('p',std::vector<float>(begin,end));
00260       }
00261       
00263       void points(const std::vector<Point32f> &ps){
00264         points(&ps[0].x,&ps[0].x + ps.size() * 2);
00265       }
00266 
00268       void points(const std::vector<Point> &ps){
00269         points(&ps[0].x,&ps[0].x + ps.size() * 2);
00270       }
00271 
00273       template<class Iterator>
00274       void polygon(Iterator begin, Iterator end){
00275         addPart('y',std::vector<float>(begin,end));
00276       }
00277       
00279       void polygon(const std::vector<Point32f> &ps){
00280         polygon(&ps[0].x,&ps[0].x + ps.size() * 2);
00281       }
00282 
00284       void polygon(const std::vector<Point> &ps){
00285         polygon(&ps[0].x,&ps[0].x + ps.size() * 2);
00286       }
00287       
00289       void linewidth(float w){
00290         addPart('L',w);
00291       }
00292       
00294       void pointsize(float s){
00295         addPart('P',s);
00296       }
00297 
00298     };
00299     
00302     inline std::ostream &operator<<(std::ostream &stream, const VisualizationDescription::Text &t){
00303       return (stream << t.pos << t.text);
00304     }
00305 
00308     inline std::istream &operator>>(std::istream &stream, VisualizationDescription::Text &t){
00309       stream >> t.pos;
00310       std::getline(stream,t.text);
00311       return stream;
00312     }
00313 
00315     inline std::ostream &operator<<(std::ostream &stream, const VisualizationDescription::Color &c){
00316       return (stream << c.rgba);
00317     }
00318 
00320     inline std::istream &operator>>(std::istream &stream, VisualizationDescription::Color &c){
00321       stream >> c.rgba;
00322       return stream;
00323     }
00324     
00326     inline void VisualizationDescription::text(icl32f x, icl32f y, const std::string &text){
00327       addPart('t',VisualizationDescription::Text(Point32f(x,y),text));
00328     }
00329     
00331     inline void VisualizationDescription::text(const Point32f &pos, const std::string &text){
00332       addPart('t',VisualizationDescription::Text(pos,text));
00333     }
00334     
00336     inline void VisualizationDescription::color(icl8u r, icl8u g, icl8u b){
00337       addPart('c',VisualizationDescription::Color(r,g,b));
00338     }
00339     
00341     inline void VisualizationDescription::color(icl8u r, icl8u g, icl8u b, icl8u a){
00342       addPart('c',VisualizationDescription::Color(r,g,b,a));
00343     }
00344     
00346     inline void VisualizationDescription::fill(icl8u r, icl8u g, icl8u b){
00347       addPart('f',VisualizationDescription::Color(r,g,b));
00348     }
00349     
00351     inline void VisualizationDescription::fill(icl8u r, icl8u g, icl8u b, icl8u a){
00352       addPart('f',VisualizationDescription::Color(r,g,b,a));
00353     }
00354   }
00355 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines