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"
24
28#include "ImageViewerArea.h"
29
30using namespace armarx;
31
32namespace visionx
33{
34 // *******************************************************
35 // construction / destruction
36 // *******************************************************
38 {
39 qRegisterMetaType<CByteImage**>("CByteImage**");
40
41 // members
42 this->controller = controller;
43
44 // ui elements
45 ui.setupUi(this);
46 imageViewer = new ImageViewerArea();
47 QSizePolicy sizePoli(QSizePolicy::Expanding, QSizePolicy::Expanding);
48 sizePoli.setVerticalStretch(15);
49 imageViewer->setSizePolicy(sizePoli);
50 ui.imageViewerLayout->addWidget(imageViewer);
51 imageViewer->show();
52
53 imageMonitorPropertiesWidget = new ImageMonitorPropertiesWidget();
54 imageMonitorPropertiesWidget->hide();
55
56 imageMonitorStatisticsWidget = new ImageMonitorStatisticsWidget();
57 imageMonitorStatisticsWidget->hide();
58
59 // signals and slots
60 connect(ui.settingsButton, SIGNAL(clicked(bool)), this, SLOT(settingsButtonClicked(bool)));
61 connect(
62 ui.statisticsButton, SIGNAL(clicked(bool)), this, SLOT(statisticsButtonClicked(bool)));
63 connect(ui.snapshotButton, SIGNAL(clicked(bool)), this, SLOT(snapshotButtonClicked(bool)));
64 connect(ui.playButton, SIGNAL(toggled(bool)), this, SLOT(playButtonToggled(bool)));
65 connect(ui.cbBufferImages, SIGNAL(toggled(bool)), this, SLOT(bufferImagesToggled(bool)));
66 connect(ui.sliderImageBuffer,
67 SIGNAL(valueChanged(int)),
68 this,
69 SLOT(sliderPositionChanged(int)));
70 connect(ui.buttonShowBufferImages,
71 SIGNAL(toggled(bool)),
72 this,
73 SLOT(bufferImagesPaneChanged(bool)));
74
75 connect(imageMonitorPropertiesWidget, SIGNAL(accepted()), this, SLOT(propertiesAccepted()));
76 connect(imageMonitorStatisticsWidget, SIGNAL(accepted()), this, SLOT(statisticsAccepted()));
77
78 ui.frameImageBuffer->hide();
79
80 setConnected(false);
81 }
82
84 {
85 delete imageMonitorPropertiesWidget;
86 }
87
88 void
90 CByteImage** images,
91 IceUtil::Time imageTimestamp,
92 IceUtil::Time receiveTimestamp)
93 {
94 if (!images)
95 {
96 return;
97 }
98
99 for (int i = 0; i < numberImages; ++i)
100 {
101 if (!images[i])
102 {
103 return;
104 }
105 }
106
107 imageViewer->setImages(numberImages, images, imageTimestamp, receiveTimestamp);
108 }
109
110 void
112 {
113 ui.controlWidgetsContainer->setVisible(!hide);
114 }
115
116 // *******************************************************
117 // Qt slots
118 // *******************************************************
119 void
121 {
122 // update the properties dialog
123 imageMonitorPropertiesWidget->update(controller->getProperties(),
124 controller->getIceManager());
125
126 // display dialog
127 imageMonitorPropertiesWidget->setModal(true);
128 imageMonitorPropertiesWidget->show();
129 }
130
131 void
133 {
134 // update the properties dialog
135 imageMonitorStatisticsWidget->update(controller->getProperties().providerName,
136 controller->getImageProviderInfo(),
137 controller->getStatistics());
138
139 // display dialog
140 imageMonitorStatisticsWidget->setModal(true);
141 imageMonitorStatisticsWidget->show();
142 }
143
144 void
146 {
147 // apply properties to controller
148 controller->applyProperties(imageMonitorPropertiesWidget->getProperties());
149
150 ui.sliderImageBuffer->setMaximum(
151 imageMonitorPropertiesWidget->getProperties().imageBufferSize);
152 }
153
154 void
158
159 void
161 {
162 controller->setBuffering(toggled);
163
164 ui.sliderImageBuffer->setEnabled(toggled);
165 }
166
167 void
169 {
170 if (ui.playButton->isChecked())
171 {
172 ui.playButton->setChecked(false);
173 }
174
175 unsigned int realPos = 0;
176 const ImageContainer images = controller->getBufferedImage(pos, realPos);
177 auto imagesToShow = controller->getProperties().imagesToShow;
178
179 ui.lblSliderPosition->setText(QString::number(realPos + 1) + "/" +
180 QString::number(controller->getBufferedImageCount()));
181
182 if (images.size() == 0)
183 {
184 return;
185 }
186
187 std::vector<CByteImage*> selectedImages;
188
189 for (unsigned int i = 0; i < images.size(); ++i)
190 {
191 if (imagesToShow.size() > 0 && imagesToShow.count(i) == 0)
192 {
193 continue;
194 }
195 if (!images[i].get())
196 {
197 ARMARX_WARNING_S << "No Image in Buffer found!" << std::endl;
198 return;
199 }
200
201 selectedImages.push_back(images[i].get());
202 }
203 if (selectedImages.size() > 0)
204 {
205 drawImages(selectedImages.size(), &selectedImages[0], IceUtil::Time(), IceUtil::Time());
206 }
207 }
208
209 void
211 {
212 if (toggled)
213 {
214 ui.buttonShowBufferImages->setArrowType(Qt::DownArrow);
215 }
216 else
217 {
218 ui.buttonShowBufferImages->setArrowType(Qt::LeftArrow);
219 }
220 }
221
224 {
225 return imageViewer;
226 }
227
228 void
230 {
231 controller->createSnapshot();
232 }
233
234 void
236 {
237 controller->setPlaying(playing);
238 ui.playButton->setChecked(playing);
239 }
240
241 void
243 {
244 ui.playButton->setEnabled(connected);
245 ui.statisticsButton->setEnabled(connected);
246 ui.snapshotButton->setEnabled(connected);
247 ui.cbBufferImages->setEnabled(connected);
248
249 if (!connected) // only disable, enabling is only done in playButtonToggled
250 {
251 ui.sliderImageBuffer->setEnabled(false);
252 }
253 playButtonToggled(connected);
254 }
255
256 void
257 ImageMonitorWidget::updateStatistics(const QString& statisticsStr)
258 {
259 ui.imageViewerStats->setText(statisticsStr);
260 }
261
262} // namespace visionx
void drawImages(int numberImages, CByteImage **images, IceUtil::Time imageTimestamp, IceUtil::Time receiveTimestamp)
void statisticsButtonClicked(bool toggled)
void settingsButtonClicked(bool toggled)
void snapshotButtonClicked(bool toggled)
ImageViewerArea * getImageViewer() const
void hideControlWidgets(bool hide=true)
void updateStatistics(const QString &statisticsStr)
void bufferImagesPaneChanged(bool toggled)
ImageMonitorWidget(ImageMonitorWidgetController *controller)
#define ARMARX_WARNING_S
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:213
This file offers overloads of toIce() and fromIce() functions for STL container types.
ArmarX headers.
std::vector< CByteImagePtr > ImageContainer