diff --git a/Navigator/src/Navigator/CutMap.cpp b/Navigator/src/Navigator/CutMap.cpp new file mode 100644 index 0000000..e4cb9c8 --- /dev/null +++ b/Navigator/src/Navigator/CutMap.cpp @@ -0,0 +1,42 @@ +#include "CutMap.h" +#include "imgui.h" +#include "implot.h" + +namespace Navigator { + + /*1D Cuts -- Can be made on and applied to either 1D or 2D histograms*/ + Cut1D::Cut1D(const std::string& name, const std::string& xpar, double min, double max) : + Cut(name, xpar), m_minVal(min), m_maxVal(max) + { + } + + Cut1D::~Cut1D() {} + + bool Cut1D::IsInside(double x, double y) const + { + return x >= m_minVal && x <= m_maxVal; + } + + //Only within an ImPlot/ImGui context!!! + void Cut1D::Draw() const + { + double points[2] = { m_minVal, m_maxVal }; + ImPlot::PlotVLines(m_params.name.c_str(), points, 2); + } + + /*2D Cuts -- Can only be made on 2D histogram, but applied to either 1D or 2D histograms*/ + Cut2D::Cut2D(const std::string& name, const std::string& xpar, const std::string& ypar, const std::vector& points) : + Cut(name, xpar, ypar), m_points(points) + { + } + + Cut2D::~Cut2D() {} + + /* + + */ + bool Cut2D::IsInside(double x, double y) const + { + return false; + } +} \ No newline at end of file diff --git a/Navigator/src/Navigator/CutMap.h b/Navigator/src/Navigator/CutMap.h new file mode 100644 index 0000000..53765aa --- /dev/null +++ b/Navigator/src/Navigator/CutMap.h @@ -0,0 +1,109 @@ +#ifndef CUT_MAP_H +#define CUT_MAP_H + +#include "NavCore.h" +#include + +namespace Navigator { + + struct NAV_API CutParams + { + CutParams(const std::string& n, const std::string& x, const std::string& y) : + name(n), x_par(x), y_par(y) + { + } + + std::string name; + std::string x_par; + std::string y_par; + }; + + struct NAV_API Point + { + double x = 0; + double y = 0; + }; + + class NAV_API Cut + { + public: + Cut(const std::string& name, const std::string& xpar, const std::string& ypar="None") : + m_params(name, xpar, ypar) + { + } + + virtual ~Cut() {} + + virtual bool IsInside(double x, double y = 0) const = 0; + virtual void Draw() const = 0; + virtual bool Is1D() const = 0; + virtual bool Is2D() const = 0; + + inline const std::string& GetName() const { return m_params.name; } + inline const std::string& GetXParameter() const { return m_params.x_par; } + inline const std::string& GetYParameter() const { return m_params.y_par; } + inline const CutParams& GetCutParams() const { return m_params }; + protected: + CutParams m_params; + }; + + class NAV_API Cut1D : public Cut + { + public: + Cut1D(const std::string& name, const std::string& xpar, double min, double max); + virtual ~Cut1D(); + virtual bool IsInside(double x, double y = 0) const override; + virtual void Draw() const override; + virtual bool Is1D() const override { return true; } + virtual bool Is2D() const override { return false; } + + private: + double m_minVal, m_maxVal; + }; + + class NAV_API Cut2D : public Cut + { + public: + Cut2D(const std::string& name, const std::string& xpar, const std::string& ypar, const std::vector& points); + virtual ~Cut2D(); + virtual bool IsInside(double x, double y = 0) const override; + virtual void Draw() const override; + virtual bool Is1D() const override { return false; } + virtual bool Is2D() const override { return true; } + + private: + std::vector m_points; + }; + + class NAV_API CutMap + { + public: + CutMap(); + ~CutMap(); + + inline static CutMap& GetInstance() { return *s_instance; } + + inline void AddCut(const std::string& name, const std::string& xpar, double min, double max) + { + std::lock_guard guard(m_cutMutex); + m_map[name].reset(new Cut1D(name, xpar, min, max)); + } + inline void AddCut(const std::string& name, const std::string& xpar, const std::string& ypar, const std::vector& points) + { + std::lock_guard guard(m_cutMutex); + m_map[name].reset(new Cut2D(name, xpar, ypar, points)); + } + + void DrawCut(const std::string& name); + bool IsInsideCut(const std::string& name, double xval, double yval = 0); + std::vector GetListOfCutParams() const; + + private: + std::unordered_map> m_map; + std::mutex m_cutMutex; + + static CutMap* s_instance; + }; +} + +#endif \ No newline at end of file