mirror of
https://github.com/gwm17/Specter.git
synced 2024-11-23 02:38:52 -05:00
Now can add cuts by drawing on a zoomed histogram. SpectrumPanel code will probably need a cleanup, as the render function is now quite busy
This commit is contained in:
parent
ee28fef0c4
commit
fe775ceb77
|
@ -76,7 +76,7 @@ namespace Navigator {
|
||||||
class NAV_API CutMap
|
class NAV_API CutMap
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using Iter = std::unordered_map<std::string, std::unique_ptr<Cut>>::iterator;
|
using Iter = std::unordered_map<std::string, std::shared_ptr<Cut>>::iterator;
|
||||||
|
|
||||||
CutMap();
|
CutMap();
|
||||||
~CutMap();
|
~CutMap();
|
||||||
|
@ -100,7 +100,7 @@ namespace Navigator {
|
||||||
inline Iter end() { return m_map.end(); }
|
inline Iter end() { return m_map.end(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<std::string, std::unique_ptr<Cut>> m_map;
|
std::unordered_map<std::string, std::shared_ptr<Cut>> m_map;
|
||||||
|
|
||||||
static CutMap* s_instance;
|
static CutMap* s_instance;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
#include "SpectrumPanel.h"
|
#include "SpectrumPanel.h"
|
||||||
#include "implot.h"
|
#include "implot.h"
|
||||||
|
#include "misc/cpp/imgui_stdlib.h"
|
||||||
|
|
||||||
namespace Navigator {
|
namespace Navigator {
|
||||||
|
|
||||||
SpectrumPanel::SpectrumPanel() :
|
SpectrumPanel::SpectrumPanel() :
|
||||||
m_zoomedFlag(false), m_cutModeFlag("false"), m_zoomedGram(""), m_totalSlots(1)
|
m_zoomedFlag(false), m_cutModeFlag(false), m_zoomedGram(""), m_totalSlots(1)
|
||||||
{
|
{
|
||||||
m_tableSizes[0] = 1; m_tableSizes[1] = 1;
|
m_tableSizes[0] = 1; m_tableSizes[1] = 1;
|
||||||
}
|
}
|
||||||
|
@ -16,6 +17,7 @@ namespace Navigator {
|
||||||
HistogramMap& histMap = HistogramMap::GetInstance();
|
HistogramMap& histMap = HistogramMap::GetInstance();
|
||||||
ParameterMap& paramMap = ParameterMap::GetInstance();
|
ParameterMap& paramMap = ParameterMap::GetInstance();
|
||||||
CutMap& cutMap = CutMap::GetInstance();
|
CutMap& cutMap = CutMap::GetInstance();
|
||||||
|
static bool acceptCutFlag = false;
|
||||||
if (ImGui::Begin("Active View"))
|
if (ImGui::Begin("Active View"))
|
||||||
{
|
{
|
||||||
if (histMap.size() > 0)
|
if (histMap.size() > 0)
|
||||||
|
@ -24,12 +26,22 @@ namespace Navigator {
|
||||||
{
|
{
|
||||||
if(ImGui::Button("Draw Cut"))
|
if(ImGui::Button("Draw Cut"))
|
||||||
{
|
{
|
||||||
|
m_newCutParams = CutParams();
|
||||||
|
m_newCutX.resize(0);
|
||||||
|
m_newCutY.resize(0);
|
||||||
ImGui::OpenPopup("New Cut Dialog");
|
ImGui::OpenPopup("New Cut Dialog");
|
||||||
}
|
}
|
||||||
if(ImGui::BeginPopupModal("New Cut Dialog"))
|
if(ImGui::BeginPopupModal("New Cut Dialog"))
|
||||||
{
|
{
|
||||||
if(ImGui::Button("Accept"))
|
auto& zoomed_params = histMap.GetHistogramParams(m_zoomedGram);
|
||||||
|
m_newCutParams.x_par = zoomed_params.x_par;
|
||||||
|
m_newCutParams.y_par = zoomed_params.y_par;
|
||||||
|
ImGui::InputText("Cut Name", &m_newCutParams.name);
|
||||||
|
ImGui::BulletText("X Parameter: %s", m_newCutParams.x_par.c_str());
|
||||||
|
ImGui::BulletText("Y Parameter: %s", m_newCutParams.y_par.c_str());
|
||||||
|
if(ImGui::Button("Accept & Draw"))
|
||||||
{
|
{
|
||||||
|
m_cutModeFlag = true;
|
||||||
ImGui::CloseCurrentPopup();
|
ImGui::CloseCurrentPopup();
|
||||||
}
|
}
|
||||||
if(ImGui::Button("Cancel"))
|
if(ImGui::Button("Cancel"))
|
||||||
|
@ -42,14 +54,72 @@ namespace Navigator {
|
||||||
if (ImPlot::BeginPlot(m_zoomedGram.c_str(), ImVec2(-1, -1)))
|
if (ImPlot::BeginPlot(m_zoomedGram.c_str(), ImVec2(-1, -1)))
|
||||||
{
|
{
|
||||||
histMap.DrawHistogram(m_zoomedGram);
|
histMap.DrawHistogram(m_zoomedGram);
|
||||||
if (ImPlot::IsPlotHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
|
if (!m_cutModeFlag && ImPlot::IsPlotHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
|
||||||
{
|
{
|
||||||
NAV_INFO("We lost 'em, de-zoom and enhance!");
|
NAV_INFO("We lost 'em, de-zoom and enhance!");
|
||||||
m_zoomedFlag = false;
|
m_zoomedFlag = false;
|
||||||
m_zoomedGram = "";
|
m_zoomedGram = "";
|
||||||
}
|
}
|
||||||
|
else if (m_cutModeFlag && m_newCutParams.y_par == "None")
|
||||||
|
{
|
||||||
|
if (m_newCutX.size() == 2)
|
||||||
|
{
|
||||||
|
acceptCutFlag = true;
|
||||||
|
}
|
||||||
|
else if (ImPlot::IsPlotHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Left))
|
||||||
|
{
|
||||||
|
m_newCutX.push_back(ImPlot::GetPlotMousePos().x);
|
||||||
|
}
|
||||||
|
ImPlot::PlotVLines(m_newCutParams.name.c_str(), m_newCutX.data(), m_newCutX.size());
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(m_cutModeFlag)
|
||||||
|
{
|
||||||
|
if (m_newCutX.size() >= 2 && ImPlot::IsPlotHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
|
||||||
|
{
|
||||||
|
acceptCutFlag = true;
|
||||||
|
m_newCutX.push_back(m_newCutX[0]);
|
||||||
|
m_newCutY.push_back(m_newCutY[0]);
|
||||||
|
}
|
||||||
|
else if (ImPlot::IsPlotHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Left))
|
||||||
|
{
|
||||||
|
auto point = ImPlot::GetPlotMousePos();
|
||||||
|
m_newCutX.push_back(point.x);
|
||||||
|
m_newCutY.push_back(point.y);
|
||||||
|
}
|
||||||
|
ImPlot::PlotLine(m_newCutParams.name.c_str(), m_newCutX.data(), m_newCutY.data(), m_newCutX.size());
|
||||||
|
}
|
||||||
ImPlot::EndPlot();
|
ImPlot::EndPlot();
|
||||||
}
|
}
|
||||||
|
if (acceptCutFlag)
|
||||||
|
{
|
||||||
|
acceptCutFlag = false;
|
||||||
|
m_cutModeFlag = false;
|
||||||
|
ImGui::OpenPopup("Accept Cut");
|
||||||
|
}
|
||||||
|
if (ImGui::BeginPopupModal("Accept Cut"))
|
||||||
|
{
|
||||||
|
ImGui::Text("Save this Cut?");
|
||||||
|
if (ImGui::Button("Yes"))
|
||||||
|
{
|
||||||
|
if (m_newCutParams.y_par == "None")
|
||||||
|
{
|
||||||
|
std::sort(m_newCutX.begin(), m_newCutX.end());
|
||||||
|
cutMap.AddCut(m_newCutParams, m_newCutX[0], m_newCutX[1]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cutMap.AddCut(m_newCutParams, m_newCutX, m_newCutY);
|
||||||
|
}
|
||||||
|
histMap.AddCutToHistogramDraw(m_newCutParams.name, m_zoomedGram);
|
||||||
|
ImGui::CloseCurrentPopup();
|
||||||
|
}
|
||||||
|
if (ImGui::Button("No"))
|
||||||
|
{
|
||||||
|
ImGui::CloseCurrentPopup();
|
||||||
|
}
|
||||||
|
ImGui::EndPopup();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,6 +25,9 @@ namespace Navigator {
|
||||||
std::string m_zoomedGram;
|
std::string m_zoomedGram;
|
||||||
int m_tableSizes[2];
|
int m_tableSizes[2];
|
||||||
int m_totalSlots;
|
int m_totalSlots;
|
||||||
|
CutParams m_newCutParams;
|
||||||
|
std::vector<double> m_newCutX;
|
||||||
|
std::vector<double> m_newCutY;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,13 +74,16 @@ namespace Navigator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<HistogramParameters> HistogramMap::GetListOfHistogramParams()
|
const HistogramParameters& HistogramMap::GetHistogramParams(const std::string& name)
|
||||||
{
|
{
|
||||||
std::vector<HistogramParameters> params;
|
|
||||||
params.reserve(m_map.size());
|
auto iter = m_map.find(name);
|
||||||
for (auto& pair : m_map)
|
if (iter != m_map.end())
|
||||||
params.push_back(pair.second->GetParameters());
|
return iter->second->GetParameters();
|
||||||
return params;
|
else
|
||||||
|
{
|
||||||
|
return HistogramParameters();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Only to be used within ImGui context!!
|
//Only to be used within ImGui context!!
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace Navigator {
|
||||||
void DrawHistograms();
|
void DrawHistograms();
|
||||||
void DrawHistogram(const std::string& name);
|
void DrawHistogram(const std::string& name);
|
||||||
|
|
||||||
std::vector<HistogramParameters> GetListOfHistogramParams(); //thread safe access for GUI to the underlying parameters. Only needs to be called when a gram is added/removed
|
const HistogramParameters& GetHistogramParams(const std::string& name); //thread safe access for GUI to the underlying parameters. Only needs to be called when a gram is added/removed
|
||||||
|
|
||||||
static HistogramMap& GetInstance() { return *s_instance; }
|
static HistogramMap& GetInstance() { return *s_instance; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user