r342: Added histogram plotting
authorKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 2 Jan 2001 13:57:30 +0000 (13:57 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 2 Jan 2001 13:57:30 +0000 (13:57 +0000)
src/views.cpp
src/views.h

index 1ba30cd9f821f42db4b34513a10652ef61344b8d..42de3a170448f107f23076d14e6d84e46a538333 100644 (file)
@@ -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&lter");
-  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<ImageFileDocument*>(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<PlotFileDocument*>(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<int> ((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
 
index 4490689db182153e14bc131f75897a76852ceaab..e8a1f25379a737706b02348f37c48455a135739a 100644 (file)
@@ -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);