From c1f1db5660072fb4f680b0cb082b358bb1a0abf8 Mon Sep 17 00:00:00 2001 From: Daniel Girardeau-Montaut Date: Sun, 30 Jun 2024 17:01:56 +0200 Subject: [PATCH] Syntax improvements --- FeaturesInterface.h | 3 +++ PointFeature.h | 12 ++++++++++-- ScalarFieldWrappers.h | 1 + confusionmatrix.cpp | 32 +++++++++++++++++++++----------- qTrain3DMASCDialog.cpp | 4 +++- 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/FeaturesInterface.h b/FeaturesInterface.h index 6142f6f..6ea2239 100644 --- a/FeaturesInterface.h +++ b/FeaturesInterface.h @@ -166,6 +166,9 @@ namespace masc , sf2WasAlreadyExisting(false) {} + //! Destructor + virtual ~Feature() {} + //! Returns the type (must be reimplemented by child struct) virtual Type getType() const = 0; diff --git a/PointFeature.h b/PointFeature.h index 84fba0e..603c706 100644 --- a/PointFeature.h +++ b/PointFeature.h @@ -99,7 +99,11 @@ namespace masc return "Invalid"; } - static inline PointFeatureType FromString(const QString& token) { return FromUpperString(token.toUpper()); } + static inline PointFeatureType FromString(const QString& token) + { + return FromUpperString(token.toUpper()); + } + static PointFeatureType FromUpperString(const QString& token) { if (token == "INT") @@ -176,6 +180,9 @@ namespace masc } } + //! Destructor + ~PointFeature() override {} + //inherited from Feature virtual Type getType() const override { return Type::PointFeature; } virtual Feature::Shared clone() const override { return Feature::Shared(new PointFeature(*this)); } @@ -209,6 +216,7 @@ namespace masc IScalarFieldWrapper::Shared field2; //! For scaled features - CCCoreLib::ScalarField *statSF1, *statSF2; + CCCoreLib::ScalarField* statSF1; + CCCoreLib::ScalarField* statSF2; }; } diff --git a/ScalarFieldWrappers.h b/ScalarFieldWrappers.h index 236e954..4873169 100644 --- a/ScalarFieldWrappers.h +++ b/ScalarFieldWrappers.h @@ -28,6 +28,7 @@ class IScalarFieldWrapper { public: + virtual ~IScalarFieldWrapper() {} using Shared = QSharedPointer; virtual double pointValue(unsigned index) const = 0; virtual bool isValid() const = 0; diff --git a/confusionmatrix.cpp b/confusionmatrix.cpp index a6a3527..40caeeb 100644 --- a/confusionmatrix.cpp +++ b/confusionmatrix.cpp @@ -16,24 +16,31 @@ #include -QColor getColor(double value, double r1, double g1, double b1) +static QColor GetColor(double value, double r1, double g1, double b1) { - double r0 = 255; - double g0 = 255; - double b0 = 255; + double r0 = 255.0; + double g0 = 255.0; + double b0 = 255.0; if (value < 0.05) + { value = 0.05; - if (value > 0.95) + } + else if (value > 0.95) + { value = 0.95; - int r = int((r1 - r0) * value + r0); - int g = int ((g1 - g0) * value + g0); - int b = int ((b1 - b0) * value + b0); + } + int r = static_cast((r1 - r0) * value + r0); + int g = static_cast((g1 - g0) * value + g0); + int b = static_cast((b1 - b0) * value + b0); // ccLog::Warning("value " + QString::number(value) + " (" + QString::number(r) + ", " + QString::number(g) + ", " + QString::number(b) + ")"); return QColor(r, g, b); } ConfusionMatrix::ConfusionMatrix(const std::vector &actual, const std::vector &predicted) - : ui(new Ui::ConfusionMatrix) + : nbClasses(0) + , ui(new Ui::ConfusionMatrix) + , m_overallAccuracy(0.0f) + { ui->setupUi(this); this->setWindowFlag(Qt::WindowStaysOnTopHint); @@ -50,6 +57,7 @@ ConfusionMatrix::ConfusionMatrix(const std::vector &actual, const st ConfusionMatrix::~ConfusionMatrix() { delete ui; + ui = nullptr; } void ConfusionMatrix::computePrecisionRecallF1Score(cv::Mat& matrix, cv::Mat& precisionRecallF1Score, cv::Mat& vec_TP_FN) @@ -233,10 +241,12 @@ void ConfusionMatrix::compute(const std::vector& actual, const std:: QTableWidgetItem *newItem = new QTableWidgetItem(QString::number(val)); if (row == column) { - newItem->setBackground(getColor(val / vec_TP_FN.at(row, 0), 0, 128, 255)); + newItem->setBackground(GetColor(val / vec_TP_FN.at(row, 0), 0, 128, 255)); } else - newItem->setBackground(getColor(val / vec_TP_FN.at(row, 0), 200, 50, 50)); + { + newItem->setBackground(GetColor(val / vec_TP_FN.at(row, 0), 200, 50, 50)); + } this->ui->tableWidget->setItem(2 + row, + 2 + column, newItem); } diff --git a/qTrain3DMASCDialog.cpp b/qTrain3DMASCDialog.cpp index 1d6fd3e..0d2bd34 100644 --- a/qTrain3DMASCDialog.cpp +++ b/qTrain3DMASCDialog.cpp @@ -293,7 +293,7 @@ bool Train3DMASCDialog::openTraceFile() } } - if (m_traceFile && m_traceFile->isOpen()) + if (m_traceFile->isOpen()) { traceFileConfigured = true; ccLog::Print("save trace in: " + traceFilePath); @@ -302,7 +302,9 @@ bool Train3DMASCDialog::openTraceFile() return true; } else + { return false; + } } bool Train3DMASCDialog::closeTraceFile()