ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvCommandLineInterface.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 #include <ecvGenericMesh.h>
11 
12 #include <QDir>
13 
14 namespace {
15 constexpr char COMMAND_OPEN_SHIFT_ON_LOAD[] = "GLOBAL_SHIFT";
16 constexpr char COMMAND_OPEN_SHIFT_ON_LOAD_AUTO[] = "AUTO";
17 constexpr char COMMAND_OPEN_SHIFT_ON_LOAD_FIRST[] =
18  "FIRST";
19 } // namespace
20 
22 // CLEntityDesc
23 
25  : basename(name), path(QDir::currentPath()), indexInFile(-1) {}
26 
27 CLEntityDesc::CLEntityDesc(const QString &filename, int _indexInFile)
28  : indexInFile(_indexInFile) {
29  if (filename.isNull()) {
30  basename = "unknown";
31  path = QDir::currentPath();
32  } else {
33  QFileInfo fi(filename);
34  basename = fi.completeBaseName();
35  path = fi.path();
36  }
37 }
38 
39 CLEntityDesc::CLEntityDesc(const QString &_basename,
40  const QString &_path,
41  int _indexInFile)
42  : basename(_basename), path(_path), indexInFile(_indexInFile) {}
43 
45 // CLGroupDesc
46 
48  const QString &basename,
49  const QString &path)
50  : CLEntityDesc(basename, path), groupEntity(group) {}
51 
53 
54 const ccHObject *CLGroupDesc::getEntity() const { return groupEntity; }
55 
57  return CL_ENTITY_TYPE::GROUP;
58 }
59 
61 // CLCloudDesc
62 
63 CLCloudDesc::CLCloudDesc() : CLEntityDesc("Unnamed cloud"), pc(nullptr) {}
64 
66  const QString &filename,
67  int index)
68  : CLEntityDesc(filename, index), pc(cloud) {}
69 
71  const QString &basename,
72  const QString &path,
73  int index)
74  : CLEntityDesc(basename, path, index), pc(cloud) {}
75 
76 ccHObject *CLCloudDesc::getEntity() { return static_cast<ccHObject *>(pc); }
77 
79  return static_cast<ccHObject *>(pc);
80 }
81 
83  return CL_ENTITY_TYPE::CLOUD;
84 }
85 
87 // CLMeshDesc
88 
89 CLMeshDesc::CLMeshDesc() : CLEntityDesc("Unnamed mesh"), mesh(nullptr) {}
90 
91 CLMeshDesc::CLMeshDesc(ccGenericMesh *_mesh, const QString &filename, int index)
92  : CLEntityDesc(filename, index), mesh(_mesh) {}
93 
95  const QString &basename,
96  const QString &path,
97  int index)
98  : CLEntityDesc(basename, path, index), mesh(_mesh) {}
99 
100 ccHObject *CLMeshDesc::getEntity() { return static_cast<ccHObject *>(mesh); }
101 
103  return static_cast<ccHObject *>(mesh);
104 }
105 
107  return CL_ENTITY_TYPE::MESH;
108 }
109 
111 // ccCommandLineInterface
112 
114  : m_silentMode(false),
115  m_autoSaveMode(true),
116  m_addTimestamp(true),
117  m_precision(12) {}
118 
119 bool ccCommandLineInterface::IsCommand(const QString &token,
120  const char *command) {
121  return token.startsWith("-") && token.mid(1).toUpper() == QString(command);
122 }
123 
125 
126 QDialog *ccCommandLineInterface::widgetParent() { return nullptr; }
127 
130  return m_loadingParameters;
131 }
132 
133 std::vector<CLCloudDesc> &ccCommandLineInterface::clouds() { return m_clouds; }
134 
135 const std::vector<CLCloudDesc> &ccCommandLineInterface::clouds() const {
136  return m_clouds;
137 }
138 
139 std::vector<CLMeshDesc> &ccCommandLineInterface::meshes() { return m_meshes; }
140 
141 const std::vector<CLMeshDesc> &ccCommandLineInterface::meshes() const {
142  return m_meshes;
143 }
144 
146  m_silentMode = state;
147 }
148 
150 
152  m_autoSaveMode = state;
153 }
154 
156 
158  m_addTimestamp = state;
159 }
160 
162 
164 
166 
168  return !arguments().empty() &&
169  IsCommand(arguments().front(), COMMAND_OPEN_SHIFT_ON_LOAD);
170 }
171 
173  GlobalShiftOptions &options) {
174  // set default parameters in case of an early exit
176  options.customGlobalShift = CCVector3d(0, 0, 0);
177 
178  if (arguments().empty()) {
179  return error(QObject::tr("Missing parameter: global shift vector or %1 "
180  "or %2 after '%3'")
181  .arg(COMMAND_OPEN_SHIFT_ON_LOAD_AUTO,
182  COMMAND_OPEN_SHIFT_ON_LOAD_FIRST,
183  COMMAND_OPEN_SHIFT_ON_LOAD));
184  }
185 
186  QString firstParam = arguments().takeFirst();
187 
188  if (firstParam.toUpper() == COMMAND_OPEN_SHIFT_ON_LOAD_AUTO) {
190  } else if (firstParam.toUpper() == COMMAND_OPEN_SHIFT_ON_LOAD_FIRST) {
192  } else if (arguments().size() < 2) {
193  return error(QObject::tr("Missing parameter: global shift vector after "
194  "'%1' (3 values expected)")
195  .arg(COMMAND_OPEN_SHIFT_ON_LOAD));
196  } else {
197  bool ok = true;
198  CCVector3d shiftOnLoadVec;
199  shiftOnLoadVec.x = firstParam.toDouble(&ok);
200  if (!ok)
201  return error(QObject::tr("Invalid parameter: X coordinate of the "
202  "global shift vector after '%1'")
203  .arg(COMMAND_OPEN_SHIFT_ON_LOAD));
204  shiftOnLoadVec.y = arguments().takeFirst().toDouble(&ok);
205  if (!ok)
206  return error(QObject::tr("Invalid parameter: Y coordinate of the "
207  "global shift vector after '%1'")
208  .arg(COMMAND_OPEN_SHIFT_ON_LOAD));
209  shiftOnLoadVec.z = arguments().takeFirst().toDouble(&ok);
210  if (!ok)
211  return error(QObject::tr("Invalid parameter: Z coordinate of the "
212  "global shift vector after '%1'")
213  .arg(COMMAND_OPEN_SHIFT_ON_LOAD));
214 
216  options.customGlobalShift = shiftOnLoadVec;
217  }
218 
219  return true;
220 }
221 
223 // ccCommandLineInterface::Command
224 
226  const QString &keyword)
227  : m_name(name), m_keyword(keyword) {}
228 
230 // ccCommandLineInterface::CLLoadParameters
231 
233  : FileIOFilter::LoadParameters(),
234  m_coordinatesShiftEnabled(false),
235  m_coordinatesShift(0, 0, 0) {
237  alwaysDisplayLoadDialog = false;
238  autoComputeNormals = false;
241 }
Vector3Tpl< double > CCVector3d
Double 3D Vector.
Definition: CVGeom.h:804
std::string filename
int size
std::string name
Generic file I/O filter.
Definition: FileIOFilter.h:46
Type y
Definition: CVGeom.h:137
Type x
Definition: CVGeom.h:137
Type z
Definition: CVGeom.h:137
void setNumericalPrecision(int p)
Sets the numerical precision.
int m_precision
Default numerical precision for ASCII output.
virtual QStringList & arguments()=0
Returns the list of arguments.
std::vector< CLMeshDesc > m_meshes
Currently opened meshes and their filename.
bool nextCommandIsGlobalShift() const
Returns whether the nex command is the '-GLOBAL_SHIFT' option.
bool processGlobalShiftCommand(GlobalShiftOptions &options)
bool m_autoSaveMode
Whether files should be automatically saved (after each process) or not.
bool m_addTimestamp
Whether a timestamp should be automatically added to output files or not.
ccCommandLineInterface()
Default constructor.
std::vector< CLCloudDesc > m_clouds
Currently opened point clouds and their filename.
virtual bool error(const QString &message) const =0
static bool IsCommand(const QString &token, const char *command)
Test whether a command line token is a valid command keyword or not.
CLLoadParameters m_loadingParameters
File loading parameters.
void toggleSilentMode(bool state)
Toggles silent mode.
bool silentMode() const
Returns the silent mode.
virtual std::vector< CLMeshDesc > & meshes()
Currently opened meshes and their filename.
virtual ecvProgressDialog * progressDialog()
Returns a (shared) progress dialog (if any is available)
virtual CLLoadParameters & fileLoadingParams()
File loading parameters.
int numericalPrecision() const
Returns the numerical precision.
virtual QDialog * widgetParent()
Returns a (widget) parent (if any is available)
virtual std::vector< CLCloudDesc > & clouds()
Currently opened point clouds and their filename.
Generic mesh interface.
Hierarchical CLOUDVIEWER Object.
Definition: ecvHObject.h:25
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
Graphical progress indicator (thread-safe)
static const std::string path
Definition: PointCloud.cpp:59
ccHObject * getEntity() override
CL_ENTITY_TYPE getCLEntityType() const override
ccPointCloud * pc
Loaded entity description.
CLEntityDesc(const QString &name)
ccHObject * getEntity() override
ccHObject * groupEntity
CLGroupDesc(ccHObject *group, const QString &basename, const QString &path=QString())
CL_ENTITY_TYPE getCLEntityType() const override
ccGenericMesh * mesh
CL_ENTITY_TYPE getCLEntityType() const override
ccHObject * getEntity() override
CCVector3d * coordinatesShift
If applicable, applied shift on load (optional)
Definition: FileIOFilter.h:71
ecvGlobalShiftManager::Mode shiftHandlingMode
How to handle big coordinates.
Definition: FileIOFilter.h:64
bool * coordinatesShiftEnabled
Whether shift on load has been applied after loading (optional)
Definition: FileIOFilter.h:69
Command(const QString &name, const QString &keyword)
Default constructor.