X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=src%2Fviews.cpp;h=0bf911a79fe7d52582b4385260fc3fa5b66aac2e;hp=631f481f78cda69482ea5bf6fa66551721812252;hb=8a7697ce57b56cdc43698cd1241ad98d49f9b5ac;hpb=99e0682c24409926fb1afd867db88a4803c734e7 diff --git a/src/views.cpp b/src/views.cpp index 631f481..0bf911a 100644 --- a/src/views.cpp +++ b/src/views.cpp @@ -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.141 2001/03/28 16:44:41 kevin Exp $ +** $Id$ ** ** 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 @@ -58,6 +58,8 @@ #include #endif +// Used to reduce calls to progress bar update function +const short int ITER_PER_UPDATE = 10; // ImageFileCanvas @@ -73,9 +75,7 @@ ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoin } ImageFileCanvas::~ImageFileCanvas() -{ - m_pView = NULL; -} +{} void ImageFileCanvas::OnDraw(wxDC& dc) @@ -184,17 +184,32 @@ ImageFileCanvas::OnChar (wxKeyEvent& event) if (m_pView) m_pView->OnUpdate (NULL); } else - wxScrolledWindow::OnChar (event); + event.Skip(); } wxSize ImageFileCanvas::GetBestSize() const { - if (! m_pView) - return wxSize(0,0); + const int iMinX = 50; + const int iMinY = 20; + wxSize bestSize (iMinX,iMinY); + + if (m_pView) { + const ImageFile& rIF = m_pView->GetDocument()->getImageFile(); + bestSize.Set (rIF.nx(), rIF.ny()); + } + + if (bestSize.x > 800) + bestSize.x = 800; + if (bestSize.y > 800) + bestSize.y = 800; - const ImageFile& rIF = m_pView->GetDocument()->getImageFile(); - return wxSize (rIF.nx(), rIF.ny()); + if (bestSize.y < iMinY) + bestSize.y = iMinY; + if (bestSize.x < iMinX) + bestSize.x = iMinX; + + return bestSize; } @@ -253,10 +268,10 @@ EVT_MENU(IFMENU_PLOT_HISTOGRAM, ImageFileView::OnPlotHistogram) END_EVENT_TABLE() ImageFileView::ImageFileView() -: wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0), m_pFilterMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false) -{ - m_iDefaultExportFormatID = ImageFile::EXPORT_FORMAT_PNG; -} + : wxView(), m_pBitmap(0), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0), + m_pFilterMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false), + m_iDefaultExportFormatID(ImageFile::EXPORT_FORMAT_PNG) +{} ImageFileView::~ImageFileView() { @@ -314,6 +329,7 @@ ImageFileView::OnScaleAuto (wxCommandEvent& event) m_dMinPixel = dMin; m_dMaxPixel = dMax; m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor(); + OnUpdate(this, NULL); GetDocument()->UpdateAllViews (this); } } @@ -340,6 +356,7 @@ ImageFileView::OnScaleMinMax (wxCommandEvent& event) m_bMaxSpecified = true; m_dMinPixel = dialogMinMax.getMinimum(); m_dMaxPixel = dialogMinMax.getMaximum(); + OnUpdate(this, NULL); GetDocument()->UpdateAllViews (this); } GetDocument()->Activate(); @@ -351,6 +368,7 @@ ImageFileView::OnScaleFull (wxCommandEvent& event) if (m_bMinSpecified || m_bMaxSpecified) { m_bMinSpecified = false; m_bMaxSpecified = false; + OnUpdate(this, NULL); GetDocument()->UpdateAllViews (this); } GetDocument()->Activate(); @@ -408,9 +426,9 @@ 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); + OnUpdate(this, NULL); + pDifferenceDoc->UpdateAllViews(this); + pDifferenceDoc->getView()->setInitialClientSize(); pDifferenceDoc->Activate(); } wxMessageBox(os.str().c_str(), "Image Comparison"); @@ -426,6 +444,7 @@ ImageFileView::OnInvertValues (wxCommandEvent& event) rIF.labelAdd ("Invert Pixel Values"); if (theApp->getAskDeleteNewDocs()) GetDocument()->Modify (true); + OnUpdate(this, NULL); GetDocument()->UpdateAllViews (this); GetDocument()->Activate(); } @@ -438,6 +457,7 @@ ImageFileView::OnSquare (wxCommandEvent& event) rIF.labelAdd ("Square Pixel Values"); if (theApp->getAskDeleteNewDocs()) GetDocument()->Modify (true); + OnUpdate(this, NULL); GetDocument()->UpdateAllViews (this); GetDocument()->Activate(); } @@ -450,6 +470,7 @@ ImageFileView::OnSquareRoot (wxCommandEvent& event) rIF.labelAdd ("Square-root Pixel Values"); if (theApp->getAskDeleteNewDocs()) GetDocument()->Modify (true); + OnUpdate(this, NULL); GetDocument()->UpdateAllViews (this); GetDocument()->Activate(); } @@ -462,6 +483,7 @@ ImageFileView::OnLog (wxCommandEvent& event) rIF.labelAdd ("Logrithm base-e Pixel Values"); if (theApp->getAskDeleteNewDocs()) GetDocument()->Modify (true); + OnUpdate(this, NULL); GetDocument()->UpdateAllViews (this); GetDocument()->Activate(); } @@ -474,6 +496,7 @@ ImageFileView::OnExp (wxCommandEvent& event) rIF.labelAdd ("Exponent base-e Pixel Values"); if (theApp->getAskDeleteNewDocs()) GetDocument()->Modify (true); + OnUpdate(this, NULL); GetDocument()->UpdateAllViews (this); GetDocument()->Activate(); } @@ -512,8 +535,9 @@ ImageFileView::OnAdd (wxCommandEvent& event) *theApp->getLog() << os.str().c_str() << "\n"; if (theApp->getAskDeleteNewDocs()) pNewDoc->Modify (true); + OnUpdate(this, NULL); pNewDoc->UpdateAllViews (this); - pNewDoc->getView()->getFrame()->Show(true); + pNewDoc->getView()->setInitialClientSize(); pNewDoc->Activate(); } } @@ -553,8 +577,9 @@ ImageFileView::OnSubtract (wxCommandEvent& event) *theApp->getLog() << os.str().c_str() << "\n"; if (theApp->getAskDeleteNewDocs()) pNewDoc->Modify (true); + OnUpdate(this, NULL); pNewDoc->UpdateAllViews (this); - pNewDoc->getView()->getFrame()->Show(true); + pNewDoc->getView()->setInitialClientSize(); pNewDoc->Activate(); } } @@ -594,8 +619,9 @@ ImageFileView::OnMultiply (wxCommandEvent& event) *theApp->getLog() << os.str().c_str() << "\n"; if (theApp->getAskDeleteNewDocs()) pNewDoc->Modify (true); + OnUpdate(this, NULL); pNewDoc->UpdateAllViews (this); - pNewDoc->getView()->getFrame()->Show(true); + pNewDoc->getView()->setInitialClientSize(); pNewDoc->Activate(); } } @@ -635,8 +661,9 @@ ImageFileView::OnDivide (wxCommandEvent& event) *theApp->getLog() << os.str().c_str() << "\n"; if (theApp->getAskDeleteNewDocs()) pNewDoc->Modify (true); + OnUpdate(this, NULL); pNewDoc->UpdateAllViews (this); - pNewDoc->getView()->getFrame()->Show(true); + pNewDoc->getView()->setInitialClientSize(); pNewDoc->Activate(); } } @@ -654,6 +681,7 @@ ImageFileView::OnFFT (wxCommandEvent& event) m_bMaxSpecified = false; if (theApp->getAskDeleteNewDocs()) GetDocument()->Modify (true); + OnUpdate(this, NULL); GetDocument()->UpdateAllViews (this); GetDocument()->Activate(); } @@ -668,6 +696,7 @@ ImageFileView::OnIFFT (wxCommandEvent& event) m_bMaxSpecified = false; if (theApp->getAskDeleteNewDocs()) GetDocument()->Modify (true); + OnUpdate(this, NULL); GetDocument()->UpdateAllViews (this); GetDocument()->Activate(); } @@ -682,6 +711,7 @@ ImageFileView::OnFFTRows (wxCommandEvent& event) m_bMaxSpecified = false; if (theApp->getAskDeleteNewDocs()) GetDocument()->Modify (true); + OnUpdate(this, NULL); GetDocument()->UpdateAllViews (this); GetDocument()->Activate(); } @@ -696,6 +726,7 @@ ImageFileView::OnIFFTRows (wxCommandEvent& event) m_bMaxSpecified = false; if (theApp->getAskDeleteNewDocs()) GetDocument()->Modify (true); + OnUpdate(this, NULL); GetDocument()->UpdateAllViews (this); GetDocument()->Activate(); } @@ -710,6 +741,7 @@ ImageFileView::OnFFTCols (wxCommandEvent& event) m_bMaxSpecified = false; if (theApp->getAskDeleteNewDocs()) GetDocument()->Modify (true); + OnUpdate(this, NULL); GetDocument()->UpdateAllViews (this); GetDocument()->Activate(); } @@ -724,6 +756,7 @@ ImageFileView::OnIFFTCols (wxCommandEvent& event) m_bMaxSpecified = false; if (theApp->getAskDeleteNewDocs()) GetDocument()->Modify (true); + OnUpdate(this, NULL); GetDocument()->UpdateAllViews (this); GetDocument()->Activate(); } @@ -740,6 +773,7 @@ ImageFileView::OnFourier (wxCommandEvent& event) m_bMaxSpecified = false; if (theApp->getAskDeleteNewDocs()) GetDocument()->Modify (true); + OnUpdate(this, NULL); GetDocument()->UpdateAllViews (this); GetDocument()->Activate(); } @@ -755,6 +789,7 @@ ImageFileView::OnInverseFourier (wxCommandEvent& event) m_bMaxSpecified = false; if (theApp->getAskDeleteNewDocs()) GetDocument()->Modify (true); + OnUpdate(this, NULL); GetDocument()->UpdateAllViews (this); GetDocument()->Activate(); } @@ -769,6 +804,7 @@ ImageFileView::OnShuffleNaturalToFourierOrder (wxCommandEvent& event) m_bMaxSpecified = false; if (theApp->getAskDeleteNewDocs()) GetDocument()->Modify (true); + OnUpdate(this, NULL); GetDocument()->UpdateAllViews (this); GetDocument()->Activate(); } @@ -783,6 +819,7 @@ ImageFileView::OnShuffleFourierToNaturalOrder (wxCommandEvent& event) m_bMaxSpecified = false; if (theApp->getAskDeleteNewDocs()) GetDocument()->Modify (true); + OnUpdate(this, NULL); GetDocument()->UpdateAllViews (this); GetDocument()->Activate(); } @@ -797,6 +834,7 @@ ImageFileView::OnMagnitude (wxCommandEvent& event) m_bMaxSpecified = false; if (theApp->getAskDeleteNewDocs()) GetDocument()->Modify (true); + OnUpdate(this, NULL); GetDocument()->UpdateAllViews (this); GetDocument()->Activate(); } @@ -812,6 +850,7 @@ ImageFileView::OnPhase (wxCommandEvent& event) m_bMaxSpecified = false; if (theApp->getAskDeleteNewDocs()) GetDocument()->Modify (true); + OnUpdate(this, NULL); GetDocument()->UpdateAllViews (this); } GetDocument()->Activate(); @@ -828,6 +867,7 @@ ImageFileView::OnReal (wxCommandEvent& event) m_bMaxSpecified = false; if (theApp->getAskDeleteNewDocs()) GetDocument()->Modify (true); + OnUpdate(this, NULL); GetDocument()->UpdateAllViews (this); } GetDocument()->Activate(); @@ -844,6 +884,7 @@ ImageFileView::OnImaginary (wxCommandEvent& event) m_bMaxSpecified = false; if (theApp->getAskDeleteNewDocs()) GetDocument()->Modify (true); + OnUpdate(this, NULL); GetDocument()->UpdateAllViews (this); } GetDocument()->Activate(); @@ -853,13 +894,8 @@ ImageFileView::OnImaginary (wxCommandEvent& event) ImageFileCanvas* ImageFileView::CreateCanvas (wxFrame* parent) { - ImageFileCanvas* pCanvas; - int width, height; - parent->GetClientSize(&width, &height); - - pCanvas = new ImageFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0); - - pCanvas->SetScrollbars(20, 20, 50, 50); + ImageFileCanvas* pCanvas = new ImageFileCanvas (this, parent, wxPoint(-1,-1), + wxSize(-1,-1), 0); pCanvas->SetBackgroundColour(*wxWHITE); pCanvas->Clear(); @@ -874,12 +910,12 @@ wxDocChildFrame* ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view) { #if CTSIM_MDI - wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE); + wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE); #else - wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE); + wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE); #endif theApp->setIconForFrame (subframe); - + m_pFileMenu = new wxMenu; m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P"); m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F"); @@ -899,11 +935,9 @@ ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view) m_pFileMenu->Append(wxID_PREVIEW, "Print Preview"); m_pFileMenu->AppendSeparator(); m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M"); -#ifdef CTSIM_MDI m_pFileMenu->AppendSeparator(); m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces..."); m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit"); -#endif GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu); GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu); @@ -1007,11 +1041,11 @@ ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view) accelEntries[iEntry++].Set (wxACCEL_CTRL, static_cast('2'), IFMENU_FILTER_FFT); accelEntries[iEntry++].Set (wxACCEL_ALT, static_cast('2'), IFMENU_FILTER_IFFT); #endif -#ifdef wxUSE_GLCANVAS +#if wxUSE_GLCANVAS accelEntries[iEntry++].Set (wxACCEL_CTRL, static_cast('3'), IFMENU_IMAGE_CONVERT3D); #endif + wxAcceleratorTable accelTable (iEntry, accelEntries); - subframe->SetAcceleratorTable (accelTable); return subframe; @@ -1021,37 +1055,44 @@ ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view) bool ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) ) { - m_pFrame = CreateChildFrame(doc, this); - m_bMinSpecified = false; m_bMaxSpecified = false; m_dAutoScaleFactor = 1.; - int width, height; - m_pFrame->GetClientSize (&width, &height); - m_pFrame->SetTitle("ImageFileView"); + m_pFrame = CreateChildFrame(doc, this); + SetFrame (m_pFrame); 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); - m_pFrame->SetFocus(); + m_pFrame->SetClientSize (m_pCanvas->GetBestSize()); + m_pCanvas->SetClientSize (m_pCanvas->GetBestSize()); + m_pFrame->SetTitle("ImageFileView"); + m_pFrame->Show(true); Activate(true); return true; } +void +ImageFileView::setInitialClientSize () +{ + if (m_pFrame && m_pCanvas) { + wxSize bestSize = m_pCanvas->GetBestSize(); + + 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); + if (m_pBitmap && m_pBitmap->Ok()) { +#ifdef DEBUG + *theApp->getLog() << "Drawing bitmap\n"; +#endif + dc->DrawBitmap(*m_pBitmap, 0, 0, false); + } int xCursor, yCursor; if (m_pCanvas->GetCurrentCursor (xCursor, yCursor)) @@ -1101,12 +1142,15 @@ ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) } } wxImage image (nx, ny, imageData, true); - m_bitmap = image.ConvertToBitmap(); + if (m_pBitmap) { + delete m_pBitmap; + m_pBitmap = NULL; + } +#ifdef DEBUG + *theApp->getLog() << "Making new bitmap\n"; +#endif + m_pBitmap = new wxBitmap (image); 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); } @@ -1118,7 +1162,6 @@ ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) bool ImageFileView::OnClose (bool deleteWindow) { - //GetDocumentManager()->ActivateView (this, false, true); if (! GetDocument() || ! GetDocument()->Close()) return false; @@ -1147,8 +1190,9 @@ void ImageFileView::OnEditCopy (wxCommandEvent& event) { wxBitmapDataObject *pBitmapObject = new wxBitmapDataObject; - - pBitmapObject->SetBitmap (m_bitmap); + + if (m_pBitmap) + pBitmapObject->SetBitmap (*m_pBitmap); if (wxTheClipboard->Open()) { wxTheClipboard->SetData (pBitmapObject); @@ -1191,12 +1235,12 @@ ImageFileView::OnEditPaste (wxCommandEvent& event) bool bMonochrome = false; if (bitmap.Ok() == true && bitmap.GetWidth() == nx && bitmap.GetHeight() == ny) { - wxImage image (bitmap); + wxImage image (bitmap.ConvertToImage()); double dScale3 = 3 * 255; unsigned char* pixels = image.GetData(); ImageFileArray v = rIF.getArray(); - for (int ix = 0; ix < rIF.nx(); ix++) { - for (int iy = 0; iy < rIF.ny(); iy++) { + for (unsigned int ix = 0; ix < rIF.nx(); ix++) { + for (unsigned int iy = 0; iy < rIF.ny(); iy++) { unsigned int iBase = 3 * (iy * nx + ix); if (ix == 0 && iy == 0 && (pixels[iBase] == pixels[iBase+1] && pixels[iBase+1] == pixels[iBase+2])) bMonochrome = true; @@ -1303,8 +1347,9 @@ ImageFileView::OnScaleSize (wxCommandEvent& event) *theApp->getLog() << os.str().c_str() << "\n"; if (theApp->getAskDeleteNewDocs()) pScaledDoc->Modify (true); + OnUpdate(this, NULL); pScaledDoc->UpdateAllViews (this); - pScaledDoc->getView()->getFrame()->Show(true); + pScaledDoc->getView()->setInitialClientSize(); pScaledDoc->Activate(); } } @@ -1315,13 +1360,12 @@ ImageFileView::OnConvert3d (wxCommandEvent& event) { ImageFile& rIF = GetDocument()->getImageFile(); Graph3dFileDocument* pGraph3d = theApp->newGraph3dDoc(); + pGraph3d->getView()->getFrame()->Show (false); pGraph3d->setBadFileOpen(); pGraph3d->createFromImageFile (rIF); - pGraph3d->getView()->OnUpdate (this, NULL); pGraph3d->UpdateAllViews(); - pGraph3d->getView()->getFrame()->SetClientSize (400, 400); pGraph3d->getView()->getFrame()->Show (true); - GetDocumentManager()->ActivateView (pGraph3d->getView(), true, false); + pGraph3d->getView()->Activate(true); ::wxYield(); pGraph3d->getView()->getCanvas()->SetFocus(); } @@ -1949,9 +1993,8 @@ ImageFileView::OnPlotHistogram (wxCommandEvent& event) // PhantomCanvas PhantomCanvas::PhantomCanvas (PhantomFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style) -: wxScrolledWindow(frame, -1, pos, size, style) + : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v) { - m_pView = v; } PhantomCanvas::~PhantomCanvas () @@ -1975,7 +2018,12 @@ PhantomCanvas::GetBestSize() const int xSize, ySize; theApp->getMainFrame()->GetClientSize (&xSize, &ySize); xSize = maxValue (xSize, ySize); +#ifdef CTSIM_MDI ySize = xSize = (xSize / 4); +#else + xSize = ySize = static_cast(ySize * .7); +#endif + return wxSize (xSize, ySize); } @@ -2003,6 +2051,7 @@ PhantomFileView::PhantomFileView() m_iDefaultNView = 320; m_iDefaultNSample = 2; #endif + m_iDefaultOffsetView = 0; m_dDefaultRotation = 1; m_dDefaultFocalLength = 2; m_dDefaultCenterDetectorLength = 2; @@ -2051,7 +2100,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 +2109,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 +2126,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 +2137,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 +2173,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,11 +2190,13 @@ 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); - if (! dlgProgress.Update (i+1)) { - delete pProj; - return; - } + //theScanner.collectProjections (*pProj, rPhantom, i, 1, true, m_iDefaultTrace); + theScanner.collectProjections (*pProj, rPhantom, i, 1, theScanner.offsetView(), true, m_iDefaultTrace); + if ((i + 1) % ITER_PER_UPDATE == 0) + if (! dlgProgress.Update (i+1)) { + delete pProj; + return; + } } } } @@ -2154,21 +2211,11 @@ 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); + OnUpdate(this, NULL); pProjectionDoc->UpdateAllViews (this); + pProjectionDoc->getView()->setInitialClientSize(); pProjectionDoc->Activate(); } @@ -2213,15 +2260,22 @@ 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 ); + + wxProgressDialog dlgProgress (wxString("Rasterize"), + wxString("Rasterization Progress"), + 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; - } + rPhantom.convertToImagefile (*pImageFile, m_dDefaultRasterViewRatio, + m_iDefaultRasterNSamples, Trace::TRACE_NONE, + i, 1, true); + if ((i + 1) % ITER_PER_UPDATE == 0) + if (! dlgProgress.Update (i+1)) { + delete pImageFile; + return; + } } ImageFileDocument* pRasterDoc = theApp->newImageDoc(); @@ -2232,15 +2286,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(); } } @@ -2249,9 +2299,8 @@ PhantomFileView::OnRasterize (wxCommandEvent& event) PhantomCanvas* PhantomFileView::CreateCanvas (wxFrame *parent) { - PhantomCanvas* pCanvas; - - pCanvas = new PhantomCanvas (this, parent, wxPoint(0, 0), wxSize(0,0), 0); + PhantomCanvas* pCanvas = new PhantomCanvas (this, parent, wxPoint(-1,-1), + wxSize(-1,-1), 0); pCanvas->SetBackgroundColour(*wxWHITE); pCanvas->Clear(); @@ -2266,9 +2315,9 @@ wxDocChildFrame* PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view) { #if CTSIM_MDI - wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE); + wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE); #else - wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE); + wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE); #endif theApp->setIconForFrame (subframe); @@ -2289,11 +2338,9 @@ PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view) m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view"); m_pFileMenu->AppendSeparator(); m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M"); -#ifdef CTSIM_MDI m_pFileMenu->AppendSeparator(); m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces..."); m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit"); -#endif GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu); GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu); @@ -2335,15 +2382,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); @@ -2360,7 +2400,6 @@ PhantomFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) bool PhantomFileView::OnClose (bool deleteWindow) { - //GetDocumentManager()->ActivateView (this, false, true); if (! GetDocument() || ! GetDocument()->Close()) return false; @@ -2420,13 +2459,26 @@ ProjectionFileCanvas::OnDraw(wxDC& dc) wxSize ProjectionFileCanvas::GetBestSize () const { - wxSize best (0, 0); + const int iMinX = 50; + const int iMinY = 20; + wxSize bestSize (iMinX,iMinY); + if (m_pView) { Projections& rProj = m_pView->GetDocument()->getProjections(); - best.Set (rProj.nDet(), rProj.nView()); + bestSize.Set (rProj.nDet(), rProj.nView()); } - return best; + if (bestSize.x > 800) + bestSize.x = 800; + if (bestSize.y > 800) + bestSize.y = 800; + + if (bestSize.x < iMinX) + bestSize.x = iMinX; + if (bestSize.y < iMinY) + bestSize.y = iMinY; + + return bestSize; } @@ -2445,12 +2497,12 @@ 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() ProjectionFileView::ProjectionFileView() -: wxView(), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0) + : wxView(), m_pBitmap(0), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0) { #ifdef DEBUG m_iDefaultNX = 115; @@ -2469,7 +2521,7 @@ ProjectionFileView::ProjectionFileView() m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION; m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT; #endif - m_iDefaultZeropad = 1; + m_iDefaultZeropad = 2; m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF; m_iDefaultInterpolation = Backprojector::INTERP_LINEAR; m_iDefaultInterpParam = 1; @@ -2478,7 +2530,7 @@ ProjectionFileView::ProjectionFileView() m_iDefaultPolarNX = 256; m_iDefaultPolarNY = 256; m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR; - m_iDefaultPolarZeropad = 1; + m_iDefaultPolarZeropad = 2; } ProjectionFileView::~ProjectionFileView() @@ -2529,8 +2581,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(); } @@ -2539,13 +2591,12 @@ ProjectionFileView::OnConvertPolar (wxCommandEvent& event) { Projections& rProj = GetDocument()->getProjections(); DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert Polar", m_iDefaultPolarNX, m_iDefaultPolarNY, - m_iDefaultPolarInterpolation, -1); + m_iDefaultPolarInterpolation, -1, IDH_DLG_POLAR); if (dialogPolar.ShowModal() == wxID_OK) { wxProgressDialog dlgProgress (wxString("Convert Polar"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL); wxString strInterpolation (dialogPolar.getInterpolationName()); m_iDefaultPolarNX = dialogPolar.getXSize(); m_iDefaultPolarNY = dialogPolar.getYSize(); - ImageFileDocument* pPolarDoc = theApp->newImageDoc(); ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY); m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str()); @@ -2555,7 +2606,7 @@ ProjectionFileView::OnConvertPolar (wxCommandEvent& event) return; } - pPolarDoc = theApp->newImageDoc (); + ImageFileDocument* pPolarDoc = theApp->newImageDoc(); if (! pPolarDoc) { sys_error (ERR_SEVERE, "Unable to create image file"); return; @@ -2570,8 +2621,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(); } } @@ -2581,7 +2632,7 @@ ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event) { Projections& rProj = GetDocument()->getProjections(); DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert to FFT Polar", m_iDefaultPolarNX, m_iDefaultPolarNY, - m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad); + m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad, IDH_DLG_FFT_POLAR); if (dialogPolar.ShowModal() == wxID_OK) { wxProgressDialog dlgProgress (wxString("Convert FFT Polar"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL); wxString strInterpolation (dialogPolar.getInterpolationName()); @@ -2611,8 +2662,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 +2811,7 @@ ProjectionFileView::OnConvertParallel (wxCommandEvent& event) if (theApp->getAskDeleteNewDocs()) pProjDocNew-> Modify(true); pProjDocNew->UpdateAllViews (this); + pProjDocNew->getView()->setInitialClientSize(); pProjDocNew->Activate(); } @@ -2768,7 +2820,7 @@ ProjectionFileView::OnReconstructFourier (wxCommandEvent& event) { Projections& rProj = GetDocument()->getProjections(); DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Fourier Reconstruction", m_iDefaultPolarNX, m_iDefaultPolarNY, - m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad); + m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad, IDH_DLG_RECON_FOURIER); if (dialogPolar.ShowModal() == wxID_OK) { wxProgressDialog dlgProgress (wxString("Reconstruction Fourier"), wxString("Reconstruction Progress"), 1, getFrameForChild(), wxPD_APP_MODAL); wxString strInterpolation (dialogPolar.getInterpolationName()); @@ -2783,7 +2835,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 +2856,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(); } } @@ -2920,10 +2974,11 @@ ProjectionFileView::doReconstructFBP (const Projections& rProj, bool bRebinToPar for (int iView = 0; iView < rProj.nView(); iView++) { pReconstructor->reconstructView (iView, 1); - if (! dlgProgress.Update (iView + 1)) { - delete pReconstructor; - return; // don't make new window, thread will do this - } + if ((iView + 1) % ITER_PER_UPDATE == 0) + if (! dlgProgress.Update (iView + 1)) { + delete pReconstructor; + return; // don't make new window, thread will do this + } } pReconstructor->postProcessing(); delete pReconstructor; @@ -2934,19 +2989,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()); } @@ -2963,7 +3015,7 @@ ProjectionFileView::CreateCanvas (wxFrame *parent) int width, height; parent->GetClientSize(&width, &height); - pCanvas = new ProjectionFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0); + pCanvas = new ProjectionFileCanvas (this, parent, wxPoint(-1,-1), wxSize(width, height), 0); pCanvas->SetScrollbars(20, 20, 50, 50); pCanvas->SetBackgroundColour(*wxWHITE); @@ -2980,9 +3032,9 @@ wxDocChildFrame* ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view) { #ifdef CTSIM_MDI - wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE); + wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE); #else - wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE); + wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE); #endif theApp->setIconForFrame (subframe); @@ -3004,32 +3056,30 @@ ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view) m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view"); m_pFileMenu->AppendSeparator(); m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M"); -#ifdef CTSIM_MDI m_pFileMenu->AppendSeparator(); m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces..."); m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit"); -#endif GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu); GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu); - wxMenu *convert_menu = new wxMenu; - convert_menu->Append (PJMENU_CONVERT_RECTANGULAR, "&Rectangular Image"); - convert_menu->Append (PJMENU_CONVERT_POLAR, "&Polar Image...\tCtrl-L"); - convert_menu->Append (PJMENU_CONVERT_FFT_POLAR, "FF&T->Polar Image...\tCtrl-T"); - convert_menu->AppendSeparator(); - convert_menu->Append (PJMENU_CONVERT_PARALLEL, "&Interpolate to Parallel"); + m_pConvertMenu = new wxMenu; + m_pConvertMenu->Append (PJMENU_CONVERT_RECTANGULAR, "&Rectangular Image"); + m_pConvertMenu->Append (PJMENU_CONVERT_POLAR, "&Polar Image...\tCtrl-L"); + m_pConvertMenu->Append (PJMENU_CONVERT_FFT_POLAR, "FF&T->Polar Image...\tCtrl-T"); + m_pConvertMenu->AppendSeparator(); + m_pConvertMenu->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"); analyze_menu->Append (PJMENU_PLOT_TTHETA_SAMPLING, "Plot T-T&heta Sampling...\tCtrl-H"); - 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"); + m_pReconstructMenu = new wxMenu; + m_pReconstructMenu->Append (PJMENU_RECONSTRUCT_FBP, "&Filtered Backprojection...\tCtrl-R", "Reconstruct image using filtered backprojection"); + m_pReconstructMenu->Append (PJMENU_RECONSTRUCT_FBP_REBIN, "Filtered &Backprojection (Rebin to Parallel)...\tCtrl-B", "Reconstruct image using filtered backprojection"); + m_pReconstructMenu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Inverse Fourier...\tCtrl-E", "Direct inverse Fourier"); wxMenu *help_menu = new wxMenu; help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1"); @@ -3040,10 +3090,10 @@ ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view) wxMenuBar *menu_bar = new wxMenuBar; menu_bar->Append (m_pFileMenu, "&File"); - menu_bar->Append (convert_menu, "&Convert"); - menu_bar->Append (filter_menu, "Fi<er"); + menu_bar->Append (m_pConvertMenu, "&Convert"); + // menu_bar->Append (filter_menu, "Fi<er"); menu_bar->Append (analyze_menu, "&Analyze"); - menu_bar->Append (reconstruct_menu, "&Reconstruct"); + menu_bar->Append (m_pReconstructMenu, "&Reconstruct"); menu_bar->Append (help_menu, "&Help"); subframe->SetMenuBar(menu_bar); @@ -3069,18 +3119,11 @@ ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) { m_pFrame = CreateChildFrame(doc, this); SetFrame(m_pFrame); - - int width, height; - m_pFrame->GetClientSize (&width, &height); - 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->SetClientSize (m_pCanvas->GetBestSize()); + m_pCanvas->SetClientSize (m_pCanvas->GetBestSize()); + m_pFrame->SetTitle ("ProjectionFileView"); + m_pFrame->Show(true); Activate(true); @@ -3090,23 +3133,37 @@ 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); + if (m_pBitmap && m_pBitmap->Ok()) + dc->DrawBitmap (*m_pBitmap, 0, 0, false); } +void +ProjectionFileView::setInitialClientSize () +{ + if (m_pFrame && m_pCanvas) { + wxSize bestSize = m_pCanvas->GetBestSize(); + + m_pFrame->SetClientSize (bestSize); + m_pFrame->Show (true); + m_pFrame->SetFocus(); + } +} + void ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) { const Projections& rProj = GetDocument()->getProjections(); const int nDet = rProj.nDet(); const int nView = rProj.nView(); + if (rProj.geometry() == Scanner::GEOMETRY_PARALLEL) { + m_pReconstructMenu->Enable (PJMENU_RECONSTRUCT_FBP_REBIN, false); + m_pConvertMenu->Enable (PJMENU_CONVERT_PARALLEL, false); + } else { + m_pReconstructMenu->Enable (PJMENU_RECONSTRUCT_FBP_REBIN, true); + m_pConvertMenu->Enable (PJMENU_CONVERT_PARALLEL, true); + } + if (nDet != 0 && nView != 0) { const DetectorArray& detarray = rProj.getDetectorArray(0); const DetectorValue* detval = detarray.detValues(); @@ -3140,18 +3197,19 @@ ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) } } wxImage image (nDet, nView, imageData, true); - m_bitmap = image.ConvertToBitmap(); + if (m_pBitmap) { + delete m_pBitmap; + m_pBitmap = NULL; + } + m_pBitmap = new wxBitmap (image); 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 @@ -3186,16 +3244,21 @@ ProjectionFileView::OnClose (bool deleteWindow) // PlotFileCanvas PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style) -: wxScrolledWindow(frame, -1, pos, size, style) + : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v) { - m_pView = v; } PlotFileCanvas::~PlotFileCanvas () { - m_pView = NULL; } +wxSize +PlotFileCanvas::GetBestSize() const +{ + return wxSize (500, 300); +} + + void PlotFileCanvas::OnDraw(wxDC& dc) { @@ -3216,7 +3279,8 @@ EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull) END_EVENT_TABLE() PlotFileView::PlotFileView() -: wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pEZPlot(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false) +: wxView(), m_pFrame(0), m_pCanvas(0), m_pEZPlot(0), m_pFileMenu(0), + m_bMinSpecified(false), m_bMaxSpecified(false) { } @@ -3226,6 +3290,7 @@ PlotFileView::~PlotFileView() delete m_pEZPlot; GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu); + GetDocumentManager()->ActivateView(this, FALSE, TRUE); } void @@ -3311,11 +3376,8 @@ PlotFileCanvas* PlotFileView::CreateCanvas (wxFrame* parent) { PlotFileCanvas* pCanvas; - int width, height; - parent->GetClientSize(&width, &height); - - pCanvas = new PlotFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0); + pCanvas = new PlotFileCanvas (this, parent, wxPoint(-1,-1), wxSize(-1,-1), 0); pCanvas->SetBackgroundColour(*wxWHITE); pCanvas->Clear(); @@ -3330,9 +3392,9 @@ wxDocChildFrame* PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view) { #ifdef CTSIM_MDI - wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE); + wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE); #else - wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE); + wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE); #endif theApp->setIconForFrame (subframe); @@ -3354,11 +3416,9 @@ PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view) m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view"); m_pFileMenu->AppendSeparator(); m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M"); -#ifdef CTSIM_MDI m_pFileMenu->AppendSeparator(); m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces..."); m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit"); -#endif GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu); GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu); @@ -3397,23 +3457,16 @@ PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view) bool PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) ) { - m_pFrame = CreateChildFrame(doc, this); - SetFrame(m_pFrame); - m_bMinSpecified = false; m_bMaxSpecified = false; m_dAutoScaleFactor = 1.; - int width, height; - m_pFrame->GetClientSize(&width, &height); - m_pFrame->SetTitle ("Plot File"); + m_pFrame = CreateChildFrame(doc, this); + SetFrame(m_pFrame); 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->SetClientSize (m_pCanvas->GetBestSize()); + m_pCanvas->SetClientSize (m_pCanvas->GetBestSize()); + m_pFrame->SetTitle ("Plot File"); m_pFrame->Show(true); Activate(true); @@ -3421,6 +3474,19 @@ PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) ) return true; } +void +PlotFileView::setInitialClientSize () +{ + if (m_pFrame && m_pCanvas) { + wxSize bestSize = m_pCanvas->GetBestSize(); + + m_pFrame->SetClientSize (bestSize); + m_pFrame->Show (true); + m_pFrame->SetFocus(); + } +} + + void PlotFileView::OnDraw (wxDC* dc) { @@ -3495,7 +3561,6 @@ PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) bool PlotFileView::OnClose (bool deleteWindow) { - //GetDocumentManager()->ActivateView (this, false, true); if (! GetDocument() || ! GetDocument()->Close()) return false; @@ -3539,16 +3604,9 @@ bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) int width, height; m_pFrame->GetClientSize(&width, &height); m_pFrame->SetTitle("TextFile"); - m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY); + m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(-1,-1), 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); @@ -3594,7 +3652,7 @@ wxDocChildFrame* TextFileView::CreateChildFrame (wxDocument *doc, wxView *view) { #if CTSIM_MDI - wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(0,0), wxDEFAULT_FRAME_STYLE, "Log"); + wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE, "Log"); #else wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE, "Log"); #endif @@ -3615,11 +3673,9 @@ TextFileView::CreateChildFrame (wxDocument *doc, wxView *view) m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view"); m_pFileMenu->AppendSeparator(); m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M"); -#ifdef CTSIM_MDI m_pFileMenu->AppendSeparator(); m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces..."); m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit"); -#endif GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu); GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu); @@ -3651,3 +3707,17 @@ TextFileCanvas::~TextFileCanvas () { m_pView = NULL; } + +wxSize +TextFileCanvas::GetBestSize() const +{ + int xSize, ySize; + theApp->getMainFrame()->GetClientSize (&xSize, &ySize); + xSize = maxValue (xSize, ySize); +#ifdef CTSIM_MDI + ySize = xSize = (xSize / 4); +#else + ySize = xSize; +#endif + return wxSize (xSize, ySize); +}