ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
qVoxFall.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 "qVoxFall.h"
9 
10 // Qt
11 #include <QMainWindow>
12 
13 // local
14 #include "qVoxFallDialog.h"
16 #include "qVoxFallProcess.h"
17 
18 // qCC_db
19 #include <ecvMesh.h>
20 
21 qVoxFall::qVoxFall(QObject *parent)
22  : QObject(parent),
23  ccStdPluginInterface(":/CC/plugin/qVoxFall/info.json"),
24  m_action(nullptr) {}
25 
26 void qVoxFall::onNewSelection(const ccHObject::Container &selectedEntities) {
27  if (m_action) {
28  m_action->setEnabled(selectedEntities.size() == 2 &&
29  selectedEntities[0]->isA(CV_TYPES::MESH) &&
30  selectedEntities[1]->isA(CV_TYPES::MESH));
31  }
32 
33  m_selectedEntities = selectedEntities;
34 }
35 
36 QList<QAction *> qVoxFall::getActions() {
37  if (!m_action) {
38  m_action = new QAction(getName(), this);
39  m_action->setToolTip(getDescription());
40  m_action->setIcon(getIcon());
41 
42  // Connect signal
43  connect(m_action, &QAction::triggered, this, &qVoxFall::doAction);
44  }
45 
46  return {m_action};
47 }
48 
49 void qVoxFall::doAction() {
50  // disclaimer accepted?
51  if (!DisclaimerDialog::show(m_app)) return;
52 
53  // m_app should have already been initialized by CC when plugin is loaded!
54  assert(m_app);
55  if (!m_app) return;
56 
57  if (m_selectedEntities.size() != 2 ||
58  !m_selectedEntities[0]->isA(CV_TYPES::MESH) ||
59  !m_selectedEntities[1]->isA(CV_TYPES::MESH)) {
60  m_app->dispToConsole("Select two meshes !",
62  return;
63  }
64 
65  ccMesh *mesh1 = ccHObjectCaster::ToMesh(m_selectedEntities[0]);
66  ccMesh *mesh2 = ccHObjectCaster::ToMesh(m_selectedEntities[1]);
67 
68  m_app->dispToConsole("[VoxFall] Meshes loaded successfully",
70 
71  // display dialog
72  qVoxFallDialog dlg(mesh1, mesh2, m_app);
73  if (!dlg.exec()) {
74  // process cancelled by the user
75  return;
76  }
77 
80  QString("[VoxFall] Voxel size: %1 m").arg(dlg.getVoxelSize()),
82 
83  QString errorMessage;
84  if (!qVoxFallProcess::Compute(dlg, errorMessage, true,
85  m_app->getMainWindow(), m_app)) {
86  if (!errorMessage.isEmpty()) {
87  m_app->dispToConsole(errorMessage,
89  } else {
90  mesh1->setEnabled(false);
91  m_app->dispToConsole("[VoxFall] Completed!",
93  }
94  }
95 
96  //'Compute' may change some parameters of the dialog
97  dlg.saveParamsToPersistentSettings();
98 }
static bool show(ecvMainAppInterface *app)
virtual QString getName() const override
Returns (short) name (for menu entry, etc.)
virtual QString getDescription() const override
Returns long name/description (for tooltip, etc.)
virtual QIcon getIcon() const override
Returns icon.
static ccMesh * ToMesh(ccHObject *obj)
Converts current object to ccMesh (if possible)
std::vector< ccHObject * > Container
Standard instances container (for children, etc.)
Definition: ecvHObject.h:337
Triangular mesh.
Definition: ecvMesh.h:35
virtual void setEnabled(bool state)
Sets the "enabled" property.
Definition: ecvObject.h:102
Standard ECV plugin interface.
ecvMainAppInterface * m_app
Main application interface.
virtual QMainWindow * getMainWindow()=0
Returns main window.
virtual void dispToConsole(QString message, ConsoleMessageLevel level=STD_CONSOLE_MESSAGE)=0
VOXFALL plugin's main dialog.
static bool Compute(const qVoxFallDialog &dlg, QString &errorMessage, bool allowDialogs, QWidget *parentWidget=nullptr, ecvMainAppInterface *app=nullptr)
@ MESH
Definition: CVTypes.h:105