From 7a4e7e832456894448ee6676e239d6ccfd2e7eaf Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Tue, 2 Jan 2001 13:57:30 +0000 Subject: [PATCH] r342: Added histogram plotting --- src/views.cpp | 78 +++++++++++++++++++++++++++++++++++++++++++-------- src/views.h | 4 +-- 2 files changed, 68 insertions(+), 14 deletions(-) diff --git a/src/views.cpp b/src/views.cpp index 1ba30cd..42de3a1 100644 --- a/src/views.cpp +++ b/src/views.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: views.cpp,v 1.47 2001/01/02 13:32:51 kevin Exp $ +** $Id: views.cpp,v 1.48 2001/01/02 13:57:30 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -195,6 +195,7 @@ EVT_MENU(IFMENU_FILTER_MAGNITUDE, ImageFileView::OnMagnitude) EVT_MENU(IFMENU_FILTER_PHASE, ImageFileView::OnPhase) EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow) EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol) +EVT_MENU(IFMENU_PLOT_HISTOGRAM, ImageFileView::OnPlotHistogram) END_EVENT_TABLE() ImageFileView::ImageFileView(void) @@ -739,7 +740,6 @@ ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view) filter_menu->Append (IFMENU_FILTER_PHASE, "&Phase"); wxMenu* image_menu = new wxMenu; - filter_menu->AppendSeparator(); image_menu->Append (IFMENU_IMAGE_ADD, "&Add..."); image_menu->Append (IFMENU_IMAGE_SUBTRACT, "&Subtract..."); image_menu->Append (IFMENU_IMAGE_MULTIPLY, "&Multiply..."); @@ -747,14 +747,14 @@ ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view) image_menu->AppendSeparator(); image_menu->Append (IFMENU_IMAGE_SCALESIZE, "S&cale Size..."); - wxMenu *plot_menu = new wxMenu; - plot_menu->Append (IFMENU_PLOT_ROW, "Plot &Row"); - plot_menu->Append (IFMENU_PLOT_COL, "Plot &Column"); - - wxMenu *compare_menu = new wxMenu; - compare_menu->Append (IFMENU_COMPARE_IMAGES, "Compare &Images..."); - compare_menu->Append (IFMENU_COMPARE_ROW, "Compare &Row"); - compare_menu->Append (IFMENU_COMPARE_COL, "Compare &Column"); + wxMenu *analyze_menu = new wxMenu; + analyze_menu->Append (IFMENU_PLOT_ROW, "Plot &Row"); + analyze_menu->Append (IFMENU_PLOT_COL, "Plot &Column"); + analyze_menu->Append (IFMENU_PLOT_HISTOGRAM, "Plot &Histogram"); + analyze_menu->AppendSeparator(); + analyze_menu->Append (IFMENU_COMPARE_IMAGES, "Compare &Images..."); + analyze_menu->Append (IFMENU_COMPARE_ROW, "Compare &Row"); + analyze_menu->Append (IFMENU_COMPARE_COL, "Compare &Column"); wxMenu *help_menu = new wxMenu; help_menu->Append(MAINMENU_HELP_ABOUT, "&About"); @@ -765,8 +765,7 @@ ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view) menu_bar->Append(view_menu, "&View"); menu_bar->Append(image_menu, "&Image"); menu_bar->Append(filter_menu, "Fi<er"); - menu_bar->Append(plot_menu, "P&lot"); - menu_bar->Append(compare_menu, "&Compare"); + menu_bar->Append(analyze_menu, "&Analyze"); menu_bar->Append(help_menu, "&Help"); subframe->SetMenuBar(menu_bar); @@ -1196,6 +1195,61 @@ ImageFileView::OnCompareRow (wxCommandEvent& event) } } +static int NUMBER_HISTOGRAM_BINS = 256; + +void +ImageFileView::OnPlotHistogram (wxCommandEvent& event) +{ + const ImageFile& rIF = dynamic_cast(GetDocument())->getImageFile(); + ImageFileArrayConst v = rIF.getArray(); + int nx = rIF.nx(); + int ny = rIF.ny(); + + if (v != NULL && nx > 0 && ny > 0) { + PlotFileDocument* pPlotDoc = dynamic_cast(theApp->getDocManager()->CreateDocument("untitled.plt", wxDOC_SILENT)); + if (! pPlotDoc) { + sys_error (ERR_SEVERE, "Internal error: unable to create Plot file"); + return; + } + + double* pX = new double [NUMBER_HISTOGRAM_BINS]; + double* pY = new double [NUMBER_HISTOGRAM_BINS]; + double dMin, dMax; + rIF.getMinMax (dMin, dMax); + double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS; + + for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) { + pX[i] = dMin + (i + 0.5) * dBinWidth; + pY[i] = 0; + } + for (int ix = 0; ix < nx; ix++) + for (int iy = 0; iy < ny; iy++) { + int iBin = nearest ((v[ix][iy] - dMin) / dBinWidth); + if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS) + pY[iBin] += 1; + } + + PlotFile& rPlotFile = pPlotDoc->getPlotFile(); + std::ostringstream os; + os << "Histogram"; + std::string title("title "); + title += os.str(); + rPlotFile.addEzsetCommand (title.c_str()); + rPlotFile.addEzsetCommand ("xlabel Pixel Value"); + rPlotFile.addEzsetCommand ("ylabel Count"); + rPlotFile.addEzsetCommand ("box"); + rPlotFile.addEzsetCommand ("grid"); + rPlotFile.setCurveSize (2, nx); + rPlotFile.addColumn (0, pX); + rPlotFile.addColumn (1, pY); + delete pX; + delete pY; + if (theApp->getSetModifyNewDocs()) + pPlotDoc->Modify(true); + pPlotDoc->UpdateAllViews(); + } +} + // PhantomCanvas diff --git a/src/views.h b/src/views.h index 4490689..e8a1f25 100644 --- a/src/views.h +++ b/src/views.h @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: views.h,v 1.22 2001/01/02 13:16:43 kevin Exp $ +** $Id: views.h,v 1.23 2001/01/02 13:57:30 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -99,7 +99,7 @@ public: void OnScaleMinMax (wxCommandEvent& event); void OnPlotRow (wxCommandEvent& event); void OnPlotCol (wxCommandEvent& event); - void OnHistogram (wxCommandEvent& event); + void OnPlotHistogram (wxCommandEvent& event); void OnCompareRow (wxCommandEvent& event); void OnCompareCol (wxCommandEvent& event); -- 2.34.1