r150: *** empty log message ***
[ctsim.git] / src / views.cpp
index 21fc80a15b5a19370761d784b3c63313d7fcad93..66770686c5010bd830ae0eb371ba50888b7dd281 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: views.cpp,v 1.2 2000/07/15 08:36:13 kevin Exp $
+**  $Id: views.cpp,v 1.3 2000/07/18 03:14:35 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
@@ -50,8 +50,8 @@
 #include "ctsim.h"
 #include "docs.h"
 #include "views.h"
+#include "dialogs.h"
 #include <sstream>
-#include "ct.h"
 
 // ImageFileCanvas
 
@@ -106,8 +106,9 @@ ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
 
 BEGIN_EVENT_TABLE(ImageFileView, wxView)
-    EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
-    EVT_MENU(IFMENU_VIEW_WINDOW_AUTO, ImageFileView::OnWindowAuto)
+  EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
+  EVT_MENU(IFMENU_VIEW_WINDOW_MINMAX, ImageFileView::OnWindowMinMax)
+  EVT_MENU(IFMENU_VIEW_WINDOW_AUTO, ImageFileView::OnWindowAuto)
 END_EVENT_TABLE()
 
 ImageFileView::ImageFileView(void) 
@@ -130,7 +131,7 @@ ImageFileView::OnProperties (wxCommandEvent& event)
     const string& rFilename = rIF.getFilename();
     rIF.statistics (min, max, mean, mode, median, stddev);
     ostringstream os;
-    os << "file: " << rFilename << "\nmin: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmode: "<<mode<<"\nstddev: "<<stddev;
+    os << "file: " << rFilename << "\nmin: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
     *theApp->getLog() << os.str().c_str();
   }
 }
@@ -139,11 +140,30 @@ void
 ImageFileView::OnWindowAuto (wxCommandEvent& event)
 {
     *theApp->getLog() << "ImageFile: Window Auto\n";
-    m_minPixel = .2;
-    m_maxPixel = .22;
-    m_bMinSpecified = true;
-    m_bMaxSpecified = true;
-    OnUpdate(this, NULL);
+}
+
+void 
+ImageFileView::OnWindowMinMax (wxCommandEvent& event)
+{
+    const ImageFile& rIF = GetDocument()->getImageFile();
+    double min, max;
+    if (! m_bMinSpecified && ! m_bMaxSpecified)
+      rIF.getMinMax (min, max);
+
+    if (m_bMinSpecified)
+      min = m_dMinPixel;
+    if (m_bMaxSpecified)
+      max = m_dMaxPixel;
+
+    DialogGetImageMinMax dialogMinMax (m_frame, rIF, min, max);
+    int retVal = dialogMinMax.ShowModal();
+    if (retVal == wxID_OK) {
+      m_bMinSpecified = true;
+      m_bMaxSpecified = true;
+      m_dMinPixel = dialogMinMax.getMinimum();
+      m_dMaxPixel = dialogMinMax.getMaximum();
+      OnUpdate (this, NULL);
+    }
 }
 
 
@@ -185,6 +205,7 @@ ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
     
     wxMenu *view_menu = new wxMenu;
     view_menu->Append(IFMENU_VIEW_WINDOW_AUTO, "&Window auto");
+    view_menu->Append(IFMENU_VIEW_WINDOW_MINMAX, "&Set Window Min/Max");
     
     wxMenu *help_menu = new wxMenu;
     help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
@@ -248,16 +269,16 @@ ImageFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
            double min, max;
            rIF.getMinMax (min, max);
            if (! m_bMinSpecified)
-               m_minPixel = min;
+               m_dMinPixel = min;
            if (! m_bMaxSpecified)
-               m_maxPixel = max;
+               m_dMaxPixel = max;
        }
-       double scaleWidth = m_maxPixel - m_minPixel;
+       double scaleWidth = m_dMaxPixel - m_dMinPixel;
     
        unsigned char imageData [nx * ny * 3];
        for (int ix = 0; ix < nx; ix++) {
            for (int iy = 0; iy < ny; iy++) {
-               double scaleValue = ((v[ix][iy] - m_minPixel) / scaleWidth) * 255;
+               double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
                int intensity = static_cast<int>(scaleValue + 0.5);
                intensity = clamp (intensity, 0, 255);
                int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
@@ -268,20 +289,8 @@ ImageFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
        m_bitmap = image.ConvertToBitmap();
     } 
 
-    if (m_canvas) {
+    if (m_canvas)
        m_canvas->Refresh();
-    }
-
-#ifdef __WXMSW__
-  if (m_canvas)
-    m_canvas->Refresh();
-#else
-  if (m_canvas) {
-    wxClientDC dc(m_canvas);
-    dc.Clear();
-    OnDraw (&dc);
-  }
-#endif
 }
 
 bool 
@@ -351,8 +360,8 @@ PhantomView::OnProperties (wxCommandEvent& event)
   ostringstream os;
   os << "Phantom " << namePhantom << " (" << static_cast<int>(idPhantom) << ")\n";
   *theApp->getLog() << os.str().c_str();
-  const Phantom& rPhantom = GetDocument()->getPhantom();
 #if DEBUG
+  const Phantom& rPhantom = GetDocument()->getPhantom();
   rPhantom.print();
 #endif
 }
@@ -361,6 +370,14 @@ PhantomView::OnProperties (wxCommandEvent& event)
 void
 PhantomView::OnProjections (wxCommandEvent& event)
 {
+  const Phantom& rPhantom = GetDocument()->getPhantom();
+  ProjectionFileDocument* pProjectionDoc = dynamic_cast<ProjectionFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.pj", wxDOC_SILENT));
+  Projections& rProj = pProjectionDoc->getProjections();
+  Scanner theScanner (rPhantom, "parallel", 367, 320, 2, PI);
+  rProj.initFromScanner (theScanner);
+  theScanner.collectProjections (rProj, rPhantom, 0, TRACE_NONE);
+  pProjectionDoc->Modify(true);
+  pProjectionDoc->UpdateAllViews(this);
 }
 
 
@@ -371,7 +388,6 @@ PhantomView::OnRasterize (wxCommandEvent& event)
   ImageFileDocument* pRasterDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
   ImageFile& imageFile = pRasterDoc->getImageFile();
   imageFile.setArraySize (256, 256);
-  imageFile.arrayDataClear();
   rPhantom.convertToImagefile (imageFile, 1, TRACE_NONE);
   pRasterDoc->Modify(true);
   pRasterDoc->UpdateAllViews(this);
@@ -467,20 +483,8 @@ PhantomView::OnDraw (wxDC* dc)
 void 
 PhantomView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
 {
-    if (m_canvas) {
+    if (m_canvas)
        m_canvas->Refresh();
-    }
-
-#ifdef __WXMSW__
-  if (m_canvas)
-    m_canvas->Refresh();
-#else
-  if (m_canvas) {
-    wxClientDC dc(m_canvas);
-    dc.Clear();
-    OnDraw (&dc);
-  }
-#endif
 }
 
 bool 
@@ -662,50 +666,40 @@ ProjectionFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint)
     const Projections& rProj = GetDocument()->getProjections();
     const int nDet = rProj.nDet();
     const int nView = rProj.nView();
-    const DetectorArray& detarray = rProj.getDetectorArray(0);
-    const DetectorValue* detval = detarray.detValues();
-    double min = detval[0];
-    double max = detval[0];
-    for (int iy = 0; iy < nView; iy++) {
-      const DetectorArray& detarray = rProj.getDetectorArray(iy);
-      const DetectorValue* detval = detarray.detValues();
-      for (int ix = 0; ix < nDet; ix++) {
-       if (min > detval[ix])
-         min = detval[ix];
-       else if (max < detval[ix])
-         max = detval[ix];
-      }
-    }
+    if (nDet != 0 && nView != 0) {
+       const DetectorArray& detarray = rProj.getDetectorArray(0);
+       const DetectorValue* detval = detarray.detValues();
+       double min = detval[0];
+       double max = detval[0];
+       for (int iy = 0; iy < nView; iy++) {
+           const DetectorArray& detarray = rProj.getDetectorArray(iy);
+           const DetectorValue* detval = detarray.detValues();
+           for (int ix = 0; ix < nDet; ix++) {
+               if (min > detval[ix])
+                   min = detval[ix];
+               else if (max < detval[ix])
+                   max = detval[ix];
+           }
+       }
 
-    unsigned char imageData [nDet * nView * 3];
-    double scale = (max - min) / 255;
-    for (int iy = 0; iy < nView; iy++) {
-      const DetectorArray& detarray = rProj.getDetectorArray(iy);
-      const DetectorValue* detval = detarray.detValues();
-      for (int ix = 0; ix < nDet; ix++) {
-       int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
-       intensity = clamp(intensity, 0, 255);
-       int baseAddr = (iy * nDet + ix) * 3;
-       imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
-      }
-    }
-    wxImage image (nDet, nView, imageData, true);
-    m_bitmap = image.ConvertToBitmap();
-    
-    if (m_canvas) {
-       m_canvas->Refresh();
+       unsigned char imageData [nDet * nView * 3];
+       double scale = (max - min) / 255;
+       for (int iy = 0; iy < nView; iy++) {
+           const DetectorArray& detarray = rProj.getDetectorArray(iy);
+           const DetectorValue* detval = detarray.detValues();
+           for (int ix = 0; ix < nDet; ix++) {
+               int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
+               intensity = clamp(intensity, 0, 255);
+               int baseAddr = (iy * nDet + ix) * 3;
+               imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
+           }
+       }
+       wxImage image (nDet, nView, imageData, true);
+       m_bitmap = image.ConvertToBitmap();
     }
 
-#ifdef __WXMSW__
-  if (m_canvas)
-    m_canvas->Refresh();
-#else
-  if (m_canvas) {
-    wxClientDC dc(m_canvas);
-    dc.Clear();
-    OnDraw (&dc);
-  }
-#endif
+    if (m_canvas)
+       m_canvas->Refresh();
 }
 
 bool