mirror of
https://github.com/gwm17/Specter.git
synced 2024-11-22 18:28:52 -05:00
Fixed a small bug in the RemoveSpectrum line. Added exporting for histograms to .csv files.
This commit is contained in:
parent
dca824dc2e
commit
b805cf9292
|
@ -1,5 +1,6 @@
|
|||
#include "EditorLayer.h"
|
||||
#include "imgui.h"
|
||||
#include "misc/cpp/imgui_stdlib.h"
|
||||
#include "implot.h"
|
||||
#include "FileDialog.h"
|
||||
#include "Navigator/Application.h"
|
||||
|
@ -11,7 +12,7 @@
|
|||
namespace Navigator {
|
||||
|
||||
EditorLayer::EditorLayer() :
|
||||
Layer("EditorLayer"), m_removeHistogram(false), m_removeCut(false)
|
||||
Layer("EditorLayer"), m_removeHistogram(false), m_removeCut(false), m_exportHistogram(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -152,6 +153,14 @@ namespace Navigator {
|
|||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
if (ImGui::BeginMenu("Export"))
|
||||
{
|
||||
if (ImGui::MenuItem(ICON_FA_SAVE "\tAs .csv"))
|
||||
{
|
||||
m_exportHistogram = true;
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
ImGui::EndMenuBar();
|
||||
}
|
||||
|
||||
|
@ -180,6 +189,8 @@ namespace Navigator {
|
|||
RemoveHistogramDialog();
|
||||
|
||||
RemoveCutDialog();
|
||||
|
||||
ExportHistogramDialog();
|
||||
|
||||
if(m_spectrumPanel.OnImGuiRender(m_histoList, m_cutList, m_paramList))
|
||||
{
|
||||
|
@ -254,7 +265,7 @@ namespace Navigator {
|
|||
if (ImGui::Selectable(gram.name.c_str(), gram.name == selectedGram, ImGuiSelectableFlags_DontClosePopups))
|
||||
selectedGram = gram.name;
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
if (ImGui::Button("Ok"))
|
||||
{
|
||||
|
@ -306,4 +317,69 @@ namespace Navigator {
|
|||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
void EditorLayer::ExportHistogramDialog()
|
||||
{
|
||||
static std::string filename = "";
|
||||
static HistogramParameters selectedGram = HistogramParameters();
|
||||
if(m_exportHistogram)
|
||||
{
|
||||
filename = "";
|
||||
selectedGram = HistogramParameters();
|
||||
m_exportHistogram = false;
|
||||
ImGui::OpenPopup("Export Histogram");
|
||||
}
|
||||
if(ImGui::BeginPopupModal("Export Histogram"))
|
||||
{
|
||||
if(ImGui::BeginCombo("Histogram", selectedGram.name.c_str()))
|
||||
{
|
||||
for (auto& gram : m_histoList)
|
||||
{
|
||||
if (ImGui::Selectable(gram.name.c_str(), gram.name == selectedGram.name, ImGuiSelectableFlags_DontClosePopups))
|
||||
selectedGram = gram;
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
ImGui::InputText("File", &filename);
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button("Open"))
|
||||
{
|
||||
m_fileDialog.SetSaveFileDialog(true);
|
||||
}
|
||||
std::string result = m_fileDialog.ImGuiRenderSaveFile(".csv");
|
||||
if(!result.empty())
|
||||
filename = result;
|
||||
if(ImGui::Button("Ok"))
|
||||
{
|
||||
ExportHistogram(selectedGram, filename);
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
ImGui::SameLine();
|
||||
if(ImGui::Button("Cancel"))
|
||||
ImGui::CloseCurrentPopup();
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
|
||||
void EditorLayer::ExportHistogram(HistogramParameters selectedGram, const std::string& filename)
|
||||
{
|
||||
std::ofstream output(filename);
|
||||
if(!output.is_open())
|
||||
{
|
||||
NAV_ERROR("Unable to create export file {0}. Check pathing.", filename);
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<double> data = SpectrumManager::GetInstance().GetBinData(selectedGram.name);
|
||||
|
||||
output<<"Histogram Name,"<<selectedGram.name<<std::endl;
|
||||
output<<"Min X,"<<selectedGram.min_x<<std::endl<<"Max X,"<<selectedGram.max_x<<std::endl;
|
||||
if(selectedGram.y_par != "None")
|
||||
output<<"Min Y,"<<selectedGram.min_y<<std::endl<<"Max Y,"<<selectedGram.max_y<<std::endl;
|
||||
output<<"Nbins,"<<data.size()<<std::endl;
|
||||
output<<"Bin,Counts"<<std::endl;
|
||||
for(size_t i=0; i<data.size(); i++)
|
||||
output<<i<<","<<data[i]<<std::endl;
|
||||
output.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,9 +33,11 @@ namespace Navigator {
|
|||
private:
|
||||
void RemoveCutDialog();
|
||||
void RemoveHistogramDialog();
|
||||
void ExportHistogramDialog();
|
||||
void UpdateHistogramList();
|
||||
void UpdateCutList();
|
||||
void UpdateParameterList(); //Currently not really used, only once. Params all made at construction time of PhysicsLayer
|
||||
void ExportHistogram(HistogramParameters selectedGram, const std::string& filename);
|
||||
|
||||
EventCallbackFunc m_callbackFunc;
|
||||
|
||||
|
@ -58,6 +60,7 @@ namespace Navigator {
|
|||
|
||||
bool m_removeHistogram;
|
||||
bool m_removeCut;
|
||||
bool m_exportHistogram;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -61,6 +61,7 @@ namespace Navigator {
|
|||
inline virtual bool Is1D() const { return false; }
|
||||
inline virtual bool Is2D() const { return false; }
|
||||
inline virtual float* GetColorScaleRange() { return nullptr; }
|
||||
inline virtual std::vector<double> GetBinData() { return std::vector<double>(); }
|
||||
inline HistogramParameters& GetParameters() { return m_params; }
|
||||
inline const std::string& GetXParam() const { return m_params.x_par; };
|
||||
inline const std::string& GetYParam() const { return m_params.y_par; };
|
||||
|
@ -84,6 +85,7 @@ namespace Navigator {
|
|||
virtual StatResults AnalyzeRegion(double x_min, double x_max, double y_min = 0.0, double y_max = 0.0) override;
|
||||
inline virtual bool Is1D() const override { return true; }
|
||||
inline virtual bool Is2D() const override { return false; }
|
||||
inline virtual std::vector<double> GetBinData() override { return m_binCounts; }
|
||||
|
||||
private:
|
||||
void InitBins();
|
||||
|
@ -105,6 +107,7 @@ namespace Navigator {
|
|||
virtual StatResults AnalyzeRegion(double x_min, double x_max, double y_min = 0.0, double y_max = 0.0) override;
|
||||
inline virtual bool Is1D() const override { return false; }
|
||||
inline virtual bool Is2D() const override { return true; }
|
||||
inline virtual std::vector<double> GetBinData() override { return m_binCounts; }
|
||||
|
||||
inline virtual float* GetColorScaleRange() override { return m_colorScaleRange; }
|
||||
|
||||
|
|
|
@ -128,6 +128,18 @@ namespace Navigator {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<double> SpectrumManager::GetBinData(const std::string& name)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
auto iter = m_histoMap.find(name);
|
||||
if (iter != m_histoMap.end())
|
||||
{
|
||||
return iter->second->GetBinData();
|
||||
}
|
||||
|
||||
return std::vector<double>();
|
||||
}
|
||||
|
||||
StatResults SpectrumManager::AnalyzeHistogramRegion(const std::string& name, const ImPlotRect& region)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(m_managerMutex);
|
||||
|
@ -282,4 +294,4 @@ namespace Navigator {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ namespace Navigator {
|
|||
void DrawHistogram(const std::string& name);
|
||||
const HistogramParameters& GetHistogramParams(const std::string& name);
|
||||
float* GetColorScaleRange(const std::string& name);
|
||||
std::vector<double> GetBinData(const std::string& name);
|
||||
StatResults AnalyzeHistogramRegion(const std::string& name, const ImPlotRect& region);
|
||||
std::vector<HistogramParameters> GetListOfHistograms();
|
||||
|
||||
|
@ -76,4 +77,4 @@ namespace Navigator {
|
|||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user