ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
qCanupoCommands.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 "qCanupoProcess.h"
15 
16 static const char COMMAND_CANUPO_CALSSIFY[] = "CANUPO_CLASSIFY";
17 static const char COMMAND_CANUPO_CONFIDENCE[] = "USE_CONFIDENCE";
18 
21  : ccCommandLineInterface::Command("Canupo Classify",
23 
24  virtual bool process(ccCommandLineInterface& cmd) override {
25  cmd.print("[CANUPO]");
26  if (cmd.arguments().empty()) {
27  return cmd.error(QString("Missing parameter: classifier filename "
28  "(.prm) after \"-%1\"")
30  }
31 
33  params.confidenceThreshold = 0.0;
34  params.generateAdditionalSF = false;
35  params.generateRoughnessSF = false;
36  params.samplingDist = 0.0;
37  params.useActiveSFForConfidence = false;
38 
39  QString classifierFilename;
40 
41  // optional parameter
42  while (!cmd.arguments().empty()) {
43  QString argument = cmd.arguments().front();
46  // local option confirmed, we can move on
47  cmd.arguments().pop_front();
48 
49  if (cmd.arguments().empty()) {
50  return cmd.error(QString("Missing parameter: confidence "
51  "threshold after '%1'")
53  }
54 
55  bool ok;
56  params.confidenceThreshold =
57  cmd.arguments().takeFirst().toDouble(&ok);
58  if (!ok || params.confidenceThreshold < 0.0) {
59  return cmd.error(QString("Invalid parameter: confidence "
60  "threshold after '%1'")
62  }
63 
64  cmd.print(QString("Confidence threshold set to %1")
65  .arg(params.confidenceThreshold));
66  } else {
67  // we assume the parameter is the classifier filename
68  classifierFilename = argument;
69  cmd.arguments().pop_front();
70  break;
71  }
72  }
73 
74  if (classifierFilename.isEmpty()) {
75  return cmd.error("Classifier name not set");
76  }
77 
78  if (cmd.clouds().empty()) {
79  return cmd.error("Need at least At least one cloud must be loaded");
80  }
81 
82  for (CLCloudDesc& desc : cmd.clouds()) {
83  CorePointDescSet corePointsDescriptors; // core point descriptors
84  ccPointCloud* realCorePoints = desc.pc;
86  realCorePoints;
87 
88  // has the current cloud an active SF?
89  int currentSFIndex = desc.pc->getCurrentDisplayedScalarFieldIndex();
90  if (currentSFIndex >= 0) {
91  desc.pc->setCurrentDisplayedScalarField(currentSFIndex);
92  params.useActiveSFForConfidence = true;
93  } else {
94  params.useActiveSFForConfidence = false;
95  }
96 
97  if (qCanupoProcess::Classify(classifierFilename, params, desc.pc,
98  corePoints, corePointsDescriptors,
99  realCorePoints, nullptr, nullptr,
100  cmd.silentMode())) {
101  if (cmd.autoSaveMode()) {
102  QString errorStr = cmd.exportEntity(desc, "CLASSIFIED");
103  if (!errorStr.isEmpty()) {
104  return cmd.error(errorStr);
105  }
106  }
107  } else {
108  // process failed
109  break;
110  }
111  }
112 
113  return true;
114  }
115 };
cmdLineReadable * params[]
Set of (core) point descriptors.
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
static bool IsCommand(const QString &token, const char *command)
Test whether a command line token is a valid command keyword or not.
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 std::vector< CLCloudDesc > & clouds()
Currently opened point clouds and their filename.
A 3D cloud and its associated features (color, normals, scalar fields, etc.)
int getCurrentDisplayedScalarFieldIndex() const
Returns the currently displayed scalar field index (or -1 if none)
A generic 3D point cloud with index-based and presistent access to points.
static bool Classify(QString classifierFilename, const ClassifyParams &params, ccPointCloud *cloud, cloudViewer::GenericIndexedCloudPersist *corePoints, CorePointDescSet &corePointsDescriptors, ccPointCloud *realCorePoints=nullptr, ecvMainAppInterface *app=nullptr, QWidget *parentWidget=nullptr, bool silent=false)
Classify a point cloud.
static const char COMMAND_CANUPO_CONFIDENCE[]
static const char COMMAND_CANUPO_CALSSIFY[]
cloudViewer::GenericIndexedCloud * corePoints
Loaded cloud description.
virtual bool process(ccCommandLineInterface &cmd) override
Main process.
Command(const QString &name, const QString &keyword)
Default constructor.