ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
qVoxFallDialog.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 
8 #include "qVoxFallDialog.h"
9 
10 // CCPluginAPI
11 #include <ecvMainAppInterface.h>
12 #include <ecvQtHelpers.h>
13 
14 // qCC_db
15 #include <ecvDisplayTools.h>
16 #include <ecvMesh.h>
17 
18 // Qt
19 #include <QComboBox>
20 #include <QMainWindow>
21 #include <QThread>
22 
23 /*** HELPERS ***/
24 static QString GetEntityName(ccHObject* obj) {
25  if (!obj) {
26  assert(false);
27  return QString();
28  }
29 
30  QString name = obj->getName();
31  if (name.isEmpty()) name = "unnamed";
32  name += QString(" [ID %1]").arg(obj->getUniqueID());
33 
34  return name;
35 }
36 
37 static ccMesh* GetMeshFromCombo(QComboBox* comboBox, ccHObject* dbRoot) {
38  assert(comboBox && dbRoot);
39  if (!comboBox || !dbRoot) {
40  assert(false);
41  return nullptr;
42  }
43 
44  // return the mesh currently selected in the combox box
45  int index = comboBox->currentIndex();
46  if (index < 0) {
47  assert(false);
48  return nullptr;
49  }
50  assert(comboBox->itemData(index).isValid());
51  unsigned uniqueID = comboBox->itemData(index).toUInt();
52  ccHObject* item = dbRoot->find(uniqueID);
53  if (!item || !item->isA(CV_TYPES::MESH)) {
54  assert(false);
55  return nullptr;
56  }
57  return static_cast<ccMesh*>(item);
58 }
59 
60 /*** HELPERS (END) ***/
61 
63  ccMesh* mesh2,
65  : QDialog(app ? app->getMainWindow() : nullptr),
66  Ui::VoxFallDialog(),
67  m_app(app),
68  m_mesh1(nullptr),
69  m_mesh2(nullptr) {
70  setupUi(this);
71 
72  connect(showMesh1CheckBox, &QAbstractButton::toggled, this,
74  connect(showMesh2CheckBox, &QAbstractButton::toggled, this,
76 
77  connect(swapMeshesToolButton, &QAbstractButton::clicked, this,
79 
80  setMeshes(mesh1, mesh2);
81 
83 }
84 
86 
87 void qVoxFallDialog::setMeshes(ccMesh* mesh1, ccMesh* mesh2) {
88  if (!mesh1 || !mesh2) {
89  assert(false);
90  return;
91  }
92 
93  m_mesh1 = mesh1;
94  m_mesh2 = mesh2;
95 
96  // mesh #1
97  mesh1LineEdit->setText(GetEntityName(mesh1));
98  showMesh1CheckBox->blockSignals(true);
99  showMesh1CheckBox->setChecked(mesh1->isVisible());
100  showMesh1CheckBox->blockSignals(false);
101 
102  // mesh #2
103  mesh2LineEdit->setText(GetEntityName(mesh2));
104  showMesh2CheckBox->blockSignals(true);
105  showMesh2CheckBox->setChecked(mesh2->isVisible());
106  showMesh2CheckBox->blockSignals(false);
107 }
108 
110  if (m_mesh1) {
111  m_mesh1->setVisible(state);
112  // m_mesh1->prepareDisplayForRefresh();
114  m_mesh1->setRedraw(true);
115  }
116  if (m_app) {
117  m_app->refreshAll();
118  m_app->updateUI();
119  }
120 }
121 
123  if (m_mesh2) {
124  m_mesh2->setVisible(state);
125  // m_mesh2->prepareDisplayForRefresh();
127  m_mesh2->setRedraw(true);
128  }
129  if (m_app) {
130  m_app->refreshAll();
131  m_app->updateUI();
132  }
133 }
134 
136  double voxelSize = voxelSizeDoubleSpinBox->value();
137  return voxelSize;
138 }
139 
141  double azimuth = azDoubleSpinBox->value();
142  return azimuth;
143 }
144 
146  return exportCheckBox->isChecked();
147 }
148 
150  return lossCheckBox->isChecked();
151 }
152 
154  return QThread::idealThreadCount();
155 }
156 
158  QSettings settings("qVoxFall");
159  loadParamsFrom(settings);
160 }
161 
162 void qVoxFallDialog::loadParamsFrom(const QSettings& settings) {
163  // read parameters
164  double voxelSize =
165  settings.value("VoxelSize", voxelSizeDoubleSpinBox->value())
166  .toDouble();
167  double azimuth =
168  settings.value("Azimuth", azDoubleSpinBox->value()).toDouble();
169  bool exportMeshesEnabled =
170  settings.value("ExportMeshesEnabled", exportCheckBox->isChecked())
171  .toBool();
172  bool lossGainEnabled =
173  settings.value("LossGainEnabled", lossCheckBox->isChecked())
174  .toBool();
175 
176  // apply parameters
177  voxelSizeDoubleSpinBox->setValue(voxelSize);
178  azDoubleSpinBox->setValue(azimuth);
179  exportCheckBox->setChecked(exportMeshesEnabled);
180  lossCheckBox->setChecked(lossGainEnabled);
181 }
182 
184  QSettings settings("qVoxFall");
185  saveParamsTo(settings);
186 }
187 
188 void qVoxFallDialog::saveParamsTo(QSettings& settings) {
189  // save parameters
190  settings.setValue("VoxelSize", voxelSizeDoubleSpinBox->value());
191  settings.setValue("Azimuth", azDoubleSpinBox->value());
192  settings.setValue("ExportMeshesEnabled", exportCheckBox->isChecked());
193  settings.setValue("LossGainEnabled", lossCheckBox->isChecked());
194 }
std::string name
virtual bool isVisible() const
Returns whether entity is visible or not.
virtual void setVisible(bool state)
Sets entity visibility.
virtual void setRedraw(bool state)
Sets entity redraw mode.
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
ccHObject * find(unsigned uniqueID)
Finds an entity in this object hierarchy.
Triangular mesh.
Definition: ecvMesh.h:35
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
static void SetRedrawRecursive(bool redraw=false)
Main application interface (for plugins)
virtual void updateUI()=0
virtual void refreshAll(bool only2D=false, bool forceRedraw=true)=0
Redraws all GL windows that have the 'refresh' flag on.
ccMesh * m_mesh1
void setMesh1Visibility(bool)
void loadParamsFromPersistentSettings()
void setMeshes(ccMesh *mesh1, ccMesh *mesh2)
Sets meshes.
void saveParamsToPersistentSettings()
bool getExportMeshesActivation() const
Returns whether the blocks will be exported as meshes.
void loadParamsFrom(const QSettings &settings)
bool getLossGainActivation() const
Labels the blocks as loss or gain clusters.
void saveParamsTo(QSettings &settings)
double getVoxelSize() const
Returns voxel size.
ccMesh * m_mesh2
ecvMainAppInterface * m_app
void setMesh2Visibility(bool)
int getMaxThreadCount() const
Returns the max number of threads to use.
qVoxFallDialog(ccMesh *mesh1, ccMesh *mesh2, ecvMainAppInterface *app)
Default constructor.
double getAzimuth() const
Returns slope azimuth.
@ MESH
Definition: CVTypes.h:105
static ccMesh * GetMeshFromCombo(QComboBox *comboBox, ccHObject *dbRoot)
static QString GetEntityName(ccHObject *obj)