ImageMonitorWidget.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @package ArmarX::
17 * @author Kai Welke ( welke at kit dot edu)
18 * @date 2012
19 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22 
23 #include "ImageMonitorWidget.h"
27 #include "ImageViewerArea.h"
28 
29 using namespace armarx;
30 
31 namespace visionx
32 {
33  // *******************************************************
34  // construction / destruction
35  // *******************************************************
36  ImageMonitorWidget::ImageMonitorWidget(ImageMonitorWidgetController* controller)
37  {
38  qRegisterMetaType<CByteImage**>("CByteImage**");
39 
40  // members
41  this->controller = controller;
42 
43  // ui elements
44  ui.setupUi(this);
45  imageViewer = new ImageViewerArea();
46  QSizePolicy sizePoli(QSizePolicy::Expanding, QSizePolicy::Expanding);
47  sizePoli.setVerticalStretch(15);
48  imageViewer->setSizePolicy(sizePoli);
49  ui.imageViewerLayout->addWidget(imageViewer);
50  imageViewer->show();
51 
52  imageMonitorPropertiesWidget = new ImageMonitorPropertiesWidget();
53  imageMonitorPropertiesWidget->hide();
54 
55  imageMonitorStatisticsWidget = new ImageMonitorStatisticsWidget();
56  imageMonitorStatisticsWidget->hide();
57 
58  // signals and slots
59  connect(ui.settingsButton, SIGNAL(clicked(bool)), this, SLOT(settingsButtonClicked(bool)));
60  connect(ui.statisticsButton, SIGNAL(clicked(bool)), this, SLOT(statisticsButtonClicked(bool)));
61  connect(ui.snapshotButton, SIGNAL(clicked(bool)), this, SLOT(snapshotButtonClicked(bool)));
62  connect(ui.playButton, SIGNAL(toggled(bool)), this, SLOT(playButtonToggled(bool)));
63  connect(ui.cbBufferImages, SIGNAL(toggled(bool)), this, SLOT(bufferImagesToggled(bool)));
64  connect(ui.sliderImageBuffer, SIGNAL(valueChanged(int)), this, SLOT(sliderPositionChanged(int)));
65  connect(ui.buttonShowBufferImages, SIGNAL(toggled(bool)), this, SLOT(bufferImagesPaneChanged(bool)));
66 
67  connect(imageMonitorPropertiesWidget, SIGNAL(accepted()), this, SLOT(propertiesAccepted()));
68  connect(imageMonitorStatisticsWidget, SIGNAL(accepted()), this, SLOT(statisticsAccepted()));
69 
70  ui.frameImageBuffer->hide();
71 
72  setConnected(false);
73  }
74 
75  ImageMonitorWidget::~ImageMonitorWidget()
76  {
77  delete imageMonitorPropertiesWidget;
78  }
79 
80  void ImageMonitorWidget::drawImages(int numberImages, CByteImage** images, IceUtil::Time imageTimestamp, IceUtil::Time receiveTimestamp)
81  {
82  if (!images)
83  {
84  return;
85  }
86 
87  for (int i = 0; i < numberImages; ++i)
88  {
89  if (!images[i])
90  {
91  return;
92  }
93  }
94 
95  imageViewer->setImages(numberImages, images, imageTimestamp, receiveTimestamp);
96  }
97 
98  void ImageMonitorWidget::hideControlWidgets(bool hide)
99  {
100  ui.controlWidgetsContainer->setVisible(!hide);
101  }
102 
103  // *******************************************************
104  // Qt slots
105  // *******************************************************
106  void ImageMonitorWidget::settingsButtonClicked(bool toggled)
107  {
108  // update the properties dialog
109  imageMonitorPropertiesWidget->update(controller->getProperties(), controller->getIceManager());
110 
111  // display dialog
112  imageMonitorPropertiesWidget->setModal(true);
113  imageMonitorPropertiesWidget->show();
114  }
115 
116  void ImageMonitorWidget::statisticsButtonClicked(bool toggled)
117  {
118  // update the properties dialog
119  imageMonitorStatisticsWidget->update(controller->getProperties().providerName, controller->getImageProviderInfo(), controller->getStatistics());
120 
121  // display dialog
122  imageMonitorStatisticsWidget->setModal(true);
123  imageMonitorStatisticsWidget->show();
124  }
125 
126 
127  void ImageMonitorWidget::propertiesAccepted()
128  {
129  // apply properties to controller
130  controller->applyProperties(imageMonitorPropertiesWidget->getProperties());
131 
132  ui.sliderImageBuffer->setMaximum(imageMonitorPropertiesWidget->getProperties().imageBufferSize);
133  }
134 
135  void ImageMonitorWidget::statisticsAccepted()
136  {
137  }
138 
139  void ImageMonitorWidget::bufferImagesToggled(bool toggled)
140  {
141  controller->setBuffering(toggled);
142 
143  ui.sliderImageBuffer->setEnabled(toggled);
144  }
145 
146  void ImageMonitorWidget::sliderPositionChanged(int pos)
147  {
148  if (ui.playButton->isChecked())
149  {
150  ui.playButton->setChecked(false);
151  }
152 
153  unsigned int realPos = 0;
154  const ImageContainer images = controller->getBufferedImage(pos, realPos);
155  auto imagesToShow = controller->getProperties().imagesToShow;
156 
157  ui.lblSliderPosition->setText(QString::number(realPos + 1) + "/" + QString::number(controller->getBufferedImageCount()));
158 
159  if (images.size() == 0)
160  {
161  return;
162  }
163 
164  std::vector<CByteImage*> selectedImages;
165 
166  for (unsigned int i = 0; i < images.size(); ++i)
167  {
168  if (imagesToShow.size() > 0 && imagesToShow.count(i) == 0)
169  {
170  continue;
171  }
172  if (!images[i].get())
173  {
174  ARMARX_WARNING_S << "No Image in Buffer found!" << std::endl;
175  return;
176  }
177 
178  selectedImages.push_back(images[i].get());
179  }
180  if (selectedImages.size() > 0)
181  {
182  drawImages(selectedImages.size(), &selectedImages[0], IceUtil::Time(), IceUtil::Time());
183  }
184  }
185 
186  void ImageMonitorWidget::bufferImagesPaneChanged(bool toggled)
187  {
188  if (toggled)
189  {
190  ui.buttonShowBufferImages->setArrowType(Qt::DownArrow);
191  }
192  else
193  {
194  ui.buttonShowBufferImages->setArrowType(Qt::LeftArrow);
195  }
196  }
197 
198  ImageViewerArea* ImageMonitorWidget::getImageViewer() const
199  {
200  return imageViewer;
201  }
202 
203  void ImageMonitorWidget::snapshotButtonClicked(bool toggled)
204  {
205  controller->createSnapshot();
206  }
207 
208  void ImageMonitorWidget::playButtonToggled(bool playing)
209  {
210  controller->setPlaying(playing);
211  ui.playButton->setChecked(playing);
212  }
213 
214  void ImageMonitorWidget::setConnected(bool connected)
215  {
216  ui.playButton->setEnabled(connected);
217  ui.statisticsButton->setEnabled(connected);
218  ui.snapshotButton->setEnabled(connected);
219  ui.cbBufferImages->setEnabled(connected);
220 
221  if (!connected) // only disable, enabling is only done in playButtonToggled
222  {
223  ui.sliderImageBuffer->setEnabled(false);
224  }
225  playButtonToggled(connected);
226  }
227 
228  void ImageMonitorWidget::updateStatistics(const QString& statisticsStr)
229  {
230  ui.imageViewerStats->setText(statisticsStr);
231  }
232 
233 }
ImageMonitorWidget.h
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
ImageMonitorStatisticsWidget.h
visionx::ImageViewerArea
Definition: ImageViewerArea.h:38
ImageMonitorWidgetController.h
visionx::ImageMonitorWidgetController
Definition: ImageMonitorWidgetController.h:116
ImageMonitorPropertiesWidget.h
controller
Definition: AddOperation.h:39
ImageViewerArea.h
visionx::ImageMonitorPropertiesWidget
Definition: ImageMonitorPropertiesWidget.h:60
visionx::ImageContainer
std::vector< CByteImagePtr > ImageContainer
Definition: ImageMonitorWidgetController.h:110
ARMARX_WARNING_S
#define ARMARX_WARNING_S
Definition: Logging.h:206
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
visionx::ImageMonitorStatisticsWidget
Definition: ImageMonitorStatisticsWidget.h:33
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28