ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ecvCommandLineInterface.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 #include "CVPluginAPI.h"
11 
12 // qCC_db
13 #include <ecvPointCloud.h>
14 
15 // qCC_io
16 #include <FileIOFilter.h>
17 
18 // Qt
19 #include <QSharedPointer>
20 #include <QString>
21 #include <QStringList>
22 
23 // System
24 #include <vector>
25 
26 class ccGenericMesh;
27 class ecvProgressDialog;
28 
29 class QDialog;
30 
31 enum class CL_ENTITY_TYPE { GROUP, CLOUD, MESH };
32 
35  QString basename;
36  QString path;
38 
39  CLEntityDesc(const QString& name);
40  CLEntityDesc(const QString& filename, int _indexInFile);
41  CLEntityDesc(const QString& _basename,
42  const QString& _path,
43  int _indexInFile = -1);
44 
45  virtual ~CLEntityDesc() = default;
46 
47  virtual ccHObject* getEntity() = 0;
48  virtual const ccHObject* getEntity() const = 0;
49  virtual CL_ENTITY_TYPE getCLEntityType() const = 0;
50 };
51 
55 
56  CLGroupDesc(ccHObject* group,
57  const QString& basename,
58  const QString& path = QString());
59 
60  ~CLGroupDesc() override = default;
61 
62  ccHObject* getEntity() override;
63  const ccHObject* getEntity() const override;
64  CL_ENTITY_TYPE getCLEntityType() const override;
65 };
66 
70 
71  CLCloudDesc();
72 
74  const QString& filename = QString(),
75  int index = -1);
76 
78  const QString& basename,
79  const QString& path,
80  int index = -1);
81 
82  ~CLCloudDesc() override = default;
83 
84  ccHObject* getEntity() override;
85  const ccHObject* getEntity() const override;
86  CL_ENTITY_TYPE getCLEntityType() const override;
87 };
88 
92 
93  CLMeshDesc();
94 
96  const QString& filename = QString(),
97  int index = -1);
98 
100  const QString& basename,
101  const QString& path,
102  int index = -1);
103 
104  ~CLMeshDesc() override = default;
105 
106  ccHObject* getEntity() override;
107  const ccHObject* getEntity() const override;
108  CL_ENTITY_TYPE getCLEntityType() const override;
109 };
110 
113 public: // constructor
116 
117  virtual ~ccCommandLineInterface() = default;
118 
119  enum class ExportOption {
120  NoOptions = 0x0,
121  ForceCloud = 0x1,
122  ForceMesh = 0x2,
123  ForceHierarchy = 0x4,
124  ForceNoTimestamp = 0x8
125  };
126  Q_DECLARE_FLAGS(ExportOptions, ExportOption)
127 
128 public: // commands
132  using Shared = QSharedPointer<Command>;
133 
135  Command(const QString& name, const QString& keyword);
136 
137  virtual ~Command() = default;
138 
140  virtual bool process(ccCommandLineInterface& cmd) = 0;
141 
143  QString m_name;
145  QString m_keyword;
146  };
147 
149  static bool IsCommand(const QString& token, const char* command);
150 
151 public: // virtual methods
153 
155  virtual bool registerCommand(Command::Shared command) = 0;
156 
158  virtual QString getExportFilename(const CLEntityDesc& entityDesc,
159  QString extension = QString(),
160  QString suffix = QString(),
161  QString* baseOutputFilename = nullptr,
162  bool forceNoTimestamp = false) const = 0;
163 
165 
167  virtual QString exportEntity(CLEntityDesc& entityDesc,
168  const QString& suffix = QString(),
169  QString* outputFilename = nullptr,
170  ccCommandLineInterface::ExportOptions options =
171  ExportOption::NoOptions) = 0;
172 
174 
178  virtual bool saveClouds(QString suffix = QString(),
179  bool allAtOnce = false,
180  const QString* allAtOnceFileName = nullptr) = 0;
181 
183 
187  virtual bool saveMeshes(QString suffix = QString(),
188  bool allAtOnce = false,
189  const QString* allAtOnceFileName = nullptr) = 0;
190 
192  virtual void removeClouds(bool onlyLast = false) = 0;
193 
195  virtual void removeMeshes(bool onlyLast = false) = 0;
196 
198  virtual QStringList& arguments() = 0;
200  virtual const QStringList& arguments() const = 0;
201 
203  virtual ecvProgressDialog* progressDialog();
205  virtual QDialog* widgetParent();
206 
207 public: // file I/O
208  // Extended file loading parameters
212 
215  };
216 
218  virtual CLLoadParameters& fileLoadingParams();
219 
222  enum Mode {
226  CUSTOM_GLOBAL_SHIFT
227  };
228 
229  Mode mode = NO_GLOBAL_SHIFT;
231  };
232 
234 
237  virtual bool importFile(
238  QString filename,
239  const GlobalShiftOptions& globalShiftOptions,
240  FileIOFilter::Shared filter = FileIOFilter::Shared(nullptr)) = 0;
241 
243  virtual QString cloudExportFormat() const = 0;
245  virtual QString cloudExportExt() const = 0;
246 
248  virtual QString meshExportFormat() const = 0;
250  virtual QString meshExportExt() const = 0;
251 
253  virtual QString hierarchyExportFormat() const = 0;
256  virtual QString hierarchyExportExt() const = 0;
257 
259  virtual void setCloudExportFormat(QString format, QString ext) = 0;
261  virtual void setMeshExportFormat(QString format, QString ext) = 0;
263  virtual void setHierarchyExportFormat(QString format, QString ext) = 0;
264 
265 public: // logging
266  // logging
267  virtual void print(const QString& message) const = 0;
268  virtual void warning(const QString& message) const = 0;
269  virtual bool error(
270  const QString& message) const = 0; // must always return false!
271 
272 public: // access to data
274  virtual std::vector<CLCloudDesc>& clouds();
276  virtual const std::vector<CLCloudDesc>& clouds() const;
277 
279  virtual std::vector<CLMeshDesc>& meshes();
281  virtual const std::vector<CLMeshDesc>& meshes() const;
282 
284 
285  void toggleSilentMode(bool state);
287  bool silentMode() const;
288 
291  void toggleAutoSaveMode(bool state);
294  bool autoSaveMode() const;
295 
298  void toggleAddTimestamp(bool state);
301  bool addTimestamp() const;
302 
304  void setNumericalPrecision(int p);
306  int numericalPrecision() const;
307 
308 public: // Global shift management
310  bool nextCommandIsGlobalShift() const;
311 
315 
318  bool processGlobalShiftCommand(GlobalShiftOptions& options);
319 
320 protected: // members
322  std::vector<CLCloudDesc> m_clouds;
323 
325  std::vector<CLMeshDesc> m_meshes;
326 
329 
332 
335 
338 
341 };
#define CVPLUGIN_LIB_API
Definition: CVPluginAPI.h:15
std::string filename
filament::Texture::InternalFormat format
std::string name
QSharedPointer< FileIOFilter > Shared
Shared type.
Definition: FileIOFilter.h:97
Command line interface.
virtual QString hierarchyExportExt() const =0
virtual QString cloudExportExt() const =0
Returns the current cloud(s) export extension (warning: can be anything)
int m_precision
Default numerical precision for ASCII output.
virtual QStringList & arguments()=0
Returns the list of arguments.
virtual bool saveClouds(QString suffix=QString(), bool allAtOnce=false, const QString *allAtOnceFileName=nullptr)=0
Saves all clouds.
virtual void warning(const QString &message) const =0
std::vector< CLMeshDesc > m_meshes
Currently opened meshes and their filename.
virtual QString hierarchyExportFormat() const =0
Returns the current hierarchy(ies) export format.
virtual const QStringList & arguments() const =0
Returns the list of arguments (const version)
virtual void print(const QString &message) const =0
virtual QString meshExportExt() const =0
Returns the current mesh(es) export extension (warning: can be anything)
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.
std::vector< CLCloudDesc > m_clouds
Currently opened point clouds and their filename.
virtual QString getExportFilename(const CLEntityDesc &entityDesc, QString extension=QString(), QString suffix=QString(), QString *baseOutputFilename=nullptr, bool forceNoTimestamp=false) const =0
Returns the name of a to-be-exported entity.
virtual bool error(const QString &message) const =0
virtual QString meshExportFormat() const =0
Returns the current mesh(es) export format.
virtual QString cloudExportFormat() const =0
Returns the current cloud(s) export format.
CLLoadParameters m_loadingParameters
File loading parameters.
virtual bool importFile(QString filename, const GlobalShiftOptions &globalShiftOptions, FileIOFilter::Shared filter=FileIOFilter::Shared(nullptr))=0
Loads a file with a specific filter.
virtual void setCloudExportFormat(QString format, QString ext)=0
Sets the current cloud(s) export format and extension.
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 bool registerCommand(Command::Shared command)=0
Registers a new command.
virtual void removeClouds(bool onlyLast=false)=0
Removes all clouds (or only the last one ;)
virtual void removeMeshes(bool onlyLast=false)=0
Removes all meshes (or only the last one ;)
virtual bool saveMeshes(QString suffix=QString(), bool allAtOnce=false, const QString *allAtOnceFileName=nullptr)=0
Saves all meshes.
virtual ~ccCommandLineInterface()=default
virtual void setHierarchyExportFormat(QString format, QString ext)=0
Sets the current hierarchy(ies) export format and extension.
virtual void setMeshExportFormat(QString format, QString ext)=0
Sets the current mesh(es) export format and extension.
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
Loaded cloud description.
~CLCloudDesc() override=default
ccPointCloud * pc
Loaded entity description.
virtual CL_ENTITY_TYPE getCLEntityType() const =0
virtual ccHObject * getEntity()=0
virtual ~CLEntityDesc()=default
virtual const ccHObject * getEntity() const =0
Loaded group description.
ccHObject * groupEntity
~CLGroupDesc() override=default
Loaded mesh description.
ccGenericMesh * mesh
~CLMeshDesc() override=default
Generic loading parameters.
Definition: FileIOFilter.h:51
QSharedPointer< Command > Shared
Shared type.
virtual bool process(ccCommandLineInterface &cmd)=0
Main process.