rock_widget_collection  0.1
Public Types | Public Slots | Signals | Public Member Functions | Protected Member Functions | Properties | List of all members
ImageView Class Reference

Image viewer with optional text and geometry overlay functionality. More...

#include <ImageView.h>

Inherits QWidget.

Public Types

enum  TextLocation { TOPLEFT, TOPRIGHT, BOTTOMLEFT, BOTTOMRIGHT }
 Text overlay alignment specification. More...
 

Public Slots

const QColor & getBackgroundColor () const
 
void setBackgroundColor (const QColor &color)
 
bool useProgressIndicator ()
 
void setUseProgressIndicator (bool use)
 
bool useSmoothTransformation ()
 
void setSmoothTransformation (bool smooth)
 
const int getProgressIndicatorTimeout () const
 
void setProgressIndicatorTimeout (int timeout)
 
void setInvertColor (bool invert)
 
bool getInvertColor ()
 

Signals

void clickedImage (const QPoint &point)
 Mouse click coordinates in image. More...
 

Public Member Functions

 ImageView (QWidget *parent=0)
 
virtual ~ImageView ()
 
QSize sizeHint () const
 
void setRgbSwapped (bool swapped)
 
bool getRgbSwapped ()
 
void addCircle (QPointF &center, double radius, QColor &color, int width, bool persistent=0)
 Draws circle overlay. More...
 
void addLine (QLineF &line, QColor &color, int width, bool persistent=0)
 Draws line overlay. More...
 
void addPolygon (QPolygonF &polygon, QColor &color, int width, bool persistent=0)
 Draws polygon overlay. More...
 
void addPoints (const QList< int > points_x, QList< int > points_y, QColor &color, int width, bool persistent=0)
 Draws points overlay (2D point cloud). More...
 
void addText (QString text, int location, QColor color=QColor(Qt::black), bool persistent=0)
 Draws text overlay. More...
 
void clearOverlays (bool clear_persistent_items=0)
 Removes overlays. More...
 
void rotate (int deg)
 Rotates image display. More...
 
void saveImage (QString path=QString(), bool overlay=0)
 Saves current image to file. More...
 
void setFrame (const base::samples::DistanceImage &frame)
 Frame input. More...
 
void setFrame (const base::samples::frame::Frame &frame)
 
void setImage (const QImage &image)
 
void setRawImage (const QString &mode, int pixel_size, int width, int height, const char *pbuffer, const int size)
 
void refresh ()
 
void processImage ()
 
void update2 ()
 Wrapper for QWidget::update(). This is due to some QtRuby limitations. More...
 
int getHeight () const
 returns the real height of the underlaying widget More...
 
int getWidth () const
 returns the real width of the underlaying widget More...
 

Protected Member Functions

void resizeEvent (QResizeEvent *event)
 
void contextMenuEvent (QContextMenuEvent *event)
 
bool eventFilter (QObject *obj, QEvent *event)
 

Properties

QColor backgroundColor
 The widget's background color. More...
 
bool use_progress_indicator
 Display progress indicator widget if no frames have being received for a defined time. More...
 
int progress_indicator_timeout
 The time without frame update in ms after which the progress indicator gets started. More...
 
bool use_smooth_transformation
 Usage of antialiasing techniques during image transformation. More...
 
bool rgb_swapped
 
bool invert_color
 

Detailed Description

Image viewer with optional text and geometry overlay functionality.

ImageView is designed to display image frames, do minor transformation on the image or enhance it with several possible overlays. The image is always displayed completely while keeping its aspect ratio.

Transformation means resizing and rotation by 90 degree steps. The transformation is only applied to the displayed image and is not kept in saved (exported) images.

There are multiple overlay possibilities to choose from like simple geometric forms or text. Except for text overlays, every overlay is attatched to the image, i.e. any transformation the image might receive is going to be executed on the overlay as well. For example: The overlays are immune to image rotation or scaling. They simple get scaled and rotated as well. Text overlays, on the other hand, are considered as status information. They are attatched to the widget and do not care about image transformation. Nevertheless, they react to widget transformation, e.g. they keep their alignment to the assigned widget corner.

Overlays – image- or widget attatched – may be set persistent or volatile. Volatile overlays are being removed with the next frame update while persistent overlays stay until you remove them. Currently, you can only remove all (persistent) overlays at once.

It is planned to extend ImageView to work as GStreamer video sink in a future version.

Author
Allan Conquest (allan.conquest[at]dfki.de)

Definition at line 47 of file ImageView.h.

Member Enumeration Documentation

◆ TextLocation

Text overlay alignment specification.

The alignment is relative to the corners of the widget (not to the image!).

Enumerator
TOPLEFT 
TOPRIGHT 
BOTTOMLEFT 
BOTTOMRIGHT 

Definition at line 110 of file ImageView.h.

Constructor & Destructor Documentation

◆ ImageView()

ImageView::ImageView ( QWidget *  parent = 0)

Definition at line 24 of file ImageView.cc.

25  : QWidget(parent),
26  bgColor(QColor(Qt::black)),
30  rgb_swapped(false),
31  invert_color(false),
32  progress_indicator_timer(this),
33  context_menu(this),
34  rotate_image_clockwise_act(this),
35  save_image_act(this),
36  save_image_overlay_act(this),
37  activate_progress_indicator_act(this),
38  rgb_swapped_act(this),
39  invert_color_act(this)
40 #ifdef USE_GST
41  ,
42  pipelineDescription("videotestsrc ! ximagesink"), //qtglvideosink
43  use_gl(false)
44 #endif
45 {
46  setWindowTitle("ImageView");
47  setMinimumSize(220,170);
48  setContentsMargins(0,0,0,0);
49 
50  imageItem = NULL;
51 
52  /* Configure progress indicator */
53  progress_indicator.setAnimationDelay(40);
54  progress_indicator.setDisplayedWhenStopped(false);
55  progress_indicator.resize(30,30);
56  progress_indicator.hide();
57 
58  /* Set up timer for progress indicator */
59  progress_indicator_timer.setInterval(getProgressIndicatorTimeout());
60  connect(&progress_indicator_timer, SIGNAL(timeout()), this, SLOT(startProgressIndicator()));
61 
62  setupContextMenu();
63 
64 #ifdef USE_GST
65  QGst::PipelinePtr pipeline;
66  QGst::ElementPtr videoSrc;
67  /* GStreamer setup */
68  QGst::init();
69 
70 // pipeline = QGst::Parse::launch(pipelineDescription).dynamicCast<QGst::Pipeline>();
71  pipeline = QGst::Pipeline::create("pipeline"); // Create hard coded pipeline for debugging
72  videoSrc = QGst::ElementFactory::make("videotestsrc");
73 #endif
74 
75  /* Setup inner graphicsscene and view. This scene contains the image and image related overlays. */
76  imageScene = new QGraphicsScene(this);
77  imageScene->setBackgroundBrush(getBackgroundColor());
78  imageScene->installEventFilter(this); // to get mouse press events to emit clicked image coordinate
79 
80  imageView = new QGraphicsView(imageScene);
81  imageView->setAlignment(Qt::AlignCenter);
82  imageView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
83  imageView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
84  imageView->setFocusPolicy(Qt::NoFocus);
85  imageView->setFrameStyle(QFrame::NoFrame);
86  imageView->setContentsMargins(0,0,0,0);
87 
88 #ifdef USE_GST
89  if(use_gl) {
90  // Indicator to use qtglvideosink (hardware rendering!) instead of qtvideosink
91  imageView->setViewport(new QGLWidget);
92  }
93 
94  QGst::Ui::GraphicsVideoSurface *surface = NULL;
95  QGst::Ui::GraphicsVideoWidget *widget = NULL;
96 
97  surface = new QGst::Ui::GraphicsVideoSurface(view);
98  widget = new QGst::Ui::GraphicsVideoWidget;
99  widget->setSurface(surface);
100 
101  scene->addItem(widget);
102 
103  // Connect hard coded pipeline
104  pipeline->add(videoSrc, surface->videoSink());
105  videoSrc->link(surface->videoSink());
106 
107  LOG_INFO_S << "Video source name: " << surface->videoSink()->property("name").toString().toStdString();
108 
109  /* Try to start playing */
110  if(!pipeline->setState(QGst::StatePlaying)) {
111  // TODO proper fallback handling
112  LOG_WARN("Could not play pipeline.");
113  }
114 #else
115  imageItem = new QGraphicsPixmapItem;
116 
118 
119  imageScene->addItem(imageItem);
120 #endif
121 
122  /* Setup outer graphicsscene and view. This scene contains fixed overlays like the
123  * image timestamp which are immune to rotation etc. i.e. they stay at the same place
124  * nevertheless the inner scene gets rotated or scaled.
125  */
126  fixedOverlayScene = new QGraphicsScene(this);
127  fixedOverlayScene->setBackgroundBrush(Qt::transparent);
128 
129  fixedOverlayView = new QGraphicsView(fixedOverlayScene, this);
130  fixedOverlayView->setAlignment(Qt::AlignCenter);
131  fixedOverlayView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
132  fixedOverlayView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
133  fixedOverlayView->setFocusPolicy(Qt::NoFocus);
134  fixedOverlayView->setFrameStyle(QFrame::NoFrame);
135  fixedOverlayView->setContentsMargins(0,0,0,0);
136 
137  /* Layout for outer scene to help positioning text overlay */
138  overlay_grid = new QGraphicsGridLayout;
139 
140  /* XXX Transparent middle item with variable size (default). This snaps the border items to the border.
141  * TODO That seems to eliminate the possibility of a middle widget with fixed size.
142  */
143  QGraphicsWidget *label_mi = fixedOverlayScene->addWidget(new QLabel);
144  QPalette label_mi_pal;
145  label_mi_pal.setColor(QPalette::Window, QColor(Qt::transparent));
146  //label_mi_pal.setColor(QPalette::Window, QColor(Qt::white));
147  label_mi->setPalette(label_mi_pal);
148  label_mi->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
149  overlay_grid->addItem(label_mi, 1, 1, Qt::AlignVCenter|Qt::AlignCenter);
150 
151  overlayWidget = new ContextMenuGraphicsWidget;//new QGraphicsWidget;
152  connect(overlayWidget, SIGNAL(contextMenuRequest(QPoint)), this, SLOT(displayContextMenu(QPoint)));
153 
154  overlayWidget->setLayout(overlay_grid);
155  overlayWidget->setZValue(12);
156  fixedOverlayScene->addItem(overlayWidget);
157 
158  // Nest inner view in outer scene
159  imageViewProxy = fixedOverlayScene->addWidget(imageView);
160 
161  progress_indicator.setParent(fixedOverlayView);
162 
163  setItemPositions();
164  update();
165 }
const QColor & getBackgroundColor() const
Definition: ImageView.cc:176
const int getProgressIndicatorTimeout() const
Definition: ImageView.cc:224
bool invert_color
Definition: ImageView.h:80
void setAnimationDelay(int delay)
bool use_progress_indicator
Display progress indicator widget if no frames have being received for a defined time.
Definition: ImageView.h:65
void setSmoothTransformation(bool smooth)
Definition: ImageView.cc:215
bool use_smooth_transformation
Usage of antialiasing techniques during image transformation.
Definition: ImageView.h:77
void setDisplayedWhenStopped(bool state)
int progress_indicator_timeout
The time without frame update in ms after which the progress indicator gets started.
Definition: ImageView.h:68
bool rgb_swapped
Definition: ImageView.h:79

◆ ~ImageView()

ImageView::~ImageView ( )
virtual

Definition at line 167 of file ImageView.cc.

168 {
169 }

Member Function Documentation

◆ addCircle()

void ImageView::addCircle ( QPointF &  center,
double  radius,
QColor &  color,
int  width,
bool  persistent = 0 
)

Draws circle overlay.

Draws a circle overlay with center point center and radius radius. The position has to be submitted in image coordinates with origin in the top left corner.

Parameters
widthpen width
persistentIf false, the overlay gets deleted with the next frame update. Otherwise not.

Definition at line 257 of file ImageView.cc.

258 {
259  QGraphicsEllipseItem *circlePtr =
260  new QGraphicsEllipseItem(QRectF(center.x() - radius/2.0, center.y() - radius/2.0, radius, radius));
261  QPen pen;
262  pen.setColor(color);
263  pen.setWidth(width);
264  circlePtr->setPen(pen);
265 
266  addDrawItem(imageScene, circlePtr, persistent);
267 }

◆ addLine()

void ImageView::addLine ( QLineF &  line,
QColor &  color,
int  width,
bool  persistent = 0 
)

Draws line overlay.

Draws a line overlay. The line is specified in line. The position has to be submitted in image coordinates with origin in the top left corner.

Parameters
widthpen width
persistentIf false, the overlay gets deleted with the next frame update. Otherwise not.

Definition at line 269 of file ImageView.cc.

270 {
271  QGraphicsLineItem *linePtr = new QGraphicsLineItem(line);
272  QPen pen;
273  pen.setColor(color);
274  pen.setWidth(width);
275  linePtr->setPen(pen);
276 
277  addDrawItem(imageScene, linePtr, persistent);
278 }

◆ addPoints()

void ImageView::addPoints ( const QList< int >  points_x,
QList< int >  points_y,
QColor &  color,
int  width,
bool  persistent = 0 
)

Draws points overlay (2D point cloud).

Draws a points overlay. This is to be understood as a 2D point cloud. The position has to be submitted in image coordinates with origin in the top left corner. Since QtRuby has problems with QList<QPoint> slot signatures, this method uses two lists: one for the x-coordinates and one for the y-coordinates.

Example:
You want to draw the pointcloud {(3,4),(6,8)}. Therefore you have to submit
points_x : {3,6}
points_y : {4,8}

Parameters
widthpen width
persistentIf false, the overlay gets deleted with the next frame update. Otherwise not.

Definition at line 280 of file ImageView.cc.

281 {
282  QList<QPoint> points;
283  QList<int>::const_iterator iter1 = points_x.begin();
284  QList<int>::const_iterator iter2 = points_y.begin();
285  for(;iter1 != points_x.end() && iter2 != points_y.end();++iter1,++iter2)
286  {
287  points.push_back(QPoint(*iter1,*iter2));
288  }
289 
290  GraphicsPointsItem *pointsPtr = new GraphicsPointsItem(points);
291  QPen pen;
292  pen.setColor(color);
293  pen.setWidth(width);
294  pointsPtr->setPen(pen);
295 
296  addDrawItem(imageScene, pointsPtr, persistent);
297 }
void setPen(const QPen &pen)

◆ addPolygon()

void ImageView::addPolygon ( QPolygonF &  polygon,
QColor &  color,
int  width,
bool  persistent = 0 
)

Draws polygon overlay.

Draws a polygon overlay. The polygon is specified in line. The position has to be submitted in image coordinates with origin in the top left corner.

Parameters
widthpen width
persistentIf false, the overlay gets deleted with the next frame update. Otherwise not.

Definition at line 299 of file ImageView.cc.

300 {
301  LOG_DEBUG_S << "Received polygon. Polygon closed: " << polygon.isClosed();
302  LOG_DEBUG_S << "The polygon has a size of " << polygon.size() << ".";
303  QGraphicsPolygonItem *polygonPtr = new QGraphicsPolygonItem(polygon);
304  QPen pen;
305  pen.setColor(color);
306  pen.setWidth(width);
307  polygonPtr->setPen(pen);
308 
309  addDrawItem(imageScene, polygonPtr, persistent);
310 }

◆ addText()

void ImageView::addText ( QString  text,
int  location,
QColor  color = QColor(Qt::black),
bool  persistent = 0 
)

Draws text overlay.

Draws a text overlay. The text is immune to image transformation, i.e. rotation or scaling. The text is in monospace style. You can align the text to the corners.

Parameters
locationText alignment to the corners. The location value is analogous to the TextLocation enum. This is an intermediate solution until we find a way to use the QtRuby binding for enums. For convenience from the ruby side, you can use a wrapper method using symbols. This method is defined in the Vizkit C++ Extensions in image_view_widget.rb.
persistentIf false, the overlay gets deleted with the next frame update. Otherwise not.
See also
TextLocation

Definition at line 312 of file ImageView.cc.

313 {
314  /* Positioning */
315  int row = 0;
316  int col = 0;
317  Qt::Alignment alignment = Qt::AlignLeft;
318 
319  switch(location) {
320  case TOPLEFT :
321  row = 0;
322  col = 0;
323  alignment = Qt::AlignTop|Qt::AlignLeft;
324  break;
325  case TOPRIGHT :
326  row = 0;
327  col = 2;
328  alignment = Qt::AlignTop|Qt::AlignRight;
329  break;
330  case BOTTOMLEFT :
331  row = 2;
332  col = 0;
333  alignment = Qt::AlignBottom|Qt::AlignLeft;
334  break;
335  case BOTTOMRIGHT :
336  row = 2;
337  col = 2;
338  alignment = Qt::AlignBottom|Qt::AlignRight;
339  break;
340  default:
341  LOG_WARN("Unsupported text location. Switching to TOPLEFT.");
342  addText(text, TOPLEFT, persistent);
343  return;
344  }
345 
346  QLabel *label = NULL;
347  QGraphicsWidget *textLabel = NULL;
348  int margin = 1;
349 
350  // Avoid displaying empty labels, i.e. labels with margin only and no text
351  if(text.isEmpty()) {
352  margin = 0;
353  }
354 
355  // Label for text location already exists?
356  if(overlayMap.contains(location)) {
357  // Alter existing label
358  label = overlayMap[location];
359  label->setText(text);
360  label->adjustSize();
361  } else {
362  // Add new label to map
363  label = new QLabel(text);
364  label->setVisible(false);
365  label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
366 
367  overlayMap[location] = label;
368 
369  textLabel = fixedOverlayScene->addWidget(label);
370  overlay_grid->addItem(textLabel, row, col, alignment);
371  textLabel->setVisible(true); // TODO use label instead?
372  }
373 
374  QPalette palette;
375  QColor labelBgColor(Qt::white);
376  labelBgColor.setAlphaF(0.7);
377  palette.setColor(QPalette::Window, labelBgColor);
378  palette.setColor(QPalette::WindowText, color);
379  palette.setColor(QPalette::Text, color); // <-- this one seems to be working but WindowText should be correct according to docu
380 
381  label->setPalette(palette);
382  label->setMargin(margin);
383 
384  QFont font("Monospace");
385  font.setPointSize(12);
386  font.setStyleHint(QFont::TypeWriter);
387  label->setFont(font);
388 
389  label->setMaximumSize(label->sizeHint());
390 
391 // std::cout << "label size hint: " << label->sizeHint().width() << "," << label->sizeHint().height() << " ('" << text.toStdString().data() << "')" << std::endl;
392 // std::cout << "label size: " << label->width() << "," << label->height() << " ('" << text.toStdString().data() << "')" << std::endl;
393 // std::cout << "label maximum size: " << label->maximumSize().width() << "," << label->maximumSize().height() << " ('" << text.toStdString().data() << "')" << std::endl;
394 // std::cout << "---" << std::endl;
395 
396  overlay_grid->invalidate();
397  //addDrawItem(NULL, textLabel, persistent); // TODO check correctness of deletion etc.
398  update();
399 }
void addText(QString text, int location, QColor color=QColor(Qt::black), bool persistent=0)
Draws text overlay.
Definition: ImageView.cc:312
Definition: DrawItem.h:19

◆ clearOverlays()

void ImageView::clearOverlays ( bool  clear_persistent_items = 0)

Removes overlays.

Parameters
persistentIf true, removes also persistent overlays. Otherwise not.

Definition at line 401 of file ImageView.cc.

402 {
403  if(clear_persistent_items) {
404  Q_FOREACH(QGraphicsItem *item, persistentDrawItems) {
405  item->scene()->removeItem(item);
406  }
407  persistentDrawItems.clear();
408  }
409 
410  Q_FOREACH(QGraphicsItem *item, volatileDrawItems) {
411  item->scene()->removeItem(item);
412  }
413  volatileDrawItems.clear();
414 }

◆ clickedImage

void ImageView::clickedImage ( const QPoint &  point)
signal

Mouse click coordinates in image.

Gets emitted if the image receives a mouse click event. The position is in image coordinates where the origin is in the top-left corner.

◆ contextMenuEvent()

void ImageView::contextMenuEvent ( QContextMenuEvent *  event)
protected

Definition at line 591 of file ImageView.cc.

592 {
593  context_menu.exec(event->globalPos());
594 }

◆ eventFilter()

bool ImageView::eventFilter ( QObject *  obj,
QEvent *  event 
)
protected

Definition at line 596 of file ImageView.cc.

597 {
598  //std::cout << "Got an event: " << event->type() << std::endl;
599 
600  if (event->type() == QEvent::GraphicsSceneMousePress) {
601  QGraphicsSceneMouseEvent *mouseEvent = static_cast<QGraphicsSceneMouseEvent *>(event);
602 
603  QPoint scenePos = mouseEvent->scenePos().toPoint();
604 
605  // Clicked on image scene?
606  if(imageScene->sceneRect().contains(scenePos)) {
607  LOG_INFO_S << "Clicked at image coordinate (w,h) (" << scenePos.x() << "," << scenePos.y() << ")";
608  emit clickedImage(scenePos);
609  }
610 
611  return true;
612  } else {
613  // standard event processing
614  return QObject::eventFilter(obj, event);
615  }
616 }
void clickedImage(const QPoint &point)
Mouse click coordinates in image.

◆ getBackgroundColor

const QColor & ImageView::getBackgroundColor ( ) const
slot

Definition at line 176 of file ImageView.cc.

177 {
178  return bgColor;
179 }

◆ getHeight()

int ImageView::getHeight ( ) const

returns the real height of the underlaying widget

Definition at line 679 of file ImageView.cc.

680 {
681  return imageSize.height();
682 }

◆ getInvertColor

bool ImageView::getInvertColor ( )
inlineslot

Definition at line 132 of file ImageView.h.

132 {return invert_color;};
bool invert_color
Definition: ImageView.h:80

◆ getProgressIndicatorTimeout

const int ImageView::getProgressIndicatorTimeout ( ) const
slot

Definition at line 224 of file ImageView.cc.

225 {
227 }
int progress_indicator_timeout
The time without frame update in ms after which the progress indicator gets started.
Definition: ImageView.h:68

◆ getRgbSwapped()

bool ImageView::getRgbSwapped ( )
inline

Definition at line 134 of file ImageView.h.

134 {return rgb_swapped;};
bool rgb_swapped
Definition: ImageView.h:79

◆ getWidth()

int ImageView::getWidth ( ) const

returns the real width of the underlaying widget

Definition at line 684 of file ImageView.cc.

685 {
686  return imageSize.width();
687 }

◆ processImage()

void ImageView::processImage ( )

Definition at line 507 of file ImageView.cc.

508 {
509  if(getInvertColor())
510  image.invertPixels();
511  if(getRgbSwapped())
512  image = image.rgbSwapped();
513 }
bool getRgbSwapped()
Definition: ImageView.h:134
bool getInvertColor()
Definition: ImageView.h:132

◆ refresh()

void ImageView::refresh ( )

Definition at line 515 of file ImageView.cc.

516 {
518  progress_indicator.hide();
519  progress_indicator_timer.start();
520  progress_indicator.stopAnimation();
521  }
522 
523 #ifdef USE_GST
524  // TODO
525 #else
526  clearOverlays();
527 
528  // Backup image size for detecting size change
529  QSize oldSize = imageSize;
530  imageSize = image.size();
531  //std::cout << "Image size: x=" << image.width() <<", y=" << image.height() << std::endl;
532  QPixmap pixmap = QPixmap::fromImage(image);
533  pixmap.scaled(size(), Qt::KeepAspectRatio);
534 
535  //std::cout << "Pixmap size: x=" << pixmap.width() <<", y=" << pixmap.height() << std::endl;
536  if(imageItem) {
537  imageItem->setPixmap(pixmap);
538  } else {
539  LOG_WARN("imageItem undefined!");
540  }
541 
542  //std::cout << "ImageItem BoundingRect: x=" << imageItem->boundingRect().width() <<", y=" << imageItem->boundingRect().height() << std::endl;
543 
544  /* Resize and repositioning if frame size changes (and on start) */
545  if(imageSize != oldSize) {
546  LOG_INFO("image size changed. resize.");
547 
548  // Avoid dynamic scene growth
549  imageScene->setSceneRect(0, 0, imageSize.width(), imageSize.height());
550 
551  setItemPositions();
552 
553  /* For some reason the first frame is not scaled to fit the full space.
554  * Calling update or even repaint did not help but a simple resize or
555  * setVisible does. On Debian, you have to call both ???
556  */
557  setVisible(false); setVisible(true);
558  resize(width(),height()-1);
559  resize(width(),height()+1);
560  }
561  update();
562 #endif
563 }
bool use_progress_indicator
Display progress indicator widget if no frames have being received for a defined time.
Definition: ImageView.h:65
void clearOverlays(bool clear_persistent_items=0)
Removes overlays.
Definition: ImageView.cc:401

◆ resizeEvent()

void ImageView::resizeEvent ( QResizeEvent *  event)
protected

Definition at line 567 of file ImageView.cc.

568 {
569  QWidget::resizeEvent(event);
570 
571  //fixedOverlayScene->setSceneRect(fixedOverlayScene->itemsBoundingRect());
572  QSize eventSize = event->size();
573  fixedOverlayScene->setSceneRect(0, 0, eventSize.width(), eventSize.height());
574  imageView->resize(eventSize);
575 
576 
577 // std::cout << "resize event.\nview.width: " << view->width() << "\n"
578 // << "view.height: " << view->height() << std::endl;
579 
580  imageView->fitInView(imageItem, Qt::KeepAspectRatio);
581 
582 
583  fixedOverlayView->resize(eventSize);
584  overlayWidget->resize(eventSize);
585  setItemPositions();
586  LOG_DEBUG_S << "scene dimensions:\n"
587  << "fixedOverlayScene (w/h): (" << fixedOverlayScene->width() << "," << fixedOverlayScene->height() << ")\n"
588  << "imageScene (w/h): (" << imageScene->width() << "," << imageScene->height() << ")\n";
589 }

◆ rotate()

void ImageView::rotate ( int  deg)

Rotates image display.

Rotates the image display about deg degrees. The image gets fit into the widget by keeping its aspect ratio.

Definition at line 416 of file ImageView.cc.

417 {
418  imageView->rotate(deg);
419  imageView->fitInView(imageItem, Qt::KeepAspectRatio);
420  //view->fitInView(view->sceneRect(), Qt::KeepAspectRatio);
421 }

◆ saveImage()

void ImageView::saveImage ( QString  path = QString(),
bool  overlay = 0 
)

Saves current image to file.

The saved image is either the plain original image or said image with overlays (depending on overlay). The saved image size is always the size of the original image.

Parameters
pathSave destination. If not submitted, a file chooser dialog is presented.
overlaySaves overlays, too if set to true. Otherwise only the image is being saved.

Definition at line 423 of file ImageView.cc.

424 {
425  QImage saveImage(imageScene->sceneRect().size().toSize(), image.format());
426  saveImage.fill(0); // Painter cannnot handle null image
427 
428  /* Get destination path if not submitted */
429  if(path.isEmpty()) {
430  path = QFileDialog::getSaveFileName(this, "Save Image",
431  last_path,
432  "Images (*.png)");
433  last_path = path;
434  }
435 
436  /* Save original image or also the overlay? */
437  if(overlay) {
438  QPainter painter(&saveImage);
439 
440  // Render image and image overlays first
441  imageScene->render(&painter);
442 
443  QSize oldSize = size();
444  QSize newSize = imageScene->sceneRect().size().toSize();
445 
446  // Hide image view from outer scene. It is already painted.
447  imageViewProxy->hide();
448 
449  fixedOverlayScene->setSceneRect(imageScene->sceneRect());
450  overlayWidget->resize(newSize);
451 
452  // Render outer scene (text overlays) on top
453  fixedOverlayScene->render(&painter);
454 
455  imageViewProxy->show();
456 
457  // restore old sizes
458  resize(oldSize.width(),oldSize.height()+1);
459  resize(oldSize.width(),oldSize.height()-1);
460  } else {
461  saveImage = image;
462  }
463 
464  saveImage.save(path, "PNG", 80);
465 }
void saveImage(QString path=QString(), bool overlay=0)
Saves current image to file.
Definition: ImageView.cc:423

◆ setBackgroundColor

void ImageView::setBackgroundColor ( const QColor &  color)
slot

Definition at line 181 of file ImageView.cc.

182 {
183  bgColor = color;
184  imageScene->setBackgroundBrush(bgColor);
185 }

◆ setFrame() [1/2]

void ImageView::setFrame ( const base::samples::DistanceImage &  frame)

Frame input.

Parameters
frameThe image to be displayed next. The display gets updated immediately.

Definition at line 467 of file ImageView.cc.

468 {
469 
470  base::samples::frame::Frame bframe(frame.width,frame.height,16);
471  std::vector<uint16_t> v(frame.data.size());
472  for(unsigned int i=0;i<v.size();i++){
473  v[i] = frame.data[i];
474  }
475 
476  bframe.setImage((uint8_t*)&v[0],frame.data.size()*2);
477  if(1 == frame_converter.copyFrameToQImageRGB888(image,bframe)) {
478  LOG_WARN("Frame size changed while converting frame to QImage (says converter)");
479  }
480  processImage();
481  refresh();
482 }
void refresh()
Definition: ImageView.cc:515
void processImage()
Definition: ImageView.cc:507

◆ setFrame() [2/2]

void ImageView::setFrame ( const base::samples::frame::Frame &  frame)

Definition at line 484 of file ImageView.cc.

485 {
486  if(1 == frame_converter.copyFrameToQImageRGB888(image,frame)) {
487  LOG_WARN("Frame size changed while converting frame to QImage (says converter)");
488  }
489  processImage();
490  refresh();
491 }
void refresh()
Definition: ImageView.cc:515
void processImage()
Definition: ImageView.cc:507

◆ setImage()

void ImageView::setImage ( const QImage &  image)

Definition at line 500 of file ImageView.cc.

501 {
502  this->image = image.copy();
503  processImage();
504  refresh();
505 }
void refresh()
Definition: ImageView.cc:515
void processImage()
Definition: ImageView.cc:507

◆ setInvertColor

void ImageView::setInvertColor ( bool  invert)
slot

Definition at line 689 of file ImageView.cc.

690 {
691  if(invert_color == invert)
692  return;
693  invert_color=invert;
694  image.invertPixels();
695  refresh();
696 }
bool invert_color
Definition: ImageView.h:80
void refresh()
Definition: ImageView.cc:515

◆ setProgressIndicatorTimeout

void ImageView::setProgressIndicatorTimeout ( int  timeout)
slot

Definition at line 229 of file ImageView.cc.

230 {
231  progress_indicator_timeout = timeout;
232  progress_indicator_timer.setInterval(timeout);
233 }
int progress_indicator_timeout
The time without frame update in ms after which the progress indicator gets started.
Definition: ImageView.h:68

◆ setRawImage()

void ImageView::setRawImage ( const QString &  mode,
int  pixel_size,
int  width,
int  height,
const char *  pbuffer,
const int  size 
)

Definition at line 493 of file ImageView.cc.

494 {
495  frame_converter.copyFrameToQImageRGB888(image,mode, pixel_size, width, height,pbuffer,size);
496  processImage();
497  refresh();
498 }
void refresh()
Definition: ImageView.cc:515
void processImage()
Definition: ImageView.cc:507

◆ setRgbSwapped()

void ImageView::setRgbSwapped ( bool  swapped)

Definition at line 697 of file ImageView.cc.

698 {
699  if(rgb_swapped == swapped)
700  return;
701  rgb_swapped=swapped;
702  image = image.rgbSwapped();
703  refresh();
704 }
void refresh()
Definition: ImageView.cc:515
bool rgb_swapped
Definition: ImageView.h:79

◆ setSmoothTransformation

void ImageView::setSmoothTransformation ( bool  smooth)
slot

Definition at line 215 of file ImageView.cc.

216 {
217  use_smooth_transformation = smooth;
218  if(smooth)
219  imageItem->setTransformationMode(Qt::SmoothTransformation);
220  else
221  imageItem->setTransformationMode(Qt::FastTransformation);
222 }
bool use_smooth_transformation
Usage of antialiasing techniques during image transformation.
Definition: ImageView.h:77

◆ setUseProgressIndicator

void ImageView::setUseProgressIndicator ( bool  use)
slot

Definition at line 193 of file ImageView.cc.

194 {
196  progress_indicator.hide();
197 
198  if(use) {
199  progress_indicator_timer.start();
200  // TODO Maybe unwanted behavior since the timer starts even if there is not a single frame yet.
201  // But it is nice if you trigger the use of the progress indicator while the replay is stopped.
202  }
203  else {
204  // Disable possibly already running widget
205  progress_indicator_timer.stop();
206  progress_indicator.stopAnimation();
207  }
208 }
bool use_progress_indicator
Display progress indicator widget if no frames have being received for a defined time.
Definition: ImageView.h:65

◆ sizeHint()

QSize ImageView::sizeHint ( ) const

Definition at line 171 of file ImageView.cc.

172 {
173  return QSize(500,500);
174 }

◆ update2()

void ImageView::update2 ( )

Wrapper for QWidget::update(). This is due to some QtRuby limitations.

Definition at line 667 of file ImageView.cc.

668 {
669  QWidget::update();
670 }

◆ useProgressIndicator

bool ImageView::useProgressIndicator ( )
slot

Definition at line 187 of file ImageView.cc.

188 {
189  return use_progress_indicator;
190 }
bool use_progress_indicator
Display progress indicator widget if no frames have being received for a defined time.
Definition: ImageView.h:65

◆ useSmoothTransformation

bool ImageView::useSmoothTransformation ( )
slot

Definition at line 210 of file ImageView.cc.

211 {
213 }
bool use_smooth_transformation
Usage of antialiasing techniques during image transformation.
Definition: ImageView.h:77

Property Documentation

◆ backgroundColor

QColor ImageView::backgroundColor
readwrite

The widget's background color.

You see the widget's background color in the areas not covered by the image. This is likely to happen because of the keeping of the images aspect ratio while fitting it in the view.

Definition at line 59 of file ImageView.h.

◆ invert_color

bool ImageView::invert_color
readwrite

Definition at line 80 of file ImageView.h.

◆ progress_indicator_timeout

int ImageView::progress_indicator_timeout
readwrite

The time without frame update in ms after which the progress indicator gets started.

Definition at line 68 of file ImageView.h.

◆ rgb_swapped

bool ImageView::rgb_swapped
readwrite

Definition at line 79 of file ImageView.h.

◆ use_progress_indicator

bool ImageView::use_progress_indicator
readwrite

Display progress indicator widget if no frames have being received for a defined time.

See also
ProgressIndicator

Definition at line 65 of file ImageView.h.

◆ use_smooth_transformation

bool ImageView::use_smooth_transformation
readwrite

Usage of antialiasing techniques during image transformation.

Do antialiased transformation by using costly techniques like bilinear filtering. That produces higher CPU load but the displayed image is much smoother. This property only applies to the displayed image - not to the overlays.

Definition at line 77 of file ImageView.h.


The documentation for this class was generated from the following files: