r1883: *** empty log message ***
[ctsim.git] / src / views.cpp
index 637b9debcf6b9065d63799fda149ab1f36b8a4b9..3a91f6eaa76d63c0efb53fba8488529b856cdb68 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
 ** FILE IDENTIFICATION
 **
-**   Name:          view.cpp
+**   Name:          views.cpp
 **   Purpose:       View & Canvas routines for CTSim program
 **   Programmer:    Kevin Rosenberg
 **   Date Started:  July 2000
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (c) 1983-2001 Kevin Rosenberg
 **
-**  $Id: views.cpp,v 1.143 2001/03/30 19:17:32 kevin Exp $
+**  $Id: views.cpp,v 1.153 2002/05/03 09:57:41 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
@@ -228,7 +228,7 @@ EVT_MENU(IFMENU_IMAGE_SUBTRACT, ImageFileView::OnSubtract)
 EVT_MENU(IFMENU_IMAGE_MULTIPLY, ImageFileView::OnMultiply)
 EVT_MENU(IFMENU_IMAGE_DIVIDE, ImageFileView::OnDivide)
 EVT_MENU(IFMENU_IMAGE_SCALESIZE, ImageFileView::OnScaleSize)
-#ifdef wxUSE_GLCANVAS
+#if wxUSE_GLCANVAS
 EVT_MENU(IFMENU_IMAGE_CONVERT3D, ImageFileView::OnConvert3d)
 #endif
 #ifdef HAVE_FFT
@@ -408,9 +408,8 @@ ImageFileView::OnCompare (wxCommandEvent& event)
         pDifferenceImage->labelAdd (os.str().c_str());
         if (theApp->getAskDeleteNewDocs())
           pDifferenceDoc->Modify (true);
-        pDifferenceDoc->UpdateAllViews (this);
-        pDifferenceDoc->getView()->OnUpdate (this, NULL);
-        pDifferenceDoc->getView()->getFrame()->Show(true);
+        pDifferenceDoc->UpdateAllViews(this);
+       pDifferenceDoc->getView()->setInitialClientSize();
         pDifferenceDoc->Activate();
       }
       wxMessageBox(os.str().c_str(), "Image Comparison");
@@ -513,7 +512,7 @@ ImageFileView::OnAdd (wxCommandEvent& event)
       if (theApp->getAskDeleteNewDocs())
         pNewDoc->Modify (true);
       pNewDoc->UpdateAllViews (this);
-      pNewDoc->getView()->getFrame()->Show(true);
+      pNewDoc->getView()->setInitialClientSize();
       pNewDoc->Activate();
     }
   }
@@ -554,7 +553,7 @@ ImageFileView::OnSubtract (wxCommandEvent& event)
       if (theApp->getAskDeleteNewDocs())
         pNewDoc->Modify (true);
       pNewDoc->UpdateAllViews (this);
-      pNewDoc->getView()->getFrame()->Show(true);
+      pNewDoc->getView()->setInitialClientSize();
       pNewDoc->Activate();
     }
   }
@@ -595,7 +594,7 @@ ImageFileView::OnMultiply (wxCommandEvent& event)
       if (theApp->getAskDeleteNewDocs())
         pNewDoc->Modify (true);
       pNewDoc->UpdateAllViews (this);
-      pNewDoc->getView()->getFrame()->Show(true);
+      pNewDoc->getView()->setInitialClientSize();
       pNewDoc->Activate();
     }
   }
@@ -636,7 +635,7 @@ ImageFileView::OnDivide (wxCommandEvent& event)
       if (theApp->getAskDeleteNewDocs())
         pNewDoc->Modify (true);
       pNewDoc->UpdateAllViews (this);
-      pNewDoc->getView()->getFrame()->Show(true);
+      pNewDoc->getView()->setInitialClientSize();
       pNewDoc->Activate();
     }
   }
@@ -1007,7 +1006,7 @@ ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
   accelEntries[iEntry++].Set (wxACCEL_CTRL, static_cast<int>('2'), IFMENU_FILTER_FFT);
   accelEntries[iEntry++].Set (wxACCEL_ALT,  static_cast<int>('2'), IFMENU_FILTER_IFFT);
 #endif
-#ifdef wxUSE_GLCANVAS
+#if wxUSE_GLCANVAS
   accelEntries[iEntry++].Set (wxACCEL_CTRL, static_cast<int>('3'), IFMENU_IMAGE_CONVERT3D);
 #endif
   wxAcceleratorTable accelTable (iEntry, accelEntries);
@@ -1027,29 +1026,41 @@ ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
   m_bMaxSpecified = false;
   m_dAutoScaleFactor = 1.;
   
-  int width, height;
-  m_pFrame->GetClientSize (&width, &height);
+  //  int width, height;
+  //  m_pFrame->GetClientSize (&width, &height);
   m_pFrame->SetTitle("ImageFileView");
   m_pCanvas = CreateCanvas (m_pFrame);
   
-  int x, y;  // X requires a forced resize
-  m_pFrame->GetSize(&x, &y);
-  m_pFrame->SetSize(-1, -1, x, y);
+  //  int x, y;  // X requires a forced resize
+  //  m_pFrame->GetSize(&x, &y);
+  //  m_pFrame->SetSize(-1, -1, x, y);
   m_pFrame->SetFocus();
   m_pFrame->Show(true);
-  Activate(true);
+  //  Activate(true);
   
   return true;
 }
 
+void 
+ImageFileView::setInitialClientSize ()
+{
+  if (m_pFrame && m_pCanvas) {
+    wxSize bestSize = m_pCanvas->GetBestSize();
+
+    if (bestSize.x > 800)
+      bestSize.x = 800;
+    if (bestSize.y > 800)
+      bestSize.y = 800;
+    
+    m_pFrame->SetClientSize (bestSize);
+    m_pFrame->Show (true);
+    m_pFrame->SetFocus();
+  }
+}  
+
 void 
 ImageFileView::OnDraw (wxDC* dc)
 {
-  wxSize sizeWindow = m_pFrame->GetClientSize();
-  wxSize sizeBest = m_pCanvas->GetBestSize();
-  if (sizeWindow.x > sizeBest.x || sizeWindow.y > sizeBest.y)
-    m_pFrame->SetClientSize (sizeBest);
-  
   if (m_bitmap.Ok())
     dc->DrawBitmap(m_bitmap, 0, 0, false);
   
@@ -1103,10 +1114,6 @@ ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
     wxImage image (nx, ny, imageData, true);
     m_bitmap = image.ConvertToBitmap();
     delete imageData;
-    int xSize = nx;
-    int ySize = ny;
-    ySize = clamp (ySize, 0, 800);
-    m_pFrame->SetClientSize (xSize, ySize);
     m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20);
     m_pCanvas->SetBackgroundColour(*wxWHITE);
   } 
@@ -1304,7 +1311,7 @@ ImageFileView::OnScaleSize (wxCommandEvent& event)
     if (theApp->getAskDeleteNewDocs())
       pScaledDoc->Modify (true);
     pScaledDoc->UpdateAllViews (this);
-    pScaledDoc->getView()->getFrame()->Show(true);
+    pScaledDoc->getView()->setInitialClientSize();
     pScaledDoc->Activate();
   }
 }
@@ -1975,7 +1982,11 @@ PhantomCanvas::GetBestSize() const
   int xSize, ySize;
   theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
   xSize = maxValue<int> (xSize, ySize);
+#ifdef CTSIM_MDI
   ySize = xSize = (xSize / 4);
+#else
+  ySize = xSize;
+#endif
   return wxSize (xSize, ySize);
 }
 
@@ -2003,6 +2014,7 @@ PhantomFileView::PhantomFileView()
   m_iDefaultNView = 320;
   m_iDefaultNSample = 2;
 #endif
+  m_iDefaultOffsetView = 0;
   m_dDefaultRotation = 1;
   m_dDefaultFocalLength = 2;
   m_dDefaultCenterDetectorLength = 2;
@@ -2051,7 +2063,7 @@ void
 PhantomFileView::OnProjections (wxCommandEvent& event)
 {
   DialogGetProjectionParameters dialogProjection (getFrameForChild(), 
-    m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, 
+    m_iDefaultNDet, m_iDefaultNView, m_iDefaultOffsetView, m_iDefaultNSample, m_dDefaultRotation, 
     m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio, 
     m_iDefaultGeometry, m_iDefaultTrace);
   int retVal = dialogProjection.ShowModal();
@@ -2060,6 +2072,7 @@ PhantomFileView::OnProjections (wxCommandEvent& event)
   
   m_iDefaultNDet = dialogProjection.getNDet();
   m_iDefaultNView = dialogProjection.getNView();
+  m_iDefaultOffsetView = dialogProjection.getOffsetView();
   m_iDefaultNSample = dialogProjection.getNSamples();
   m_iDefaultTrace = dialogProjection.getTrace();
   m_dDefaultRotation = dialogProjection.getRotAngle();
@@ -2076,7 +2089,7 @@ PhantomFileView::OnProjections (wxCommandEvent& event)
     return;
   
   const Phantom& rPhantom = GetDocument()->getPhantom();
-  Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, 
+  Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultOffsetView, m_iDefaultNSample, 
     dRotationRadians, m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio);
   if (theScanner.fail()) {
     wxString msg = "Failed making scanner\n";
@@ -2087,13 +2100,18 @@ PhantomFileView::OnProjections (wxCommandEvent& event)
   }
   
   std::ostringstream os;
-  os << "Projections for " << rPhantom.name() << ": nDet=" << m_iDefaultNDet 
-    << ", nView=" << m_iDefaultNView << ", nSamples=" << m_iDefaultNSample 
-    << ", RotAngle=" << m_dDefaultRotation << ", FocalLengthRatio=" << m_dDefaultFocalLength 
+  os << "Projections for " << rPhantom.name() 
+       << ": nDet=" << m_iDefaultNDet 
+    << ", nView=" << m_iDefaultNView 
+       << ", gantry offset=" << m_iDefaultOffsetView 
+       << ", nSamples=" << m_iDefaultNSample 
+    << ", RotAngle=" << m_dDefaultRotation 
+       << ", FocalLengthRatio=" << m_dDefaultFocalLength 
     << ", CenterDetectorLengthRatio=" << m_dDefaultCenterDetectorLength
-    << ", ViewRatio=" << m_dDefaultViewRatio << ", ScanRatio=" << m_dDefaultScanRatio 
-    << ", Geometry=" << sGeometry.c_str() << ", FanBeamAngle=" << 
-    convertRadiansToDegrees (theScanner.fanBeamAngle());
+    << ", ViewRatio=" << m_dDefaultViewRatio 
+       << ", ScanRatio=" << m_dDefaultScanRatio 
+    << ", Geometry=" << sGeometry.c_str() 
+       << ", FanBeamAngle=" << convertRadiansToDegrees (theScanner.fanBeamAngle());
   
   Timer timer;
   Projections* pProj = NULL;
@@ -2118,7 +2136,7 @@ PhantomFileView::OnProjections (wxCommandEvent& event)
 #if HAVE_WXTHREADS
     if (theApp->getUseBackgroundTasks()) {
       ProjectorSupervisorThread* pProjector = new ProjectorSupervisorThread (this, m_iDefaultNDet,
-        m_iDefaultNView, sGeometry.c_str(), m_iDefaultNSample, dRotationRadians,
+        m_iDefaultNView, m_iDefaultOffsetView, sGeometry.c_str(), m_iDefaultNSample, dRotationRadians,
         m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio, os.str().c_str());
       if (pProjector->Create() != wxTHREAD_NO_ERROR) {
         sys_error (ERR_SEVERE, "Error creating projector thread");
@@ -2135,7 +2153,8 @@ PhantomFileView::OnProjections (wxCommandEvent& event)
       pProj->initFromScanner (theScanner);
       wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), pProj->nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
       for (int i = 0; i < pProj->nView(); i++) {
-        theScanner.collectProjections (*pProj, rPhantom, i, 1, true, m_iDefaultTrace);
+        //theScanner.collectProjections (*pProj, rPhantom, i, 1, true, m_iDefaultTrace);
+        theScanner.collectProjections (*pProj, rPhantom, i, 1, theScanner.offsetView(), true, m_iDefaultTrace);
         if (! dlgProgress.Update (i+1)) {
           delete pProj;
           return;
@@ -2154,21 +2173,10 @@ PhantomFileView::OnProjections (wxCommandEvent& event)
     return;
   }
   pProjectionDoc->setProjections (pProj);
-  ProjectionFileView* projView = pProjectionDoc->getView();
-  if (projView) {
-    projView->OnUpdate (projView, NULL);
-    if (projView->getCanvas())
-      projView->getCanvas()->SetClientSize (m_iDefaultNDet, m_iDefaultNView);
-    if (wxFrame* pFrame = projView->getFrame()) {
-      pFrame->Show(true);
-      pFrame->SetFocus();
-      pFrame->Raise();
-    }
-    GetDocumentManager()->ActivateView (projView, true, false);
-  }
   if (theApp->getAskDeleteNewDocs())
     pProjectionDoc-> Modify(true);
   pProjectionDoc->UpdateAllViews (this);
+  pProjectionDoc->getView()->setInitialClientSize();
   pProjectionDoc->Activate();
 }
 
@@ -2213,14 +2221,15 @@ PhantomFileView::OnRasterize (wxCommandEvent& event)
 #endif
   {
     ImageFile* pImageFile = new ImageFile (m_iDefaultRasterNX, m_iDefaultRasterNY);
+
     wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"), 
-      pImageFile->nx() + 1, getFrameForChild(), wxPD_CAN_ABORT );
+                 pImageFile->nx() + 1, getFrameForChild(), wxPD_CAN_ABORT );
     Timer timer;
     for (unsigned int i = 0; i < pImageFile->nx(); i++) {
       rPhantom.convertToImagefile (*pImageFile, m_dDefaultRasterViewRatio, m_iDefaultRasterNSamples, Trace::TRACE_NONE, i, 1, true);
       if (! dlgProgress.Update (i+1)) {
-        delete pImageFile;
-        return;
+       delete pImageFile;
+       return;
       }
     }
     
@@ -2232,15 +2241,11 @@ PhantomFileView::OnRasterize (wxCommandEvent& event)
     pRasterDoc->setImageFile (pImageFile);
     if (theApp->getAskDeleteNewDocs())
       pRasterDoc->Modify (true);
-    pRasterDoc->UpdateAllViews (this);
-    pRasterDoc->getView()->getFrame()->Show(true);
     *theApp->getLog() << os.str().c_str() << "\n";
     pImageFile->labelAdd (os.str().c_str(), timer.timerEnd());
-    ImageFileView* rasterView = pRasterDoc->getView();
-    if (rasterView) {
-      rasterView->getFrame()->SetFocus();
-      rasterView->OnUpdate (rasterView, NULL);
-    }
+
+    pRasterDoc->UpdateAllViews(this);
+    pRasterDoc->getView()->setInitialClientSize();
     pRasterDoc->Activate();
   }
 }
@@ -2335,15 +2340,8 @@ PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
   m_pCanvas = CreateCanvas (m_pFrame);
   m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
   m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
-  
   m_pFrame->SetTitle ("PhantomFileView");
-  
-#ifdef __X__
-  int x, y;  // X requires a forced resize
-  m_pFrame->GetSize(&x, &y);
-  m_pFrame->SetSize(-1, -1, x, y);
-#endif
-  
+
   m_pFrame->Show(true);
   Activate(true);
   
@@ -2421,6 +2419,9 @@ wxSize
 ProjectionFileCanvas::GetBestSize () const
 {
   wxSize best (0, 0);
+  if (! m_pView)
+    return best;
+
   if (m_pView) {
     Projections& rProj = m_pView->GetDocument()->getProjections();
     best.Set (rProj.nDet(), rProj.nView());
@@ -2445,7 +2446,7 @@ EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
 EVT_MENU(PJMENU_CONVERT_PARALLEL, ProjectionFileView::OnConvertParallel)
 EVT_MENU(PJMENU_PLOT_TTHETA_SAMPLING, ProjectionFileView::OnPlotTThetaSampling)
 EVT_MENU(PJMENU_PLOT_HISTOGRAM, ProjectionFileView::OnPlotHistogram)
-EVT_MENU(PJMENU_ARTIFACT_REDUCTION, ProjectionFileView::OnArtifactReduction)
+  // EVT_MENU(PJMENU_ARTIFACT_REDUCTION, ProjectionFileView::OnArtifactReduction)
 END_EVENT_TABLE()
 
 
@@ -2529,8 +2530,8 @@ ProjectionFileView::OnConvertRectangular (wxCommandEvent& event)
   pIF->labelAdd (os.str().c_str());
   if (theApp->getAskDeleteNewDocs())
     pRectDoc->Modify (true);
-  pRectDoc->getView()->getFrame()->Show(true);
-  pRectDoc->UpdateAllViews ();
+  pRectDoc->UpdateAllViews();
+  pRectDoc->getView()->setInitialClientSize();
   pRectDoc->Activate();
 }
 
@@ -2570,8 +2571,8 @@ ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
     pIF->labelAdd (os.str().c_str());
     if (theApp->getAskDeleteNewDocs())
       pPolarDoc->Modify (true);
-    pPolarDoc->getView()->getFrame()->Show(true);
     pPolarDoc->UpdateAllViews ();
+    pPolarDoc->getView()->setInitialClientSize();
     pPolarDoc->Activate();
   }
 }
@@ -2611,8 +2612,8 @@ ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
     pIF->labelAdd (os.str().c_str());
     if (theApp->getAskDeleteNewDocs())
       pPolarDoc->Modify (true);
-    pPolarDoc->getView()->getFrame()->Show(true);
-    pPolarDoc->UpdateAllViews ();
+    pPolarDoc->UpdateAllViews (this);
+    pPolarDoc->getView()->setInitialClientSize();
     pPolarDoc->Activate();
   }
 }
@@ -2760,6 +2761,7 @@ ProjectionFileView::OnConvertParallel (wxCommandEvent& event)
   if (theApp->getAskDeleteNewDocs())
     pProjDocNew-> Modify(true);
   pProjDocNew->UpdateAllViews (this);
+  pProjDocNew->getView()->setInitialClientSize();
   pProjDocNew->Activate();
 }
 
@@ -2783,7 +2785,9 @@ ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
       *theApp->getLog() << "Error converting to polar\n";
       return;
     }
+#ifdef HAVE_FFT
     pIF->ifft(*pIF);
+#endif
     pIF->magnitude(*pIF);
     Fourier::shuffleFourierToNaturalOrder (*pIF);
 
@@ -2802,8 +2806,8 @@ ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
     pIF->labelAdd (os.str().c_str());
     if (theApp->getAskDeleteNewDocs())
       pPolarDoc->Modify (true);
-    pPolarDoc->getView()->getFrame()->Show(true);
     pPolarDoc->UpdateAllViews ();
+    pPolarDoc->getView()->setInitialClientSize();
     pPolarDoc->Activate();
   }
 }
@@ -2934,19 +2938,16 @@ ProjectionFileView::doReconstructFBP (const Projections& rProj, bool bRebinToPar
     sys_error (ERR_SEVERE, "Unable to create image file");
     return;
   }
+  *theApp->getLog() << os.str().c_str() << "\n";
+  pImageFile->labelAdd (rProj.getLabel());
+  pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd());    
+
   pReconDoc->setImageFile (pImageFile);
   if (theApp->getAskDeleteNewDocs())
     pReconDoc->Modify (true);
-  pReconDoc->UpdateAllViews (this);
+  pReconDoc->UpdateAllViews();
+  pReconDoc->getView()->setInitialClientSize();
   pReconDoc->Activate();
-  if (ImageFileView* rasterView = pReconDoc->getView()) {
-    rasterView->OnUpdate (rasterView, NULL);
-    rasterView->getFrame()->SetFocus();
-    rasterView->getFrame()->Show(true);
-  }
-  *theApp->getLog() << os.str().c_str() << "\n";
-  pImageFile->labelAdd (rProj.getLabel());
-  pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd());    
 }
 
 
@@ -3019,8 +3020,8 @@ ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
   convert_menu->AppendSeparator();
   convert_menu->Append (PJMENU_CONVERT_PARALLEL, "&Interpolate to Parallel");
   
-  wxMenu* filter_menu = new wxMenu;
-  filter_menu->Append (PJMENU_ARTIFACT_REDUCTION, "&Artifact Reduction");
+  //  wxMenu* filter_menu = new wxMenu;
+  //  filter_menu->Append (PJMENU_ARTIFACT_REDUCTION, "&Artifact Reduction");
   
   wxMenu* analyze_menu = new wxMenu;
   analyze_menu->Append (PJMENU_PLOT_HISTOGRAM, "&Plot Histogram");
@@ -3029,7 +3030,8 @@ ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
   wxMenu *reconstruct_menu = new wxMenu;
   reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP, "&Filtered Backprojection...\tCtrl-R", "Reconstruct image using filtered backprojection");
   reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP_REBIN, "Filtered &Backprojection (Rebin to Parallel)...\tCtrl-B", "Reconstruct image using filtered backprojection");
-  reconstruct_menu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Fourier...\tCtrl-E", "Reconstruct image using inverse Fourier");
+  // still buggy
+  //   reconstruct_menu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Fourier...\tCtrl-E", "Reconstruct image using inverse Fourier");
   
   wxMenu *help_menu = new wxMenu;
   help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
@@ -3041,7 +3043,7 @@ ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
   
   menu_bar->Append (m_pFileMenu, "&File");
   menu_bar->Append (convert_menu, "&Convert");
-  menu_bar->Append (filter_menu, "Fi&lter");
+  //  menu_bar->Append (filter_menu, "Fi&lter");
   menu_bar->Append (analyze_menu, "&Analyze");
   menu_bar->Append (reconstruct_menu, "&Reconstruct");
   menu_bar->Append (help_menu, "&Help");
@@ -3075,12 +3077,6 @@ ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
   m_pFrame->SetTitle ("ProjectionFileView");
   m_pCanvas = CreateCanvas (m_pFrame);
   
-#ifdef __X__
-  int x, y;  // X requires a forced resize
-  m_pFrame->GetSize(&x, &y);
-  m_pFrame->SetSize(-1, -1, x, y);
-#endif
-  
   m_pFrame->Show(true);
   Activate(true);
   
@@ -3090,17 +3086,26 @@ ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
 void 
 ProjectionFileView::OnDraw (wxDC* dc)
 {
-  wxSize clientSize = m_pFrame->GetClientSize();
-  wxSize bestSize = m_pCanvas->GetBestSize();
-  
-  if (clientSize.x > bestSize.x || clientSize.y > bestSize.y)
-    m_pFrame->SetClientSize (bestSize);
-  
   if (m_bitmap.Ok())
     dc->DrawBitmap (m_bitmap, 0, 0, false);
 }
 
 
+void 
+ProjectionFileView::setInitialClientSize ()
+{
+  wxSize bestSize = m_pCanvas->GetBestSize();
+
+  if (bestSize.x > 800)
+    bestSize.x = 800;
+  if (bestSize.y > 800)
+    bestSize.y = 800;
+
+  m_pFrame->SetClientSize (bestSize);
+  m_pFrame->Show (true);
+  m_pFrame->SetFocus();
+}  
+
 void 
 ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
 {
@@ -3142,16 +3147,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_pFrame->SetClientSize (xSize, ySize);
-    m_pCanvas->SetScrollbars (20, 20, nDet/20, nView/20);
   }
   
-  if (m_pCanvas)
-    m_pCanvas->Refresh();
+    m_pCanvas->SetScrollbars(20, 20, nDet/20, nView/20);
+    m_pCanvas->SetBackgroundColour(*wxWHITE);
+
+    if (m_pCanvas)
+      m_pCanvas->Refresh();
 }
 
 bool 
@@ -3191,6 +3193,23 @@ PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint&
   m_pView = v;
 }
 
+wxSize
+PlotFileCanvas::GetBestSize() const
+{
+  if (! m_pView)
+    return wxSize(0,0);
+  
+  int xSize, ySize;
+  theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
+  xSize = maxValue<int> (xSize, ySize);
+#ifdef CTSIM_MDI
+  ySize = xSize = (xSize / 4);
+#else
+  ySize = xSize;
+#endif
+  return wxSize (xSize, ySize);
+}
+
 PlotFileCanvas::~PlotFileCanvas ()
 {
   m_pView = NULL;
@@ -3409,12 +3428,6 @@ PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
   m_pFrame->SetTitle ("Plot File");
   m_pCanvas = CreateCanvas (m_pFrame);
   
-#ifdef __X__
-  int x, y;  // X requires a forced resize
-  m_pFrame->GetSize(&x, &y);
-  m_pFrame->SetSize(-1, -1, x, y);
-#endif
-  
   m_pFrame->Show(true);
   Activate(true);
   
@@ -3542,13 +3555,6 @@ bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
   m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
   m_pFrame->SetTitle("Log");
   
-#ifdef __X__
-  // X seems to require a forced resize
-  int x, y;
-  frame->GetSize(&x, &y);
-  frame->SetSize(-1, -1, x, y);
-#endif
-  
   m_pFrame->Show (true);
   Activate (true);
   
@@ -3651,3 +3657,17 @@ TextFileCanvas::~TextFileCanvas ()
 {
   m_pView = NULL;
 }
+
+wxSize
+TextFileCanvas::GetBestSize() const
+{
+  int xSize, ySize;
+  theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
+  xSize = maxValue<int> (xSize, ySize);
+#ifdef CTSIM_MDI
+  ySize = xSize = (xSize / 4);
+#else
+  ySize = xSize;
+#endif
+  return wxSize (xSize, ySize);
+}