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 <QCheckBox>
26 #include <QTableWidget>
27 #include <QTableWidgetItem>
28 #include <QComboBox>
29 #include <QLabel>
30 #include <QMetaObject>
31 
32 #include <string>
33 
34 namespace armarx
35 {
37  {
38  widget.setupUi(getWidget());
39  updateTimer.setInterval(100);
40  updateTimer.setSingleShot(false);
41  }
42 
43 
45  {
46 
47  }
48 
49 
51  {
52  visualizerName = settings->value("visualizerName", "").toString().toStdString();
53  }
54 
56  {
57  settings->setValue("visualizerName", QString::fromStdString(visualizerName));
58  }
59 
61  {
62  if (!configDialog)
63  {
64  configDialog = new PointCloudVisualizationConfigDialog(parent);
65  }
66 
67  return qobject_cast<PointCloudVisualizationConfigDialog*>(configDialog);
68  }
69 
71  {
72  visualizerName = configDialog->pointCloudVisualizationProxyFinder->getSelectedProxyName().toStdString();
73  }
74 
76  {
77  usingProxy(visualizerName);
78  }
79 
81  {
82  visualizer = getProxy<visionx::PointCloudVisualizationInterfacePrx>(visualizerName);
83  if (!visualizer)
84  {
85  ARMARX_ERROR << "Could not obtain point cloud visualizer proxy";
86  return;
87  }
88 
90 
91  connect(this, SIGNAL(providerListChanged()), this, SLOT(updateProviderTable()));
92  connect(&updateTimer, SIGNAL(timeout()), this, SLOT(updateProviderTable()));
93  QMetaObject::invokeMethod(&updateTimer, "start", Qt::QueuedConnection);
94  }
95 
97  {
98  QMetaObject::invokeMethod(&updateTimer, "stop", Qt::QueuedConnection);
99  QObject::disconnect(this, SLOT(updateProviderTable()));
100  }
101 
103  {
104  providers.clear();
105  providers = visualizer->getAvailableProviders();
106 
107  std::sort(providers.begin(), providers.end());
108 
109  emit providerListChanged();
110  }
111 
113  {
114  bool rebuild = static_cast<unsigned int>(widget.tableWidgetProviders->rowCount()) != providers.size();
115  if (!rebuild)
116  {
117  for (unsigned int i = 0; i < providers.size(); i++)
118  {
119  if (static_cast<QCheckBox*>(widget.tableWidgetProviders->cellWidget(static_cast<int>(i), 0))->text().toStdString() != providers[i].name)
120  {
121  rebuild = true;
122  break;
123  }
124  }
125  }
126  if (rebuild)
127  {
128  rebuildProviderTable();
129  }
130 
131  for (unsigned int i = 0; i < providers.size(); i++)
132  {
133  auto info = visualizer->getCurrentPointCloudVisualizationInfo(providers[i].name);
134  static_cast<QCheckBox*>(widget.tableWidgetProviders->cellWidget(static_cast<int>(i), 0))->setCheckState(info.enabled ? Qt::Checked : Qt::Unchecked);
135 
136  if (providers[i].type == visionx::ePoints)
137  {
138  // nothing to update
139  }
140  else if (providers[i].type == visionx::eColoredPoints || providers[i].type == visionx::eColoredOrientedPoints)
141  {
142  static_cast<QComboBox*>(widget.tableWidgetProviders->cellWidget(static_cast<int>(i), 1))->setCurrentIndex(info.type == visionx::eColoredPoints ? 1 : 0);
143  }
144  else if (providers[i].type == visionx::eLabeledPoints)
145  {
146  static_cast<QComboBox*>(widget.tableWidgetProviders->cellWidget(static_cast<int>(i), 1))->setCurrentIndex(info.type == visionx::eLabeledPoints ? 1 : 0);
147  }
148  else if (providers[i].type == visionx::eColoredLabeledPoints)
149  {
150  static_cast<QComboBox*>(widget.tableWidgetProviders->cellWidget(static_cast<int>(i), 1))->setCurrentIndex(info.type == visionx::eLabeledPoints ? 2 : (info.type == visionx::eColoredPoints ? 1 : 0));
151  }
152  else
153  {
154  // nothing to update
155  }
156  }
157  }
158  void PointCloudVisualizationWidgetController::rebuildProviderTable()
159  {
160  QObject::disconnect(this, SLOT(providerSelectionChanged()));
161  QObject::disconnect(this, SLOT(providerVisualizationTypeChanged(int)));
162  widget.tableWidgetProviders->clear();
163 
164  widget.tableWidgetProviders->setColumnCount(2);
165  widget.tableWidgetProviders->setRowCount(static_cast<int>(providers.size()));
166 
167  for (unsigned int i = 0; i < providers.size(); i++)
168  {
169  QCheckBox* cb = new QCheckBox(QString::fromStdString(providers[i].name));
170  connect(cb, SIGNAL(toggled(bool)), this, SLOT(providerSelectionChanged()));
171  widget.tableWidgetProviders->setCellWidget(static_cast<int>(i), 0, cb);
172 
173  if (providers[i].type == visionx::ePoints)
174  {
175  widget.tableWidgetProviders->setItem(static_cast<int>(i), 1, new QTableWidgetItem("Plain"));
176  }
177  else if (providers[i].type == visionx::eColoredPoints || providers[i].type == visionx::eColoredOrientedPoints)
178  {
179  QComboBox* combo = new QComboBox();
180  combo->addItem("Plain");
181  combo->addItem("Colors");
182  combo->setCurrentIndex(1);
183  connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(providerVisualizationTypeChanged(int)));
184  widget.tableWidgetProviders->setCellWidget(static_cast<int>(i), 1, combo);
185  }
186  else if (providers[i].type == visionx::eLabeledPoints)
187  {
188  QComboBox* combo = new QComboBox();
189  combo->addItem("Plain");
190  combo->addItem("Labels");
191  combo->setCurrentIndex(1);
192  connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(providerVisualizationTypeChanged(int)));
193  widget.tableWidgetProviders->setCellWidget(static_cast<int>(i), 1, combo);
194  }
195  else if (providers[i].type == visionx::eColoredLabeledPoints)
196  {
197  QComboBox* combo = new QComboBox();
198  combo->addItem("Plain");
199  combo->addItem("Colors");
200  combo->addItem("Labels");
201  combo->setCurrentIndex(1);
202  connect(combo, SIGNAL(currentIndexChanged(int)), this, SLOT(providerVisualizationTypeChanged(int)));
203  widget.tableWidgetProviders->setCellWidget(static_cast<int>(i), 1, combo);
204  }
205  else
206  {
207  cb->setEnabled(false);
208  widget.tableWidgetProviders->setItem(static_cast<int>(i), 1, new QTableWidgetItem("Unsupported"));
209  }
210  }
211  }
212 
214  {
215  for (unsigned int i = 0; i < providers.size(); i++)
216  {
217  visionx::PointContentType type;
218 
219  QCheckBox* check = dynamic_cast<QCheckBox*>(widget.tableWidgetProviders->cellWidget(i, 0));
220 
221  if (dynamic_cast<QComboBox*>(widget.tableWidgetProviders->cellWidget(i, 1)) != nullptr)
222  {
223  QComboBox* combo = dynamic_cast<QComboBox*>(widget.tableWidgetProviders->cellWidget(i, 1));
224 
225  if (combo->currentText() == "Colors")
226  {
227  type = visionx::eColoredPoints;
228  }
229  else if (combo->currentText() == "Labels")
230  {
231  type = visionx::eLabeledPoints;
232  }
233  else
234  {
235  type = visionx::ePoints;
236  }
237  }
238  else
239  {
240  type = providers[i].type;
241  }
242 
243  visualizer->begin_enablePointCloudVisualization(providers[i].name, type, check->isChecked());
244  }
245  }
246 
248  {
250  }
251 }
armarx::PointCloudVisualizationWidgetController::configured
void configured() override
This function must be implemented by the user, if he supplies a config dialog.
Definition: PointCloudVisualizationWidgetController.cpp:70
armarx::PointCloudVisualizationWidgetController::~PointCloudVisualizationWidgetController
virtual ~PointCloudVisualizationWidgetController()
Controller destructor.
Definition: PointCloudVisualizationWidgetController.cpp:44
armarx::PointCloudVisualizationWidgetController::saveSettings
void saveSettings(QSettings *settings) override
Definition: PointCloudVisualizationWidgetController.cpp:55
armarx::PointCloudVisualizationWidgetController::providerVisualizationTypeChanged
void providerVisualizationTypeChanged(int x)
Definition: PointCloudVisualizationWidgetController.cpp:247
armarx::PointCloudVisualizationWidgetController::providerListChanged
void providerListChanged()
armarx::PointCloudVisualizationConfigDialog
Definition: PointCloudVisualizationConfigDialog.h:40
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
armarx::PointCloudVisualizationWidgetController::onInitComponent
void onInitComponent() override
Definition: PointCloudVisualizationWidgetController.cpp:75
armarx::PointCloudVisualizationWidgetController::PointCloudVisualizationWidgetController
PointCloudVisualizationWidgetController()
Controller Constructor.
Definition: PointCloudVisualizationWidgetController.cpp:36
armarx::PointCloudVisualizationWidgetController::onConnectComponent
void onConnectComponent() override
Definition: PointCloudVisualizationWidgetController.cpp:80
armarx::PointCloudVisualizationWidgetController::updateProviderTable
void updateProviderTable()
Definition: PointCloudVisualizationWidgetController.cpp:112
armarx::PointCloudVisualizationWidgetController::providerSelectionChanged
void providerSelectionChanged()
Definition: PointCloudVisualizationWidgetController.cpp:213
PointCloudVisualizationWidgetController.h
armarx::PointCloudVisualizationWidgetController::getConfigDialog
QPointer< QDialog > getConfigDialog(QWidget *parent=0) override
getConfigDialog returns a pointer to the a configuration widget of this controller.
Definition: PointCloudVisualizationWidgetController.cpp:60
armarx::ArmarXWidgetController::getWidget
virtual QPointer< QWidget > getWidget()
getWidget returns a pointer to the a widget of this controller.
Definition: ArmarXWidgetController.cpp:54
armarx::PointCloudVisualizationWidgetController::loadSettings
void loadSettings(QSettings *settings) override
Definition: PointCloudVisualizationWidgetController.cpp:50
armarx::ManagedIceObject::usingProxy
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Definition: ManagedIceObject.cpp:151
armarx::PointCloudVisualizationWidgetController::onDisconnectComponent
void onDisconnectComponent() override
Hook for subclass.
Definition: PointCloudVisualizationWidgetController.cpp:96
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::PointCloudVisualizationWidgetController::updateProviderList
void updateProviderList()
Definition: PointCloudVisualizationWidgetController.cpp:102