From 1fc07c2b662aad7aa481a4efe92ff8875ce5f880 Mon Sep 17 00:00:00 2001 From: Daniel Girardeau-Montaut Date: Fri, 22 Mar 2019 15:02:28 +0100 Subject: [PATCH] MEDIAN stat operation added --- FeaturesInterface.h | 3 +++ PointFeature.cpp | 20 ++++++++++++++++++-- q3DMASCTools.cpp | 5 +++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/FeaturesInterface.h b/FeaturesInterface.h index 788d90a..be5703c 100644 --- a/FeaturesInterface.h +++ b/FeaturesInterface.h @@ -65,6 +65,7 @@ namespace masc NO_STAT, MEAN, MODE, //number with the highest frequency + MEDIAN, STD, RANGE, SKEW //(SKEW = (MEAN - MODE)/STD) @@ -78,6 +79,8 @@ namespace masc return "MEAN"; case MODE: return "MODE"; + case MEDIAN: + return "MEDIAN"; case STD: return "STD"; case RANGE: diff --git a/PointFeature.cpp b/PointFeature.cpp index 6892dd0..3eaee21 100644 --- a/PointFeature.cpp +++ b/PointFeature.cpp @@ -372,7 +372,7 @@ static bool ExtractStatFromSF( const CCVector3& queryPoint, else { bool withSums = (stat == Feature::MEAN || stat == Feature::STD); - bool storeValues = (stat == Feature::MODE || stat == Feature::SKEW); + bool storeValues = (stat == Feature::MEDIAN || stat == Feature::MODE || stat == Feature::SKEW); double sum = 0.0; double sum2 = 0.0; @@ -424,6 +424,14 @@ static bool ExtractStatFromSF( const CCVector3& queryPoint, } break; + case Feature::MEDIAN: + { + size_t medianIndex = values.size() / 2; + std::nth_element(values.begin(), values.begin() + medianIndex, values.end()); + outputValue = values[medianIndex]; + } + break; + case Feature::STD: { outputValue = sqrt(std::abs(sum2 * kNN - sum * sum)) / kNN; @@ -670,7 +678,7 @@ bool PointFeature::computeStat(const CCLib::DgmOctree::NeighboursSet& pointsInNe else { bool withSums = (stat == Feature::MEAN || stat == Feature::STD); - bool storeValues = (stat == Feature::MODE || stat == Feature::SKEW); + bool storeValues = (stat == Feature::MEDIAN || stat == Feature::MODE || stat == Feature::SKEW); double sum = 0.0; double sum2 = 0.0; @@ -722,6 +730,14 @@ bool PointFeature::computeStat(const CCLib::DgmOctree::NeighboursSet& pointsInNe } break; + case Feature::MEDIAN: + { + size_t medianIndex = values.size() / 2; + std::nth_element(values.begin(), values.begin() + medianIndex, values.end()); + outputValue = values[medianIndex]; + } + break; + case Feature::STD: { outputValue = sqrt(std::abs(sum2 * kNN - sum * sum)) / kNN; diff --git a/q3DMASCTools.cpp b/q3DMASCTools.cpp index 991f366..0a477d2 100644 --- a/q3DMASCTools.cpp +++ b/q3DMASCTools.cpp @@ -269,6 +269,11 @@ static bool CreateFeaturesFromCommand(const QString& command, int lineNumber, co feature->stat = Feature::MODE; statDefined = true; } + else if (token == "MEDIAN") + { + feature->stat = Feature::MEDIAN; + statDefined = true; + } else if (token == "STD") { feature->stat = Feature::STD;