qCanupoCommands.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #ifndef CANUPO_PLUGIN_COMMANDS_HEADER
  18. #define CANUPO_PLUGIN_COMMANDS_HEADER
  19. //CloudCompare
  20. #include "ccCommandLineInterface.h"
  21. //Local
  22. #include "qCanupoProcess.h"
  23. static const char COMMAND_CANUPO_CALSSIFY[] = "CANUPO_CLASSIFY";
  24. static const char COMMAND_CANUPO_CONFIDENCE[] = "USE_CONFIDENCE";
  25. struct CommandCanupoClassif : public ccCommandLineInterface::Command
  26. {
  27. CommandCanupoClassif() : ccCommandLineInterface::Command("Canupo Classify", COMMAND_CANUPO_CALSSIFY) {}
  28. virtual bool process(ccCommandLineInterface& cmd) override
  29. {
  30. cmd.print("[CANUPO]");
  31. if (cmd.arguments().empty())
  32. {
  33. return cmd.error(QString("Missing parameter: classifier filename (.prm) after \"-%1\"").arg(COMMAND_CANUPO_CALSSIFY));
  34. }
  35. qCanupoProcess::ClassifyParams params;
  36. params.confidenceThreshold = 0.0;
  37. params.generateAdditionalSF = false;
  38. params.generateRoughnessSF = false;
  39. params.samplingDist = 0.0;
  40. params.useActiveSFForConfidence = false;
  41. QString classifierFilename;
  42. //optional parameter
  43. while (!cmd.arguments().empty())
  44. {
  45. QString argument = cmd.arguments().front();
  46. if (ccCommandLineInterface::IsCommand(argument, COMMAND_CANUPO_CONFIDENCE))
  47. {
  48. //local option confirmed, we can move on
  49. cmd.arguments().pop_front();
  50. if (cmd.arguments().empty())
  51. {
  52. return cmd.error(QString("Missing parameter: confidence threshold after '%1'").arg(COMMAND_CANUPO_CONFIDENCE));
  53. }
  54. bool ok;
  55. params.confidenceThreshold = cmd.arguments().takeFirst().toDouble(&ok);
  56. if (!ok || params.confidenceThreshold < 0.0)
  57. {
  58. return cmd.error(QString("Invalid parameter: confidence threshold after '%1'").arg(COMMAND_CANUPO_CONFIDENCE));
  59. }
  60. cmd.print(QString("Confidence threshold set to %1").arg(params.confidenceThreshold));
  61. }
  62. else
  63. {
  64. //we assume the parameter is the classifier filename
  65. classifierFilename = argument;
  66. cmd.arguments().pop_front();
  67. break;
  68. }
  69. }
  70. if (classifierFilename.isEmpty())
  71. {
  72. return cmd.error("Classifier name not set");
  73. }
  74. if (cmd.clouds().empty())
  75. {
  76. return cmd.error("Need at least At least one cloud must be loaded");
  77. }
  78. for (CLCloudDesc& desc : cmd.clouds())
  79. {
  80. CorePointDescSet corePointsDescriptors; //core point descriptors
  81. ccPointCloud* realCorePoints = desc.pc;
  82. CCCoreLib::GenericIndexedCloudPersist* corePoints = realCorePoints;
  83. //has the current cloud an active SF?
  84. int currentSFIndex = desc.pc->getCurrentDisplayedScalarFieldIndex();
  85. if (currentSFIndex >= 0)
  86. {
  87. desc.pc->setCurrentDisplayedScalarField(currentSFIndex);
  88. params.useActiveSFForConfidence = true;
  89. }
  90. else
  91. {
  92. params.useActiveSFForConfidence = false;
  93. }
  94. if (qCanupoProcess::Classify(classifierFilename, params, desc.pc, corePoints, corePointsDescriptors, realCorePoints, nullptr, nullptr, cmd.silentMode()))
  95. {
  96. if (cmd.autoSaveMode())
  97. {
  98. QString errorStr = cmd.exportEntity(desc, "CLASSIFIED");
  99. if (!errorStr.isEmpty())
  100. {
  101. return cmd.error(errorStr);
  102. }
  103. }
  104. }
  105. else
  106. {
  107. //process failed
  108. break;
  109. }
  110. }
  111. return true;
  112. }
  113. };
  114. #endif //CANUPO_PLUGIN_COMMANDS_HEADER