Image Component Library (ICL)
VisualizationDescription.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 : ICLUtils/src/ICLUtils/VisualizationDescription.h **
10 ** Module : ICLUtils **
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>
34 #include <ICLUtils/Any.h>
35 #include <ICLUtils/Point32f.h>
36 #include <ICLUtils/Rect32f.h>
37 
38 namespace icl{
39  namespace utils{
40 
41 
43 
74  public:
75 
77  struct Part{
79  inline Part(){}
80 
83 
85  char type;
86 
89  };
90 
92  struct Text{
94  std::string text;
95  Text(){}
97 
99  Text(const Point32f &pos, const std::string &text):pos(pos),text(text){}
100  };
101 
103  struct Color{
105  union{
108  };
110  Color(){}
111 
114  this->r() = r;
115  this->g() = g;
116  this->b() = b;
117  this->a() = a;
118  }
120  inline icl8u &r() { return comp[0]; }
121 
123  inline icl8u &g() { return comp[1]; }
124 
126  inline icl8u &b() { return comp[2]; }
127 
129  inline icl8u &a() { return comp[3]; }
130 
132  inline const icl8u &r() const { return comp[0]; }
133 
135  inline const icl8u &g() const { return comp[1]; }
136 
138  inline const icl8u &b() const { return comp[2]; }
139 
141  inline const icl8u &a() const { return comp[3]; }
142 
143  };
144 
145  protected:
146 
148  std::vector<Part> parts;
149  public:
150 
152  inline const std::vector<Part> &getParts() const {
153  return parts;
154  }
155 
157  inline void clear() {
158  parts.clear();
159  }
160 
162  inline void addPart(const Part &part){
163  parts.push_back(part);
164  }
166  inline void addPart(char c, const Any &content){
167  addPart(Part(c,content));
168  }
169 
171 
173  size_t oldSize = parts.size();
174  parts.resize(oldSize + other.parts.size());
175  std::copy(other.parts.begin(),other.parts.end(),parts.begin()+oldSize);
176  return *this;
177  }
178 
180 
183  sum.parts.resize(parts.size()+other.parts.size());
184  std::copy(parts.begin(),parts.end(),sum.parts.begin());
185  std::copy(other.parts.begin(),other.parts.end(),sum.parts.begin()+parts.size());
186  return sum;
187  }
188 
190  void color(icl8u r, icl8u g, icl8u b);
191 
193  void color(icl8u r, icl8u g, icl8u b, icl8u a);
194 
196  void fill(icl8u r, icl8u g, icl8u b);
197 
199  void fill(icl8u r, icl8u g, icl8u b, icl8u a);
200 
202  inline void rect(icl32f x, icl32f y, icl32f width, icl32f height){
203  addPart('r',Rect32f(x,y,width,height));
204  }
205 
207  inline void rect(const Rect32f &r){
208  addPart('r',r);
209  }
210 
212  inline void ellipse(icl32f x, icl32f y, icl32f width, icl32f height){
213  addPart('e',Rect32f(x,y,width,height));
214  }
215 
217  inline void ellipse(const Rect32f &r){
218  addPart('e',r);
219  }
220 
222  inline void circle(icl32f cx, icl32f cy, icl32f radius){
223  addPart('e',Rect32f(cx-radius,cy-radius,2*radius,2*radius));
224  }
225 
227  inline void line(icl32f x1, icl32f y1, icl32f x2, icl32f y2){
228  addPart('l',Rect32f(x1,y1,x2-x1,y2-y1));
229  }
230 
232  inline void line(const Point32f &a, const Point32f &b){
233  addPart('l',Rect32f(a.x,a.y,b.x-a.x,b.y-a.y));
234  }
235 
237  inline void sym(char type, icl32f x, icl32f y){
238  addPart(type,Point32f(x,y));
239  }
240 
242  inline void sym(char type, const Point32f &p){
243  addPart(type,p);
244  }
245 
247 
248  void text(icl32f x, icl32f y, const std::string &text);
249 
251 
252  void text(const Point32f &pos, const std::string &text);
253 
255  void point(const Point32f &p){
256  sym('.',p);
257  }
258 
260  template<class Iterator>
261  void points(Iterator begin, Iterator end){
262  addPart('p',std::vector<float>(begin,end));
263  }
264 
266  void points(const std::vector<Point32f> &ps){
267  points(&ps[0].x,&ps[0].x + ps.size() * 2);
268  }
269 
271  void points(const std::vector<Point> &ps){
272  points(&ps[0].x,&ps[0].x + ps.size() * 2);
273  }
274 
276  template<class Iterator>
277  void polygon(Iterator begin, Iterator end){
278  addPart('y',std::vector<float>(begin,end));
279  }
280 
282  void polygon(const std::vector<Point32f> &ps){
283  polygon(&ps[0].x,&ps[0].x + ps.size() * 2);
284  }
285 
287  void polygon(const std::vector<Point> &ps){
288  polygon(&ps[0].x,&ps[0].x + ps.size() * 2);
289  }
290 
292  void linewidth(float w){
293  addPart('L',w);
294  }
295 
297  void pointsize(float s){
298  addPart('P',s);
299  }
300 
302  inline void fontsize(float s){
303  addPart('F',s);
304  }
305 
307  inline void textangle(float angle){
308  addPart('A',angle);
309  }
310  };
311 
314  inline std::ostream &operator<<(std::ostream &stream, const VisualizationDescription::Text &t){
315  return (stream << t.pos << t.text);
316  }
317 
320  inline std::istream &operator>>(std::istream &stream, VisualizationDescription::Text &t){
321  stream >> t.pos;
322  std::getline(stream,t.text);
323  return stream;
324  }
325 
327  inline std::ostream &operator<<(std::ostream &stream, const VisualizationDescription::Color &c){
328  return (stream << c.rgba);
329  }
330 
332  inline std::istream &operator>>(std::istream &stream, VisualizationDescription::Color &c){
333  stream >> c.rgba;
334  return stream;
335  }
336 
338  inline void VisualizationDescription::text(icl32f x, icl32f y, const std::string &text){
340  }
341 
343  inline void VisualizationDescription::text(const Point32f &pos, const std::string &text){
345  }
346 
350  }
351 
355  }
356 
360  }
361 
365  }
366  }
367 }
368 
void points(const std::vector< Point > &ps)
adds points from given vector of Points
Definition: VisualizationDescription.h:271
const icl8u & a() const
accesses alpha value (const)
Definition: VisualizationDescription.h:141
std::vector< Part > parts
internal part list
Definition: VisualizationDescription.h:148
icl8u & b()
accesses blue value
Definition: VisualizationDescription.h:126
undocument this line if you encounter any issues!
Definition: Any.h:37
void pointsize(float s)
defines the point size
Definition: VisualizationDescription.h:297
Ipp8u icl8u
8Bit unsigned integer type for the ICL
Definition: BasicTypes.h:64
const icl8u & r() const
accesses red value (const)
Definition: VisualizationDescription.h:132
Point32f pos
text pos
Definition: VisualizationDescription.h:93
float y
y position of this point
Definition: Point32f.h:48
Text(const Point32f &pos, const std::string &text)
Constructor with given pos and content.
Definition: VisualizationDescription.h:99
ICLQt_API void text(ImgQ &image, int x, int y, const string &text)
renders a text into an image (only available with Qt-Support)
std::string text
Definition: VisualizationDescription.h:94
Color()
Empty default constructor.
Definition: VisualizationDescription.h:110
void polygon(Iterator begin, Iterator end)
template based creation of a polygon
Definition: VisualizationDescription.h:277
void circle(icl32f cx, icl32f cy, icl32f radius)
adds a circle (intnerally handeled as ellipse)
Definition: VisualizationDescription.h:222
icl8u & g()
accesses green value
Definition: VisualizationDescription.h:123
void clear()
clears the list
Definition: VisualizationDescription.h:157
Part(char type, const Any &content)
constructor with given parameters
Definition: VisualizationDescription.h:82
void polygon(const std::vector< Point > &ps)
adds polygon from given vector of Points
Definition: VisualizationDescription.h:287
char type
type
Definition: VisualizationDescription.h:85
Part()
constructor
Definition: VisualizationDescription.h:79
icl8u & a()
accesses alpha value
Definition: VisualizationDescription.h:129
void rect(icl32f x, icl32f y, icl32f width, icl32f height)
add a rectangle
Definition: VisualizationDescription.h:202
icl8u & r()
accesses red value
Definition: VisualizationDescription.h:120
Floating point precision implementation of the Rect class.
Definition: Rect32f.h:45
void linewidth(float w)
defines the linewidth
Definition: VisualizationDescription.h:292
void ellipse(icl32f x, icl32f y, icl32f width, icl32f height)
add an ellipse
Definition: VisualizationDescription.h:212
Ipp32s icl32s
32bit signed integer type for the ICL
Definition: BasicTypes.h:58
Ipp32f icl32f
32Bit floating point type for the ICL
Definition: BasicTypes.h:55
void textangle(float angle)
sets the vertical text mode
Definition: VisualizationDescription.h:307
const icl8u & b() const
accesses blue value (const)
Definition: VisualizationDescription.h:138
void text(icl32f x, icl32f y, const std::string &text)
adds text
Definition: VisualizationDescription.h:338
Any content
strind-serialized content
Definition: VisualizationDescription.h:88
icl32s rgba
Definition: VisualizationDescription.h:107
ICLUtils_API std::ostream & operator<<(std::ostream &s, const ConfigFile &cf)
Default ostream operator to put a ConfigFile into a stream.
void addPart(char c, const Any &content)
adds a given part
Definition: VisualizationDescription.h:166
Text()
Empty constructor.
Definition: VisualizationDescription.h:96
ICLUtils_API std::istream & operator>>(std::istream &s, Point &p)
istream operator
void line(icl32f x1, icl32f y1, icl32f x2, icl32f y2)
adds a line (intnerally represented by bounding rectangle)
Definition: VisualizationDescription.h:227
void rect(const Rect32f &r)
add a rectangle
Definition: VisualizationDescription.h:207
const icl8u & g() const
accesses green value (const)
Definition: VisualizationDescription.h:135
void addPart(const Part &part)
adds a given part
Definition: VisualizationDescription.h:162
Abstract class for visualization tasks.
Definition: VisualizationDescription.h:73
void polygon(const std::vector< Point32f > &ps)
adds polygon from given float vector
Definition: VisualizationDescription.h:282
Single precission 3D Vectors Point class of the ICL.
Definition: Point32f.h:41
void line(const Point32f &a, const Point32f &b)
adds a line (intnerally represented by bounding rectangle)
Definition: VisualizationDescription.h:232
Utility class for Text.
Definition: VisualizationDescription.h:92
void sym(char type, const Point32f &p)
adds a symbol (supported types are +*x and .)
Definition: VisualizationDescription.h:242
float x
x position of this point
Definition: Point32f.h:45
Utility Color class.
Definition: VisualizationDescription.h:103
const std::vector< Part > & getParts() const
returns the parts
Definition: VisualizationDescription.h:152
void points(const std::vector< Point32f > &ps)
adds points from given float vector
Definition: VisualizationDescription.h:266
void copy(const T *src, const T *srcEnd, T *dst)
moves data from source to destination array (no casting possible)
Definition: CoreFunctions.h:216
icl8u comp[4]
Definition: VisualizationDescription.h:106
Single part of the the visualization pipeline.
Definition: VisualizationDescription.h:77
VisualizationDescription & operator+=(const VisualizationDescription &other)
adds another visualization description
Definition: VisualizationDescription.h:172
void color(icl8u r, icl8u g, icl8u b)
sets the current draw color (no alpha)
Definition: VisualizationDescription.h:348
void ellipse(const Rect32f &r)
add an ellipse
Definition: VisualizationDescription.h:217
void fontsize(float s)
defines the font size to be used
Definition: VisualizationDescription.h:302
Color(icl8u r, icl8u g, icl8u b, icl8u a=255)
Constructor with given color values.
Definition: VisualizationDescription.h:113
Simple generic data type implementation that uses a string based data representation.
Definition: Any.h:109
void point(const Point32f &p)
adds a point (internally handles as a sym of type '.')
Definition: VisualizationDescription.h:255
void fill(icl8u r, icl8u g, icl8u b)
sets the current fill color (no alpha)
Definition: VisualizationDescription.h:358
void points(Iterator begin, Iterator end)
adds points (data is in order [x1,y1,x2,y2]
Definition: VisualizationDescription.h:261
void sym(char type, icl32f x, icl32f y)
adds a symbol (supported types are +*x and .)
Definition: VisualizationDescription.h:237
VisualizationDescription operator+(const VisualizationDescription &other)
adds two descriptions
Definition: VisualizationDescription.h:181