ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
MinimumCutSegmentationDlg.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
9 
10 // CV_DB_LIB
11 #include <ecv2DLabel.h>
12 #include <ecvDisplayTools.h>
13 #include <ecvGLMatrix.h>
14 #include <ecvMainAppInterface.h>
15 #include <ecvPointCloud.h>
16 
18  : QDialog(app ? app->getActiveWindow() : 0),
20  m_app(app) {
21  setupUi(this);
22 
23  connect(label2DCloudComboBox, SIGNAL(currentIndexChanged(int)), this,
24  SLOT(onLabelChanged(int)));
25 }
26 
29 }
30 
32  if (m_app) {
33  // add list of labels to the combo-boxes
34  ccHObject::Container labels;
35  if (m_app->dbRootObject())
36  m_app->dbRootObject()->filterChildren(labels, true,
38 
39  unsigned cloudCount = 0;
40  label2DCloudComboBox->clear();
41  for (size_t i = 0; i < labels.size(); ++i) {
42  if (labels[i]->isA(CV_TYPES::LABEL_2D)) // as filterChildren only
43  // test 'isKindOf'
44  {
45  QString name = getEntityName(labels[i]);
46  QVariant uniqueID(labels[i]->getUniqueID());
47  label2DCloudComboBox->addItem(name, uniqueID);
48  ++cloudCount;
49  }
50  }
51 
52  if (cloudCount >= 1 && m_app) {
53  // return the 2D Label currently selected in the combox box
54  selectLabel2DCheckBox->setChecked(true);
55  label2DCloudComboBox->setEnabled(true);
57  } else {
58  selectLabel2DCheckBox->setChecked(false);
59  label2DCloudComboBox->setEnabled(false);
60  }
61  }
62 }
63 
65  if (!label2DCloudComboBox || !m_app) {
66  return;
67  }
68  cc2DLabel* label =
69  get2DLabelFromCombo(label2DCloudComboBox, m_app->dbRootObject());
70  if (!label) {
71  return;
72  }
73  const CCVector3* center = label->getPickedPoint(0).cloud->getPoint(
74  label->getPickedPoint(0).index);
75  if (!center) {
76  return;
77  }
78 
79  cxAxisDoubleSpinBox->setValue(center->x);
80  cyAxisDoubleSpinBox->setValue(center->y);
81  czAxisDoubleSpinBox->setValue(center->z);
82 }
83 
85  if (!obj) {
86  assert(false);
87  return QString();
88  }
89 
90  QString name = obj->getName();
91  if (name.isEmpty()) name = tr("unnamed");
92  name += QString(" [ID %1]").arg(obj->getUniqueID());
93 
94  return name;
95 }
96 
98  ccHObject* dbRoot) {
99  assert(comboBox && dbRoot);
100  if (!comboBox || !dbRoot) {
101  return nullptr;
102  }
103 
104  // return the cloud currently selected in the combox box
105  int index = comboBox->currentIndex();
106  if (index < 0) {
107  return nullptr;
108  }
109  unsigned uniqueID = comboBox->itemData(index).toUInt();
110  ccHObject* item = dbRoot->find(uniqueID);
111  if (!item || !item->isA(CV_TYPES::LABEL_2D)) {
112  return nullptr;
113  }
114  return static_cast<cc2DLabel*>(item);
115 }
std::string name
QString getEntityName(ccHObject *obj)
MinimumCutSegmentationDlg(ecvMainAppInterface *app)
cc2DLabel * get2DLabelFromCombo(QComboBox *comboBox, ccHObject *dbRoot)
ecvMainAppInterface * m_app
Gives access to the application (data-base, UI, etc.)
Type y
Definition: CVGeom.h:137
Type x
Definition: CVGeom.h:137
Type z
Definition: CVGeom.h:137
2D label (typically attached to points)
Definition: ecv2DLabel.h:22
const PickedPoint & getPickedPoint(unsigned index) const
Returns a given point.
Definition: ecv2DLabel.h:194
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
ccHObject * find(unsigned uniqueID)
Finds an entity in this object hierarchy.
unsigned filterChildren(Container &filteredChildren, bool recursive=false, CV_CLASS_ENUM filter=CV_TYPES::OBJECT, bool strict=false) const
Collects the children corresponding to a certain pattern.
std::vector< ccHObject * > Container
Standard instances container (for children, etc.)
Definition: ecvHObject.h:337
virtual QString getName() const
Returns object name.
Definition: ecvObject.h:72
virtual unsigned getUniqueID() const
Returns object unique ID.
Definition: ecvObject.h:86
bool isA(CV_CLASS_ENUM type) const
Definition: ecvObject.h:131
virtual const CCVector3 * getPoint(unsigned index) const =0
Returns the ith point.
Main application interface (for plugins)
virtual ccHObject * dbRootObject()=0
Returns DB root (as a ccHObject)
@ LABEL_2D
Definition: CVTypes.h:140
unsigned index
Point/triangle index.
Definition: ecv2DLabel.h:128
ccGenericPointCloud * cloud
Cloud.
Definition: ecv2DLabel.h:124