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-2000 Kevin Rosenberg
12 ** $Id: views.cpp,v 1.82 2001/01/28 03:48:55 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)
71 ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
72 : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v), m_xCursor(-1), m_yCursor(-1)
76 ImageFileCanvas::~ImageFileCanvas()
82 ImageFileCanvas::OnDraw(wxDC& dc)
85 m_pView->OnDraw(& dc);
89 ImageFileCanvas::DrawRubberBandCursor (wxDC& dc, int x, int y)
91 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
96 dc.SetLogicalFunction (wxINVERT);
97 dc.SetPen (*wxGREEN_PEN);
98 dc.DrawLine (0, yPt, nx, yPt);
99 dc.DrawLine (x, 0, x, ny);
100 dc.SetLogicalFunction (wxCOPY);
104 ImageFileCanvas::GetCurrentCursor (int& x, int& y)
109 if (m_xCursor >= 0 && m_yCursor >= 0)
116 ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
124 wxPoint pt(event.GetLogicalPosition(dc));
126 const ImageFileDocument* pIFDoc = m_pView->GetDocument();
129 const ImageFile& rIF = pIFDoc->getImageFile();
130 ImageFileArrayConst v = rIF.getArray();
133 const int yPt = ny - 1 - pt.y;
134 if (event.RightIsDown()) {
135 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
136 std::ostringstream os;
137 os << "Image value (" << pt.x << "," << yPt << ") = " << v[pt.x][yPt];
138 if (rIF.isComplex()) {
139 double dImag = rIF.getImaginaryArray()[pt.x][yPt];
141 os << " - " << -dImag;
143 os << " + " << dImag;
147 *theApp->getLog() << os.str().c_str();
149 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
151 else if (event.LeftIsDown() || event.LeftUp() || event.RightUp()) {
152 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
153 if (m_xCursor >= 0 && m_yCursor >= 0) {
154 DrawRubberBandCursor (dc, m_xCursor, m_yCursor);
156 DrawRubberBandCursor (dc, pt.x, yPt);
160 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
162 if (event.LeftUp()) {
163 std::ostringstream os;
164 os << "Selected column " << pt.x << " , row " << yPt << "\n";
165 *theApp->getLog() << os.str().c_str();
170 ImageFileCanvas::GetBestSize() const
175 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
176 return wxSize (rIF.nx(), rIF.ny());
182 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
184 BEGIN_EVENT_TABLE(ImageFileView, wxView)
185 EVT_MENU(IFMENU_FILE_EXPORT, ImageFileView::OnExport)
186 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
187 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
188 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
189 EVT_MENU(IFMENU_VIEW_SCALE_FULL, ImageFileView::OnScaleFull)
190 EVT_MENU(IFMENU_COMPARE_IMAGES, ImageFileView::OnCompare)
191 EVT_MENU(IFMENU_COMPARE_ROW, ImageFileView::OnCompareRow)
192 EVT_MENU(IFMENU_COMPARE_COL, ImageFileView::OnCompareCol)
193 EVT_MENU(IFMENU_FILTER_INVERTVALUES, ImageFileView::OnInvertValues)
194 EVT_MENU(IFMENU_FILTER_SQUARE, ImageFileView::OnSquare)
195 EVT_MENU(IFMENU_FILTER_SQRT, ImageFileView::OnSquareRoot)
196 EVT_MENU(IFMENU_FILTER_LOG, ImageFileView::OnLog)
197 EVT_MENU(IFMENU_FILTER_EXP, ImageFileView::OnExp)
198 EVT_MENU(IFMENU_FILTER_FOURIER, ImageFileView::OnFourier)
199 EVT_MENU(IFMENU_FILTER_INVERSE_FOURIER, ImageFileView::OnInverseFourier)
200 EVT_MENU(IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, ImageFileView::OnShuffleFourierToNaturalOrder)
201 EVT_MENU(IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, ImageFileView::OnShuffleNaturalToFourierOrder)
202 EVT_MENU(IFMENU_IMAGE_ADD, ImageFileView::OnAdd)
203 EVT_MENU(IFMENU_IMAGE_SUBTRACT, ImageFileView::OnSubtract)
204 EVT_MENU(IFMENU_IMAGE_MULTIPLY, ImageFileView::OnMultiply)
205 EVT_MENU(IFMENU_IMAGE_DIVIDE, ImageFileView::OnDivide)
206 EVT_MENU(IFMENU_IMAGE_SCALESIZE, ImageFileView::OnScaleSize)
208 EVT_MENU(IFMENU_FILTER_FFT, ImageFileView::OnFFT)
209 EVT_MENU(IFMENU_FILTER_IFFT, ImageFileView::OnIFFT)
210 EVT_MENU(IFMENU_FILTER_FFT_ROWS, ImageFileView::OnFFTRows)
211 EVT_MENU(IFMENU_FILTER_IFFT_ROWS, ImageFileView::OnIFFTRows)
212 EVT_MENU(IFMENU_FILTER_FFT_COLS, ImageFileView::OnFFTCols)
213 EVT_MENU(IFMENU_FILTER_IFFT_COLS, ImageFileView::OnIFFTCols)
215 EVT_MENU(IFMENU_FILTER_MAGNITUDE, ImageFileView::OnMagnitude)
216 EVT_MENU(IFMENU_FILTER_PHASE, ImageFileView::OnPhase)
217 EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)
218 EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol)
220 EVT_MENU(IFMENU_PLOT_FFT_ROW, ImageFileView::OnPlotFFTRow)
221 EVT_MENU(IFMENU_PLOT_FFT_COL, ImageFileView::OnPlotFFTCol)
223 EVT_MENU(IFMENU_PLOT_HISTOGRAM, ImageFileView::OnPlotHistogram)
226 ImageFileView::ImageFileView()
227 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
229 m_iDefaultExportFormatID = ImageFile::FORMAT_PNG;
232 ImageFileView::~ImageFileView()
234 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
235 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
239 ImageFileView::OnProperties (wxCommandEvent& event)
241 const ImageFile& rIF = GetDocument()->getImageFile();
242 if (rIF.nx() == 0 || rIF.ny() == 0)
243 *theApp->getLog() << "Properties: empty imagefile\n";
245 const std::string& rFilename = rIF.getFilename();
246 std::ostringstream os;
247 double min, max, mean, mode, median, stddev;
248 rIF.statistics (rIF.getArray(), min, max, mean, mode, median, stddev);
249 os << "Filename: " << rFilename << "\n";
250 os << "Size: (" << rIF.nx() << "," << rIF.ny() << ")\n";
256 os << "\nMinimum: "<<min<<"\nMaximum: "<<max<<"\nMean: "<<mean<<"\nMedian: "<<median<<"\nMode: "<<mode<<"\nStandard Deviation: "<<stddev << "\n";
257 if (rIF.isComplex()) {
258 rIF.statistics (rIF.getImaginaryArray(), min, max, mean, mode, median, stddev);
259 os << "\nImaginary: min: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
261 if (rIF.nLabels() > 0) {
263 rIF.printLabelsBrief (os);
265 *theApp->getLog() << os.str().c_str();
266 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
267 dialogMsg.ShowModal();
272 ImageFileView::OnScaleAuto (wxCommandEvent& event)
274 const ImageFile& rIF = GetDocument()->getImageFile();
275 double min, max, mean, mode, median, stddev;
276 rIF.statistics(min, max, mean, mode, median, stddev);
277 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
278 int iRetVal = dialogAutoScale.ShowModal();
279 if (iRetVal == wxID_OK) {
280 m_bMinSpecified = true;
281 m_bMaxSpecified = true;
283 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
286 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
287 OnUpdate (this, NULL);
293 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
295 const ImageFile& rIF = GetDocument()->getImageFile();
297 if (! m_bMinSpecified && ! m_bMaxSpecified)
298 rIF.getMinMax (min, max);
305 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Image Minimum & Maximum", min, max);
306 int retVal = dialogMinMax.ShowModal();
307 if (retVal == wxID_OK) {
308 m_bMinSpecified = true;
309 m_bMaxSpecified = true;
310 m_dMinPixel = dialogMinMax.getMinimum();
311 m_dMaxPixel = dialogMinMax.getMaximum();
312 OnUpdate (this, NULL);
317 ImageFileView::OnScaleFull (wxCommandEvent& event)
319 if (m_bMinSpecified || m_bMaxSpecified) {
320 m_bMinSpecified = false;
321 m_bMaxSpecified = false;
322 OnUpdate (this, NULL);
327 ImageFileView::OnCompare (wxCommandEvent& event)
329 std::vector<ImageFileDocument*> vecIF;
330 theApp->getCompatibleImages (GetDocument(), vecIF);
332 if (vecIF.size() == 0) {
333 wxMessageBox("There are no compatible image files open for comparision", "No comparison images");
335 DialogGetComparisonImage dialogGetCompare(getFrameForChild(), "Get Comparison Image", vecIF, true);
337 if (dialogGetCompare.ShowModal() == wxID_OK) {
338 const ImageFile& rIF = GetDocument()->getImageFile();
339 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
340 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
341 std::ostringstream os;
342 double min, max, mean, mode, median, stddev;
343 rIF.statistics (min, max, mean, mode, median, stddev);
344 os << GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
345 rCompareIF.statistics (min, max, mean, mode, median, stddev);
346 os << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
349 rIF.comparativeStatistics (rCompareIF, d, r, e);
350 os << "Comparative Statistics: d=" << d << ", r=" << r << ", e=" << e << "\n";
351 *theApp->getLog() << os.str().c_str();
352 if (dialogGetCompare.getMakeDifferenceImage()) {
353 ImageFileDocument* pDifferenceDoc = theApp->newImageDoc();
354 if (! pDifferenceDoc) {
355 sys_error (ERR_SEVERE, "Unable to create image file");
358 ImageFile& differenceImage = pDifferenceDoc->getImageFile();
360 differenceImage.setArraySize (rIF.nx(), rIF.ny());
361 if (! rIF.subtractImages (rCompareIF, differenceImage)) {
362 pDifferenceDoc->getView()->getFrame()->Close(true);
366 wxString s = GetFrame()->GetTitle() + ": ";
367 differenceImage.labelsCopy (rIF, s.c_str());
368 s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
369 differenceImage.labelsCopy (rCompareIF, s.c_str());
370 std::ostringstream osLabel;
371 osLabel << "Compare image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str()
372 << " and " << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": "
374 differenceImage.labelAdd (os.str().c_str());
375 if (theApp->getSetModifyNewDocs())
376 pDifferenceDoc->Modify(true);
377 pDifferenceDoc->UpdateAllViews(this);
378 pDifferenceDoc->getView()->OnUpdate (this, NULL);
379 pDifferenceDoc->getView()->getFrame()->Show(true);
381 wxMessageBox(os.str().c_str(), "Image Comparison");
387 ImageFileView::OnInvertValues (wxCommandEvent& event)
389 ImageFile& rIF = GetDocument()->getImageFile();
390 rIF.invertPixelValues (rIF);
391 rIF.labelAdd ("Invert Pixel Values");
392 if (theApp->getSetModifyNewDocs())
393 GetDocument()->Modify(TRUE);
394 GetDocument()->UpdateAllViews(this);
398 ImageFileView::OnSquare (wxCommandEvent& event)
400 ImageFile& rIF = GetDocument()->getImageFile();
402 rIF.labelAdd ("Square Pixel Values");
403 if (theApp->getSetModifyNewDocs())
404 GetDocument()->Modify(TRUE);
405 GetDocument()->UpdateAllViews(this);
409 ImageFileView::OnSquareRoot (wxCommandEvent& event)
411 ImageFile& rIF = GetDocument()->getImageFile();
413 rIF.labelAdd ("Square-root Pixel Values");
414 if (theApp->getSetModifyNewDocs())
415 GetDocument()->Modify(TRUE);
416 GetDocument()->UpdateAllViews(this);
420 ImageFileView::OnLog (wxCommandEvent& event)
422 ImageFile& rIF = GetDocument()->getImageFile();
424 rIF.labelAdd ("Logrithm base-e Pixel Values");
425 if (theApp->getSetModifyNewDocs())
426 GetDocument()->Modify(TRUE);
427 GetDocument()->UpdateAllViews(this);
431 ImageFileView::OnExp (wxCommandEvent& event)
433 ImageFile& rIF = GetDocument()->getImageFile();
435 rIF.labelAdd ("Exponent base-e Pixel Values");
436 if (theApp->getSetModifyNewDocs())
437 GetDocument()->Modify(TRUE);
438 GetDocument()->UpdateAllViews(this);
442 ImageFileView::OnAdd (wxCommandEvent& event)
444 std::vector<ImageFileDocument*> vecIF;
445 theApp->getCompatibleImages (GetDocument(), vecIF);
447 if (vecIF.size() == 0) {
448 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
450 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Add", vecIF, false);
452 if (dialogGetCompare.ShowModal() == wxID_OK) {
453 ImageFile& rIF = GetDocument()->getImageFile();
454 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
455 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
456 ImageFileDocument* pNewDoc = theApp->newImageDoc();
458 sys_error (ERR_SEVERE, "Unable to create image file");
461 ImageFile& newImage = pNewDoc->getImageFile();
462 newImage.setArraySize (rIF.nx(), rIF.ny());
463 rIF.addImages (rRHSIF, newImage);
464 std::ostringstream os;
465 os << "Add image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
466 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
467 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
468 newImage.labelsCopy (rIF, s.c_str());
469 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
470 newImage.labelsCopy (rRHSIF, s.c_str());
471 newImage.labelAdd (os.str().c_str());
472 *theApp->getLog() << os.str().c_str() << "\n";
473 if (theApp->getSetModifyNewDocs())
474 pNewDoc->Modify(TRUE);
475 pNewDoc->UpdateAllViews(this);
476 pNewDoc->getView()->OnUpdate (this, NULL);
477 pNewDoc->getView()->getFrame()->Show(true);
483 ImageFileView::OnSubtract (wxCommandEvent& event)
485 std::vector<ImageFileDocument*> vecIF;
486 theApp->getCompatibleImages (GetDocument(), vecIF);
488 if (vecIF.size() == 0) {
489 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
491 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Subtract", vecIF, false);
493 if (dialogGetCompare.ShowModal() == wxID_OK) {
494 ImageFile& rIF = GetDocument()->getImageFile();
495 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
496 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
497 ImageFileDocument* pNewDoc = theApp->newImageDoc();
499 sys_error (ERR_SEVERE, "Unable to create image file");
502 ImageFile& newImage = pNewDoc->getImageFile();
503 newImage.setArraySize (rIF.nx(), rIF.ny());
504 rIF.subtractImages (rRHSIF, newImage);
505 std::ostringstream os;
506 os << "Subtract image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
507 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
508 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
509 newImage.labelsCopy (rIF, s.c_str());
510 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
511 newImage.labelsCopy (rRHSIF, s.c_str());
512 newImage.labelAdd (os.str().c_str());
513 *theApp->getLog() << os.str().c_str() << "\n";
514 if (theApp->getSetModifyNewDocs())
515 pNewDoc->Modify(TRUE);
516 pNewDoc->UpdateAllViews(this);
517 pNewDoc->getView()->OnUpdate (this, NULL);
518 pNewDoc->getView()->getFrame()->Show(true);
524 ImageFileView::OnMultiply (wxCommandEvent& event)
526 std::vector<ImageFileDocument*> vecIF;
527 theApp->getCompatibleImages (GetDocument(), vecIF);
529 if (vecIF.size() == 0) {
530 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
532 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Multiply", vecIF, false);
534 if (dialogGetCompare.ShowModal() == wxID_OK) {
535 ImageFile& rIF = GetDocument()->getImageFile();
536 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
537 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
538 ImageFileDocument* pNewDoc = theApp->newImageDoc();
540 sys_error (ERR_SEVERE, "Unable to create image file");
543 ImageFile& newImage = pNewDoc->getImageFile();
544 newImage.setArraySize (rIF.nx(), rIF.ny());
545 rIF.multiplyImages (rRHSIF, newImage);
546 std::ostringstream os;
547 os << "Multiply image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
548 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
549 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
550 newImage.labelsCopy (rIF, s.c_str());
551 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
552 newImage.labelsCopy (rRHSIF, s.c_str());
553 newImage.labelAdd (os.str().c_str());
554 *theApp->getLog() << os.str().c_str() << "\n";
555 if (theApp->getSetModifyNewDocs())
556 pNewDoc->Modify(TRUE);
557 pNewDoc->UpdateAllViews(this);
558 pNewDoc->getView()->OnUpdate (this, NULL);
559 pNewDoc->getView()->getFrame()->Show(true);
565 ImageFileView::OnDivide (wxCommandEvent& event)
567 std::vector<ImageFileDocument*> vecIF;
568 theApp->getCompatibleImages (GetDocument(), vecIF);
570 if (vecIF.size() == 0) {
571 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
573 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Divide", vecIF, false);
575 if (dialogGetCompare.ShowModal() == wxID_OK) {
576 ImageFile& rIF = GetDocument()->getImageFile();
577 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
578 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
579 ImageFileDocument* pNewDoc = theApp->newImageDoc();
581 sys_error (ERR_SEVERE, "Unable to create image file");
584 ImageFile& newImage = pNewDoc->getImageFile();
585 newImage.setArraySize (rIF.nx(), rIF.ny());
586 rIF.divideImages (rRHSIF, newImage);
587 std::ostringstream os;
588 os << "Divide image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " by "
589 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
590 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
591 newImage.labelsCopy (rIF, s.c_str());
592 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
593 newImage.labelsCopy (rRHSIF, s.c_str());
594 newImage.labelAdd (os.str().c_str());
595 *theApp->getLog() << os.str().c_str() << "\n";
596 if (theApp->getSetModifyNewDocs())
597 pNewDoc->Modify(TRUE);
598 pNewDoc->UpdateAllViews(this);
599 pNewDoc->getView()->OnUpdate (this, NULL);
600 pNewDoc->getView()->getFrame()->Show(true);
608 ImageFileView::OnFFT (wxCommandEvent& event)
610 ImageFile& rIF = GetDocument()->getImageFile();
612 rIF.labelAdd ("FFT Image");
613 m_bMinSpecified = false;
614 m_bMaxSpecified = false;
615 if (theApp->getSetModifyNewDocs())
616 GetDocument()->Modify(TRUE);
617 GetDocument()->UpdateAllViews(this);
621 ImageFileView::OnIFFT (wxCommandEvent& event)
623 ImageFile& rIF = GetDocument()->getImageFile();
625 rIF.labelAdd ("IFFT Image");
626 m_bMinSpecified = false;
627 m_bMaxSpecified = false;
628 if (theApp->getSetModifyNewDocs())
629 GetDocument()->Modify(TRUE);
630 GetDocument()->UpdateAllViews(this);
634 ImageFileView::OnFFTRows (wxCommandEvent& event)
636 ImageFile& rIF = GetDocument()->getImageFile();
638 rIF.labelAdd ("FFT Rows");
639 m_bMinSpecified = false;
640 m_bMaxSpecified = false;
641 if (theApp->getSetModifyNewDocs())
642 GetDocument()->Modify(TRUE);
643 GetDocument()->UpdateAllViews(this);
647 ImageFileView::OnIFFTRows (wxCommandEvent& event)
649 ImageFile& rIF = GetDocument()->getImageFile();
651 rIF.labelAdd ("IFFT Rows");
652 m_bMinSpecified = false;
653 m_bMaxSpecified = false;
654 if (theApp->getSetModifyNewDocs())
655 GetDocument()->Modify(TRUE);
656 GetDocument()->UpdateAllViews(this);
660 ImageFileView::OnFFTCols (wxCommandEvent& event)
662 ImageFile& rIF = GetDocument()->getImageFile();
664 rIF.labelAdd ("FFT Columns");
665 m_bMinSpecified = false;
666 m_bMaxSpecified = false;
667 if (theApp->getSetModifyNewDocs())
668 GetDocument()->Modify(TRUE);
669 GetDocument()->UpdateAllViews(this);
673 ImageFileView::OnIFFTCols (wxCommandEvent& event)
675 ImageFile& rIF = GetDocument()->getImageFile();
677 rIF.labelAdd ("IFFT Columns");
678 m_bMinSpecified = false;
679 m_bMaxSpecified = false;
680 if (theApp->getSetModifyNewDocs())
681 GetDocument()->Modify(TRUE);
682 GetDocument()->UpdateAllViews(this);
687 ImageFileView::OnFourier (wxCommandEvent& event)
689 ImageFile& rIF = GetDocument()->getImageFile();
690 wxProgressDialog dlgProgress (wxString("Fourier"), wxString("Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
692 rIF.labelAdd ("Fourier Image");
693 m_bMinSpecified = false;
694 m_bMaxSpecified = false;
695 if (theApp->getSetModifyNewDocs())
696 GetDocument()->Modify(TRUE);
697 GetDocument()->UpdateAllViews(this);
701 ImageFileView::OnInverseFourier (wxCommandEvent& event)
703 ImageFile& rIF = GetDocument()->getImageFile();
704 wxProgressDialog dlgProgress (wxString("Inverse Fourier"), wxString("Inverse Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
705 rIF.inverseFourier (rIF);
706 rIF.labelAdd ("Inverse Fourier Image");
707 m_bMinSpecified = false;
708 m_bMaxSpecified = false;
709 if (theApp->getSetModifyNewDocs())
710 GetDocument()->Modify(TRUE);
711 GetDocument()->UpdateAllViews(this);
715 ImageFileView::OnShuffleNaturalToFourierOrder (wxCommandEvent& event)
717 ImageFile& rIF = GetDocument()->getImageFile();
718 Fourier::shuffleNaturalToFourierOrder (rIF);
719 rIF.labelAdd ("Shuffle Natural To Fourier Order");
720 m_bMinSpecified = false;
721 m_bMaxSpecified = false;
722 if (theApp->getSetModifyNewDocs())
723 GetDocument()->Modify(TRUE);
724 GetDocument()->UpdateAllViews(this);
728 ImageFileView::OnShuffleFourierToNaturalOrder (wxCommandEvent& event)
730 ImageFile& rIF = GetDocument()->getImageFile();
731 Fourier::shuffleFourierToNaturalOrder (rIF);
732 rIF.labelAdd ("Shuffle Fourier To Natural Order");
733 m_bMinSpecified = false;
734 m_bMaxSpecified = false;
735 if (theApp->getSetModifyNewDocs())
736 GetDocument()->Modify(TRUE);
737 GetDocument()->UpdateAllViews(this);
741 ImageFileView::OnMagnitude (wxCommandEvent& event)
743 ImageFile& rIF = GetDocument()->getImageFile();
744 if (rIF.isComplex()) {
746 rIF.labelAdd ("Magnitude of complex-image");
747 m_bMinSpecified = false;
748 m_bMaxSpecified = false;
749 if (theApp->getSetModifyNewDocs())
750 GetDocument()->Modify(TRUE);
751 GetDocument()->UpdateAllViews(this);
756 ImageFileView::OnPhase (wxCommandEvent& event)
758 ImageFile& rIF = GetDocument()->getImageFile();
759 if (rIF.isComplex()) {
761 rIF.labelAdd ("Phase of complex-image");
762 m_bMinSpecified = false;
763 m_bMaxSpecified = false;
764 if (theApp->getSetModifyNewDocs())
765 GetDocument()->Modify(TRUE);
766 GetDocument()->UpdateAllViews(this);
772 ImageFileView::CreateCanvas (wxView *view, wxFrame *parent)
774 ImageFileCanvas* pCanvas;
776 parent->GetClientSize(&width, &height);
778 pCanvas = new ImageFileCanvas (dynamic_cast<ImageFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
780 pCanvas->SetScrollbars(20, 20, 50, 50);
781 pCanvas->SetBackgroundColour(*wxWHITE);
792 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
795 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
797 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
799 theApp->setIconForFrame (subframe);
801 wxMenu *m_pFileMenu = new wxMenu;
803 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
804 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
805 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
806 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
807 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
808 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
810 m_pFileMenu->AppendSeparator();
811 m_pFileMenu->Append(IFMENU_FILE_PROPERTIES, "P&roperties");
812 m_pFileMenu->Append(IFMENU_FILE_EXPORT, "&Export...");
814 m_pFileMenu->AppendSeparator();
815 m_pFileMenu->Append(wxID_PRINT, "&Print...");
816 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
817 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
819 m_pFileMenu->AppendSeparator();
820 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
822 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
823 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
825 wxMenu *view_menu = new wxMenu;
826 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale S&et...\tCtrl-E");
827 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
828 view_menu->Append(IFMENU_VIEW_SCALE_FULL, "Display F&ull Scale\tCtrl-U");
830 wxMenu* filter_menu = new wxMenu;
831 filter_menu->Append (IFMENU_FILTER_INVERTVALUES, "&Invert Values");
832 filter_menu->Append (IFMENU_FILTER_SQUARE, "&Square");
833 filter_menu->Append (IFMENU_FILTER_SQRT, "Square &Root");
834 filter_menu->Append (IFMENU_FILTER_LOG, "&Log");
835 filter_menu->Append (IFMENU_FILTER_EXP, "&Exp");
836 filter_menu->AppendSeparator();
838 filter_menu->Append (IFMENU_FILTER_FFT, "2D &FFT");
839 filter_menu->Append (IFMENU_FILTER_IFFT, "2D &IFFT");
840 filter_menu->Append (IFMENU_FILTER_FFT_ROWS, "FFT Rows");
841 filter_menu->Append (IFMENU_FILTER_IFFT_ROWS, "IFFT Rows");
842 filter_menu->Append (IFMENU_FILTER_FFT_COLS, "FFT Columns");
843 filter_menu->Append (IFMENU_FILTER_IFFT_COLS, "IFFT Columns");
844 filter_menu->Append (IFMENU_FILTER_FOURIER, "F&ourier");
845 filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "Inverse Fo&urier");
847 filter_menu->Append (IFMENU_FILTER_FOURIER, "&Fourier");
848 filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "&Inverse Fourier");
850 filter_menu->Append (IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, "S&huffle Fourier to Natural Order");
851 filter_menu->Append (IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, "Shu&ffle Natural to Fourier Order");
852 filter_menu->Append (IFMENU_FILTER_MAGNITUDE, "&Magnitude");
853 filter_menu->Append (IFMENU_FILTER_PHASE, "&Phase");
855 wxMenu* image_menu = new wxMenu;
856 image_menu->Append (IFMENU_IMAGE_ADD, "&Add...");
857 image_menu->Append (IFMENU_IMAGE_SUBTRACT, "&Subtract...");
858 image_menu->Append (IFMENU_IMAGE_MULTIPLY, "&Multiply...");
859 image_menu->Append (IFMENU_IMAGE_DIVIDE, "&Divide...");
860 image_menu->AppendSeparator();
861 image_menu->Append (IFMENU_IMAGE_SCALESIZE, "S&cale Size...");
863 wxMenu *analyze_menu = new wxMenu;
864 analyze_menu->Append (IFMENU_PLOT_ROW, "Plot &Row");
865 analyze_menu->Append (IFMENU_PLOT_COL, "Plot &Column");
866 analyze_menu->Append (IFMENU_PLOT_HISTOGRAM, "Plot &Histogram");
867 analyze_menu->AppendSeparator();
868 analyze_menu->Append (IFMENU_PLOT_FFT_ROW, "Plot FFT Row");
869 analyze_menu->Append (IFMENU_PLOT_FFT_COL, "Plot FFT Column");
870 analyze_menu->AppendSeparator();
871 analyze_menu->Append (IFMENU_COMPARE_IMAGES, "Compare &Images...");
872 analyze_menu->Append (IFMENU_COMPARE_ROW, "Compare &Row");
873 analyze_menu->Append (IFMENU_COMPARE_COL, "Compare &Column");
875 wxMenu *help_menu = new wxMenu;
876 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
877 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
878 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
880 wxMenuBar *menu_bar = new wxMenuBar;
882 menu_bar->Append(m_pFileMenu, "&File");
883 menu_bar->Append(view_menu, "&View");
884 menu_bar->Append(image_menu, "&Image");
885 menu_bar->Append(filter_menu, "Fi<er");
886 menu_bar->Append(analyze_menu, "&Analyze");
887 menu_bar->Append(help_menu, "&Help");
889 subframe->SetMenuBar(menu_bar);
891 subframe->Centre(wxBOTH);
893 wxAcceleratorEntry accelEntries[10];
894 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
895 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
896 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
897 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
898 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
899 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
900 accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
901 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('A'), IFMENU_VIEW_SCALE_AUTO);
902 accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('U'), IFMENU_VIEW_SCALE_FULL);
903 accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('E'), IFMENU_VIEW_SCALE_MINMAX);
904 wxAcceleratorTable accelTable (10, accelEntries);
905 subframe->SetAcceleratorTable (accelTable);
912 ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
914 m_pFrame = CreateChildFrame(doc, this);
917 m_bMinSpecified = false;
918 m_bMaxSpecified = false;
919 m_dAutoScaleFactor = 1.;
922 m_pFrame->GetClientSize (&width, &height);
923 m_pFrame->SetTitle("ImageFileView");
924 m_pCanvas = CreateCanvas (this, m_pFrame);
926 int x, y; // X requires a forced resize
927 m_pFrame->GetSize(&x, &y);
928 m_pFrame->SetSize(-1, -1, x, y);
929 m_pFrame->SetFocus();
930 m_pFrame->Show(true);
937 ImageFileView::OnDraw (wxDC* dc)
939 wxSize sizeWindow = m_pFrame->GetClientSize();
940 wxSize sizeBest = m_pCanvas->GetBestSize();
941 if (sizeWindow.x > sizeBest.x || sizeWindow.y > sizeBest.y)
942 m_pFrame->SetClientSize (sizeBest);
945 dc->DrawBitmap(m_bitmap, 0, 0, false);
947 int xCursor, yCursor;
948 if (m_pCanvas->GetCurrentCursor (xCursor, yCursor))
949 m_pCanvas->DrawRubberBandCursor (*dc, xCursor, yCursor);
954 ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
956 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
957 ImageFileArrayConst v = rIF.getArray();
960 if (v != NULL && nx != 0 && ny != 0) {
961 if (! m_bMinSpecified || ! m_bMaxSpecified) {
963 rIF.getMinMax (min, max);
964 if (! m_bMinSpecified)
966 if (! m_bMaxSpecified)
969 double scaleWidth = m_dMaxPixel - m_dMinPixel;
971 unsigned char* imageData = new unsigned char [nx * ny * 3];
972 for (int ix = 0; ix < nx; ix++) {
973 for (int iy = 0; iy < ny; iy++) {
974 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
975 int intensity = static_cast<int>(scaleValue + 0.5);
976 intensity = clamp (intensity, 0, 255);
977 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
978 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
981 wxImage image (nx, ny, imageData, true);
982 m_bitmap = image.ConvertToBitmap();
986 ySize = clamp (ySize, 0, 800);
987 m_pFrame->SetClientSize (xSize, ySize);
988 m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20);
989 m_pCanvas->SetBackgroundColour(*wxWHITE);
993 m_pCanvas->Refresh();
997 ImageFileView::OnClose (bool deleteWindow)
999 if (! GetDocument() || ! GetDocument()->Close())
1003 // m_pCanvas->Show(false);
1004 // m_pCanvas->Clear();
1005 m_pCanvas->setView(NULL);
1008 wxString s(theApp->GetAppName());
1010 m_pFrame->SetTitle(s);
1016 m_pFrame->Show(false);
1017 //m_pFrame->Close(true);
1018 m_pFrame->Destroy();
1026 ImageFileView::OnExport (wxCommandEvent& event)
1028 ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
1029 ImageFileArrayConst v = rIF.getArray();
1032 if (v != NULL && nx != 0 && ny != 0) {
1033 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1035 rIF.getMinMax (min, max);
1036 if (! m_bMinSpecified)
1038 if (! m_bMaxSpecified)
1042 DialogExportParameters dialogExport (getFrameForChild(), m_iDefaultExportFormatID);
1043 if (dialogExport.ShowModal() == wxID_OK) {
1044 wxString strFormatName (dialogExport.getFormatName ());
1045 m_iDefaultExportFormatID = ImageFile::convertFormatNameToID (strFormatName.c_str());
1048 wxString strWildcard;
1049 if (m_iDefaultExportFormatID == ImageFile::FORMAT_PGM || m_iDefaultExportFormatID == ImageFile::FORMAT_PGMASCII) {
1051 strWildcard = "PGM Files (*.pgm)|*.pgm";
1054 else if (m_iDefaultExportFormatID == ImageFile::FORMAT_PNG || m_iDefaultExportFormatID == ImageFile::FORMAT_PNG16) {
1056 strWildcard = "PNG Files (*.png)|*.png";
1060 const wxString& strFilename = wxFileSelector (wxString("Export Filename"), wxString(""),
1061 wxString(""), strExt, strWildcard, wxOVERWRITE_PROMPT | wxHIDE_READONLY | wxSAVE);
1063 rIF.exportImage (strFormatName.c_str(), strFilename.c_str(), 1, 1, m_dMinPixel, m_dMaxPixel);
1064 *theApp->getLog() << "Exported file " << strFilename << "\n";
1071 ImageFileView::OnScaleSize (wxCommandEvent& event)
1073 ImageFile& rIF = GetDocument()->getImageFile();
1074 unsigned int iOldNX = rIF.nx();
1075 unsigned int iOldNY = rIF.ny();
1077 DialogGetXYSize dialogGetXYSize (getFrameForChild(), "Set New X & Y Dimensions", iOldNX, iOldNY);
1078 if (dialogGetXYSize.ShowModal() == wxID_OK) {
1079 unsigned int iNewNX = dialogGetXYSize.getXSize();
1080 unsigned int iNewNY = dialogGetXYSize.getYSize();
1081 std::ostringstream os;
1082 os << "Scale Size from (" << iOldNX << "," << iOldNY << ") to (" << iNewNX << "," << iNewNY << ")";
1083 ImageFileDocument* pScaledDoc = theApp->newImageDoc();
1085 sys_error (ERR_SEVERE, "Unable to create image file");
1088 ImageFile& rScaledIF = pScaledDoc->getImageFile();
1089 rScaledIF.setArraySize (iNewNX, iNewNY);
1090 rScaledIF.labelsCopy (rIF);
1091 rScaledIF.labelAdd (os.str().c_str());
1092 rIF.scaleImage (rScaledIF);
1093 *theApp->getLog() << os.str().c_str() << "\n";
1094 if (theApp->getSetModifyNewDocs())
1095 pScaledDoc->Modify(TRUE);
1096 pScaledDoc->UpdateAllViews (this);
1097 pScaledDoc->getView()->OnUpdate (this, NULL);
1098 pScaledDoc->getView()->getFrame()->Show(true);
1103 ImageFileView::OnPlotRow (wxCommandEvent& event)
1105 int xCursor, yCursor;
1106 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1107 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1111 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
1112 ImageFileArrayConst v = rIF.getArray();
1113 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1117 if (v != NULL && yCursor < ny) {
1118 double* pX = new double [nx];
1119 double* pYReal = new double [nx];
1120 double *pYImag = NULL;
1121 double *pYMag = NULL;
1122 if (rIF.isComplex()) {
1123 pYImag = new double [nx];
1124 pYMag = new double [nx];
1126 for (int i = 0; i < nx; i++) {
1128 pYReal[i] = v[i][yCursor];
1129 if (rIF.isComplex()) {
1130 pYImag[i] = vImag[i][yCursor];
1131 pYMag[i] = ::sqrt (v[i][yCursor] * v[i][yCursor] + vImag[i][yCursor] * vImag[i][yCursor]);
1134 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1136 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1138 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1139 std::ostringstream os;
1140 os << "Row " << yCursor;
1141 std::string title("title ");
1143 rPlotFile.addEzsetCommand (title.c_str());
1144 rPlotFile.addEzsetCommand ("xlabel Column");
1145 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1146 rPlotFile.addEzsetCommand ("lxfrac 0");
1147 rPlotFile.addEzsetCommand ("box");
1148 rPlotFile.addEzsetCommand ("grid");
1149 rPlotFile.addEzsetCommand ("curve 1");
1150 rPlotFile.addEzsetCommand ("color 1");
1151 if (rIF.isComplex()) {
1152 rPlotFile.addEzsetCommand ("dash 1");
1153 rPlotFile.addEzsetCommand ("curve 2");
1154 rPlotFile.addEzsetCommand ("color 4");
1155 rPlotFile.addEzsetCommand ("dash 3");
1156 rPlotFile.addEzsetCommand ("curve 3");
1157 rPlotFile.addEzsetCommand ("color 0");
1158 rPlotFile.addEzsetCommand ("solid");
1159 rPlotFile.setCurveSize (4, nx);
1161 rPlotFile.setCurveSize (2, nx);
1162 rPlotFile.addColumn (0, pX);
1163 rPlotFile.addColumn (1, pYReal);
1164 if (rIF.isComplex()) {
1165 rPlotFile.addColumn (2, pYImag);
1166 rPlotFile.addColumn (3, pYMag);
1168 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1169 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1170 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1171 *theApp->getLog() << os.str().c_str() << "\n";
1172 rPlotFile.addDescription (os.str().c_str());
1176 if (rIF.isComplex()) {
1180 if (theApp->getSetModifyNewDocs())
1181 pPlotDoc->Modify(true);
1182 pPlotDoc->UpdateAllViews();
1187 ImageFileView::OnPlotCol (wxCommandEvent& event)
1189 int xCursor, yCursor;
1190 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1191 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1195 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
1196 ImageFileArrayConst v = rIF.getArray();
1197 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1201 if (v != NULL && xCursor < nx) {
1202 double* pX = new double [ny];
1203 double* pYReal = new double [ny];
1204 double* pYImag = NULL;
1205 double* pYMag = NULL;
1206 if (rIF.isComplex()) {
1207 pYImag = new double [ny];
1208 pYMag = new double [ny];
1210 for (int i = 0; i < ny; i++) {
1212 pYReal[i] = v[xCursor][i];
1213 if (rIF.isComplex()) {
1214 pYImag[i] = vImag[xCursor][i];
1215 pYMag[i] = ::sqrt (v[xCursor][i] * v[xCursor][i] + vImag[xCursor][i] * vImag[xCursor][i]);
1218 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1220 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1222 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1223 std::ostringstream os;
1224 os << "Column " << xCursor;
1225 std::string title("title ");
1227 rPlotFile.addEzsetCommand (title.c_str());
1228 rPlotFile.addEzsetCommand ("xlabel Row");
1229 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1230 rPlotFile.addEzsetCommand ("lxfrac 0");
1231 rPlotFile.addEzsetCommand ("box");
1232 rPlotFile.addEzsetCommand ("grid");
1233 rPlotFile.addEzsetCommand ("curve 1");
1234 rPlotFile.addEzsetCommand ("color 1");
1235 if (rIF.isComplex()) {
1236 rPlotFile.addEzsetCommand ("dash 1");
1237 rPlotFile.addEzsetCommand ("curve 2");
1238 rPlotFile.addEzsetCommand ("color 4");
1239 rPlotFile.addEzsetCommand ("dash 3");
1240 rPlotFile.addEzsetCommand ("curve 3");
1241 rPlotFile.addEzsetCommand ("color 0");
1242 rPlotFile.addEzsetCommand ("solid");
1243 rPlotFile.setCurveSize (4, ny);
1245 rPlotFile.setCurveSize (2, ny);
1246 rPlotFile.addColumn (0, pX);
1247 rPlotFile.addColumn (1, pYReal);
1248 if (rIF.isComplex()) {
1249 rPlotFile.addColumn (2, pYImag);
1250 rPlotFile.addColumn (3, pYMag);
1252 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1253 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1254 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1255 *theApp->getLog() << os.str().c_str() << "\n";
1256 rPlotFile.addDescription (os.str().c_str());
1260 if (rIF.isComplex()) {
1264 if (theApp->getSetModifyNewDocs())
1265 pPlotDoc->Modify(true);
1266 pPlotDoc->UpdateAllViews();
1272 ImageFileView::OnPlotFFTRow (wxCommandEvent& event)
1274 int xCursor, yCursor;
1275 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1276 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1280 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
1281 ImageFileArrayConst v = rIF.getArray();
1282 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1286 if (v != NULL && yCursor < ny) {
1287 fftw_complex* pcIn = new fftw_complex [nx];
1290 for (i = 0; i < nx; i++) {
1291 pcIn[i].re = v[i][yCursor];
1292 if (rIF.isComplex())
1293 pcIn[i].im = vImag[i][yCursor];
1298 fftw_plan plan = fftw_create_plan (nx, FFTW_FORWARD, FFTW_IN_PLACE);
1299 fftw_one (plan, pcIn, NULL);
1300 fftw_destroy_plan (plan);
1302 double* pX = new double [nx];
1303 double* pYReal = new double [nx];
1304 double* pYImag = new double [nx];
1305 double* pYMag = new double [nx];
1306 for (i = 0; i < nx; i++) {
1308 pYReal[i] = pcIn[i].re;
1309 pYImag[i] = pcIn[i].im;
1310 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1312 Fourier::shuffleFourierToNaturalOrder (pYReal, nx);
1313 Fourier::shuffleFourierToNaturalOrder (pYImag, nx);
1314 Fourier::shuffleFourierToNaturalOrder (pYMag, nx);
1316 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1318 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1320 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1321 std::ostringstream os;
1322 os << "Row " << yCursor;
1323 std::string title("title ");
1325 rPlotFile.addEzsetCommand (title.c_str());
1326 rPlotFile.addEzsetCommand ("xlabel Column");
1327 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1328 rPlotFile.addEzsetCommand ("lxfrac 0");
1329 rPlotFile.addEzsetCommand ("curve 1");
1330 rPlotFile.addEzsetCommand ("color 1");
1331 rPlotFile.addEzsetCommand ("dash 1");
1332 rPlotFile.addEzsetCommand ("curve 2");
1333 rPlotFile.addEzsetCommand ("color 4");
1334 rPlotFile.addEzsetCommand ("dash 3");
1335 rPlotFile.addEzsetCommand ("curve 3");
1336 rPlotFile.addEzsetCommand ("color 0");
1337 rPlotFile.addEzsetCommand ("solid");
1338 rPlotFile.addEzsetCommand ("box");
1339 rPlotFile.addEzsetCommand ("grid");
1340 rPlotFile.setCurveSize (4, nx);
1341 rPlotFile.addColumn (0, pX);
1342 rPlotFile.addColumn (1, pYReal);
1343 rPlotFile.addColumn (2, pYImag);
1344 rPlotFile.addColumn (3, pYMag);
1345 for (int iL = 0; iL < rIF.nLabels(); iL++)
1346 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1347 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1348 *theApp->getLog() << os.str().c_str() << "\n";
1349 rPlotFile.addDescription (os.str().c_str());
1357 if (theApp->getSetModifyNewDocs())
1358 pPlotDoc->Modify(true);
1359 pPlotDoc->UpdateAllViews();
1364 ImageFileView::OnPlotFFTCol (wxCommandEvent& event)
1366 int xCursor, yCursor;
1367 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1368 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1372 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
1373 ImageFileArrayConst v = rIF.getArray();
1374 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1378 if (v != NULL && xCursor < nx) {
1379 fftw_complex* pcIn = new fftw_complex [ny];
1380 double *pdTemp = new double [ny];
1383 for (i = 0; i < ny; i++)
1384 pdTemp[i] = v[xCursor][i];
1385 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1386 for (i = 0; i < ny; i++)
1387 pcIn[i].re = pdTemp[i];
1389 for (i = 0; i < ny; i++) {
1390 if (rIF.isComplex())
1391 pdTemp[i] = vImag[xCursor][i];
1395 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1396 for (i = 0; i < ny; i++)
1397 pcIn[i].im = pdTemp[i];
1399 fftw_plan plan = fftw_create_plan (ny, FFTW_BACKWARD, FFTW_IN_PLACE);
1400 fftw_one (plan, pcIn, NULL);
1401 fftw_destroy_plan (plan);
1403 double* pX = new double [ny];
1404 double* pYReal = new double [ny];
1405 double* pYImag = new double [ny];
1406 double* pYMag = new double [ny];
1407 for (i = 0; i < ny; i++) {
1409 pYReal[i] = pcIn[i].re;
1410 pYImag[i] = pcIn[i].im;
1411 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1414 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1416 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1418 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1419 std::ostringstream os;
1420 os << "Column " << xCursor;
1421 std::string title("title ");
1423 rPlotFile.addEzsetCommand (title.c_str());
1424 rPlotFile.addEzsetCommand ("xlabel Column");
1425 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1426 rPlotFile.addEzsetCommand ("lxfrac 0");
1427 rPlotFile.addEzsetCommand ("curve 1");
1428 rPlotFile.addEzsetCommand ("color 1");
1429 rPlotFile.addEzsetCommand ("dash 1");
1430 rPlotFile.addEzsetCommand ("curve 2");
1431 rPlotFile.addEzsetCommand ("color 4");
1432 rPlotFile.addEzsetCommand ("dash 3");
1433 rPlotFile.addEzsetCommand ("curve 3");
1434 rPlotFile.addEzsetCommand ("color 0");
1435 rPlotFile.addEzsetCommand ("solid");
1436 rPlotFile.addEzsetCommand ("box");
1437 rPlotFile.addEzsetCommand ("grid");
1438 rPlotFile.setCurveSize (4, ny);
1439 rPlotFile.addColumn (0, pX);
1440 rPlotFile.addColumn (1, pYReal);
1441 rPlotFile.addColumn (2, pYImag);
1442 rPlotFile.addColumn (3, pYMag);
1443 for (int iL = 0; iL < rIF.nLabels(); iL++)
1444 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1445 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1446 *theApp->getLog() << os.str().c_str() << "\n";
1447 rPlotFile.addDescription (os.str().c_str());
1456 if (theApp->getSetModifyNewDocs())
1457 pPlotDoc->Modify(true);
1458 pPlotDoc->UpdateAllViews();
1464 ImageFileView::OnCompareCol (wxCommandEvent& event)
1466 int xCursor, yCursor;
1467 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1468 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1472 std::vector<ImageFileDocument*> vecIFDoc;
1473 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1474 if (vecIFDoc.size() == 0) {
1475 wxMessageBox ("No compatible images for Column Comparison", "Error");
1478 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1480 if (dialogGetCompare.ShowModal() == wxID_OK) {
1481 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1482 const ImageFile& rIF = GetDocument()->getImageFile();
1483 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1485 ImageFileArrayConst v1 = rIF.getArray();
1486 ImageFileArrayConst v2 = rCompareIF.getArray();
1490 if (v1 != NULL && xCursor < nx) {
1491 double* pX = new double [ny];
1492 double* pY1 = new double [ny];
1493 double* pY2 = new double [ny];
1494 for (int i = 0; i < ny; i++) {
1496 pY1[i] = v1[xCursor][i];
1497 pY2[i] = v2[xCursor][i];
1499 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1501 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1503 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1504 std::ostringstream os;
1505 os << "Column " << xCursor << " Comparison";
1506 std::string title("title ");
1508 rPlotFile.addEzsetCommand (title.c_str());
1509 rPlotFile.addEzsetCommand ("xlabel Row");
1510 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1511 rPlotFile.addEzsetCommand ("lxfrac 0");
1512 rPlotFile.addEzsetCommand ("curve 1");
1513 rPlotFile.addEzsetCommand ("color 2");
1514 rPlotFile.addEzsetCommand ("curve 2");
1515 rPlotFile.addEzsetCommand ("color 4");
1516 rPlotFile.addEzsetCommand ("dash 5");
1517 rPlotFile.addEzsetCommand ("box");
1518 rPlotFile.addEzsetCommand ("grid");
1519 rPlotFile.setCurveSize (3, ny);
1520 rPlotFile.addColumn (0, pX);
1521 rPlotFile.addColumn (1, pY1);
1522 rPlotFile.addColumn (2, pY2);
1525 for (iL = 0; iL < rIF.nLabels(); iL++) {
1526 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1528 s += rIF.labelGet(iL).getLabelString();
1529 rPlotFile.addDescription (s.c_str());
1531 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1532 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1534 s += rCompareIF.labelGet(iL).getLabelString();
1535 rPlotFile.addDescription (s.c_str());
1537 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1538 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1539 *theApp->getLog() << os.str().c_str() << "\n";
1540 rPlotFile.addDescription (os.str().c_str());
1545 if (theApp->getSetModifyNewDocs())
1546 pPlotDoc->Modify(true);
1547 pPlotDoc->UpdateAllViews();
1553 ImageFileView::OnCompareRow (wxCommandEvent& event)
1555 int xCursor, yCursor;
1556 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1557 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1561 std::vector<ImageFileDocument*> vecIFDoc;
1562 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1564 if (vecIFDoc.size() == 0) {
1565 wxMessageBox ("No compatible images for Row Comparison", "Error");
1569 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1571 if (dialogGetCompare.ShowModal() == wxID_OK) {
1572 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1573 const ImageFile& rIF = GetDocument()->getImageFile();
1574 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1576 ImageFileArrayConst v1 = rIF.getArray();
1577 ImageFileArrayConst v2 = rCompareIF.getArray();
1581 if (v1 != NULL && yCursor < ny) {
1582 double* pX = new double [nx];
1583 double* pY1 = new double [nx];
1584 double* pY2 = new double [nx];
1585 for (int i = 0; i < nx; i++) {
1587 pY1[i] = v1[i][yCursor];
1588 pY2[i] = v2[i][yCursor];
1590 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1592 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1594 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1595 std::ostringstream os;
1596 os << "Row " << yCursor << " Comparison";
1597 std::string title("title ");
1599 rPlotFile.addEzsetCommand (title.c_str());
1600 rPlotFile.addEzsetCommand ("xlabel Column");
1601 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1602 rPlotFile.addEzsetCommand ("lxfrac 0");
1603 rPlotFile.addEzsetCommand ("curve 1");
1604 rPlotFile.addEzsetCommand ("color 2");
1605 rPlotFile.addEzsetCommand ("curve 2");
1606 rPlotFile.addEzsetCommand ("color 4");
1607 rPlotFile.addEzsetCommand ("dash 5");
1608 rPlotFile.addEzsetCommand ("box");
1609 rPlotFile.addEzsetCommand ("grid");
1610 rPlotFile.setCurveSize (3, nx);
1611 rPlotFile.addColumn (0, pX);
1612 rPlotFile.addColumn (1, pY1);
1613 rPlotFile.addColumn (2, pY2);
1615 for (iL = 0; iL < rIF.nLabels(); iL++) {
1616 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1618 s += rIF.labelGet(iL).getLabelString();
1619 rPlotFile.addDescription (s.c_str());
1621 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1622 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1624 s += rCompareIF.labelGet(iL).getLabelString();
1625 rPlotFile.addDescription (s.c_str());
1627 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1628 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1629 *theApp->getLog() << os.str().c_str() << "\n";
1630 rPlotFile.addDescription (os.str().c_str());
1635 if (theApp->getSetModifyNewDocs())
1636 pPlotDoc->Modify(true);
1637 pPlotDoc->UpdateAllViews();
1642 static int NUMBER_HISTOGRAM_BINS = 256;
1645 ImageFileView::OnPlotHistogram (wxCommandEvent& event)
1647 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
1648 ImageFileArrayConst v = rIF.getArray();
1652 if (v != NULL && nx > 0 && ny > 0) {
1653 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1655 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1659 double* pX = new double [NUMBER_HISTOGRAM_BINS];
1660 double* pY = new double [NUMBER_HISTOGRAM_BINS];
1662 rIF.getMinMax (dMin, dMax);
1663 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
1665 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
1666 pX[i] = dMin + (i + 0.5) * dBinWidth;
1669 for (int ix = 0; ix < nx; ix++)
1670 for (int iy = 0; iy < ny; iy++) {
1671 int iBin = nearest<int> ((v[ix][iy] - dMin) / dBinWidth);
1672 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
1676 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1677 std::ostringstream os;
1679 std::string title("title ");
1681 rPlotFile.addEzsetCommand (title.c_str());
1682 rPlotFile.addEzsetCommand ("xlabel Pixel Value");
1683 rPlotFile.addEzsetCommand ("ylabel Count");
1684 rPlotFile.addEzsetCommand ("box");
1685 rPlotFile.addEzsetCommand ("grid");
1686 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
1687 rPlotFile.addColumn (0, pX);
1688 rPlotFile.addColumn (1, pY);
1689 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++) {
1690 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1692 s += rIF.labelGet(iL).getLabelString();
1693 rPlotFile.addDescription (s.c_str());
1695 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1696 *theApp->getLog() << os.str().c_str() << "\n";
1697 rPlotFile.addDescription (os.str().c_str());
1700 if (theApp->getSetModifyNewDocs())
1701 pPlotDoc->Modify(true);
1702 pPlotDoc->UpdateAllViews();
1709 PhantomCanvas::PhantomCanvas (PhantomFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1710 : wxScrolledWindow(frame, -1, pos, size, style)
1715 PhantomCanvas::~PhantomCanvas ()
1721 PhantomCanvas::OnDraw (wxDC& dc)
1724 m_pView->OnDraw(& dc);
1730 IMPLEMENT_DYNAMIC_CLASS(PhantomFileView, wxView)
1732 BEGIN_EVENT_TABLE(PhantomFileView, wxView)
1733 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomFileView::OnProperties)
1734 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomFileView::OnRasterize)
1735 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomFileView::OnProjections)
1738 PhantomFileView::PhantomFileView()
1739 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0)
1741 #if defined(DEBUG) || defined(_DEBUG)
1742 m_iDefaultNDet = 165;
1743 m_iDefaultNView = 180;
1745 m_iDefaultNDet = 367;
1746 m_iDefaultNView = 320;
1748 m_iDefaultNSample = 1;
1749 m_dDefaultRotation = 1;
1750 m_dDefaultFocalLength = 2;
1751 m_dDefaultFieldOfView = 1;
1752 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
1753 m_iDefaultTrace = Trace::TRACE_NONE;
1756 m_iDefaultRasterNX = 115;
1757 m_iDefaultRasterNY = 115;
1758 m_iDefaultRasterNSamples = 1;
1760 m_iDefaultRasterNX = 256;
1761 m_iDefaultRasterNY = 256;
1762 m_iDefaultRasterNSamples = 2;
1766 PhantomFileView::~PhantomFileView()
1768 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
1769 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
1773 PhantomFileView::OnProperties (wxCommandEvent& event)
1775 const int idPhantom = GetDocument()->getPhantomID();
1776 const wxString& namePhantom = GetDocument()->getPhantomName();
1777 std::ostringstream os;
1778 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")" << "\n";
1779 const Phantom& rPhantom = GetDocument()->getPhantom();
1780 rPhantom.printDefinitions (os);
1782 rPhantom.print (os);
1784 *theApp->getLog() << os.str().c_str() << "\n";
1785 wxMessageBox (os.str().c_str(), "Phantom Properties");
1790 PhantomFileView::OnProjections (wxCommandEvent& event)
1792 DialogGetProjectionParameters dialogProjection (getFrameForChild(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView, m_iDefaultGeometry, m_iDefaultTrace);
1793 int retVal = dialogProjection.ShowModal();
1794 if (retVal == wxID_OK) {
1795 m_iDefaultNDet = dialogProjection.getNDet();
1796 m_iDefaultNView = dialogProjection.getNView();
1797 m_iDefaultNSample = dialogProjection.getNSamples();
1798 m_iDefaultTrace = dialogProjection.getTrace();
1799 m_dDefaultRotation = dialogProjection.getRotAngle();
1800 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
1801 m_dDefaultFieldOfView = dialogProjection.getFieldOfViewRatio();
1802 wxString sGeometry = dialogProjection.getGeometry();
1803 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
1805 if (m_iDefaultNDet > 0 && m_iDefaultNView > 0 && sGeometry != "") {
1806 const Phantom& rPhantom = GetDocument()->getPhantom();
1807 ProjectionFileDocument* pProjectionDoc = theApp->newProjectionDoc();
1808 if (! pProjectionDoc) {
1809 sys_error (ERR_SEVERE, "Unable to create projection document");
1812 Projections& rProj = pProjectionDoc->getProjections();
1813 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView);
1814 if (theScanner.fail()) {
1815 *theApp->getLog() << "Failed making scanner: " << theScanner.failMessage().c_str() << "\n";
1818 rProj.initFromScanner (theScanner);
1819 m_dDefaultRotation /= PI; // convert back to PI units
1822 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
1823 ProjectionsDialog dialogProjections (theScanner, rProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(getFrameForChild()));
1824 for (int iView = 0; iView < rProj.nView(); iView++) {
1826 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
1827 pProjectionDoc->getView()->getFrame()->Close(true);
1831 while (dialogProjections.isPaused()) {
1837 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT);
1838 for (int i = 0; i < rProj.nView(); i++) {
1839 theScanner.collectProjections (rProj, rPhantom, i, 1, true, m_iDefaultTrace);
1840 if (! dlgProgress.Update (i+1)) {
1841 pProjectionDoc->getView()->getFrame()->Close(true);
1847 std::ostringstream os;
1848 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();
1849 rProj.setCalcTime (timer.timerEnd());
1850 rProj.setRemark (os.str());
1851 *theApp->getLog() << os.str().c_str() << "\n";
1855 ProjectionFileView* projView = dynamic_cast<ProjectionFileView*>(pProjectionDoc->GetFirstView());
1857 projView->getFrame()->SetFocus();
1858 projView->OnUpdate (projView, NULL);
1860 if (wxView* pView = pProjectionDoc->GetFirstView()) {
1861 if (wxFrame* pFrame = pView->GetFrame()) {
1865 GetDocumentManager()->ActivateView (pView, true, false);
1868 if (theApp->getSetModifyNewDocs())
1869 pProjectionDoc->Modify(true);
1870 pProjectionDoc->getView()->getFrame()->Show(true);
1871 pProjectionDoc->UpdateAllViews(this);
1878 PhantomFileView::OnRasterize (wxCommandEvent& event)
1880 DialogGetRasterParameters dialogRaster (getFrameForChild(), m_iDefaultRasterNX, m_iDefaultRasterNY, m_iDefaultRasterNSamples);
1881 int retVal = dialogRaster.ShowModal();
1882 if (retVal == wxID_OK) {
1883 m_iDefaultRasterNX = dialogRaster.getXSize();
1884 m_iDefaultRasterNY = dialogRaster.getYSize();
1885 m_iDefaultRasterNSamples = dialogRaster.getNSamples();
1886 if (m_iDefaultRasterNSamples < 1)
1887 m_iDefaultRasterNSamples = 1;
1888 if (m_iDefaultRasterNX > 0 && m_iDefaultRasterNY > 0) {
1889 const Phantom& rPhantom = GetDocument()->getPhantom();
1890 ImageFileDocument* pRasterDoc = theApp->newImageDoc();
1892 sys_error (ERR_SEVERE, "Unable to create image file");
1895 ImageFile& imageFile = pRasterDoc->getImageFile();
1897 imageFile.setArraySize (m_iDefaultRasterNX, m_iDefaultRasterNX);
1898 wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"), imageFile.nx() + 1, getFrameForChild(), wxPD_CAN_ABORT);
1900 for (unsigned int i = 0; i < imageFile.nx(); i++) {
1901 rPhantom.convertToImagefile (imageFile, m_iDefaultRasterNSamples, Trace::TRACE_NONE, i, 1, true);
1902 if (! dlgProgress.Update(i+1)) {
1903 pRasterDoc->Close();
1904 pRasterDoc->getView()->getFrame()->Close(true);
1908 if (theApp->getSetModifyNewDocs())
1909 pRasterDoc->Modify(true);
1910 pRasterDoc->UpdateAllViews(this);
1911 pRasterDoc->getView()->getFrame()->Show(true);
1912 std::ostringstream os;
1913 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << m_iDefaultRasterNX << ", YSize="
1914 << m_iDefaultRasterNY << ", nSamples=" << m_iDefaultRasterNSamples;
1915 *theApp->getLog() << os.str().c_str() << "\n";
1916 imageFile.labelAdd (os.str().c_str(), timer.timerEnd());
1917 ImageFileView* rasterView = dynamic_cast<ImageFileView*>(pRasterDoc->GetFirstView());
1919 rasterView->getFrame()->SetFocus();
1920 rasterView->OnUpdate (rasterView, NULL);
1929 PhantomFileView::CreateCanvas (wxView *view, wxFrame *parent)
1931 PhantomCanvas* pCanvas;
1933 parent->GetClientSize(&width, &height);
1935 pCanvas = new PhantomCanvas (dynamic_cast<PhantomFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
1937 pCanvas->SetBackgroundColour(*wxWHITE);
1948 PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view)
1951 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
1953 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
1955 theApp->setIconForFrame (subframe);
1957 wxMenu *m_pFileMenu = new wxMenu;
1959 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
1960 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
1961 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
1962 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
1963 m_pFileMenu->Append(wxID_CLOSE, "&Close");
1965 m_pFileMenu->AppendSeparator();
1966 m_pFileMenu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties");
1968 m_pFileMenu->AppendSeparator();
1969 m_pFileMenu->Append(wxID_PRINT, "&Print...");
1970 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
1971 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
1973 m_pFileMenu->AppendSeparator();
1974 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
1976 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
1977 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
1979 wxMenu *process_menu = new wxMenu;
1980 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...\tCtrl-R");
1981 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...\tCtrl-J");
1983 wxMenu *help_menu = new wxMenu;
1984 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
1985 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
1986 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
1988 wxMenuBar *menu_bar = new wxMenuBar;
1990 menu_bar->Append(m_pFileMenu, "&File");
1991 menu_bar->Append(process_menu, "&Process");
1992 menu_bar->Append(help_menu, "&Help");
1994 subframe->SetMenuBar(menu_bar);
1995 subframe->Centre(wxBOTH);
1997 wxAcceleratorEntry accelEntries[8];
1998 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
1999 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
2000 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
2001 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
2002 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
2003 accelEntries[5].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
2004 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('J'), PHMMENU_PROCESS_PROJECTIONS);
2005 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('R'), PHMMENU_PROCESS_RASTERIZE);
2006 wxAcceleratorTable accelTable (8, accelEntries);
2007 subframe->SetAcceleratorTable (accelTable);
2014 PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2016 m_pFrame = CreateChildFrame(doc, this);
2020 m_pFrame->GetClientSize(&width, &height);
2021 m_pFrame->SetTitle("PhantomFileView");
2022 m_pCanvas = CreateCanvas (this, m_pFrame);
2025 int x, y; // X requires a forced resize
2026 m_pFrame->GetSize(&x, &y);
2027 m_pFrame->SetSize(-1, -1, x, y);
2030 m_pFrame->Show(true);
2037 PhantomFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2040 m_pCanvas->Refresh();
2044 PhantomFileView::OnClose (bool deleteWindow)
2046 if (! GetDocument() || ! GetDocument()->Close())
2050 //m_pCanvas->Show(false);
2051 //m_pCanvas->Clear();
2052 m_pCanvas->setView(NULL);
2055 wxString s(wxTheApp->GetAppName());
2057 m_pFrame->SetTitle(s);
2063 m_pFrame->Show(false);
2064 m_pFrame->Destroy();
2065 //GetDocumentManager()->ActivateView(this, FALSE, TRUE);
2074 PhantomFileView::OnDraw (wxDC* dc)
2077 m_pCanvas->GetClientSize (&xsize, &ysize);
2078 SGPDriver driver (dc, xsize, ysize);
2080 const Phantom& rPhantom = GetDocument()->getPhantom();
2081 sgp.setColor (C_RED);
2082 rPhantom.show (sgp);
2087 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2088 : wxScrolledWindow(frame, -1, pos, size, style)
2093 ProjectionFileCanvas::~ProjectionFileCanvas ()
2099 ProjectionFileCanvas::OnDraw(wxDC& dc)
2102 m_pView->OnDraw(& dc);
2106 ProjectionFileCanvas::GetBestSize () const
2110 Projections& rProj = m_pView->GetDocument()->getProjections();
2111 best.Set (rProj.nDet(), rProj.nView());
2118 // ProjectionFileView
2120 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
2122 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
2123 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
2124 EVT_MENU(PJMENU_RECONSTRUCT_FBP, ProjectionFileView::OnReconstructFBP)
2125 EVT_MENU(PJMENU_CONVERT_POLAR, ProjectionFileView::OnConvertPolar)
2126 EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
2129 ProjectionFileView::ProjectionFileView()
2130 : wxView(), m_pCanvas(NULL), m_pFrame(NULL), m_pFileMenu(0)
2140 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
2141 m_dDefaultFilterParam = 1.;
2143 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
2144 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
2146 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
2147 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
2149 m_iDefaultZeropad = 1;
2150 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF3;
2151 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
2152 m_iDefaultInterpParam = 1;
2153 m_iDefaultTrace = Trace::TRACE_NONE;
2155 m_iDefaultPolarNX = 256;
2156 m_iDefaultPolarNY = 256;
2157 m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR;
2158 m_iDefaultPolarZeropad = 1;
2161 ProjectionFileView::~ProjectionFileView()
2163 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2164 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2168 ProjectionFileView::OnProperties (wxCommandEvent& event)
2170 const Projections& rProj = GetDocument()->getProjections();
2171 std::ostringstream os;
2172 rProj.printScanInfo(os);
2173 *theApp->getLog() << os.str().c_str();
2174 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
2175 dialogMsg.ShowModal();
2180 ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
2182 Projections& rProj = GetDocument()->getProjections();
2183 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2184 m_iDefaultPolarInterpolation, -1);
2185 if (dialogPolar.ShowModal() == wxID_OK) {
2186 wxString strInterpolation (dialogPolar.getInterpolationName());
2187 m_iDefaultPolarNX = dialogPolar.getXSize();
2188 m_iDefaultPolarNY = dialogPolar.getYSize();
2189 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2190 ImageFile& rIF = pPolarDoc->getImageFile();
2192 sys_error (ERR_SEVERE, "Unable to create image file");
2195 rIF.setArraySize (m_iDefaultPolarNX, m_iDefaultPolarNY);
2196 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2197 rProj.convertPolar (rIF, m_iDefaultPolarInterpolation);
2198 rIF.labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2199 std::ostringstream os;
2200 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to polar image: xSize="
2201 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2202 << strInterpolation.c_str();
2203 *theApp->getLog() << os.str().c_str() << "\n";
2204 rIF.labelAdd (os.str().c_str());
2205 if (theApp->getSetModifyNewDocs())
2206 pPolarDoc->Modify(true);
2207 pPolarDoc->UpdateAllViews();
2208 pPolarDoc->getView()->OnUpdate (this, NULL);
2209 pPolarDoc->getView()->getFrame()->Show(true);
2214 ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
2216 Projections& rProj = GetDocument()->getProjections();
2217 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert to FFT Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2218 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad);
2219 if (dialogPolar.ShowModal() == wxID_OK) {
2220 wxString strInterpolation (dialogPolar.getInterpolationName());
2221 m_iDefaultPolarNX = dialogPolar.getXSize();
2222 m_iDefaultPolarNY = dialogPolar.getYSize();
2223 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2224 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2225 ImageFile& rIF = pPolarDoc->getImageFile();
2227 sys_error (ERR_SEVERE, "Unable to create image file");
2230 rIF.setArraySize (m_iDefaultPolarNX, m_iDefaultPolarNY);
2231 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2232 rProj.convertFFTPolar (rIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad);
2233 rIF.labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2234 std::ostringstream os;
2235 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to FFT polar image: xSize="
2236 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2237 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2238 *theApp->getLog() << os.str().c_str() << "\n";
2239 rIF.labelAdd (os.str().c_str());
2240 if (theApp->getSetModifyNewDocs())
2241 pPolarDoc->Modify(true);
2242 pPolarDoc->UpdateAllViews();
2243 pPolarDoc->getView()->OnUpdate (this, NULL);
2244 pPolarDoc->getView()->getFrame()->Show(true);
2249 ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
2251 wxMessageBox ("Fourier Reconstruction is not yet supported", "Unimplemented function");
2255 ProjectionFileView::OnReconstructFBP (wxCommandEvent& event)
2257 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);
2259 int retVal = dialogReconstruction.ShowModal();
2260 if (retVal == wxID_OK) {
2261 m_iDefaultNX = dialogReconstruction.getXSize();
2262 m_iDefaultNY = dialogReconstruction.getYSize();
2263 wxString optFilterName = dialogReconstruction.getFilterName();
2264 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
2265 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
2266 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
2267 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
2268 m_iDefaultZeropad = dialogReconstruction.getZeropad();
2269 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
2270 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
2271 wxString optInterpName = dialogReconstruction.getInterpName();
2272 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
2273 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
2274 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
2275 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
2276 m_iDefaultTrace = dialogReconstruction.getTrace();
2277 if (m_iDefaultNX > 0 && m_iDefaultNY > 0) {
2278 ImageFileDocument* pReconDoc = theApp->newImageDoc();
2280 sys_error (ERR_SEVERE, "Unable to create image file");
2283 ImageFile& imageFile = pReconDoc->getImageFile();
2284 const Projections& rProj = GetDocument()->getProjections();
2285 imageFile.setArraySize (m_iDefaultNX, m_iDefaultNY);
2287 Reconstructor* pReconstruct = new Reconstructor (rProj, imageFile, optFilterName.c_str(), m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(), optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace);
2290 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2291 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstruct, rProj, imageFile, m_iDefaultTrace, getFrameForChild());
2292 for (int iView = 0; iView < rProj.nView(); iView++) {
2295 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView)) {
2296 delete pDlgReconstruct;
2297 delete pReconstruct;
2298 pReconDoc->getView()->getFrame()->Close(true);
2303 while (pDlgReconstruct->isPaused()) {
2308 delete pDlgReconstruct;
2310 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT);
2311 for (int i = 0; i < rProj.nView(); i++) {
2312 pReconstruct->reconstructView (i, 1);
2313 if (! dlgProgress.Update(i + 1)) {
2314 delete pReconstruct;
2315 pReconDoc->getView()->getFrame()->Close(true);
2320 delete pReconstruct;
2321 if (theApp->getSetModifyNewDocs())
2322 pReconDoc->Modify(true);
2323 pReconDoc->UpdateAllViews(this);
2324 pReconDoc->getView()->getFrame()->Show(true);
2325 ImageFileView* rasterView = dynamic_cast<ImageFileView*>(pReconDoc->GetFirstView());
2327 rasterView->getFrame()->SetFocus();
2328 rasterView->OnUpdate (rasterView, NULL);
2330 std::ostringstream os;
2331 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();
2332 *theApp->getLog() << os.str().c_str() << "\n";
2333 imageFile.labelAdd (rProj.getLabel());
2334 imageFile.labelAdd (os.str().c_str(), timerRecon.timerEnd());
2340 ProjectionFileCanvas*
2341 ProjectionFileView::CreateCanvas (wxView *view, wxFrame *parent)
2343 ProjectionFileCanvas* pCanvas;
2345 parent->GetClientSize(&width, &height);
2347 pCanvas = new ProjectionFileCanvas (dynamic_cast<ProjectionFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
2349 pCanvas->SetScrollbars(20, 20, 50, 50);
2350 pCanvas->SetBackgroundColour(*wxWHITE);
2361 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2364 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2366 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2368 theApp->setIconForFrame (subframe);
2370 wxMenu *m_pFileMenu = new wxMenu;
2372 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2373 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2374 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2375 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2376 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2377 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2379 m_pFileMenu->AppendSeparator();
2380 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
2382 m_pFileMenu->AppendSeparator();
2383 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2384 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2385 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2387 m_pFileMenu->AppendSeparator();
2388 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2390 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2391 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2393 wxMenu *convert_menu = new wxMenu;
2394 convert_menu->Append (PJMENU_CONVERT_POLAR, "&Polar Image...\tCtrl-L");
2395 convert_menu->Append (PJMENU_CONVERT_FFT_POLAR, "&FFT->Polar Image...\tCtrl-I");
2397 wxMenu *reconstruct_menu = new wxMenu;
2398 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP, "&Filtered Backprojection...\tCtrl-R");
2399 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Fourier...\tCtrl-E");
2401 wxMenu *help_menu = new wxMenu;
2402 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2403 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
2404 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2406 wxMenuBar *menu_bar = new wxMenuBar;
2408 menu_bar->Append (m_pFileMenu, "&File");
2409 menu_bar->Append (convert_menu, "&Convert");
2410 menu_bar->Append (reconstruct_menu, "&Reconstruct");
2411 menu_bar->Append (help_menu, "&Help");
2413 subframe->SetMenuBar(menu_bar);
2414 subframe->Centre(wxBOTH);
2416 wxAcceleratorEntry accelEntries[11];
2417 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
2418 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
2419 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
2420 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
2421 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
2422 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
2423 accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
2424 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('L'), PJMENU_CONVERT_POLAR);
2425 accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('I'), PJMENU_CONVERT_FFT_POLAR);
2426 accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('R'), PJMENU_RECONSTRUCT_FBP);
2427 accelEntries[10].Set (wxACCEL_CTRL, static_cast<int>('E'), PJMENU_RECONSTRUCT_FOURIER);
2428 wxAcceleratorTable accelTable (11, accelEntries);
2429 subframe->SetAcceleratorTable (accelTable);
2436 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2438 m_pFrame = CreateChildFrame(doc, this);
2442 m_pFrame->GetClientSize(&width, &height);
2443 m_pFrame->SetTitle("ProjectionFileView");
2444 m_pCanvas = CreateCanvas(this, m_pFrame);
2447 int x, y; // X requires a forced resize
2448 m_pFrame->GetSize(&x, &y);
2449 m_pFrame->SetSize(-1, -1, x, y);
2452 m_pFrame->Show(true);
2459 ProjectionFileView::OnDraw (wxDC* dc)
2461 wxSize clientSize = m_pFrame->GetClientSize();
2462 wxSize bestSize = m_pCanvas->GetBestSize();
2464 if (clientSize.x > bestSize.x || clientSize.y > bestSize.y)
2465 m_pFrame->SetClientSize (bestSize);
2468 dc->DrawBitmap (m_bitmap, 0, 0, false);
2473 ProjectionFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2475 const Projections& rProj = GetDocument()->getProjections();
2476 const int nDet = rProj.nDet();
2477 const int nView = rProj.nView();
2478 if (nDet != 0 && nView != 0) {
2479 const DetectorArray& detarray = rProj.getDetectorArray(0);
2480 const DetectorValue* detval = detarray.detValues();
2481 double min = detval[0];
2482 double max = detval[0];
2483 for (int iy = 0; iy < nView; iy++) {
2484 const DetectorArray& detarray = rProj.getDetectorArray(iy);
2485 const DetectorValue* detval = detarray.detValues();
2486 for (int ix = 0; ix < nDet; ix++) {
2487 if (min > detval[ix])
2489 else if (max < detval[ix])
2494 unsigned char* imageData = new unsigned char [nDet * nView * 3];
2495 double scale = (max - min) / 255;
2496 for (int iy2 = 0; iy2 < nView; iy2++) {
2497 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
2498 const DetectorValue* detval = detarray.detValues();
2499 for (int ix = 0; ix < nDet; ix++) {
2500 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
2501 intensity = clamp(intensity, 0, 255);
2502 int baseAddr = (iy2 * nDet + ix) * 3;
2503 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
2506 wxImage image (nDet, nView, imageData, true);
2507 m_bitmap = image.ConvertToBitmap();
2511 xSize = clamp (xSize, 0, 800);
2512 ySize = clamp (ySize, 0, 800);
2513 m_pFrame->SetClientSize (xSize, ySize);
2514 m_pCanvas->SetScrollbars (20, 20, nDet/20, nView/20);
2518 m_pCanvas->Refresh();
2522 ProjectionFileView::OnClose (bool deleteWindow)
2524 if (! GetDocument() || ! GetDocument()->Close())
2528 //m_pCanvas->Show(false);
2529 //m_pCanvas->Clear();
2530 m_pCanvas->setView(NULL);
2533 wxString s(wxTheApp->GetAppName());
2535 m_pFrame->SetTitle(s);
2541 m_pFrame->Show(false);
2542 m_pFrame->Destroy();
2544 //m_pFrame->Close(true);
2553 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2554 : wxScrolledWindow(frame, -1, pos, size, style)
2559 PlotFileCanvas::~PlotFileCanvas ()
2565 PlotFileCanvas::OnDraw(wxDC& dc)
2568 m_pView->OnDraw(& dc);
2574 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
2576 BEGIN_EVENT_TABLE(PlotFileView, wxView)
2577 EVT_MENU(PJMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
2578 EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
2579 EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
2580 EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
2583 PlotFileView::PlotFileView()
2584 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pEZPlot(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
2588 PlotFileView::~PlotFileView()
2593 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2597 PlotFileView::OnProperties (wxCommandEvent& event)
2599 const PlotFile& rPlot = GetDocument()->getPlotFile();
2600 std::ostringstream os;
2601 os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
2602 rPlot.printHeadersBrief (os);
2603 *theApp->getLog() << os.str().c_str();
2604 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
2605 dialogMsg.ShowModal();
2610 PlotFileView::OnScaleAuto (wxCommandEvent& event)
2612 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2613 double min, max, mean, mode, median, stddev;
2614 rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
2615 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
2616 int iRetVal = dialogAutoScale.ShowModal();
2617 if (iRetVal == wxID_OK) {
2618 m_bMinSpecified = true;
2619 m_bMaxSpecified = true;
2621 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
2624 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
2625 OnUpdate (this, NULL);
2631 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
2633 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2637 if (! m_bMinSpecified || ! m_bMaxSpecified) {
2638 if (! rPlotFile.getMinMax (1, min, max)) {
2639 *theApp->getLog() << "Error: unable to find Min/Max\n";
2644 if (m_bMinSpecified)
2646 if (m_bMaxSpecified)
2649 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Y-axis Minimum & Maximum", min, max);
2650 int retVal = dialogMinMax.ShowModal();
2651 if (retVal == wxID_OK) {
2652 m_bMinSpecified = true;
2653 m_bMaxSpecified = true;
2654 m_dMinPixel = dialogMinMax.getMinimum();
2655 m_dMaxPixel = dialogMinMax.getMaximum();
2656 OnUpdate (this, NULL);
2661 PlotFileView::OnScaleFull (wxCommandEvent& event)
2663 if (m_bMinSpecified || m_bMaxSpecified) {
2664 m_bMinSpecified = false;
2665 m_bMaxSpecified = false;
2666 OnUpdate (this, NULL);
2672 PlotFileView::CreateCanvas (wxView *view, wxFrame *parent)
2674 PlotFileCanvas* pCanvas;
2676 parent->GetClientSize(&width, &height);
2678 pCanvas = new PlotFileCanvas (dynamic_cast<PlotFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
2680 pCanvas->SetBackgroundColour(*wxWHITE);
2691 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2694 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2696 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2698 theApp->setIconForFrame (subframe);
2700 wxMenu *m_pFileMenu = new wxMenu;
2702 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2703 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2704 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2705 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2706 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2707 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2709 m_pFileMenu->AppendSeparator();
2710 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
2712 m_pFileMenu->AppendSeparator();
2713 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2714 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2715 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2717 m_pFileMenu->AppendSeparator();
2718 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2720 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2721 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2723 wxMenu *view_menu = new wxMenu;
2724 view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...\tCtrl-E");
2725 view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
2726 view_menu->Append(PLOTMENU_VIEW_SCALE_FULL, "Display &Full Scale\tCtrl-U");
2728 wxMenu *help_menu = new wxMenu;
2729 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2730 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
2731 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2733 wxMenuBar *menu_bar = new wxMenuBar;
2735 menu_bar->Append(m_pFileMenu, "&File");
2736 menu_bar->Append(view_menu, "&View");
2737 menu_bar->Append(help_menu, "&Help");
2739 subframe->SetMenuBar(menu_bar);
2740 subframe->Centre(wxBOTH);
2742 wxAcceleratorEntry accelEntries[10];
2743 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
2744 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
2745 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
2746 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
2747 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
2748 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
2749 accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
2750 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('E'), PLOTMENU_VIEW_SCALE_MINMAX);
2751 accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('A'), PLOTMENU_VIEW_SCALE_AUTO);
2752 accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('U'), PLOTMENU_VIEW_SCALE_FULL);
2753 wxAcceleratorTable accelTable (10, accelEntries);
2754 subframe->SetAcceleratorTable (accelTable);
2761 PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
2763 m_pFrame = CreateChildFrame(doc, this);
2766 m_bMinSpecified = false;
2767 m_bMaxSpecified = false;
2768 m_dAutoScaleFactor = 1.;
2771 m_pFrame->GetClientSize(&width, &height);
2772 m_pFrame->SetTitle ("Plot File");
2773 m_pCanvas = CreateCanvas (this, m_pFrame);
2776 int x, y; // X requires a forced resize
2777 m_pFrame->GetSize(&x, &y);
2778 m_pFrame->SetSize(-1, -1, x, y);
2781 m_pFrame->Show(true);
2788 PlotFileView::OnDraw (wxDC* dc)
2790 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2791 const int iNColumns = rPlotFile.getNumColumns();
2792 const int iNRecords = rPlotFile.getNumRecords();
2794 if (iNColumns > 0 && iNRecords > 0) {
2796 m_pCanvas->GetClientSize (&xsize, &ysize);
2797 SGPDriver driver (dc, xsize, ysize);
2800 m_pEZPlot->plot (&sgp);
2806 PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2808 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2809 const int iNColumns = rPlotFile.getNumColumns();
2810 const int iNRecords = rPlotFile.getNumRecords();
2812 if (iNColumns > 0 && iNRecords > 0) {
2815 m_pEZPlot = new EZPlot;
2817 for (unsigned int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)
2818 m_pEZPlot->ezset (rPlotFile.getEzsetCommand (iEzset));
2820 if (m_bMinSpecified) {
2821 std::ostringstream os;
2822 os << "ymin " << m_dMinPixel;
2823 m_pEZPlot->ezset (os.str());
2826 if (m_bMaxSpecified) {
2827 std::ostringstream os;
2828 os << "ymax " << m_dMaxPixel;
2829 m_pEZPlot->ezset (os.str());
2832 m_pEZPlot->ezset("box");
2833 m_pEZPlot->ezset("grid");
2835 double* pdXaxis = new double [iNRecords];
2836 rPlotFile.getColumn (0, pdXaxis);
2838 double* pdY = new double [iNRecords];
2839 for (int iCol = 1; iCol < iNColumns; iCol++) {
2840 rPlotFile.getColumn (iCol, pdY);
2841 m_pEZPlot->addCurve (pdXaxis, pdY, iNRecords);
2849 m_pCanvas->Refresh();
2853 PlotFileView::OnClose (bool deleteWindow)
2855 if (! GetDocument() || ! GetDocument()->Close())
2859 // m_pCanvas->Show(false);
2860 // m_pCanvas->Clear();
2861 m_pCanvas->setView (NULL);
2864 wxString s(wxTheApp->GetAppName());
2866 m_pFrame->SetTitle(s);
2870 m_pFrame->SetView(NULL);
2873 m_pFrame->Show(false);
2874 m_pFrame->Destroy();
2875 //m_pFrame->Close(true);
2876 //GetDocumentManager()->ActivateView(this, FALSE, TRUE);
2884 ////////////////////////////////////////////////////////////////
2887 IMPLEMENT_DYNAMIC_CLASS(TextFileView, wxView)
2889 TextFileView::~TextFileView()
2891 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2892 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2895 bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2897 m_pFrame = CreateChildFrame(doc, this);
2898 SetFrame (m_pFrame);
2901 m_pFrame->GetClientSize(&width, &height);
2902 m_pFrame->SetTitle("TextFile");
2903 m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
2904 m_pFrame->SetTitle("Log");
2907 // X seems to require a forced resize
2909 frame->GetSize(&x, &y);
2910 frame->SetSize(-1, -1, x, y);
2913 m_pFrame->Show (true);
2919 // Handled by wxTextWindow
2920 void TextFileView::OnDraw(wxDC *WXUNUSED(dc) )
2924 void TextFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2929 TextFileView::OnClose (bool deleteWindow)
2931 // if (m_pFrame && m_pFrame->GetTitle() == "Log")
2934 if (! GetDocument() || ! GetDocument()->Close())
2937 m_pCanvas->Show(false);
2941 m_pFrame->SetView(NULL);
2943 m_pFrame->Show(false);
2944 m_pFrame->Destroy();
2945 //m_pFrame->Close(true);
2946 //GetDocumentManager()->ActivateView(this, FALSE, TRUE);
2959 TextFileView::CreateChildFrame (wxDocument *doc, wxView *view)
2962 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE);
2964 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE);
2966 theApp->setIconForFrame (subframe);
2968 wxMenu *m_pFileMenu = new wxMenu;
2970 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2971 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2972 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2973 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2974 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2975 // m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2977 m_pFileMenu->AppendSeparator();
2978 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2979 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2980 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2982 m_pFileMenu->AppendSeparator();
2983 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2985 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2986 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2988 wxMenu *help_menu = new wxMenu;
2989 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2990 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
2991 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2993 wxMenuBar *menu_bar = new wxMenuBar;
2995 menu_bar->Append(m_pFileMenu, "&File");
2996 menu_bar->Append(help_menu, "&Help");
2998 subframe->SetMenuBar(menu_bar);
2999 subframe->Centre(wxBOTH);
3001 wxAcceleratorEntry accelEntries[5];
3002 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
3003 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
3004 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
3005 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
3006 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
3007 wxAcceleratorTable accelTable (5, accelEntries);
3008 subframe->SetAcceleratorTable (accelTable);
3014 // Define a constructor for my text subwindow
3015 TextFileCanvas::TextFileCanvas (TextFileView* v, wxFrame* frame, const wxPoint& pos, const wxSize& size, long style)
3016 : wxTextCtrl (frame, -1, "", pos, size, style), m_pView(v)
3020 TextFileCanvas::~TextFileCanvas ()