38 #include <vtkSmartPointer.h>
39 #include <vtkCubeSource.h>
41 #include <boost/make_shared.hpp>
43 #include <QMessageBox>
45 #include <QFileDialog>
46 #include <QInputDialog>
47 #include <QColorDialog>
48 #include <QButtonGroup>
49 #include <vtkSelectEnclosedPoints.h>
50 #include <vtkPolyDataMapper.h>
51 #include <vtkPointData.h>
55 #include <vtkLookupTable.h>
56 #include <vtkExtractGeometry.h>
67 m_treeWidget(treeWidget)
70 m_ui =
new Ui_LabelDialog;
73 QObject::connect(
m_ui->newLabelButton, SIGNAL(pressed()),
this, SLOT(
addNewLabel()));
74 QObject::connect(
m_ui->loadLabeledPoints, SIGNAL(pressed()),
this, SLOT(
loadLabels()));
75 QObject::connect(
m_ui->newInstanceButton, SIGNAL(pressed()),
this, SLOT(
addNewInstance()));
76 QObject::connect(
m_ui->treeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,
int)),
this, SLOT(
cellSelected(QTreeWidgetItem*,
int)));
77 QObject::connect(
m_ui->selectedLabelComboBox, SIGNAL(currentIndexChanged(
int)),
this, SLOT(
comboBoxIndexChanged(
int)));
78 QObject::connect(
m_ui->treeWidget, SIGNAL(itemChanged(QTreeWidgetItem*,
int)),
this, SLOT(
visibilityChanged(QTreeWidgetItem*,
int)));
103 if (changedItem->parent())
110 for (
int i = 0; i < changedItem->childCount(); i++)
112 QTreeWidgetItem* childItem = changedItem->child(i);
128 QString label_name = QInputDialog::getText(
m_dialog,
tr(
"Select Label Name"),
131 if (accepted && !label_name.isEmpty())
139 int comboBoxPos =
m_ui->selectedLabelComboBox->findData(item->data(
LABEL_ID_COLUMN, 0).toInt());
140 if (comboBoxPos >= 0)
142 m_ui->selectedLabelComboBox->setItemText(comboBoxPos, label_name);
150 QColor label_color = QColorDialog::getColor(Qt::red,
m_dialog,
tr(
"Choose Label Color"));
151 if (label_color.isValid())
163 QMessageBox colorUpdateDialog;
164 colorUpdateDialog.setText(
"Labelclass default color changed. Shall all instance colors be updated?");
165 colorUpdateDialog.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
166 colorUpdateDialog.setDefaultButton(QMessageBox::Yes);
167 int returnValue = colorUpdateDialog.exec();
168 if (returnValue == QMessageBox::Yes)
171 for (
int i = 0; i < item->childCount(); i++)
187 int topItemCount =
m_ui->treeWidget->topLevelItemCount();
188 for (
int i = 0; i < topItemCount; i++)
190 QTreeWidgetItem* topLevelItem =
m_ui->treeWidget->topLevelItem(i);
191 int childCount = topLevelItem->childCount();
192 for (
int j = 0; j < childCount; j++)
196 int pointCountDifference = selectedPointCount - topLevelItem->child(j)->text(
LABELED_POINT_COLUMN).toInt();
210 QString fileName = QFileDialog::getOpenFileName(
m_dialog,
211 tr(
"Open HDF5 File"), QDir::homePath(),
tr(
"HDF5 files (*.h5)"));
212 if(!QFile::exists(fileName))
218 std::vector<std::string> pointCloudNames;
220 for (
auto pointcloudName : pointCloudNames)
223 boost::filesystem::path classGroup = (boost::filesystem::path(
"pointclouds") / boost::filesystem::path(pointcloudName) / boost::filesystem::path(
"labels"));
224 std::vector<std::string> labelClasses;
226 for (
auto labelClass : labelClasses)
229 QTreeWidgetItem * item =
new QTreeWidgetItem();
230 item->setText(0, QString::fromStdString(labelClass));
234 if (
m_ui->treeWidget->topLevelItemCount() == 0)
236 m_ui->newInstanceButton->setEnabled(
true);
238 m_ui->treeWidget->addTopLevelItem(item);
242 boost::filesystem::path instanceGroup = (classGroup / boost::filesystem::path(labelClass));
243 std::vector<std::string> labelInstances;
244 kernel.
subGroupNames(instanceGroup.string(), labelInstances);
245 for (
auto instance : labelInstances)
249 boost::filesystem::path finalGroup = instanceGroup;
251 finalGroup = (instanceGroup / boost::filesystem::path(instance));
252 if (labelClass !=
"Unlabeled")
259 boost::shared_array<int> rgbData;
260 std::vector<size_t> rgbDim;
261 boost::shared_array<int> idData;
262 std::vector<size_t> idDim;
263 idData = kernel.
loadArray<
int>(finalGroup.string(),
"IDs", idDim);
264 rgbData = kernel.
loadArray<
int>(finalGroup.string(),
"Color", rgbDim);
267 QTreeWidgetItem * childItem =
new QTreeWidgetItem();
269 childItem->setText(0, QString::fromStdString(instance));
270 QColor label_color(rgbData[0], rgbData[1], rgbData[2]);
273 item->addChild(childItem);
275 std::vector<int> out(idData.get(), idData.get() + idDim[0]);
277 if (labelClass !=
"Unlabeled")
287 std::map<uint16_t,std::vector<int>> idMap;
289 for (
int i = 0; i < labeledPoints.size(); i++)
292 if(idMap.find(labeledPoints[i]) == idMap.end())
295 idMap[labeledPoints[i]] = {};
297 idMap[labeledPoints[i]].push_back(i);
301 dialog.setDirectory(QDir::homePath());
302 dialog.setFileMode(QFileDialog::AnyFile);
303 QString strFile = dialog.getSaveFileName(
m_dialog,
"Creat New HDF5 File",
"",
"");
305 HDF5Kernel label_hdf5kernel((strFile + QString(
".h5")).toStdString());
306 int topItemCount =
m_ui->treeWidget->topLevelItemCount();
310 boost::filesystem::path pointcloudName(
m_points.begin()->first);
311 auto points =
m_points.begin()->second;
313 double* pointsData =
new double[points->GetNumberOfPoints() * 3];
317 for (
int i = 0; i < points->GetNumberOfPoints(); i++)
319 auto point = points->GetPoint(i);
320 pointsData[(3 * i)] = point[0];
321 pointsData[(3 * i) + 1] = point[1];
322 pointsData[(3 * i) + 2] = point[2];
326 std::vector<size_t> pointsDimension = {3, points->GetNumberOfPoints()};
327 boost::shared_array<double> sharedPoints(pointsData);
330 QTreeWidgetItem* unlabeledItem;
332 boost::filesystem::path pointGroup = (boost::filesystem::path(
"pointclouds") / pointcloudName);
333 label_hdf5kernel.
saveDoubleArray(pointGroup.string(),
"Points" , pointsDimension, sharedPoints);
334 for (
int i = 0; i < topItemCount; i++)
336 QTreeWidgetItem* topLevelItem =
m_ui->treeWidget->topLevelItem(i);
339 unlabeledItem = topLevelItem;
341 boost::filesystem::path topLabel = topLevelItem->text(
LABEL_NAME_COLUMN).toStdString();
342 int childCount = topLevelItem->childCount();
343 for (
int j = 0; j < childCount; j++)
345 int childID = topLevelItem->child(j)->data(
LABEL_ID_COLUMN, 0).toInt();
346 int* sharedArrayData =
new int[idMap[childID].size()];
347 std::memcpy(sharedArrayData, idMap[childID].data(), idMap[childID].size() *
sizeof(
int));
348 boost::shared_array<int> data(sharedArrayData);
349 std::vector<size_t> dimension = {idMap[childID].size()};
350 if(idMap.find(childID) != idMap.end())
352 boost::filesystem::path childLabel = (topLevelItem->child(j)->text(
LABEL_NAME_COLUMN)).toStdString();
353 boost::filesystem::path completeGroup = (pointGroup / boost::filesystem::path(
"labels") / topLabel / childLabel);
355 label_hdf5kernel.
saveArray(completeGroup.string(),
"IDs" , dimension, data);
356 int* rgbSharedData =
new int[3];
357 (topLevelItem->child(j)->data(
LABEL_ID_COLUMN, 1)).value<QColor>().getRgb(&rgbSharedData[0], &rgbSharedData[1], &rgbSharedData[2]);
358 boost::shared_array<int> rgbData(rgbSharedData);
359 std::vector<size_t> rgbDimension = {3};
360 label_hdf5kernel.
saveArray(completeGroup.string(),
"Color" , rgbDimension, rgbData);
371 QString label_name = QInputDialog::getText(
m_dialog,
tr(
"Select Label Name"),
373 tr(
"LabelName") , &accepted);
374 if (!accepted || label_name.isEmpty())
380 QColor label_color = QColorDialog::getColor(Qt::red,
m_dialog,
tr(
"Choose default Label Color for label Class(willbe used for first isntance)"));
381 if (!label_color.isValid())
387 if (
m_ui->treeWidget->topLevelItemCount() == 0)
391 QTreeWidgetItem * item =
new QTreeWidgetItem();
392 item->setText(0,
"Unlabeled");
398 QTreeWidgetItem * childItem =
new QTreeWidgetItem();
399 childItem->setText(
LABEL_NAME_COLUMN, QString(
"Unlabeled") + QString::number(1));
404 item->addChild(childItem);
405 m_ui->treeWidget->addTopLevelItem(item);
407 m_ui->newInstanceButton->setEnabled(
true);
413 QTreeWidgetItem * item =
new QTreeWidgetItem();
414 item->setText(0, label_name);
420 QTreeWidgetItem * childItem =
new QTreeWidgetItem();
426 item->addChild(childItem);
427 m_ui->treeWidget->addTopLevelItem(item);
437 QInputDialog topLevelDialog;
438 QStringList topLabels;
439 if (
m_ui->treeWidget->topLevelItemCount() == 0)
444 for (
int i = 0; i <
m_ui->treeWidget->topLevelItemCount(); i++)
451 topLevelDialog.setComboBoxItems(topLabels);
452 topLevelDialog.setWindowTitle(
"Create new Instance");
453 if (QDialog::Accepted != topLevelDialog.exec())
458 QString choosenLabel = topLevelDialog.textValue();
459 QList<QTreeWidgetItem*> selectedTopLevelItem =
m_ui->treeWidget->findItems(choosenLabel, Qt::MatchExactly);
460 if (selectedTopLevelItem.count() != 1)
468 QString instance_name = QInputDialog::getText(
m_dialog,
tr(
"Choose Name for new Instance"),
470 QString(choosenLabel + QString::number(selectedTopLevelItem[0]->childCount() + 1)) , &accepted);
471 if (!accepted || instance_name.isEmpty())
477 QColor label_color = QColorDialog::getColor(selectedTopLevelItem[0]->data(3,1).value<QColor>(),
m_dialog,
tr(
"Choose Label Color for first instance"));
478 if (!label_color.isValid())
485 QTreeWidgetItem * childItem =
new QTreeWidgetItem();
491 selectedTopLevelItem[0]->addChild(childItem);