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.76 2001/01/27 01:51:47 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_pCanvas(NULL), m_pFrame(NULL), m_bMinSpecified(false), m_bMaxSpecified(false), m_pFileMenu(0)
229 m_iDefaultExportFormatID = ImageFile::FORMAT_PNG;
232 ImageFileView::~ImageFileView()
234 theApp->getDocManager()->FileHistoryRemoveMenu (m_pFileMenu);
238 ImageFileView::OnProperties (wxCommandEvent& event)
240 const ImageFile& rIF = GetDocument()->getImageFile();
241 if (rIF.nx() == 0 || rIF.ny() == 0)
242 *theApp->getLog() << "Properties: empty imagefile\n";
244 const std::string& rFilename = rIF.getFilename();
245 std::ostringstream os;
246 double min, max, mean, mode, median, stddev;
247 rIF.statistics (rIF.getArray(), min, max, mean, mode, median, stddev);
248 os << "Filename: " << rFilename << "\n";
249 os << "Size: (" << rIF.nx() << "," << rIF.ny() << ")\n";
255 os << "\nMinimum: "<<min<<"\nMaximum: "<<max<<"\nMean: "<<mean<<"\nMedian: "<<median<<"\nMode: "<<mode<<"\nStandard Deviation: "<<stddev << "\n";
256 if (rIF.isComplex()) {
257 rIF.statistics (rIF.getImaginaryArray(), min, max, mean, mode, median, stddev);
258 os << "\nImaginary: min: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
260 if (rIF.nLabels() > 0) {
262 rIF.printLabelsBrief (os);
264 *theApp->getLog() << os.str().c_str();
265 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
266 dialogMsg.ShowModal();
271 ImageFileView::OnScaleAuto (wxCommandEvent& event)
273 const ImageFile& rIF = GetDocument()->getImageFile();
274 double min, max, mean, mode, median, stddev;
275 rIF.statistics(min, max, mean, mode, median, stddev);
276 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
277 int iRetVal = dialogAutoScale.ShowModal();
278 if (iRetVal == wxID_OK) {
279 m_bMinSpecified = true;
280 m_bMaxSpecified = true;
282 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
285 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
286 OnUpdate (this, NULL);
292 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
294 const ImageFile& rIF = GetDocument()->getImageFile();
296 if (! m_bMinSpecified && ! m_bMaxSpecified)
297 rIF.getMinMax (min, max);
304 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Image Minimum & Maximum", min, max);
305 int retVal = dialogMinMax.ShowModal();
306 if (retVal == wxID_OK) {
307 m_bMinSpecified = true;
308 m_bMaxSpecified = true;
309 m_dMinPixel = dialogMinMax.getMinimum();
310 m_dMaxPixel = dialogMinMax.getMaximum();
311 OnUpdate (this, NULL);
316 ImageFileView::OnScaleFull (wxCommandEvent& event)
318 if (m_bMinSpecified || m_bMaxSpecified) {
319 m_bMinSpecified = false;
320 m_bMaxSpecified = false;
321 OnUpdate (this, NULL);
326 ImageFileView::OnCompare (wxCommandEvent& event)
328 std::vector<ImageFileDocument*> vecIF;
329 theApp->getCompatibleImages (GetDocument(), vecIF);
331 if (vecIF.size() == 0) {
332 wxMessageBox("There are no compatible image files open for comparision", "No comparison images");
334 DialogGetComparisonImage dialogGetCompare(getFrameForChild(), "Get Comparison Image", vecIF, true);
336 if (dialogGetCompare.ShowModal() == wxID_OK) {
337 const ImageFile& rIF = GetDocument()->getImageFile();
338 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
339 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
340 std::ostringstream os;
341 double min, max, mean, mode, median, stddev;
342 rIF.statistics (min, max, mean, mode, median, stddev);
343 os << GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
344 rCompareIF.statistics (min, max, mean, mode, median, stddev);
345 os << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
348 rIF.comparativeStatistics (rCompareIF, d, r, e);
349 os << "Comparative Statistics: d=" << d << ", r=" << r << ", e=" << e << "\n";
350 *theApp->getLog() << os.str().c_str();
351 if (dialogGetCompare.getMakeDifferenceImage()) {
352 ImageFileDocument* pDifferenceDoc = theApp->newImageDoc();
353 if (! pDifferenceDoc) {
354 sys_error (ERR_SEVERE, "Unable to create image file");
357 ImageFile& differenceImage = pDifferenceDoc->getImageFile();
359 differenceImage.setArraySize (rIF.nx(), rIF.ny());
360 if (! rIF.subtractImages (rCompareIF, differenceImage)) {
361 pDifferenceDoc->DeleteAllViews();
365 wxString s = GetFrame()->GetTitle() + ": ";
366 differenceImage.labelsCopy (rIF, s.c_str());
367 s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
368 differenceImage.labelsCopy (rCompareIF, s.c_str());
369 std::ostringstream osLabel;
370 osLabel << "Compare image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str()
371 << " and " << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": "
373 differenceImage.labelAdd (os.str().c_str());
374 if (theApp->getSetModifyNewDocs())
375 pDifferenceDoc->Modify(true);
376 pDifferenceDoc->UpdateAllViews(this);
377 pDifferenceDoc->getView()->OnUpdate (this, NULL);
378 pDifferenceDoc->getView()->getFrame()->Show(true);
380 wxMessageBox(os.str().c_str(), "Image Comparison");
386 ImageFileView::OnInvertValues (wxCommandEvent& event)
388 ImageFile& rIF = GetDocument()->getImageFile();
389 rIF.invertPixelValues (rIF);
390 rIF.labelAdd ("Invert Pixel Values");
391 if (theApp->getSetModifyNewDocs())
392 GetDocument()->Modify(TRUE);
393 GetDocument()->UpdateAllViews(this);
397 ImageFileView::OnSquare (wxCommandEvent& event)
399 ImageFile& rIF = GetDocument()->getImageFile();
401 rIF.labelAdd ("Square Pixel Values");
402 if (theApp->getSetModifyNewDocs())
403 GetDocument()->Modify(TRUE);
404 GetDocument()->UpdateAllViews(this);
408 ImageFileView::OnSquareRoot (wxCommandEvent& event)
410 ImageFile& rIF = GetDocument()->getImageFile();
412 rIF.labelAdd ("Square-root Pixel Values");
413 if (theApp->getSetModifyNewDocs())
414 GetDocument()->Modify(TRUE);
415 GetDocument()->UpdateAllViews(this);
419 ImageFileView::OnLog (wxCommandEvent& event)
421 ImageFile& rIF = GetDocument()->getImageFile();
423 rIF.labelAdd ("Logrithm base-e Pixel Values");
424 if (theApp->getSetModifyNewDocs())
425 GetDocument()->Modify(TRUE);
426 GetDocument()->UpdateAllViews(this);
430 ImageFileView::OnExp (wxCommandEvent& event)
432 ImageFile& rIF = GetDocument()->getImageFile();
434 rIF.labelAdd ("Exponent base-e Pixel Values");
435 if (theApp->getSetModifyNewDocs())
436 GetDocument()->Modify(TRUE);
437 GetDocument()->UpdateAllViews(this);
441 ImageFileView::OnAdd (wxCommandEvent& event)
443 std::vector<ImageFileDocument*> vecIF;
444 theApp->getCompatibleImages (GetDocument(), vecIF);
446 if (vecIF.size() == 0) {
447 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
449 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Add", vecIF, false);
451 if (dialogGetCompare.ShowModal() == wxID_OK) {
452 ImageFile& rIF = GetDocument()->getImageFile();
453 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
454 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
455 ImageFileDocument* pNewDoc = theApp->newImageDoc();
457 sys_error (ERR_SEVERE, "Unable to create image file");
460 ImageFile& newImage = pNewDoc->getImageFile();
461 newImage.setArraySize (rIF.nx(), rIF.ny());
462 rIF.addImages (rRHSIF, newImage);
463 std::ostringstream os;
464 os << "Add image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
465 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
466 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
467 newImage.labelsCopy (rIF, s.c_str());
468 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
469 newImage.labelsCopy (rRHSIF, s.c_str());
470 newImage.labelAdd (os.str().c_str());
471 *theApp->getLog() << os.str().c_str() << "\n";
472 if (theApp->getSetModifyNewDocs())
473 pNewDoc->Modify(TRUE);
474 pNewDoc->UpdateAllViews(this);
475 pNewDoc->getView()->OnUpdate (this, NULL);
476 pNewDoc->getView()->getFrame()->Show(true);
482 ImageFileView::OnSubtract (wxCommandEvent& event)
484 std::vector<ImageFileDocument*> vecIF;
485 theApp->getCompatibleImages (GetDocument(), vecIF);
487 if (vecIF.size() == 0) {
488 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
490 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Subtract", vecIF, false);
492 if (dialogGetCompare.ShowModal() == wxID_OK) {
493 ImageFile& rIF = GetDocument()->getImageFile();
494 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
495 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
496 ImageFileDocument* pNewDoc = theApp->newImageDoc();
498 sys_error (ERR_SEVERE, "Unable to create image file");
501 ImageFile& newImage = pNewDoc->getImageFile();
502 newImage.setArraySize (rIF.nx(), rIF.ny());
503 rIF.subtractImages (rRHSIF, newImage);
504 std::ostringstream os;
505 os << "Subtract image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
506 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
507 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
508 newImage.labelsCopy (rIF, s.c_str());
509 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
510 newImage.labelsCopy (rRHSIF, s.c_str());
511 newImage.labelAdd (os.str().c_str());
512 *theApp->getLog() << os.str().c_str() << "\n";
513 if (theApp->getSetModifyNewDocs())
514 pNewDoc->Modify(TRUE);
515 pNewDoc->UpdateAllViews(this);
516 pNewDoc->getView()->OnUpdate (this, NULL);
517 pNewDoc->getView()->getFrame()->Show(true);
523 ImageFileView::OnMultiply (wxCommandEvent& event)
525 std::vector<ImageFileDocument*> vecIF;
526 theApp->getCompatibleImages (GetDocument(), vecIF);
528 if (vecIF.size() == 0) {
529 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
531 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Multiply", vecIF, false);
533 if (dialogGetCompare.ShowModal() == wxID_OK) {
534 ImageFile& rIF = GetDocument()->getImageFile();
535 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
536 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
537 ImageFileDocument* pNewDoc = theApp->newImageDoc();
539 sys_error (ERR_SEVERE, "Unable to create image file");
542 ImageFile& newImage = pNewDoc->getImageFile();
543 newImage.setArraySize (rIF.nx(), rIF.ny());
544 rIF.multiplyImages (rRHSIF, newImage);
545 std::ostringstream os;
546 os << "Multiply image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
547 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
548 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
549 newImage.labelsCopy (rIF, s.c_str());
550 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
551 newImage.labelsCopy (rRHSIF, s.c_str());
552 newImage.labelAdd (os.str().c_str());
553 *theApp->getLog() << os.str().c_str() << "\n";
554 if (theApp->getSetModifyNewDocs())
555 pNewDoc->Modify(TRUE);
556 pNewDoc->UpdateAllViews(this);
557 pNewDoc->getView()->OnUpdate (this, NULL);
558 pNewDoc->getView()->getFrame()->Show(true);
564 ImageFileView::OnDivide (wxCommandEvent& event)
566 std::vector<ImageFileDocument*> vecIF;
567 theApp->getCompatibleImages (GetDocument(), vecIF);
569 if (vecIF.size() == 0) {
570 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
572 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Divide", vecIF, false);
574 if (dialogGetCompare.ShowModal() == wxID_OK) {
575 ImageFile& rIF = GetDocument()->getImageFile();
576 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
577 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
578 ImageFileDocument* pNewDoc = theApp->newImageDoc();
580 sys_error (ERR_SEVERE, "Unable to create image file");
583 ImageFile& newImage = pNewDoc->getImageFile();
584 newImage.setArraySize (rIF.nx(), rIF.ny());
585 rIF.divideImages (rRHSIF, newImage);
586 std::ostringstream os;
587 os << "Divide image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " by "
588 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
589 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
590 newImage.labelsCopy (rIF, s.c_str());
591 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
592 newImage.labelsCopy (rRHSIF, s.c_str());
593 newImage.labelAdd (os.str().c_str());
594 *theApp->getLog() << os.str().c_str() << "\n";
595 if (theApp->getSetModifyNewDocs())
596 pNewDoc->Modify(TRUE);
597 pNewDoc->UpdateAllViews(this);
598 pNewDoc->getView()->OnUpdate (this, NULL);
599 pNewDoc->getView()->getFrame()->Show(true);
607 ImageFileView::OnFFT (wxCommandEvent& event)
609 ImageFile& rIF = GetDocument()->getImageFile();
611 rIF.labelAdd ("FFT Image");
612 m_bMinSpecified = false;
613 m_bMaxSpecified = false;
614 if (theApp->getSetModifyNewDocs())
615 GetDocument()->Modify(TRUE);
616 GetDocument()->UpdateAllViews(this);
620 ImageFileView::OnIFFT (wxCommandEvent& event)
622 ImageFile& rIF = GetDocument()->getImageFile();
624 rIF.labelAdd ("IFFT Image");
625 m_bMinSpecified = false;
626 m_bMaxSpecified = false;
627 if (theApp->getSetModifyNewDocs())
628 GetDocument()->Modify(TRUE);
629 GetDocument()->UpdateAllViews(this);
633 ImageFileView::OnFFTRows (wxCommandEvent& event)
635 ImageFile& rIF = GetDocument()->getImageFile();
637 rIF.labelAdd ("FFT Rows");
638 m_bMinSpecified = false;
639 m_bMaxSpecified = false;
640 if (theApp->getSetModifyNewDocs())
641 GetDocument()->Modify(TRUE);
642 GetDocument()->UpdateAllViews(this);
646 ImageFileView::OnIFFTRows (wxCommandEvent& event)
648 ImageFile& rIF = GetDocument()->getImageFile();
650 rIF.labelAdd ("IFFT Rows");
651 m_bMinSpecified = false;
652 m_bMaxSpecified = false;
653 if (theApp->getSetModifyNewDocs())
654 GetDocument()->Modify(TRUE);
655 GetDocument()->UpdateAllViews(this);
659 ImageFileView::OnFFTCols (wxCommandEvent& event)
661 ImageFile& rIF = GetDocument()->getImageFile();
663 rIF.labelAdd ("FFT Columns");
664 m_bMinSpecified = false;
665 m_bMaxSpecified = false;
666 if (theApp->getSetModifyNewDocs())
667 GetDocument()->Modify(TRUE);
668 GetDocument()->UpdateAllViews(this);
672 ImageFileView::OnIFFTCols (wxCommandEvent& event)
674 ImageFile& rIF = GetDocument()->getImageFile();
676 rIF.labelAdd ("IFFT Columns");
677 m_bMinSpecified = false;
678 m_bMaxSpecified = false;
679 if (theApp->getSetModifyNewDocs())
680 GetDocument()->Modify(TRUE);
681 GetDocument()->UpdateAllViews(this);
686 ImageFileView::OnFourier (wxCommandEvent& event)
688 ImageFile& rIF = GetDocument()->getImageFile();
689 wxProgressDialog dlgProgress (wxString("Fourier"), wxString("Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
691 rIF.labelAdd ("Fourier Image");
692 m_bMinSpecified = false;
693 m_bMaxSpecified = false;
694 if (theApp->getSetModifyNewDocs())
695 GetDocument()->Modify(TRUE);
696 GetDocument()->UpdateAllViews(this);
700 ImageFileView::OnInverseFourier (wxCommandEvent& event)
702 ImageFile& rIF = GetDocument()->getImageFile();
703 wxProgressDialog dlgProgress (wxString("Inverse Fourier"), wxString("Inverse Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
704 rIF.inverseFourier (rIF);
705 rIF.labelAdd ("Inverse Fourier Image");
706 m_bMinSpecified = false;
707 m_bMaxSpecified = false;
708 if (theApp->getSetModifyNewDocs())
709 GetDocument()->Modify(TRUE);
710 GetDocument()->UpdateAllViews(this);
714 ImageFileView::OnShuffleNaturalToFourierOrder (wxCommandEvent& event)
716 ImageFile& rIF = GetDocument()->getImageFile();
717 Fourier::shuffleNaturalToFourierOrder (rIF);
718 rIF.labelAdd ("Shuffle Natural To Fourier Order");
719 m_bMinSpecified = false;
720 m_bMaxSpecified = false;
721 if (theApp->getSetModifyNewDocs())
722 GetDocument()->Modify(TRUE);
723 GetDocument()->UpdateAllViews(this);
727 ImageFileView::OnShuffleFourierToNaturalOrder (wxCommandEvent& event)
729 ImageFile& rIF = GetDocument()->getImageFile();
730 Fourier::shuffleFourierToNaturalOrder (rIF);
731 rIF.labelAdd ("Shuffle Fourier To Natural Order");
732 m_bMinSpecified = false;
733 m_bMaxSpecified = false;
734 if (theApp->getSetModifyNewDocs())
735 GetDocument()->Modify(TRUE);
736 GetDocument()->UpdateAllViews(this);
740 ImageFileView::OnMagnitude (wxCommandEvent& event)
742 ImageFile& rIF = GetDocument()->getImageFile();
743 if (rIF.isComplex()) {
745 rIF.labelAdd ("Magnitude of complex-image");
746 m_bMinSpecified = false;
747 m_bMaxSpecified = false;
748 if (theApp->getSetModifyNewDocs())
749 GetDocument()->Modify(TRUE);
750 GetDocument()->UpdateAllViews(this);
755 ImageFileView::OnPhase (wxCommandEvent& event)
757 ImageFile& rIF = GetDocument()->getImageFile();
758 if (rIF.isComplex()) {
760 rIF.labelAdd ("Phase of complex-image");
761 m_bMinSpecified = false;
762 m_bMaxSpecified = false;
763 if (theApp->getSetModifyNewDocs())
764 GetDocument()->Modify(TRUE);
765 GetDocument()->UpdateAllViews(this);
771 ImageFileView::CreateCanvas (wxView *view, wxFrame *parent)
773 ImageFileCanvas* pCanvas;
775 parent->GetClientSize(&width, &height);
777 pCanvas = new ImageFileCanvas (dynamic_cast<ImageFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
779 pCanvas->SetScrollbars(20, 20, 50, 50);
780 pCanvas->SetBackgroundColour(*wxWHITE);
791 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
794 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
796 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
798 theApp->setIconForFrame (subframe);
800 wxMenu *m_pFileMenu = new wxMenu;
802 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
803 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
804 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
805 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
806 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
807 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
809 m_pFileMenu->AppendSeparator();
810 m_pFileMenu->Append(IFMENU_FILE_PROPERTIES, "P&roperties");
811 m_pFileMenu->Append(IFMENU_FILE_EXPORT, "&Export...");
813 m_pFileMenu->AppendSeparator();
814 m_pFileMenu->Append(wxID_PRINT, "&Print...");
815 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
816 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
818 m_pFileMenu->AppendSeparator();
819 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
821 theApp->getDocManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
822 theApp->getDocManager()->FileHistoryUseMenu(m_pFileMenu);
824 wxMenu *view_menu = new wxMenu;
825 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale S&et...\tCtrl-E");
826 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
827 view_menu->Append(IFMENU_VIEW_SCALE_FULL, "Display F&ull Scale\tCtrl-U");
829 wxMenu* filter_menu = new wxMenu;
830 filter_menu->Append (IFMENU_FILTER_INVERTVALUES, "&Invert Values");
831 filter_menu->Append (IFMENU_FILTER_SQUARE, "&Square");
832 filter_menu->Append (IFMENU_FILTER_SQRT, "Square &Root");
833 filter_menu->Append (IFMENU_FILTER_LOG, "&Log");
834 filter_menu->Append (IFMENU_FILTER_EXP, "&Exp");
835 filter_menu->AppendSeparator();
837 filter_menu->Append (IFMENU_FILTER_FFT, "2D &FFT");
838 filter_menu->Append (IFMENU_FILTER_IFFT, "2D &IFFT");
839 filter_menu->Append (IFMENU_FILTER_FFT_ROWS, "FFT Rows");
840 filter_menu->Append (IFMENU_FILTER_IFFT_ROWS, "IFFT Rows");
841 filter_menu->Append (IFMENU_FILTER_FFT_COLS, "FFT Columns");
842 filter_menu->Append (IFMENU_FILTER_IFFT_COLS, "IFFT Columns");
843 filter_menu->Append (IFMENU_FILTER_FOURIER, "F&ourier");
844 filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "Inverse Fo&urier");
846 filter_menu->Append (IFMENU_FILTER_FOURIER, "&Fourier");
847 filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "&Inverse Fourier");
849 filter_menu->Append (IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, "S&huffle Fourier to Natural Order");
850 filter_menu->Append (IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, "Shu&ffle Natural to Fourier Order");
851 filter_menu->Append (IFMENU_FILTER_MAGNITUDE, "&Magnitude");
852 filter_menu->Append (IFMENU_FILTER_PHASE, "&Phase");
854 wxMenu* image_menu = new wxMenu;
855 image_menu->Append (IFMENU_IMAGE_ADD, "&Add...");
856 image_menu->Append (IFMENU_IMAGE_SUBTRACT, "&Subtract...");
857 image_menu->Append (IFMENU_IMAGE_MULTIPLY, "&Multiply...");
858 image_menu->Append (IFMENU_IMAGE_DIVIDE, "&Divide...");
859 image_menu->AppendSeparator();
860 image_menu->Append (IFMENU_IMAGE_SCALESIZE, "S&cale Size...");
862 wxMenu *analyze_menu = new wxMenu;
863 analyze_menu->Append (IFMENU_PLOT_ROW, "Plot &Row");
864 analyze_menu->Append (IFMENU_PLOT_COL, "Plot &Column");
865 analyze_menu->Append (IFMENU_PLOT_HISTOGRAM, "Plot &Histogram");
866 analyze_menu->AppendSeparator();
867 analyze_menu->Append (IFMENU_PLOT_FFT_ROW, "Plot FFT Row");
868 analyze_menu->Append (IFMENU_PLOT_FFT_COL, "Plot FFT Column");
869 analyze_menu->AppendSeparator();
870 analyze_menu->Append (IFMENU_COMPARE_IMAGES, "Compare &Images...");
871 analyze_menu->Append (IFMENU_COMPARE_ROW, "Compare &Row");
872 analyze_menu->Append (IFMENU_COMPARE_COL, "Compare &Column");
874 wxMenu *help_menu = new wxMenu;
875 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
876 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
877 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
879 wxMenuBar *menu_bar = new wxMenuBar;
881 menu_bar->Append(m_pFileMenu, "&File");
882 menu_bar->Append(view_menu, "&View");
883 menu_bar->Append(image_menu, "&Image");
884 menu_bar->Append(filter_menu, "Fi<er");
885 menu_bar->Append(analyze_menu, "&Analyze");
886 menu_bar->Append(help_menu, "&Help");
888 subframe->SetMenuBar(menu_bar);
890 subframe->Centre(wxBOTH);
892 wxAcceleratorEntry accelEntries[10];
893 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
894 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
895 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
896 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
897 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
898 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
899 accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
900 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('A'), IFMENU_VIEW_SCALE_AUTO);
901 accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('U'), IFMENU_VIEW_SCALE_FULL);
902 accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('E'), IFMENU_VIEW_SCALE_MINMAX);
903 wxAcceleratorTable accelTable (10, accelEntries);
904 subframe->SetAcceleratorTable (accelTable);
911 ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
913 m_pFrame = CreateChildFrame(doc, this);
916 m_bMinSpecified = false;
917 m_bMaxSpecified = false;
918 m_dAutoScaleFactor = 1.;
921 m_pFrame->GetClientSize (&width, &height);
922 m_pFrame->SetTitle("ImageFileView");
923 m_pCanvas = CreateCanvas (this, m_pFrame);
925 int x, y; // X requires a forced resize
926 m_pFrame->GetSize(&x, &y);
927 m_pFrame->SetSize(-1, -1, x, y);
928 m_pFrame->SetFocus();
929 m_pFrame->Show(true);
936 ImageFileView::OnDraw (wxDC* dc)
938 wxSize sizeWindow = m_pFrame->GetClientSize();
939 wxSize sizeBest = m_pCanvas->GetBestSize();
940 if (sizeWindow.x > sizeBest.x || sizeWindow.y > sizeBest.y)
941 m_pFrame->SetClientSize (sizeBest);
944 dc->DrawBitmap(m_bitmap, 0, 0, false);
946 int xCursor, yCursor;
947 if (m_pCanvas->GetCurrentCursor (xCursor, yCursor))
948 m_pCanvas->DrawRubberBandCursor (*dc, xCursor, yCursor);
953 ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
955 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
956 ImageFileArrayConst v = rIF.getArray();
959 if (v != NULL && nx != 0 && ny != 0) {
960 if (! m_bMinSpecified || ! m_bMaxSpecified) {
962 rIF.getMinMax (min, max);
963 if (! m_bMinSpecified)
965 if (! m_bMaxSpecified)
968 double scaleWidth = m_dMaxPixel - m_dMinPixel;
970 unsigned char* imageData = new unsigned char [nx * ny * 3];
971 for (int ix = 0; ix < nx; ix++) {
972 for (int iy = 0; iy < ny; iy++) {
973 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
974 int intensity = static_cast<int>(scaleValue + 0.5);
975 intensity = clamp (intensity, 0, 255);
976 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
977 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
980 wxImage image (nx, ny, imageData, true);
981 m_bitmap = image.ConvertToBitmap();
985 ySize = clamp (ySize, 0, 800);
986 m_pFrame->SetClientSize (xSize, ySize);
987 m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20);
988 m_pCanvas->SetBackgroundColour(*wxWHITE);
992 m_pCanvas->Refresh();
996 ImageFileView::OnClose (bool deleteWindow)
998 if (! GetDocument() || ! GetDocument()->Close())
1003 m_pCanvas->Show(false);
1004 m_pCanvas->setView(NULL);
1007 wxString s(theApp->GetAppName());
1009 m_pFrame->SetTitle(s);
1015 m_pFrame->Show(false);
1016 m_pFrame->Destroy();
1024 ImageFileView::OnExport (wxCommandEvent& event)
1026 ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
1027 ImageFileArrayConst v = rIF.getArray();
1030 if (v != NULL && nx != 0 && ny != 0) {
1031 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1033 rIF.getMinMax (min, max);
1034 if (! m_bMinSpecified)
1036 if (! m_bMaxSpecified)
1040 DialogExportParameters dialogExport (getFrameForChild(), m_iDefaultExportFormatID);
1041 if (dialogExport.ShowModal() == wxID_OK) {
1042 wxString strFormatName (dialogExport.getFormatName ());
1043 m_iDefaultExportFormatID = ImageFile::convertFormatNameToID (strFormatName.c_str());
1046 wxString strWildcard;
1047 if (m_iDefaultExportFormatID == ImageFile::FORMAT_PGM || m_iDefaultExportFormatID == ImageFile::FORMAT_PGMASCII) {
1049 strWildcard = "PGM Files (*.pgm)|*.pgm";
1052 else if (m_iDefaultExportFormatID == ImageFile::FORMAT_PNG || m_iDefaultExportFormatID == ImageFile::FORMAT_PNG16) {
1054 strWildcard = "PNG Files (*.png)|*.png";
1058 const wxString& strFilename = wxFileSelector (wxString("Export Filename"), wxString(""),
1059 wxString(""), strExt, strWildcard, wxOVERWRITE_PROMPT | wxHIDE_READONLY | wxSAVE);
1061 rIF.exportImage (strFormatName.c_str(), strFilename.c_str(), 1, 1, m_dMinPixel, m_dMaxPixel);
1062 *theApp->getLog() << "Exported file " << strFilename << "\n";
1069 ImageFileView::OnScaleSize (wxCommandEvent& event)
1071 ImageFile& rIF = GetDocument()->getImageFile();
1072 unsigned int iOldNX = rIF.nx();
1073 unsigned int iOldNY = rIF.ny();
1075 DialogGetXYSize dialogGetXYSize (getFrameForChild(), "Set New X & Y Dimensions", iOldNX, iOldNY);
1076 if (dialogGetXYSize.ShowModal() == wxID_OK) {
1077 unsigned int iNewNX = dialogGetXYSize.getXSize();
1078 unsigned int iNewNY = dialogGetXYSize.getYSize();
1079 std::ostringstream os;
1080 os << "Scale Size from (" << iOldNX << "," << iOldNY << ") to (" << iNewNX << "," << iNewNY << ")";
1081 ImageFileDocument* pScaledDoc = theApp->newImageDoc();
1083 sys_error (ERR_SEVERE, "Unable to create image file");
1086 ImageFile& rScaledIF = pScaledDoc->getImageFile();
1087 rScaledIF.setArraySize (iNewNX, iNewNY);
1088 rScaledIF.labelsCopy (rIF);
1089 rScaledIF.labelAdd (os.str().c_str());
1090 rIF.scaleImage (rScaledIF);
1091 *theApp->getLog() << os.str().c_str() << "\n";
1092 if (theApp->getSetModifyNewDocs())
1093 pScaledDoc->Modify(TRUE);
1094 pScaledDoc->UpdateAllViews (this);
1095 pScaledDoc->getView()->OnUpdate (this, NULL);
1096 pScaledDoc->getView()->getFrame()->Show(true);
1101 ImageFileView::OnPlotRow (wxCommandEvent& event)
1103 int xCursor, yCursor;
1104 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1105 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1109 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
1110 ImageFileArrayConst v = rIF.getArray();
1111 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1115 if (v != NULL && yCursor < ny) {
1116 double* pX = new double [nx];
1117 double* pYReal = new double [nx];
1118 double *pYImag = NULL;
1119 double *pYMag = NULL;
1120 if (rIF.isComplex()) {
1121 pYImag = new double [nx];
1122 pYMag = new double [nx];
1124 for (int i = 0; i < nx; i++) {
1126 pYReal[i] = v[i][yCursor];
1127 if (rIF.isComplex()) {
1128 pYImag[i] = vImag[i][yCursor];
1129 pYMag[i] = ::sqrt (v[i][yCursor] * v[i][yCursor] + vImag[i][yCursor] * vImag[i][yCursor]);
1132 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1134 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1136 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1137 std::ostringstream os;
1138 os << "Row " << yCursor;
1139 std::string title("title ");
1141 rPlotFile.addEzsetCommand (title.c_str());
1142 rPlotFile.addEzsetCommand ("xlabel Column");
1143 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1144 rPlotFile.addEzsetCommand ("lxfrac 0");
1145 rPlotFile.addEzsetCommand ("box");
1146 rPlotFile.addEzsetCommand ("grid");
1147 rPlotFile.addEzsetCommand ("curve 1");
1148 rPlotFile.addEzsetCommand ("color 1");
1149 if (rIF.isComplex()) {
1150 rPlotFile.addEzsetCommand ("dash 1");
1151 rPlotFile.addEzsetCommand ("curve 2");
1152 rPlotFile.addEzsetCommand ("color 4");
1153 rPlotFile.addEzsetCommand ("dash 3");
1154 rPlotFile.addEzsetCommand ("curve 3");
1155 rPlotFile.addEzsetCommand ("color 0");
1156 rPlotFile.addEzsetCommand ("solid");
1157 rPlotFile.setCurveSize (4, nx);
1159 rPlotFile.setCurveSize (2, nx);
1160 rPlotFile.addColumn (0, pX);
1161 rPlotFile.addColumn (1, pYReal);
1162 if (rIF.isComplex()) {
1163 rPlotFile.addColumn (2, pYImag);
1164 rPlotFile.addColumn (3, pYMag);
1166 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1167 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1168 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1169 *theApp->getLog() << os.str().c_str() << "\n";
1170 rPlotFile.addDescription (os.str().c_str());
1174 if (rIF.isComplex()) {
1178 if (theApp->getSetModifyNewDocs())
1179 pPlotDoc->Modify(true);
1180 pPlotDoc->UpdateAllViews();
1185 ImageFileView::OnPlotCol (wxCommandEvent& event)
1187 int xCursor, yCursor;
1188 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1189 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1193 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
1194 ImageFileArrayConst v = rIF.getArray();
1195 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1199 if (v != NULL && xCursor < nx) {
1200 double* pX = new double [ny];
1201 double* pYReal = new double [ny];
1202 double* pYImag = NULL;
1203 double* pYMag = NULL;
1204 if (rIF.isComplex()) {
1205 pYImag = new double [ny];
1206 pYMag = new double [ny];
1208 for (int i = 0; i < ny; i++) {
1210 pYReal[i] = v[xCursor][i];
1211 if (rIF.isComplex()) {
1212 pYImag[i] = vImag[xCursor][i];
1213 pYMag[i] = ::sqrt (v[xCursor][i] * v[xCursor][i] + vImag[xCursor][i] * vImag[xCursor][i]);
1216 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1218 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1220 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1221 std::ostringstream os;
1222 os << "Column " << xCursor;
1223 std::string title("title ");
1225 rPlotFile.addEzsetCommand (title.c_str());
1226 rPlotFile.addEzsetCommand ("xlabel Row");
1227 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1228 rPlotFile.addEzsetCommand ("lxfrac 0");
1229 rPlotFile.addEzsetCommand ("box");
1230 rPlotFile.addEzsetCommand ("grid");
1231 rPlotFile.addEzsetCommand ("curve 1");
1232 rPlotFile.addEzsetCommand ("color 1");
1233 if (rIF.isComplex()) {
1234 rPlotFile.addEzsetCommand ("dash 1");
1235 rPlotFile.addEzsetCommand ("curve 2");
1236 rPlotFile.addEzsetCommand ("color 4");
1237 rPlotFile.addEzsetCommand ("dash 3");
1238 rPlotFile.addEzsetCommand ("curve 3");
1239 rPlotFile.addEzsetCommand ("color 0");
1240 rPlotFile.addEzsetCommand ("solid");
1241 rPlotFile.setCurveSize (4, ny);
1243 rPlotFile.setCurveSize (2, ny);
1244 rPlotFile.addColumn (0, pX);
1245 rPlotFile.addColumn (1, pYReal);
1246 if (rIF.isComplex()) {
1247 rPlotFile.addColumn (2, pYImag);
1248 rPlotFile.addColumn (3, pYMag);
1250 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1251 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1252 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1253 *theApp->getLog() << os.str().c_str() << "\n";
1254 rPlotFile.addDescription (os.str().c_str());
1258 if (rIF.isComplex()) {
1262 if (theApp->getSetModifyNewDocs())
1263 pPlotDoc->Modify(true);
1264 pPlotDoc->UpdateAllViews();
1270 ImageFileView::OnPlotFFTRow (wxCommandEvent& event)
1272 int xCursor, yCursor;
1273 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1274 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1278 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
1279 ImageFileArrayConst v = rIF.getArray();
1280 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1284 if (v != NULL && yCursor < ny) {
1285 fftw_complex* pcIn = new fftw_complex [nx];
1288 for (i = 0; i < nx; i++) {
1289 pcIn[i].re = v[i][yCursor];
1290 if (rIF.isComplex())
1291 pcIn[i].im = vImag[i][yCursor];
1296 fftw_plan plan = fftw_create_plan (nx, FFTW_FORWARD, FFTW_IN_PLACE);
1297 fftw_one (plan, pcIn, NULL);
1298 fftw_destroy_plan (plan);
1300 double* pX = new double [nx];
1301 double* pYReal = new double [nx];
1302 double* pYImag = new double [nx];
1303 double* pYMag = new double [nx];
1304 for (i = 0; i < nx; i++) {
1306 pYReal[i] = pcIn[i].re;
1307 pYImag[i] = pcIn[i].im;
1308 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1310 Fourier::shuffleFourierToNaturalOrder (pYReal, nx);
1311 Fourier::shuffleFourierToNaturalOrder (pYImag, nx);
1312 Fourier::shuffleFourierToNaturalOrder (pYMag, nx);
1314 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1316 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1318 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1319 std::ostringstream os;
1320 os << "Row " << yCursor;
1321 std::string title("title ");
1323 rPlotFile.addEzsetCommand (title.c_str());
1324 rPlotFile.addEzsetCommand ("xlabel Column");
1325 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1326 rPlotFile.addEzsetCommand ("lxfrac 0");
1327 rPlotFile.addEzsetCommand ("curve 1");
1328 rPlotFile.addEzsetCommand ("color 1");
1329 rPlotFile.addEzsetCommand ("dash 1");
1330 rPlotFile.addEzsetCommand ("curve 2");
1331 rPlotFile.addEzsetCommand ("color 4");
1332 rPlotFile.addEzsetCommand ("dash 3");
1333 rPlotFile.addEzsetCommand ("curve 3");
1334 rPlotFile.addEzsetCommand ("color 0");
1335 rPlotFile.addEzsetCommand ("solid");
1336 rPlotFile.addEzsetCommand ("box");
1337 rPlotFile.addEzsetCommand ("grid");
1338 rPlotFile.setCurveSize (4, nx);
1339 rPlotFile.addColumn (0, pX);
1340 rPlotFile.addColumn (1, pYReal);
1341 rPlotFile.addColumn (2, pYImag);
1342 rPlotFile.addColumn (3, pYMag);
1343 for (int iL = 0; iL < rIF.nLabels(); iL++)
1344 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1345 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1346 *theApp->getLog() << os.str().c_str() << "\n";
1347 rPlotFile.addDescription (os.str().c_str());
1355 if (theApp->getSetModifyNewDocs())
1356 pPlotDoc->Modify(true);
1357 pPlotDoc->UpdateAllViews();
1362 ImageFileView::OnPlotFFTCol (wxCommandEvent& event)
1364 int xCursor, yCursor;
1365 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1366 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1370 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
1371 ImageFileArrayConst v = rIF.getArray();
1372 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1376 if (v != NULL && xCursor < nx) {
1377 fftw_complex* pcIn = new fftw_complex [ny];
1378 double *pdTemp = new double [ny];
1381 for (i = 0; i < ny; i++)
1382 pdTemp[i] = v[xCursor][i];
1383 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1384 for (i = 0; i < ny; i++)
1385 pcIn[i].re = pdTemp[i];
1387 for (i = 0; i < ny; i++) {
1388 if (rIF.isComplex())
1389 pdTemp[i] = vImag[xCursor][i];
1393 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1394 for (i = 0; i < ny; i++)
1395 pcIn[i].im = pdTemp[i];
1397 fftw_plan plan = fftw_create_plan (ny, FFTW_BACKWARD, FFTW_IN_PLACE);
1398 fftw_one (plan, pcIn, NULL);
1399 fftw_destroy_plan (plan);
1401 double* pX = new double [ny];
1402 double* pYReal = new double [ny];
1403 double* pYImag = new double [ny];
1404 double* pYMag = new double [ny];
1405 for (i = 0; i < ny; i++) {
1407 pYReal[i] = pcIn[i].re;
1408 pYImag[i] = pcIn[i].im;
1409 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1412 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1414 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1416 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1417 std::ostringstream os;
1418 os << "Column " << xCursor;
1419 std::string title("title ");
1421 rPlotFile.addEzsetCommand (title.c_str());
1422 rPlotFile.addEzsetCommand ("xlabel Column");
1423 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1424 rPlotFile.addEzsetCommand ("lxfrac 0");
1425 rPlotFile.addEzsetCommand ("curve 1");
1426 rPlotFile.addEzsetCommand ("color 1");
1427 rPlotFile.addEzsetCommand ("dash 1");
1428 rPlotFile.addEzsetCommand ("curve 2");
1429 rPlotFile.addEzsetCommand ("color 4");
1430 rPlotFile.addEzsetCommand ("dash 3");
1431 rPlotFile.addEzsetCommand ("curve 3");
1432 rPlotFile.addEzsetCommand ("color 0");
1433 rPlotFile.addEzsetCommand ("solid");
1434 rPlotFile.addEzsetCommand ("box");
1435 rPlotFile.addEzsetCommand ("grid");
1436 rPlotFile.setCurveSize (4, ny);
1437 rPlotFile.addColumn (0, pX);
1438 rPlotFile.addColumn (1, pYReal);
1439 rPlotFile.addColumn (2, pYImag);
1440 rPlotFile.addColumn (3, pYMag);
1441 for (int iL = 0; iL < rIF.nLabels(); iL++)
1442 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1443 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1444 *theApp->getLog() << os.str().c_str() << "\n";
1445 rPlotFile.addDescription (os.str().c_str());
1454 if (theApp->getSetModifyNewDocs())
1455 pPlotDoc->Modify(true);
1456 pPlotDoc->UpdateAllViews();
1462 ImageFileView::OnCompareCol (wxCommandEvent& event)
1464 int xCursor, yCursor;
1465 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1466 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1470 std::vector<ImageFileDocument*> vecIFDoc;
1471 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1472 if (vecIFDoc.size() == 0) {
1473 wxMessageBox ("No compatible images for Column Comparison", "Error");
1476 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1478 if (dialogGetCompare.ShowModal() == wxID_OK) {
1479 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1480 const ImageFile& rIF = GetDocument()->getImageFile();
1481 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1483 ImageFileArrayConst v1 = rIF.getArray();
1484 ImageFileArrayConst v2 = rCompareIF.getArray();
1488 if (v1 != NULL && xCursor < nx) {
1489 double* pX = new double [ny];
1490 double* pY1 = new double [ny];
1491 double* pY2 = new double [ny];
1492 for (int i = 0; i < ny; i++) {
1494 pY1[i] = v1[xCursor][i];
1495 pY2[i] = v2[xCursor][i];
1497 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1499 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1501 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1502 std::ostringstream os;
1503 os << "Column " << xCursor << " Comparison";
1504 std::string title("title ");
1506 rPlotFile.addEzsetCommand (title.c_str());
1507 rPlotFile.addEzsetCommand ("xlabel Row");
1508 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1509 rPlotFile.addEzsetCommand ("lxfrac 0");
1510 rPlotFile.addEzsetCommand ("curve 1");
1511 rPlotFile.addEzsetCommand ("color 2");
1512 rPlotFile.addEzsetCommand ("curve 2");
1513 rPlotFile.addEzsetCommand ("color 4");
1514 rPlotFile.addEzsetCommand ("dash 5");
1515 rPlotFile.addEzsetCommand ("box");
1516 rPlotFile.addEzsetCommand ("grid");
1517 rPlotFile.setCurveSize (3, ny);
1518 rPlotFile.addColumn (0, pX);
1519 rPlotFile.addColumn (1, pY1);
1520 rPlotFile.addColumn (2, pY2);
1523 for (iL = 0; iL < rIF.nLabels(); iL++) {
1524 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1526 s += rIF.labelGet(iL).getLabelString();
1527 rPlotFile.addDescription (s.c_str());
1529 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1530 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1532 s += rCompareIF.labelGet(iL).getLabelString();
1533 rPlotFile.addDescription (s.c_str());
1535 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1536 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1537 *theApp->getLog() << os.str().c_str() << "\n";
1538 rPlotFile.addDescription (os.str().c_str());
1543 if (theApp->getSetModifyNewDocs())
1544 pPlotDoc->Modify(true);
1545 pPlotDoc->UpdateAllViews();
1551 ImageFileView::OnCompareRow (wxCommandEvent& event)
1553 int xCursor, yCursor;
1554 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1555 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1559 std::vector<ImageFileDocument*> vecIFDoc;
1560 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1562 if (vecIFDoc.size() == 0) {
1563 wxMessageBox ("No compatible images for Row Comparison", "Error");
1567 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1569 if (dialogGetCompare.ShowModal() == wxID_OK) {
1570 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1571 const ImageFile& rIF = GetDocument()->getImageFile();
1572 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1574 ImageFileArrayConst v1 = rIF.getArray();
1575 ImageFileArrayConst v2 = rCompareIF.getArray();
1579 if (v1 != NULL && yCursor < ny) {
1580 double* pX = new double [nx];
1581 double* pY1 = new double [nx];
1582 double* pY2 = new double [nx];
1583 for (int i = 0; i < nx; i++) {
1585 pY1[i] = v1[i][yCursor];
1586 pY2[i] = v2[i][yCursor];
1588 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1590 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1592 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1593 std::ostringstream os;
1594 os << "Row " << yCursor << " Comparison";
1595 std::string title("title ");
1597 rPlotFile.addEzsetCommand (title.c_str());
1598 rPlotFile.addEzsetCommand ("xlabel Column");
1599 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1600 rPlotFile.addEzsetCommand ("lxfrac 0");
1601 rPlotFile.addEzsetCommand ("curve 1");
1602 rPlotFile.addEzsetCommand ("color 2");
1603 rPlotFile.addEzsetCommand ("curve 2");
1604 rPlotFile.addEzsetCommand ("color 4");
1605 rPlotFile.addEzsetCommand ("dash 5");
1606 rPlotFile.addEzsetCommand ("box");
1607 rPlotFile.addEzsetCommand ("grid");
1608 rPlotFile.setCurveSize (3, nx);
1609 rPlotFile.addColumn (0, pX);
1610 rPlotFile.addColumn (1, pY1);
1611 rPlotFile.addColumn (2, pY2);
1613 for (iL = 0; iL < rIF.nLabels(); iL++) {
1614 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1616 s += rIF.labelGet(iL).getLabelString();
1617 rPlotFile.addDescription (s.c_str());
1619 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1620 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1622 s += rCompareIF.labelGet(iL).getLabelString();
1623 rPlotFile.addDescription (s.c_str());
1625 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1626 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1627 *theApp->getLog() << os.str().c_str() << "\n";
1628 rPlotFile.addDescription (os.str().c_str());
1633 if (theApp->getSetModifyNewDocs())
1634 pPlotDoc->Modify(true);
1635 pPlotDoc->UpdateAllViews();
1640 static int NUMBER_HISTOGRAM_BINS = 256;
1643 ImageFileView::OnPlotHistogram (wxCommandEvent& event)
1645 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
1646 ImageFileArrayConst v = rIF.getArray();
1650 if (v != NULL && nx > 0 && ny > 0) {
1651 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1653 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1657 double* pX = new double [NUMBER_HISTOGRAM_BINS];
1658 double* pY = new double [NUMBER_HISTOGRAM_BINS];
1660 rIF.getMinMax (dMin, dMax);
1661 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
1663 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
1664 pX[i] = dMin + (i + 0.5) * dBinWidth;
1667 for (int ix = 0; ix < nx; ix++)
1668 for (int iy = 0; iy < ny; iy++) {
1669 int iBin = nearest<int> ((v[ix][iy] - dMin) / dBinWidth);
1670 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
1674 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1675 std::ostringstream os;
1677 std::string title("title ");
1679 rPlotFile.addEzsetCommand (title.c_str());
1680 rPlotFile.addEzsetCommand ("xlabel Pixel Value");
1681 rPlotFile.addEzsetCommand ("ylabel Count");
1682 rPlotFile.addEzsetCommand ("box");
1683 rPlotFile.addEzsetCommand ("grid");
1684 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
1685 rPlotFile.addColumn (0, pX);
1686 rPlotFile.addColumn (1, pY);
1687 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++) {
1688 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1690 s += rIF.labelGet(iL).getLabelString();
1691 rPlotFile.addDescription (s.c_str());
1693 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1694 *theApp->getLog() << os.str().c_str() << "\n";
1695 rPlotFile.addDescription (os.str().c_str());
1698 if (theApp->getSetModifyNewDocs())
1699 pPlotDoc->Modify(true);
1700 pPlotDoc->UpdateAllViews();
1707 PhantomCanvas::PhantomCanvas (PhantomFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1708 : wxScrolledWindow(frame, -1, pos, size, style)
1713 PhantomCanvas::~PhantomCanvas ()
1719 PhantomCanvas::OnDraw (wxDC& dc)
1722 m_pView->OnDraw(& dc);
1728 IMPLEMENT_DYNAMIC_CLASS(PhantomFileView, wxView)
1730 BEGIN_EVENT_TABLE(PhantomFileView, wxView)
1731 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomFileView::OnProperties)
1732 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomFileView::OnRasterize)
1733 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomFileView::OnProjections)
1736 PhantomFileView::PhantomFileView()
1737 : wxView(), m_pCanvas(NULL), m_pFrame(NULL), m_pFileMenu(0)
1739 m_iDefaultNDet = 367;
1740 m_iDefaultNView = 320;
1741 m_iDefaultNSample = 1;
1742 m_dDefaultRotation = 1;
1743 m_dDefaultFocalLength = 2;
1744 m_dDefaultFieldOfView = 1;
1745 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
1746 m_iDefaultTrace = Trace::TRACE_NONE;
1748 m_iDefaultRasterNX = 256;
1749 m_iDefaultRasterNY = 256;
1750 m_iDefaultRasterNSamples = 2;
1753 PhantomFileView::~PhantomFileView()
1755 theApp->getDocManager()->FileHistoryRemoveMenu (m_pFileMenu);
1759 PhantomFileView::OnProperties (wxCommandEvent& event)
1761 const int idPhantom = GetDocument()->getPhantomID();
1762 const wxString& namePhantom = GetDocument()->getPhantomName();
1763 std::ostringstream os;
1764 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")" << "\n";
1765 const Phantom& rPhantom = GetDocument()->getPhantom();
1766 rPhantom.printDefinitions (os);
1768 rPhantom.print (os);
1770 *theApp->getLog() << os.str().c_str() << "\n";
1771 wxMessageBox (os.str().c_str(), "Phantom Properties");
1776 PhantomFileView::OnProjections (wxCommandEvent& event)
1778 DialogGetProjectionParameters dialogProjection (getFrameForChild(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView, m_iDefaultGeometry, m_iDefaultTrace);
1779 int retVal = dialogProjection.ShowModal();
1780 if (retVal == wxID_OK) {
1781 m_iDefaultNDet = dialogProjection.getNDet();
1782 m_iDefaultNView = dialogProjection.getNView();
1783 m_iDefaultNSample = dialogProjection.getNSamples();
1784 m_iDefaultTrace = dialogProjection.getTrace();
1785 m_dDefaultRotation = dialogProjection.getRotAngle();
1786 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
1787 m_dDefaultFieldOfView = dialogProjection.getFieldOfViewRatio();
1788 wxString sGeometry = dialogProjection.getGeometry();
1789 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
1791 if (m_iDefaultNDet > 0 && m_iDefaultNView > 0 && sGeometry != "") {
1792 const Phantom& rPhantom = GetDocument()->getPhantom();
1793 ProjectionFileDocument* pProjectionDoc = theApp->newProjectionDoc();
1794 if (! pProjectionDoc) {
1795 sys_error (ERR_SEVERE, "Unable to create projection document");
1798 Projections& rProj = pProjectionDoc->getProjections();
1799 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView);
1800 if (theScanner.fail()) {
1801 *theApp->getLog() << "Failed making scanner: " << theScanner.failMessage().c_str() << "\n";
1804 rProj.initFromScanner (theScanner);
1805 m_dDefaultRotation /= PI; // convert back to PI units
1808 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
1809 ProjectionsDialog dialogProjections (theScanner, rProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(getFrameForChild()));
1810 for (int iView = 0; iView < rProj.nView(); iView++) {
1813 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
1814 pProjectionDoc->DeleteAllViews();
1819 while (dialogProjections.isPaused()) {
1825 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT);
1826 for (int i = 0; i < rProj.nView(); i++) {
1827 theScanner.collectProjections (rProj, rPhantom, i, 1, true, m_iDefaultTrace);
1828 if (! dlgProgress.Update (i+1)) {
1829 pProjectionDoc->DeleteAllViews();
1835 std::ostringstream os;
1836 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();
1837 rProj.setCalcTime (timer.timerEnd());
1838 rProj.setRemark (os.str());
1839 *theApp->getLog() << os.str().c_str() << "\n";
1843 ProjectionFileView* projView = dynamic_cast<ProjectionFileView*>(pProjectionDoc->GetFirstView());
1845 projView->getFrame()->SetFocus();
1846 projView->OnUpdate (projView, NULL);
1848 if (wxView* pView = pProjectionDoc->GetFirstView()) {
1849 if (wxFrame* pFrame = pView->GetFrame()) {
1853 theApp->getDocManager()->ActivateView (pView, true, false);
1856 if (theApp->getSetModifyNewDocs())
1857 pProjectionDoc->Modify(true);
1858 pProjectionDoc->getView()->getFrame()->Show(true);
1859 pProjectionDoc->UpdateAllViews(this);
1866 PhantomFileView::OnRasterize (wxCommandEvent& event)
1868 DialogGetRasterParameters dialogRaster (getFrameForChild(), m_iDefaultRasterNX, m_iDefaultRasterNY, m_iDefaultRasterNSamples);
1869 int retVal = dialogRaster.ShowModal();
1870 if (retVal == wxID_OK) {
1871 m_iDefaultRasterNX = dialogRaster.getXSize();
1872 m_iDefaultRasterNY = dialogRaster.getYSize();
1873 m_iDefaultRasterNSamples = dialogRaster.getNSamples();
1874 if (m_iDefaultRasterNSamples < 1)
1875 m_iDefaultRasterNSamples = 1;
1876 if (m_iDefaultRasterNX > 0 && m_iDefaultRasterNY > 0) {
1877 const Phantom& rPhantom = GetDocument()->getPhantom();
1878 ImageFileDocument* pRasterDoc = theApp->newImageDoc();
1880 sys_error (ERR_SEVERE, "Unable to create image file");
1883 ImageFile& imageFile = pRasterDoc->getImageFile();
1885 imageFile.setArraySize (m_iDefaultRasterNX, m_iDefaultRasterNX);
1886 wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"), imageFile.nx() + 1, getFrameForChild(), wxPD_CAN_ABORT);
1888 for (unsigned int i = 0; i < imageFile.nx(); i++) {
1889 rPhantom.convertToImagefile (imageFile, m_iDefaultRasterNSamples, Trace::TRACE_NONE, i, 1, true);
1890 if (! dlgProgress.Update(i+1)) {
1891 pRasterDoc->DeleteAllViews();
1895 if (theApp->getSetModifyNewDocs())
1896 pRasterDoc->Modify(true);
1897 pRasterDoc->UpdateAllViews(this);
1898 pRasterDoc->getView()->getFrame()->Show(true);
1899 std::ostringstream os;
1900 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << m_iDefaultRasterNX << ", YSize="
1901 << m_iDefaultRasterNY << ", nSamples=" << m_iDefaultRasterNSamples;
1902 *theApp->getLog() << os.str().c_str() << "\n";
1903 imageFile.labelAdd (os.str().c_str(), timer.timerEnd());
1904 ImageFileView* rasterView = dynamic_cast<ImageFileView*>(pRasterDoc->GetFirstView());
1906 rasterView->getFrame()->SetFocus();
1907 rasterView->OnUpdate (rasterView, NULL);
1916 PhantomFileView::CreateCanvas (wxView *view, wxFrame *parent)
1918 PhantomCanvas* pCanvas;
1920 parent->GetClientSize(&width, &height);
1922 pCanvas = new PhantomCanvas (dynamic_cast<PhantomFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
1924 pCanvas->SetBackgroundColour(*wxWHITE);
1935 PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view)
1938 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
1940 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
1942 theApp->setIconForFrame (subframe);
1944 wxMenu *m_pFileMenu = new wxMenu;
1946 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
1947 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
1948 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
1949 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
1950 m_pFileMenu->Append(wxID_CLOSE, "&Close");
1952 m_pFileMenu->AppendSeparator();
1953 m_pFileMenu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties");
1955 m_pFileMenu->AppendSeparator();
1956 m_pFileMenu->Append(wxID_PRINT, "&Print...");
1957 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
1958 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
1960 m_pFileMenu->AppendSeparator();
1961 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
1963 theApp->getDocManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
1964 theApp->getDocManager()->FileHistoryUseMenu(m_pFileMenu);
1966 wxMenu *process_menu = new wxMenu;
1967 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...\tCtrl-R");
1968 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...\tCtrl-J");
1970 wxMenu *help_menu = new wxMenu;
1971 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
1972 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
1973 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
1975 wxMenuBar *menu_bar = new wxMenuBar;
1977 menu_bar->Append(m_pFileMenu, "&File");
1978 menu_bar->Append(process_menu, "&Process");
1979 menu_bar->Append(help_menu, "&Help");
1981 subframe->SetMenuBar(menu_bar);
1982 subframe->Centre(wxBOTH);
1984 wxAcceleratorEntry accelEntries[8];
1985 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
1986 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
1987 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
1988 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
1989 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
1990 accelEntries[5].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
1991 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('J'), PHMMENU_PROCESS_PROJECTIONS);
1992 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('R'), PHMMENU_PROCESS_RASTERIZE);
1993 wxAcceleratorTable accelTable (8, accelEntries);
1994 subframe->SetAcceleratorTable (accelTable);
2001 PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2003 m_pFrame = CreateChildFrame(doc, this);
2007 m_pFrame->GetClientSize(&width, &height);
2008 m_pFrame->SetTitle("PhantomFileView");
2009 m_pCanvas = CreateCanvas (this, m_pFrame);
2012 int x, y; // X requires a forced resize
2013 m_pFrame->GetSize(&x, &y);
2014 m_pFrame->SetSize(-1, -1, x, y);
2017 m_pFrame->Show(true);
2024 PhantomFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2027 m_pCanvas->Refresh();
2031 PhantomFileView::OnClose (bool deleteWindow)
2033 if (! GetDocument() || ! GetDocument()->Close())
2038 m_pCanvas->setView(NULL);
2039 m_pCanvas->Show(false);
2042 wxString s(wxTheApp->GetAppName());
2044 m_pFrame->SetTitle(s);
2050 m_pFrame->Show(false);
2051 m_pFrame->Destroy();
2060 PhantomFileView::OnDraw (wxDC* dc)
2063 m_pCanvas->GetClientSize (&xsize, &ysize);
2064 SGPDriver driver (dc, xsize, ysize);
2066 const Phantom& rPhantom = GetDocument()->getPhantom();
2067 sgp.setColor (C_RED);
2068 rPhantom.show (sgp);
2073 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2074 : wxScrolledWindow(frame, -1, pos, size, style)
2079 ProjectionFileCanvas::~ProjectionFileCanvas ()
2085 ProjectionFileCanvas::OnDraw(wxDC& dc)
2088 m_pView->OnDraw(& dc);
2092 ProjectionFileCanvas::GetBestSize () const
2096 Projections& rProj = m_pView->GetDocument()->getProjections();
2097 best.Set (rProj.nDet(), rProj.nView());
2104 // ProjectionFileView
2106 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
2108 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
2109 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
2110 EVT_MENU(PJMENU_RECONSTRUCT_FBP, ProjectionFileView::OnReconstructFBP)
2111 EVT_MENU(PJMENU_CONVERT_POLAR, ProjectionFileView::OnConvertPolar)
2112 EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
2115 ProjectionFileView::ProjectionFileView()
2116 : wxView(), m_pCanvas(NULL), m_pFrame(NULL), m_pFileMenu(0)
2120 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
2121 m_dDefaultFilterParam = 1.;
2123 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
2124 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
2126 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
2127 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
2129 m_iDefaultZeropad = 1;
2130 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF3;
2131 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
2132 m_iDefaultInterpParam = 1;
2133 m_iDefaultTrace = Trace::TRACE_NONE;
2135 m_iDefaultPolarNX = 256;
2136 m_iDefaultPolarNY = 256;
2137 m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR;
2138 m_iDefaultPolarZeropad = 1;
2141 ProjectionFileView::~ProjectionFileView()
2143 theApp->getDocManager()->FileHistoryRemoveMenu (m_pFileMenu);
2147 ProjectionFileView::OnProperties (wxCommandEvent& event)
2149 const Projections& rProj = GetDocument()->getProjections();
2150 std::ostringstream os;
2151 rProj.printScanInfo(os);
2152 *theApp->getLog() << os.str().c_str();
2153 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
2154 dialogMsg.ShowModal();
2159 ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
2161 Projections& rProj = GetDocument()->getProjections();
2162 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2163 m_iDefaultPolarInterpolation, -1);
2164 if (dialogPolar.ShowModal() == wxID_OK) {
2165 wxString strInterpolation (dialogPolar.getInterpolationName());
2166 m_iDefaultPolarNX = dialogPolar.getXSize();
2167 m_iDefaultPolarNY = dialogPolar.getYSize();
2168 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2169 ImageFile& rIF = pPolarDoc->getImageFile();
2171 sys_error (ERR_SEVERE, "Unable to create image file");
2174 rIF.setArraySize (m_iDefaultPolarNX, m_iDefaultPolarNY);
2175 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2176 rProj.convertPolar (rIF, m_iDefaultPolarInterpolation);
2177 rIF.labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2178 std::ostringstream os;
2179 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to polar image: xSize="
2180 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2181 << strInterpolation.c_str();
2182 *theApp->getLog() << os.str().c_str() << "\n";
2183 rIF.labelAdd (os.str().c_str());
2184 if (theApp->getSetModifyNewDocs())
2185 pPolarDoc->Modify(true);
2186 pPolarDoc->UpdateAllViews();
2187 pPolarDoc->getView()->OnUpdate (this, NULL);
2188 pPolarDoc->getView()->getFrame()->Show(true);
2193 ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
2195 Projections& rProj = GetDocument()->getProjections();
2196 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert to FFT Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2197 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad);
2198 if (dialogPolar.ShowModal() == wxID_OK) {
2199 wxString strInterpolation (dialogPolar.getInterpolationName());
2200 m_iDefaultPolarNX = dialogPolar.getXSize();
2201 m_iDefaultPolarNY = dialogPolar.getYSize();
2202 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2203 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2204 ImageFile& rIF = pPolarDoc->getImageFile();
2206 sys_error (ERR_SEVERE, "Unable to create image file");
2209 rIF.setArraySize (m_iDefaultPolarNX, m_iDefaultPolarNY);
2210 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2211 rProj.convertFFTPolar (rIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad);
2212 rIF.labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2213 std::ostringstream os;
2214 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to FFT polar image: xSize="
2215 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2216 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2217 *theApp->getLog() << os.str().c_str() << "\n";
2218 rIF.labelAdd (os.str().c_str());
2219 if (theApp->getSetModifyNewDocs())
2220 pPolarDoc->Modify(true);
2221 pPolarDoc->UpdateAllViews();
2222 pPolarDoc->getView()->OnUpdate (this, NULL);
2223 pPolarDoc->getView()->getFrame()->Show(true);
2228 ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
2230 wxMessageBox ("Fourier Reconstruction is not yet supported", "Unimplemented function");
2234 ProjectionFileView::OnReconstructFBP (wxCommandEvent& event)
2236 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);
2238 int retVal = dialogReconstruction.ShowModal();
2239 if (retVal == wxID_OK) {
2240 m_iDefaultNX = dialogReconstruction.getXSize();
2241 m_iDefaultNY = dialogReconstruction.getYSize();
2242 wxString optFilterName = dialogReconstruction.getFilterName();
2243 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
2244 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
2245 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
2246 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
2247 m_iDefaultZeropad = dialogReconstruction.getZeropad();
2248 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
2249 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
2250 wxString optInterpName = dialogReconstruction.getInterpName();
2251 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
2252 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
2253 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
2254 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
2255 m_iDefaultTrace = dialogReconstruction.getTrace();
2256 if (m_iDefaultNX > 0 && m_iDefaultNY > 0) {
2257 ImageFileDocument* pReconDoc = theApp->newImageDoc();
2259 sys_error (ERR_SEVERE, "Unable to create image file");
2262 ImageFile& imageFile = pReconDoc->getImageFile();
2263 const Projections& rProj = GetDocument()->getProjections();
2264 imageFile.setArraySize (m_iDefaultNX, m_iDefaultNY);
2266 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);
2269 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2270 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstruct, rProj, imageFile, m_iDefaultTrace, getFrameForChild());
2271 for (int iView = 0; iView < rProj.nView(); iView++) {
2274 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView)) {
2275 delete pDlgReconstruct;
2276 delete pReconstruct;
2277 pReconDoc->DeleteAllViews();
2282 while (pDlgReconstruct->isPaused()) {
2287 delete pDlgReconstruct;
2289 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT);
2290 for (int i = 0; i < rProj.nView(); i++) {
2291 pReconstruct->reconstructView (i, 1);
2292 if (! dlgProgress.Update(i + 1)) {
2293 delete pReconstruct;
2294 pReconDoc->DeleteAllViews();
2299 delete pReconstruct;
2300 if (theApp->getSetModifyNewDocs())
2301 pReconDoc->Modify(true);
2302 pReconDoc->UpdateAllViews(this);
2303 pReconDoc->getView()->getFrame()->Show(true);
2304 ImageFileView* rasterView = dynamic_cast<ImageFileView*>(pReconDoc->GetFirstView());
2306 rasterView->getFrame()->SetFocus();
2307 rasterView->OnUpdate (rasterView, NULL);
2309 std::ostringstream os;
2310 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();
2311 *theApp->getLog() << os.str().c_str() << "\n";
2312 imageFile.labelAdd (rProj.getLabel());
2313 imageFile.labelAdd (os.str().c_str(), timerRecon.timerEnd());
2319 ProjectionFileCanvas*
2320 ProjectionFileView::CreateCanvas (wxView *view, wxFrame *parent)
2322 ProjectionFileCanvas* pCanvas;
2324 parent->GetClientSize(&width, &height);
2326 pCanvas = new ProjectionFileCanvas (dynamic_cast<ProjectionFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
2328 pCanvas->SetScrollbars(20, 20, 50, 50);
2329 pCanvas->SetBackgroundColour(*wxWHITE);
2340 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2343 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2345 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2347 theApp->setIconForFrame (subframe);
2349 wxMenu *m_pFileMenu = new wxMenu;
2351 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2352 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2353 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2354 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2355 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2356 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2358 m_pFileMenu->AppendSeparator();
2359 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
2361 m_pFileMenu->AppendSeparator();
2362 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2363 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2364 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2366 m_pFileMenu->AppendSeparator();
2367 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2369 theApp->getDocManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2370 theApp->getDocManager()->FileHistoryUseMenu(m_pFileMenu);
2372 wxMenu *convert_menu = new wxMenu;
2373 convert_menu->Append (PJMENU_CONVERT_POLAR, "&Polar Image...\tCtrl-L");
2374 convert_menu->Append (PJMENU_CONVERT_FFT_POLAR, "&FFT->Polar Image...\tCtrl-I");
2376 wxMenu *reconstruct_menu = new wxMenu;
2377 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP, "&Filtered Backprojection...\tCtrl-R");
2378 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Fourier...\tCtrl-E");
2380 wxMenu *help_menu = new wxMenu;
2381 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2382 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
2383 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2385 wxMenuBar *menu_bar = new wxMenuBar;
2387 menu_bar->Append (m_pFileMenu, "&File");
2388 menu_bar->Append (convert_menu, "&Convert");
2389 menu_bar->Append (reconstruct_menu, "&Reconstruct");
2390 menu_bar->Append (help_menu, "&Help");
2392 subframe->SetMenuBar(menu_bar);
2393 subframe->Centre(wxBOTH);
2395 wxAcceleratorEntry accelEntries[11];
2396 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
2397 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
2398 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
2399 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
2400 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
2401 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
2402 accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
2403 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('L'), PJMENU_CONVERT_POLAR);
2404 accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('I'), PJMENU_CONVERT_FFT_POLAR);
2405 accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('R'), PJMENU_RECONSTRUCT_FBP);
2406 accelEntries[10].Set (wxACCEL_CTRL, static_cast<int>('E'), PJMENU_RECONSTRUCT_FOURIER);
2407 wxAcceleratorTable accelTable (11, accelEntries);
2408 subframe->SetAcceleratorTable (accelTable);
2415 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2417 m_pFrame = CreateChildFrame(doc, this);
2421 m_pFrame->GetClientSize(&width, &height);
2422 m_pFrame->SetTitle("ProjectionFileView");
2423 m_pCanvas = CreateCanvas(this, m_pFrame);
2426 int x, y; // X requires a forced resize
2427 m_pFrame->GetSize(&x, &y);
2428 m_pFrame->SetSize(-1, -1, x, y);
2431 m_pFrame->Show(true);
2438 ProjectionFileView::OnDraw (wxDC* dc)
2440 wxSize clientSize = m_pFrame->GetClientSize();
2441 wxSize bestSize = m_pCanvas->GetBestSize();
2443 if (clientSize.x > bestSize.x || clientSize.y > bestSize.y)
2444 m_pFrame->SetClientSize (bestSize);
2447 dc->DrawBitmap (m_bitmap, 0, 0, false);
2452 ProjectionFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2454 const Projections& rProj = GetDocument()->getProjections();
2455 const int nDet = rProj.nDet();
2456 const int nView = rProj.nView();
2457 if (nDet != 0 && nView != 0) {
2458 const DetectorArray& detarray = rProj.getDetectorArray(0);
2459 const DetectorValue* detval = detarray.detValues();
2460 double min = detval[0];
2461 double max = detval[0];
2462 for (int iy = 0; iy < nView; iy++) {
2463 const DetectorArray& detarray = rProj.getDetectorArray(iy);
2464 const DetectorValue* detval = detarray.detValues();
2465 for (int ix = 0; ix < nDet; ix++) {
2466 if (min > detval[ix])
2468 else if (max < detval[ix])
2473 unsigned char* imageData = new unsigned char [nDet * nView * 3];
2474 double scale = (max - min) / 255;
2475 for (int iy2 = 0; iy2 < nView; iy2++) {
2476 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
2477 const DetectorValue* detval = detarray.detValues();
2478 for (int ix = 0; ix < nDet; ix++) {
2479 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
2480 intensity = clamp(intensity, 0, 255);
2481 int baseAddr = (iy2 * nDet + ix) * 3;
2482 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
2485 wxImage image (nDet, nView, imageData, true);
2486 m_bitmap = image.ConvertToBitmap();
2490 xSize = clamp (xSize, 0, 800);
2491 ySize = clamp (ySize, 0, 800);
2492 m_pFrame->SetClientSize (xSize, ySize);
2493 m_pCanvas->SetScrollbars (20, 20, nDet/20, nView/20);
2497 m_pCanvas->Refresh();
2501 ProjectionFileView::OnClose (bool deleteWindow)
2503 if (! GetDocument() || ! GetDocument()->Close())
2508 m_pCanvas->setView(NULL);
2509 m_pCanvas->Show(false);
2512 wxString s(wxTheApp->GetAppName());
2514 m_pFrame->SetTitle(s);
2520 m_pFrame->Show(false);
2521 m_pFrame->Destroy();
2531 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2532 : wxScrolledWindow(frame, -1, pos, size, style)
2537 PlotFileCanvas::~PlotFileCanvas ()
2543 PlotFileCanvas::OnDraw(wxDC& dc)
2546 m_pView->OnDraw(& dc);
2552 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
2554 BEGIN_EVENT_TABLE(PlotFileView, wxView)
2555 EVT_MENU(PJMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
2556 EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
2557 EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
2558 EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
2561 PlotFileView::PlotFileView()
2562 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pEZPlot(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
2566 PlotFileView::~PlotFileView()
2571 theApp->getDocManager()->FileHistoryRemoveMenu (m_pFileMenu);
2575 PlotFileView::OnProperties (wxCommandEvent& event)
2577 const PlotFile& rPlot = GetDocument()->getPlotFile();
2578 std::ostringstream os;
2579 os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
2580 rPlot.printHeadersBrief (os);
2581 *theApp->getLog() << os.str().c_str();
2582 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
2583 dialogMsg.ShowModal();
2588 PlotFileView::OnScaleAuto (wxCommandEvent& event)
2590 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2591 double min, max, mean, mode, median, stddev;
2592 rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
2593 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
2594 int iRetVal = dialogAutoScale.ShowModal();
2595 if (iRetVal == wxID_OK) {
2596 m_bMinSpecified = true;
2597 m_bMaxSpecified = true;
2599 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
2602 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
2603 OnUpdate (this, NULL);
2609 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
2611 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2615 if (! m_bMinSpecified || ! m_bMaxSpecified) {
2616 if (! rPlotFile.getMinMax (1, min, max)) {
2617 *theApp->getLog() << "Error: unable to find Min/Max\n";
2622 if (m_bMinSpecified)
2624 if (m_bMaxSpecified)
2627 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Y-axis Minimum & Maximum", min, max);
2628 int retVal = dialogMinMax.ShowModal();
2629 if (retVal == wxID_OK) {
2630 m_bMinSpecified = true;
2631 m_bMaxSpecified = true;
2632 m_dMinPixel = dialogMinMax.getMinimum();
2633 m_dMaxPixel = dialogMinMax.getMaximum();
2634 OnUpdate (this, NULL);
2639 PlotFileView::OnScaleFull (wxCommandEvent& event)
2641 if (m_bMinSpecified || m_bMaxSpecified) {
2642 m_bMinSpecified = false;
2643 m_bMaxSpecified = false;
2644 OnUpdate (this, NULL);
2650 PlotFileView::CreateCanvas (wxView *view, wxFrame *parent)
2652 PlotFileCanvas* pCanvas;
2654 parent->GetClientSize(&width, &height);
2656 pCanvas = new PlotFileCanvas (dynamic_cast<PlotFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
2658 pCanvas->SetBackgroundColour(*wxWHITE);
2669 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2672 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2674 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2676 theApp->setIconForFrame (subframe);
2678 wxMenu *m_pFileMenu = new wxMenu;
2680 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2681 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2682 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2683 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2684 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2685 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2687 m_pFileMenu->AppendSeparator();
2688 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
2690 m_pFileMenu->AppendSeparator();
2691 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2692 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2693 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2695 m_pFileMenu->AppendSeparator();
2696 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2698 theApp->getDocManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2699 theApp->getDocManager()->FileHistoryUseMenu(m_pFileMenu);
2701 wxMenu *view_menu = new wxMenu;
2702 view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...\tCtrl-E");
2703 view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
2704 view_menu->Append(PLOTMENU_VIEW_SCALE_FULL, "Display &Full Scale\tCtrl-U");
2706 wxMenu *help_menu = new wxMenu;
2707 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2708 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
2709 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2711 wxMenuBar *menu_bar = new wxMenuBar;
2713 menu_bar->Append(m_pFileMenu, "&File");
2714 menu_bar->Append(view_menu, "&View");
2715 menu_bar->Append(help_menu, "&Help");
2717 subframe->SetMenuBar(menu_bar);
2718 subframe->Centre(wxBOTH);
2720 wxAcceleratorEntry accelEntries[10];
2721 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
2722 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
2723 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
2724 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
2725 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
2726 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
2727 accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
2728 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('E'), PLOTMENU_VIEW_SCALE_MINMAX);
2729 accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('A'), PLOTMENU_VIEW_SCALE_AUTO);
2730 accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('U'), PLOTMENU_VIEW_SCALE_FULL);
2731 wxAcceleratorTable accelTable (10, accelEntries);
2732 subframe->SetAcceleratorTable (accelTable);
2739 PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
2741 m_pFrame = CreateChildFrame(doc, this);
2744 m_bMinSpecified = false;
2745 m_bMaxSpecified = false;
2746 m_dAutoScaleFactor = 1.;
2749 m_pFrame->GetClientSize(&width, &height);
2750 m_pFrame->SetTitle ("Plot File");
2751 m_pCanvas = CreateCanvas (this, m_pFrame);
2754 int x, y; // X requires a forced resize
2755 m_pFrame->GetSize(&x, &y);
2756 m_pFrame->SetSize(-1, -1, x, y);
2759 m_pFrame->Show(true);
2766 PlotFileView::OnDraw (wxDC* dc)
2768 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2769 const int iNColumns = rPlotFile.getNumColumns();
2770 const int iNRecords = rPlotFile.getNumRecords();
2772 if (iNColumns > 0 && iNRecords > 0) {
2774 m_pCanvas->GetClientSize (&xsize, &ysize);
2775 SGPDriver driver (dc, xsize, ysize);
2778 m_pEZPlot->plot (&sgp);
2784 PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2786 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2787 const int iNColumns = rPlotFile.getNumColumns();
2788 const int iNRecords = rPlotFile.getNumRecords();
2790 if (iNColumns > 0 && iNRecords > 0) {
2793 m_pEZPlot = new EZPlot;
2795 for (unsigned int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)
2796 m_pEZPlot->ezset (rPlotFile.getEzsetCommand (iEzset));
2798 if (m_bMinSpecified) {
2799 std::ostringstream os;
2800 os << "ymin " << m_dMinPixel;
2801 m_pEZPlot->ezset (os.str());
2804 if (m_bMaxSpecified) {
2805 std::ostringstream os;
2806 os << "ymax " << m_dMaxPixel;
2807 m_pEZPlot->ezset (os.str());
2810 m_pEZPlot->ezset("box");
2811 m_pEZPlot->ezset("grid");
2813 double* pdXaxis = new double [iNRecords];
2814 rPlotFile.getColumn (0, pdXaxis);
2816 double* pdY = new double [iNRecords];
2817 for (int iCol = 1; iCol < iNColumns; iCol++) {
2818 rPlotFile.getColumn (iCol, pdY);
2819 m_pEZPlot->addCurve (pdXaxis, pdY, iNRecords);
2827 m_pCanvas->Refresh();
2831 PlotFileView::OnClose (bool deleteWindow)
2833 if (! GetDocument() || ! GetDocument()->Close())
2838 m_pCanvas->setView (NULL);
2839 m_pCanvas->Show(false);
2842 wxString s(wxTheApp->GetAppName());
2844 m_pFrame->SetTitle(s);
2850 m_pFrame->Show(false);
2851 m_pFrame->Destroy();
2859 ////////////////////////////////////////////////////////////////
2862 IMPLEMENT_DYNAMIC_CLASS(TextFileView, wxView)
2864 TextFileView::~TextFileView()
2866 theApp->getDocManager()->FileHistoryRemoveMenu (m_pFileMenu);
2869 bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2871 m_pFrame = CreateChildFrame(doc, this);
2872 SetFrame (m_pFrame);
2875 m_pFrame->GetClientSize(&width, &height);
2876 m_pFrame->SetTitle("TextFile");
2877 m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
2878 m_pFrame->SetTitle("Log");
2881 // X seems to require a forced resize
2883 frame->GetSize(&x, &y);
2884 frame->SetSize(-1, -1, x, y);
2887 m_pFrame->Show (true);
2893 // Handled by wxTextWindow
2894 void TextFileView::OnDraw(wxDC *WXUNUSED(dc) )
2898 void TextFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2903 TextFileView::OnClose (bool deleteWindow)
2905 if (m_pFrame && m_pFrame->GetTitle() == "Log")
2908 if (! GetDocument() || ! GetDocument()->Close())
2911 m_pCanvas->Show(false);
2915 m_pFrame->Show(false);
2916 m_pFrame->Destroy();
2929 TextFileView::CreateChildFrame (wxDocument *doc, wxView *view)
2932 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE);
2934 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE);
2936 theApp->setIconForFrame (subframe);
2938 wxMenu *m_pFileMenu = new wxMenu;
2940 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2941 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2942 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2943 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2944 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2945 // m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2947 m_pFileMenu->AppendSeparator();
2948 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2949 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2950 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2952 m_pFileMenu->AppendSeparator();
2953 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2955 theApp->getDocManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2956 theApp->getDocManager()->FileHistoryUseMenu(m_pFileMenu);
2958 wxMenu *help_menu = new wxMenu;
2959 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2960 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
2961 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2963 wxMenuBar *menu_bar = new wxMenuBar;
2965 menu_bar->Append(m_pFileMenu, "&File");
2966 menu_bar->Append(help_menu, "&Help");
2968 subframe->SetMenuBar(menu_bar);
2969 subframe->Centre(wxBOTH);
2971 wxAcceleratorEntry accelEntries[5];
2972 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
2973 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
2974 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
2975 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
2976 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
2977 wxAcceleratorTable accelTable (5, accelEntries);
2978 subframe->SetAcceleratorTable (accelTable);
2984 // Define a constructor for my text subwindow
2985 TextFileCanvas::TextFileCanvas (TextFileView* v, wxFrame* frame, const wxPoint& pos, const wxSize& size, long style)
2986 : wxTextCtrl (frame, -1, "", pos, size, style), m_pView(v)
2990 TextFileCanvas::~TextFileCanvas ()