Image Component Library (ICL)
AbstractCanvas.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 : ICLCore/src/ICLCore/AbstractCanvas.h **
10 ** Module : ICLCore **
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 <ICLCore/Img.h>
35 #include <ICLUtils/Uncopyable.h>
36 #include <ICLMath/FixedMatrix.h>
37 #include <ICLCore/Color.h>
38 #include <ICLUtils/Rect32f.h>
39 
40 
41 namespace icl{
42 
43  using namespace math;
44  using namespace utils;
45 
46  namespace core{
47 
48 
49 
51  public:
55  ClipRect(float minx=0, float maxx=0, float miny=0, float maxy=0):
56  minx(minx),maxx(maxx),miny(miny),maxy(maxy){}
57  float minx;
58  float maxx;
59  float miny;
60  float maxy;
61  bool in(float x, float y) const{
62  return ((x >= minx) && (x<= maxx)
63  && (y >= miny) && (y <= maxy));
64  }
65  bool in(const Point32f &p) const{
66  return in(p.x,p.y);
67  }
68  };
69 
70  protected:
71  struct State{
75  float linewidth;
76  float pointsize;
77  float symsize;
78  float fontsize;
79  std::string fontname;
81 
82  inline State():
83  T(AbstractCanvas::Transform::id()),
84  linecolor(255,0,0,255),fillcolor(0,0,0,0),
85  linewidth(1),pointsize(1),symsize(10),
86  fontsize(10),fontname("arial"){}
87  };
88 
90  std::vector<State> stack;
91 
92  inline utils::Point32f transform(float x, float y) const{
93  return Point32f(state.T(0,0)*x + state.T(1,0)*y + state.T(2,0),
94  state.T(0,1)*x + state.T(1,1)*y + state.T(2,1));
95  }
96  inline bool clip(float x, float y) const{
97  return state.clip.in(x,y);
98  }
99  inline bool clip(const Point32f &p) const{
100  return state.clip.in(p);
101  }
102 
103 
104  public:
105 
107  virtual ~AbstractCanvas(){}
108 
109  virtual void draw_point_internal(const utils::Point32f &p) = 0;
110  virtual void draw_line_internal(const utils::Point32f &a,
111  const utils::Point32f &b) = 0;
112  virtual void fill_triangle_internal(const utils::Point32f &a,
113  const utils::Point32f &b,
114  const utils::Point32f &c) = 0;
115  virtual void draw_ellipse_internal(const utils::Point32f &c,
116  const utils::Point32f &axis1,
117  const utils::Point32f &axis2) = 0;
118  virtual void draw_image_internal(const utils::Point32f &ul,
119  const utils::Point32f &ur,
120  const utils::Point32f &lr,
121  const utils::Point32f &ll,
122  float alpha, scalemode sm) = 0;
123 
124  public:
125 
126  virtual const Transform &getTransform() const{
127  return state.T;
128  }
129  virtual void getTransform(float &angle, float &tx, float &ty) const{
130  angle = acos(state.T(0,0));
131  tx = state.T(2,0);
132  ty = state.T(2,1);
133  }
134 
135 
136  virtual Rect32f getClipRect(){
137  return Rect32f(state.clip.minx, state.clip.miny,
138  state.clip.maxx-state.clip.minx,
139  state.clip.maxy-state.clip.miny);
140  }
141 
142  virtual void push(){
143  stack.push_back(state);
144  }
145 
146  virtual void pop() {
147  ICLASSERT_THROW(stack.size(), utils::ICLException("AbstractCanvas::pop: stack is empty"));
148  state = stack.back();
149  stack.pop_back();
150  }
151 
152  virtual void point(float x, float y);
153  virtual void line(float x0, float y0, float x1, float y1);
154  virtual void triangle(float x0, float y0, float x1, float y1, float x2, float y2);
155  virtual void sym(char c, float x, float y) ;
156  virtual void linestrip(int n, const float *xs, const float *ys,
157  int xStride=1, int yStride=1, bool loop=false);
158  virtual void rect(float x, float y, float w, float h);
159  virtual void circle(float cx, float cy, float r);
160  virtual void ellipse(float cx, float cy, float rx, float ry);
161  virtual void image(const ImgBase *image, float xanchor,
162  float yanchor, float alpha,
164  bool centered=false) ;
165  virtual void text(const std::string &t, float x, float y, bool centered = false);
166 
167  virtual void linecolor(float r, float g, float b, float a=255){
168  state.linecolor = Color(r,g,b,a);
169  }
170 
171  virtual void fillcolor(float r, float g, float b, float a=255){
172  state.fillcolor = Color(r,g,b,a);
173  }
174 
175  virtual void linewidth(float width){
176  state.linewidth = width;
177  }
178 
179  virtual void pointsize(float size){
180  state.pointsize = size;
181  }
182 
183  virtual void symsize(float size){
184  state.symsize = size;
185  }
186 
187  virtual void fontsize(float size){
188  state.fontsize = size;
189  }
190 
191  virtual void fontname(const std::string &fontname){
192  state.fontname = fontname;
193  }
194 
195  virtual void transform(const Transform &T){
196  state.T = T*state.T;
197  }
198 
199  virtual void transform(float tx, float ty, float angle){
200  if(angle){
201  const float sa = sin(angle), ca = cos(angle);
202  state.T = Transform(ca,sa,tx,
203  -sa,ca,ty,
204  0,0,1)*state.T;
205  }else{
206  state.T(2,0) += tx;
207  state.T(2,1) += ty;
208  }
209  }
210 
212  virtual void reset(){
213  state.T = Transform::id();
214  }
215 
216  virtual void rotate(float angle){
217  transform(0,0,angle);
218  }
219  virtual void translate(float tx, float ty){
220  transform(tx,ty,0);
221  }
222  virtual void scale(float s){
223  scale(s,s);
224  }
225 
226  virtual void scale(float sx, float sy){
227  state.T = Transform(sx,0,0,
228  0,sy,0,
229  0,0,1) * state.T;
230  }
231  };
232 
233  }
234 }
virtual void scale(float s)
Definition: AbstractCanvas.h:222
virtual void linewidth(float width)
Definition: AbstractCanvas.h:175
AbstractCanvas::Color linecolor
Definition: AbstractCanvas.h:73
undocument this line if you encounter any issues!
Definition: Any.h:37
math::FixedColVector< icl8u, 3 > Color
Default color type of the ICL.
Definition: Color.h:42
Class interface for un-copyable classes.
Definition: Uncopyable.h:64
ICLQt_API void triangle(ImgQ &image, int x1, int y1, int x2, int y2, int x3, int y3)
draws a triangle into an image
math::FixedMatrix< float, 3, 3 > Transform
Definition: AbstractCanvas.h:52
float minx
Definition: AbstractCanvas.h:57
ICLQt_API void fontsize(int size)
sets up current fontsize (only available with Qt-Support)
float y
y position of this point
Definition: Point32f.h:48
virtual const Transform & getTransform() const
Definition: AbstractCanvas.h:126
std::string fontname
Definition: AbstractCanvas.h:79
ICLQt_API void text(ImgQ &image, int x, int y, const string &text)
renders a text into an image (only available with Qt-Support)
virtual void fillcolor(float r, float g, float b, float a=255)
Definition: AbstractCanvas.h:171
virtual void fontname(const std::string &fontname)
Definition: AbstractCanvas.h:191
Definition: AbstractCanvas.h:54
float symsize
Definition: AbstractCanvas.h:77
virtual void pointsize(float size)
Definition: AbstractCanvas.h:179
virtual void scale(float sx, float sy)
Definition: AbstractCanvas.h:226
virtual void reset()
resets the transform
Definition: AbstractCanvas.h:212
virtual void transform(const Transform &T)
Definition: AbstractCanvas.h:195
virtual void fontsize(float size)
Definition: AbstractCanvas.h:187
ICLQt_API void line(ImgQ &image, int x1, int y1, int x2, int y2)
draws a line into an image
ClipRect clip
Definition: AbstractCanvas.h:80
utils::Point32f transform(float x, float y) const
Definition: AbstractCanvas.h:92
virtual void rotate(float angle)
Definition: AbstractCanvas.h:216
virtual void getTransform(float &angle, float &tx, float &ty) const
Definition: AbstractCanvas.h:129
Floating point precision implementation of the Rect class.
Definition: Rect32f.h:45
virtual void transform(float tx, float ty, float angle)
Definition: AbstractCanvas.h:199
ICLQt_API void linestrip(ImgQ &image, const std::vector< utils::Point > &pts, bool closeLoop=true)
draws a strip of connected lines
std::vector< State > stack
Definition: AbstractCanvas.h:90
virtual void symsize(float size)
Definition: AbstractCanvas.h:183
AbstractCanvas::Color fillcolor
Definition: AbstractCanvas.h:74
float linewidth
Definition: AbstractCanvas.h:75
bool clip(const Point32f &p) const
Definition: AbstractCanvas.h:99
virtual void pop()
Definition: AbstractCanvas.h:146
bool in(const Point32f &p) const
Definition: AbstractCanvas.h:65
State state
Definition: AbstractCanvas.h:89
virtual void linecolor(float r, float g, float b, float a=255)
Definition: AbstractCanvas.h:167
float maxy
Definition: AbstractCanvas.h:60
float fontsize
Definition: AbstractCanvas.h:78
float miny
Definition: AbstractCanvas.h:59
virtual ~AbstractCanvas()
Definition: AbstractCanvas.h:107
Definition: AbstractCanvas.h:71
AbstractCanvas()
Definition: AbstractCanvas.h:106
AbstractCanvas::Transform T
Definition: AbstractCanvas.h:72
Definition: AbstractCanvas.h:50
scalemode
for scaling of Img images theses functions are provided
Definition: Types.h:84
Single precission 3D Vectors Point class of the ICL.
Definition: Point32f.h:41
core::Color4D32f Color
Definition: AbstractCanvas.h:53
static void scale(const int deg, xcomplex *P)
Definition: PolynomialSolver.h:133
float x
x position of this point
Definition: Point32f.h:45
State()
Definition: AbstractCanvas.h:82
ICLQt_API void circle(ImgQ &image, int x, int y, int r)
renders a filled circle into an image
Base class for Exception handling in the ICL.
Definition: Exception.h:42
virtual void push()
Definition: AbstractCanvas.h:142
ICLQt_API void rect(ImgQ &image, int x, int y, int w, int h, int rounding=0)
draws a rect into an image
virtual Rect32f getClipRect()
Definition: AbstractCanvas.h:136
float maxx
Definition: AbstractCanvas.h:58
bool clip(float x, float y) const
Definition: AbstractCanvas.h:96
float pointsize
Definition: AbstractCanvas.h:76
Definition: Types.h:86
ImgBase is the Image-Interface class that provides save access to underlying Img-template .
Definition: ImgBase.h:131
#define ICLASSERT_THROW(X, OBJ)
Definition: Macros.h:155
bool in(float x, float y) const
Definition: AbstractCanvas.h:61
virtual void translate(float tx, float ty)
Definition: AbstractCanvas.h:219
#define ICLCore_API
Definition: CompatMacros.h:174
ClipRect(float minx=0, float maxx=0, float miny=0, float maxy=0)
Definition: AbstractCanvas.h:55