1 /*****************************************************************************
5 ** Purpose: View & Canvas routines for CTSim program
6 ** Programmer: Kevin Rosenberg
7 ** Date Started: July 2000
9 ** This is part of the CTSim program
10 ** Copyright (c) 1983-2001 Kevin Rosenberg
12 ** $Id: views.cpp,v 1.93 2001/01/30 10:58:13 kevin Exp $
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
28 // For compilers that support precompilation, includes "wx/wx.h".
29 #include "wx/wxprec.h"
39 #if !wxUSE_DOC_VIEW_ARCHITECTURE
40 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
44 #include "wx/progdlg.h"
51 #include "dlgprojections.h"
52 #include "dlgreconstruct.h"
53 #include "backprojectors.h"
54 #include "reconstruct.h"
57 #if defined(MSVC) || HAVE_SSTREAM
60 #include <sstream_subst>
66 BEGIN_EVENT_TABLE(ImageFileCanvas, wxScrolledWindow)
67 EVT_MOUSE_EVENTS(ImageFileCanvas::OnMouseEvent)
68 EVT_CHAR(ImageFileCanvas::OnChar)
72 ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
73 : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v), m_xCursor(-1), m_yCursor(-1)
77 ImageFileCanvas::~ImageFileCanvas()
83 ImageFileCanvas::OnDraw(wxDC& dc)
86 m_pView->OnDraw(& dc);
90 ImageFileCanvas::DrawRubberBandCursor (wxDC& dc, int x, int y)
92 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
97 dc.SetLogicalFunction (wxINVERT);
98 dc.SetPen (*wxGREEN_PEN);
99 dc.DrawLine (0, yPt, nx, yPt);
100 dc.DrawLine (x, 0, x, ny);
101 dc.SetLogicalFunction (wxCOPY);
105 ImageFileCanvas::GetCurrentCursor (int& x, int& y)
110 if (m_xCursor >= 0 && m_yCursor >= 0)
117 ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
125 wxPoint pt(event.GetLogicalPosition(dc));
127 const ImageFileDocument* pIFDoc = m_pView->GetDocument();
130 const ImageFile& rIF = pIFDoc->getImageFile();
131 ImageFileArrayConst v = rIF.getArray();
134 const int yPt = ny - 1 - pt.y;
135 if (event.RightIsDown()) {
136 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
137 std::ostringstream os;
138 os << "Image value (" << pt.x << "," << yPt << ") = " << v[pt.x][yPt];
139 if (rIF.isComplex()) {
140 double dImag = rIF.getImaginaryArray()[pt.x][yPt];
142 os << " - " << -dImag;
144 os << " + " << dImag;
148 *theApp->getLog() << os.str().c_str();
150 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
152 else if (event.LeftIsDown() || event.LeftUp() || event.RightUp()) {
153 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
154 if (m_xCursor >= 0 && m_yCursor >= 0) {
155 DrawRubberBandCursor (dc, m_xCursor, m_yCursor);
157 DrawRubberBandCursor (dc, pt.x, yPt);
160 wxMenu* pMenu = m_pView->getMenuAnalyze();
161 if (pMenu && ! pMenu->IsEnabled(IFMENU_PLOT_ROW)) {
162 pMenu->Enable (IFMENU_PLOT_ROW, true);
163 pMenu->Enable (IFMENU_PLOT_COL, true);
164 pMenu->Enable (IFMENU_COMPARE_ROW, true);
165 pMenu->Enable (IFMENU_COMPARE_COL, true);
166 pMenu->Enable (IFMENU_PLOT_FFT_ROW, true);
167 pMenu->Enable (IFMENU_PLOT_FFT_COL, true);
170 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
172 if (event.LeftUp()) {
173 std::ostringstream os;
174 os << "Selected column " << pt.x << " , row " << yPt << "\n";
175 *theApp->getLog() << os.str().c_str();
180 ImageFileCanvas::OnChar (wxKeyEvent& event)
182 if (event.GetKeyCode() == WXK_ESCAPE) {
186 m_pView->OnUpdate (NULL);
188 wxScrolledWindow::OnChar (event);
192 ImageFileCanvas::GetBestSize() const
197 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
198 return wxSize (rIF.nx(), rIF.ny());
204 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
206 BEGIN_EVENT_TABLE(ImageFileView, wxView)
207 EVT_MENU(IFMENU_FILE_EXPORT, ImageFileView::OnExport)
208 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
209 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
210 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
211 EVT_MENU(IFMENU_VIEW_SCALE_FULL, ImageFileView::OnScaleFull)
212 EVT_MENU(IFMENU_COMPARE_IMAGES, ImageFileView::OnCompare)
213 EVT_MENU(IFMENU_COMPARE_ROW, ImageFileView::OnCompareRow)
214 EVT_MENU(IFMENU_COMPARE_COL, ImageFileView::OnCompareCol)
215 EVT_MENU(IFMENU_FILTER_INVERTVALUES, ImageFileView::OnInvertValues)
216 EVT_MENU(IFMENU_FILTER_SQUARE, ImageFileView::OnSquare)
217 EVT_MENU(IFMENU_FILTER_SQRT, ImageFileView::OnSquareRoot)
218 EVT_MENU(IFMENU_FILTER_LOG, ImageFileView::OnLog)
219 EVT_MENU(IFMENU_FILTER_EXP, ImageFileView::OnExp)
220 EVT_MENU(IFMENU_FILTER_FOURIER, ImageFileView::OnFourier)
221 EVT_MENU(IFMENU_FILTER_INVERSE_FOURIER, ImageFileView::OnInverseFourier)
222 EVT_MENU(IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, ImageFileView::OnShuffleFourierToNaturalOrder)
223 EVT_MENU(IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, ImageFileView::OnShuffleNaturalToFourierOrder)
224 EVT_MENU(IFMENU_IMAGE_ADD, ImageFileView::OnAdd)
225 EVT_MENU(IFMENU_IMAGE_SUBTRACT, ImageFileView::OnSubtract)
226 EVT_MENU(IFMENU_IMAGE_MULTIPLY, ImageFileView::OnMultiply)
227 EVT_MENU(IFMENU_IMAGE_DIVIDE, ImageFileView::OnDivide)
228 EVT_MENU(IFMENU_IMAGE_SCALESIZE, ImageFileView::OnScaleSize)
229 EVT_MENU(IFMENU_IMAGE_CONVERT3D, ImageFileView::OnConvert3d)
231 EVT_MENU(IFMENU_FILTER_FFT, ImageFileView::OnFFT)
232 EVT_MENU(IFMENU_FILTER_IFFT, ImageFileView::OnIFFT)
233 EVT_MENU(IFMENU_FILTER_FFT_ROWS, ImageFileView::OnFFTRows)
234 EVT_MENU(IFMENU_FILTER_IFFT_ROWS, ImageFileView::OnIFFTRows)
235 EVT_MENU(IFMENU_FILTER_FFT_COLS, ImageFileView::OnFFTCols)
236 EVT_MENU(IFMENU_FILTER_IFFT_COLS, ImageFileView::OnIFFTCols)
238 EVT_MENU(IFMENU_FILTER_MAGNITUDE, ImageFileView::OnMagnitude)
239 EVT_MENU(IFMENU_FILTER_PHASE, ImageFileView::OnPhase)
240 EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)
241 EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol)
243 EVT_MENU(IFMENU_PLOT_FFT_ROW, ImageFileView::OnPlotFFTRow)
244 EVT_MENU(IFMENU_PLOT_FFT_COL, ImageFileView::OnPlotFFTCol)
246 EVT_MENU(IFMENU_PLOT_HISTOGRAM, ImageFileView::OnPlotHistogram)
249 ImageFileView::ImageFileView()
250 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
252 m_iDefaultExportFormatID = ImageFile::FORMAT_PNG;
255 ImageFileView::~ImageFileView()
257 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
258 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
263 ImageFileView::OnProperties (wxCommandEvent& event)
265 const ImageFile& rIF = GetDocument()->getImageFile();
266 if (rIF.nx() == 0 || rIF.ny() == 0)
267 *theApp->getLog() << "Properties: empty imagefile\n";
269 const std::string& rFilename = rIF.getFilename();
270 std::ostringstream os;
271 double min, max, mean, mode, median, stddev;
272 rIF.statistics (rIF.getArray(), min, max, mean, mode, median, stddev);
273 os << "Filename: " << rFilename << "\n";
274 os << "Size: (" << rIF.nx() << "," << rIF.ny() << ")\n";
280 os << "Minimum: "<<min<<"\nMaximum: "<<max<<"\nMean: "<<mean<<"\nMedian: "<<median<<"\nMode: "<<mode<<"\nStandard Deviation: "<<stddev << "\n";
281 if (rIF.isComplex()) {
282 rIF.statistics (rIF.getImaginaryArray(), min, max, mean, mode, median, stddev);
283 os << "Imaginary: min: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
285 if (rIF.nLabels() > 0) {
286 rIF.printLabelsBrief (os);
288 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
289 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
290 dialogMsg.ShowModal();
295 ImageFileView::OnScaleAuto (wxCommandEvent& event)
297 const ImageFile& rIF = GetDocument()->getImageFile();
298 double min, max, mean, mode, median, stddev;
299 rIF.statistics(min, max, mean, mode, median, stddev);
300 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
301 int iRetVal = dialogAutoScale.ShowModal();
302 if (iRetVal == wxID_OK) {
303 m_bMinSpecified = true;
304 m_bMaxSpecified = true;
306 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
309 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
310 OnUpdate (this, NULL);
316 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
318 const ImageFile& rIF = GetDocument()->getImageFile();
320 if (! m_bMinSpecified && ! m_bMaxSpecified)
321 rIF.getMinMax (min, max);
328 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Image Minimum & Maximum", min, max);
329 int retVal = dialogMinMax.ShowModal();
330 if (retVal == wxID_OK) {
331 m_bMinSpecified = true;
332 m_bMaxSpecified = true;
333 m_dMinPixel = dialogMinMax.getMinimum();
334 m_dMaxPixel = dialogMinMax.getMaximum();
335 OnUpdate (this, NULL);
340 ImageFileView::OnScaleFull (wxCommandEvent& event)
342 if (m_bMinSpecified || m_bMaxSpecified) {
343 m_bMinSpecified = false;
344 m_bMaxSpecified = false;
345 OnUpdate (this, NULL);
350 ImageFileView::OnCompare (wxCommandEvent& event)
352 std::vector<ImageFileDocument*> vecIF;
353 theApp->getCompatibleImages (GetDocument(), vecIF);
355 if (vecIF.size() == 0) {
356 wxMessageBox("There are no compatible image files open for comparision", "No comparison images");
358 DialogGetComparisonImage dialogGetCompare(getFrameForChild(), "Get Comparison Image", vecIF, true);
360 if (dialogGetCompare.ShowModal() == wxID_OK) {
361 const ImageFile& rIF = GetDocument()->getImageFile();
362 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
363 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
364 std::ostringstream os;
365 double min, max, mean, mode, median, stddev;
366 rIF.statistics (min, max, mean, mode, median, stddev);
367 os << GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
368 rCompareIF.statistics (min, max, mean, mode, median, stddev);
369 os << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
371 rIF.comparativeStatistics (rCompareIF, d, r, e);
372 os << "Comparative Statistics: d=" << d << ", r=" << r << ", e=" << e << "\n";
373 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
374 if (dialogGetCompare.getMakeDifferenceImage()) {
375 ImageFile* pDifferenceImage = new ImageFile;
377 pDifferenceImage->setArraySize (rIF.nx(), rIF.ny());
378 if (! rIF.subtractImages (rCompareIF, *pDifferenceImage)) {
379 *theApp->getLog() << "Unable to subtract images\n";
380 delete pDifferenceImage;
383 ImageFileDocument* pDifferenceDoc = theApp->newImageDoc();
384 if (! pDifferenceDoc) {
385 sys_error (ERR_SEVERE, "Unable to create image file");
388 pDifferenceDoc->setImageFile (pDifferenceImage);
390 wxString s = GetFrame()->GetTitle() + ": ";
391 pDifferenceImage->labelsCopy (rIF, s.c_str());
392 s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
393 pDifferenceImage->labelsCopy (rCompareIF, s.c_str());
394 std::ostringstream osLabel;
395 osLabel << "Compare image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str()
396 << " and " << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": "
398 pDifferenceImage->labelAdd (os.str().c_str());
399 pDifferenceDoc->Modify (true);
400 pDifferenceDoc->UpdateAllViews (this);
401 pDifferenceDoc->getView()->OnUpdate (this, NULL);
402 pDifferenceDoc->getView()->getFrame()->Show(true);
404 wxMessageBox(os.str().c_str(), "Image Comparison");
410 ImageFileView::OnInvertValues (wxCommandEvent& event)
412 ImageFile& rIF = GetDocument()->getImageFile();
413 rIF.invertPixelValues (rIF);
414 rIF.labelAdd ("Invert Pixel Values");
415 GetDocument()->Modify (true);
416 GetDocument()->UpdateAllViews (this);
420 ImageFileView::OnSquare (wxCommandEvent& event)
422 ImageFile& rIF = GetDocument()->getImageFile();
424 rIF.labelAdd ("Square Pixel Values");
425 GetDocument()->Modify (true);
426 GetDocument()->UpdateAllViews (this);
430 ImageFileView::OnSquareRoot (wxCommandEvent& event)
432 ImageFile& rIF = GetDocument()->getImageFile();
434 rIF.labelAdd ("Square-root Pixel Values");
435 GetDocument()->Modify (true);
436 GetDocument()->UpdateAllViews (this);
440 ImageFileView::OnLog (wxCommandEvent& event)
442 ImageFile& rIF = GetDocument()->getImageFile();
444 rIF.labelAdd ("Logrithm base-e Pixel Values");
445 GetDocument()->Modify (true);
446 GetDocument()->UpdateAllViews (this);
450 ImageFileView::OnExp (wxCommandEvent& event)
452 ImageFile& rIF = GetDocument()->getImageFile();
454 rIF.labelAdd ("Exponent base-e Pixel Values");
455 GetDocument()->Modify (true);
456 GetDocument()->UpdateAllViews (this);
460 ImageFileView::OnAdd (wxCommandEvent& event)
462 std::vector<ImageFileDocument*> vecIF;
463 theApp->getCompatibleImages (GetDocument(), vecIF);
465 if (vecIF.size() == 0) {
466 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
468 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Add", vecIF, false);
470 if (dialogGetCompare.ShowModal() == wxID_OK) {
471 ImageFile& rIF = GetDocument()->getImageFile();
472 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
473 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
474 ImageFileDocument* pNewDoc = theApp->newImageDoc();
476 sys_error (ERR_SEVERE, "Unable to create image file");
479 ImageFile& newImage = pNewDoc->getImageFile();
480 newImage.setArraySize (rIF.nx(), rIF.ny());
481 rIF.addImages (rRHSIF, newImage);
482 std::ostringstream os;
483 os << "Add image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
484 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
485 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
486 newImage.labelsCopy (rIF, s.c_str());
487 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
488 newImage.labelsCopy (rRHSIF, s.c_str());
489 newImage.labelAdd (os.str().c_str());
490 *theApp->getLog() << os.str().c_str() << "\n";
491 pNewDoc->Modify (true);
492 pNewDoc->UpdateAllViews (this);
493 pNewDoc->getView()->OnUpdate (this, NULL);
494 pNewDoc->getView()->getFrame()->Show(true);
500 ImageFileView::OnSubtract (wxCommandEvent& event)
502 std::vector<ImageFileDocument*> vecIF;
503 theApp->getCompatibleImages (GetDocument(), vecIF);
505 if (vecIF.size() == 0) {
506 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
508 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Subtract", vecIF, false);
510 if (dialogGetCompare.ShowModal() == wxID_OK) {
511 ImageFile& rIF = GetDocument()->getImageFile();
512 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
513 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
514 ImageFileDocument* pNewDoc = theApp->newImageDoc();
516 sys_error (ERR_SEVERE, "Unable to create image file");
519 ImageFile& newImage = pNewDoc->getImageFile();
520 newImage.setArraySize (rIF.nx(), rIF.ny());
521 rIF.subtractImages (rRHSIF, newImage);
522 std::ostringstream os;
523 os << "Subtract image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
524 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
525 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
526 newImage.labelsCopy (rIF, s.c_str());
527 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
528 newImage.labelsCopy (rRHSIF, s.c_str());
529 newImage.labelAdd (os.str().c_str());
530 *theApp->getLog() << os.str().c_str() << "\n";
531 pNewDoc->Modify (true);
532 pNewDoc->UpdateAllViews (this);
533 pNewDoc->getView()->OnUpdate (this, NULL);
534 pNewDoc->getView()->getFrame()->Show(true);
540 ImageFileView::OnMultiply (wxCommandEvent& event)
542 std::vector<ImageFileDocument*> vecIF;
543 theApp->getCompatibleImages (GetDocument(), vecIF);
545 if (vecIF.size() == 0) {
546 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
548 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Multiply", vecIF, false);
550 if (dialogGetCompare.ShowModal() == wxID_OK) {
551 ImageFile& rIF = GetDocument()->getImageFile();
552 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
553 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
554 ImageFileDocument* pNewDoc = theApp->newImageDoc();
556 sys_error (ERR_SEVERE, "Unable to create image file");
559 ImageFile& newImage = pNewDoc->getImageFile();
560 newImage.setArraySize (rIF.nx(), rIF.ny());
561 rIF.multiplyImages (rRHSIF, newImage);
562 std::ostringstream os;
563 os << "Multiply image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
564 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
565 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
566 newImage.labelsCopy (rIF, s.c_str());
567 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
568 newImage.labelsCopy (rRHSIF, s.c_str());
569 newImage.labelAdd (os.str().c_str());
570 *theApp->getLog() << os.str().c_str() << "\n";
571 pNewDoc->Modify (true);
572 pNewDoc->UpdateAllViews (this);
573 pNewDoc->getView()->OnUpdate (this, NULL);
574 pNewDoc->getView()->getFrame()->Show(true);
580 ImageFileView::OnDivide (wxCommandEvent& event)
582 std::vector<ImageFileDocument*> vecIF;
583 theApp->getCompatibleImages (GetDocument(), vecIF);
585 if (vecIF.size() == 0) {
586 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
588 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Divide", vecIF, false);
590 if (dialogGetCompare.ShowModal() == wxID_OK) {
591 ImageFile& rIF = GetDocument()->getImageFile();
592 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
593 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
594 ImageFileDocument* pNewDoc = theApp->newImageDoc();
596 sys_error (ERR_SEVERE, "Unable to create image file");
599 ImageFile& newImage = pNewDoc->getImageFile();
600 newImage.setArraySize (rIF.nx(), rIF.ny());
601 rIF.divideImages (rRHSIF, newImage);
602 std::ostringstream os;
603 os << "Divide image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " by "
604 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
605 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
606 newImage.labelsCopy (rIF, s.c_str());
607 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
608 newImage.labelsCopy (rRHSIF, s.c_str());
609 newImage.labelAdd (os.str().c_str());
610 *theApp->getLog() << os.str().c_str() << "\n";
611 pNewDoc->Modify (true);
612 pNewDoc->UpdateAllViews (this);
613 pNewDoc->getView()->OnUpdate (this, NULL);
614 pNewDoc->getView()->getFrame()->Show(true);
622 ImageFileView::OnFFT (wxCommandEvent& event)
624 ImageFile& rIF = GetDocument()->getImageFile();
626 rIF.labelAdd ("FFT Image");
627 m_bMinSpecified = false;
628 m_bMaxSpecified = false;
629 GetDocument()->Modify (true);
630 GetDocument()->UpdateAllViews (this);
634 ImageFileView::OnIFFT (wxCommandEvent& event)
636 ImageFile& rIF = GetDocument()->getImageFile();
638 rIF.labelAdd ("IFFT Image");
639 m_bMinSpecified = false;
640 m_bMaxSpecified = false;
641 GetDocument()->Modify (true);
642 GetDocument()->UpdateAllViews (this);
646 ImageFileView::OnFFTRows (wxCommandEvent& event)
648 ImageFile& rIF = GetDocument()->getImageFile();
650 rIF.labelAdd ("FFT Rows");
651 m_bMinSpecified = false;
652 m_bMaxSpecified = false;
653 GetDocument()->Modify (true);
654 GetDocument()->UpdateAllViews (this);
658 ImageFileView::OnIFFTRows (wxCommandEvent& event)
660 ImageFile& rIF = GetDocument()->getImageFile();
662 rIF.labelAdd ("IFFT Rows");
663 m_bMinSpecified = false;
664 m_bMaxSpecified = false;
665 GetDocument()->Modify (true);
666 GetDocument()->UpdateAllViews (this);
670 ImageFileView::OnFFTCols (wxCommandEvent& event)
672 ImageFile& rIF = GetDocument()->getImageFile();
674 rIF.labelAdd ("FFT Columns");
675 m_bMinSpecified = false;
676 m_bMaxSpecified = false;
677 GetDocument()->Modify (true);
678 GetDocument()->UpdateAllViews (this);
682 ImageFileView::OnIFFTCols (wxCommandEvent& event)
684 ImageFile& rIF = GetDocument()->getImageFile();
686 rIF.labelAdd ("IFFT Columns");
687 m_bMinSpecified = false;
688 m_bMaxSpecified = false;
689 GetDocument()->Modify (true);
690 GetDocument()->UpdateAllViews (this);
695 ImageFileView::OnFourier (wxCommandEvent& event)
697 ImageFile& rIF = GetDocument()->getImageFile();
698 wxProgressDialog dlgProgress (wxString("Fourier"), wxString("Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
700 rIF.labelAdd ("Fourier Image");
701 m_bMinSpecified = false;
702 m_bMaxSpecified = false;
703 GetDocument()->Modify (true);
704 GetDocument()->UpdateAllViews (this);
708 ImageFileView::OnInverseFourier (wxCommandEvent& event)
710 ImageFile& rIF = GetDocument()->getImageFile();
711 wxProgressDialog dlgProgress (wxString("Inverse Fourier"), wxString("Inverse Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
712 rIF.inverseFourier (rIF);
713 rIF.labelAdd ("Inverse Fourier Image");
714 m_bMinSpecified = false;
715 m_bMaxSpecified = false;
716 GetDocument()->Modify (true);
717 GetDocument()->UpdateAllViews (this);
721 ImageFileView::OnShuffleNaturalToFourierOrder (wxCommandEvent& event)
723 ImageFile& rIF = GetDocument()->getImageFile();
724 Fourier::shuffleNaturalToFourierOrder (rIF);
725 rIF.labelAdd ("Shuffle Natural To Fourier Order");
726 m_bMinSpecified = false;
727 m_bMaxSpecified = false;
728 GetDocument()->Modify (true);
729 GetDocument()->UpdateAllViews (this);
733 ImageFileView::OnShuffleFourierToNaturalOrder (wxCommandEvent& event)
735 ImageFile& rIF = GetDocument()->getImageFile();
736 Fourier::shuffleFourierToNaturalOrder (rIF);
737 rIF.labelAdd ("Shuffle Fourier To Natural Order");
738 m_bMinSpecified = false;
739 m_bMaxSpecified = false;
740 GetDocument()->Modify (true);
741 GetDocument()->UpdateAllViews (this);
745 ImageFileView::OnMagnitude (wxCommandEvent& event)
747 ImageFile& rIF = GetDocument()->getImageFile();
748 if (rIF.isComplex()) {
750 rIF.labelAdd ("Magnitude of complex-image");
751 m_bMinSpecified = false;
752 m_bMaxSpecified = false;
753 GetDocument()->Modify (true);
754 GetDocument()->UpdateAllViews (this);
759 ImageFileView::OnPhase (wxCommandEvent& event)
761 ImageFile& rIF = GetDocument()->getImageFile();
762 if (rIF.isComplex()) {
764 rIF.labelAdd ("Phase of complex-image");
765 m_bMinSpecified = false;
766 m_bMaxSpecified = false;
767 GetDocument()->Modify (true);
768 GetDocument()->UpdateAllViews (this);
774 ImageFileView::CreateCanvas (wxFrame* parent)
776 ImageFileCanvas* pCanvas;
778 parent->GetClientSize(&width, &height);
780 pCanvas = new ImageFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
782 pCanvas->SetScrollbars(20, 20, 50, 50);
783 pCanvas->SetBackgroundColour(*wxWHITE);
794 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
797 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
799 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
801 theApp->setIconForFrame (subframe);
803 m_pFileMenu = new wxMenu;
805 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
806 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
807 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
808 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
809 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
810 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
811 m_pFileMenu->Append(wxID_REVERT, "Re&vert");
813 m_pFileMenu->AppendSeparator();
814 m_pFileMenu->Append(IFMENU_FILE_PROPERTIES, "P&roperties");
815 m_pFileMenu->Append(IFMENU_FILE_EXPORT, "&Export...");
817 m_pFileMenu->AppendSeparator();
818 m_pFileMenu->Append(wxID_PRINT, "&Print...");
819 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
820 m_pFileMenu->Append(wxID_PREVIEW, "Print Preview");
822 m_pFileMenu->AppendSeparator();
823 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
825 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
826 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
828 wxMenu *view_menu = new wxMenu;
829 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale S&et...\tCtrl-E");
830 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
831 view_menu->Append(IFMENU_VIEW_SCALE_FULL, "Display F&ull Scale\tCtrl-U");
833 wxMenu* filter_menu = new wxMenu;
834 filter_menu->Append (IFMENU_FILTER_INVERTVALUES, "&Invert Values");
835 filter_menu->Append (IFMENU_FILTER_SQUARE, "&Square");
836 filter_menu->Append (IFMENU_FILTER_SQRT, "Square &Root");
837 filter_menu->Append (IFMENU_FILTER_LOG, "&Log");
838 filter_menu->Append (IFMENU_FILTER_EXP, "&Exp");
839 filter_menu->AppendSeparator();
841 filter_menu->Append (IFMENU_FILTER_FFT, "2D &FFT");
842 filter_menu->Append (IFMENU_FILTER_IFFT, "2D &IFFT");
843 filter_menu->Append (IFMENU_FILTER_FFT_ROWS, "FFT Rows");
844 filter_menu->Append (IFMENU_FILTER_IFFT_ROWS, "IFFT Rows");
845 filter_menu->Append (IFMENU_FILTER_FFT_COLS, "FFT Columns");
846 filter_menu->Append (IFMENU_FILTER_IFFT_COLS, "IFFT Columns");
847 filter_menu->Append (IFMENU_FILTER_FOURIER, "F&ourier");
848 filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "Inverse Fo&urier");
850 filter_menu->Append (IFMENU_FILTER_FOURIER, "&Fourier");
851 filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "&Inverse Fourier");
853 filter_menu->Append (IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, "S&huffle Fourier to Natural Order");
854 filter_menu->Append (IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, "Shu&ffle Natural to Fourier Order");
855 filter_menu->Append (IFMENU_FILTER_MAGNITUDE, "&Magnitude");
856 filter_menu->Append (IFMENU_FILTER_PHASE, "&Phase");
858 wxMenu* image_menu = new wxMenu;
859 image_menu->Append (IFMENU_IMAGE_ADD, "&Add...");
860 image_menu->Append (IFMENU_IMAGE_SUBTRACT, "&Subtract...");
861 image_menu->Append (IFMENU_IMAGE_MULTIPLY, "&Multiply...");
862 image_menu->Append (IFMENU_IMAGE_DIVIDE, "&Divide...");
863 image_menu->AppendSeparator();
864 image_menu->Append (IFMENU_IMAGE_SCALESIZE, "S&cale Size...");
865 image_menu->Append (IFMENU_IMAGE_CONVERT3D, "Convert &3-D\tCtrl-3");
867 m_pMenuAnalyze = new wxMenu;
868 m_pMenuAnalyze->Append (IFMENU_PLOT_ROW, "Plot &Row");
869 m_pMenuAnalyze->Append (IFMENU_PLOT_COL, "Plot &Column");
870 m_pMenuAnalyze->Append (IFMENU_PLOT_HISTOGRAM, "Plot &Histogram");
871 m_pMenuAnalyze->AppendSeparator();
872 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_ROW, "Plot FFT Row");
873 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_COL, "Plot FFT Column");
874 m_pMenuAnalyze->AppendSeparator();
875 m_pMenuAnalyze->Append (IFMENU_COMPARE_IMAGES, "Compare &Images...");
876 m_pMenuAnalyze->Append (IFMENU_COMPARE_ROW, "Compare &Row");
877 m_pMenuAnalyze->Append (IFMENU_COMPARE_COL, "Compare &Column");
878 m_pMenuAnalyze->Enable (IFMENU_PLOT_ROW, false);
879 m_pMenuAnalyze->Enable (IFMENU_PLOT_COL, false);
880 m_pMenuAnalyze->Enable (IFMENU_COMPARE_ROW, false);
881 m_pMenuAnalyze->Enable (IFMENU_COMPARE_COL, false);
882 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_ROW, false);
883 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_COL, false);
885 wxMenu *help_menu = new wxMenu;
886 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
887 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
888 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
890 wxMenuBar *menu_bar = new wxMenuBar;
892 menu_bar->Append(m_pFileMenu, "&File");
893 menu_bar->Append(view_menu, "&View");
894 menu_bar->Append(image_menu, "&Image");
895 menu_bar->Append(filter_menu, "Fi<er");
896 menu_bar->Append(m_pMenuAnalyze, "&Analyze");
897 menu_bar->Append(help_menu, "&Help");
899 subframe->SetMenuBar(menu_bar);
901 subframe->Centre(wxBOTH);
903 wxAcceleratorEntry accelEntries[11];
904 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
905 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
906 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
907 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
908 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
909 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
910 accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
911 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('A'), IFMENU_VIEW_SCALE_AUTO);
912 accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('U'), IFMENU_VIEW_SCALE_FULL);
913 accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('E'), IFMENU_VIEW_SCALE_MINMAX);
914 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('3'), IFMENU_IMAGE_CONVERT3D);
915 wxAcceleratorTable accelTable (11, accelEntries);
916 subframe->SetAcceleratorTable (accelTable);
923 ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
925 m_pFrame = CreateChildFrame(doc, this);
928 m_bMinSpecified = false;
929 m_bMaxSpecified = false;
930 m_dAutoScaleFactor = 1.;
933 m_pFrame->GetClientSize (&width, &height);
934 m_pFrame->SetTitle("ImageFileView");
935 m_pCanvas = CreateCanvas (m_pFrame);
937 int x, y; // X requires a forced resize
938 m_pFrame->GetSize(&x, &y);
939 m_pFrame->SetSize(-1, -1, x, y);
940 m_pFrame->SetFocus();
941 m_pFrame->Show(true);
948 ImageFileView::OnDraw (wxDC* dc)
950 wxSize sizeWindow = m_pFrame->GetClientSize();
951 wxSize sizeBest = m_pCanvas->GetBestSize();
952 if (sizeWindow.x > sizeBest.x || sizeWindow.y > sizeBest.y)
953 m_pFrame->SetClientSize (sizeBest);
956 dc->DrawBitmap(m_bitmap, 0, 0, false);
958 int xCursor, yCursor;
959 if (m_pCanvas->GetCurrentCursor (xCursor, yCursor))
960 m_pCanvas->DrawRubberBandCursor (*dc, xCursor, yCursor);
965 ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
967 const ImageFile& rIF = GetDocument()->getImageFile();
968 ImageFileArrayConst v = rIF.getArray();
971 if (v != NULL && nx != 0 && ny != 0) {
972 if (! m_bMinSpecified || ! m_bMaxSpecified) {
974 rIF.getMinMax (min, max);
975 if (! m_bMinSpecified)
977 if (! m_bMaxSpecified)
980 double scaleWidth = m_dMaxPixel - m_dMinPixel;
982 unsigned char* imageData = new unsigned char [nx * ny * 3];
983 for (int ix = 0; ix < nx; ix++) {
984 for (int iy = 0; iy < ny; iy++) {
985 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
986 int intensity = static_cast<int>(scaleValue + 0.5);
987 intensity = clamp (intensity, 0, 255);
988 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
989 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
992 wxImage image (nx, ny, imageData, true);
993 m_bitmap = image.ConvertToBitmap();
997 ySize = clamp (ySize, 0, 800);
998 m_pFrame->SetClientSize (xSize, ySize);
999 m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20);
1000 m_pCanvas->SetBackgroundColour(*wxWHITE);
1004 m_pCanvas->Refresh();
1008 ImageFileView::OnClose (bool deleteWindow)
1010 //GetDocumentManager()->ActivateView (this, false, true);
1011 if (! GetDocument() || ! GetDocument()->Close())
1016 m_pCanvas->setView(NULL);
1019 wxString s(theApp->GetAppName());
1021 m_pFrame->SetTitle(s);
1026 m_pFrame->Destroy();
1028 if (GetDocument() && GetDocument()->getBadFileOpen())
1029 ::wxYield(); // wxWindows bug workaround
1036 ImageFileView::OnExport (wxCommandEvent& event)
1038 ImageFile& rIF = GetDocument()->getImageFile();
1039 ImageFileArrayConst v = rIF.getArray();
1042 if (v != NULL && nx != 0 && ny != 0) {
1043 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1045 rIF.getMinMax (min, max);
1046 if (! m_bMinSpecified)
1048 if (! m_bMaxSpecified)
1052 DialogExportParameters dialogExport (getFrameForChild(), m_iDefaultExportFormatID);
1053 if (dialogExport.ShowModal() == wxID_OK) {
1054 wxString strFormatName (dialogExport.getFormatName ());
1055 m_iDefaultExportFormatID = ImageFile::convertFormatNameToID (strFormatName.c_str());
1058 wxString strWildcard;
1059 if (m_iDefaultExportFormatID == ImageFile::FORMAT_PGM || m_iDefaultExportFormatID == ImageFile::FORMAT_PGMASCII) {
1061 strWildcard = "PGM Files (*.pgm)|*.pgm";
1064 else if (m_iDefaultExportFormatID == ImageFile::FORMAT_PNG || m_iDefaultExportFormatID == ImageFile::FORMAT_PNG16) {
1066 strWildcard = "PNG Files (*.png)|*.png";
1070 const wxString& strFilename = wxFileSelector (wxString("Export Filename"), wxString(""),
1071 wxString(""), strExt, strWildcard, wxOVERWRITE_PROMPT | wxHIDE_READONLY | wxSAVE);
1073 rIF.exportImage (strFormatName.c_str(), strFilename.c_str(), 1, 1, m_dMinPixel, m_dMaxPixel);
1074 *theApp->getLog() << "Exported file " << strFilename << "\n";
1081 ImageFileView::OnScaleSize (wxCommandEvent& event)
1083 ImageFile& rIF = GetDocument()->getImageFile();
1084 unsigned int iOldNX = rIF.nx();
1085 unsigned int iOldNY = rIF.ny();
1087 DialogGetXYSize dialogGetXYSize (getFrameForChild(), "Set New X & Y Dimensions", iOldNX, iOldNY);
1088 if (dialogGetXYSize.ShowModal() == wxID_OK) {
1089 unsigned int iNewNX = dialogGetXYSize.getXSize();
1090 unsigned int iNewNY = dialogGetXYSize.getYSize();
1091 std::ostringstream os;
1092 os << "Scale Size from (" << iOldNX << "," << iOldNY << ") to (" << iNewNX << "," << iNewNY << ")";
1093 ImageFileDocument* pScaledDoc = theApp->newImageDoc();
1095 sys_error (ERR_SEVERE, "Unable to create image file");
1098 ImageFile& rScaledIF = pScaledDoc->getImageFile();
1099 rScaledIF.setArraySize (iNewNX, iNewNY);
1100 rScaledIF.labelsCopy (rIF);
1101 rScaledIF.labelAdd (os.str().c_str());
1102 rIF.scaleImage (rScaledIF);
1103 *theApp->getLog() << os.str().c_str() << "\n";
1104 pScaledDoc->Modify (true);
1105 pScaledDoc->UpdateAllViews (this);
1106 pScaledDoc->getView()->OnUpdate (this, NULL);
1107 pScaledDoc->getView()->getFrame()->Show(true);
1112 ImageFileView::OnConvert3d (wxCommandEvent& event)
1114 ImageFile& rIF = GetDocument()->getImageFile();
1115 Graph3dFileDocument* pGraph3d = theApp->newGraph3dDoc();
1116 pGraph3d->setBadFileOpen();
1117 pGraph3d->createFromImageFile (rIF);
1118 pGraph3d->getView()->getFrame()->SetClientSize (200, 200);
1119 pGraph3d->getView()->getFrame()->Show (true);
1123 ImageFileView::OnPlotRow (wxCommandEvent& event)
1125 int xCursor, yCursor;
1126 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1127 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1131 const ImageFile& rIF = GetDocument()->getImageFile();
1132 ImageFileArrayConst v = rIF.getArray();
1133 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1137 if (v != NULL && yCursor < ny) {
1138 double* pX = new double [nx];
1139 double* pYReal = new double [nx];
1140 double *pYImag = NULL;
1141 double *pYMag = NULL;
1142 if (rIF.isComplex()) {
1143 pYImag = new double [nx];
1144 pYMag = new double [nx];
1146 for (int i = 0; i < nx; i++) {
1148 pYReal[i] = v[i][yCursor];
1149 if (rIF.isComplex()) {
1150 pYImag[i] = vImag[i][yCursor];
1151 pYMag[i] = ::sqrt (v[i][yCursor] * v[i][yCursor] + vImag[i][yCursor] * vImag[i][yCursor]);
1154 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1156 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1158 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1159 std::ostringstream os;
1160 os << "Row " << yCursor;
1161 std::string title("title ");
1163 rPlotFile.addEzsetCommand (title.c_str());
1164 rPlotFile.addEzsetCommand ("xlabel Column");
1165 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1166 rPlotFile.addEzsetCommand ("lxfrac 0");
1167 rPlotFile.addEzsetCommand ("box");
1168 rPlotFile.addEzsetCommand ("grid");
1169 rPlotFile.addEzsetCommand ("curve 1");
1170 rPlotFile.addEzsetCommand ("color 1");
1171 if (rIF.isComplex()) {
1172 rPlotFile.addEzsetCommand ("dash 1");
1173 rPlotFile.addEzsetCommand ("curve 2");
1174 rPlotFile.addEzsetCommand ("color 4");
1175 rPlotFile.addEzsetCommand ("dash 3");
1176 rPlotFile.addEzsetCommand ("curve 3");
1177 rPlotFile.addEzsetCommand ("color 0");
1178 rPlotFile.addEzsetCommand ("solid");
1179 rPlotFile.setCurveSize (4, nx);
1181 rPlotFile.setCurveSize (2, nx);
1182 rPlotFile.addColumn (0, pX);
1183 rPlotFile.addColumn (1, pYReal);
1184 if (rIF.isComplex()) {
1185 rPlotFile.addColumn (2, pYImag);
1186 rPlotFile.addColumn (3, pYMag);
1188 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1189 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1190 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1191 *theApp->getLog() << os.str().c_str() << "\n";
1192 rPlotFile.addDescription (os.str().c_str());
1196 if (rIF.isComplex()) {
1200 pPlotDoc->Modify (true);
1201 pPlotDoc->UpdateAllViews ();
1202 pPlotDoc->getView()->OnUpdate (this, NULL);
1203 pPlotDoc->getView()->getFrame()->Show(true);
1208 ImageFileView::OnPlotCol (wxCommandEvent& event)
1210 int xCursor, yCursor;
1211 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1212 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1216 const ImageFile& rIF = GetDocument()->getImageFile();
1217 ImageFileArrayConst v = rIF.getArray();
1218 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1222 if (v != NULL && xCursor < nx) {
1223 double* pX = new double [ny];
1224 double* pYReal = new double [ny];
1225 double* pYImag = NULL;
1226 double* pYMag = NULL;
1227 if (rIF.isComplex()) {
1228 pYImag = new double [ny];
1229 pYMag = new double [ny];
1231 for (int i = 0; i < ny; i++) {
1233 pYReal[i] = v[xCursor][i];
1234 if (rIF.isComplex()) {
1235 pYImag[i] = vImag[xCursor][i];
1236 pYMag[i] = ::sqrt (v[xCursor][i] * v[xCursor][i] + vImag[xCursor][i] * vImag[xCursor][i]);
1239 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1241 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1243 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1244 std::ostringstream os;
1245 os << "Column " << xCursor;
1246 std::string title("title ");
1248 rPlotFile.addEzsetCommand (title.c_str());
1249 rPlotFile.addEzsetCommand ("xlabel Row");
1250 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1251 rPlotFile.addEzsetCommand ("lxfrac 0");
1252 rPlotFile.addEzsetCommand ("box");
1253 rPlotFile.addEzsetCommand ("grid");
1254 rPlotFile.addEzsetCommand ("curve 1");
1255 rPlotFile.addEzsetCommand ("color 1");
1256 if (rIF.isComplex()) {
1257 rPlotFile.addEzsetCommand ("dash 1");
1258 rPlotFile.addEzsetCommand ("curve 2");
1259 rPlotFile.addEzsetCommand ("color 4");
1260 rPlotFile.addEzsetCommand ("dash 3");
1261 rPlotFile.addEzsetCommand ("curve 3");
1262 rPlotFile.addEzsetCommand ("color 0");
1263 rPlotFile.addEzsetCommand ("solid");
1264 rPlotFile.setCurveSize (4, ny);
1266 rPlotFile.setCurveSize (2, ny);
1267 rPlotFile.addColumn (0, pX);
1268 rPlotFile.addColumn (1, pYReal);
1269 if (rIF.isComplex()) {
1270 rPlotFile.addColumn (2, pYImag);
1271 rPlotFile.addColumn (3, pYMag);
1273 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1274 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1275 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1276 *theApp->getLog() << os.str().c_str() << "\n";
1277 rPlotFile.addDescription (os.str().c_str());
1281 if (rIF.isComplex()) {
1285 pPlotDoc->Modify (true);
1286 pPlotDoc->UpdateAllViews ();
1287 pPlotDoc->getView()->OnUpdate (this, NULL);
1288 pPlotDoc->getView()->getFrame()->Show(true);
1294 ImageFileView::OnPlotFFTRow (wxCommandEvent& event)
1296 int xCursor, yCursor;
1297 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1298 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1302 const ImageFile& rIF = GetDocument()->getImageFile();
1303 ImageFileArrayConst v = rIF.getArray();
1304 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1308 if (v != NULL && yCursor < ny) {
1309 fftw_complex* pcIn = new fftw_complex [nx];
1312 for (i = 0; i < nx; i++) {
1313 pcIn[i].re = v[i][yCursor];
1314 if (rIF.isComplex())
1315 pcIn[i].im = vImag[i][yCursor];
1320 fftw_plan plan = fftw_create_plan (nx, FFTW_FORWARD, FFTW_IN_PLACE);
1321 fftw_one (plan, pcIn, NULL);
1322 fftw_destroy_plan (plan);
1324 double* pX = new double [nx];
1325 double* pYReal = new double [nx];
1326 double* pYImag = new double [nx];
1327 double* pYMag = new double [nx];
1328 for (i = 0; i < nx; i++) {
1330 pYReal[i] = pcIn[i].re;
1331 pYImag[i] = pcIn[i].im;
1332 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1334 Fourier::shuffleFourierToNaturalOrder (pYReal, nx);
1335 Fourier::shuffleFourierToNaturalOrder (pYImag, nx);
1336 Fourier::shuffleFourierToNaturalOrder (pYMag, nx);
1338 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1340 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1342 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1343 std::ostringstream os;
1344 os << "Row " << yCursor;
1345 std::string title("title ");
1347 rPlotFile.addEzsetCommand (title.c_str());
1348 rPlotFile.addEzsetCommand ("xlabel Column");
1349 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1350 rPlotFile.addEzsetCommand ("lxfrac 0");
1351 rPlotFile.addEzsetCommand ("curve 1");
1352 rPlotFile.addEzsetCommand ("color 1");
1353 rPlotFile.addEzsetCommand ("dash 1");
1354 rPlotFile.addEzsetCommand ("curve 2");
1355 rPlotFile.addEzsetCommand ("color 4");
1356 rPlotFile.addEzsetCommand ("dash 3");
1357 rPlotFile.addEzsetCommand ("curve 3");
1358 rPlotFile.addEzsetCommand ("color 0");
1359 rPlotFile.addEzsetCommand ("solid");
1360 rPlotFile.addEzsetCommand ("box");
1361 rPlotFile.addEzsetCommand ("grid");
1362 rPlotFile.setCurveSize (4, nx);
1363 rPlotFile.addColumn (0, pX);
1364 rPlotFile.addColumn (1, pYReal);
1365 rPlotFile.addColumn (2, pYImag);
1366 rPlotFile.addColumn (3, pYMag);
1367 for (int iL = 0; iL < rIF.nLabels(); iL++)
1368 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1369 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1370 *theApp->getLog() << os.str().c_str() << "\n";
1371 rPlotFile.addDescription (os.str().c_str());
1379 pPlotDoc->Modify (true);
1380 pPlotDoc->UpdateAllViews ();
1381 pPlotDoc->getView()->OnUpdate (this, NULL);
1382 pPlotDoc->getView()->getFrame()->Show(true);
1387 ImageFileView::OnPlotFFTCol (wxCommandEvent& event)
1389 int xCursor, yCursor;
1390 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1391 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1395 const ImageFile& rIF = GetDocument()->getImageFile();
1396 ImageFileArrayConst v = rIF.getArray();
1397 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1401 if (v != NULL && xCursor < nx) {
1402 fftw_complex* pcIn = new fftw_complex [ny];
1403 double *pdTemp = new double [ny];
1406 for (i = 0; i < ny; i++)
1407 pdTemp[i] = v[xCursor][i];
1408 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1409 for (i = 0; i < ny; i++)
1410 pcIn[i].re = pdTemp[i];
1412 for (i = 0; i < ny; i++) {
1413 if (rIF.isComplex())
1414 pdTemp[i] = vImag[xCursor][i];
1418 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1419 for (i = 0; i < ny; i++)
1420 pcIn[i].im = pdTemp[i];
1422 fftw_plan plan = fftw_create_plan (ny, FFTW_BACKWARD, FFTW_IN_PLACE);
1423 fftw_one (plan, pcIn, NULL);
1424 fftw_destroy_plan (plan);
1426 double* pX = new double [ny];
1427 double* pYReal = new double [ny];
1428 double* pYImag = new double [ny];
1429 double* pYMag = new double [ny];
1430 for (i = 0; i < ny; i++) {
1432 pYReal[i] = pcIn[i].re;
1433 pYImag[i] = pcIn[i].im;
1434 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1437 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1439 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1441 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1442 std::ostringstream os;
1443 os << "Column " << xCursor;
1444 std::string title("title ");
1446 rPlotFile.addEzsetCommand (title.c_str());
1447 rPlotFile.addEzsetCommand ("xlabel Column");
1448 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1449 rPlotFile.addEzsetCommand ("lxfrac 0");
1450 rPlotFile.addEzsetCommand ("curve 1");
1451 rPlotFile.addEzsetCommand ("color 1");
1452 rPlotFile.addEzsetCommand ("dash 1");
1453 rPlotFile.addEzsetCommand ("curve 2");
1454 rPlotFile.addEzsetCommand ("color 4");
1455 rPlotFile.addEzsetCommand ("dash 3");
1456 rPlotFile.addEzsetCommand ("curve 3");
1457 rPlotFile.addEzsetCommand ("color 0");
1458 rPlotFile.addEzsetCommand ("solid");
1459 rPlotFile.addEzsetCommand ("box");
1460 rPlotFile.addEzsetCommand ("grid");
1461 rPlotFile.setCurveSize (4, ny);
1462 rPlotFile.addColumn (0, pX);
1463 rPlotFile.addColumn (1, pYReal);
1464 rPlotFile.addColumn (2, pYImag);
1465 rPlotFile.addColumn (3, pYMag);
1466 for (int iL = 0; iL < rIF.nLabels(); iL++)
1467 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1468 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1469 *theApp->getLog() << os.str().c_str() << "\n";
1470 rPlotFile.addDescription (os.str().c_str());
1479 pPlotDoc->Modify (true);
1480 pPlotDoc->UpdateAllViews ();
1481 pPlotDoc->getView()->OnUpdate (this, NULL);
1482 pPlotDoc->getView()->getFrame()->Show(true);
1488 ImageFileView::OnCompareCol (wxCommandEvent& event)
1490 int xCursor, yCursor;
1491 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1492 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1496 std::vector<ImageFileDocument*> vecIFDoc;
1497 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1498 if (vecIFDoc.size() == 0) {
1499 wxMessageBox ("No compatible images for Column Comparison", "Error");
1502 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1504 if (dialogGetCompare.ShowModal() == wxID_OK) {
1505 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1506 const ImageFile& rIF = GetDocument()->getImageFile();
1507 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1509 ImageFileArrayConst v1 = rIF.getArray();
1510 ImageFileArrayConst v2 = rCompareIF.getArray();
1514 if (v1 != NULL && xCursor < nx) {
1515 double* pX = new double [ny];
1516 double* pY1 = new double [ny];
1517 double* pY2 = new double [ny];
1518 for (int i = 0; i < ny; i++) {
1520 pY1[i] = v1[xCursor][i];
1521 pY2[i] = v2[xCursor][i];
1523 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1525 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1527 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1528 std::ostringstream os;
1529 os << "Column " << xCursor << " Comparison";
1530 std::string title("title ");
1532 rPlotFile.addEzsetCommand (title.c_str());
1533 rPlotFile.addEzsetCommand ("xlabel Row");
1534 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1535 rPlotFile.addEzsetCommand ("lxfrac 0");
1536 rPlotFile.addEzsetCommand ("curve 1");
1537 rPlotFile.addEzsetCommand ("color 2");
1538 rPlotFile.addEzsetCommand ("curve 2");
1539 rPlotFile.addEzsetCommand ("color 4");
1540 rPlotFile.addEzsetCommand ("dash 5");
1541 rPlotFile.addEzsetCommand ("box");
1542 rPlotFile.addEzsetCommand ("grid");
1543 rPlotFile.setCurveSize (3, ny);
1544 rPlotFile.addColumn (0, pX);
1545 rPlotFile.addColumn (1, pY1);
1546 rPlotFile.addColumn (2, pY2);
1549 for (iL = 0; iL < rIF.nLabels(); iL++) {
1550 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1552 s += rIF.labelGet(iL).getLabelString();
1553 rPlotFile.addDescription (s.c_str());
1555 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1556 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1558 s += rCompareIF.labelGet(iL).getLabelString();
1559 rPlotFile.addDescription (s.c_str());
1561 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1562 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1563 *theApp->getLog() << os.str().c_str() << "\n";
1564 rPlotFile.addDescription (os.str().c_str());
1569 pPlotDoc->Modify (true);
1570 pPlotDoc->UpdateAllViews ();
1571 pPlotDoc->getView()->OnUpdate (this, NULL);
1572 pPlotDoc->getView()->getFrame()->Show(true);
1578 ImageFileView::OnCompareRow (wxCommandEvent& event)
1580 int xCursor, yCursor;
1581 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1582 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1586 std::vector<ImageFileDocument*> vecIFDoc;
1587 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1589 if (vecIFDoc.size() == 0) {
1590 wxMessageBox ("No compatible images for Row Comparison", "Error");
1594 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1596 if (dialogGetCompare.ShowModal() == wxID_OK) {
1597 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1598 const ImageFile& rIF = GetDocument()->getImageFile();
1599 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1601 ImageFileArrayConst v1 = rIF.getArray();
1602 ImageFileArrayConst v2 = rCompareIF.getArray();
1606 if (v1 != NULL && yCursor < ny) {
1607 double* pX = new double [nx];
1608 double* pY1 = new double [nx];
1609 double* pY2 = new double [nx];
1610 for (int i = 0; i < nx; i++) {
1612 pY1[i] = v1[i][yCursor];
1613 pY2[i] = v2[i][yCursor];
1615 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1617 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1619 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1620 std::ostringstream os;
1621 os << "Row " << yCursor << " Comparison";
1622 std::string title("title ");
1624 rPlotFile.addEzsetCommand (title.c_str());
1625 rPlotFile.addEzsetCommand ("xlabel Column");
1626 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1627 rPlotFile.addEzsetCommand ("lxfrac 0");
1628 rPlotFile.addEzsetCommand ("curve 1");
1629 rPlotFile.addEzsetCommand ("color 2");
1630 rPlotFile.addEzsetCommand ("curve 2");
1631 rPlotFile.addEzsetCommand ("color 4");
1632 rPlotFile.addEzsetCommand ("dash 5");
1633 rPlotFile.addEzsetCommand ("box");
1634 rPlotFile.addEzsetCommand ("grid");
1635 rPlotFile.setCurveSize (3, nx);
1636 rPlotFile.addColumn (0, pX);
1637 rPlotFile.addColumn (1, pY1);
1638 rPlotFile.addColumn (2, pY2);
1640 for (iL = 0; iL < rIF.nLabels(); iL++) {
1641 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1643 s += rIF.labelGet(iL).getLabelString();
1644 rPlotFile.addDescription (s.c_str());
1646 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1647 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1649 s += rCompareIF.labelGet(iL).getLabelString();
1650 rPlotFile.addDescription (s.c_str());
1652 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1653 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1654 *theApp->getLog() << os.str().c_str() << "\n";
1655 rPlotFile.addDescription (os.str().c_str());
1660 pPlotDoc->Modify (true);
1661 pPlotDoc->UpdateAllViews ();
1662 pPlotDoc->getView()->OnUpdate (this, NULL);
1663 pPlotDoc->getView()->getFrame()->Show(true);
1668 static int NUMBER_HISTOGRAM_BINS = 256;
1671 ImageFileView::OnPlotHistogram (wxCommandEvent& event)
1673 const ImageFile& rIF = GetDocument()->getImageFile();
1674 ImageFileArrayConst v = rIF.getArray();
1678 if (v != NULL && nx > 0 && ny > 0) {
1679 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1681 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1685 double* pX = new double [NUMBER_HISTOGRAM_BINS];
1686 double* pY = new double [NUMBER_HISTOGRAM_BINS];
1688 rIF.getMinMax (dMin, dMax);
1689 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
1691 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
1692 pX[i] = dMin + (i + 0.5) * dBinWidth;
1695 for (int ix = 0; ix < nx; ix++)
1696 for (int iy = 0; iy < ny; iy++) {
1697 int iBin = nearest<int> ((v[ix][iy] - dMin) / dBinWidth);
1698 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
1702 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1703 std::ostringstream os;
1705 std::string title("title ");
1707 rPlotFile.addEzsetCommand (title.c_str());
1708 rPlotFile.addEzsetCommand ("xlabel Pixel Value");
1709 rPlotFile.addEzsetCommand ("ylabel Count");
1710 rPlotFile.addEzsetCommand ("box");
1711 rPlotFile.addEzsetCommand ("grid");
1712 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
1713 rPlotFile.addColumn (0, pX);
1714 rPlotFile.addColumn (1, pY);
1715 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++) {
1716 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1718 s += rIF.labelGet(iL).getLabelString();
1719 rPlotFile.addDescription (s.c_str());
1721 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1722 *theApp->getLog() << os.str().c_str() << "\n";
1723 rPlotFile.addDescription (os.str().c_str());
1726 pPlotDoc->Modify (true);
1727 pPlotDoc->UpdateAllViews ();
1728 pPlotDoc->getView()->OnUpdate (this, NULL);
1729 pPlotDoc->getView()->getFrame()->Show(true);
1736 PhantomCanvas::PhantomCanvas (PhantomFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1737 : wxScrolledWindow(frame, -1, pos, size, style)
1742 PhantomCanvas::~PhantomCanvas ()
1748 PhantomCanvas::OnDraw (wxDC& dc)
1751 m_pView->OnDraw(& dc);
1757 IMPLEMENT_DYNAMIC_CLASS(PhantomFileView, wxView)
1759 BEGIN_EVENT_TABLE(PhantomFileView, wxView)
1760 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomFileView::OnProperties)
1761 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomFileView::OnRasterize)
1762 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomFileView::OnProjections)
1765 PhantomFileView::PhantomFileView()
1766 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0)
1768 #if defined(DEBUG) || defined(_DEBUG)
1769 m_iDefaultNDet = 165;
1770 m_iDefaultNView = 180;
1772 m_iDefaultNDet = 367;
1773 m_iDefaultNView = 320;
1775 m_iDefaultNSample = 1;
1776 m_dDefaultRotation = 1;
1777 m_dDefaultFocalLength = 2;
1778 m_dDefaultFieldOfView = 1;
1779 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
1780 m_iDefaultTrace = Trace::TRACE_NONE;
1783 m_iDefaultRasterNX = 115;
1784 m_iDefaultRasterNY = 115;
1785 m_iDefaultRasterNSamples = 1;
1787 m_iDefaultRasterNX = 256;
1788 m_iDefaultRasterNY = 256;
1789 m_iDefaultRasterNSamples = 2;
1793 PhantomFileView::~PhantomFileView()
1795 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
1796 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
1800 PhantomFileView::OnProperties (wxCommandEvent& event)
1802 const int idPhantom = GetDocument()->getPhantomID();
1803 const wxString& namePhantom = GetDocument()->getPhantomName();
1804 std::ostringstream os;
1805 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")" << "\n";
1806 const Phantom& rPhantom = GetDocument()->getPhantom();
1807 rPhantom.printDefinitions (os);
1809 rPhantom.print (os);
1811 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
1812 wxMessageBox (os.str().c_str(), "Phantom Properties");
1817 PhantomFileView::OnProjections (wxCommandEvent& event)
1819 DialogGetProjectionParameters dialogProjection (getFrameForChild(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView, m_iDefaultGeometry, m_iDefaultTrace);
1820 int retVal = dialogProjection.ShowModal();
1821 if (retVal == wxID_OK) {
1822 m_iDefaultNDet = dialogProjection.getNDet();
1823 m_iDefaultNView = dialogProjection.getNView();
1824 m_iDefaultNSample = dialogProjection.getNSamples();
1825 m_iDefaultTrace = dialogProjection.getTrace();
1826 m_dDefaultRotation = dialogProjection.getRotAngle();
1827 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
1828 m_dDefaultFieldOfView = dialogProjection.getFieldOfViewRatio();
1829 wxString sGeometry = dialogProjection.getGeometry();
1830 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
1832 if (m_iDefaultNDet > 0 && m_iDefaultNView > 0 && sGeometry != "") {
1833 const Phantom& rPhantom = GetDocument()->getPhantom();
1834 Projections* pProj = new Projections;
1835 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample,
1836 m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView);
1837 if (theScanner.fail()) {
1838 *theApp->getLog() << "Failed making scanner: " << theScanner.failMessage().c_str() << "\n";
1841 pProj->initFromScanner (theScanner);
1842 m_dDefaultRotation /= PI; // convert back to PI units
1845 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
1846 ProjectionsDialog dialogProjections (theScanner, *pProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(getFrameForChild()));
1847 for (int iView = 0; iView < pProj->nView(); iView++) {
1849 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
1854 while (dialogProjections.isPaused()) {
1860 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), pProj->nView() + 1, getFrameForChild(), wxPD_CAN_ABORT);
1861 for (int i = 0; i < pProj->nView(); i++) {
1862 theScanner.collectProjections (*pProj, rPhantom, i, 1, true, m_iDefaultTrace);
1863 if (! dlgProgress.Update (i+1)) {
1870 std::ostringstream os;
1871 os << "Projections for " << rPhantom.name() << ": nDet=" << m_iDefaultNDet << ", nView=" << m_iDefaultNView << ", nSamples=" << m_iDefaultNSample << ", RotAngle=" << m_dDefaultRotation << ", FocalLengthRatio=" << m_dDefaultFocalLength << ", FieldOfViewRatio=" << m_dDefaultFieldOfView << ", Geometry=" << sGeometry.c_str();
1872 pProj->setCalcTime (timer.timerEnd());
1873 pProj->setRemark (os.str());
1874 *theApp->getLog() << os.str().c_str() << "\n";
1877 ProjectionFileDocument* pProjectionDoc = theApp->newProjectionDoc();
1878 if (! pProjectionDoc) {
1879 sys_error (ERR_SEVERE, "Unable to create projection document");
1882 pProjectionDoc->setProjections (pProj);
1883 ProjectionFileView* projView = pProjectionDoc->getView();
1885 projView->OnUpdate (projView, NULL);
1886 if (projView->getCanvas())
1887 projView->getCanvas()->SetClientSize (m_iDefaultNDet, m_iDefaultNView);
1888 if (wxFrame* pFrame = projView->getFrame()) {
1893 GetDocumentManager()->ActivateView (projView, true, false);
1896 pProjectionDoc-> Modify(true);
1897 pProjectionDoc->UpdateAllViews (this);
1904 PhantomFileView::OnRasterize (wxCommandEvent& event)
1906 DialogGetRasterParameters dialogRaster (getFrameForChild(), m_iDefaultRasterNX, m_iDefaultRasterNY, m_iDefaultRasterNSamples);
1907 int retVal = dialogRaster.ShowModal();
1908 if (retVal == wxID_OK) {
1909 m_iDefaultRasterNX = dialogRaster.getXSize();
1910 m_iDefaultRasterNY = dialogRaster.getYSize();
1911 m_iDefaultRasterNSamples = dialogRaster.getNSamples();
1912 if (m_iDefaultRasterNSamples < 1)
1913 m_iDefaultRasterNSamples = 1;
1914 if (m_iDefaultRasterNX > 0 && m_iDefaultRasterNY > 0) {
1915 const Phantom& rPhantom = GetDocument()->getPhantom();
1917 ImageFile* pImageFile = new ImageFile;
1919 pImageFile->setArraySize (m_iDefaultRasterNX, m_iDefaultRasterNY);
1920 wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"),
1921 pImageFile->nx() + 1, getFrameForChild(), wxPD_CAN_ABORT);
1923 for (unsigned int i = 0; i < pImageFile->nx(); i++) {
1924 rPhantom.convertToImagefile (*pImageFile, m_iDefaultRasterNSamples, Trace::TRACE_NONE, i, 1, true);
1925 if (! dlgProgress.Update (i+1)) {
1931 ImageFileDocument* pRasterDoc = theApp->newImageDoc();
1933 sys_error (ERR_SEVERE, "Unable to create image file");
1936 pRasterDoc->setImageFile (pImageFile);
1938 pRasterDoc->Modify (true);
1939 pRasterDoc->UpdateAllViews (this);
1940 pRasterDoc->getView()->getFrame()->Show(true);
1941 std::ostringstream os;
1942 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << m_iDefaultRasterNX << ", YSize="
1943 << m_iDefaultRasterNY << ", nSamples=" << m_iDefaultRasterNSamples;
1944 *theApp->getLog() << os.str().c_str() << "\n";
1945 pImageFile->labelAdd (os.str().c_str(), timer.timerEnd());
1946 ImageFileView* rasterView = pRasterDoc->getView();
1948 rasterView->getFrame()->SetFocus();
1949 rasterView->OnUpdate (rasterView, NULL);
1958 PhantomFileView::CreateCanvas (wxFrame *parent)
1960 PhantomCanvas* pCanvas;
1962 parent->GetClientSize(&width, &height);
1964 pCanvas = new PhantomCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
1966 pCanvas->SetBackgroundColour(*wxWHITE);
1977 PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view)
1980 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
1982 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
1984 theApp->setIconForFrame (subframe);
1986 m_pFileMenu = new wxMenu;
1988 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
1989 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
1990 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
1991 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
1992 m_pFileMenu->Append(wxID_CLOSE, "&Close");
1994 m_pFileMenu->AppendSeparator();
1995 m_pFileMenu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties");
1997 m_pFileMenu->AppendSeparator();
1998 m_pFileMenu->Append(wxID_PRINT, "&Print...");
1999 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2000 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2002 m_pFileMenu->AppendSeparator();
2003 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2005 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2006 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2008 wxMenu *process_menu = new wxMenu;
2009 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...\tCtrl-R");
2010 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...\tCtrl-J");
2012 wxMenu *help_menu = new wxMenu;
2013 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2014 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
2015 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2017 wxMenuBar *menu_bar = new wxMenuBar;
2019 menu_bar->Append(m_pFileMenu, "&File");
2020 menu_bar->Append(process_menu, "&Process");
2021 menu_bar->Append(help_menu, "&Help");
2023 subframe->SetMenuBar(menu_bar);
2024 subframe->Centre(wxBOTH);
2026 wxAcceleratorEntry accelEntries[8];
2027 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
2028 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
2029 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
2030 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
2031 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
2032 accelEntries[5].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
2033 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('J'), PHMMENU_PROCESS_PROJECTIONS);
2034 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('R'), PHMMENU_PROCESS_RASTERIZE);
2035 wxAcceleratorTable accelTable (8, accelEntries);
2036 subframe->SetAcceleratorTable (accelTable);
2043 PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2045 m_pFrame = CreateChildFrame(doc, this);
2049 m_pFrame->GetClientSize(&width, &height);
2050 m_pFrame->SetTitle("PhantomFileView");
2051 m_pCanvas = CreateCanvas (m_pFrame);
2054 int x, y; // X requires a forced resize
2055 m_pFrame->GetSize(&x, &y);
2056 m_pFrame->SetSize(-1, -1, x, y);
2059 m_pFrame->Show(true);
2066 PhantomFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2069 m_pCanvas->Refresh();
2073 PhantomFileView::OnClose (bool deleteWindow)
2075 //GetDocumentManager()->ActivateView (this, false, true);
2076 if (! GetDocument() || ! GetDocument()->Close())
2081 m_pCanvas->setView(NULL);
2084 wxString s(wxTheApp->GetAppName());
2086 m_pFrame->SetTitle(s);
2093 if (GetDocument() && GetDocument()->getBadFileOpen())
2094 ::wxYield(); // wxWindows bug workaround
2101 PhantomFileView::OnDraw (wxDC* dc)
2104 m_pCanvas->GetClientSize (&xsize, &ysize);
2105 SGPDriver driver (dc, xsize, ysize);
2107 const Phantom& rPhantom = GetDocument()->getPhantom();
2108 sgp.setColor (C_RED);
2109 rPhantom.show (sgp);
2114 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2115 : wxScrolledWindow(frame, -1, pos, size, style)
2120 ProjectionFileCanvas::~ProjectionFileCanvas ()
2126 ProjectionFileCanvas::OnDraw(wxDC& dc)
2129 m_pView->OnDraw(& dc);
2133 ProjectionFileCanvas::GetBestSize () const
2137 Projections& rProj = m_pView->GetDocument()->getProjections();
2138 best.Set (rProj.nDet(), rProj.nView());
2145 // ProjectionFileView
2147 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
2149 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
2150 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
2151 EVT_MENU(PJMENU_RECONSTRUCT_FBP, ProjectionFileView::OnReconstructFBP)
2152 EVT_MENU(PJMENU_CONVERT_POLAR, ProjectionFileView::OnConvertPolar)
2153 EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
2156 ProjectionFileView::ProjectionFileView()
2157 : wxView(), m_pCanvas(NULL), m_pFrame(NULL), m_pFileMenu(0)
2167 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
2168 m_dDefaultFilterParam = 1.;
2170 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
2171 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
2173 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
2174 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
2176 m_iDefaultZeropad = 1;
2177 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF3;
2178 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
2179 m_iDefaultInterpParam = 1;
2180 m_iDefaultTrace = Trace::TRACE_NONE;
2182 m_iDefaultPolarNX = 256;
2183 m_iDefaultPolarNY = 256;
2184 m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR;
2185 m_iDefaultPolarZeropad = 1;
2188 ProjectionFileView::~ProjectionFileView()
2190 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2191 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2195 ProjectionFileView::OnProperties (wxCommandEvent& event)
2197 const Projections& rProj = GetDocument()->getProjections();
2198 std::ostringstream os;
2199 rProj.printScanInfo(os);
2200 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2201 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
2202 dialogMsg.ShowModal();
2207 ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
2209 Projections& rProj = GetDocument()->getProjections();
2210 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2211 m_iDefaultPolarInterpolation, -1);
2212 if (dialogPolar.ShowModal() == wxID_OK) {
2213 wxString strInterpolation (dialogPolar.getInterpolationName());
2214 m_iDefaultPolarNX = dialogPolar.getXSize();
2215 m_iDefaultPolarNY = dialogPolar.getYSize();
2216 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2217 ImageFile& rIF = pPolarDoc->getImageFile();
2219 sys_error (ERR_SEVERE, "Unable to create image file");
2222 rIF.setArraySize (m_iDefaultPolarNX, m_iDefaultPolarNY);
2223 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2224 rProj.convertPolar (rIF, m_iDefaultPolarInterpolation);
2225 rIF.labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2226 std::ostringstream os;
2227 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to polar image: xSize="
2228 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2229 << strInterpolation.c_str();
2230 *theApp->getLog() << os.str().c_str() << "\n";
2231 rIF.labelAdd (os.str().c_str());
2232 pPolarDoc->Modify (true);
2233 pPolarDoc->UpdateAllViews ();
2234 pPolarDoc->getView()->OnUpdate (this, NULL);
2235 pPolarDoc->getView()->getFrame()->Show(true);
2240 ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
2242 Projections& rProj = GetDocument()->getProjections();
2243 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert to FFT Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2244 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad);
2245 if (dialogPolar.ShowModal() == wxID_OK) {
2246 wxString strInterpolation (dialogPolar.getInterpolationName());
2247 m_iDefaultPolarNX = dialogPolar.getXSize();
2248 m_iDefaultPolarNY = dialogPolar.getYSize();
2249 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2250 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2251 ImageFile& rIF = pPolarDoc->getImageFile();
2253 sys_error (ERR_SEVERE, "Unable to create image file");
2256 rIF.setArraySize (m_iDefaultPolarNX, m_iDefaultPolarNY);
2257 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2258 rProj.convertFFTPolar (rIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad);
2259 rIF.labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2260 std::ostringstream os;
2261 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to FFT polar image: xSize="
2262 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2263 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2264 *theApp->getLog() << os.str().c_str() << "\n";
2265 rIF.labelAdd (os.str().c_str());
2266 pPolarDoc->Modify (true);
2267 pPolarDoc->UpdateAllViews ();
2268 pPolarDoc->getView()->OnUpdate (this, NULL);
2269 pPolarDoc->getView()->getFrame()->Show(true);
2274 ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
2276 wxMessageBox ("Fourier Reconstruction is not yet supported", "Unimplemented function");
2280 ProjectionFileView::OnReconstructFBP (wxCommandEvent& event)
2282 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);
2284 int retVal = dialogReconstruction.ShowModal();
2285 if (retVal == wxID_OK) {
2286 m_iDefaultNX = dialogReconstruction.getXSize();
2287 m_iDefaultNY = dialogReconstruction.getYSize();
2288 wxString optFilterName = dialogReconstruction.getFilterName();
2289 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
2290 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
2291 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
2292 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
2293 m_iDefaultZeropad = dialogReconstruction.getZeropad();
2294 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
2295 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
2296 wxString optInterpName = dialogReconstruction.getInterpName();
2297 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
2298 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
2299 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
2300 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
2301 m_iDefaultTrace = dialogReconstruction.getTrace();
2302 if (m_iDefaultNX > 0 && m_iDefaultNY > 0) {
2303 const Projections& rProj = GetDocument()->getProjections();
2305 ImageFile* pImageFile = new ImageFile;
2306 pImageFile->setArraySize (m_iDefaultNX, m_iDefaultNY);
2308 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);
2311 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2312 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstructor, rProj, *pImageFile, m_iDefaultTrace, getFrameForChild());
2313 for (int iView = 0; iView < rProj.nView(); iView++) {
2315 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView)) {
2316 delete pDlgReconstruct;
2317 delete pReconstructor;
2322 while (pDlgReconstruct->isPaused()) {
2327 delete pDlgReconstruct;
2329 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT);
2330 for (int i = 0; i < rProj.nView(); i++) {
2331 pReconstructor->reconstructView (i, 1);
2332 if (! dlgProgress.Update (i + 1)) {
2333 delete pReconstructor;
2339 delete pReconstructor;
2340 ImageFileDocument* pReconDoc = theApp->newImageDoc();
2342 sys_error (ERR_SEVERE, "Unable to create image file");
2345 pReconDoc->setImageFile (pImageFile);
2346 pReconDoc->Modify (true);
2347 pReconDoc->UpdateAllViews (this);
2348 if (ImageFileView* rasterView = pReconDoc->getView()) {
2349 rasterView->OnUpdate (rasterView, NULL);
2350 rasterView->getFrame()->SetFocus();
2351 rasterView->getFrame()->Show(true);
2353 std::ostringstream os;
2354 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();
2355 *theApp->getLog() << os.str().c_str() << "\n";
2356 pImageFile->labelAdd (rProj.getLabel());
2357 pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd());
2363 ProjectionFileCanvas*
2364 ProjectionFileView::CreateCanvas (wxFrame *parent)
2366 ProjectionFileCanvas* pCanvas;
2368 parent->GetClientSize(&width, &height);
2370 pCanvas = new ProjectionFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
2372 pCanvas->SetScrollbars(20, 20, 50, 50);
2373 pCanvas->SetBackgroundColour(*wxWHITE);
2384 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2387 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2389 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2391 theApp->setIconForFrame (subframe);
2393 m_pFileMenu = new wxMenu;
2395 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2396 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2397 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2398 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2399 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2400 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2402 m_pFileMenu->AppendSeparator();
2403 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
2405 m_pFileMenu->AppendSeparator();
2406 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2407 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2408 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2410 m_pFileMenu->AppendSeparator();
2411 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2413 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2414 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2416 wxMenu *convert_menu = new wxMenu;
2417 convert_menu->Append (PJMENU_CONVERT_POLAR, "&Polar Image...\tCtrl-L");
2418 convert_menu->Append (PJMENU_CONVERT_FFT_POLAR, "&FFT->Polar Image...\tCtrl-I");
2420 wxMenu *reconstruct_menu = new wxMenu;
2421 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP, "&Filtered Backprojection...\tCtrl-R", "Reconstruct image using filtered backprojection");
2422 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Fourier...\tCtrl-E", "Reconstruct image using inverse Fourier");
2423 reconstruct_menu->Enable (PJMENU_RECONSTRUCT_FOURIER, false);
2425 wxMenu *help_menu = new wxMenu;
2426 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2427 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
2428 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2430 wxMenuBar *menu_bar = new wxMenuBar;
2432 menu_bar->Append (m_pFileMenu, "&File");
2433 menu_bar->Append (convert_menu, "&Convert");
2434 menu_bar->Append (reconstruct_menu, "&Reconstruct");
2435 menu_bar->Append (help_menu, "&Help");
2437 subframe->SetMenuBar(menu_bar);
2438 subframe->Centre(wxBOTH);
2440 wxAcceleratorEntry accelEntries[11];
2441 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
2442 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
2443 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
2444 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
2445 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
2446 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
2447 accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
2448 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('L'), PJMENU_CONVERT_POLAR);
2449 accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('I'), PJMENU_CONVERT_FFT_POLAR);
2450 accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('R'), PJMENU_RECONSTRUCT_FBP);
2451 accelEntries[10].Set (wxACCEL_CTRL, static_cast<int>('E'), PJMENU_RECONSTRUCT_FOURIER);
2452 wxAcceleratorTable accelTable (11, accelEntries);
2453 subframe->SetAcceleratorTable (accelTable);
2460 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2462 m_pFrame = CreateChildFrame(doc, this);
2466 m_pFrame->GetClientSize (&width, &height);
2467 m_pFrame->SetTitle ("ProjectionFileView");
2468 m_pCanvas = CreateCanvas (m_pFrame);
2471 int x, y; // X requires a forced resize
2472 m_pFrame->GetSize(&x, &y);
2473 m_pFrame->SetSize(-1, -1, x, y);
2476 m_pFrame->Show(true);
2483 ProjectionFileView::OnDraw (wxDC* dc)
2485 wxSize clientSize = m_pFrame->GetClientSize();
2486 wxSize bestSize = m_pCanvas->GetBestSize();
2488 if (clientSize.x > bestSize.x || clientSize.y > bestSize.y)
2489 m_pFrame->SetClientSize (bestSize);
2492 dc->DrawBitmap (m_bitmap, 0, 0, false);
2497 ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2499 const Projections& rProj = GetDocument()->getProjections();
2500 const int nDet = rProj.nDet();
2501 const int nView = rProj.nView();
2502 if (nDet != 0 && nView != 0) {
2503 const DetectorArray& detarray = rProj.getDetectorArray(0);
2504 const DetectorValue* detval = detarray.detValues();
2505 double min = detval[0];
2506 double max = detval[0];
2507 for (int iy = 0; iy < nView; iy++) {
2508 const DetectorArray& detarray = rProj.getDetectorArray(iy);
2509 const DetectorValue* detval = detarray.detValues();
2510 for (int ix = 0; ix < nDet; ix++) {
2511 if (min > detval[ix])
2513 else if (max < detval[ix])
2518 unsigned char* imageData = new unsigned char [nDet * nView * 3];
2519 double scale = (max - min) / 255;
2520 for (int iy2 = 0; iy2 < nView; iy2++) {
2521 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
2522 const DetectorValue* detval = detarray.detValues();
2523 for (int ix = 0; ix < nDet; ix++) {
2524 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
2525 intensity = clamp(intensity, 0, 255);
2526 int baseAddr = (iy2 * nDet + ix) * 3;
2527 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
2530 wxImage image (nDet, nView, imageData, true);
2531 m_bitmap = image.ConvertToBitmap();
2535 xSize = clamp (xSize, 0, 800);
2536 ySize = clamp (ySize, 0, 800);
2537 m_pFrame->SetClientSize (xSize, ySize);
2538 m_pCanvas->SetScrollbars (20, 20, nDet/20, nView/20);
2542 m_pCanvas->Refresh();
2546 ProjectionFileView::OnClose (bool deleteWindow)
2548 //GetDocumentManager()->ActivateView (this, false, true);
2549 if (! GetDocument() || ! GetDocument()->Close())
2554 m_pCanvas->setView(NULL);
2557 wxString s(wxTheApp->GetAppName());
2559 m_pFrame->SetTitle(s);
2566 if (GetDocument() && GetDocument()->getBadFileOpen())
2567 ::wxYield(); // wxWindows bug workaround
2576 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2577 : wxScrolledWindow(frame, -1, pos, size, style)
2582 PlotFileCanvas::~PlotFileCanvas ()
2588 PlotFileCanvas::OnDraw(wxDC& dc)
2591 m_pView->OnDraw(& dc);
2597 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
2599 BEGIN_EVENT_TABLE(PlotFileView, wxView)
2600 EVT_MENU(PJMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
2601 EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
2602 EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
2603 EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
2606 PlotFileView::PlotFileView()
2607 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pEZPlot(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
2611 PlotFileView::~PlotFileView()
2616 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2620 PlotFileView::OnProperties (wxCommandEvent& event)
2622 const PlotFile& rPlot = GetDocument()->getPlotFile();
2623 std::ostringstream os;
2624 os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
2625 rPlot.printHeadersBrief (os);
2626 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<<\n";
2627 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
2628 dialogMsg.ShowModal();
2633 PlotFileView::OnScaleAuto (wxCommandEvent& event)
2635 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2636 double min, max, mean, mode, median, stddev;
2637 rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
2638 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
2639 int iRetVal = dialogAutoScale.ShowModal();
2640 if (iRetVal == wxID_OK) {
2641 m_bMinSpecified = true;
2642 m_bMaxSpecified = true;
2644 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
2647 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
2648 OnUpdate (this, NULL);
2654 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
2656 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2660 if (! m_bMinSpecified || ! m_bMaxSpecified) {
2661 if (! rPlotFile.getMinMax (1, min, max)) {
2662 *theApp->getLog() << "Error: unable to find Min/Max\n";
2667 if (m_bMinSpecified)
2669 if (m_bMaxSpecified)
2672 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Y-axis Minimum & Maximum", min, max);
2673 int retVal = dialogMinMax.ShowModal();
2674 if (retVal == wxID_OK) {
2675 m_bMinSpecified = true;
2676 m_bMaxSpecified = true;
2677 m_dMinPixel = dialogMinMax.getMinimum();
2678 m_dMaxPixel = dialogMinMax.getMaximum();
2679 OnUpdate (this, NULL);
2684 PlotFileView::OnScaleFull (wxCommandEvent& event)
2686 if (m_bMinSpecified || m_bMaxSpecified) {
2687 m_bMinSpecified = false;
2688 m_bMaxSpecified = false;
2689 OnUpdate (this, NULL);
2695 PlotFileView::CreateCanvas (wxFrame* parent)
2697 PlotFileCanvas* pCanvas;
2699 parent->GetClientSize(&width, &height);
2701 pCanvas = new PlotFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
2703 pCanvas->SetBackgroundColour(*wxWHITE);
2714 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2717 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2719 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2721 theApp->setIconForFrame (subframe);
2723 m_pFileMenu = new wxMenu;
2725 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2726 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2727 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2728 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2729 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2730 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2732 m_pFileMenu->AppendSeparator();
2733 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
2735 m_pFileMenu->AppendSeparator();
2736 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2737 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2738 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2740 m_pFileMenu->AppendSeparator();
2741 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2743 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2744 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2746 wxMenu *view_menu = new wxMenu;
2747 view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...\tCtrl-E");
2748 view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
2749 view_menu->Append(PLOTMENU_VIEW_SCALE_FULL, "Display &Full Scale\tCtrl-U");
2751 wxMenu *help_menu = new wxMenu;
2752 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2753 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
2754 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2756 wxMenuBar *menu_bar = new wxMenuBar;
2758 menu_bar->Append(m_pFileMenu, "&File");
2759 menu_bar->Append(view_menu, "&View");
2760 menu_bar->Append(help_menu, "&Help");
2762 subframe->SetMenuBar(menu_bar);
2763 subframe->Centre(wxBOTH);
2765 wxAcceleratorEntry accelEntries[10];
2766 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
2767 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
2768 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
2769 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
2770 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
2771 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
2772 accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
2773 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('E'), PLOTMENU_VIEW_SCALE_MINMAX);
2774 accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('A'), PLOTMENU_VIEW_SCALE_AUTO);
2775 accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('U'), PLOTMENU_VIEW_SCALE_FULL);
2776 wxAcceleratorTable accelTable (10, accelEntries);
2777 subframe->SetAcceleratorTable (accelTable);
2784 PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
2786 m_pFrame = CreateChildFrame(doc, this);
2789 m_bMinSpecified = false;
2790 m_bMaxSpecified = false;
2791 m_dAutoScaleFactor = 1.;
2794 m_pFrame->GetClientSize(&width, &height);
2795 m_pFrame->SetTitle ("Plot File");
2796 m_pCanvas = CreateCanvas (m_pFrame);
2799 int x, y; // X requires a forced resize
2800 m_pFrame->GetSize(&x, &y);
2801 m_pFrame->SetSize(-1, -1, x, y);
2804 m_pFrame->Show(true);
2811 PlotFileView::OnDraw (wxDC* dc)
2813 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2814 const int iNColumns = rPlotFile.getNumColumns();
2815 const int iNRecords = rPlotFile.getNumRecords();
2817 if (iNColumns > 0 && iNRecords > 0) {
2819 m_pCanvas->GetClientSize (&xsize, &ysize);
2820 SGPDriver driver (dc, xsize, ysize);
2823 m_pEZPlot->plot (&sgp);
2829 PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2831 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2832 const int iNColumns = rPlotFile.getNumColumns();
2833 const int iNRecords = rPlotFile.getNumRecords();
2835 if (iNColumns > 0 && iNRecords > 0) {
2838 m_pEZPlot = new EZPlot;
2840 for (unsigned int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)
2841 m_pEZPlot->ezset (rPlotFile.getEzsetCommand (iEzset));
2843 if (m_bMinSpecified) {
2844 std::ostringstream os;
2845 os << "ymin " << m_dMinPixel;
2846 m_pEZPlot->ezset (os.str());
2849 if (m_bMaxSpecified) {
2850 std::ostringstream os;
2851 os << "ymax " << m_dMaxPixel;
2852 m_pEZPlot->ezset (os.str());
2855 m_pEZPlot->ezset("box");
2856 m_pEZPlot->ezset("grid");
2858 double* pdXaxis = new double [iNRecords];
2859 rPlotFile.getColumn (0, pdXaxis);
2861 double* pdY = new double [iNRecords];
2862 for (int iCol = 1; iCol < iNColumns; iCol++) {
2863 rPlotFile.getColumn (iCol, pdY);
2864 m_pEZPlot->addCurve (pdXaxis, pdY, iNRecords);
2872 m_pCanvas->Refresh();
2876 PlotFileView::OnClose (bool deleteWindow)
2878 //GetDocumentManager()->ActivateView (this, false, true);
2879 if (! GetDocument() || ! GetDocument()->Close())
2884 m_pCanvas->setView (NULL);
2887 wxString s(wxTheApp->GetAppName());
2889 m_pFrame->SetTitle(s);
2895 if (GetDocument() && GetDocument()->getBadFileOpen())
2896 ::wxYield(); // wxWindows bug workaround
2903 ////////////////////////////////////////////////////////////////
2906 IMPLEMENT_DYNAMIC_CLASS(TextFileView, wxView)
2908 TextFileView::~TextFileView()
2910 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2911 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2914 bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2916 m_pFrame = CreateChildFrame(doc, this);
2917 SetFrame (m_pFrame);
2920 m_pFrame->GetClientSize(&width, &height);
2921 m_pFrame->SetTitle("TextFile");
2922 m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
2923 m_pFrame->SetTitle("Log");
2926 // X seems to require a forced resize
2928 frame->GetSize(&x, &y);
2929 frame->SetSize(-1, -1, x, y);
2932 m_pFrame->Show (true);
2938 // Handled by wxTextWindow
2939 void TextFileView::OnDraw(wxDC *WXUNUSED(dc) )
2943 void TextFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2948 TextFileView::OnClose (bool deleteWindow)
2950 if (! theApp->getMainFrame()->getShuttingDown())
2954 //GetDocumentManager()->ActivateView (this, false, true);
2955 if (! GetDocument() || ! GetDocument()->Close())
2962 if (GetDocument() && GetDocument()->getBadFileOpen())
2963 ::wxYield(); // wxWindows bug workaround
2974 TextFileView::CreateChildFrame (wxDocument *doc, wxView *view)
2977 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(0,0), wxDEFAULT_FRAME_STYLE, "Log");
2979 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE, "Log");
2981 theApp->setIconForFrame (subframe);
2983 m_pFileMenu = new wxMenu;
2985 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2986 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2987 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2988 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2989 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2990 // m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2992 m_pFileMenu->AppendSeparator();
2993 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2994 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2995 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2997 m_pFileMenu->AppendSeparator();
2998 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3000 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3001 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3003 wxMenu *help_menu = new wxMenu;
3004 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3005 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
3006 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3008 wxMenuBar *menu_bar = new wxMenuBar;
3010 menu_bar->Append(m_pFileMenu, "&File");
3011 menu_bar->Append(help_menu, "&Help");
3013 subframe->SetMenuBar(menu_bar);
3014 subframe->Centre(wxBOTH);
3016 wxAcceleratorEntry accelEntries[5];
3017 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
3018 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
3019 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
3020 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
3021 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
3022 wxAcceleratorTable accelTable (5, accelEntries);
3023 subframe->SetAcceleratorTable (accelTable);
3029 // Define a constructor for my text subwindow
3030 TextFileCanvas::TextFileCanvas (TextFileView* v, wxFrame* frame, const wxPoint& pos, const wxSize& size, long style)
3031 : wxTextCtrl (frame, -1, "", pos, size, style), m_pView(v)
3035 TextFileCanvas::~TextFileCanvas ()