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.79 2001/01/27 03:39:53 kevin Exp $
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
28 // For compilers that support precompilation, includes "wx/wx.h".
29 #include "wx/wxprec.h"
39 #if !wxUSE_DOC_VIEW_ARCHITECTURE
40 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
44 #include "wx/progdlg.h"
51 #include "dlgprojections.h"
52 #include "dlgreconstruct.h"
53 #include "backprojectors.h"
54 #include "reconstruct.h"
57 #if defined(MSVC) || HAVE_SSTREAM
60 #include <sstream_subst>
66 BEGIN_EVENT_TABLE(ImageFileCanvas, wxScrolledWindow)
67 EVT_MOUSE_EVENTS(ImageFileCanvas::OnMouseEvent)
71 ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
72 : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v), m_xCursor(-1), m_yCursor(-1)
76 ImageFileCanvas::~ImageFileCanvas()
82 ImageFileCanvas::OnDraw(wxDC& dc)
85 m_pView->OnDraw(& dc);
89 ImageFileCanvas::DrawRubberBandCursor (wxDC& dc, int x, int y)
91 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
96 dc.SetLogicalFunction (wxINVERT);
97 dc.SetPen (*wxGREEN_PEN);
98 dc.DrawLine (0, yPt, nx, yPt);
99 dc.DrawLine (x, 0, x, ny);
100 dc.SetLogicalFunction (wxCOPY);
104 ImageFileCanvas::GetCurrentCursor (int& x, int& y)
109 if (m_xCursor >= 0 && m_yCursor >= 0)
116 ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
124 wxPoint pt(event.GetLogicalPosition(dc));
126 const ImageFileDocument* pIFDoc = m_pView->GetDocument();
129 const ImageFile& rIF = pIFDoc->getImageFile();
130 ImageFileArrayConst v = rIF.getArray();
133 const int yPt = ny - 1 - pt.y;
134 if (event.RightIsDown()) {
135 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
136 std::ostringstream os;
137 os << "Image value (" << pt.x << "," << yPt << ") = " << v[pt.x][yPt];
138 if (rIF.isComplex()) {
139 double dImag = rIF.getImaginaryArray()[pt.x][yPt];
141 os << " - " << -dImag;
143 os << " + " << dImag;
147 *theApp->getLog() << os.str().c_str();
149 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
151 else if (event.LeftIsDown() || event.LeftUp() || event.RightUp()) {
152 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
153 if (m_xCursor >= 0 && m_yCursor >= 0) {
154 DrawRubberBandCursor (dc, m_xCursor, m_yCursor);
156 DrawRubberBandCursor (dc, pt.x, yPt);
160 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
162 if (event.LeftUp()) {
163 std::ostringstream os;
164 os << "Selected column " << pt.x << " , row " << yPt << "\n";
165 *theApp->getLog() << os.str().c_str();
170 ImageFileCanvas::GetBestSize() const
175 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
176 return wxSize (rIF.nx(), rIF.ny());
182 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
184 BEGIN_EVENT_TABLE(ImageFileView, wxView)
185 EVT_MENU(IFMENU_FILE_EXPORT, ImageFileView::OnExport)
186 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
187 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
188 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
189 EVT_MENU(IFMENU_VIEW_SCALE_FULL, ImageFileView::OnScaleFull)
190 EVT_MENU(IFMENU_COMPARE_IMAGES, ImageFileView::OnCompare)
191 EVT_MENU(IFMENU_COMPARE_ROW, ImageFileView::OnCompareRow)
192 EVT_MENU(IFMENU_COMPARE_COL, ImageFileView::OnCompareCol)
193 EVT_MENU(IFMENU_FILTER_INVERTVALUES, ImageFileView::OnInvertValues)
194 EVT_MENU(IFMENU_FILTER_SQUARE, ImageFileView::OnSquare)
195 EVT_MENU(IFMENU_FILTER_SQRT, ImageFileView::OnSquareRoot)
196 EVT_MENU(IFMENU_FILTER_LOG, ImageFileView::OnLog)
197 EVT_MENU(IFMENU_FILTER_EXP, ImageFileView::OnExp)
198 EVT_MENU(IFMENU_FILTER_FOURIER, ImageFileView::OnFourier)
199 EVT_MENU(IFMENU_FILTER_INVERSE_FOURIER, ImageFileView::OnInverseFourier)
200 EVT_MENU(IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, ImageFileView::OnShuffleFourierToNaturalOrder)
201 EVT_MENU(IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, ImageFileView::OnShuffleNaturalToFourierOrder)
202 EVT_MENU(IFMENU_IMAGE_ADD, ImageFileView::OnAdd)
203 EVT_MENU(IFMENU_IMAGE_SUBTRACT, ImageFileView::OnSubtract)
204 EVT_MENU(IFMENU_IMAGE_MULTIPLY, ImageFileView::OnMultiply)
205 EVT_MENU(IFMENU_IMAGE_DIVIDE, ImageFileView::OnDivide)
206 EVT_MENU(IFMENU_IMAGE_SCALESIZE, ImageFileView::OnScaleSize)
208 EVT_MENU(IFMENU_FILTER_FFT, ImageFileView::OnFFT)
209 EVT_MENU(IFMENU_FILTER_IFFT, ImageFileView::OnIFFT)
210 EVT_MENU(IFMENU_FILTER_FFT_ROWS, ImageFileView::OnFFTRows)
211 EVT_MENU(IFMENU_FILTER_IFFT_ROWS, ImageFileView::OnIFFTRows)
212 EVT_MENU(IFMENU_FILTER_FFT_COLS, ImageFileView::OnFFTCols)
213 EVT_MENU(IFMENU_FILTER_IFFT_COLS, ImageFileView::OnIFFTCols)
215 EVT_MENU(IFMENU_FILTER_MAGNITUDE, ImageFileView::OnMagnitude)
216 EVT_MENU(IFMENU_FILTER_PHASE, ImageFileView::OnPhase)
217 EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)
218 EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol)
220 EVT_MENU(IFMENU_PLOT_FFT_ROW, ImageFileView::OnPlotFFTRow)
221 EVT_MENU(IFMENU_PLOT_FFT_COL, ImageFileView::OnPlotFFTCol)
223 EVT_MENU(IFMENU_PLOT_HISTOGRAM, ImageFileView::OnPlotHistogram)
226 ImageFileView::ImageFileView()
227 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
229 m_iDefaultExportFormatID = ImageFile::FORMAT_PNG;
232 ImageFileView::~ImageFileView()
234 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->getView()->getFrame()->Close(true);
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++) {
1812 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
1813 pProjectionDoc->getView()->getFrame()->Close(true);
1817 while (dialogProjections.isPaused()) {
1823 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT);
1824 for (int i = 0; i < rProj.nView(); i++) {
1825 theScanner.collectProjections (rProj, rPhantom, i, 1, true, m_iDefaultTrace);
1826 if (! dlgProgress.Update (i+1)) {
1827 pProjectionDoc->getView()->getFrame()->Close(true);
1833 std::ostringstream os;
1834 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();
1835 rProj.setCalcTime (timer.timerEnd());
1836 rProj.setRemark (os.str());
1837 *theApp->getLog() << os.str().c_str() << "\n";
1841 ProjectionFileView* projView = dynamic_cast<ProjectionFileView*>(pProjectionDoc->GetFirstView());
1843 projView->getFrame()->SetFocus();
1844 projView->OnUpdate (projView, NULL);
1846 if (wxView* pView = pProjectionDoc->GetFirstView()) {
1847 if (wxFrame* pFrame = pView->GetFrame()) {
1851 theApp->getDocManager()->ActivateView (pView, true, false);
1854 if (theApp->getSetModifyNewDocs())
1855 pProjectionDoc->Modify(true);
1856 pProjectionDoc->getView()->getFrame()->Show(true);
1857 pProjectionDoc->UpdateAllViews(this);
1864 PhantomFileView::OnRasterize (wxCommandEvent& event)
1866 DialogGetRasterParameters dialogRaster (getFrameForChild(), m_iDefaultRasterNX, m_iDefaultRasterNY, m_iDefaultRasterNSamples);
1867 int retVal = dialogRaster.ShowModal();
1868 if (retVal == wxID_OK) {
1869 m_iDefaultRasterNX = dialogRaster.getXSize();
1870 m_iDefaultRasterNY = dialogRaster.getYSize();
1871 m_iDefaultRasterNSamples = dialogRaster.getNSamples();
1872 if (m_iDefaultRasterNSamples < 1)
1873 m_iDefaultRasterNSamples = 1;
1874 if (m_iDefaultRasterNX > 0 && m_iDefaultRasterNY > 0) {
1875 const Phantom& rPhantom = GetDocument()->getPhantom();
1876 ImageFileDocument* pRasterDoc = theApp->newImageDoc();
1878 sys_error (ERR_SEVERE, "Unable to create image file");
1881 ImageFile& imageFile = pRasterDoc->getImageFile();
1883 imageFile.setArraySize (m_iDefaultRasterNX, m_iDefaultRasterNX);
1884 wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"), imageFile.nx() + 1, getFrameForChild(), wxPD_CAN_ABORT);
1886 for (unsigned int i = 0; i < imageFile.nx(); i++) {
1887 rPhantom.convertToImagefile (imageFile, m_iDefaultRasterNSamples, Trace::TRACE_NONE, i, 1, true);
1888 if (! dlgProgress.Update(i+1)) {
1889 pRasterDoc->Close();
1890 pRasterDoc->getView()->getFrame()->Close(true);
1894 if (theApp->getSetModifyNewDocs())
1895 pRasterDoc->Modify(true);
1896 pRasterDoc->UpdateAllViews(this);
1897 pRasterDoc->getView()->getFrame()->Show(true);
1898 std::ostringstream os;
1899 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << m_iDefaultRasterNX << ", YSize="
1900 << m_iDefaultRasterNY << ", nSamples=" << m_iDefaultRasterNSamples;
1901 *theApp->getLog() << os.str().c_str() << "\n";
1902 imageFile.labelAdd (os.str().c_str(), timer.timerEnd());
1903 ImageFileView* rasterView = dynamic_cast<ImageFileView*>(pRasterDoc->GetFirstView());
1905 rasterView->getFrame()->SetFocus();
1906 rasterView->OnUpdate (rasterView, NULL);
1915 PhantomFileView::CreateCanvas (wxView *view, wxFrame *parent)
1917 PhantomCanvas* pCanvas;
1919 parent->GetClientSize(&width, &height);
1921 pCanvas = new PhantomCanvas (dynamic_cast<PhantomFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
1923 pCanvas->SetBackgroundColour(*wxWHITE);
1934 PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view)
1937 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
1939 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
1941 theApp->setIconForFrame (subframe);
1943 wxMenu *m_pFileMenu = new wxMenu;
1945 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
1946 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
1947 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
1948 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
1949 m_pFileMenu->Append(wxID_CLOSE, "&Close");
1951 m_pFileMenu->AppendSeparator();
1952 m_pFileMenu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties");
1954 m_pFileMenu->AppendSeparator();
1955 m_pFileMenu->Append(wxID_PRINT, "&Print...");
1956 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
1957 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
1959 m_pFileMenu->AppendSeparator();
1960 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
1962 theApp->getDocManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
1963 theApp->getDocManager()->FileHistoryUseMenu(m_pFileMenu);
1965 wxMenu *process_menu = new wxMenu;
1966 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...\tCtrl-R");
1967 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...\tCtrl-J");
1969 wxMenu *help_menu = new wxMenu;
1970 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
1971 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
1972 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
1974 wxMenuBar *menu_bar = new wxMenuBar;
1976 menu_bar->Append(m_pFileMenu, "&File");
1977 menu_bar->Append(process_menu, "&Process");
1978 menu_bar->Append(help_menu, "&Help");
1980 subframe->SetMenuBar(menu_bar);
1981 subframe->Centre(wxBOTH);
1983 wxAcceleratorEntry accelEntries[8];
1984 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
1985 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
1986 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
1987 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
1988 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
1989 accelEntries[5].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
1990 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('J'), PHMMENU_PROCESS_PROJECTIONS);
1991 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('R'), PHMMENU_PROCESS_RASTERIZE);
1992 wxAcceleratorTable accelTable (8, accelEntries);
1993 subframe->SetAcceleratorTable (accelTable);
2000 PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2002 m_pFrame = CreateChildFrame(doc, this);
2006 m_pFrame->GetClientSize(&width, &height);
2007 m_pFrame->SetTitle("PhantomFileView");
2008 m_pCanvas = CreateCanvas (this, m_pFrame);
2011 int x, y; // X requires a forced resize
2012 m_pFrame->GetSize(&x, &y);
2013 m_pFrame->SetSize(-1, -1, x, y);
2016 m_pFrame->Show(true);
2023 PhantomFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2026 m_pCanvas->Refresh();
2030 PhantomFileView::OnClose (bool deleteWindow)
2032 if (! GetDocument() || ! GetDocument()->Close())
2037 m_pCanvas->setView(NULL);
2038 m_pCanvas->Show(false);
2041 wxString s(wxTheApp->GetAppName());
2043 m_pFrame->SetTitle(s);
2049 m_pFrame->Show(false);
2050 m_pFrame->Destroy();
2059 PhantomFileView::OnDraw (wxDC* dc)
2062 m_pCanvas->GetClientSize (&xsize, &ysize);
2063 SGPDriver driver (dc, xsize, ysize);
2065 const Phantom& rPhantom = GetDocument()->getPhantom();
2066 sgp.setColor (C_RED);
2067 rPhantom.show (sgp);
2072 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2073 : wxScrolledWindow(frame, -1, pos, size, style)
2078 ProjectionFileCanvas::~ProjectionFileCanvas ()
2084 ProjectionFileCanvas::OnDraw(wxDC& dc)
2087 m_pView->OnDraw(& dc);
2091 ProjectionFileCanvas::GetBestSize () const
2095 Projections& rProj = m_pView->GetDocument()->getProjections();
2096 best.Set (rProj.nDet(), rProj.nView());
2103 // ProjectionFileView
2105 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
2107 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
2108 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
2109 EVT_MENU(PJMENU_RECONSTRUCT_FBP, ProjectionFileView::OnReconstructFBP)
2110 EVT_MENU(PJMENU_CONVERT_POLAR, ProjectionFileView::OnConvertPolar)
2111 EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
2114 ProjectionFileView::ProjectionFileView()
2115 : wxView(), m_pCanvas(NULL), m_pFrame(NULL), m_pFileMenu(0)
2119 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
2120 m_dDefaultFilterParam = 1.;
2122 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
2123 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
2125 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
2126 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
2128 m_iDefaultZeropad = 1;
2129 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF3;
2130 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
2131 m_iDefaultInterpParam = 1;
2132 m_iDefaultTrace = Trace::TRACE_NONE;
2134 m_iDefaultPolarNX = 256;
2135 m_iDefaultPolarNY = 256;
2136 m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR;
2137 m_iDefaultPolarZeropad = 1;
2140 ProjectionFileView::~ProjectionFileView()
2142 theApp->getDocManager()->FileHistoryRemoveMenu (m_pFileMenu);
2146 ProjectionFileView::OnProperties (wxCommandEvent& event)
2148 const Projections& rProj = GetDocument()->getProjections();
2149 std::ostringstream os;
2150 rProj.printScanInfo(os);
2151 *theApp->getLog() << os.str().c_str();
2152 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
2153 dialogMsg.ShowModal();
2158 ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
2160 Projections& rProj = GetDocument()->getProjections();
2161 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2162 m_iDefaultPolarInterpolation, -1);
2163 if (dialogPolar.ShowModal() == wxID_OK) {
2164 wxString strInterpolation (dialogPolar.getInterpolationName());
2165 m_iDefaultPolarNX = dialogPolar.getXSize();
2166 m_iDefaultPolarNY = dialogPolar.getYSize();
2167 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2168 ImageFile& rIF = pPolarDoc->getImageFile();
2170 sys_error (ERR_SEVERE, "Unable to create image file");
2173 rIF.setArraySize (m_iDefaultPolarNX, m_iDefaultPolarNY);
2174 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2175 rProj.convertPolar (rIF, m_iDefaultPolarInterpolation);
2176 rIF.labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2177 std::ostringstream os;
2178 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to polar image: xSize="
2179 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2180 << strInterpolation.c_str();
2181 *theApp->getLog() << os.str().c_str() << "\n";
2182 rIF.labelAdd (os.str().c_str());
2183 if (theApp->getSetModifyNewDocs())
2184 pPolarDoc->Modify(true);
2185 pPolarDoc->UpdateAllViews();
2186 pPolarDoc->getView()->OnUpdate (this, NULL);
2187 pPolarDoc->getView()->getFrame()->Show(true);
2192 ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
2194 Projections& rProj = GetDocument()->getProjections();
2195 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert to FFT Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2196 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad);
2197 if (dialogPolar.ShowModal() == wxID_OK) {
2198 wxString strInterpolation (dialogPolar.getInterpolationName());
2199 m_iDefaultPolarNX = dialogPolar.getXSize();
2200 m_iDefaultPolarNY = dialogPolar.getYSize();
2201 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2202 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2203 ImageFile& rIF = pPolarDoc->getImageFile();
2205 sys_error (ERR_SEVERE, "Unable to create image file");
2208 rIF.setArraySize (m_iDefaultPolarNX, m_iDefaultPolarNY);
2209 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2210 rProj.convertFFTPolar (rIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad);
2211 rIF.labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2212 std::ostringstream os;
2213 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to FFT polar image: xSize="
2214 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2215 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2216 *theApp->getLog() << os.str().c_str() << "\n";
2217 rIF.labelAdd (os.str().c_str());
2218 if (theApp->getSetModifyNewDocs())
2219 pPolarDoc->Modify(true);
2220 pPolarDoc->UpdateAllViews();
2221 pPolarDoc->getView()->OnUpdate (this, NULL);
2222 pPolarDoc->getView()->getFrame()->Show(true);
2227 ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
2229 wxMessageBox ("Fourier Reconstruction is not yet supported", "Unimplemented function");
2233 ProjectionFileView::OnReconstructFBP (wxCommandEvent& event)
2235 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);
2237 int retVal = dialogReconstruction.ShowModal();
2238 if (retVal == wxID_OK) {
2239 m_iDefaultNX = dialogReconstruction.getXSize();
2240 m_iDefaultNY = dialogReconstruction.getYSize();
2241 wxString optFilterName = dialogReconstruction.getFilterName();
2242 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
2243 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
2244 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
2245 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
2246 m_iDefaultZeropad = dialogReconstruction.getZeropad();
2247 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
2248 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
2249 wxString optInterpName = dialogReconstruction.getInterpName();
2250 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
2251 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
2252 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
2253 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
2254 m_iDefaultTrace = dialogReconstruction.getTrace();
2255 if (m_iDefaultNX > 0 && m_iDefaultNY > 0) {
2256 ImageFileDocument* pReconDoc = theApp->newImageDoc();
2258 sys_error (ERR_SEVERE, "Unable to create image file");
2261 ImageFile& imageFile = pReconDoc->getImageFile();
2262 const Projections& rProj = GetDocument()->getProjections();
2263 imageFile.setArraySize (m_iDefaultNX, m_iDefaultNY);
2265 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);
2268 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2269 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstruct, rProj, imageFile, m_iDefaultTrace, getFrameForChild());
2270 for (int iView = 0; iView < rProj.nView(); iView++) {
2273 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView)) {
2274 delete pDlgReconstruct;
2275 delete pReconstruct;
2276 pReconDoc->getView()->getFrame()->Close(true);
2281 while (pDlgReconstruct->isPaused()) {
2286 delete pDlgReconstruct;
2288 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT);
2289 for (int i = 0; i < rProj.nView(); i++) {
2290 pReconstruct->reconstructView (i, 1);
2291 if (! dlgProgress.Update(i + 1)) {
2292 delete pReconstruct;
2293 pReconDoc->getView()->getFrame()->Close(true);
2298 delete pReconstruct;
2299 if (theApp->getSetModifyNewDocs())
2300 pReconDoc->Modify(true);
2301 pReconDoc->UpdateAllViews(this);
2302 pReconDoc->getView()->getFrame()->Show(true);
2303 ImageFileView* rasterView = dynamic_cast<ImageFileView*>(pReconDoc->GetFirstView());
2305 rasterView->getFrame()->SetFocus();
2306 rasterView->OnUpdate (rasterView, NULL);
2308 std::ostringstream os;
2309 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();
2310 *theApp->getLog() << os.str().c_str() << "\n";
2311 imageFile.labelAdd (rProj.getLabel());
2312 imageFile.labelAdd (os.str().c_str(), timerRecon.timerEnd());
2318 ProjectionFileCanvas*
2319 ProjectionFileView::CreateCanvas (wxView *view, wxFrame *parent)
2321 ProjectionFileCanvas* pCanvas;
2323 parent->GetClientSize(&width, &height);
2325 pCanvas = new ProjectionFileCanvas (dynamic_cast<ProjectionFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
2327 pCanvas->SetScrollbars(20, 20, 50, 50);
2328 pCanvas->SetBackgroundColour(*wxWHITE);
2339 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2342 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2344 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2346 theApp->setIconForFrame (subframe);
2348 wxMenu *m_pFileMenu = new wxMenu;
2350 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2351 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2352 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2353 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2354 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2355 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2357 m_pFileMenu->AppendSeparator();
2358 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
2360 m_pFileMenu->AppendSeparator();
2361 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2362 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2363 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2365 m_pFileMenu->AppendSeparator();
2366 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2368 theApp->getDocManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2369 theApp->getDocManager()->FileHistoryUseMenu(m_pFileMenu);
2371 wxMenu *convert_menu = new wxMenu;
2372 convert_menu->Append (PJMENU_CONVERT_POLAR, "&Polar Image...\tCtrl-L");
2373 convert_menu->Append (PJMENU_CONVERT_FFT_POLAR, "&FFT->Polar Image...\tCtrl-I");
2375 wxMenu *reconstruct_menu = new wxMenu;
2376 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP, "&Filtered Backprojection...\tCtrl-R");
2377 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Fourier...\tCtrl-E");
2379 wxMenu *help_menu = new wxMenu;
2380 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2381 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
2382 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2384 wxMenuBar *menu_bar = new wxMenuBar;
2386 menu_bar->Append (m_pFileMenu, "&File");
2387 menu_bar->Append (convert_menu, "&Convert");
2388 menu_bar->Append (reconstruct_menu, "&Reconstruct");
2389 menu_bar->Append (help_menu, "&Help");
2391 subframe->SetMenuBar(menu_bar);
2392 subframe->Centre(wxBOTH);
2394 wxAcceleratorEntry accelEntries[11];
2395 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
2396 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
2397 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
2398 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
2399 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
2400 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
2401 accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
2402 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('L'), PJMENU_CONVERT_POLAR);
2403 accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('I'), PJMENU_CONVERT_FFT_POLAR);
2404 accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('R'), PJMENU_RECONSTRUCT_FBP);
2405 accelEntries[10].Set (wxACCEL_CTRL, static_cast<int>('E'), PJMENU_RECONSTRUCT_FOURIER);
2406 wxAcceleratorTable accelTable (11, accelEntries);
2407 subframe->SetAcceleratorTable (accelTable);
2414 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2416 m_pFrame = CreateChildFrame(doc, this);
2420 m_pFrame->GetClientSize(&width, &height);
2421 m_pFrame->SetTitle("ProjectionFileView");
2422 m_pCanvas = CreateCanvas(this, m_pFrame);
2425 int x, y; // X requires a forced resize
2426 m_pFrame->GetSize(&x, &y);
2427 m_pFrame->SetSize(-1, -1, x, y);
2430 m_pFrame->Show(true);
2437 ProjectionFileView::OnDraw (wxDC* dc)
2439 wxSize clientSize = m_pFrame->GetClientSize();
2440 wxSize bestSize = m_pCanvas->GetBestSize();
2442 if (clientSize.x > bestSize.x || clientSize.y > bestSize.y)
2443 m_pFrame->SetClientSize (bestSize);
2446 dc->DrawBitmap (m_bitmap, 0, 0, false);
2451 ProjectionFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2453 const Projections& rProj = GetDocument()->getProjections();
2454 const int nDet = rProj.nDet();
2455 const int nView = rProj.nView();
2456 if (nDet != 0 && nView != 0) {
2457 const DetectorArray& detarray = rProj.getDetectorArray(0);
2458 const DetectorValue* detval = detarray.detValues();
2459 double min = detval[0];
2460 double max = detval[0];
2461 for (int iy = 0; iy < nView; iy++) {
2462 const DetectorArray& detarray = rProj.getDetectorArray(iy);
2463 const DetectorValue* detval = detarray.detValues();
2464 for (int ix = 0; ix < nDet; ix++) {
2465 if (min > detval[ix])
2467 else if (max < detval[ix])
2472 unsigned char* imageData = new unsigned char [nDet * nView * 3];
2473 double scale = (max - min) / 255;
2474 for (int iy2 = 0; iy2 < nView; iy2++) {
2475 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
2476 const DetectorValue* detval = detarray.detValues();
2477 for (int ix = 0; ix < nDet; ix++) {
2478 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
2479 intensity = clamp(intensity, 0, 255);
2480 int baseAddr = (iy2 * nDet + ix) * 3;
2481 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
2484 wxImage image (nDet, nView, imageData, true);
2485 m_bitmap = image.ConvertToBitmap();
2489 xSize = clamp (xSize, 0, 800);
2490 ySize = clamp (ySize, 0, 800);
2491 m_pFrame->SetClientSize (xSize, ySize);
2492 m_pCanvas->SetScrollbars (20, 20, nDet/20, nView/20);
2496 m_pCanvas->Refresh();
2500 ProjectionFileView::OnClose (bool deleteWindow)
2502 if (! GetDocument() || ! GetDocument()->Close())
2507 m_pCanvas->setView(NULL);
2508 m_pCanvas->Show(false);
2511 wxString s(wxTheApp->GetAppName());
2513 m_pFrame->SetTitle(s);
2519 m_pFrame->Show(false);
2520 m_pFrame->Destroy();
2530 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2531 : wxScrolledWindow(frame, -1, pos, size, style)
2536 PlotFileCanvas::~PlotFileCanvas ()
2542 PlotFileCanvas::OnDraw(wxDC& dc)
2545 m_pView->OnDraw(& dc);
2551 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
2553 BEGIN_EVENT_TABLE(PlotFileView, wxView)
2554 EVT_MENU(PJMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
2555 EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
2556 EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
2557 EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
2560 PlotFileView::PlotFileView()
2561 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pEZPlot(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
2565 PlotFileView::~PlotFileView()
2570 theApp->getDocManager()->FileHistoryRemoveMenu (m_pFileMenu);
2574 PlotFileView::OnProperties (wxCommandEvent& event)
2576 const PlotFile& rPlot = GetDocument()->getPlotFile();
2577 std::ostringstream os;
2578 os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
2579 rPlot.printHeadersBrief (os);
2580 *theApp->getLog() << os.str().c_str();
2581 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
2582 dialogMsg.ShowModal();
2587 PlotFileView::OnScaleAuto (wxCommandEvent& event)
2589 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2590 double min, max, mean, mode, median, stddev;
2591 rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
2592 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
2593 int iRetVal = dialogAutoScale.ShowModal();
2594 if (iRetVal == wxID_OK) {
2595 m_bMinSpecified = true;
2596 m_bMaxSpecified = true;
2598 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
2601 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
2602 OnUpdate (this, NULL);
2608 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
2610 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2614 if (! m_bMinSpecified || ! m_bMaxSpecified) {
2615 if (! rPlotFile.getMinMax (1, min, max)) {
2616 *theApp->getLog() << "Error: unable to find Min/Max\n";
2621 if (m_bMinSpecified)
2623 if (m_bMaxSpecified)
2626 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Y-axis Minimum & Maximum", min, max);
2627 int retVal = dialogMinMax.ShowModal();
2628 if (retVal == wxID_OK) {
2629 m_bMinSpecified = true;
2630 m_bMaxSpecified = true;
2631 m_dMinPixel = dialogMinMax.getMinimum();
2632 m_dMaxPixel = dialogMinMax.getMaximum();
2633 OnUpdate (this, NULL);
2638 PlotFileView::OnScaleFull (wxCommandEvent& event)
2640 if (m_bMinSpecified || m_bMaxSpecified) {
2641 m_bMinSpecified = false;
2642 m_bMaxSpecified = false;
2643 OnUpdate (this, NULL);
2649 PlotFileView::CreateCanvas (wxView *view, wxFrame *parent)
2651 PlotFileCanvas* pCanvas;
2653 parent->GetClientSize(&width, &height);
2655 pCanvas = new PlotFileCanvas (dynamic_cast<PlotFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
2657 pCanvas->SetBackgroundColour(*wxWHITE);
2668 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2671 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2673 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2675 theApp->setIconForFrame (subframe);
2677 wxMenu *m_pFileMenu = new wxMenu;
2679 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2680 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2681 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2682 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2683 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2684 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2686 m_pFileMenu->AppendSeparator();
2687 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
2689 m_pFileMenu->AppendSeparator();
2690 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2691 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2692 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2694 m_pFileMenu->AppendSeparator();
2695 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2697 theApp->getDocManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2698 theApp->getDocManager()->FileHistoryUseMenu(m_pFileMenu);
2700 wxMenu *view_menu = new wxMenu;
2701 view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...\tCtrl-E");
2702 view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
2703 view_menu->Append(PLOTMENU_VIEW_SCALE_FULL, "Display &Full Scale\tCtrl-U");
2705 wxMenu *help_menu = new wxMenu;
2706 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2707 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
2708 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2710 wxMenuBar *menu_bar = new wxMenuBar;
2712 menu_bar->Append(m_pFileMenu, "&File");
2713 menu_bar->Append(view_menu, "&View");
2714 menu_bar->Append(help_menu, "&Help");
2716 subframe->SetMenuBar(menu_bar);
2717 subframe->Centre(wxBOTH);
2719 wxAcceleratorEntry accelEntries[10];
2720 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
2721 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
2722 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
2723 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
2724 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
2725 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
2726 accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
2727 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('E'), PLOTMENU_VIEW_SCALE_MINMAX);
2728 accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('A'), PLOTMENU_VIEW_SCALE_AUTO);
2729 accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('U'), PLOTMENU_VIEW_SCALE_FULL);
2730 wxAcceleratorTable accelTable (10, accelEntries);
2731 subframe->SetAcceleratorTable (accelTable);
2738 PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
2740 m_pFrame = CreateChildFrame(doc, this);
2743 m_bMinSpecified = false;
2744 m_bMaxSpecified = false;
2745 m_dAutoScaleFactor = 1.;
2748 m_pFrame->GetClientSize(&width, &height);
2749 m_pFrame->SetTitle ("Plot File");
2750 m_pCanvas = CreateCanvas (this, m_pFrame);
2753 int x, y; // X requires a forced resize
2754 m_pFrame->GetSize(&x, &y);
2755 m_pFrame->SetSize(-1, -1, x, y);
2758 m_pFrame->Show(true);
2765 PlotFileView::OnDraw (wxDC* dc)
2767 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2768 const int iNColumns = rPlotFile.getNumColumns();
2769 const int iNRecords = rPlotFile.getNumRecords();
2771 if (iNColumns > 0 && iNRecords > 0) {
2773 m_pCanvas->GetClientSize (&xsize, &ysize);
2774 SGPDriver driver (dc, xsize, ysize);
2777 m_pEZPlot->plot (&sgp);
2783 PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2785 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2786 const int iNColumns = rPlotFile.getNumColumns();
2787 const int iNRecords = rPlotFile.getNumRecords();
2789 if (iNColumns > 0 && iNRecords > 0) {
2792 m_pEZPlot = new EZPlot;
2794 for (unsigned int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)
2795 m_pEZPlot->ezset (rPlotFile.getEzsetCommand (iEzset));
2797 if (m_bMinSpecified) {
2798 std::ostringstream os;
2799 os << "ymin " << m_dMinPixel;
2800 m_pEZPlot->ezset (os.str());
2803 if (m_bMaxSpecified) {
2804 std::ostringstream os;
2805 os << "ymax " << m_dMaxPixel;
2806 m_pEZPlot->ezset (os.str());
2809 m_pEZPlot->ezset("box");
2810 m_pEZPlot->ezset("grid");
2812 double* pdXaxis = new double [iNRecords];
2813 rPlotFile.getColumn (0, pdXaxis);
2815 double* pdY = new double [iNRecords];
2816 for (int iCol = 1; iCol < iNColumns; iCol++) {
2817 rPlotFile.getColumn (iCol, pdY);
2818 m_pEZPlot->addCurve (pdXaxis, pdY, iNRecords);
2826 m_pCanvas->Refresh();
2830 PlotFileView::OnClose (bool deleteWindow)
2832 if (! GetDocument() || ! GetDocument()->Close())
2837 m_pCanvas->setView (NULL);
2838 m_pCanvas->Show(false);
2841 wxString s(wxTheApp->GetAppName());
2843 m_pFrame->SetTitle(s);
2849 m_pFrame->Show(false);
2850 m_pFrame->Destroy();
2858 ////////////////////////////////////////////////////////////////
2861 IMPLEMENT_DYNAMIC_CLASS(TextFileView, wxView)
2863 TextFileView::~TextFileView()
2865 theApp->getDocManager()->FileHistoryRemoveMenu (m_pFileMenu);
2868 bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2870 m_pFrame = CreateChildFrame(doc, this);
2871 SetFrame (m_pFrame);
2874 m_pFrame->GetClientSize(&width, &height);
2875 m_pFrame->SetTitle("TextFile");
2876 m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
2877 m_pFrame->SetTitle("Log");
2880 // X seems to require a forced resize
2882 frame->GetSize(&x, &y);
2883 frame->SetSize(-1, -1, x, y);
2886 m_pFrame->Show (true);
2892 // Handled by wxTextWindow
2893 void TextFileView::OnDraw(wxDC *WXUNUSED(dc) )
2897 void TextFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2902 TextFileView::OnClose (bool deleteWindow)
2904 if (m_pFrame && m_pFrame->GetTitle() == "Log")
2907 if (! GetDocument() || ! GetDocument()->Close())
2910 m_pCanvas->Show(false);
2914 m_pFrame->Show(false);
2915 m_pFrame->Destroy();
2928 TextFileView::CreateChildFrame (wxDocument *doc, wxView *view)
2931 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE);
2933 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE);
2935 theApp->setIconForFrame (subframe);
2937 wxMenu *m_pFileMenu = new wxMenu;
2939 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2940 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2941 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2942 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2943 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2944 // m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2946 m_pFileMenu->AppendSeparator();
2947 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2948 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2949 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2951 m_pFileMenu->AppendSeparator();
2952 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2954 theApp->getDocManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2955 theApp->getDocManager()->FileHistoryUseMenu(m_pFileMenu);
2957 wxMenu *help_menu = new wxMenu;
2958 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2959 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
2960 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2962 wxMenuBar *menu_bar = new wxMenuBar;
2964 menu_bar->Append(m_pFileMenu, "&File");
2965 menu_bar->Append(help_menu, "&Help");
2967 subframe->SetMenuBar(menu_bar);
2968 subframe->Centre(wxBOTH);
2970 wxAcceleratorEntry accelEntries[5];
2971 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
2972 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
2973 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
2974 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
2975 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
2976 wxAcceleratorTable accelTable (5, accelEntries);
2977 subframe->SetAcceleratorTable (accelTable);
2983 // Define a constructor for my text subwindow
2984 TextFileCanvas::TextFileCanvas (TextFileView* v, wxFrame* frame, const wxPoint& pos, const wxSize& size, long style)
2985 : wxTextCtrl (frame, -1, "", pos, size, style), m_pView(v)
2989 TextFileCanvas::~TextFileCanvas ()