Image Component Library (ICL)
|
Extended Image visualization widget, with a drawing state machine interface. More...
#include <DrawWidget.h>
Public Types | |
enum | Sym { symRect, symCross, symPlus, symTriangle, symCircle } |
enum used for specification of predefined symbols More... | |
Public Member Functions | |
ICLDrawWidget (QWidget *parent=0) | |
creates a new ICLDrawWidget embedded into the parent component | |
~ICLDrawWidget () | |
destructor2 | |
void | setAutoResetQueue (bool on) |
sets whether the draw commands are accumulative (default is on=true) | |
void | resetQueue () |
clears the current draw queue | |
void | abs () |
sets up the state machine to treat coordinates in the image pixel coordinate system | |
void | rel () |
sets up the state machine to receive relative coordinates in range [0,1] | |
void | image (core::ImgBase *image, float x, float y, float w, float h) |
draws an image into the given rectangle | |
void | image (core::ImgBase *image, const utils::Rect &r) |
convenience function for image using an image rect | |
void | image (const core::ImgBase *image, const float a[2], const float b[2], const float c[2], const float d[2]) |
draws an image into given quadrangle | |
void | text (std::string text, float x, float y, float w, float h, float fontsize=10) |
draws a string into the given rect | |
void | text (const std::string &text, float x, float y, float fontsize=10) |
draws text at given x, y location with given fontsize | |
void | text (const std::string &text, const utils::Point32f &p, float fontsize=10) |
draws the text at given position p | |
void | point (float x, float y) |
draws a point at the given location | |
void | point (const utils::Point &p) |
convenience wrapper for utils::Point types | |
void | point (const utils::Point32f &p) |
convenience wrapper for utils::Point32f types | |
template<class VectorType > | |
void | point (const VectorType &p) |
convenience wrapper for arbitrary types, that provide an index operator [int] | |
void | points (const std::vector< utils::Point > &pts, int xfac=1, int yfac=1) |
draws a set of points | |
void | points (const std::vector< utils::Point32f > &pts) |
draws a set of points | |
template<class VectorType > | |
void | point (const std::vector< VectorType > &points) |
convenience wrapper for arbitrary types, that provide an index operator [int] | |
void | linestrip (const std::vector< utils::Point > &pts, bool closeLoop=true, int xfac=1, int yfac=1) |
draws a set of connected points | |
void | linestrip (const std::vector< utils::Point32f > &pts, bool closeLoop=true) |
draws a set of connected points | |
void | line (float x1, float y1, float x2, float y2) |
draws a line from point (x1,y1) to point (x2,y2) | |
void | line (const utils::Point32f &a, const utils::Point32f &b) |
convenience function for drawing lines between two points | |
template<class VectorTypeA , class VectorTypeB > | |
void | line (const VectorTypeA &a, const VectorTypeB &b) |
convenience wrapper for arbitrary types, that provide an index operator [int] | |
void | arrow (float ax, float ay, float bx, float by, float capsize=10) |
draws an arrow from a to b (arrow cap is at b) | |
void | arrow (const utils::Point32f &a, const utils::Point32f &b, float capsize=10) |
draws an arrow from a to b (arrow cap is at b) | |
void | rect (float x, float y, float w, float h) |
draws a rect with given parameters | |
void | rect (const utils::Rect32f &r) |
convenience function for drawing float rects | |
void | rect (const utils::Rect &r) |
draws a rect from a icl utils::Rect structure | |
void | triangle (float x1, float y1, float x2, float y2, float x3, float y3) |
draws a triangle defined by 3 points | |
void | triangle (const utils::Point32f &a, const utils::Point32f &b, const utils::Point32f &c) |
draws a triangle defined by 3 points | |
void | quad (float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) |
draws a quad with given 4 points | |
void | quad (const utils::Point32f &a, const utils::Point32f &b, const utils::Point32f &c, const utils::Point32f &d) |
draws a quad with given 4 points | |
void | ellipse (float x, float y, float w, float h) |
draws an ellipse with given parameters (w==H --> circle) | |
void | ellipse (const utils::Rect &r) |
draws an ellipse into given rectangle | |
void | ellipse (const utils::Rect32f &r) |
draws an ellipse into given rectangle | |
void | circle (float cx, float cy, float r) |
draws a circle with given center and radius | |
void | circle (const utils::Point32f ¢er, float radius) |
draws a circle with given center and radius | |
void | polygon (const std::vector< utils::Point32f > &ps) |
draws a convex polygon | |
void | polygon (const std::vector< utils::Point > &ps) |
draws a convex polygon (int-points) | |
void | grid (const utils::Point32f *points, int nx, int ny, bool rowMajor=true) |
draws a regular grid between given points | |
void | sym (float x, float y, Sym s) |
draws a predefined symbol at the given location | |
void | sym (const utils::Point32f &p, Sym s) |
convenience wrapper for sym(float,float,Sym) | |
void | sym (float x, float y, char sym) |
this is a convenience function for sym(float,float,Sym) | |
void | sym (const utils::Point32f &p, char sym) |
convenicence wrapper for sym(float,flota,char) | |
void | symsize (float w, float h=-1) |
sets the size for following "sym" draw commands | |
void | linewidth (float w) |
sets current linewidth (default is 1); | |
void | pointsize (float s) |
sets current pointsize (default is 1) | |
void | color (float r, float g, float b, float alpha=255) |
sets the draw state machines "edge"-color buffer to a given value | |
void | fill (float r, float g, float b, float alpha=255) |
set the draw state machines "fill"-color buffer to a given value | |
template<class T , unsigned int COLS> | |
void | color (const math::FixedMatrix< T, COLS, 3/COLS > &v) |
utility template method that allows to pass 3D vectors as colors | |
template<class T , unsigned int COLS> | |
void | color (const math::FixedMatrix< T, COLS, 4/COLS > &v) |
utility template method that allows to pass 4D vectors as colors | |
template<class T , unsigned int COLS> | |
void | fill (const math::FixedMatrix< T, COLS, 3/COLS > &v) |
utility template method that allows to pass 3D vectors as fill color | |
template<class T , unsigned int COLS> | |
void | fill (const math::FixedMatrix< T, COLS, 4/COLS > &v) |
utility template method that allows to pass 4D vectors as fill color | |
void | nocolor () |
disables drawing edges | |
void | nofill () |
disables filling primitives | |
void | draw (const utils::VisualizationDescription &d) |
draws a VisualizationDescription instance | |
virtual void | customPaintEvent (PaintEngine *e) |
this function can be reimplemented in derived classes to perform some custom drawing operations | |
virtual void | initializeCustomPaintEvent (PaintEngine *e) |
this function can be reimplemented perform some custom initialization before the actual draw call | |
virtual void | finishCustomPaintEvent (PaintEngine *e) |
this function can be reimplemented perform some custom initialization after the actual draw call | |
Protected Member Functions | |
virtual void | swapQueues () |
swaps the draw queues | |
Protected Attributes | |
std::vector< DrawCommand * > * | m_queues [2] |
two lists of draw commands | |
State * | m_poState |
Data of the "State Machine". | |
QMutex | m_oCommandMutex |
utils::Mutex for a thread save event queue | |
bool | m_autoResetQueue |
internal flag | |
Static Private Member Functions | |
template<class T > | |
static void | icl_given_type_has_no_int_index_operator (const T &t) |
Extended Image visualization widget, with a drawing state machine interface.
The ICLDrawWidget can be used to draw annotation on images in real time. It provides the ability for translating draw command given in image coordinations with respect to the currently used image scaling type (hold-ar, no-scaling or fit to widget) and to the currently used widget size.
Like other drawing state machines, like the QPainter or OpenGL, the ICLDrawWidget can be used for drawing 2D-primitives step by step into the frame-buffer using OpenGL hardware acceleration. Each implementation of drawing function should contain the following steps.
drawWidget->setImage(..);
drawWidget.lock();
drawWidget.reset();
... draw commands ...
drawWidget->unlock(); /// (is deprecated) enable the widget to be drawed
\#include <ICLQt/Common.h> \#include <ICLQt/Quick.h> icl::qt::GUI gui; std::vector<double> c(3,255); // ref color void click(const MouseEvent &e){ if(e.isLeft() && !gui["vis"].as<int>()){ c = e.getColor(); } } void init(){ gui << Draw().handle("draw").minSize(32,24) << (HBox().maxSize(100,3) << Combo("image,levelmap").handle("vis") << Slider(2,10,5).out("levels").label("levels")); gui.show(); gui["draw"].install(new MouseHandler(click)); } void run(){ static GenericGrabber g(pa("-input")); g.setDesiredSizeInternal(utils::Size::VGA); // DrawHandle object draw provides direct access to the underlying // ICLDrawWidget by the 'operator->' i.e., it behaves like // an ICLDrawWidget-pointer DrawHandle draw = gui["draw"]; // do some image processing (pretty slow here) ImgQ im = cvt(g.grab()); // re-quantize grabbed image to reduce levels ImgQ lm = levels(im,gui["levels"].as<int>()); vector<vector<utils::Point> > pxs; pxs.push_back(vector<utils::Point>(1, Point(lm.getWidth()/2, lm.getHeight()/2))); // visualize selected image ImgQ *ims[2] = {&im, &lm}; draw = ims[gui["vis"].as<int>()]; // use drawing state-machine to post draw commands draw->pointsize(2); draw->color(255,0,0,60); draw->points(pxs[0]); } int main(int n, char **ppc){ return ICLApplication(n,ppc,"-input(2)",init,run).exec(); } |
icl::qt::ICLDrawWidget::ICLDrawWidget | ( | QWidget * | parent = 0 | ) |
creates a new ICLDrawWidget embedded into the parent component
destructor2
void icl::qt::ICLDrawWidget::abs | ( | ) |
sets up the state machine to treat coordinates in the image pixel coordinate system
the visualization space is x={0..w-1} and y={0..h-1}
void icl::qt::ICLDrawWidget::arrow | ( | float | ax, |
float | ay, | ||
float | bx, | ||
float | by, | ||
float | capsize = 10 |
||
) |
draws an arrow from a to b (arrow cap is at b)
void icl::qt::ICLDrawWidget::arrow | ( | const utils::Point32f & | a, |
const utils::Point32f & | b, | ||
float | capsize = 10 |
||
) |
draws an arrow from a to b (arrow cap is at b)
void icl::qt::ICLDrawWidget::circle | ( | float | cx, |
float | cy, | ||
float | r | ||
) |
draws a circle with given center and radius
void icl::qt::ICLDrawWidget::circle | ( | const utils::Point32f & | center, |
float | radius | ||
) |
draws a circle with given center and radius
void icl::qt::ICLDrawWidget::color | ( | float | r, |
float | g, | ||
float | b, | ||
float | alpha = 255 |
||
) |
sets the draw state machines "edge"-color buffer to a given value
Primitives except images are drawn with the currently set "color" and filled with the currently set "fill" alpha values of 0 disables the edge drawing at all
void icl::qt::ICLDrawWidget::color | ( | const math::FixedMatrix< T, COLS, 3/COLS > & | v | ) | [inline] |
utility template method that allows to pass 3D vectors as colors
void icl::qt::ICLDrawWidget::color | ( | const math::FixedMatrix< T, COLS, 4/COLS > & | v | ) | [inline] |
utility template method that allows to pass 4D vectors as colors
virtual void icl::qt::ICLDrawWidget::customPaintEvent | ( | PaintEngine * | e | ) | [virtual] |
this function can be reimplemented in derived classes to perform some custom drawing operations
Reimplemented from icl::qt::ICLWidget.
Reimplemented in icl::qt::ICLDrawWidget3D.
void icl::qt::ICLDrawWidget::draw | ( | const utils::VisualizationDescription & | d | ) |
draws a VisualizationDescription instance
Internally, the description is decomposed to normal function calls
void icl::qt::ICLDrawWidget::ellipse | ( | float | x, |
float | y, | ||
float | w, | ||
float | h | ||
) |
draws an ellipse with given parameters (w==H --> circle)
void icl::qt::ICLDrawWidget::ellipse | ( | const utils::Rect & | r | ) |
draws an ellipse into given rectangle
void icl::qt::ICLDrawWidget::ellipse | ( | const utils::Rect32f & | r | ) |
draws an ellipse into given rectangle
void icl::qt::ICLDrawWidget::fill | ( | float | r, |
float | g, | ||
float | b, | ||
float | alpha = 255 |
||
) |
set the draw state machines "fill"-color buffer to a given value
Primitives except images are drawn with the currently set "color" and filled with the currently set "fill" alpha values of 0 disables the edge drawing at all
void icl::qt::ICLDrawWidget::fill | ( | const math::FixedMatrix< T, COLS, 3/COLS > & | v | ) | [inline] |
utility template method that allows to pass 3D vectors as fill color
void icl::qt::ICLDrawWidget::fill | ( | const math::FixedMatrix< T, COLS, 4/COLS > & | v | ) | [inline] |
utility template method that allows to pass 4D vectors as fill color
virtual void icl::qt::ICLDrawWidget::finishCustomPaintEvent | ( | PaintEngine * | e | ) | [virtual] |
this function can be reimplemented perform some custom initialization after the actual draw call
void icl::qt::ICLDrawWidget::grid | ( | const utils::Point32f * | points, |
int | nx, | ||
int | ny, | ||
bool | rowMajor = true |
||
) |
draws a regular grid between given points
static void icl::qt::ICLDrawWidget::icl_given_type_has_no_int_index_operator | ( | const T & | t | ) | [inline, static, private] |
void icl::qt::ICLDrawWidget::image | ( | core::ImgBase * | image, |
float | x, | ||
float | y, | ||
float | w, | ||
float | h | ||
) |
draws an image into the given rectangle
The image is copied by the state machine to ensure, that the data is persistent when the draw command is passed to the underlying PaintEngine. Otherwise, it would not be possible to ensure, that the set image data that is drawn is not changed elsewhere note: If image has four channels, the last channel is used as alpha channel where a pixel value of 0 means invisible=100transparent and 255 means no transparency
void icl::qt::ICLDrawWidget::image | ( | core::ImgBase * | image, |
const utils::Rect & | r | ||
) | [inline] |
convenience function for image using an image rect
void icl::qt::ICLDrawWidget::image | ( | const core::ImgBase * | image, |
const float | a[2], | ||
const float | b[2], | ||
const float | c[2], | ||
const float | d[2] | ||
) |
draws an image into given quadrangle
node order is
a--------b | \ | \ d---___ \ ---___c
virtual void icl::qt::ICLDrawWidget::initializeCustomPaintEvent | ( | PaintEngine * | e | ) | [virtual] |
this function can be reimplemented perform some custom initialization before the actual draw call
void icl::qt::ICLDrawWidget::line | ( | float | x1, |
float | y1, | ||
float | x2, | ||
float | y2 | ||
) |
draws a line from point (x1,y1) to point (x2,y2)
void icl::qt::ICLDrawWidget::line | ( | const utils::Point32f & | a, |
const utils::Point32f & | b | ||
) |
convenience function for drawing lines between two points
void icl::qt::ICLDrawWidget::line | ( | const VectorTypeA & | a, |
const VectorTypeB & | b | ||
) | [inline] |
convenience wrapper for arbitrary types, that provide an index operator [int]
void icl::qt::ICLDrawWidget::linestrip | ( | const std::vector< utils::Point > & | pts, |
bool | closeLoop = true , |
||
int | xfac = 1 , |
||
int | yfac = 1 |
||
) |
draws a set of connected points
for relative utils::Point coordinates the factors can be set point i is drawn at pts[i].x/xfac and pts[i].y/yfac
void icl::qt::ICLDrawWidget::linestrip | ( | const std::vector< utils::Point32f > & | pts, |
bool | closeLoop = true |
||
) |
draws a set of connected points
void icl::qt::ICLDrawWidget::linewidth | ( | float | w | ) |
sets current linewidth (default is 1);
Reimplemented in icl::geom::PlotWidget3D.
void icl::qt::ICLDrawWidget::nocolor | ( | ) |
disables drawing edges
Reimplemented in icl::geom::PlotWidget3D.
void icl::qt::ICLDrawWidget::nofill | ( | ) |
disables filling primitives
Reimplemented in icl::geom::PlotWidget3D.
void icl::qt::ICLDrawWidget::point | ( | float | x, |
float | y | ||
) |
draws a point at the given location
void icl::qt::ICLDrawWidget::point | ( | const utils::Point & | p | ) | [inline] |
convenience wrapper for utils::Point types
void icl::qt::ICLDrawWidget::point | ( | const utils::Point32f & | p | ) | [inline] |
convenience wrapper for utils::Point32f types
void icl::qt::ICLDrawWidget::point | ( | const VectorType & | p | ) | [inline] |
convenience wrapper for arbitrary types, that provide an index operator [int]
void icl::qt::ICLDrawWidget::point | ( | const std::vector< VectorType > & | points | ) | [inline] |
convenience wrapper for arbitrary types, that provide an index operator [int]
void icl::qt::ICLDrawWidget::points | ( | const std::vector< utils::Point > & | pts, |
int | xfac = 1 , |
||
int | yfac = 1 |
||
) |
draws a set of points
for relative utils::Point coordinates the factors can be set point i is drawn at pts[i].x/xfac and pts[i].y/yfac
void icl::qt::ICLDrawWidget::points | ( | const std::vector< utils::Point32f > & | pts | ) |
draws a set of points
void icl::qt::ICLDrawWidget::pointsize | ( | float | s | ) |
sets current pointsize (default is 1)
Reimplemented in icl::geom::PlotWidget3D.
void icl::qt::ICLDrawWidget::polygon | ( | const std::vector< utils::Point32f > & | ps | ) |
draws a convex polygon
void icl::qt::ICLDrawWidget::polygon | ( | const std::vector< utils::Point > & | ps | ) |
draws a convex polygon (int-points)
void icl::qt::ICLDrawWidget::quad | ( | float | x1, |
float | y1, | ||
float | x2, | ||
float | y2, | ||
float | x3, | ||
float | y3, | ||
float | x4, | ||
float | y4 | ||
) |
draws a quad with given 4 points
void icl::qt::ICLDrawWidget::quad | ( | const utils::Point32f & | a, |
const utils::Point32f & | b, | ||
const utils::Point32f & | c, | ||
const utils::Point32f & | d | ||
) |
draws a quad with given 4 points
void icl::qt::ICLDrawWidget::rect | ( | float | x, |
float | y, | ||
float | w, | ||
float | h | ||
) |
draws a rect with given parameters
void icl::qt::ICLDrawWidget::rect | ( | const utils::Rect32f & | r | ) |
convenience function for drawing float rects
void icl::qt::ICLDrawWidget::rect | ( | const utils::Rect & | r | ) |
draws a rect from a icl utils::Rect structure
void icl::qt::ICLDrawWidget::rel | ( | ) |
sets up the state machine to receive relative coordinates in range [0,1]
void icl::qt::ICLDrawWidget::resetQueue | ( | ) |
clears the current draw queue
This is done automatically by default. Only if the user wants accumulative draw commands, resetQueue can be called manually to clear the queues
void icl::qt::ICLDrawWidget::setAutoResetQueue | ( | bool | on | ) |
sets whether the draw commands are accumulative (default is on=true)
If the "auto reset queue" flag is set to false, the internal draw command queues are not cleared when ICLWidget::render() is called. In this case, ICLDrawWidget::resetQueue can be called manually.
virtual void icl::qt::ICLDrawWidget::swapQueues | ( | ) | [protected, virtual] |
swaps the draw queues
Reimplemented from icl::qt::ICLWidget.
void icl::qt::ICLDrawWidget::sym | ( | float | x, |
float | y, | ||
Sym | s | ||
) |
draws a predefined symbol at the given location
The symbols size can be set using symsize
void icl::qt::ICLDrawWidget::sym | ( | const utils::Point32f & | p, |
Sym | s | ||
) | [inline] |
convenience wrapper for sym(float,float,Sym)
void icl::qt::ICLDrawWidget::sym | ( | float | x, |
float | y, | ||
char | sym | ||
) | [inline] |
this is a convenience function for sym(float,float,Sym)
possible values for sym are:
instead of writing
draw->sym(x,y,ICLDrawWidget::symPlus)
you can simply write
draw->sym(x,y,'+')
for all invalid chars, 'x' is used
void icl::qt::ICLDrawWidget::sym | ( | const utils::Point32f & | p, |
char | sym | ||
) | [inline] |
convenicence wrapper for sym(float,flota,char)
void icl::qt::ICLDrawWidget::symsize | ( | float | w, |
float | h = -1 |
||
) |
sets the size for following "sym" draw commands
void icl::qt::ICLDrawWidget::text | ( | std::string | text, |
float | x, | ||
float | y, | ||
float | w, | ||
float | h, | ||
float | fontsize = 10 |
||
) |
draws a string into the given rect
if w=-1 and h=-1, fontsize is used to determine the bitmap size. The given fontsize paramter defines the font-size in screen pixels. Important: if the given fontsize is negative, its absolute value is used but the font size unit is image pixels instead of screen-pixels
void icl::qt::ICLDrawWidget::text | ( | const std::string & | text, |
float | x, | ||
float | y, | ||
float | fontsize = 10 |
||
) | [inline] |
draws text at given x, y location with given fontsize
void icl::qt::ICLDrawWidget::text | ( | const std::string & | text, |
const utils::Point32f & | p, | ||
float | fontsize = 10 |
||
) | [inline] |
draws the text at given position p
void icl::qt::ICLDrawWidget::triangle | ( | float | x1, |
float | y1, | ||
float | x2, | ||
float | y2, | ||
float | x3, | ||
float | y3 | ||
) |
draws a triangle defined by 3 points
void icl::qt::ICLDrawWidget::triangle | ( | const utils::Point32f & | a, |
const utils::Point32f & | b, | ||
const utils::Point32f & | c | ||
) |
draws a triangle defined by 3 points
bool icl::qt::ICLDrawWidget::m_autoResetQueue [protected] |
internal flag
QMutex icl::qt::ICLDrawWidget::m_oCommandMutex [protected] |
utils::Mutex for a thread save event queue
State* icl::qt::ICLDrawWidget::m_poState [protected] |
Data of the "State Machine".
std::vector<DrawCommand*>* icl::qt::ICLDrawWidget::m_queues[2] [protected] |
two lists of draw commands
queues[0] is filled, queues[1] is drawn