ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
qLASFWFIOCommands.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 
11 
12 // Local
13 #include "LASFWFFilter.h"
14 
15 static const char COMMAND_LOAD_FWF[] = "FWF_O";
16 static const char COMMAND_SAVE_CLOUDS_FWF[] = "FWF_SAVE_CLOUDS";
17 static const char OPTION_ALL_AT_ONCE[] = "ALL_AT_ONCE";
18 static const char OPTION_COMPRESSED[] = "COMPRESSED";
19 
23 
24  virtual bool process(ccCommandLineInterface& cmd) override {
25  cmd.print("[LOADING LAS]");
26  if (cmd.arguments().empty()) {
27  return cmd.error(
28  QString("Missing parameter: filename after \"-%1\"")
29  .arg(COMMAND_LOAD_FWF));
30  }
31 
33  if (cmd.nextCommandIsGlobalShift()) {
34  // local option confirmed, we can move on
35  cmd.arguments().pop_front();
36 
37  if (!cmd.processGlobalShiftCommand(globalShiftOptions)) {
38  // error message already issued
39  return false;
40  }
41  }
42 
43  // open specified file
44  QString filename(cmd.arguments().takeFirst());
45  cmd.print(QString("Opening file: '%1'").arg(filename));
46 
48  FileIOFilter::Shared filter =
50  if (!filter) {
51  return cmd.error(
52  "Internal error: failed to load the LAS FWF I/O filter");
53  }
54 
55  if (!cmd.importFile(filename, globalShiftOptions, filter)) {
56  return false;
57  }
58 
59  return true;
60  }
61 };
62 
65  : ccCommandLineInterface::Command("Save clouds with FWF",
67 
68  virtual bool process(ccCommandLineInterface& cmd) override {
69  bool allAtOnce = false;
70  QString ext = "las";
71 
72  // look for additional parameters
73  while (!cmd.arguments().empty()) {
74  QString argument = cmd.arguments().front();
75 
76  if (argument.toUpper() == OPTION_ALL_AT_ONCE) {
77  // local option confirmed, we can move on
78  cmd.arguments().pop_front();
79  allAtOnce = true;
80  } else if (argument.toUpper() == OPTION_COMPRESSED) {
81  // local option confirmed, we can move on
82  cmd.arguments().pop_front();
83  ext = "laz";
84  } else {
85  break; // as soon as we encounter an unrecognized argument, we
86  // break the local loop to go back to the main one!
87  }
88  }
89 
90  // backup the existing cloud export format first
91  QString previousCloudExportFormat = cmd.cloudExportFormat();
92  QString previousCloudExportExt = cmd.cloudExportExt();
93 
94  // force the export format to LAS FWF
96 
97  bool success = cmd.saveClouds(QString(), allAtOnce);
98 
99  // restore the previous file output format
100  cmd.setCloudExportFormat(previousCloudExportFormat,
101  previousCloudExportExt);
102 
103  return success;
104  }
105 };
std::string filename
CC_FILE_ERROR
Typical I/O filter errors.
Definition: FileIOFilter.h:20
@ CC_FERR_NO_ERROR
Definition: FileIOFilter.h:21
core::Tensor result
Definition: VtkUtils.cpp:76
static Shared GetFilter(const QString &fileFilter, bool onImport)
Returns the filter corresponding to the given 'file filter'.
QSharedPointer< FileIOFilter > Shared
Shared type.
Definition: FileIOFilter.h:97
static QString GetFileFilter()
Definition: LASFWFFilter.h:19
Command line interface.
virtual QString cloudExportExt() const =0
Returns the current cloud(s) export extension (warning: can be anything)
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.
bool nextCommandIsGlobalShift() const
Returns whether the nex command is the '-GLOBAL_SHIFT' option.
bool processGlobalShiftCommand(GlobalShiftOptions &options)
virtual void print(const QString &message) const =0
virtual bool error(const QString &message) const =0
virtual QString cloudExportFormat() const =0
Returns the current cloud(s) export format.
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.
static const char COMMAND_LOAD_FWF[]
static const char OPTION_COMPRESSED[]
static const char OPTION_ALL_AT_ONCE[]
static const char COMMAND_SAVE_CLOUDS_FWF[]
virtual bool process(ccCommandLineInterface &cmd) override
Main process.
virtual bool process(ccCommandLineInterface &cmd) override
Main process.
Command(const QString &name, const QString &keyword)
Default constructor.