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 : 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.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 <ICLUtils/Any.h> 00034 #include <ICLUtils/Point32f.h> 00035 #include <ICLUtils/Rect32f.h> 00036 00037 namespace icl{ 00038 namespace utils{ 00039 00040 00042 00070 class VisualizationDescription{ 00071 public: 00072 00074 struct Part{ 00076 inline Part(){} 00077 00079 Part(char type, const Any &content):type(type),content(content){} 00080 00082 char type; 00083 00085 Any content; 00086 }; 00087 00089 struct Text{ 00090 Point32f pos; 00091 std::string text; 00092 00093 Text(){} 00094 00096 Text(const Point32f &pos, const std::string &text):pos(pos),text(text){} 00097 }; 00098 00100 struct Color{ 00102 union{ 00103 icl8u comp[4]; 00104 icl32s rgba; 00105 }; 00107 Color(){} 00108 00110 Color(icl8u r, icl8u g, icl8u b, icl8u a=255){ 00111 this->r() = r; 00112 this->g() = g; 00113 this->b() = b; 00114 this->a() = a; 00115 } 00117 inline icl8u &r() { return comp[0]; } 00118 00120 inline icl8u &g() { return comp[1]; } 00121 00123 inline icl8u &b() { return comp[2]; } 00124 00126 inline icl8u &a() { return comp[3]; } 00127 00129 inline const icl8u &r() const { return comp[0]; } 00130 00132 inline const icl8u &g() const { return comp[1]; } 00133 00135 inline const icl8u &b() const { return comp[2]; } 00136 00138 inline const icl8u &a() const { return comp[3]; } 00139 00140 }; 00141 00142 protected: 00143 00145 std::vector<Part> parts; 00146 public: 00147 00149 inline const std::vector<Part> &getParts() const { 00150 return parts; 00151 } 00152 00154 inline void clear() { 00155 parts.clear(); 00156 } 00157 00159 inline void addPart(const Part &part){ 00160 parts.push_back(part); 00161 } 00163 inline void addPart(char c, const Any &content){ 00164 addPart(Part(c,content)); 00165 } 00166 00168 00169 VisualizationDescription &operator+=(const VisualizationDescription &other){ 00170 size_t oldSize = parts.size(); 00171 parts.resize(oldSize + other.parts.size()); 00172 std::copy(other.parts.begin(),other.parts.end(),parts.begin()+oldSize); 00173 return *this; 00174 } 00175 00177 00178 VisualizationDescription operator+(const VisualizationDescription &other){ 00179 VisualizationDescription sum; 00180 sum.parts.resize(parts.size()+other.parts.size()); 00181 std::copy(parts.begin(),parts.end(),sum.parts.begin()); 00182 std::copy(other.parts.begin(),other.parts.end(),sum.parts.begin()+parts.size()); 00183 return sum; 00184 } 00185 00187 void color(icl8u r, icl8u g, icl8u b); 00188 00190 void color(icl8u r, icl8u g, icl8u b, icl8u a); 00191 00193 void fill(icl8u r, icl8u g, icl8u b); 00194 00196 void fill(icl8u r, icl8u g, icl8u b, icl8u a); 00197 00199 inline void rect(icl32f x, icl32f y, icl32f width, icl32f height){ 00200 addPart('r',Rect32f(x,y,width,height)); 00201 } 00202 00204 inline void rect(const Rect32f &r){ 00205 addPart('r',r); 00206 } 00207 00209 inline void ellipse(icl32f x, icl32f y, icl32f width, icl32f height){ 00210 addPart('e',Rect32f(x,y,width,height)); 00211 } 00212 00214 inline void ellipse(const Rect32f &r){ 00215 addPart('e',r); 00216 } 00217 00219 inline void circle(icl32f cx, icl32f cy, icl32f radius){ 00220 addPart('e',Rect32f(cx-radius,cy-radius,2*radius,2*radius)); 00221 } 00222 00224 inline void line(icl32f x1, icl32f y1, icl32f x2, icl32f y2){ 00225 addPart('l',Rect32f(x1,y1,x2-x1,y2-y1)); 00226 } 00227 00229 inline void line(const Point32f &a, const Point32f &b){ 00230 addPart('l',Rect32f(a.x,a.y,b.x-a.x,b.y-a.y)); 00231 } 00232 00234 inline void sym(char type, icl32f x, icl32f y){ 00235 addPart(type,Point32f(x,y)); 00236 } 00237 00239 inline void sym(char type, const Point32f &p){ 00240 addPart(type,p); 00241 } 00243 00244 void text(icl32f x, icl32f y, const std::string &text); 00245 00247 00248 void text(const Point32f &pos, const std::string &text); 00249 00251 void point(const Point32f &p){ 00252 sym('.',p); 00253 } 00254 00256 template<class Iterator> 00257 void points(Iterator begin, Iterator end){ 00258 addPart('p',std::vector<float>(begin,end)); 00259 } 00260 00262 void points(const std::vector<Point32f> &ps){ 00263 points(&ps[0].x,&ps[0].x + ps.size() * 2); 00264 } 00265 00267 void points(const std::vector<Point> &ps){ 00268 points(&ps[0].x,&ps[0].x + ps.size() * 2); 00269 } 00270 00272 template<class Iterator> 00273 void polygon(Iterator begin, Iterator end){ 00274 addPart('y',std::vector<float>(begin,end)); 00275 } 00276 00278 void polygon(const std::vector<Point32f> &ps){ 00279 polygon(&ps[0].x,&ps[0].x + ps.size() * 2); 00280 } 00281 00283 void polygon(const std::vector<Point> &ps){ 00284 polygon(&ps[0].x,&ps[0].x + ps.size() * 2); 00285 } 00286 00288 void linewidth(float w){ 00289 addPart('L',w); 00290 } 00291 00293 void pointsize(float s){ 00294 addPart('P',s); 00295 } 00296 00297 }; 00298 00301 inline std::ostream &operator<<(std::ostream &stream, const VisualizationDescription::Text &t){ 00302 return (stream << t.pos << t.text); 00303 } 00304 00307 inline std::istream &operator>>(std::istream &stream, VisualizationDescription::Text &t){ 00308 stream >> t.pos; 00309 std::getline(stream,t.text); 00310 return stream; 00311 } 00312 00314 inline std::ostream &operator<<(std::ostream &stream, const VisualizationDescription::Color &c){ 00315 return (stream << c.rgba); 00316 } 00317 00319 inline std::istream &operator>>(std::istream &stream, VisualizationDescription::Color &c){ 00320 stream >> c.rgba; 00321 return stream; 00322 } 00323 00325 inline void VisualizationDescription::text(icl32f x, icl32f y, const std::string &text){ 00326 addPart('t',VisualizationDescription::Text(Point32f(x,y),text)); 00327 } 00328 00330 inline void VisualizationDescription::text(const Point32f &pos, const std::string &text){ 00331 addPart('t',VisualizationDescription::Text(pos,text)); 00332 } 00333 00335 inline void VisualizationDescription::color(icl8u r, icl8u g, icl8u b){ 00336 addPart('c',VisualizationDescription::Color(r,g,b)); 00337 } 00338 00340 inline void VisualizationDescription::color(icl8u r, icl8u g, icl8u b, icl8u a){ 00341 addPart('c',VisualizationDescription::Color(r,g,b,a)); 00342 } 00343 00345 inline void VisualizationDescription::fill(icl8u r, icl8u g, icl8u b){ 00346 addPart('f',VisualizationDescription::Color(r,g,b)); 00347 } 00348 00350 inline void VisualizationDescription::fill(icl8u r, icl8u g, icl8u b, icl8u a){ 00351 addPart('f',VisualizationDescription::Color(r,g,b,a)); 00352 } 00353 } 00354 }