Image Component Library (ICL)
DefineRectanglesMouseHandler.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 : ICLQt/src/ICLQt/DefineRectanglesMouseHandler.h **
10 ** Module : ICLQt **
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/Lockable.h>
35 #include <ICLUtils/Any.h>
36 #include <ICLUtils/Function.h>
37 #include <ICLCore/Color.h>
38 #include <ICLQt/MouseHandler.h>
39 
40 namespace icl{
41  namespace qt{
42 
44  class ICLDrawWidget;
48 
75 
78 
82 
103  public:
108  Options(const core::Color4D &edgeColor=core::Color4D(0,255,0,255),
109  const core::Color4D &fillColor=core::Color4D(0,255,0,50),
110  const core::Color4D &centerColor=core::Color4D(0,255,0,255),
111  const core::Color4D &metaColor=core::Color4D(0,255,0,255),
112  int handleWidth=3, bool visualizeCenter=false,
113  bool visualizeHovering=true,
114  bool showOffsetText=false,
115  bool showSizeText=false,
116  bool showCenterText=false,
117  bool showMetaData=false,
118  int lineWidth=1,
119  float textSize=9);
120  public:
132  int lineWidth;
133  float textSize;
134  int xStepping;
135  int yStepping;
137  };
138 
139  protected:
140 
145 
147  enum Edge{
148  T,
149  R,
150  B,
151  L
152  };
154  enum State{
157  dragged
158  };
159 
161  State states[4];
162 
165 
168 
170  utils::Rect edge(Edge e) const;
172  utils::Rect edgei(int i) const;
174  utils::Rect inner() const;
176  utils::Rect outer() const;
178  bool allHovered() const;
180  bool allDragged() const;
182  bool anyDragged() const;
183 
186 
188  State event(const MouseEvent &e);
189 
191  void visualize(ICLDrawWidget &w);
192 
195  };
196 
197 
198  int maxRects;
199  int minDim;
200  std::vector<DefinedRect> rects;
205 
206  private:
208  std::map<std::string,Callback> callbacks;
209  void callCallbacks();
210 
211  public:
212 
213 
214  void registerCallback(const std::string &id, Callback cb);
215  void unregisterCallback(const std::string &id);
216 
218 
221  DefineRectanglesMouseHandler(int maxRects=10, int minDim=4);
222 
224  void process(const MouseEvent &e);
225 
227 
228  void visualize(ICLDrawWidget &w);
229 
231  Options &getOptions();
232 
234  const Options &getOptions() const;
235 
237  void clearAllRects();
238 
240 
243  void clearRectAt(int x, int y, bool all=false);
244 
246 
247  void addRect(const utils::Rect &rect);
248 
250 
251  void setMaxRects(int maxRects);
252 
254  void setMinDim(int minDim);
255 
257  int getNumRects() const;
258 
260 
261  utils::Rect getRectAtIndex(int index) const;
262 
264  std::vector<utils::Rect> getRects() const;
265 
267 
270  utils::Rect getRectAt(int x, int y) const;
271 
273  std::vector<utils::Rect> getAllRectsAt(int x, int y) const;
274 
276  int getMinDim() const;
277 
279  int getMaxRects() const;
280 
282  const utils::Any &getMetaData(int index) const;
283 
285  const utils::Any &getMetaDataAt(int x, int y) const;
286 
288  void setMetaData(int index, const utils::Any &data);
289 
291  void setMetaDataAt(int x, int y, const utils::Any &data);
292 
294  void bringToFront(int idx);
295 
297  void bringToBack(int idx);
298  };
299  } // namespace qt
300 }
301 
The General Function Template.
Definition: Function.h:284
Cummulative Options structure.
Definition: DefineRectanglesMouseHandler.h:105
int xStepping
can be set to force a given stepping for defined rectangles (x-direction)
Definition: DefineRectanglesMouseHandler.h:134
undocument this line if you encounter any issues!
Definition: Any.h:37
core::Color4D centerColor
edge color used for the center visualization
Definition: DefineRectanglesMouseHandler.h:123
utils::Any meta
this can be used to attach meta data to rectangles
Definition: DefineRectanglesMouseHandler.h:194
std::map< std::string, Callback > callbacks
Definition: DefineRectanglesMouseHandler.h:208
nothing is currently done with this edge
Definition: DefineRectanglesMouseHandler.h:155
State
Edge states.
Definition: DefineRectanglesMouseHandler.h:154
core::Color4D edgeColor
edge color for rect visualization
Definition: DefineRectanglesMouseHandler.h:121
core::Color4D fillColor
fill color for rect visualization (set alpha to 0 to have no fill)
Definition: DefineRectanglesMouseHandler.h:122
utils::Point currCurr
used for the currently defined rectangle
Definition: DefineRectanglesMouseHandler.h:202
static const Rect null
null Rect is w=0, h=0, x=0, y=0
Definition: Rect.h:99
this edge is currently hovered (mouse over/not dragged)
Definition: DefineRectanglesMouseHandler.h:156
bool visualizeCenter
if true, the center of each rectangle is visualized
Definition: DefineRectanglesMouseHandler.h:126
ICLQt_API ImgROI data(ImgQ &r)
creates full ROI ROI-struct
int handleWidth
handle width (amount of pixels, you can be of an edge and still drag it)
Definition: DefineRectanglesMouseHandler.h:125
int yStepping
can be set to force a given stepping for defined rectangles (x-direction)
Definition: DefineRectanglesMouseHandler.h:135
std::vector< DefinedRect > rects
list of defined rectanges
Definition: DefineRectanglesMouseHandler.h:200
Top edge.
Definition: DefineRectanglesMouseHandler.h:148
Extended Image visualization widget, with a drawing state machine interface.
Definition: DrawWidget.h:142
Internally used utils::Rect structure.
Definition: DefineRectanglesMouseHandler.h:142
DefinedRect * draggedRect
use if any rectangle is currently moved or manipulated
Definition: DefineRectanglesMouseHandler.h:203
Utility mouse handler implementation that allows to define rectangles via drag and drop.
Definition: DefineRectanglesMouseHandler.h:102
MouseEvent Handler.
Definition: MouseHandler.h:92
int lineWidth
linewidth for visualization
Definition: DefineRectanglesMouseHandler.h:132
utils::Point allDragOffs
Internal help variable for smooth shifting of the whole rectangle.
Definition: DefineRectanglesMouseHandler.h:164
bool showCenterText
if true, the rects center is shown (as text)
Definition: DefineRectanglesMouseHandler.h:130
#define ICLQt_API
Definition: CompatMacros.h:178
Bottom edge.
Definition: DefineRectanglesMouseHandler.h:150
Point class of the ICL used e.g. for the Images ROI offset.
Definition: Point.h:58
Provided by interface MouseGrabber.
Definition: MouseEvent.h:86
utils::Function< void, const std::vector< utils::Rect > & > Callback
Definition: DefineRectanglesMouseHandler.h:207
utils::Point currBegin
used for the currently defined rectangle
Definition: DefineRectanglesMouseHandler.h:201
bool showOffsetText
if true, the rects upper left pixel's coordinates are shown (as text)
Definition: DefineRectanglesMouseHandler.h:128
core::Color4D metaColor
text color for visualization of meta-data
Definition: DefineRectanglesMouseHandler.h:124
bool showMetaData
if true, the meta data is shown as (as text)
Definition: DefineRectanglesMouseHandler.h:131
DefineRectanglesMouseHandler::Options * options
a pointer to the parent DefineRectanglesMouseHandler's Option structure
Definition: DefineRectanglesMouseHandler.h:167
int minDim
minimum dimension of rectangles
Definition: DefineRectanglesMouseHandler.h:199
ICLQt_API void rect(ImgQ &image, int x, int y, int w, int h, int rounding=0)
draws a rect into an image
Interface for objects, that can be locked using an internal mutex.
Definition: Lockable.h:41
bool visualizeHovering
if true, the rects boundary are drawn thicker if they are hovered
Definition: DefineRectanglesMouseHandler.h:127
Rectangle class of the ICL used e.g. for the Images ROI-rect.
Definition: Rect.h:95
Options options
options structure
Definition: DefineRectanglesMouseHandler.h:204
Edge
Edges.
Definition: DefineRectanglesMouseHandler.h:147
Simple generic data type implementation that uses a string based data representation.
Definition: Any.h:109
float textSize
text size used for all texts (note: if this is negative, it's defined in image pixels)
Definition: DefineRectanglesMouseHandler.h:133
Right edge.
Definition: DefineRectanglesMouseHandler.h:149
bool showSizeText
if true, the rects size is shown (as text)
Definition: DefineRectanglesMouseHandler.h:129
int maxRects
maximum count of rectangles
Definition: DefineRectanglesMouseHandler.h:198
bool canDeleteRects
defines whether rectangles can be deleted using right click
Definition: DefineRectanglesMouseHandler.h:136