+void
+PhantomFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
+{
+ if (m_pCanvas)
+ m_pCanvas->Refresh();
+}
+
+bool
+PhantomFileView::OnClose (bool deleteWindow)
+{
+ //GetDocumentManager()->ActivateView (this, false, true);
+ if (! GetDocument() || ! GetDocument()->Close())
+ return false;
+
+ Activate(false);
+ if (m_pCanvas) {
+ m_pCanvas->setView(NULL);
+ m_pCanvas = NULL;
+ }
+ wxString s(wxTheApp->GetAppName());
+ if (m_pFrame)
+ m_pFrame->SetTitle(s);
+
+ SetFrame(NULL);
+
+ if (deleteWindow) {
+ delete m_pFrame;
+ m_pFrame = NULL;
+ if (GetDocument() && GetDocument()->getBadFileOpen())
+ ::wxYield(); // wxWindows bug workaround
+ }
+
+ return true;
+}
+
+void
+PhantomFileView::OnDraw (wxDC* dc)
+{
+ int xsize, ysize;
+ m_pCanvas->GetClientSize (&xsize, &ysize);
+ SGPDriver driver (dc, xsize, ysize);
+ SGP sgp (driver);
+ const Phantom& rPhantom = GetDocument()->getPhantom();
+ sgp.setColor (C_RED);
+ rPhantom.show (sgp);
+}
+
+// ProjectionCanvas
+
+ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
+: wxScrolledWindow(frame, -1, pos, size, style)
+{
+ m_pView = v;
+}
+
+ProjectionFileCanvas::~ProjectionFileCanvas ()
+{
+ m_pView = NULL;
+}
+
+void
+ProjectionFileCanvas::OnDraw(wxDC& dc)
+{
+ if (m_pView)
+ m_pView->OnDraw(& dc);
+}
+
+wxSize
+ProjectionFileCanvas::GetBestSize () const
+{
+ wxSize best (0, 0);
+ if (m_pView) {
+ Projections& rProj = m_pView->GetDocument()->getProjections();
+ best.Set (rProj.nDet(), rProj.nView());
+ }
+
+ return best;
+}
+
+
+// ProjectionFileView
+
+IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
+
+BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
+EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
+EVT_MENU(PJMENU_RECONSTRUCT_FBP, ProjectionFileView::OnReconstructFBP)
+EVT_MENU(PJMENU_CONVERT_POLAR, ProjectionFileView::OnConvertPolar)
+EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
+END_EVENT_TABLE()
+
+ProjectionFileView::ProjectionFileView()
+: wxView(), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0)
+{
+#ifdef DEBUG
+ m_iDefaultNX = 115;
+ m_iDefaultNY = 115;
+#else
+ m_iDefaultNX = 256;
+ m_iDefaultNY = 256;
+#endif
+
+ m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
+ m_dDefaultFilterParam = 1.;
+#if HAVE_FFTW
+ m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
+ m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
+#else
+ m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
+ m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
+#endif
+ m_iDefaultZeropad = 1;
+ m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF;
+ m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
+ m_iDefaultInterpParam = 1;
+ m_iDefaultTrace = Trace::TRACE_NONE;
+
+ m_iDefaultPolarNX = 256;
+ m_iDefaultPolarNY = 256;
+ m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR;
+ m_iDefaultPolarZeropad = 1;
+}
+
+ProjectionFileView::~ProjectionFileView()
+{
+ GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
+ GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
+}
+
+void
+ProjectionFileView::OnProperties (wxCommandEvent& event)
+{
+ const Projections& rProj = GetDocument()->getProjections();
+ std::ostringstream os;
+ rProj.printScanInfo(os);
+ *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
+ wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
+ dialogMsg.ShowModal();
+}
+
+
+void
+ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
+{
+ Projections& rProj = GetDocument()->getProjections();
+ DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
+ m_iDefaultPolarInterpolation, -1);
+ if (dialogPolar.ShowModal() == wxID_OK) {
+ wxString strInterpolation (dialogPolar.getInterpolationName());
+ m_iDefaultPolarNX = dialogPolar.getXSize();
+ m_iDefaultPolarNY = dialogPolar.getYSize();
+ ImageFileDocument* pPolarDoc = theApp->newImageDoc();
+ ImageFile& rIF = pPolarDoc->getImageFile();
+ if (! pPolarDoc) {
+ sys_error (ERR_SEVERE, "Unable to create image file");
+ return;
+ }
+ rIF.setArraySize (m_iDefaultPolarNX, m_iDefaultPolarNY);
+ m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
+ rProj.convertPolar (rIF, m_iDefaultPolarInterpolation);
+ rIF.labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
+ std::ostringstream os;
+ os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to polar image: xSize="
+ << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
+ << strInterpolation.c_str();
+ *theApp->getLog() << os.str().c_str() << "\n";
+ rIF.labelAdd (os.str().c_str());
+ if (theApp->getAskDeleteNewDocs())
+ pPolarDoc->Modify (true);
+ pPolarDoc->UpdateAllViews ();
+ pPolarDoc->getView()->OnUpdate (this, NULL);
+ pPolarDoc->getView()->getFrame()->Show(true);
+ }
+}
+
+void
+ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
+{
+ Projections& rProj = GetDocument()->getProjections();
+ DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert to FFT Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
+ m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad);
+ if (dialogPolar.ShowModal() == wxID_OK) {
+ wxString strInterpolation (dialogPolar.getInterpolationName());
+ m_iDefaultPolarNX = dialogPolar.getXSize();
+ m_iDefaultPolarNY = dialogPolar.getYSize();
+ m_iDefaultPolarZeropad = dialogPolar.getZeropad();
+ ImageFileDocument* pPolarDoc = theApp->newImageDoc();
+ ImageFile& rIF = pPolarDoc->getImageFile();
+ if (! pPolarDoc) {
+ sys_error (ERR_SEVERE, "Unable to create image file");
+ return;
+ }
+ rIF.setArraySize (m_iDefaultPolarNX, m_iDefaultPolarNY);
+ m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
+ rProj.convertFFTPolar (rIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad);
+ rIF.labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
+ std::ostringstream os;
+ os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to FFT polar image: xSize="
+ << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
+ << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
+ *theApp->getLog() << os.str().c_str() << "\n";
+ rIF.labelAdd (os.str().c_str());
+ if (theApp->getAskDeleteNewDocs())
+ pPolarDoc->Modify (true);
+ pPolarDoc->UpdateAllViews ();
+ pPolarDoc->getView()->OnUpdate (this, NULL);
+ pPolarDoc->getView()->getFrame()->Show(true);
+ }
+}
+
+void
+ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
+{
+ wxMessageBox ("Fourier Reconstruction is not yet supported", "Unimplemented function");
+}
+
+void
+ProjectionFileView::OnReconstructFBP (wxCommandEvent& event)
+{
+ DialogGetReconstructionParameters dialogReconstruction (getFrameForChild(), m_iDefaultNX, m_iDefaultNY,
+ m_iDefaultFilter, m_dDefaultFilterParam, m_iDefaultFilterMethod, m_iDefaultFilterGeneration,
+ m_iDefaultZeropad, m_iDefaultInterpolation, m_iDefaultInterpParam, m_iDefaultBackprojector,
+ m_iDefaultTrace);
+
+ int retVal = dialogReconstruction.ShowModal();
+ if (retVal == wxID_OK) {
+ m_iDefaultNX = dialogReconstruction.getXSize();
+ m_iDefaultNY = dialogReconstruction.getYSize();
+ wxString optFilterName = dialogReconstruction.getFilterName();
+ m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
+ m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
+ wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
+ m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
+ m_iDefaultZeropad = dialogReconstruction.getZeropad();
+ wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
+ m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
+ wxString optInterpName = dialogReconstruction.getInterpName();
+ m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
+ m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
+ wxString optBackprojectName = dialogReconstruction.getBackprojectName();
+ m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
+ m_iDefaultTrace = dialogReconstruction.getTrace();
+ if (m_iDefaultNX > 0 && m_iDefaultNY > 0) {
+ const Projections& rProj = GetDocument()->getProjections();
+
+ ImageFile* pImageFile = new ImageFile;
+ pImageFile->setArraySize (m_iDefaultNX, m_iDefaultNY);
+
+ Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(), m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(), optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace);
+
+ Timer timerRecon;
+ if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
+ ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstructor, rProj, *pImageFile, m_iDefaultTrace, getFrameForChild());
+ for (int iView = 0; iView < rProj.nView(); iView++) {
+ ::wxYield();
+ if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView)) {
+ delete pDlgReconstruct;
+ delete pReconstructor;
+ delete pImageFile;
+ return;
+ }
+ ::wxYield();
+ while (pDlgReconstruct->isPaused()) {
+ ::wxYield();
+ ::wxUsleep(50);
+ }
+ }
+ delete pDlgReconstruct;
+ } else {
+ wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT);
+ for (int i = 0; i < rProj.nView(); i++) {
+ pReconstructor->reconstructView (i, 1);
+ if (! dlgProgress.Update (i + 1)) {
+ delete pReconstructor;
+ delete pImageFile;
+ return;
+ }
+ }
+ }
+ delete pReconstructor;
+ ImageFileDocument* pReconDoc = theApp->newImageDoc();
+ if (! pReconDoc) {
+ sys_error (ERR_SEVERE, "Unable to create image file");
+ return;
+ }
+ pReconDoc->setImageFile (pImageFile);
+ if (theApp->getAskDeleteNewDocs())
+ pReconDoc->Modify (true);
+ pReconDoc->UpdateAllViews (this);
+ if (ImageFileView* rasterView = pReconDoc->getView()) {
+ rasterView->OnUpdate (rasterView, NULL);
+ rasterView->getFrame()->SetFocus();
+ rasterView->getFrame()->Show(true);
+ }
+ std::ostringstream os;
+ os << "Reconstruct " << rProj.getFilename() << ": xSize=" << m_iDefaultNX << ", ySize=" << m_iDefaultNY << ", Filter=" << optFilterName.c_str() << ", FilterParam=" << m_dDefaultFilterParam << ", FilterMethod=" << optFilterMethodName.c_str() << ", FilterGeneration=" << optFilterGenerationName.c_str() << ", Zeropad=" << m_iDefaultZeropad << ", Interpolation=" << optInterpName.c_str() << ", InterpolationParam=" << m_iDefaultInterpParam << ", Backprojection=" << optBackprojectName.c_str();
+ *theApp->getLog() << os.str().c_str() << "\n";
+ pImageFile->labelAdd (rProj.getLabel());
+ pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd());
+ }
+ }
+}
+
+
+ProjectionFileCanvas*
+ProjectionFileView::CreateCanvas (wxFrame *parent)
+{
+ ProjectionFileCanvas* pCanvas;
+ int width, height;
+ parent->GetClientSize(&width, &height);
+
+ pCanvas = new ProjectionFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
+
+ pCanvas->SetScrollbars(20, 20, 50, 50);
+ pCanvas->SetBackgroundColour(*wxWHITE);
+ pCanvas->Clear();
+
+ return pCanvas;
+}
+
+#if CTSIM_MDI
+wxDocMDIChildFrame*
+#else
+wxDocChildFrame*
+#endif
+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);
+#else
+ wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), 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");
+ m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
+ m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
+ m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
+ m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
+
+ m_pFileMenu->AppendSeparator();
+ m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
+
+ m_pFileMenu->AppendSeparator();
+ m_pFileMenu->Append(wxID_PRINT, "&Print...");
+ m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
+ m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
+#ifdef CTSIM_MDI
+ m_pFileMenu->AppendSeparator();
+ m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Pr&eferences...");
+ 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_POLAR, "&Polar Image...\tCtrl-L");
+ convert_menu->Append (PJMENU_CONVERT_FFT_POLAR, "&FFT->Polar Image...\tCtrl-I");
+
+ 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_FOURIER, "&Fourier...\tCtrl-E", "Reconstruct image using inverse Fourier");
+ reconstruct_menu->Enable (PJMENU_RECONSTRUCT_FOURIER, false);
+
+ wxMenu *help_menu = new wxMenu;
+ help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
+ help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
+ help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
+
+ wxMenuBar *menu_bar = new wxMenuBar;
+
+ menu_bar->Append (m_pFileMenu, "&File");
+ menu_bar->Append (convert_menu, "&Convert");
+ menu_bar->Append (reconstruct_menu, "&Reconstruct");
+ menu_bar->Append (help_menu, "&Help");
+
+ subframe->SetMenuBar(menu_bar);
+ subframe->Centre(wxBOTH);
+
+ wxAcceleratorEntry accelEntries[11];
+ accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
+ accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
+ accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
+ accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
+ accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
+ accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
+ accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
+ accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('L'), PJMENU_CONVERT_POLAR);
+ accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('I'), PJMENU_CONVERT_FFT_POLAR);
+ accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('R'), PJMENU_RECONSTRUCT_FBP);
+ accelEntries[10].Set (wxACCEL_CTRL, static_cast<int>('E'), PJMENU_RECONSTRUCT_FOURIER);
+ wxAcceleratorTable accelTable (11, accelEntries);
+ subframe->SetAcceleratorTable (accelTable);
+
+ return subframe;
+}
+
+
+bool
+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->Show(true);
+ Activate(true);
+
+ return true;