r153: *** empty log message ***
[ctsim.git] / src / views.cpp
index 66770686c5010bd830ae0eb371ba50888b7dd281..3d46d0493394ea6da58162b9ef5cdffbe261c941 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: views.cpp,v 1.3 2000/07/18 03:14:35 kevin Exp $
+**  $Id: views.cpp,v 1.4 2000/07/18 14:51:06 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
@@ -84,7 +84,7 @@ ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
     
     wxPoint pt(event.GetLogicalPosition(dc));
 
-    if (event.LeftUp()) {
+    if (event.LeftIsDown()) {
        const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
        ImageFileArrayConst v = rIF.getArray();
        int nx = rIF.nx();
@@ -133,6 +133,16 @@ ImageFileView::OnProperties (wxCommandEvent& event)
     ostringstream os;
     os << "file: " << rFilename << "\nmin: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
     *theApp->getLog() << os.str().c_str();
+
+    int xSize, ySize;
+    ostringstream osSize;
+    m_frame->GetSize (&xSize, &ySize);
+    osSize << "Frame size: (" << xSize << "," << ySize << ")\n";
+    m_frame->GetClientSize (&xSize, &ySize);
+    osSize << "Frame Client size: (" << xSize << "," << ySize << ")\n";
+    m_canvas->GetSize (&xSize, &ySize);
+    osSize << "Canvas size: (" << xSize << "," << ySize << ")\n";
+    *theApp->getLog() << osSize.str().c_str();
   }
 }
 
@@ -186,10 +196,11 @@ ImageFileView::CreateCanvas (wxView *view, wxFrame *parent)
 wxFrame*
 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
 {
-    wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(10, 10), wxSize(300, 300), wxDEFAULT_FRAME_STYLE);
+    wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
     
     wxMenu *file_menu = new wxMenu;
     
+    file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "&Create Phantom...");
     file_menu->Append(wxID_OPEN, "&Open...");
     file_menu->Append(wxID_CLOSE, "&Close");
     file_menu->Append(wxID_SAVE, "&Save");
@@ -204,8 +215,8 @@ ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
     file_menu->Append(wxID_PREVIEW, "Print Pre&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");
+    view_menu->Append(IFMENU_VIEW_WINDOW_AUTO, "&Auto Window...");
     
     wxMenu *help_menu = new wxMenu;
     help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
@@ -275,7 +286,7 @@ ImageFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
        }
        double scaleWidth = m_dMaxPixel - m_dMinPixel;
     
-       unsigned char imageData [nx * ny * 3];
+       unsigned char* imageData = new unsigned char [nx * ny * 3];
        for (int ix = 0; ix < nx; ix++) {
            for (int iy = 0; iy < ny; iy++) {
                double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
@@ -287,6 +298,14 @@ ImageFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
        }
        wxImage image (ny, nx, imageData, true);
        m_bitmap = image.ConvertToBitmap();
+       delete imageData;
+       int xSize = nx;
+       int ySize = ny;
+       xSize = clamp (xSize, 0, 800);
+       ySize = clamp (ySize, 0, 800);
+       m_frame->SetClientSize (xSize, ySize);
+       m_canvas->SetScrollbars(20, 20, nx/20, ny/20);
+       m_canvas->SetBackgroundColour(*wxWHITE);
     } 
 
     if (m_canvas)
@@ -321,7 +340,7 @@ ImageFileView::OnClose (bool deleteWindow)
 // PhantomCanvas
 
 PhantomCanvas::PhantomCanvas (PhantomView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
-  : wxScrolledWindow(frame, -1, pos, size, style)
+  : wxPanel(frame, -1, pos, size, style)
 {
     m_pView = v;
 }
@@ -370,27 +389,54 @@ 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);
+  DialogGetProjectionParameters dialogProjection (m_frame, 367, 320, 1, 1., Scanner::GEOMETRY_PARALLEL_STR);
+  int retVal = dialogProjection.ShowModal();
+  if (retVal == wxID_OK) {
+    int nDet = dialogProjection.getNDet();
+    int nView = dialogProjection.getNView();
+    int nSamples = dialogProjection.getNSamples();
+    double dRotAngle = dialogProjection.getRotAngle();
+    string sGeometry = dialogProjection.getGeometry();
+    if (nDet > 0 && nView > 0 && sGeometry != "") {
+      const Phantom& rPhantom = GetDocument()->getPhantom();
+      ProjectionFileDocument* pProjectionDoc = dynamic_cast<ProjectionFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.pj", wxDOC_SILENT));
+      Projections& rProj = pProjectionDoc->getProjections();
+      Scanner theScanner (rPhantom, sGeometry.c_str(), nDet, nView, nSamples, dRotAngle);
+      rProj.initFromScanner (theScanner);
+      theScanner.collectProjections (rProj, rPhantom, 0, TRACE_NONE);
+      pProjectionDoc->Modify(true);
+      pProjectionDoc->UpdateAllViews(this);
+    }
+  }
 }
 
 
 void
 PhantomView::OnRasterize (wxCommandEvent& event)
 {
-  const Phantom& rPhantom = GetDocument()->getPhantom();
-  ImageFileDocument* pRasterDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
-  ImageFile& imageFile = pRasterDoc->getImageFile();
-  imageFile.setArraySize (256, 256);
-  rPhantom.convertToImagefile (imageFile, 1, TRACE_NONE);
-  pRasterDoc->Modify(true);
-  pRasterDoc->UpdateAllViews(this);
+  DialogGetRasterParameters dialogRaster (m_frame, 256, 256, 1);
+  int retVal = dialogRaster.ShowModal();
+  if (retVal == wxID_OK) {
+    int xSize = dialogRaster.getXSize();
+    int ySize = dialogRaster.getYSize();
+    int nSamples = dialogRaster.getNSamples();
+    if (nSamples < 1)
+      nSamples = 1;
+    if (xSize > 0 && ySize > 0) {
+      const Phantom& rPhantom = GetDocument()->getPhantom();
+      ImageFileDocument* pRasterDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
+      ImageFile& imageFile = pRasterDoc->getImageFile();
+
+      imageFile.setArraySize (xSize, ySize);
+      rPhantom.convertToImagefile (imageFile, nSamples, TRACE_NONE);
+      pRasterDoc->Modify(true);
+      pRasterDoc->UpdateAllViews(this);
+
+      ostringstream os;
+      os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << xSize << ", YSize=" << ySize << ", nSamples=" << nSamples << "\n";
+      *theApp->getLog() << os.str().c_str();
+    }
+  }
 }
 
 
@@ -403,7 +449,6 @@ PhantomView::CreateCanvas (wxView *view, wxFrame *parent)
     
     pCanvas = new PhantomCanvas (dynamic_cast<PhantomView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
     
-    pCanvas->SetScrollbars(20, 20, 50, 50);
     pCanvas->SetBackgroundColour(*wxWHITE);
     pCanvas->Clear();
     
@@ -413,10 +458,11 @@ PhantomView::CreateCanvas (wxView *view, wxFrame *parent)
 wxFrame*
 PhantomView::CreateChildFrame(wxDocument *doc, wxView *view)
 {
-    wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(300, 300), wxDEFAULT_FRAME_STYLE);
+    wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
     
     wxMenu *file_menu = new wxMenu;
     
+    file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "&Create Phantom...");
     file_menu->Append(wxID_OPEN, "&Open...");
     file_menu->Append(wxID_CLOSE, "&Close");
     
@@ -593,10 +639,11 @@ ProjectionFileView::CreateCanvas (wxView *view, wxFrame *parent)
 wxFrame*
 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
 {
-    wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(300, 300), wxDEFAULT_FRAME_STYLE);
+    wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
     
     wxMenu *file_menu = new wxMenu;
     
+    file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "&Create Phantom...");
     file_menu->Append(wxID_OPEN, "&Open...");
     file_menu->Append(wxID_CLOSE, "&Close");
     
@@ -682,7 +729,7 @@ ProjectionFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint)
            }
        }
 
-       unsigned char imageData [nDet * nView * 3];
+       unsigned char* imageData = new unsigned char [nDet * nView * 3];
        double scale = (max - min) / 255;
        for (int iy = 0; iy < nView; iy++) {
            const DetectorArray& detarray = rProj.getDetectorArray(iy);
@@ -696,6 +743,13 @@ ProjectionFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint)
        }
        wxImage image (nDet, nView, imageData, true);
        m_bitmap = image.ConvertToBitmap();
+       delete imageData;
+       int xSize = nDet;
+       int ySize = nView;
+       xSize = clamp (xSize, 0, 800);
+       ySize = clamp (ySize, 0, 800);
+       m_frame->SetClientSize (xSize, ySize);
+       m_canvas->SetScrollbars (20, 20, nDet/20, nView/20);
     }
 
     if (m_canvas)