diff --git a/Navigator/src/Navigator/Histogram.cpp b/Navigator/src/Navigator/Histogram.cpp new file mode 100644 index 0000000..bfd6e08 --- /dev/null +++ b/Navigator/src/Navigator/Histogram.cpp @@ -0,0 +1,128 @@ +#include "Histogram.h" +#include "implot.h" + +/* + For Navigator histograms, binnning is done over ranges as + [min, max), so that each bin is exclusive. +*/ + +namespace Navigator { + + /* + 1D Histogram class + */ + Histogram1D::Histogram1D(const std::string& name, const std::string& param, int bins, double min, double max) : + Histogram(name, param), m_nBins(bins), m_xMin(min), m_xMax(max) + { + InitBins(); + } + + Histogram1D::~Histogram1D() {} + + void Histogram1D::InitBins() + { + if(m_nBins == 0 || (m_xMin >= m_xMax)) + { + NAV_WARN("Attempting to create an illegal Histogram1D {0} with {1} bins and a range from {2} to {3}. Historgram not initialized.", m_name, m_nBins, m_xMin, m_xMax); + m_initFlag = false; + return; + } + + m_binWidth = (m_xMax - m_xMin)/m_nBins; + + m_binCenters.resize(m_nBins); + m_binCounts.resize(m_nBins); + + for(int i=0; i= m_xMax || !m_initFlag) + return; + + int bin = int((x - m_xMin)/(m_binWidth)); + + m_binCounts[bin] += 1.0; + } + + //Can only be used within an ImGui / ImPlot context!! + void Histogram1D::Draw() + { + ImPlot::PlotBars(m_name.c_str(), &m_binCenters.data()[0], &m_binCounts.data()[0], m_nBins, m_binWidth); + } + + void Histogram1D::ClearData() + { + for(int i=0; i= m_xMax || m_yMin >= m_yMax) + { + NAV_WARN("Attempting to create illegal Histogram2D {0} with {1} x bins, {2} y bins, an x range of {3} to {4}, and a y range of {5} to {6}. Not initialized.", m_name, m_nXBins, m_nYBins, + m_xMin, m_xMax, m_yMin, m_yMax); + m_initFlag = false; + return; + } + + m_binWidthX = (m_xMax - m_xMin)/m_nXBins; + m_binWidthY = (m_yMax - m_yMin)/m_nYBins; + + m_nBins = m_nXBins*m_nYBins; + + m_binCounts.resize(m_nBins); + for(int i=0; i= m_xMax || y < m_yMin || y >= m_yMax || !m_initFlag) + return; + + int bin_x = int((x - m_xMin)/m_binWidthX); + int bin_y = int((y - m_yMin)/m_binWidthY); + int bin = bin_y*m_nXBins + bin_x; + + m_binCounts[bin] += 1.0; + + m_maxBinContent = m_binCounts[bin] > m_maxBinContent ? m_binCounts[bin] : m_maxBinContent; + } + + //Can only be used within an ImGui / ImPlot context!! + void Histogram2D::Draw() + { + ImPlot::PlotHeatmap(m_name.c_str(), &m_binCounts.data()[0], m_nYBins, m_nXBins, 0, m_maxBinContent, NULL, ImPlotPoint(m_xMin, m_yMin), ImPlotPoint(m_xMax, m_yMax)); + } + + void Histogram2D::ClearData() + { + for(int i=0; i m_binCenters; + std::vector m_binCounts; + int m_nBins; + double m_binWidth; + double m_xMin; + double m_xMax; + }; + + class Histogram2D : public Histogram + { + public: + Histogram2D(const std::string& name, const std::string& param_x, const std::string& param_y, int bins_x, double min_x, double max_x, + int bins_y, double min_y, double max_y); + virtual ~Histogram2D(); + virtual void FillData(double x, double y=0) override; + virtual void Draw() override; + virtual void ClearData() override; + + private: + void InitBins(); + + std::vector m_binCounts; + int m_nBins; + int m_nXBins; + int m_nYBins; + double m_xMin; + double m_xMax; + double m_yMin; + double m_yMax; + double m_binWidthY; + double m_binWidthX; + double m_maxBinContent; + }; + +} + +#endif \ No newline at end of file diff --git a/Navigator/src/Navigator/ParameterMap.h b/Navigator/src/Navigator/ParameterMap.h new file mode 100644 index 0000000..e687994 --- /dev/null +++ b/Navigator/src/Navigator/ParameterMap.h @@ -0,0 +1,49 @@ +#ifndef PARAMETER_MAP_H +#define PARAMETER_MAP_H + +namespace Navigator { + + struct ParameterData + { + double value = 0; + bool validFlag = false; + }; + + class NavParameter + { + + public: + NavParameter(const std::string& name, const std::string& alias); + ~NavParameter(); + + inline void SetValue(double value) { p.value = value; } + + private: + std::string name; + ParameterData p; + + }; + + class ParameterMap + { + + public: + ParameterMap(); + ~ParameterMap(); + inline void AddParameter(const std::string& name) { m_map[name] = nullptr; } + inline void SetParameter(const std::string& name, ParameterData* param) { m_map[name] = param; } + double GetParameterValue(const std::string& name); + void ResetParameters(); + + inline static ParameterMap& GetParameterMap() { return s_map; } + + private: + std::unordered_map m_map; + static ParameterMap s_map; + + }; + + ParameterMap* CreateParameterMap(); +} + +#endif \ No newline at end of file