+ if (dialogGetCompare.ShowModal() == wxID_OK) {
+ ImageFile& rIF = GetDocument()->getImageFile();
+ ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
+ const ImageFile& rRHSIF = pRHSDoc->getImageFile();
+ ImageFileDocument* pNewDoc = theApp->newImageDoc();
+ if (! pNewDoc) {
+ sys_error (ERR_SEVERE, "Unable to create image file");
+ return;
+ }
+ ImageFile& newImage = pNewDoc->getImageFile();
+ newImage.setArraySize (rIF.nx(), rIF.ny());
+ rIF.divideImages (rRHSIF, newImage);
+ std::ostringstream os;
+ os << "Divide image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " by "
+ << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
+ wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
+ newImage.labelsCopy (rIF, s.c_str());
+ s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
+ newImage.labelsCopy (rRHSIF, s.c_str());
+ newImage.labelAdd (os.str().c_str());
+ *theApp->getLog() << os.str().c_str() << "\n";
+ if (theApp->getAskDeleteNewDocs())
+ pNewDoc->Modify (true);
+ pNewDoc->UpdateAllViews (this);
+ pNewDoc->getView()->getFrame()->Show(true);
+ pNewDoc->Activate();
+ }
+ }
+}
+
+
+#ifdef HAVE_FFT
+void
+ImageFileView::OnFFT (wxCommandEvent& event)
+{
+ ImageFile& rIF = GetDocument()->getImageFile();
+ rIF.fft (rIF);
+ rIF.labelAdd ("FFT Image");
+ m_bMinSpecified = false;
+ m_bMaxSpecified = false;
+ if (theApp->getAskDeleteNewDocs())
+ GetDocument()->Modify (true);
+ GetDocument()->UpdateAllViews (this);
+ GetDocument()->Activate();
+}
+
+void
+ImageFileView::OnIFFT (wxCommandEvent& event)
+{
+ ImageFile& rIF = GetDocument()->getImageFile();
+ rIF.ifft (rIF);
+ rIF.labelAdd ("IFFT Image");
+ m_bMinSpecified = false;
+ m_bMaxSpecified = false;
+ if (theApp->getAskDeleteNewDocs())
+ GetDocument()->Modify (true);
+ GetDocument()->UpdateAllViews (this);
+ GetDocument()->Activate();
+}
+
+void
+ImageFileView::OnFFTRows (wxCommandEvent& event)
+{
+ ImageFile& rIF = GetDocument()->getImageFile();
+ rIF.fftRows (rIF);
+ rIF.labelAdd ("FFT Rows");
+ m_bMinSpecified = false;
+ m_bMaxSpecified = false;
+ if (theApp->getAskDeleteNewDocs())
+ GetDocument()->Modify (true);
+ GetDocument()->UpdateAllViews (this);
+ GetDocument()->Activate();
+}
+
+void
+ImageFileView::OnIFFTRows (wxCommandEvent& event)
+{
+ ImageFile& rIF = GetDocument()->getImageFile();
+ rIF.ifftRows (rIF);
+ rIF.labelAdd ("IFFT Rows");
+ m_bMinSpecified = false;
+ m_bMaxSpecified = false;
+ if (theApp->getAskDeleteNewDocs())
+ GetDocument()->Modify (true);
+ GetDocument()->UpdateAllViews (this);
+ GetDocument()->Activate();
+}
+
+void
+ImageFileView::OnFFTCols (wxCommandEvent& event)
+{
+ ImageFile& rIF = GetDocument()->getImageFile();
+ rIF.fftCols (rIF);
+ rIF.labelAdd ("FFT Columns");
+ m_bMinSpecified = false;
+ m_bMaxSpecified = false;
+ if (theApp->getAskDeleteNewDocs())
+ GetDocument()->Modify (true);
+ GetDocument()->UpdateAllViews (this);
+ GetDocument()->Activate();
+}
+
+void
+ImageFileView::OnIFFTCols (wxCommandEvent& event)
+{
+ ImageFile& rIF = GetDocument()->getImageFile();
+ rIF.ifftCols (rIF);
+ rIF.labelAdd ("IFFT Columns");
+ m_bMinSpecified = false;
+ m_bMaxSpecified = false;
+ if (theApp->getAskDeleteNewDocs())
+ GetDocument()->Modify (true);
+ GetDocument()->UpdateAllViews (this);
+ GetDocument()->Activate();
+}
+#endif
+
+void
+ImageFileView::OnFourier (wxCommandEvent& event)
+{
+ ImageFile& rIF = GetDocument()->getImageFile();
+ wxProgressDialog dlgProgress (wxString("Fourier"), wxString("Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
+ rIF.fourier (rIF);
+ rIF.labelAdd ("Fourier Image");
+ m_bMinSpecified = false;
+ m_bMaxSpecified = false;
+ if (theApp->getAskDeleteNewDocs())
+ GetDocument()->Modify (true);
+ GetDocument()->UpdateAllViews (this);
+ GetDocument()->Activate();
+}
+
+void
+ImageFileView::OnInverseFourier (wxCommandEvent& event)
+{
+ ImageFile& rIF = GetDocument()->getImageFile();
+ wxProgressDialog dlgProgress (wxString("Inverse Fourier"), wxString("Inverse Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
+ rIF.inverseFourier (rIF);
+ rIF.labelAdd ("Inverse Fourier Image");
+ m_bMinSpecified = false;
+ m_bMaxSpecified = false;
+ if (theApp->getAskDeleteNewDocs())
+ GetDocument()->Modify (true);
+ GetDocument()->UpdateAllViews (this);
+ GetDocument()->Activate();
+}
+
+void
+ImageFileView::OnShuffleNaturalToFourierOrder (wxCommandEvent& event)
+{
+ ImageFile& rIF = GetDocument()->getImageFile();
+ Fourier::shuffleNaturalToFourierOrder (rIF);
+ rIF.labelAdd ("Shuffle Natural To Fourier Order");
+ m_bMinSpecified = false;
+ m_bMaxSpecified = false;
+ if (theApp->getAskDeleteNewDocs())
+ GetDocument()->Modify (true);
+ GetDocument()->UpdateAllViews (this);
+ GetDocument()->Activate();
+}
+
+void
+ImageFileView::OnShuffleFourierToNaturalOrder (wxCommandEvent& event)
+{
+ ImageFile& rIF = GetDocument()->getImageFile();
+ Fourier::shuffleFourierToNaturalOrder (rIF);
+ rIF.labelAdd ("Shuffle Fourier To Natural Order");
+ m_bMinSpecified = false;
+ m_bMaxSpecified = false;
+ if (theApp->getAskDeleteNewDocs())
+ GetDocument()->Modify (true);
+ GetDocument()->UpdateAllViews (this);
+ GetDocument()->Activate();
+}
+
+void
+ImageFileView::OnMagnitude (wxCommandEvent& event)
+{
+ ImageFile& rIF = GetDocument()->getImageFile();
+ if (rIF.isComplex()) {
+ rIF.magnitude (rIF);
+ rIF.labelAdd ("Magnitude of complex-image");
+ m_bMinSpecified = false;
+ m_bMaxSpecified = false;
+ if (theApp->getAskDeleteNewDocs())
+ GetDocument()->Modify (true);
+ GetDocument()->UpdateAllViews (this);
+ }
+ GetDocument()->Activate();
+}
+
+void
+ImageFileView::OnPhase (wxCommandEvent& event)
+{
+ ImageFile& rIF = GetDocument()->getImageFile();
+ if (rIF.isComplex()) {
+ rIF.phase (rIF);
+ rIF.labelAdd ("Phase of complex-image");
+ m_bMinSpecified = false;
+ m_bMaxSpecified = false;
+ if (theApp->getAskDeleteNewDocs())
+ GetDocument()->Modify (true);
+ GetDocument()->UpdateAllViews (this);
+ }
+ GetDocument()->Activate();
+}
+
+
+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);
+ pCanvas->SetBackgroundColour(*wxWHITE);
+ pCanvas->Clear();
+
+ return pCanvas;
+}
+
+#if CTSIM_MDI
+wxDocMDIChildFrame*
+#else
+wxDocChildFrame*
+#endif
+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);
+#else
+ wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), 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->Append(wxID_REVERT, "Re&vert");
+
+ m_pFileMenu->AppendSeparator();
+ m_pFileMenu->Append(IFMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
+ m_pFileMenu->Append(IFMENU_FILE_EXPORT, "&Export...");
+
+ m_pFileMenu->AppendSeparator();
+ m_pFileMenu->Append(wxID_PRINT, "&Print...");
+ m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
+ 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);
+
+ wxMenu* edit_menu = new wxMenu;
+ edit_menu->Append(IFMENU_EDIT_COPY, "Copy\tCtrl-C");
+ edit_menu->Append(IFMENU_EDIT_CUT, "Cut\tCtrl-X");
+ edit_menu->Append(IFMENU_EDIT_PASTE, "Paste\tCtrl-V");
+
+ wxMenu *view_menu = new wxMenu;
+ view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale S&et...\tCtrl-E");
+ view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
+ view_menu->Append(IFMENU_VIEW_SCALE_FULL, "Display F&ull Scale\tCtrl-U");
+
+ wxMenu* filter_menu = new wxMenu;
+ filter_menu->Append (IFMENU_FILTER_INVERTVALUES, "&Invert Values");
+ filter_menu->Append (IFMENU_FILTER_SQUARE, "&Square");
+ filter_menu->Append (IFMENU_FILTER_SQRT, "Square &Root");
+ filter_menu->Append (IFMENU_FILTER_LOG, "&Log");
+ filter_menu->Append (IFMENU_FILTER_EXP, "&Exp");
+ filter_menu->AppendSeparator();
+#ifdef HAVE_FFT
+ filter_menu->Append (IFMENU_FILTER_FFT, "2-D &FFT");
+ filter_menu->Append (IFMENU_FILTER_IFFT, "2-D &IFFT");
+ filter_menu->Append (IFMENU_FILTER_FFT_ROWS, "FFT Rows");
+ filter_menu->Append (IFMENU_FILTER_IFFT_ROWS, "IFFT Rows");
+ filter_menu->Append (IFMENU_FILTER_FFT_COLS, "FFT Columns");
+ filter_menu->Append (IFMENU_FILTER_IFFT_COLS, "IFFT Columns");
+ filter_menu->Append (IFMENU_FILTER_FOURIER, "2-D F&ourier");
+ filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "2-D Inverse Fo&urier");
+#else
+ filter_menu->Append (IFMENU_FILTER_FOURIER, "&Fourier");
+ filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "&Inverse Fourier");
+#endif
+ filter_menu->Append (IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, "S&huffle Fourier to Natural Order");
+ filter_menu->Append (IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, "Shu&ffle Natural to Fourier Order");
+ filter_menu->Append (IFMENU_FILTER_MAGNITUDE, "&Magnitude");
+ filter_menu->Append (IFMENU_FILTER_PHASE, "&Phase");
+
+ wxMenu* image_menu = new wxMenu;
+ image_menu->Append (IFMENU_IMAGE_ADD, "&Add...");
+ image_menu->Append (IFMENU_IMAGE_SUBTRACT, "&Subtract...");
+ image_menu->Append (IFMENU_IMAGE_MULTIPLY, "&Multiply...");
+ image_menu->Append (IFMENU_IMAGE_DIVIDE, "&Divide...");
+ image_menu->AppendSeparator();
+ image_menu->Append (IFMENU_IMAGE_SCALESIZE, "S&cale Size...");
+#if wxUSE_GLCANVAS
+ image_menu->Append (IFMENU_IMAGE_CONVERT3D, "Convert &3-D\tCtrl-3");
+#endif
+
+ m_pMenuAnalyze = new wxMenu;
+ m_pMenuAnalyze->Append (IFMENU_PLOT_ROW, "Plot &Row");
+ m_pMenuAnalyze->Append (IFMENU_PLOT_COL, "Plot &Column");
+ m_pMenuAnalyze->Append (IFMENU_PLOT_HISTOGRAM, "Plot &Histogram");
+ m_pMenuAnalyze->AppendSeparator();
+ m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_ROW, "P&lot FFT Row");
+ m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_COL, "Plo&t FFT Column");
+ m_pMenuAnalyze->AppendSeparator();
+ m_pMenuAnalyze->Append (IFMENU_COMPARE_IMAGES, "Compare &Images...");
+ m_pMenuAnalyze->Append (IFMENU_COMPARE_ROW, "Compare Ro&w");
+ m_pMenuAnalyze->Append (IFMENU_COMPARE_COL, "Compare Colu&mn");
+ m_pMenuAnalyze->Enable (IFMENU_PLOT_ROW, false);
+ m_pMenuAnalyze->Enable (IFMENU_PLOT_COL, false);
+ m_pMenuAnalyze->Enable (IFMENU_COMPARE_ROW, false);
+ m_pMenuAnalyze->Enable (IFMENU_COMPARE_COL, false);
+ m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_ROW, false);
+ m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_COL, false);
+
+ wxMenu *help_menu = new wxMenu;
+ help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
+ help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
+ help_menu->Append (IDH_QUICKSTART, "&Quick Start");
+ help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
+
+ wxMenuBar *menu_bar = new wxMenuBar;
+
+ menu_bar->Append(m_pFileMenu, "&File");
+ menu_bar->Append(edit_menu, "&Edit");
+ menu_bar->Append(view_menu, "&View");
+ menu_bar->Append(image_menu, "&Image");
+ menu_bar->Append(filter_menu, "Fi<er");
+ menu_bar->Append(m_pMenuAnalyze, "&Analyze");
+ menu_bar->Append(help_menu, "&Help");
+
+ subframe->SetMenuBar(menu_bar);
+
+ subframe->Centre(wxBOTH);
+
+ wxAcceleratorEntry accelEntries[8];
+ accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('A'), IFMENU_VIEW_SCALE_AUTO);
+ accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('U'), IFMENU_VIEW_SCALE_FULL);
+ accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('E'), IFMENU_VIEW_SCALE_MINMAX);
+ accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), IFMENU_FILE_PROPERTIES);
+ accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('C'), IFMENU_EDIT_COPY);
+ accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('X'), IFMENU_EDIT_CUT);
+ accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('V'), IFMENU_EDIT_PASTE);
+#if wxUSE_GLCANVAS
+ accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('3'), IFMENU_IMAGE_CONVERT3D);
+ wxAcceleratorTable accelTable (8, accelEntries);
+#else
+ wxAcceleratorTable accelTable (7, accelEntries);
+#endif
+
+ subframe->SetAcceleratorTable (accelTable);
+
+ return subframe;
+}
+
+
+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_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->Show(true);
+ Activate(true);
+
+ return true;
+}
+
+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);
+
+ int xCursor, yCursor;
+ if (m_pCanvas->GetCurrentCursor (xCursor, yCursor))
+ m_pCanvas->DrawRubberBandCursor (*dc, xCursor, yCursor);
+}
+
+
+void
+ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
+{
+ const ImageFile& rIF = GetDocument()->getImageFile();
+ ImageFileArrayConst v = rIF.getArray();
+ int nx = rIF.nx();
+ int ny = rIF.ny();
+ if (v != NULL && nx != 0 && ny != 0) {
+ if (! m_bMinSpecified || ! m_bMaxSpecified) {
+ double min, max;
+ rIF.getMinMax (min, max);
+ if (! m_bMinSpecified)
+ m_dMinPixel = min;
+ if (! m_bMaxSpecified)
+ m_dMaxPixel = max;
+ }
+ double scaleWidth = m_dMaxPixel - m_dMinPixel;