1
0
Fork 0
mirror of https://github.com/gwm17/Specter.git synced 2024-11-26 12:18:51 -05:00

Beginnings of cuts

This commit is contained in:
Gordon McCann 2022-01-17 11:09:00 -05:00
parent 9ef998a5df
commit 87b2041e8f
2 changed files with 151 additions and 0 deletions

View File

@ -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<Point>& points) :
Cut(name, xpar, ypar), m_points(points)
{
}
Cut2D::~Cut2D() {}
/*
*/
bool Cut2D::IsInside(double x, double y) const
{
return false;
}
}

View File

@ -0,0 +1,109 @@
#ifndef CUT_MAP_H
#define CUT_MAP_H
#include "NavCore.h"
#include <thread>
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<Point>& 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<Point> 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<std::mutex> 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<Point>& points)
{
std::lock_guard<std::mutex> 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<CutParams> GetListOfCutParams() const;
private:
std::unordered_map<std::string, std::unique_ptr<Cut>> m_map;
std::mutex m_cutMutex;
static CutMap* s_instance;
};
}
#endif