PointCloudVisualizationWidgetController.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 VisionX::gui-plugins::PointCloudVisualizationWidgetController
17 * \author Peter Kaiser ( peter dot kaiser at kit dot edu )
18 * \date 2017
19 * \copyright http://www.gnu.org/licenses/gpl-2.0.txt
20 * GNU General Public License
21 */
22
24
25#include <string>
26
27#include <QCheckBox>
28#include <QComboBox>
29#include <QLabel>
30#include <QMetaObject>
31#include <QTableWidget>
32#include <QTableWidgetItem>
33
34namespace armarx
35{
37 {
38 widget.setupUi(getWidget());
39 updateTimer.setInterval(100);
40 updateTimer.setSingleShot(false);
41 }
42
46
47 void
49 {
50 visualizerName = settings->value("visualizerName", "").toString().toStdString();
51 }
52
53 void
55 {
56 settings->setValue("visualizerName", QString::fromStdString(visualizerName));
57 }
58
59 QPointer<QDialog>
61 {
62 if (!configDialog)
63 {
64 configDialog = new PointCloudVisualizationConfigDialog(parent);
65 }
66
67 return qobject_cast<PointCloudVisualizationConfigDialog*>(configDialog);
68 }
69
70 void
72 {
73 visualizerName =
74 configDialog->pointCloudVisualizationProxyFinder->getSelectedProxyName().toStdString();
75 }
76
77 void
82
83 void
85 {
87 if (!visualizer)
88 {
89 ARMARX_ERROR << "Could not obtain point cloud visualizer proxy";
90 return;
91 }
92
94
95 connect(this, SIGNAL(providerListChanged()), this, SLOT(updateProviderTable()));
96 connect(&updateTimer, SIGNAL(timeout()), this, SLOT(updateProviderTable()));
97 QMetaObject::invokeMethod(&updateTimer, "start", Qt::QueuedConnection);
98 }
99
100 void
102 {
103 QMetaObject::invokeMethod(&updateTimer, "stop", Qt::QueuedConnection);
104 QObject::disconnect(this, SLOT(updateProviderTable()));
105 }
106
107 void
109 {
110 providers.clear();
111 providers = visualizer->getAvailableProviders();
112
113 std::sort(providers.begin(), providers.end());
114
115 emit providerListChanged();
116 }
117
118 void
120 {
121 bool rebuild =
122 static_cast<unsigned int>(widget.tableWidgetProviders->rowCount()) != providers.size();
123 if (!rebuild)
124 {
125 for (unsigned int i = 0; i < providers.size(); i++)
126 {
127 if (static_cast<QCheckBox*>(
128 widget.tableWidgetProviders->cellWidget(static_cast<int>(i), 0))
129 ->text()
130 .toStdString() != providers[i].name)
131 {
132 rebuild = true;
133 break;
134 }
135 }
136 }
137 if (rebuild)
138 {
139 rebuildProviderTable();
140 }
141
142 for (unsigned int i = 0; i < providers.size(); i++)
143 {
144 auto info = visualizer->getCurrentPointCloudVisualizationInfo(providers[i].name);
145 static_cast<QCheckBox*>(widget.tableWidgetProviders->cellWidget(static_cast<int>(i), 0))
146 ->setCheckState(info.enabled ? Qt::Checked : Qt::Unchecked);
147
148 if (providers[i].type == visionx::ePoints)
149 {
150 // nothing to update
151 }
152 else if (providers[i].type == visionx::eColoredPoints ||
153 providers[i].type == visionx::eColoredOrientedPoints)
154 {
155 static_cast<QComboBox*>(
156 widget.tableWidgetProviders->cellWidget(static_cast<int>(i), 1))
157 ->setCurrentIndex(info.type == visionx::eColoredPoints ? 1 : 0);
158 }
159 else if (providers[i].type == visionx::eLabeledPoints)
160 {
161 static_cast<QComboBox*>(
162 widget.tableWidgetProviders->cellWidget(static_cast<int>(i), 1))
163 ->setCurrentIndex(info.type == visionx::eLabeledPoints ? 1 : 0);
164 }
165 else if (providers[i].type == visionx::eColoredLabeledPoints)
166 {
167 static_cast<QComboBox*>(
168 widget.tableWidgetProviders->cellWidget(static_cast<int>(i), 1))
169 ->setCurrentIndex(info.type == visionx::eLabeledPoints
170 ? 2
171 : (info.type == visionx::eColoredPoints ? 1 : 0));
172 }
173 else
174 {
175 // nothing to update
176 }
177 }
178 }
179
180 void
181 PointCloudVisualizationWidgetController::rebuildProviderTable()
182 {
183 QObject::disconnect(this, SLOT(providerSelectionChanged()));
184 QObject::disconnect(this, SLOT(providerVisualizationTypeChanged(int)));
185 widget.tableWidgetProviders->clear();
186
187 widget.tableWidgetProviders->setColumnCount(2);
188 widget.tableWidgetProviders->setRowCount(static_cast<int>(providers.size()));
189
190 for (unsigned int i = 0; i < providers.size(); i++)
191 {
192 QCheckBox* cb = new QCheckBox(QString::fromStdString(providers[i].name));
193 connect(cb, SIGNAL(toggled(bool)), this, SLOT(providerSelectionChanged()));
194 widget.tableWidgetProviders->setCellWidget(static_cast<int>(i), 0, cb);
195
196 if (providers[i].type == visionx::ePoints)
197 {
198 widget.tableWidgetProviders->setItem(
199 static_cast<int>(i), 1, new QTableWidgetItem("Plain"));
200 }
201 else if (providers[i].type == visionx::eColoredPoints ||
202 providers[i].type == visionx::eColoredOrientedPoints)
203 {
204 QComboBox* combo = new QComboBox();
205 combo->addItem("Plain");
206 combo->addItem("Colors");
207 combo->setCurrentIndex(1);
208 connect(combo,
209 SIGNAL(currentIndexChanged(int)),
210 this,
212 widget.tableWidgetProviders->setCellWidget(static_cast<int>(i), 1, combo);
213 }
214 else if (providers[i].type == visionx::eLabeledPoints)
215 {
216 QComboBox* combo = new QComboBox();
217 combo->addItem("Plain");
218 combo->addItem("Labels");
219 combo->setCurrentIndex(1);
220 connect(combo,
221 SIGNAL(currentIndexChanged(int)),
222 this,
224 widget.tableWidgetProviders->setCellWidget(static_cast<int>(i), 1, combo);
225 }
226 else if (providers[i].type == visionx::eColoredLabeledPoints)
227 {
228 QComboBox* combo = new QComboBox();
229 combo->addItem("Plain");
230 combo->addItem("Colors");
231 combo->addItem("Labels");
232 combo->setCurrentIndex(1);
233 connect(combo,
234 SIGNAL(currentIndexChanged(int)),
235 this,
237 widget.tableWidgetProviders->setCellWidget(static_cast<int>(i), 1, combo);
238 }
239 else
240 {
241 cb->setEnabled(false);
242 widget.tableWidgetProviders->setItem(
243 static_cast<int>(i), 1, new QTableWidgetItem("Unsupported"));
244 }
245 }
246 }
247
248 void
250 {
251 for (unsigned int i = 0; i < providers.size(); i++)
252 {
253 visionx::PointContentType type;
254
255 QCheckBox* check =
256 dynamic_cast<QCheckBox*>(widget.tableWidgetProviders->cellWidget(i, 0));
257
258 if (dynamic_cast<QComboBox*>(widget.tableWidgetProviders->cellWidget(i, 1)) != nullptr)
259 {
260 QComboBox* combo =
261 dynamic_cast<QComboBox*>(widget.tableWidgetProviders->cellWidget(i, 1));
262
263 if (combo->currentText() == "Colors")
264 {
265 type = visionx::eColoredPoints;
266 }
267 else if (combo->currentText() == "Labels")
268 {
269 type = visionx::eLabeledPoints;
270 }
271 else
272 {
273 type = visionx::ePoints;
274 }
275 }
276 else
277 {
278 type = providers[i].type;
279 }
280
281 visualizer->begin_enablePointCloudVisualization(
282 providers[i].name, type, check->isChecked());
283 }
284 }
285
286 void
291} // namespace armarx
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
QPointer< QDialog > getConfigDialog(QWidget *parent=0) override
getConfigDialog returns a pointer to the a configuration widget of this controller.
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
This file offers overloads of toIce() and fromIce() functions for STL container types.