ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
qM3C2Commands.h
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 #pragma once
9 
10 // CLOUDVIEWER
12 
13 // LOCAL
14 #include "qM3C2Process.h"
15 
16 static const char COMMAND_M3C2[] = "M3C2";
17 
20 
21  virtual bool process(ccCommandLineInterface& cmd) override {
22  cmd.print("[M3C2]");
23  if (cmd.arguments().empty()) {
24  return cmd.error(QString("Missing parameter: parameters filename "
25  "after \"-%1\"")
26  .arg(COMMAND_M3C2));
27  }
28 
29  // open specified file
30  QString paramFilename(cmd.arguments().takeFirst());
31  cmd.print(QString("Parameters file: '%1'").arg(paramFilename));
32 
33  if (cmd.clouds().size() < 2) {
34  cmd.error(
35  "Not enough clouds loaded (2 or 3 are expected: cloud 1, "
36  "cloud 2 and optionally some core points)");
37  return false;
38  }
39 
40  ccPointCloud* cloud1 =
42  ccPointCloud* cloud2 =
44  ccPointCloud* corePointsCloud =
45  (cmd.clouds().size() > 2 ? cmd.clouds()[2].pc : nullptr);
46 
47  // display dialog
48  qM3C2Dialog dlg(cloud1, cloud2, nullptr);
49  if (!dlg.loadParamsFromFile(paramFilename)) {
50  return false;
51  }
52  dlg.setCorePointsCloud(corePointsCloud);
53 
54  QString errorMessage;
55  ccPointCloud* outputCloud =
56  nullptr; // only necessary for the command line version in fact
57  if (!qM3C2Process::Compute(dlg, errorMessage, outputCloud,
58  !cmd.silentMode(), cmd.widgetParent())) {
59  return cmd.error(errorMessage);
60  }
61 
62  if (outputCloud) {
63  CLCloudDesc cloudDesc(
64  outputCloud,
65  cmd.clouds()[0].basename + QObject::tr("_M3C2"),
66  cmd.clouds()[0].path);
67  if (cmd.autoSaveMode()) {
68  QString errorStr = cmd.exportEntity(
69  cloudDesc, QString(), 0,
71  if (!errorStr.isEmpty()) {
72  cmd.error(errorStr);
73  }
74  }
75  // add cloud to the current pool
76  cmd.clouds().push_back(cloudDesc);
77  }
78 
79  return true;
80  }
81 };
Command line interface.
virtual QStringList & arguments()=0
Returns the list of arguments.
virtual void print(const QString &message) const =0
virtual bool error(const QString &message) const =0
bool silentMode() const
Returns the silent mode.
virtual QString exportEntity(CLEntityDesc &entityDesc, const QString &suffix=QString(), QString *outputFilename=nullptr, ccCommandLineInterface::ExportOptions options=ExportOption::NoOptions)=0
Exports a cloud or a mesh.
virtual QDialog * widgetParent()
Returns a (widget) parent (if any is available)
virtual std::vector< CLCloudDesc > & clouds()
Currently opened point clouds and their filename.
static ccPointCloud * ToPointCloud(ccHObject *obj, bool *isLockedVertices=nullptr)
Converts current object to 'equivalent' ccPointCloud.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
M3C2 plugin's main dialog.
Definition: qM3C2Dialog.h:22
void setCorePointsCloud(ccPointCloud *cloud)
Sets the core points cloud.
Definition: qM3C2Dialog.h:44
bool loadParamsFromFile(QString filename)
Loads parameters from persistent settings.
static bool Compute(const qM3C2Dialog &dlg, QString &errorMessage, ccPointCloud *&outputCloud, bool allowDialogs, QWidget *parentWidget=nullptr, ecvMainAppInterface *app=nullptr)
static const char COMMAND_M3C2[]
Definition: qM3C2Commands.h:16
Loaded cloud description.
virtual bool process(ccCommandLineInterface &cmd) override
Main process.
Definition: qM3C2Commands.h:21
Command(const QString &name, const QString &keyword)
Default constructor.