Debian Codegraph @

plugins/core/Standard/qCanupo/include/qCanupoCommands.h

raw
1 //##########################################################################
2 //# #
3 //# CLOUDCOMPARE PLUGIN: qCANUPO #
4 //# #
5 //# This program is free software; you can redistribute it and/or modify #
6 //# it under the terms of the GNU General Public License as published by #
7 //# the Free Software Foundation; version 2 or later of the License. #
8 //# #
9 //# This program is distributed in the hope that it will be useful, #
10 //# but WITHOUT ANY WARRANTY; without even the implied warranty of #
11 //# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
12 //# GNU General Public License for more details. #
13 //# #
14 //# COPYRIGHT: UEB (UNIVERSITE EUROPEENNE DE BRETAGNE) / CNRS #
15 //# #
16 //##########################################################################
17
18 #ifndef CANUPO_PLUGIN_COMMANDS_HEADER
19 #define CANUPO_PLUGIN_COMMANDS_HEADER
20
21 //CloudCompare
22 #include "ccCommandLineInterface.h"
23
24 //Local
25 #include "qCanupoProcess.h"
26
27 static const char COMMAND_CANUPO_CALSSIFY[] = "CANUPO_CLASSIFY";
28 static const char COMMAND_CANUPO_CONFIDENCE[] = "USE_CONFIDENCE";
29
30 struct CommandCanupoClassif : public ccCommandLineInterface::Command
31 {
32 CommandCanupoClassif() : ccCommandLineInterface::Command("Canupo Classify", COMMAND_CANUPO_CALSSIFY) {}
33
34 virtual bool process(ccCommandLineInterface& cmd) override
35 {
36 cmd.print("[CANUPO]");
37 if (cmd.arguments().empty())
38 {
39 return cmd.error(QString("Missing parameter: classifier filename (.prm) after \"-%1\"").arg(COMMAND_CANUPO_CALSSIFY));
40 }
41
42 qCanupoProcess::ClassifyParams params;
43 params.confidenceThreshold = 0.0;
44 params.generateAdditionalSF = false;
45 params.generateRoughnessSF = false;
46 params.samplingDist = 0.0;
47 params.useActiveSFForConfidence = false;
48
49 QString classifierFilename;
50
51 //optional parameter
52 while (!cmd.arguments().empty())
53 {
54 QString argument = cmd.arguments().front();
55 if (ccCommandLineInterface::IsCommand(argument, COMMAND_CANUPO_CONFIDENCE))
56 {
57 //local option confirmed, we can move on
58 cmd.arguments().pop_front();
59
60 if (cmd.arguments().empty())
61 {
62 return cmd.error(QString("Missing parameter: confidence threshold after '%1'").arg(COMMAND_CANUPO_CONFIDENCE));
63 }
64
65 bool ok;
66 params.confidenceThreshold = cmd.arguments().takeFirst().toDouble(&ok);
67 if (!ok || params.confidenceThreshold < 0.0)
68 {
69 return cmd.error(QString("Invalid parameter: confidence threshold after '%1'").arg(COMMAND_CANUPO_CONFIDENCE));
70 }
71
72 cmd.print(QString("Confidence threshold set to %1").arg(params.confidenceThreshold));
73 }
74 else
75 {
76 //we assume the parameter is the classifier filename
77 classifierFilename = argument;
78 cmd.arguments().pop_front();
79 break;
80 }
81 }
82
83 if (classifierFilename.isEmpty())
84 {
85 return cmd.error("Classifier name not set");
86 }
87
88 if (cmd.clouds().empty())
89 {
90 return cmd.error("Need at least At least one cloud must be loaded");
91 }
92
93 for (CLCloudDesc& desc : cmd.clouds())
94 {
95 CorePointDescSet corePointsDescriptors; //core point descriptors
96 ccPointCloud* realCorePoints = desc.pc;
97 CCCoreLib::GenericIndexedCloudPersist* corePoints = realCorePoints;
98
99 //has the current cloud an active SF?
100 int currentSFIndex = desc.pc->getCurrentDisplayedScalarFieldIndex();
101 if (currentSFIndex >= 0)
102 {
103 desc.pc->setCurrentDisplayedScalarField(currentSFIndex);
104 params.useActiveSFForConfidence = true;
105 }
106 else
107 {
108 params.useActiveSFForConfidence = false;
109 }
110
111 if (qCanupoProcess::Classify(classifierFilename, params, desc.pc, corePoints, corePointsDescriptors, realCorePoints, nullptr, nullptr, cmd.silentMode()))
112 {
113 if (cmd.autoSaveMode())
114 {
115 QString errorStr = cmd.exportEntity(desc, "CLASSIFIED");
116 if (!errorStr.isEmpty())
117 {
118 return cmd.error(errorStr);
119 }
120 }
121 }
122 else
123 {
124 //process failed
125 break;
126 }
127 }
128
129 return true;
130 }
131 };
132
133 #endif //CANUPO_PLUGIN_COMMANDS_HEADER