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.91 2001/01/30 05:05:41 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)
230 EVT_MENU(IFMENU_FILTER_FFT, ImageFileView::OnFFT)
231 EVT_MENU(IFMENU_FILTER_IFFT, ImageFileView::OnIFFT)
232 EVT_MENU(IFMENU_FILTER_FFT_ROWS, ImageFileView::OnFFTRows)
233 EVT_MENU(IFMENU_FILTER_IFFT_ROWS, ImageFileView::OnIFFTRows)
234 EVT_MENU(IFMENU_FILTER_FFT_COLS, ImageFileView::OnFFTCols)
235 EVT_MENU(IFMENU_FILTER_IFFT_COLS, ImageFileView::OnIFFTCols)
237 EVT_MENU(IFMENU_FILTER_MAGNITUDE, ImageFileView::OnMagnitude)
238 EVT_MENU(IFMENU_FILTER_PHASE, ImageFileView::OnPhase)
239 EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)
240 EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol)
242 EVT_MENU(IFMENU_PLOT_FFT_ROW, ImageFileView::OnPlotFFTRow)
243 EVT_MENU(IFMENU_PLOT_FFT_COL, ImageFileView::OnPlotFFTCol)
245 EVT_MENU(IFMENU_PLOT_HISTOGRAM, ImageFileView::OnPlotHistogram)
248 ImageFileView::ImageFileView()
249 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
251 m_iDefaultExportFormatID = ImageFile::FORMAT_PNG;
254 ImageFileView::~ImageFileView()
256 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
257 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
262 ImageFileView::OnProperties (wxCommandEvent& event)
264 const ImageFile& rIF = GetDocument()->getImageFile();
265 if (rIF.nx() == 0 || rIF.ny() == 0)
266 *theApp->getLog() << "Properties: empty imagefile\n";
268 const std::string& rFilename = rIF.getFilename();
269 std::ostringstream os;
270 double min, max, mean, mode, median, stddev;
271 rIF.statistics (rIF.getArray(), min, max, mean, mode, median, stddev);
272 os << "Filename: " << rFilename << "\n";
273 os << "Size: (" << rIF.nx() << "," << rIF.ny() << ")\n";
279 os << "Minimum: "<<min<<"\nMaximum: "<<max<<"\nMean: "<<mean<<"\nMedian: "<<median<<"\nMode: "<<mode<<"\nStandard Deviation: "<<stddev << "\n";
280 if (rIF.isComplex()) {
281 rIF.statistics (rIF.getImaginaryArray(), min, max, mean, mode, median, stddev);
282 os << "Imaginary: min: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
284 if (rIF.nLabels() > 0) {
285 rIF.printLabelsBrief (os);
287 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
288 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
289 dialogMsg.ShowModal();
294 ImageFileView::OnScaleAuto (wxCommandEvent& event)
296 const ImageFile& rIF = GetDocument()->getImageFile();
297 double min, max, mean, mode, median, stddev;
298 rIF.statistics(min, max, mean, mode, median, stddev);
299 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
300 int iRetVal = dialogAutoScale.ShowModal();
301 if (iRetVal == wxID_OK) {
302 m_bMinSpecified = true;
303 m_bMaxSpecified = true;
305 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
308 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
309 OnUpdate (this, NULL);
315 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
317 const ImageFile& rIF = GetDocument()->getImageFile();
319 if (! m_bMinSpecified && ! m_bMaxSpecified)
320 rIF.getMinMax (min, max);
327 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Image Minimum & Maximum", min, max);
328 int retVal = dialogMinMax.ShowModal();
329 if (retVal == wxID_OK) {
330 m_bMinSpecified = true;
331 m_bMaxSpecified = true;
332 m_dMinPixel = dialogMinMax.getMinimum();
333 m_dMaxPixel = dialogMinMax.getMaximum();
334 OnUpdate (this, NULL);
339 ImageFileView::OnScaleFull (wxCommandEvent& event)
341 if (m_bMinSpecified || m_bMaxSpecified) {
342 m_bMinSpecified = false;
343 m_bMaxSpecified = false;
344 OnUpdate (this, NULL);
349 ImageFileView::OnCompare (wxCommandEvent& event)
351 std::vector<ImageFileDocument*> vecIF;
352 theApp->getCompatibleImages (GetDocument(), vecIF);
354 if (vecIF.size() == 0) {
355 wxMessageBox("There are no compatible image files open for comparision", "No comparison images");
357 DialogGetComparisonImage dialogGetCompare(getFrameForChild(), "Get Comparison Image", vecIF, true);
359 if (dialogGetCompare.ShowModal() == wxID_OK) {
360 const ImageFile& rIF = GetDocument()->getImageFile();
361 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
362 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
363 std::ostringstream os;
364 double min, max, mean, mode, median, stddev;
365 rIF.statistics (min, max, mean, mode, median, stddev);
366 os << GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
367 rCompareIF.statistics (min, max, mean, mode, median, stddev);
368 os << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
370 rIF.comparativeStatistics (rCompareIF, d, r, e);
371 os << "Comparative Statistics: d=" << d << ", r=" << r << ", e=" << e << "\n";
372 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
373 if (dialogGetCompare.getMakeDifferenceImage()) {
374 ImageFile* pDifferenceImage = new ImageFile;
376 pDifferenceImage->setArraySize (rIF.nx(), rIF.ny());
377 if (! rIF.subtractImages (rCompareIF, *pDifferenceImage)) {
378 *theApp->getLog() << "Unable to subtract images\n";
379 delete pDifferenceImage;
382 ImageFileDocument* pDifferenceDoc = theApp->newImageDoc();
383 if (! pDifferenceDoc) {
384 sys_error (ERR_SEVERE, "Unable to create image file");
387 pDifferenceDoc->setImageFile (pDifferenceImage);
389 wxString s = GetFrame()->GetTitle() + ": ";
390 pDifferenceImage->labelsCopy (rIF, s.c_str());
391 s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
392 pDifferenceImage->labelsCopy (rCompareIF, s.c_str());
393 std::ostringstream osLabel;
394 osLabel << "Compare image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str()
395 << " and " << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": "
397 pDifferenceImage->labelAdd (os.str().c_str());
398 pDifferenceDoc->Modify (true);
399 pDifferenceDoc->UpdateAllViews (this);
400 pDifferenceDoc->getView()->OnUpdate (this, NULL);
401 pDifferenceDoc->getView()->getFrame()->Show(true);
403 wxMessageBox(os.str().c_str(), "Image Comparison");
409 ImageFileView::OnInvertValues (wxCommandEvent& event)
411 ImageFile& rIF = GetDocument()->getImageFile();
412 rIF.invertPixelValues (rIF);
413 rIF.labelAdd ("Invert Pixel Values");
414 GetDocument()->Modify (true);
415 GetDocument()->UpdateAllViews (this);
419 ImageFileView::OnSquare (wxCommandEvent& event)
421 ImageFile& rIF = GetDocument()->getImageFile();
423 rIF.labelAdd ("Square Pixel Values");
424 GetDocument()->Modify (true);
425 GetDocument()->UpdateAllViews (this);
429 ImageFileView::OnSquareRoot (wxCommandEvent& event)
431 ImageFile& rIF = GetDocument()->getImageFile();
433 rIF.labelAdd ("Square-root Pixel Values");
434 GetDocument()->Modify (true);
435 GetDocument()->UpdateAllViews (this);
439 ImageFileView::OnLog (wxCommandEvent& event)
441 ImageFile& rIF = GetDocument()->getImageFile();
443 rIF.labelAdd ("Logrithm base-e Pixel Values");
444 GetDocument()->Modify (true);
445 GetDocument()->UpdateAllViews (this);
449 ImageFileView::OnExp (wxCommandEvent& event)
451 ImageFile& rIF = GetDocument()->getImageFile();
453 rIF.labelAdd ("Exponent base-e Pixel Values");
454 GetDocument()->Modify (true);
455 GetDocument()->UpdateAllViews (this);
459 ImageFileView::OnAdd (wxCommandEvent& event)
461 std::vector<ImageFileDocument*> vecIF;
462 theApp->getCompatibleImages (GetDocument(), vecIF);
464 if (vecIF.size() == 0) {
465 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
467 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Add", vecIF, false);
469 if (dialogGetCompare.ShowModal() == wxID_OK) {
470 ImageFile& rIF = GetDocument()->getImageFile();
471 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
472 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
473 ImageFileDocument* pNewDoc = theApp->newImageDoc();
475 sys_error (ERR_SEVERE, "Unable to create image file");
478 ImageFile& newImage = pNewDoc->getImageFile();
479 newImage.setArraySize (rIF.nx(), rIF.ny());
480 rIF.addImages (rRHSIF, newImage);
481 std::ostringstream os;
482 os << "Add image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
483 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
484 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
485 newImage.labelsCopy (rIF, s.c_str());
486 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
487 newImage.labelsCopy (rRHSIF, s.c_str());
488 newImage.labelAdd (os.str().c_str());
489 *theApp->getLog() << os.str().c_str() << "\n";
490 pNewDoc->Modify (true);
491 pNewDoc->UpdateAllViews (this);
492 pNewDoc->getView()->OnUpdate (this, NULL);
493 pNewDoc->getView()->getFrame()->Show(true);
499 ImageFileView::OnSubtract (wxCommandEvent& event)
501 std::vector<ImageFileDocument*> vecIF;
502 theApp->getCompatibleImages (GetDocument(), vecIF);
504 if (vecIF.size() == 0) {
505 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
507 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Subtract", vecIF, false);
509 if (dialogGetCompare.ShowModal() == wxID_OK) {
510 ImageFile& rIF = GetDocument()->getImageFile();
511 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
512 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
513 ImageFileDocument* pNewDoc = theApp->newImageDoc();
515 sys_error (ERR_SEVERE, "Unable to create image file");
518 ImageFile& newImage = pNewDoc->getImageFile();
519 newImage.setArraySize (rIF.nx(), rIF.ny());
520 rIF.subtractImages (rRHSIF, newImage);
521 std::ostringstream os;
522 os << "Subtract image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
523 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
524 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
525 newImage.labelsCopy (rIF, s.c_str());
526 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
527 newImage.labelsCopy (rRHSIF, s.c_str());
528 newImage.labelAdd (os.str().c_str());
529 *theApp->getLog() << os.str().c_str() << "\n";
530 pNewDoc->Modify (true);
531 pNewDoc->UpdateAllViews (this);
532 pNewDoc->getView()->OnUpdate (this, NULL);
533 pNewDoc->getView()->getFrame()->Show(true);
539 ImageFileView::OnMultiply (wxCommandEvent& event)
541 std::vector<ImageFileDocument*> vecIF;
542 theApp->getCompatibleImages (GetDocument(), vecIF);
544 if (vecIF.size() == 0) {
545 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
547 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Multiply", vecIF, false);
549 if (dialogGetCompare.ShowModal() == wxID_OK) {
550 ImageFile& rIF = GetDocument()->getImageFile();
551 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
552 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
553 ImageFileDocument* pNewDoc = theApp->newImageDoc();
555 sys_error (ERR_SEVERE, "Unable to create image file");
558 ImageFile& newImage = pNewDoc->getImageFile();
559 newImage.setArraySize (rIF.nx(), rIF.ny());
560 rIF.multiplyImages (rRHSIF, newImage);
561 std::ostringstream os;
562 os << "Multiply image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
563 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
564 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
565 newImage.labelsCopy (rIF, s.c_str());
566 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
567 newImage.labelsCopy (rRHSIF, s.c_str());
568 newImage.labelAdd (os.str().c_str());
569 *theApp->getLog() << os.str().c_str() << "\n";
570 pNewDoc->Modify (true);
571 pNewDoc->UpdateAllViews (this);
572 pNewDoc->getView()->OnUpdate (this, NULL);
573 pNewDoc->getView()->getFrame()->Show(true);
579 ImageFileView::OnDivide (wxCommandEvent& event)
581 std::vector<ImageFileDocument*> vecIF;
582 theApp->getCompatibleImages (GetDocument(), vecIF);
584 if (vecIF.size() == 0) {
585 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
587 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Divide", vecIF, false);
589 if (dialogGetCompare.ShowModal() == wxID_OK) {
590 ImageFile& rIF = GetDocument()->getImageFile();
591 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
592 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
593 ImageFileDocument* pNewDoc = theApp->newImageDoc();
595 sys_error (ERR_SEVERE, "Unable to create image file");
598 ImageFile& newImage = pNewDoc->getImageFile();
599 newImage.setArraySize (rIF.nx(), rIF.ny());
600 rIF.divideImages (rRHSIF, newImage);
601 std::ostringstream os;
602 os << "Divide image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " by "
603 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
604 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
605 newImage.labelsCopy (rIF, s.c_str());
606 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
607 newImage.labelsCopy (rRHSIF, s.c_str());
608 newImage.labelAdd (os.str().c_str());
609 *theApp->getLog() << os.str().c_str() << "\n";
610 pNewDoc->Modify (true);
611 pNewDoc->UpdateAllViews (this);
612 pNewDoc->getView()->OnUpdate (this, NULL);
613 pNewDoc->getView()->getFrame()->Show(true);
621 ImageFileView::OnFFT (wxCommandEvent& event)
623 ImageFile& rIF = GetDocument()->getImageFile();
625 rIF.labelAdd ("FFT Image");
626 m_bMinSpecified = false;
627 m_bMaxSpecified = false;
628 GetDocument()->Modify (true);
629 GetDocument()->UpdateAllViews (this);
633 ImageFileView::OnIFFT (wxCommandEvent& event)
635 ImageFile& rIF = GetDocument()->getImageFile();
637 rIF.labelAdd ("IFFT Image");
638 m_bMinSpecified = false;
639 m_bMaxSpecified = false;
640 GetDocument()->Modify (true);
641 GetDocument()->UpdateAllViews (this);
645 ImageFileView::OnFFTRows (wxCommandEvent& event)
647 ImageFile& rIF = GetDocument()->getImageFile();
649 rIF.labelAdd ("FFT Rows");
650 m_bMinSpecified = false;
651 m_bMaxSpecified = false;
652 GetDocument()->Modify (true);
653 GetDocument()->UpdateAllViews (this);
657 ImageFileView::OnIFFTRows (wxCommandEvent& event)
659 ImageFile& rIF = GetDocument()->getImageFile();
661 rIF.labelAdd ("IFFT Rows");
662 m_bMinSpecified = false;
663 m_bMaxSpecified = false;
664 GetDocument()->Modify (true);
665 GetDocument()->UpdateAllViews (this);
669 ImageFileView::OnFFTCols (wxCommandEvent& event)
671 ImageFile& rIF = GetDocument()->getImageFile();
673 rIF.labelAdd ("FFT Columns");
674 m_bMinSpecified = false;
675 m_bMaxSpecified = false;
676 GetDocument()->Modify (true);
677 GetDocument()->UpdateAllViews (this);
681 ImageFileView::OnIFFTCols (wxCommandEvent& event)
683 ImageFile& rIF = GetDocument()->getImageFile();
685 rIF.labelAdd ("IFFT Columns");
686 m_bMinSpecified = false;
687 m_bMaxSpecified = false;
688 GetDocument()->Modify (true);
689 GetDocument()->UpdateAllViews (this);
694 ImageFileView::OnFourier (wxCommandEvent& event)
696 ImageFile& rIF = GetDocument()->getImageFile();
697 wxProgressDialog dlgProgress (wxString("Fourier"), wxString("Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
699 rIF.labelAdd ("Fourier Image");
700 m_bMinSpecified = false;
701 m_bMaxSpecified = false;
702 GetDocument()->Modify (true);
703 GetDocument()->UpdateAllViews (this);
707 ImageFileView::OnInverseFourier (wxCommandEvent& event)
709 ImageFile& rIF = GetDocument()->getImageFile();
710 wxProgressDialog dlgProgress (wxString("Inverse Fourier"), wxString("Inverse Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
711 rIF.inverseFourier (rIF);
712 rIF.labelAdd ("Inverse Fourier Image");
713 m_bMinSpecified = false;
714 m_bMaxSpecified = false;
715 GetDocument()->Modify (true);
716 GetDocument()->UpdateAllViews (this);
720 ImageFileView::OnShuffleNaturalToFourierOrder (wxCommandEvent& event)
722 ImageFile& rIF = GetDocument()->getImageFile();
723 Fourier::shuffleNaturalToFourierOrder (rIF);
724 rIF.labelAdd ("Shuffle Natural To Fourier Order");
725 m_bMinSpecified = false;
726 m_bMaxSpecified = false;
727 GetDocument()->Modify (true);
728 GetDocument()->UpdateAllViews (this);
732 ImageFileView::OnShuffleFourierToNaturalOrder (wxCommandEvent& event)
734 ImageFile& rIF = GetDocument()->getImageFile();
735 Fourier::shuffleFourierToNaturalOrder (rIF);
736 rIF.labelAdd ("Shuffle Fourier To Natural Order");
737 m_bMinSpecified = false;
738 m_bMaxSpecified = false;
739 GetDocument()->Modify (true);
740 GetDocument()->UpdateAllViews (this);
744 ImageFileView::OnMagnitude (wxCommandEvent& event)
746 ImageFile& rIF = GetDocument()->getImageFile();
747 if (rIF.isComplex()) {
749 rIF.labelAdd ("Magnitude of complex-image");
750 m_bMinSpecified = false;
751 m_bMaxSpecified = false;
752 GetDocument()->Modify (true);
753 GetDocument()->UpdateAllViews (this);
758 ImageFileView::OnPhase (wxCommandEvent& event)
760 ImageFile& rIF = GetDocument()->getImageFile();
761 if (rIF.isComplex()) {
763 rIF.labelAdd ("Phase of complex-image");
764 m_bMinSpecified = false;
765 m_bMaxSpecified = false;
766 GetDocument()->Modify (true);
767 GetDocument()->UpdateAllViews (this);
773 ImageFileView::CreateCanvas (wxFrame* parent)
775 ImageFileCanvas* pCanvas;
777 parent->GetClientSize(&width, &height);
779 pCanvas = new ImageFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
781 pCanvas->SetScrollbars(20, 20, 50, 50);
782 pCanvas->SetBackgroundColour(*wxWHITE);
793 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
796 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
798 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
800 theApp->setIconForFrame (subframe);
802 wxMenu *m_pFileMenu = new wxMenu;
804 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
805 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
806 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
807 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
808 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
809 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
810 m_pFileMenu->Append(wxID_REVERT, "Re&vert");
812 m_pFileMenu->AppendSeparator();
813 m_pFileMenu->Append(IFMENU_FILE_PROPERTIES, "P&roperties");
814 m_pFileMenu->Append(IFMENU_FILE_EXPORT, "&Export...");
816 m_pFileMenu->AppendSeparator();
817 m_pFileMenu->Append(wxID_PRINT, "&Print...");
818 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
819 m_pFileMenu->Append(wxID_PREVIEW, "Print Preview");
821 m_pFileMenu->AppendSeparator();
822 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
824 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
825 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
827 wxMenu *view_menu = new wxMenu;
828 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale S&et...\tCtrl-E");
829 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
830 view_menu->Append(IFMENU_VIEW_SCALE_FULL, "Display F&ull Scale\tCtrl-U");
832 wxMenu* filter_menu = new wxMenu;
833 filter_menu->Append (IFMENU_FILTER_INVERTVALUES, "&Invert Values");
834 filter_menu->Append (IFMENU_FILTER_SQUARE, "&Square");
835 filter_menu->Append (IFMENU_FILTER_SQRT, "Square &Root");
836 filter_menu->Append (IFMENU_FILTER_LOG, "&Log");
837 filter_menu->Append (IFMENU_FILTER_EXP, "&Exp");
838 filter_menu->AppendSeparator();
840 filter_menu->Append (IFMENU_FILTER_FFT, "2D &FFT");
841 filter_menu->Append (IFMENU_FILTER_IFFT, "2D &IFFT");
842 filter_menu->Append (IFMENU_FILTER_FFT_ROWS, "FFT Rows");
843 filter_menu->Append (IFMENU_FILTER_IFFT_ROWS, "IFFT Rows");
844 filter_menu->Append (IFMENU_FILTER_FFT_COLS, "FFT Columns");
845 filter_menu->Append (IFMENU_FILTER_IFFT_COLS, "IFFT Columns");
846 filter_menu->Append (IFMENU_FILTER_FOURIER, "F&ourier");
847 filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "Inverse Fo&urier");
849 filter_menu->Append (IFMENU_FILTER_FOURIER, "&Fourier");
850 filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "&Inverse Fourier");
852 filter_menu->Append (IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, "S&huffle Fourier to Natural Order");
853 filter_menu->Append (IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, "Shu&ffle Natural to Fourier Order");
854 filter_menu->Append (IFMENU_FILTER_MAGNITUDE, "&Magnitude");
855 filter_menu->Append (IFMENU_FILTER_PHASE, "&Phase");
857 wxMenu* image_menu = new wxMenu;
858 image_menu->Append (IFMENU_IMAGE_ADD, "&Add...");
859 image_menu->Append (IFMENU_IMAGE_SUBTRACT, "&Subtract...");
860 image_menu->Append (IFMENU_IMAGE_MULTIPLY, "&Multiply...");
861 image_menu->Append (IFMENU_IMAGE_DIVIDE, "&Divide...");
862 image_menu->AppendSeparator();
863 image_menu->Append (IFMENU_IMAGE_SCALESIZE, "S&cale Size...");
865 m_pMenuAnalyze = new wxMenu;
866 m_pMenuAnalyze->Append (IFMENU_PLOT_ROW, "Plot &Row");
867 m_pMenuAnalyze->Append (IFMENU_PLOT_COL, "Plot &Column");
868 m_pMenuAnalyze->Append (IFMENU_PLOT_HISTOGRAM, "Plot &Histogram");
869 m_pMenuAnalyze->AppendSeparator();
870 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_ROW, "Plot FFT Row");
871 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_COL, "Plot FFT Column");
872 m_pMenuAnalyze->AppendSeparator();
873 m_pMenuAnalyze->Append (IFMENU_COMPARE_IMAGES, "Compare &Images...");
874 m_pMenuAnalyze->Append (IFMENU_COMPARE_ROW, "Compare &Row");
875 m_pMenuAnalyze->Append (IFMENU_COMPARE_COL, "Compare &Column");
876 m_pMenuAnalyze->Enable (IFMENU_PLOT_ROW, false);
877 m_pMenuAnalyze->Enable (IFMENU_PLOT_COL, false);
878 m_pMenuAnalyze->Enable (IFMENU_COMPARE_ROW, false);
879 m_pMenuAnalyze->Enable (IFMENU_COMPARE_COL, false);
880 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_ROW, false);
881 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_COL, false);
883 wxMenu *help_menu = new wxMenu;
884 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
885 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
886 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
888 wxMenuBar *menu_bar = new wxMenuBar;
890 menu_bar->Append(m_pFileMenu, "&File");
891 menu_bar->Append(view_menu, "&View");
892 menu_bar->Append(image_menu, "&Image");
893 menu_bar->Append(filter_menu, "Fi<er");
894 menu_bar->Append(m_pMenuAnalyze, "&Analyze");
895 menu_bar->Append(help_menu, "&Help");
897 subframe->SetMenuBar(menu_bar);
899 subframe->Centre(wxBOTH);
901 wxAcceleratorEntry accelEntries[10];
902 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
903 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
904 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
905 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
906 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
907 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
908 accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
909 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('A'), IFMENU_VIEW_SCALE_AUTO);
910 accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('U'), IFMENU_VIEW_SCALE_FULL);
911 accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('E'), IFMENU_VIEW_SCALE_MINMAX);
912 wxAcceleratorTable accelTable (10, accelEntries);
913 subframe->SetAcceleratorTable (accelTable);
920 ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
922 m_pFrame = CreateChildFrame(doc, this);
925 m_bMinSpecified = false;
926 m_bMaxSpecified = false;
927 m_dAutoScaleFactor = 1.;
930 m_pFrame->GetClientSize (&width, &height);
931 m_pFrame->SetTitle("ImageFileView");
932 m_pCanvas = CreateCanvas (m_pFrame);
934 int x, y; // X requires a forced resize
935 m_pFrame->GetSize(&x, &y);
936 m_pFrame->SetSize(-1, -1, x, y);
937 m_pFrame->SetFocus();
938 m_pFrame->Show(true);
945 ImageFileView::OnDraw (wxDC* dc)
947 wxSize sizeWindow = m_pFrame->GetClientSize();
948 wxSize sizeBest = m_pCanvas->GetBestSize();
949 if (sizeWindow.x > sizeBest.x || sizeWindow.y > sizeBest.y)
950 m_pFrame->SetClientSize (sizeBest);
953 dc->DrawBitmap(m_bitmap, 0, 0, false);
955 int xCursor, yCursor;
956 if (m_pCanvas->GetCurrentCursor (xCursor, yCursor))
957 m_pCanvas->DrawRubberBandCursor (*dc, xCursor, yCursor);
962 ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
964 const ImageFile& rIF = GetDocument()->getImageFile();
965 ImageFileArrayConst v = rIF.getArray();
968 if (v != NULL && nx != 0 && ny != 0) {
969 if (! m_bMinSpecified || ! m_bMaxSpecified) {
971 rIF.getMinMax (min, max);
972 if (! m_bMinSpecified)
974 if (! m_bMaxSpecified)
977 double scaleWidth = m_dMaxPixel - m_dMinPixel;
979 unsigned char* imageData = new unsigned char [nx * ny * 3];
980 for (int ix = 0; ix < nx; ix++) {
981 for (int iy = 0; iy < ny; iy++) {
982 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
983 int intensity = static_cast<int>(scaleValue + 0.5);
984 intensity = clamp (intensity, 0, 255);
985 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
986 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
989 wxImage image (nx, ny, imageData, true);
990 m_bitmap = image.ConvertToBitmap();
994 ySize = clamp (ySize, 0, 800);
995 m_pFrame->SetClientSize (xSize, ySize);
996 m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20);
997 m_pCanvas->SetBackgroundColour(*wxWHITE);
1001 m_pCanvas->Refresh();
1005 ImageFileView::OnClose (bool deleteWindow)
1007 //GetDocumentManager()->ActivateView (this, false, true);
1008 if (! GetDocument() || ! GetDocument()->Close())
1013 m_pCanvas->setView(NULL);
1016 wxString s(theApp->GetAppName());
1018 m_pFrame->SetTitle(s);
1023 m_pFrame->Destroy();
1025 if (GetDocument() && GetDocument()->getBadFileOpen())
1026 ::wxYield(); // wxWindows bug workaround
1033 ImageFileView::OnExport (wxCommandEvent& event)
1035 ImageFile& rIF = GetDocument()->getImageFile();
1036 ImageFileArrayConst v = rIF.getArray();
1039 if (v != NULL && nx != 0 && ny != 0) {
1040 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1042 rIF.getMinMax (min, max);
1043 if (! m_bMinSpecified)
1045 if (! m_bMaxSpecified)
1049 DialogExportParameters dialogExport (getFrameForChild(), m_iDefaultExportFormatID);
1050 if (dialogExport.ShowModal() == wxID_OK) {
1051 wxString strFormatName (dialogExport.getFormatName ());
1052 m_iDefaultExportFormatID = ImageFile::convertFormatNameToID (strFormatName.c_str());
1055 wxString strWildcard;
1056 if (m_iDefaultExportFormatID == ImageFile::FORMAT_PGM || m_iDefaultExportFormatID == ImageFile::FORMAT_PGMASCII) {
1058 strWildcard = "PGM Files (*.pgm)|*.pgm";
1061 else if (m_iDefaultExportFormatID == ImageFile::FORMAT_PNG || m_iDefaultExportFormatID == ImageFile::FORMAT_PNG16) {
1063 strWildcard = "PNG Files (*.png)|*.png";
1067 const wxString& strFilename = wxFileSelector (wxString("Export Filename"), wxString(""),
1068 wxString(""), strExt, strWildcard, wxOVERWRITE_PROMPT | wxHIDE_READONLY | wxSAVE);
1070 rIF.exportImage (strFormatName.c_str(), strFilename.c_str(), 1, 1, m_dMinPixel, m_dMaxPixel);
1071 *theApp->getLog() << "Exported file " << strFilename << "\n";
1078 ImageFileView::OnScaleSize (wxCommandEvent& event)
1080 ImageFile& rIF = GetDocument()->getImageFile();
1081 unsigned int iOldNX = rIF.nx();
1082 unsigned int iOldNY = rIF.ny();
1084 DialogGetXYSize dialogGetXYSize (getFrameForChild(), "Set New X & Y Dimensions", iOldNX, iOldNY);
1085 if (dialogGetXYSize.ShowModal() == wxID_OK) {
1086 unsigned int iNewNX = dialogGetXYSize.getXSize();
1087 unsigned int iNewNY = dialogGetXYSize.getYSize();
1088 std::ostringstream os;
1089 os << "Scale Size from (" << iOldNX << "," << iOldNY << ") to (" << iNewNX << "," << iNewNY << ")";
1090 ImageFileDocument* pScaledDoc = theApp->newImageDoc();
1092 sys_error (ERR_SEVERE, "Unable to create image file");
1095 ImageFile& rScaledIF = pScaledDoc->getImageFile();
1096 rScaledIF.setArraySize (iNewNX, iNewNY);
1097 rScaledIF.labelsCopy (rIF);
1098 rScaledIF.labelAdd (os.str().c_str());
1099 rIF.scaleImage (rScaledIF);
1100 *theApp->getLog() << os.str().c_str() << "\n";
1101 pScaledDoc->Modify (true);
1102 pScaledDoc->UpdateAllViews (this);
1103 pScaledDoc->getView()->OnUpdate (this, NULL);
1104 pScaledDoc->getView()->getFrame()->Show(true);
1109 ImageFileView::OnPlotRow (wxCommandEvent& event)
1111 int xCursor, yCursor;
1112 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1113 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1117 const ImageFile& rIF = GetDocument()->getImageFile();
1118 ImageFileArrayConst v = rIF.getArray();
1119 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1123 if (v != NULL && yCursor < ny) {
1124 double* pX = new double [nx];
1125 double* pYReal = new double [nx];
1126 double *pYImag = NULL;
1127 double *pYMag = NULL;
1128 if (rIF.isComplex()) {
1129 pYImag = new double [nx];
1130 pYMag = new double [nx];
1132 for (int i = 0; i < nx; i++) {
1134 pYReal[i] = v[i][yCursor];
1135 if (rIF.isComplex()) {
1136 pYImag[i] = vImag[i][yCursor];
1137 pYMag[i] = ::sqrt (v[i][yCursor] * v[i][yCursor] + vImag[i][yCursor] * vImag[i][yCursor]);
1140 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1142 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1144 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1145 std::ostringstream os;
1146 os << "Row " << yCursor;
1147 std::string title("title ");
1149 rPlotFile.addEzsetCommand (title.c_str());
1150 rPlotFile.addEzsetCommand ("xlabel Column");
1151 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1152 rPlotFile.addEzsetCommand ("lxfrac 0");
1153 rPlotFile.addEzsetCommand ("box");
1154 rPlotFile.addEzsetCommand ("grid");
1155 rPlotFile.addEzsetCommand ("curve 1");
1156 rPlotFile.addEzsetCommand ("color 1");
1157 if (rIF.isComplex()) {
1158 rPlotFile.addEzsetCommand ("dash 1");
1159 rPlotFile.addEzsetCommand ("curve 2");
1160 rPlotFile.addEzsetCommand ("color 4");
1161 rPlotFile.addEzsetCommand ("dash 3");
1162 rPlotFile.addEzsetCommand ("curve 3");
1163 rPlotFile.addEzsetCommand ("color 0");
1164 rPlotFile.addEzsetCommand ("solid");
1165 rPlotFile.setCurveSize (4, nx);
1167 rPlotFile.setCurveSize (2, nx);
1168 rPlotFile.addColumn (0, pX);
1169 rPlotFile.addColumn (1, pYReal);
1170 if (rIF.isComplex()) {
1171 rPlotFile.addColumn (2, pYImag);
1172 rPlotFile.addColumn (3, pYMag);
1174 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1175 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1176 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1177 *theApp->getLog() << os.str().c_str() << "\n";
1178 rPlotFile.addDescription (os.str().c_str());
1182 if (rIF.isComplex()) {
1186 pPlotDoc->Modify (true);
1187 pPlotDoc->UpdateAllViews ();
1188 pPlotDoc->getView()->OnUpdate (this, NULL);
1189 pPlotDoc->getView()->getFrame()->Show(true);
1194 ImageFileView::OnPlotCol (wxCommandEvent& event)
1196 int xCursor, yCursor;
1197 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1198 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1202 const ImageFile& rIF = GetDocument()->getImageFile();
1203 ImageFileArrayConst v = rIF.getArray();
1204 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1208 if (v != NULL && xCursor < nx) {
1209 double* pX = new double [ny];
1210 double* pYReal = new double [ny];
1211 double* pYImag = NULL;
1212 double* pYMag = NULL;
1213 if (rIF.isComplex()) {
1214 pYImag = new double [ny];
1215 pYMag = new double [ny];
1217 for (int i = 0; i < ny; i++) {
1219 pYReal[i] = v[xCursor][i];
1220 if (rIF.isComplex()) {
1221 pYImag[i] = vImag[xCursor][i];
1222 pYMag[i] = ::sqrt (v[xCursor][i] * v[xCursor][i] + vImag[xCursor][i] * vImag[xCursor][i]);
1225 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1227 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1229 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1230 std::ostringstream os;
1231 os << "Column " << xCursor;
1232 std::string title("title ");
1234 rPlotFile.addEzsetCommand (title.c_str());
1235 rPlotFile.addEzsetCommand ("xlabel Row");
1236 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1237 rPlotFile.addEzsetCommand ("lxfrac 0");
1238 rPlotFile.addEzsetCommand ("box");
1239 rPlotFile.addEzsetCommand ("grid");
1240 rPlotFile.addEzsetCommand ("curve 1");
1241 rPlotFile.addEzsetCommand ("color 1");
1242 if (rIF.isComplex()) {
1243 rPlotFile.addEzsetCommand ("dash 1");
1244 rPlotFile.addEzsetCommand ("curve 2");
1245 rPlotFile.addEzsetCommand ("color 4");
1246 rPlotFile.addEzsetCommand ("dash 3");
1247 rPlotFile.addEzsetCommand ("curve 3");
1248 rPlotFile.addEzsetCommand ("color 0");
1249 rPlotFile.addEzsetCommand ("solid");
1250 rPlotFile.setCurveSize (4, ny);
1252 rPlotFile.setCurveSize (2, ny);
1253 rPlotFile.addColumn (0, pX);
1254 rPlotFile.addColumn (1, pYReal);
1255 if (rIF.isComplex()) {
1256 rPlotFile.addColumn (2, pYImag);
1257 rPlotFile.addColumn (3, pYMag);
1259 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1260 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1261 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1262 *theApp->getLog() << os.str().c_str() << "\n";
1263 rPlotFile.addDescription (os.str().c_str());
1267 if (rIF.isComplex()) {
1271 pPlotDoc->Modify (true);
1272 pPlotDoc->UpdateAllViews ();
1273 pPlotDoc->getView()->OnUpdate (this, NULL);
1274 pPlotDoc->getView()->getFrame()->Show(true);
1280 ImageFileView::OnPlotFFTRow (wxCommandEvent& event)
1282 int xCursor, yCursor;
1283 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1284 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1288 const ImageFile& rIF = GetDocument()->getImageFile();
1289 ImageFileArrayConst v = rIF.getArray();
1290 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1294 if (v != NULL && yCursor < ny) {
1295 fftw_complex* pcIn = new fftw_complex [nx];
1298 for (i = 0; i < nx; i++) {
1299 pcIn[i].re = v[i][yCursor];
1300 if (rIF.isComplex())
1301 pcIn[i].im = vImag[i][yCursor];
1306 fftw_plan plan = fftw_create_plan (nx, FFTW_FORWARD, FFTW_IN_PLACE);
1307 fftw_one (plan, pcIn, NULL);
1308 fftw_destroy_plan (plan);
1310 double* pX = new double [nx];
1311 double* pYReal = new double [nx];
1312 double* pYImag = new double [nx];
1313 double* pYMag = new double [nx];
1314 for (i = 0; i < nx; i++) {
1316 pYReal[i] = pcIn[i].re;
1317 pYImag[i] = pcIn[i].im;
1318 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1320 Fourier::shuffleFourierToNaturalOrder (pYReal, nx);
1321 Fourier::shuffleFourierToNaturalOrder (pYImag, nx);
1322 Fourier::shuffleFourierToNaturalOrder (pYMag, nx);
1324 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1326 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1328 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1329 std::ostringstream os;
1330 os << "Row " << yCursor;
1331 std::string title("title ");
1333 rPlotFile.addEzsetCommand (title.c_str());
1334 rPlotFile.addEzsetCommand ("xlabel Column");
1335 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1336 rPlotFile.addEzsetCommand ("lxfrac 0");
1337 rPlotFile.addEzsetCommand ("curve 1");
1338 rPlotFile.addEzsetCommand ("color 1");
1339 rPlotFile.addEzsetCommand ("dash 1");
1340 rPlotFile.addEzsetCommand ("curve 2");
1341 rPlotFile.addEzsetCommand ("color 4");
1342 rPlotFile.addEzsetCommand ("dash 3");
1343 rPlotFile.addEzsetCommand ("curve 3");
1344 rPlotFile.addEzsetCommand ("color 0");
1345 rPlotFile.addEzsetCommand ("solid");
1346 rPlotFile.addEzsetCommand ("box");
1347 rPlotFile.addEzsetCommand ("grid");
1348 rPlotFile.setCurveSize (4, nx);
1349 rPlotFile.addColumn (0, pX);
1350 rPlotFile.addColumn (1, pYReal);
1351 rPlotFile.addColumn (2, pYImag);
1352 rPlotFile.addColumn (3, pYMag);
1353 for (int iL = 0; iL < rIF.nLabels(); iL++)
1354 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1355 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1356 *theApp->getLog() << os.str().c_str() << "\n";
1357 rPlotFile.addDescription (os.str().c_str());
1365 pPlotDoc->Modify (true);
1366 pPlotDoc->UpdateAllViews ();
1367 pPlotDoc->getView()->OnUpdate (this, NULL);
1368 pPlotDoc->getView()->getFrame()->Show(true);
1373 ImageFileView::OnPlotFFTCol (wxCommandEvent& event)
1375 int xCursor, yCursor;
1376 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1377 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1381 const ImageFile& rIF = GetDocument()->getImageFile();
1382 ImageFileArrayConst v = rIF.getArray();
1383 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1387 if (v != NULL && xCursor < nx) {
1388 fftw_complex* pcIn = new fftw_complex [ny];
1389 double *pdTemp = new double [ny];
1392 for (i = 0; i < ny; i++)
1393 pdTemp[i] = v[xCursor][i];
1394 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1395 for (i = 0; i < ny; i++)
1396 pcIn[i].re = pdTemp[i];
1398 for (i = 0; i < ny; i++) {
1399 if (rIF.isComplex())
1400 pdTemp[i] = vImag[xCursor][i];
1404 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1405 for (i = 0; i < ny; i++)
1406 pcIn[i].im = pdTemp[i];
1408 fftw_plan plan = fftw_create_plan (ny, FFTW_BACKWARD, FFTW_IN_PLACE);
1409 fftw_one (plan, pcIn, NULL);
1410 fftw_destroy_plan (plan);
1412 double* pX = new double [ny];
1413 double* pYReal = new double [ny];
1414 double* pYImag = new double [ny];
1415 double* pYMag = new double [ny];
1416 for (i = 0; i < ny; i++) {
1418 pYReal[i] = pcIn[i].re;
1419 pYImag[i] = pcIn[i].im;
1420 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1423 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1425 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1427 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1428 std::ostringstream os;
1429 os << "Column " << xCursor;
1430 std::string title("title ");
1432 rPlotFile.addEzsetCommand (title.c_str());
1433 rPlotFile.addEzsetCommand ("xlabel Column");
1434 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1435 rPlotFile.addEzsetCommand ("lxfrac 0");
1436 rPlotFile.addEzsetCommand ("curve 1");
1437 rPlotFile.addEzsetCommand ("color 1");
1438 rPlotFile.addEzsetCommand ("dash 1");
1439 rPlotFile.addEzsetCommand ("curve 2");
1440 rPlotFile.addEzsetCommand ("color 4");
1441 rPlotFile.addEzsetCommand ("dash 3");
1442 rPlotFile.addEzsetCommand ("curve 3");
1443 rPlotFile.addEzsetCommand ("color 0");
1444 rPlotFile.addEzsetCommand ("solid");
1445 rPlotFile.addEzsetCommand ("box");
1446 rPlotFile.addEzsetCommand ("grid");
1447 rPlotFile.setCurveSize (4, ny);
1448 rPlotFile.addColumn (0, pX);
1449 rPlotFile.addColumn (1, pYReal);
1450 rPlotFile.addColumn (2, pYImag);
1451 rPlotFile.addColumn (3, pYMag);
1452 for (int iL = 0; iL < rIF.nLabels(); iL++)
1453 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1454 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1455 *theApp->getLog() << os.str().c_str() << "\n";
1456 rPlotFile.addDescription (os.str().c_str());
1465 pPlotDoc->Modify (true);
1466 pPlotDoc->UpdateAllViews ();
1467 pPlotDoc->getView()->OnUpdate (this, NULL);
1468 pPlotDoc->getView()->getFrame()->Show(true);
1474 ImageFileView::OnCompareCol (wxCommandEvent& event)
1476 int xCursor, yCursor;
1477 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1478 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1482 std::vector<ImageFileDocument*> vecIFDoc;
1483 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1484 if (vecIFDoc.size() == 0) {
1485 wxMessageBox ("No compatible images for Column Comparison", "Error");
1488 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1490 if (dialogGetCompare.ShowModal() == wxID_OK) {
1491 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1492 const ImageFile& rIF = GetDocument()->getImageFile();
1493 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1495 ImageFileArrayConst v1 = rIF.getArray();
1496 ImageFileArrayConst v2 = rCompareIF.getArray();
1500 if (v1 != NULL && xCursor < nx) {
1501 double* pX = new double [ny];
1502 double* pY1 = new double [ny];
1503 double* pY2 = new double [ny];
1504 for (int i = 0; i < ny; i++) {
1506 pY1[i] = v1[xCursor][i];
1507 pY2[i] = v2[xCursor][i];
1509 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1511 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1513 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1514 std::ostringstream os;
1515 os << "Column " << xCursor << " Comparison";
1516 std::string title("title ");
1518 rPlotFile.addEzsetCommand (title.c_str());
1519 rPlotFile.addEzsetCommand ("xlabel Row");
1520 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1521 rPlotFile.addEzsetCommand ("lxfrac 0");
1522 rPlotFile.addEzsetCommand ("curve 1");
1523 rPlotFile.addEzsetCommand ("color 2");
1524 rPlotFile.addEzsetCommand ("curve 2");
1525 rPlotFile.addEzsetCommand ("color 4");
1526 rPlotFile.addEzsetCommand ("dash 5");
1527 rPlotFile.addEzsetCommand ("box");
1528 rPlotFile.addEzsetCommand ("grid");
1529 rPlotFile.setCurveSize (3, ny);
1530 rPlotFile.addColumn (0, pX);
1531 rPlotFile.addColumn (1, pY1);
1532 rPlotFile.addColumn (2, pY2);
1535 for (iL = 0; iL < rIF.nLabels(); iL++) {
1536 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1538 s += rIF.labelGet(iL).getLabelString();
1539 rPlotFile.addDescription (s.c_str());
1541 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1542 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1544 s += rCompareIF.labelGet(iL).getLabelString();
1545 rPlotFile.addDescription (s.c_str());
1547 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1548 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1549 *theApp->getLog() << os.str().c_str() << "\n";
1550 rPlotFile.addDescription (os.str().c_str());
1555 pPlotDoc->Modify (true);
1556 pPlotDoc->UpdateAllViews ();
1557 pPlotDoc->getView()->OnUpdate (this, NULL);
1558 pPlotDoc->getView()->getFrame()->Show(true);
1564 ImageFileView::OnCompareRow (wxCommandEvent& event)
1566 int xCursor, yCursor;
1567 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1568 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1572 std::vector<ImageFileDocument*> vecIFDoc;
1573 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1575 if (vecIFDoc.size() == 0) {
1576 wxMessageBox ("No compatible images for Row Comparison", "Error");
1580 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1582 if (dialogGetCompare.ShowModal() == wxID_OK) {
1583 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1584 const ImageFile& rIF = GetDocument()->getImageFile();
1585 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1587 ImageFileArrayConst v1 = rIF.getArray();
1588 ImageFileArrayConst v2 = rCompareIF.getArray();
1592 if (v1 != NULL && yCursor < ny) {
1593 double* pX = new double [nx];
1594 double* pY1 = new double [nx];
1595 double* pY2 = new double [nx];
1596 for (int i = 0; i < nx; i++) {
1598 pY1[i] = v1[i][yCursor];
1599 pY2[i] = v2[i][yCursor];
1601 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1603 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1605 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1606 std::ostringstream os;
1607 os << "Row " << yCursor << " Comparison";
1608 std::string title("title ");
1610 rPlotFile.addEzsetCommand (title.c_str());
1611 rPlotFile.addEzsetCommand ("xlabel Column");
1612 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1613 rPlotFile.addEzsetCommand ("lxfrac 0");
1614 rPlotFile.addEzsetCommand ("curve 1");
1615 rPlotFile.addEzsetCommand ("color 2");
1616 rPlotFile.addEzsetCommand ("curve 2");
1617 rPlotFile.addEzsetCommand ("color 4");
1618 rPlotFile.addEzsetCommand ("dash 5");
1619 rPlotFile.addEzsetCommand ("box");
1620 rPlotFile.addEzsetCommand ("grid");
1621 rPlotFile.setCurveSize (3, nx);
1622 rPlotFile.addColumn (0, pX);
1623 rPlotFile.addColumn (1, pY1);
1624 rPlotFile.addColumn (2, pY2);
1626 for (iL = 0; iL < rIF.nLabels(); iL++) {
1627 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1629 s += rIF.labelGet(iL).getLabelString();
1630 rPlotFile.addDescription (s.c_str());
1632 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1633 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1635 s += rCompareIF.labelGet(iL).getLabelString();
1636 rPlotFile.addDescription (s.c_str());
1638 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1639 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1640 *theApp->getLog() << os.str().c_str() << "\n";
1641 rPlotFile.addDescription (os.str().c_str());
1646 pPlotDoc->Modify (true);
1647 pPlotDoc->UpdateAllViews ();
1648 pPlotDoc->getView()->OnUpdate (this, NULL);
1649 pPlotDoc->getView()->getFrame()->Show(true);
1654 static int NUMBER_HISTOGRAM_BINS = 256;
1657 ImageFileView::OnPlotHistogram (wxCommandEvent& event)
1659 const ImageFile& rIF = GetDocument()->getImageFile();
1660 ImageFileArrayConst v = rIF.getArray();
1664 if (v != NULL && nx > 0 && ny > 0) {
1665 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1667 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1671 double* pX = new double [NUMBER_HISTOGRAM_BINS];
1672 double* pY = new double [NUMBER_HISTOGRAM_BINS];
1674 rIF.getMinMax (dMin, dMax);
1675 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
1677 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
1678 pX[i] = dMin + (i + 0.5) * dBinWidth;
1681 for (int ix = 0; ix < nx; ix++)
1682 for (int iy = 0; iy < ny; iy++) {
1683 int iBin = nearest<int> ((v[ix][iy] - dMin) / dBinWidth);
1684 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
1688 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1689 std::ostringstream os;
1691 std::string title("title ");
1693 rPlotFile.addEzsetCommand (title.c_str());
1694 rPlotFile.addEzsetCommand ("xlabel Pixel Value");
1695 rPlotFile.addEzsetCommand ("ylabel Count");
1696 rPlotFile.addEzsetCommand ("box");
1697 rPlotFile.addEzsetCommand ("grid");
1698 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
1699 rPlotFile.addColumn (0, pX);
1700 rPlotFile.addColumn (1, pY);
1701 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++) {
1702 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1704 s += rIF.labelGet(iL).getLabelString();
1705 rPlotFile.addDescription (s.c_str());
1707 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1708 *theApp->getLog() << os.str().c_str() << "\n";
1709 rPlotFile.addDescription (os.str().c_str());
1712 pPlotDoc->Modify (true);
1713 pPlotDoc->UpdateAllViews ();
1714 pPlotDoc->getView()->OnUpdate (this, NULL);
1715 pPlotDoc->getView()->getFrame()->Show(true);
1722 PhantomCanvas::PhantomCanvas (PhantomFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1723 : wxScrolledWindow(frame, -1, pos, size, style)
1728 PhantomCanvas::~PhantomCanvas ()
1734 PhantomCanvas::OnDraw (wxDC& dc)
1737 m_pView->OnDraw(& dc);
1743 IMPLEMENT_DYNAMIC_CLASS(PhantomFileView, wxView)
1745 BEGIN_EVENT_TABLE(PhantomFileView, wxView)
1746 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomFileView::OnProperties)
1747 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomFileView::OnRasterize)
1748 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomFileView::OnProjections)
1751 PhantomFileView::PhantomFileView()
1752 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0)
1754 #if defined(DEBUG) || defined(_DEBUG)
1755 m_iDefaultNDet = 165;
1756 m_iDefaultNView = 180;
1758 m_iDefaultNDet = 367;
1759 m_iDefaultNView = 320;
1761 m_iDefaultNSample = 1;
1762 m_dDefaultRotation = 1;
1763 m_dDefaultFocalLength = 2;
1764 m_dDefaultFieldOfView = 1;
1765 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
1766 m_iDefaultTrace = Trace::TRACE_NONE;
1769 m_iDefaultRasterNX = 115;
1770 m_iDefaultRasterNY = 115;
1771 m_iDefaultRasterNSamples = 1;
1773 m_iDefaultRasterNX = 256;
1774 m_iDefaultRasterNY = 256;
1775 m_iDefaultRasterNSamples = 2;
1779 PhantomFileView::~PhantomFileView()
1781 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
1782 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
1786 PhantomFileView::OnProperties (wxCommandEvent& event)
1788 const int idPhantom = GetDocument()->getPhantomID();
1789 const wxString& namePhantom = GetDocument()->getPhantomName();
1790 std::ostringstream os;
1791 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")" << "\n";
1792 const Phantom& rPhantom = GetDocument()->getPhantom();
1793 rPhantom.printDefinitions (os);
1795 rPhantom.print (os);
1797 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
1798 wxMessageBox (os.str().c_str(), "Phantom Properties");
1803 PhantomFileView::OnProjections (wxCommandEvent& event)
1805 DialogGetProjectionParameters dialogProjection (getFrameForChild(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView, m_iDefaultGeometry, m_iDefaultTrace);
1806 int retVal = dialogProjection.ShowModal();
1807 if (retVal == wxID_OK) {
1808 m_iDefaultNDet = dialogProjection.getNDet();
1809 m_iDefaultNView = dialogProjection.getNView();
1810 m_iDefaultNSample = dialogProjection.getNSamples();
1811 m_iDefaultTrace = dialogProjection.getTrace();
1812 m_dDefaultRotation = dialogProjection.getRotAngle();
1813 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
1814 m_dDefaultFieldOfView = dialogProjection.getFieldOfViewRatio();
1815 wxString sGeometry = dialogProjection.getGeometry();
1816 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
1818 if (m_iDefaultNDet > 0 && m_iDefaultNView > 0 && sGeometry != "") {
1819 const Phantom& rPhantom = GetDocument()->getPhantom();
1820 Projections* pProj = new Projections;
1821 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample,
1822 m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView);
1823 if (theScanner.fail()) {
1824 *theApp->getLog() << "Failed making scanner: " << theScanner.failMessage().c_str() << "\n";
1827 pProj->initFromScanner (theScanner);
1828 m_dDefaultRotation /= PI; // convert back to PI units
1831 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
1832 ProjectionsDialog dialogProjections (theScanner, *pProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(getFrameForChild()));
1833 for (int iView = 0; iView < pProj->nView(); iView++) {
1835 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
1840 while (dialogProjections.isPaused()) {
1846 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), pProj->nView() + 1, getFrameForChild(), wxPD_CAN_ABORT);
1847 for (int i = 0; i < pProj->nView(); i++) {
1848 theScanner.collectProjections (*pProj, rPhantom, i, 1, true, m_iDefaultTrace);
1849 if (! dlgProgress.Update (i+1)) {
1856 std::ostringstream os;
1857 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();
1858 pProj->setCalcTime (timer.timerEnd());
1859 pProj->setRemark (os.str());
1860 *theApp->getLog() << os.str().c_str() << "\n";
1863 ProjectionFileDocument* pProjectionDoc = theApp->newProjectionDoc();
1864 if (! pProjectionDoc) {
1865 sys_error (ERR_SEVERE, "Unable to create projection document");
1868 pProjectionDoc->setProjections (pProj);
1869 ProjectionFileView* projView = pProjectionDoc->getView();
1871 projView->OnUpdate (projView, NULL);
1872 if (projView->getCanvas())
1873 projView->getCanvas()->SetClientSize (m_iDefaultNDet, m_iDefaultNView);
1874 if (wxFrame* pFrame = projView->getFrame()) {
1879 GetDocumentManager()->ActivateView (projView, true, false);
1882 pProjectionDoc-> Modify(true);
1883 pProjectionDoc->UpdateAllViews (this);
1890 PhantomFileView::OnRasterize (wxCommandEvent& event)
1892 DialogGetRasterParameters dialogRaster (getFrameForChild(), m_iDefaultRasterNX, m_iDefaultRasterNY, m_iDefaultRasterNSamples);
1893 int retVal = dialogRaster.ShowModal();
1894 if (retVal == wxID_OK) {
1895 m_iDefaultRasterNX = dialogRaster.getXSize();
1896 m_iDefaultRasterNY = dialogRaster.getYSize();
1897 m_iDefaultRasterNSamples = dialogRaster.getNSamples();
1898 if (m_iDefaultRasterNSamples < 1)
1899 m_iDefaultRasterNSamples = 1;
1900 if (m_iDefaultRasterNX > 0 && m_iDefaultRasterNY > 0) {
1901 const Phantom& rPhantom = GetDocument()->getPhantom();
1903 ImageFile* pImageFile = new ImageFile;
1905 pImageFile->setArraySize (m_iDefaultRasterNX, m_iDefaultRasterNY);
1906 wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"),
1907 pImageFile->nx() + 1, getFrameForChild(), wxPD_CAN_ABORT);
1909 for (unsigned int i = 0; i < pImageFile->nx(); i++) {
1910 rPhantom.convertToImagefile (*pImageFile, m_iDefaultRasterNSamples, Trace::TRACE_NONE, i, 1, true);
1911 if (! dlgProgress.Update (i+1)) {
1917 ImageFileDocument* pRasterDoc = theApp->newImageDoc();
1919 sys_error (ERR_SEVERE, "Unable to create image file");
1922 pRasterDoc->setImageFile (pImageFile);
1924 pRasterDoc->Modify (true);
1925 pRasterDoc->UpdateAllViews (this);
1926 pRasterDoc->getView()->getFrame()->Show(true);
1927 std::ostringstream os;
1928 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << m_iDefaultRasterNX << ", YSize="
1929 << m_iDefaultRasterNY << ", nSamples=" << m_iDefaultRasterNSamples;
1930 *theApp->getLog() << os.str().c_str() << "\n";
1931 pImageFile->labelAdd (os.str().c_str(), timer.timerEnd());
1932 ImageFileView* rasterView = pRasterDoc->getView();
1934 rasterView->getFrame()->SetFocus();
1935 rasterView->OnUpdate (rasterView, NULL);
1944 PhantomFileView::CreateCanvas (wxFrame *parent)
1946 PhantomCanvas* pCanvas;
1948 parent->GetClientSize(&width, &height);
1950 pCanvas = new PhantomCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
1952 pCanvas->SetBackgroundColour(*wxWHITE);
1963 PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view)
1966 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
1968 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
1970 theApp->setIconForFrame (subframe);
1972 wxMenu *m_pFileMenu = new wxMenu;
1974 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
1975 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
1976 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
1977 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
1978 m_pFileMenu->Append(wxID_CLOSE, "&Close");
1980 m_pFileMenu->AppendSeparator();
1981 m_pFileMenu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties");
1983 m_pFileMenu->AppendSeparator();
1984 m_pFileMenu->Append(wxID_PRINT, "&Print...");
1985 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
1986 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
1988 m_pFileMenu->AppendSeparator();
1989 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
1991 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
1992 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
1994 wxMenu *process_menu = new wxMenu;
1995 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...\tCtrl-R");
1996 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...\tCtrl-J");
1998 wxMenu *help_menu = new wxMenu;
1999 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2000 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
2001 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2003 wxMenuBar *menu_bar = new wxMenuBar;
2005 menu_bar->Append(m_pFileMenu, "&File");
2006 menu_bar->Append(process_menu, "&Process");
2007 menu_bar->Append(help_menu, "&Help");
2009 subframe->SetMenuBar(menu_bar);
2010 subframe->Centre(wxBOTH);
2012 wxAcceleratorEntry accelEntries[8];
2013 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
2014 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
2015 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
2016 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
2017 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
2018 accelEntries[5].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
2019 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('J'), PHMMENU_PROCESS_PROJECTIONS);
2020 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('R'), PHMMENU_PROCESS_RASTERIZE);
2021 wxAcceleratorTable accelTable (8, accelEntries);
2022 subframe->SetAcceleratorTable (accelTable);
2029 PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2031 m_pFrame = CreateChildFrame(doc, this);
2035 m_pFrame->GetClientSize(&width, &height);
2036 m_pFrame->SetTitle("PhantomFileView");
2037 m_pCanvas = CreateCanvas (m_pFrame);
2040 int x, y; // X requires a forced resize
2041 m_pFrame->GetSize(&x, &y);
2042 m_pFrame->SetSize(-1, -1, x, y);
2045 m_pFrame->Show(true);
2052 PhantomFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2055 m_pCanvas->Refresh();
2059 PhantomFileView::OnClose (bool deleteWindow)
2061 //GetDocumentManager()->ActivateView (this, false, true);
2062 if (! GetDocument() || ! GetDocument()->Close())
2067 m_pCanvas->setView(NULL);
2070 wxString s(wxTheApp->GetAppName());
2072 m_pFrame->SetTitle(s);
2079 if (GetDocument() && GetDocument()->getBadFileOpen())
2080 ::wxYield(); // wxWindows bug workaround
2087 PhantomFileView::OnDraw (wxDC* dc)
2090 m_pCanvas->GetClientSize (&xsize, &ysize);
2091 SGPDriver driver (dc, xsize, ysize);
2093 const Phantom& rPhantom = GetDocument()->getPhantom();
2094 sgp.setColor (C_RED);
2095 rPhantom.show (sgp);
2100 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2101 : wxScrolledWindow(frame, -1, pos, size, style)
2106 ProjectionFileCanvas::~ProjectionFileCanvas ()
2112 ProjectionFileCanvas::OnDraw(wxDC& dc)
2115 m_pView->OnDraw(& dc);
2119 ProjectionFileCanvas::GetBestSize () const
2123 Projections& rProj = m_pView->GetDocument()->getProjections();
2124 best.Set (rProj.nDet(), rProj.nView());
2131 // ProjectionFileView
2133 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
2135 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
2136 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
2137 EVT_MENU(PJMENU_RECONSTRUCT_FBP, ProjectionFileView::OnReconstructFBP)
2138 EVT_MENU(PJMENU_CONVERT_POLAR, ProjectionFileView::OnConvertPolar)
2139 EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
2142 ProjectionFileView::ProjectionFileView()
2143 : wxView(), m_pCanvas(NULL), m_pFrame(NULL), m_pFileMenu(0)
2153 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
2154 m_dDefaultFilterParam = 1.;
2156 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
2157 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
2159 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
2160 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
2162 m_iDefaultZeropad = 1;
2163 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF3;
2164 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
2165 m_iDefaultInterpParam = 1;
2166 m_iDefaultTrace = Trace::TRACE_NONE;
2168 m_iDefaultPolarNX = 256;
2169 m_iDefaultPolarNY = 256;
2170 m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR;
2171 m_iDefaultPolarZeropad = 1;
2174 ProjectionFileView::~ProjectionFileView()
2176 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2177 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2181 ProjectionFileView::OnProperties (wxCommandEvent& event)
2183 const Projections& rProj = GetDocument()->getProjections();
2184 std::ostringstream os;
2185 rProj.printScanInfo(os);
2186 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2187 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
2188 dialogMsg.ShowModal();
2193 ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
2195 Projections& rProj = GetDocument()->getProjections();
2196 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2197 m_iDefaultPolarInterpolation, -1);
2198 if (dialogPolar.ShowModal() == wxID_OK) {
2199 wxString strInterpolation (dialogPolar.getInterpolationName());
2200 m_iDefaultPolarNX = dialogPolar.getXSize();
2201 m_iDefaultPolarNY = dialogPolar.getYSize();
2202 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2203 ImageFile& rIF = pPolarDoc->getImageFile();
2205 sys_error (ERR_SEVERE, "Unable to create image file");
2208 rIF.setArraySize (m_iDefaultPolarNX, m_iDefaultPolarNY);
2209 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2210 rProj.convertPolar (rIF, m_iDefaultPolarInterpolation);
2211 rIF.labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2212 std::ostringstream os;
2213 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to polar image: xSize="
2214 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2215 << strInterpolation.c_str();
2216 *theApp->getLog() << os.str().c_str() << "\n";
2217 rIF.labelAdd (os.str().c_str());
2218 pPolarDoc->Modify (true);
2219 pPolarDoc->UpdateAllViews ();
2220 pPolarDoc->getView()->OnUpdate (this, NULL);
2221 pPolarDoc->getView()->getFrame()->Show(true);
2226 ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
2228 Projections& rProj = GetDocument()->getProjections();
2229 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert to FFT Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2230 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad);
2231 if (dialogPolar.ShowModal() == wxID_OK) {
2232 wxString strInterpolation (dialogPolar.getInterpolationName());
2233 m_iDefaultPolarNX = dialogPolar.getXSize();
2234 m_iDefaultPolarNY = dialogPolar.getYSize();
2235 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2236 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2237 ImageFile& rIF = pPolarDoc->getImageFile();
2239 sys_error (ERR_SEVERE, "Unable to create image file");
2242 rIF.setArraySize (m_iDefaultPolarNX, m_iDefaultPolarNY);
2243 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2244 rProj.convertFFTPolar (rIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad);
2245 rIF.labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2246 std::ostringstream os;
2247 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to FFT polar image: xSize="
2248 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2249 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2250 *theApp->getLog() << os.str().c_str() << "\n";
2251 rIF.labelAdd (os.str().c_str());
2252 pPolarDoc->Modify (true);
2253 pPolarDoc->UpdateAllViews ();
2254 pPolarDoc->getView()->OnUpdate (this, NULL);
2255 pPolarDoc->getView()->getFrame()->Show(true);
2260 ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
2262 wxMessageBox ("Fourier Reconstruction is not yet supported", "Unimplemented function");
2266 ProjectionFileView::OnReconstructFBP (wxCommandEvent& event)
2268 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);
2270 int retVal = dialogReconstruction.ShowModal();
2271 if (retVal == wxID_OK) {
2272 m_iDefaultNX = dialogReconstruction.getXSize();
2273 m_iDefaultNY = dialogReconstruction.getYSize();
2274 wxString optFilterName = dialogReconstruction.getFilterName();
2275 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
2276 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
2277 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
2278 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
2279 m_iDefaultZeropad = dialogReconstruction.getZeropad();
2280 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
2281 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
2282 wxString optInterpName = dialogReconstruction.getInterpName();
2283 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
2284 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
2285 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
2286 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
2287 m_iDefaultTrace = dialogReconstruction.getTrace();
2288 if (m_iDefaultNX > 0 && m_iDefaultNY > 0) {
2289 const Projections& rProj = GetDocument()->getProjections();
2291 ImageFile* pImageFile = new ImageFile;
2292 pImageFile->setArraySize (m_iDefaultNX, m_iDefaultNY);
2294 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);
2297 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2298 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstructor, rProj, *pImageFile, m_iDefaultTrace, getFrameForChild());
2299 for (int iView = 0; iView < rProj.nView(); iView++) {
2301 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView)) {
2302 delete pDlgReconstruct;
2303 delete pReconstructor;
2308 while (pDlgReconstruct->isPaused()) {
2313 delete pDlgReconstruct;
2315 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT);
2316 for (int i = 0; i < rProj.nView(); i++) {
2317 pReconstructor->reconstructView (i, 1);
2318 if (! dlgProgress.Update (i + 1)) {
2319 delete pReconstructor;
2325 delete pReconstructor;
2326 ImageFileDocument* pReconDoc = theApp->newImageDoc();
2328 sys_error (ERR_SEVERE, "Unable to create image file");
2331 pReconDoc->setImageFile (pImageFile);
2332 pReconDoc->Modify (true);
2333 pReconDoc->UpdateAllViews (this);
2334 if (ImageFileView* rasterView = pReconDoc->getView()) {
2335 rasterView->OnUpdate (rasterView, NULL);
2336 rasterView->getFrame()->SetFocus();
2337 rasterView->getFrame()->Show(true);
2339 std::ostringstream os;
2340 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();
2341 *theApp->getLog() << os.str().c_str() << "\n";
2342 pImageFile->labelAdd (rProj.getLabel());
2343 pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd());
2349 ProjectionFileCanvas*
2350 ProjectionFileView::CreateCanvas (wxFrame *parent)
2352 ProjectionFileCanvas* pCanvas;
2354 parent->GetClientSize(&width, &height);
2356 pCanvas = new ProjectionFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
2358 pCanvas->SetScrollbars(20, 20, 50, 50);
2359 pCanvas->SetBackgroundColour(*wxWHITE);
2370 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2373 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2375 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2377 theApp->setIconForFrame (subframe);
2379 wxMenu *m_pFileMenu = new wxMenu;
2381 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2382 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2383 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2384 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2385 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2386 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2388 m_pFileMenu->AppendSeparator();
2389 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
2391 m_pFileMenu->AppendSeparator();
2392 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2393 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2394 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2396 m_pFileMenu->AppendSeparator();
2397 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2399 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2400 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2402 wxMenu *convert_menu = new wxMenu;
2403 convert_menu->Append (PJMENU_CONVERT_POLAR, "&Polar Image...\tCtrl-L");
2404 convert_menu->Append (PJMENU_CONVERT_FFT_POLAR, "&FFT->Polar Image...\tCtrl-I");
2406 wxMenu *reconstruct_menu = new wxMenu;
2407 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP, "&Filtered Backprojection...\tCtrl-R", "Reconstruct image using filtered backprojection");
2408 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Fourier...\tCtrl-E", "Reconstruct image using inverse Fourier");
2409 reconstruct_menu->Enable (PJMENU_RECONSTRUCT_FOURIER, false);
2411 wxMenu *help_menu = new wxMenu;
2412 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2413 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
2414 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2416 wxMenuBar *menu_bar = new wxMenuBar;
2418 menu_bar->Append (m_pFileMenu, "&File");
2419 menu_bar->Append (convert_menu, "&Convert");
2420 menu_bar->Append (reconstruct_menu, "&Reconstruct");
2421 menu_bar->Append (help_menu, "&Help");
2423 subframe->SetMenuBar(menu_bar);
2424 subframe->Centre(wxBOTH);
2426 wxAcceleratorEntry accelEntries[11];
2427 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
2428 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
2429 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
2430 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
2431 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
2432 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
2433 accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
2434 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('L'), PJMENU_CONVERT_POLAR);
2435 accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('I'), PJMENU_CONVERT_FFT_POLAR);
2436 accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('R'), PJMENU_RECONSTRUCT_FBP);
2437 accelEntries[10].Set (wxACCEL_CTRL, static_cast<int>('E'), PJMENU_RECONSTRUCT_FOURIER);
2438 wxAcceleratorTable accelTable (11, accelEntries);
2439 subframe->SetAcceleratorTable (accelTable);
2446 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2448 m_pFrame = CreateChildFrame(doc, this);
2452 m_pFrame->GetClientSize (&width, &height);
2453 m_pFrame->SetTitle ("ProjectionFileView");
2454 m_pCanvas = CreateCanvas (m_pFrame);
2457 int x, y; // X requires a forced resize
2458 m_pFrame->GetSize(&x, &y);
2459 m_pFrame->SetSize(-1, -1, x, y);
2462 m_pFrame->Show(true);
2469 ProjectionFileView::OnDraw (wxDC* dc)
2471 wxSize clientSize = m_pFrame->GetClientSize();
2472 wxSize bestSize = m_pCanvas->GetBestSize();
2474 if (clientSize.x > bestSize.x || clientSize.y > bestSize.y)
2475 m_pFrame->SetClientSize (bestSize);
2478 dc->DrawBitmap (m_bitmap, 0, 0, false);
2483 ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2485 const Projections& rProj = GetDocument()->getProjections();
2486 const int nDet = rProj.nDet();
2487 const int nView = rProj.nView();
2488 if (nDet != 0 && nView != 0) {
2489 const DetectorArray& detarray = rProj.getDetectorArray(0);
2490 const DetectorValue* detval = detarray.detValues();
2491 double min = detval[0];
2492 double max = detval[0];
2493 for (int iy = 0; iy < nView; iy++) {
2494 const DetectorArray& detarray = rProj.getDetectorArray(iy);
2495 const DetectorValue* detval = detarray.detValues();
2496 for (int ix = 0; ix < nDet; ix++) {
2497 if (min > detval[ix])
2499 else if (max < detval[ix])
2504 unsigned char* imageData = new unsigned char [nDet * nView * 3];
2505 double scale = (max - min) / 255;
2506 for (int iy2 = 0; iy2 < nView; iy2++) {
2507 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
2508 const DetectorValue* detval = detarray.detValues();
2509 for (int ix = 0; ix < nDet; ix++) {
2510 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
2511 intensity = clamp(intensity, 0, 255);
2512 int baseAddr = (iy2 * nDet + ix) * 3;
2513 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
2516 wxImage image (nDet, nView, imageData, true);
2517 m_bitmap = image.ConvertToBitmap();
2521 xSize = clamp (xSize, 0, 800);
2522 ySize = clamp (ySize, 0, 800);
2523 m_pFrame->SetClientSize (xSize, ySize);
2524 m_pCanvas->SetScrollbars (20, 20, nDet/20, nView/20);
2528 m_pCanvas->Refresh();
2532 ProjectionFileView::OnClose (bool deleteWindow)
2534 //GetDocumentManager()->ActivateView (this, false, true);
2535 if (! GetDocument() || ! GetDocument()->Close())
2540 m_pCanvas->setView(NULL);
2543 wxString s(wxTheApp->GetAppName());
2545 m_pFrame->SetTitle(s);
2552 if (GetDocument() && GetDocument()->getBadFileOpen())
2553 ::wxYield(); // wxWindows bug workaround
2562 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2563 : wxScrolledWindow(frame, -1, pos, size, style)
2568 PlotFileCanvas::~PlotFileCanvas ()
2574 PlotFileCanvas::OnDraw(wxDC& dc)
2577 m_pView->OnDraw(& dc);
2583 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
2585 BEGIN_EVENT_TABLE(PlotFileView, wxView)
2586 EVT_MENU(PJMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
2587 EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
2588 EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
2589 EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
2592 PlotFileView::PlotFileView()
2593 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pEZPlot(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
2597 PlotFileView::~PlotFileView()
2602 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2606 PlotFileView::OnProperties (wxCommandEvent& event)
2608 const PlotFile& rPlot = GetDocument()->getPlotFile();
2609 std::ostringstream os;
2610 os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
2611 rPlot.printHeadersBrief (os);
2612 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<<\n";
2613 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
2614 dialogMsg.ShowModal();
2619 PlotFileView::OnScaleAuto (wxCommandEvent& event)
2621 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2622 double min, max, mean, mode, median, stddev;
2623 rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
2624 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
2625 int iRetVal = dialogAutoScale.ShowModal();
2626 if (iRetVal == wxID_OK) {
2627 m_bMinSpecified = true;
2628 m_bMaxSpecified = true;
2630 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
2633 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
2634 OnUpdate (this, NULL);
2640 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
2642 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2646 if (! m_bMinSpecified || ! m_bMaxSpecified) {
2647 if (! rPlotFile.getMinMax (1, min, max)) {
2648 *theApp->getLog() << "Error: unable to find Min/Max\n";
2653 if (m_bMinSpecified)
2655 if (m_bMaxSpecified)
2658 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Y-axis Minimum & Maximum", min, max);
2659 int retVal = dialogMinMax.ShowModal();
2660 if (retVal == wxID_OK) {
2661 m_bMinSpecified = true;
2662 m_bMaxSpecified = true;
2663 m_dMinPixel = dialogMinMax.getMinimum();
2664 m_dMaxPixel = dialogMinMax.getMaximum();
2665 OnUpdate (this, NULL);
2670 PlotFileView::OnScaleFull (wxCommandEvent& event)
2672 if (m_bMinSpecified || m_bMaxSpecified) {
2673 m_bMinSpecified = false;
2674 m_bMaxSpecified = false;
2675 OnUpdate (this, NULL);
2681 PlotFileView::CreateCanvas (wxFrame* parent)
2683 PlotFileCanvas* pCanvas;
2685 parent->GetClientSize(&width, &height);
2687 pCanvas = new PlotFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
2689 pCanvas->SetBackgroundColour(*wxWHITE);
2700 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2703 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2705 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2707 theApp->setIconForFrame (subframe);
2709 wxMenu *m_pFileMenu = new wxMenu;
2711 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2712 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2713 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2714 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2715 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2716 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2718 m_pFileMenu->AppendSeparator();
2719 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
2721 m_pFileMenu->AppendSeparator();
2722 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2723 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2724 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2726 m_pFileMenu->AppendSeparator();
2727 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2729 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2730 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2732 wxMenu *view_menu = new wxMenu;
2733 view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...\tCtrl-E");
2734 view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
2735 view_menu->Append(PLOTMENU_VIEW_SCALE_FULL, "Display &Full Scale\tCtrl-U");
2737 wxMenu *help_menu = new wxMenu;
2738 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2739 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
2740 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2742 wxMenuBar *menu_bar = new wxMenuBar;
2744 menu_bar->Append(m_pFileMenu, "&File");
2745 menu_bar->Append(view_menu, "&View");
2746 menu_bar->Append(help_menu, "&Help");
2748 subframe->SetMenuBar(menu_bar);
2749 subframe->Centre(wxBOTH);
2751 wxAcceleratorEntry accelEntries[10];
2752 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
2753 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
2754 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
2755 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
2756 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
2757 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
2758 accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
2759 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('E'), PLOTMENU_VIEW_SCALE_MINMAX);
2760 accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('A'), PLOTMENU_VIEW_SCALE_AUTO);
2761 accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('U'), PLOTMENU_VIEW_SCALE_FULL);
2762 wxAcceleratorTable accelTable (10, accelEntries);
2763 subframe->SetAcceleratorTable (accelTable);
2770 PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
2772 m_pFrame = CreateChildFrame(doc, this);
2775 m_bMinSpecified = false;
2776 m_bMaxSpecified = false;
2777 m_dAutoScaleFactor = 1.;
2780 m_pFrame->GetClientSize(&width, &height);
2781 m_pFrame->SetTitle ("Plot File");
2782 m_pCanvas = CreateCanvas (m_pFrame);
2785 int x, y; // X requires a forced resize
2786 m_pFrame->GetSize(&x, &y);
2787 m_pFrame->SetSize(-1, -1, x, y);
2790 m_pFrame->Show(true);
2797 PlotFileView::OnDraw (wxDC* dc)
2799 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2800 const int iNColumns = rPlotFile.getNumColumns();
2801 const int iNRecords = rPlotFile.getNumRecords();
2803 if (iNColumns > 0 && iNRecords > 0) {
2805 m_pCanvas->GetClientSize (&xsize, &ysize);
2806 SGPDriver driver (dc, xsize, ysize);
2809 m_pEZPlot->plot (&sgp);
2815 PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2817 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2818 const int iNColumns = rPlotFile.getNumColumns();
2819 const int iNRecords = rPlotFile.getNumRecords();
2821 if (iNColumns > 0 && iNRecords > 0) {
2824 m_pEZPlot = new EZPlot;
2826 for (unsigned int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)
2827 m_pEZPlot->ezset (rPlotFile.getEzsetCommand (iEzset));
2829 if (m_bMinSpecified) {
2830 std::ostringstream os;
2831 os << "ymin " << m_dMinPixel;
2832 m_pEZPlot->ezset (os.str());
2835 if (m_bMaxSpecified) {
2836 std::ostringstream os;
2837 os << "ymax " << m_dMaxPixel;
2838 m_pEZPlot->ezset (os.str());
2841 m_pEZPlot->ezset("box");
2842 m_pEZPlot->ezset("grid");
2844 double* pdXaxis = new double [iNRecords];
2845 rPlotFile.getColumn (0, pdXaxis);
2847 double* pdY = new double [iNRecords];
2848 for (int iCol = 1; iCol < iNColumns; iCol++) {
2849 rPlotFile.getColumn (iCol, pdY);
2850 m_pEZPlot->addCurve (pdXaxis, pdY, iNRecords);
2858 m_pCanvas->Refresh();
2862 PlotFileView::OnClose (bool deleteWindow)
2864 //GetDocumentManager()->ActivateView (this, false, true);
2865 if (! GetDocument() || ! GetDocument()->Close())
2870 m_pCanvas->setView (NULL);
2873 wxString s(wxTheApp->GetAppName());
2875 m_pFrame->SetTitle(s);
2881 if (GetDocument() && GetDocument()->getBadFileOpen())
2882 ::wxYield(); // wxWindows bug workaround
2889 ////////////////////////////////////////////////////////////////
2892 IMPLEMENT_DYNAMIC_CLASS(TextFileView, wxView)
2894 TextFileView::~TextFileView()
2896 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2897 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2900 bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2902 m_pFrame = CreateChildFrame(doc, this);
2903 SetFrame (m_pFrame);
2906 m_pFrame->GetClientSize(&width, &height);
2907 m_pFrame->SetTitle("TextFile");
2908 m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
2909 m_pFrame->SetTitle("Log");
2912 // X seems to require a forced resize
2914 frame->GetSize(&x, &y);
2915 frame->SetSize(-1, -1, x, y);
2918 m_pFrame->Show (true);
2924 // Handled by wxTextWindow
2925 void TextFileView::OnDraw(wxDC *WXUNUSED(dc) )
2929 void TextFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2934 TextFileView::OnClose (bool deleteWindow)
2936 if (! theApp->getMainFrame()->getShuttingDown())
2940 //GetDocumentManager()->ActivateView (this, false, true);
2941 if (! GetDocument() || ! GetDocument()->Close())
2948 if (GetDocument() && GetDocument()->getBadFileOpen())
2949 ::wxYield(); // wxWindows bug workaround
2960 TextFileView::CreateChildFrame (wxDocument *doc, wxView *view)
2963 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(0,0), wxDEFAULT_FRAME_STYLE, "Log");
2965 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE, "Log");
2967 theApp->setIconForFrame (subframe);
2969 wxMenu *m_pFileMenu = new wxMenu;
2971 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2972 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2973 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2974 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2975 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2976 // m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2978 m_pFileMenu->AppendSeparator();
2979 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2980 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2981 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2983 m_pFileMenu->AppendSeparator();
2984 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2986 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2987 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2989 wxMenu *help_menu = new wxMenu;
2990 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2991 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
2992 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2994 wxMenuBar *menu_bar = new wxMenuBar;
2996 menu_bar->Append(m_pFileMenu, "&File");
2997 menu_bar->Append(help_menu, "&Help");
2999 subframe->SetMenuBar(menu_bar);
3000 subframe->Centre(wxBOTH);
3002 wxAcceleratorEntry accelEntries[5];
3003 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
3004 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
3005 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
3006 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
3007 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
3008 wxAcceleratorTable accelTable (5, accelEntries);
3009 subframe->SetAcceleratorTable (accelTable);
3015 // Define a constructor for my text subwindow
3016 TextFileCanvas::TextFileCanvas (TextFileView* v, wxFrame* frame, const wxPoint& pos, const wxSize& size, long style)
3017 : wxTextCtrl (frame, -1, "", pos, size, style), m_pView(v)
3021 TextFileCanvas::~TextFileCanvas ()