diff --git a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeArrayStatistics.cpp b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeArrayStatistics.cpp index 94e347512f..9a8c268dca 100644 --- a/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeArrayStatistics.cpp +++ b/src/Plugins/SimplnxCore/src/SimplnxCore/Filters/Algorithms/ComputeArrayStatistics.cpp @@ -251,7 +251,7 @@ class ComputeArrayStatisticsByIndexImpl HistogramUtilities::serial::FillBinRanges(ranges, std::make_pair(histMin, histMax), m_NumBins); - const T increment = (histMax - histMin) / (m_NumBins); + const float32 increment = HistogramUtilities::serial::CalculateIncrement(histMin, histMax, m_NumBins); if(std::fabs(increment) < 1E-10) { histogram[0] = length[localFeatureIndex]; @@ -273,63 +273,38 @@ class ComputeArrayStatisticsByIndexImpl continue; } const T value = m_Source[i]; - const auto bin = static_cast(static_cast(HistogramUtilities::serial::CalculateBin(value, histMin, increment))); // find bin for this input array value + const auto bin = static_cast(HistogramUtilities::serial::CalculateBin(value, histMin, increment)); // find bin for this input array value if((bin >= 0) && (bin < m_NumBins)) // make certain bin is in range { - ++histogram[bin]; // increment histogram element corresponding to this input array value - } - else if(value == histMax) - { - histogram[m_NumBins - 1]++; + histogram[bin]++; // increment histogram element corresponding to this input array value } } // end of numTuples loop } // end of increment else if(m_ModalBinRanges) { - bool skip = false; - if constexpr(std::is_floating_point_v) + if(std::fabs(increment) < 1E-10) { - if(m_HistFullRange && std::fabs(increment) < 1E-10) - { - m_ModalBinRangesArray->addEntry(j, histMin); - m_ModalBinRangesArray->addEntry(j, histMax); - - skip = true; - } + m_ModalBinRangesArray->addEntry(j, histMin); + m_ModalBinRangesArray->addEntry(j, histMax); } else - { - if(m_HistFullRange && increment == 0) - { - m_ModalBinRangesArray->addEntry(j, histMin); - m_ModalBinRangesArray->addEntry(j, histMax); - - skip = true; - } - } - - if(!skip) { auto modeList = m_ModeArray->getList(j); for(int i = 0; i < modeList->size(); i++) { const T mode = modeList->at(i); const auto modalBin = HistogramUtilities::serial::CalculateBin(mode, histMin, increment); - T minBinValue; - T maxBinValue; if((modalBin >= 0) && (modalBin < m_NumBins)) // make certain bin is in range { - minBinValue = static_cast(histMin + (modalBin * increment)); - maxBinValue = static_cast(histMin + ((modalBin + 1) * increment)); + m_ModalBinRangesArray->addEntry(j, static_cast(histMin + (modalBin * increment))); + m_ModalBinRangesArray->addEntry(j, static_cast(histMin + ((modalBin + 1) * increment))); } else if(mode == histMax) { - minBinValue = static_cast(histMin + ((modalBin - 1) * increment)); - maxBinValue = static_cast(histMin + (modalBin * increment)); + m_ModalBinRangesArray->addEntry(j, static_cast(histMin + ((modalBin - 1) * increment))); + m_ModalBinRangesArray->addEntry(j, static_cast(histMin + (modalBin * increment))); } - m_ModalBinRangesArray->addEntry(j, minBinValue); - m_ModalBinRangesArray->addEntry(j, maxBinValue); } } } diff --git a/src/simplnx/Utilities/HistogramUtilities.hpp b/src/simplnx/Utilities/HistogramUtilities.hpp index 802ddd8364..9654b51a44 100644 --- a/src/simplnx/Utilities/HistogramUtilities.hpp +++ b/src/simplnx/Utilities/HistogramUtilities.hpp @@ -9,6 +9,12 @@ namespace nx::core::HistogramUtilities { namespace serial { +template +float32 CalculateIncrement(Type min, Type max, int32 numBins) +{ + return static_cast(max - min) / static_cast(numBins); +} + /** * @function FillBinRange * @brief This function fills a container that is STL compatible and has a bracket operator defined with the bin ranges in the following pattern: @@ -21,7 +27,7 @@ namespace serial * @param increment this is the uniform size of the bins */ template -void FillBinRanges(Container& outputContainer, const std::pair& rangeMinMax, const int32 numBins, const Type increment) +void FillBinRanges(Container& outputContainer, const std::pair& rangeMinMax, const int32 numBins, const float32 increment) { // WARNING: No bounds checking for type compatibility, it is expected to be done higher up where the type is not abstracted // EXPECTED CONTAINER SIZE: numBins + 1 @@ -57,15 +63,15 @@ void FillBinRanges(Container& outputContainer, const std::pair& rang // DEV NOTE: this function also serves to act as a jumping off point for implementing logarithmic histograms down the line // Uniform Bin Sizes - const Type increment = (rangeMinMax.second - rangeMinMax.first) / static_cast(numBins); + const float32 increment = CalculateIncrement(rangeMinMax.first, rangeMinMax.second, numBins); FillBinRanges(outputContainer, rangeMinMax, numBins, increment); } template -Type CalculateBin(Type value, Type min, Type increment) +Type CalculateBin(Type value, Type min, float32 increment) { - return std::floor((value - min) / increment); + return static_cast(std::floor(static_cast(value - min) / increment)); } /** @@ -119,7 +125,7 @@ Result<> GenerateHistogram(const InputContainer& inputStore, OutputContain } } - const Type increment = (rangeMinMax.second - rangeMinMax.first) / static_cast(numBins); + const float32 increment = CalculateIncrement(rangeMinMax.first, rangeMinMax.second, numBins); // Fill Bins FillBinRanges(binRangesStore, rangeMinMax, numBins, increment); @@ -202,7 +208,7 @@ Result<> GenerateHistogramAtComponent(const AbstractDataStore& inputStore, } } - const Type increment = (rangeMinMax.second - rangeMinMax.first) / static_cast(numBins); + const float32 increment = CalculateIncrement(rangeMinMax.first, rangeMinMax.second, numBins); // Fill Bins FillBinRanges(binRangesStore, rangeMinMax, numBins, increment);