1 /*****************************************************************************
5 ** Purpose: View & Canvas routines for CTSim program
6 ** Programmer: Kevin Rosenberg
7 ** Date Started: July 2000
9 ** This is part of the CTSim program
10 ** Copyright (c) 1983-2001 Kevin Rosenberg
12 ** $Id: views.cpp,v 1.88 2001/01/29 23:11:32 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);
159 wxMenu* pMenu = m_pView->getMenuAnalyze();
160 if (pMenu && ! pMenu->IsEnabled(IFMENU_PLOT_ROW)) {
161 pMenu->Enable (IFMENU_PLOT_ROW, true);
162 pMenu->Enable (IFMENU_PLOT_COL, true);
163 pMenu->Enable (IFMENU_COMPARE_ROW, true);
164 pMenu->Enable (IFMENU_COMPARE_COL, true);
165 pMenu->Enable (IFMENU_PLOT_FFT_ROW, true);
166 pMenu->Enable (IFMENU_PLOT_FFT_COL, true);
169 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
171 if (event.LeftUp()) {
172 std::ostringstream os;
173 os << "Selected column " << pt.x << " , row " << yPt << "\n";
174 *theApp->getLog() << os.str().c_str();
179 ImageFileCanvas::GetBestSize() const
184 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
185 return wxSize (rIF.nx(), rIF.ny());
191 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
193 BEGIN_EVENT_TABLE(ImageFileView, wxView)
194 EVT_MENU(IFMENU_FILE_EXPORT, ImageFileView::OnExport)
195 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
196 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
197 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
198 EVT_MENU(IFMENU_VIEW_SCALE_FULL, ImageFileView::OnScaleFull)
199 EVT_MENU(IFMENU_COMPARE_IMAGES, ImageFileView::OnCompare)
200 EVT_MENU(IFMENU_COMPARE_ROW, ImageFileView::OnCompareRow)
201 EVT_MENU(IFMENU_COMPARE_COL, ImageFileView::OnCompareCol)
202 EVT_MENU(IFMENU_FILTER_INVERTVALUES, ImageFileView::OnInvertValues)
203 EVT_MENU(IFMENU_FILTER_SQUARE, ImageFileView::OnSquare)
204 EVT_MENU(IFMENU_FILTER_SQRT, ImageFileView::OnSquareRoot)
205 EVT_MENU(IFMENU_FILTER_LOG, ImageFileView::OnLog)
206 EVT_MENU(IFMENU_FILTER_EXP, ImageFileView::OnExp)
207 EVT_MENU(IFMENU_FILTER_FOURIER, ImageFileView::OnFourier)
208 EVT_MENU(IFMENU_FILTER_INVERSE_FOURIER, ImageFileView::OnInverseFourier)
209 EVT_MENU(IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, ImageFileView::OnShuffleFourierToNaturalOrder)
210 EVT_MENU(IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, ImageFileView::OnShuffleNaturalToFourierOrder)
211 EVT_MENU(IFMENU_IMAGE_ADD, ImageFileView::OnAdd)
212 EVT_MENU(IFMENU_IMAGE_SUBTRACT, ImageFileView::OnSubtract)
213 EVT_MENU(IFMENU_IMAGE_MULTIPLY, ImageFileView::OnMultiply)
214 EVT_MENU(IFMENU_IMAGE_DIVIDE, ImageFileView::OnDivide)
215 EVT_MENU(IFMENU_IMAGE_SCALESIZE, ImageFileView::OnScaleSize)
217 EVT_MENU(IFMENU_FILTER_FFT, ImageFileView::OnFFT)
218 EVT_MENU(IFMENU_FILTER_IFFT, ImageFileView::OnIFFT)
219 EVT_MENU(IFMENU_FILTER_FFT_ROWS, ImageFileView::OnFFTRows)
220 EVT_MENU(IFMENU_FILTER_IFFT_ROWS, ImageFileView::OnIFFTRows)
221 EVT_MENU(IFMENU_FILTER_FFT_COLS, ImageFileView::OnFFTCols)
222 EVT_MENU(IFMENU_FILTER_IFFT_COLS, ImageFileView::OnIFFTCols)
224 EVT_MENU(IFMENU_FILTER_MAGNITUDE, ImageFileView::OnMagnitude)
225 EVT_MENU(IFMENU_FILTER_PHASE, ImageFileView::OnPhase)
226 EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)
227 EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol)
229 EVT_MENU(IFMENU_PLOT_FFT_ROW, ImageFileView::OnPlotFFTRow)
230 EVT_MENU(IFMENU_PLOT_FFT_COL, ImageFileView::OnPlotFFTCol)
232 EVT_MENU(IFMENU_PLOT_HISTOGRAM, ImageFileView::OnPlotHistogram)
235 ImageFileView::ImageFileView()
236 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
238 m_iDefaultExportFormatID = ImageFile::FORMAT_PNG;
241 ImageFileView::~ImageFileView()
243 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
244 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
248 ImageFileView::OnProperties (wxCommandEvent& event)
250 const ImageFile& rIF = GetDocument()->getImageFile();
251 if (rIF.nx() == 0 || rIF.ny() == 0)
252 *theApp->getLog() << "Properties: empty imagefile\n";
254 const std::string& rFilename = rIF.getFilename();
255 std::ostringstream os;
256 double min, max, mean, mode, median, stddev;
257 rIF.statistics (rIF.getArray(), min, max, mean, mode, median, stddev);
258 os << "Filename: " << rFilename << "\n";
259 os << "Size: (" << rIF.nx() << "," << rIF.ny() << ")\n";
265 os << "\nMinimum: "<<min<<"\nMaximum: "<<max<<"\nMean: "<<mean<<"\nMedian: "<<median<<"\nMode: "<<mode<<"\nStandard Deviation: "<<stddev << "\n";
266 if (rIF.isComplex()) {
267 rIF.statistics (rIF.getImaginaryArray(), min, max, mean, mode, median, stddev);
268 os << "\nImaginary: min: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
270 if (rIF.nLabels() > 0) {
272 rIF.printLabelsBrief (os);
274 *theApp->getLog() << os.str().c_str();
275 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
276 dialogMsg.ShowModal();
281 ImageFileView::OnScaleAuto (wxCommandEvent& event)
283 const ImageFile& rIF = GetDocument()->getImageFile();
284 double min, max, mean, mode, median, stddev;
285 rIF.statistics(min, max, mean, mode, median, stddev);
286 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
287 int iRetVal = dialogAutoScale.ShowModal();
288 if (iRetVal == wxID_OK) {
289 m_bMinSpecified = true;
290 m_bMaxSpecified = true;
292 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
295 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
296 OnUpdate (this, NULL);
302 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
304 const ImageFile& rIF = GetDocument()->getImageFile();
306 if (! m_bMinSpecified && ! m_bMaxSpecified)
307 rIF.getMinMax (min, max);
314 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Image Minimum & Maximum", min, max);
315 int retVal = dialogMinMax.ShowModal();
316 if (retVal == wxID_OK) {
317 m_bMinSpecified = true;
318 m_bMaxSpecified = true;
319 m_dMinPixel = dialogMinMax.getMinimum();
320 m_dMaxPixel = dialogMinMax.getMaximum();
321 OnUpdate (this, NULL);
326 ImageFileView::OnScaleFull (wxCommandEvent& event)
328 if (m_bMinSpecified || m_bMaxSpecified) {
329 m_bMinSpecified = false;
330 m_bMaxSpecified = false;
331 OnUpdate (this, NULL);
336 ImageFileView::OnCompare (wxCommandEvent& event)
338 std::vector<ImageFileDocument*> vecIF;
339 theApp->getCompatibleImages (GetDocument(), vecIF);
341 if (vecIF.size() == 0) {
342 wxMessageBox("There are no compatible image files open for comparision", "No comparison images");
344 DialogGetComparisonImage dialogGetCompare(getFrameForChild(), "Get Comparison Image", vecIF, true);
346 if (dialogGetCompare.ShowModal() == wxID_OK) {
347 const ImageFile& rIF = GetDocument()->getImageFile();
348 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
349 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
350 std::ostringstream os;
351 double min, max, mean, mode, median, stddev;
352 rIF.statistics (min, max, mean, mode, median, stddev);
353 os << GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
354 rCompareIF.statistics (min, max, mean, mode, median, stddev);
355 os << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
358 rIF.comparativeStatistics (rCompareIF, d, r, e);
359 os << "Comparative Statistics: d=" << d << ", r=" << r << ", e=" << e << "\n";
360 *theApp->getLog() << os.str().c_str();
361 if (dialogGetCompare.getMakeDifferenceImage()) {
362 ImageFileDocument* pDifferenceDoc = theApp->newImageDoc();
363 if (! pDifferenceDoc) {
364 sys_error (ERR_SEVERE, "Unable to create image file");
367 ImageFile& differenceImage = pDifferenceDoc->getImageFile();
369 differenceImage.setArraySize (rIF.nx(), rIF.ny());
370 if (! rIF.subtractImages (rCompareIF, differenceImage)) {
371 pDifferenceDoc->getView()->getFrame()->Show(true);
372 GetDocumentManager()->ActivateView (pDifferenceDoc->getView(), true, false);
373 pDifferenceDoc->getView()->getFrame()->SetFocus();
374 wxCommandEvent event;
375 GetDocumentManager()->OnFileClose (event);
376 GetDocumentManager()->ActivateView (this, true, false);
377 getFrame()->SetFocus();
381 wxString s = GetFrame()->GetTitle() + ": ";
382 differenceImage.labelsCopy (rIF, s.c_str());
383 s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
384 differenceImage.labelsCopy (rCompareIF, s.c_str());
385 std::ostringstream osLabel;
386 osLabel << "Compare image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str()
387 << " and " << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": "
389 differenceImage.labelAdd (os.str().c_str());
390 pDifferenceDoc->Modify (true);
391 pDifferenceDoc->UpdateAllViews (this);
392 pDifferenceDoc->getView()->OnUpdate (this, NULL);
393 pDifferenceDoc->getView()->getFrame()->Show(true);
395 wxMessageBox(os.str().c_str(), "Image Comparison");
401 ImageFileView::OnInvertValues (wxCommandEvent& event)
403 ImageFile& rIF = GetDocument()->getImageFile();
404 rIF.invertPixelValues (rIF);
405 rIF.labelAdd ("Invert Pixel Values");
406 GetDocument()->Modify (true);
407 GetDocument()->UpdateAllViews (this);
411 ImageFileView::OnSquare (wxCommandEvent& event)
413 ImageFile& rIF = GetDocument()->getImageFile();
415 rIF.labelAdd ("Square Pixel Values");
416 GetDocument()->Modify (true);
417 GetDocument()->UpdateAllViews (this);
421 ImageFileView::OnSquareRoot (wxCommandEvent& event)
423 ImageFile& rIF = GetDocument()->getImageFile();
425 rIF.labelAdd ("Square-root Pixel Values");
426 GetDocument()->Modify (true);
427 GetDocument()->UpdateAllViews (this);
431 ImageFileView::OnLog (wxCommandEvent& event)
433 ImageFile& rIF = GetDocument()->getImageFile();
435 rIF.labelAdd ("Logrithm base-e Pixel Values");
436 GetDocument()->Modify (true);
437 GetDocument()->UpdateAllViews (this);
441 ImageFileView::OnExp (wxCommandEvent& event)
443 ImageFile& rIF = GetDocument()->getImageFile();
445 rIF.labelAdd ("Exponent base-e Pixel Values");
446 GetDocument()->Modify (true);
447 GetDocument()->UpdateAllViews (this);
451 ImageFileView::OnAdd (wxCommandEvent& event)
453 std::vector<ImageFileDocument*> vecIF;
454 theApp->getCompatibleImages (GetDocument(), vecIF);
456 if (vecIF.size() == 0) {
457 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
459 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Add", vecIF, false);
461 if (dialogGetCompare.ShowModal() == wxID_OK) {
462 ImageFile& rIF = GetDocument()->getImageFile();
463 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
464 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
465 ImageFileDocument* pNewDoc = theApp->newImageDoc();
467 sys_error (ERR_SEVERE, "Unable to create image file");
470 ImageFile& newImage = pNewDoc->getImageFile();
471 newImage.setArraySize (rIF.nx(), rIF.ny());
472 rIF.addImages (rRHSIF, newImage);
473 std::ostringstream os;
474 os << "Add image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
475 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
476 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
477 newImage.labelsCopy (rIF, s.c_str());
478 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
479 newImage.labelsCopy (rRHSIF, s.c_str());
480 newImage.labelAdd (os.str().c_str());
481 *theApp->getLog() << os.str().c_str() << "\n";
482 pNewDoc->Modify (true);
483 pNewDoc->UpdateAllViews (this);
484 pNewDoc->getView()->OnUpdate (this, NULL);
485 pNewDoc->getView()->getFrame()->Show(true);
491 ImageFileView::OnSubtract (wxCommandEvent& event)
493 std::vector<ImageFileDocument*> vecIF;
494 theApp->getCompatibleImages (GetDocument(), vecIF);
496 if (vecIF.size() == 0) {
497 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
499 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Subtract", vecIF, false);
501 if (dialogGetCompare.ShowModal() == wxID_OK) {
502 ImageFile& rIF = GetDocument()->getImageFile();
503 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
504 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
505 ImageFileDocument* pNewDoc = theApp->newImageDoc();
507 sys_error (ERR_SEVERE, "Unable to create image file");
510 ImageFile& newImage = pNewDoc->getImageFile();
511 newImage.setArraySize (rIF.nx(), rIF.ny());
512 rIF.subtractImages (rRHSIF, newImage);
513 std::ostringstream os;
514 os << "Subtract image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
515 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
516 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
517 newImage.labelsCopy (rIF, s.c_str());
518 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
519 newImage.labelsCopy (rRHSIF, s.c_str());
520 newImage.labelAdd (os.str().c_str());
521 *theApp->getLog() << os.str().c_str() << "\n";
522 pNewDoc->Modify (true);
523 pNewDoc->UpdateAllViews (this);
524 pNewDoc->getView()->OnUpdate (this, NULL);
525 pNewDoc->getView()->getFrame()->Show(true);
531 ImageFileView::OnMultiply (wxCommandEvent& event)
533 std::vector<ImageFileDocument*> vecIF;
534 theApp->getCompatibleImages (GetDocument(), vecIF);
536 if (vecIF.size() == 0) {
537 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
539 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Multiply", vecIF, false);
541 if (dialogGetCompare.ShowModal() == wxID_OK) {
542 ImageFile& rIF = GetDocument()->getImageFile();
543 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
544 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
545 ImageFileDocument* pNewDoc = theApp->newImageDoc();
547 sys_error (ERR_SEVERE, "Unable to create image file");
550 ImageFile& newImage = pNewDoc->getImageFile();
551 newImage.setArraySize (rIF.nx(), rIF.ny());
552 rIF.multiplyImages (rRHSIF, newImage);
553 std::ostringstream os;
554 os << "Multiply image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
555 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
556 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
557 newImage.labelsCopy (rIF, s.c_str());
558 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
559 newImage.labelsCopy (rRHSIF, s.c_str());
560 newImage.labelAdd (os.str().c_str());
561 *theApp->getLog() << os.str().c_str() << "\n";
562 pNewDoc->Modify (true);
563 pNewDoc->UpdateAllViews (this);
564 pNewDoc->getView()->OnUpdate (this, NULL);
565 pNewDoc->getView()->getFrame()->Show(true);
571 ImageFileView::OnDivide (wxCommandEvent& event)
573 std::vector<ImageFileDocument*> vecIF;
574 theApp->getCompatibleImages (GetDocument(), vecIF);
576 if (vecIF.size() == 0) {
577 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
579 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Divide", vecIF, false);
581 if (dialogGetCompare.ShowModal() == wxID_OK) {
582 ImageFile& rIF = GetDocument()->getImageFile();
583 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
584 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
585 ImageFileDocument* pNewDoc = theApp->newImageDoc();
587 sys_error (ERR_SEVERE, "Unable to create image file");
590 ImageFile& newImage = pNewDoc->getImageFile();
591 newImage.setArraySize (rIF.nx(), rIF.ny());
592 rIF.divideImages (rRHSIF, newImage);
593 std::ostringstream os;
594 os << "Divide image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " by "
595 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
596 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
597 newImage.labelsCopy (rIF, s.c_str());
598 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
599 newImage.labelsCopy (rRHSIF, s.c_str());
600 newImage.labelAdd (os.str().c_str());
601 *theApp->getLog() << os.str().c_str() << "\n";
602 pNewDoc->Modify (true);
603 pNewDoc->UpdateAllViews (this);
604 pNewDoc->getView()->OnUpdate (this, NULL);
605 pNewDoc->getView()->getFrame()->Show(true);
613 ImageFileView::OnFFT (wxCommandEvent& event)
615 ImageFile& rIF = GetDocument()->getImageFile();
617 rIF.labelAdd ("FFT Image");
618 m_bMinSpecified = false;
619 m_bMaxSpecified = false;
620 GetDocument()->Modify (true);
621 GetDocument()->UpdateAllViews (this);
625 ImageFileView::OnIFFT (wxCommandEvent& event)
627 ImageFile& rIF = GetDocument()->getImageFile();
629 rIF.labelAdd ("IFFT Image");
630 m_bMinSpecified = false;
631 m_bMaxSpecified = false;
632 GetDocument()->Modify (true);
633 GetDocument()->UpdateAllViews (this);
637 ImageFileView::OnFFTRows (wxCommandEvent& event)
639 ImageFile& rIF = GetDocument()->getImageFile();
641 rIF.labelAdd ("FFT Rows");
642 m_bMinSpecified = false;
643 m_bMaxSpecified = false;
644 GetDocument()->Modify (true);
645 GetDocument()->UpdateAllViews (this);
649 ImageFileView::OnIFFTRows (wxCommandEvent& event)
651 ImageFile& rIF = GetDocument()->getImageFile();
653 rIF.labelAdd ("IFFT Rows");
654 m_bMinSpecified = false;
655 m_bMaxSpecified = false;
656 GetDocument()->Modify (true);
657 GetDocument()->UpdateAllViews (this);
661 ImageFileView::OnFFTCols (wxCommandEvent& event)
663 ImageFile& rIF = GetDocument()->getImageFile();
665 rIF.labelAdd ("FFT Columns");
666 m_bMinSpecified = false;
667 m_bMaxSpecified = false;
668 GetDocument()->Modify (true);
669 GetDocument()->UpdateAllViews (this);
673 ImageFileView::OnIFFTCols (wxCommandEvent& event)
675 ImageFile& rIF = GetDocument()->getImageFile();
677 rIF.labelAdd ("IFFT Columns");
678 m_bMinSpecified = false;
679 m_bMaxSpecified = false;
680 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 GetDocument()->Modify (true);
695 GetDocument()->UpdateAllViews (this);
699 ImageFileView::OnInverseFourier (wxCommandEvent& event)
701 ImageFile& rIF = GetDocument()->getImageFile();
702 wxProgressDialog dlgProgress (wxString("Inverse Fourier"), wxString("Inverse Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
703 rIF.inverseFourier (rIF);
704 rIF.labelAdd ("Inverse Fourier Image");
705 m_bMinSpecified = false;
706 m_bMaxSpecified = false;
707 GetDocument()->Modify (true);
708 GetDocument()->UpdateAllViews (this);
712 ImageFileView::OnShuffleNaturalToFourierOrder (wxCommandEvent& event)
714 ImageFile& rIF = GetDocument()->getImageFile();
715 Fourier::shuffleNaturalToFourierOrder (rIF);
716 rIF.labelAdd ("Shuffle Natural To Fourier Order");
717 m_bMinSpecified = false;
718 m_bMaxSpecified = false;
719 GetDocument()->Modify (true);
720 GetDocument()->UpdateAllViews (this);
724 ImageFileView::OnShuffleFourierToNaturalOrder (wxCommandEvent& event)
726 ImageFile& rIF = GetDocument()->getImageFile();
727 Fourier::shuffleFourierToNaturalOrder (rIF);
728 rIF.labelAdd ("Shuffle Fourier To Natural Order");
729 m_bMinSpecified = false;
730 m_bMaxSpecified = false;
731 GetDocument()->Modify (true);
732 GetDocument()->UpdateAllViews (this);
736 ImageFileView::OnMagnitude (wxCommandEvent& event)
738 ImageFile& rIF = GetDocument()->getImageFile();
739 if (rIF.isComplex()) {
741 rIF.labelAdd ("Magnitude of complex-image");
742 m_bMinSpecified = false;
743 m_bMaxSpecified = false;
744 GetDocument()->Modify (true);
745 GetDocument()->UpdateAllViews (this);
750 ImageFileView::OnPhase (wxCommandEvent& event)
752 ImageFile& rIF = GetDocument()->getImageFile();
753 if (rIF.isComplex()) {
755 rIF.labelAdd ("Phase of complex-image");
756 m_bMinSpecified = false;
757 m_bMaxSpecified = false;
758 GetDocument()->Modify (true);
759 GetDocument()->UpdateAllViews (this);
765 ImageFileView::CreateCanvas (wxFrame* parent)
767 ImageFileCanvas* pCanvas;
769 parent->GetClientSize(&width, &height);
771 pCanvas = new ImageFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
773 pCanvas->SetScrollbars(20, 20, 50, 50);
774 pCanvas->SetBackgroundColour(*wxWHITE);
785 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
788 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
790 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
792 theApp->setIconForFrame (subframe);
794 wxMenu *m_pFileMenu = new wxMenu;
796 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
797 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
798 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
799 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
800 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
801 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
803 m_pFileMenu->AppendSeparator();
804 m_pFileMenu->Append(IFMENU_FILE_PROPERTIES, "P&roperties");
805 m_pFileMenu->Append(IFMENU_FILE_EXPORT, "&Export...");
807 m_pFileMenu->AppendSeparator();
808 m_pFileMenu->Append(wxID_PRINT, "&Print...");
809 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
810 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
812 m_pFileMenu->AppendSeparator();
813 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
815 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
816 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
818 wxMenu *view_menu = new wxMenu;
819 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale S&et...\tCtrl-E");
820 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
821 view_menu->Append(IFMENU_VIEW_SCALE_FULL, "Display F&ull Scale\tCtrl-U");
823 wxMenu* filter_menu = new wxMenu;
824 filter_menu->Append (IFMENU_FILTER_INVERTVALUES, "&Invert Values");
825 filter_menu->Append (IFMENU_FILTER_SQUARE, "&Square");
826 filter_menu->Append (IFMENU_FILTER_SQRT, "Square &Root");
827 filter_menu->Append (IFMENU_FILTER_LOG, "&Log");
828 filter_menu->Append (IFMENU_FILTER_EXP, "&Exp");
829 filter_menu->AppendSeparator();
831 filter_menu->Append (IFMENU_FILTER_FFT, "2D &FFT");
832 filter_menu->Append (IFMENU_FILTER_IFFT, "2D &IFFT");
833 filter_menu->Append (IFMENU_FILTER_FFT_ROWS, "FFT Rows");
834 filter_menu->Append (IFMENU_FILTER_IFFT_ROWS, "IFFT Rows");
835 filter_menu->Append (IFMENU_FILTER_FFT_COLS, "FFT Columns");
836 filter_menu->Append (IFMENU_FILTER_IFFT_COLS, "IFFT Columns");
837 filter_menu->Append (IFMENU_FILTER_FOURIER, "F&ourier");
838 filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "Inverse Fo&urier");
840 filter_menu->Append (IFMENU_FILTER_FOURIER, "&Fourier");
841 filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "&Inverse Fourier");
843 filter_menu->Append (IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, "S&huffle Fourier to Natural Order");
844 filter_menu->Append (IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, "Shu&ffle Natural to Fourier Order");
845 filter_menu->Append (IFMENU_FILTER_MAGNITUDE, "&Magnitude");
846 filter_menu->Append (IFMENU_FILTER_PHASE, "&Phase");
848 wxMenu* image_menu = new wxMenu;
849 image_menu->Append (IFMENU_IMAGE_ADD, "&Add...");
850 image_menu->Append (IFMENU_IMAGE_SUBTRACT, "&Subtract...");
851 image_menu->Append (IFMENU_IMAGE_MULTIPLY, "&Multiply...");
852 image_menu->Append (IFMENU_IMAGE_DIVIDE, "&Divide...");
853 image_menu->AppendSeparator();
854 image_menu->Append (IFMENU_IMAGE_SCALESIZE, "S&cale Size...");
856 m_pMenuAnalyze = new wxMenu;
857 m_pMenuAnalyze->Append (IFMENU_PLOT_ROW, "Plot &Row");
858 m_pMenuAnalyze->Append (IFMENU_PLOT_COL, "Plot &Column");
859 m_pMenuAnalyze->Append (IFMENU_PLOT_HISTOGRAM, "Plot &Histogram");
860 m_pMenuAnalyze->AppendSeparator();
861 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_ROW, "Plot FFT Row");
862 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_COL, "Plot FFT Column");
863 m_pMenuAnalyze->AppendSeparator();
864 m_pMenuAnalyze->Append (IFMENU_COMPARE_IMAGES, "Compare &Images...");
865 m_pMenuAnalyze->Append (IFMENU_COMPARE_ROW, "Compare &Row");
866 m_pMenuAnalyze->Append (IFMENU_COMPARE_COL, "Compare &Column");
867 m_pMenuAnalyze->Enable (IFMENU_PLOT_ROW, false);
868 m_pMenuAnalyze->Enable (IFMENU_PLOT_COL, false);
869 m_pMenuAnalyze->Enable (IFMENU_COMPARE_ROW, false);
870 m_pMenuAnalyze->Enable (IFMENU_COMPARE_COL, false);
871 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_ROW, false);
872 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_COL, false);
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(m_pMenuAnalyze, "&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 (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 = 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 GetDocumentManager()->ActivateView (this, false, true);
999 if (! GetDocument() || ! GetDocument()->Close())
1003 //m_pCanvas->Show(false);
1004 m_pCanvas->setView(NULL);
1007 //m_pFrame->Show(false);
1008 wxString s(theApp->GetAppName());
1010 m_pFrame->SetTitle(s);
1017 m_pFrame->Destroy();
1025 ImageFileView::OnExport (wxCommandEvent& event)
1027 ImageFile& rIF = GetDocument()->getImageFile();
1028 ImageFileArrayConst v = rIF.getArray();
1031 if (v != NULL && nx != 0 && ny != 0) {
1032 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1034 rIF.getMinMax (min, max);
1035 if (! m_bMinSpecified)
1037 if (! m_bMaxSpecified)
1041 DialogExportParameters dialogExport (getFrameForChild(), m_iDefaultExportFormatID);
1042 if (dialogExport.ShowModal() == wxID_OK) {
1043 wxString strFormatName (dialogExport.getFormatName ());
1044 m_iDefaultExportFormatID = ImageFile::convertFormatNameToID (strFormatName.c_str());
1047 wxString strWildcard;
1048 if (m_iDefaultExportFormatID == ImageFile::FORMAT_PGM || m_iDefaultExportFormatID == ImageFile::FORMAT_PGMASCII) {
1050 strWildcard = "PGM Files (*.pgm)|*.pgm";
1053 else if (m_iDefaultExportFormatID == ImageFile::FORMAT_PNG || m_iDefaultExportFormatID == ImageFile::FORMAT_PNG16) {
1055 strWildcard = "PNG Files (*.png)|*.png";
1059 const wxString& strFilename = wxFileSelector (wxString("Export Filename"), wxString(""),
1060 wxString(""), strExt, strWildcard, wxOVERWRITE_PROMPT | wxHIDE_READONLY | wxSAVE);
1062 rIF.exportImage (strFormatName.c_str(), strFilename.c_str(), 1, 1, m_dMinPixel, m_dMaxPixel);
1063 *theApp->getLog() << "Exported file " << strFilename << "\n";
1070 ImageFileView::OnScaleSize (wxCommandEvent& event)
1072 ImageFile& rIF = GetDocument()->getImageFile();
1073 unsigned int iOldNX = rIF.nx();
1074 unsigned int iOldNY = rIF.ny();
1076 DialogGetXYSize dialogGetXYSize (getFrameForChild(), "Set New X & Y Dimensions", iOldNX, iOldNY);
1077 if (dialogGetXYSize.ShowModal() == wxID_OK) {
1078 unsigned int iNewNX = dialogGetXYSize.getXSize();
1079 unsigned int iNewNY = dialogGetXYSize.getYSize();
1080 std::ostringstream os;
1081 os << "Scale Size from (" << iOldNX << "," << iOldNY << ") to (" << iNewNX << "," << iNewNY << ")";
1082 ImageFileDocument* pScaledDoc = theApp->newImageDoc();
1084 sys_error (ERR_SEVERE, "Unable to create image file");
1087 ImageFile& rScaledIF = pScaledDoc->getImageFile();
1088 rScaledIF.setArraySize (iNewNX, iNewNY);
1089 rScaledIF.labelsCopy (rIF);
1090 rScaledIF.labelAdd (os.str().c_str());
1091 rIF.scaleImage (rScaledIF);
1092 *theApp->getLog() << os.str().c_str() << "\n";
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 = 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 pPlotDoc->Modify (true);
1179 pPlotDoc->UpdateAllViews ();
1180 pPlotDoc->getView()->OnUpdate (this, NULL);
1181 pPlotDoc->getView()->getFrame()->Show(true);
1186 ImageFileView::OnPlotCol (wxCommandEvent& event)
1188 int xCursor, yCursor;
1189 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1190 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1194 const ImageFile& rIF = GetDocument()->getImageFile();
1195 ImageFileArrayConst v = rIF.getArray();
1196 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1200 if (v != NULL && xCursor < nx) {
1201 double* pX = new double [ny];
1202 double* pYReal = new double [ny];
1203 double* pYImag = NULL;
1204 double* pYMag = NULL;
1205 if (rIF.isComplex()) {
1206 pYImag = new double [ny];
1207 pYMag = new double [ny];
1209 for (int i = 0; i < ny; i++) {
1211 pYReal[i] = v[xCursor][i];
1212 if (rIF.isComplex()) {
1213 pYImag[i] = vImag[xCursor][i];
1214 pYMag[i] = ::sqrt (v[xCursor][i] * v[xCursor][i] + vImag[xCursor][i] * vImag[xCursor][i]);
1217 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1219 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1221 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1222 std::ostringstream os;
1223 os << "Column " << xCursor;
1224 std::string title("title ");
1226 rPlotFile.addEzsetCommand (title.c_str());
1227 rPlotFile.addEzsetCommand ("xlabel Row");
1228 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1229 rPlotFile.addEzsetCommand ("lxfrac 0");
1230 rPlotFile.addEzsetCommand ("box");
1231 rPlotFile.addEzsetCommand ("grid");
1232 rPlotFile.addEzsetCommand ("curve 1");
1233 rPlotFile.addEzsetCommand ("color 1");
1234 if (rIF.isComplex()) {
1235 rPlotFile.addEzsetCommand ("dash 1");
1236 rPlotFile.addEzsetCommand ("curve 2");
1237 rPlotFile.addEzsetCommand ("color 4");
1238 rPlotFile.addEzsetCommand ("dash 3");
1239 rPlotFile.addEzsetCommand ("curve 3");
1240 rPlotFile.addEzsetCommand ("color 0");
1241 rPlotFile.addEzsetCommand ("solid");
1242 rPlotFile.setCurveSize (4, ny);
1244 rPlotFile.setCurveSize (2, ny);
1245 rPlotFile.addColumn (0, pX);
1246 rPlotFile.addColumn (1, pYReal);
1247 if (rIF.isComplex()) {
1248 rPlotFile.addColumn (2, pYImag);
1249 rPlotFile.addColumn (3, pYMag);
1251 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1252 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1253 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1254 *theApp->getLog() << os.str().c_str() << "\n";
1255 rPlotFile.addDescription (os.str().c_str());
1259 if (rIF.isComplex()) {
1263 pPlotDoc->Modify (true);
1264 pPlotDoc->UpdateAllViews ();
1265 pPlotDoc->getView()->OnUpdate (this, NULL);
1266 pPlotDoc->getView()->getFrame()->Show(true);
1272 ImageFileView::OnPlotFFTRow (wxCommandEvent& event)
1274 int xCursor, yCursor;
1275 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1276 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1280 const ImageFile& rIF = GetDocument()->getImageFile();
1281 ImageFileArrayConst v = rIF.getArray();
1282 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1286 if (v != NULL && yCursor < ny) {
1287 fftw_complex* pcIn = new fftw_complex [nx];
1290 for (i = 0; i < nx; i++) {
1291 pcIn[i].re = v[i][yCursor];
1292 if (rIF.isComplex())
1293 pcIn[i].im = vImag[i][yCursor];
1298 fftw_plan plan = fftw_create_plan (nx, FFTW_FORWARD, FFTW_IN_PLACE);
1299 fftw_one (plan, pcIn, NULL);
1300 fftw_destroy_plan (plan);
1302 double* pX = new double [nx];
1303 double* pYReal = new double [nx];
1304 double* pYImag = new double [nx];
1305 double* pYMag = new double [nx];
1306 for (i = 0; i < nx; i++) {
1308 pYReal[i] = pcIn[i].re;
1309 pYImag[i] = pcIn[i].im;
1310 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1312 Fourier::shuffleFourierToNaturalOrder (pYReal, nx);
1313 Fourier::shuffleFourierToNaturalOrder (pYImag, nx);
1314 Fourier::shuffleFourierToNaturalOrder (pYMag, nx);
1316 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1318 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1320 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1321 std::ostringstream os;
1322 os << "Row " << yCursor;
1323 std::string title("title ");
1325 rPlotFile.addEzsetCommand (title.c_str());
1326 rPlotFile.addEzsetCommand ("xlabel Column");
1327 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1328 rPlotFile.addEzsetCommand ("lxfrac 0");
1329 rPlotFile.addEzsetCommand ("curve 1");
1330 rPlotFile.addEzsetCommand ("color 1");
1331 rPlotFile.addEzsetCommand ("dash 1");
1332 rPlotFile.addEzsetCommand ("curve 2");
1333 rPlotFile.addEzsetCommand ("color 4");
1334 rPlotFile.addEzsetCommand ("dash 3");
1335 rPlotFile.addEzsetCommand ("curve 3");
1336 rPlotFile.addEzsetCommand ("color 0");
1337 rPlotFile.addEzsetCommand ("solid");
1338 rPlotFile.addEzsetCommand ("box");
1339 rPlotFile.addEzsetCommand ("grid");
1340 rPlotFile.setCurveSize (4, nx);
1341 rPlotFile.addColumn (0, pX);
1342 rPlotFile.addColumn (1, pYReal);
1343 rPlotFile.addColumn (2, pYImag);
1344 rPlotFile.addColumn (3, pYMag);
1345 for (int iL = 0; iL < rIF.nLabels(); iL++)
1346 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1347 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1348 *theApp->getLog() << os.str().c_str() << "\n";
1349 rPlotFile.addDescription (os.str().c_str());
1357 pPlotDoc->Modify (true);
1358 pPlotDoc->UpdateAllViews ();
1359 pPlotDoc->getView()->OnUpdate (this, NULL);
1360 pPlotDoc->getView()->getFrame()->Show(true);
1365 ImageFileView::OnPlotFFTCol (wxCommandEvent& event)
1367 int xCursor, yCursor;
1368 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1369 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1373 const ImageFile& rIF = GetDocument()->getImageFile();
1374 ImageFileArrayConst v = rIF.getArray();
1375 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1379 if (v != NULL && xCursor < nx) {
1380 fftw_complex* pcIn = new fftw_complex [ny];
1381 double *pdTemp = new double [ny];
1384 for (i = 0; i < ny; i++)
1385 pdTemp[i] = v[xCursor][i];
1386 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1387 for (i = 0; i < ny; i++)
1388 pcIn[i].re = pdTemp[i];
1390 for (i = 0; i < ny; i++) {
1391 if (rIF.isComplex())
1392 pdTemp[i] = vImag[xCursor][i];
1396 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1397 for (i = 0; i < ny; i++)
1398 pcIn[i].im = pdTemp[i];
1400 fftw_plan plan = fftw_create_plan (ny, FFTW_BACKWARD, FFTW_IN_PLACE);
1401 fftw_one (plan, pcIn, NULL);
1402 fftw_destroy_plan (plan);
1404 double* pX = new double [ny];
1405 double* pYReal = new double [ny];
1406 double* pYImag = new double [ny];
1407 double* pYMag = new double [ny];
1408 for (i = 0; i < ny; i++) {
1410 pYReal[i] = pcIn[i].re;
1411 pYImag[i] = pcIn[i].im;
1412 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1415 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1417 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1419 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1420 std::ostringstream os;
1421 os << "Column " << xCursor;
1422 std::string title("title ");
1424 rPlotFile.addEzsetCommand (title.c_str());
1425 rPlotFile.addEzsetCommand ("xlabel Column");
1426 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1427 rPlotFile.addEzsetCommand ("lxfrac 0");
1428 rPlotFile.addEzsetCommand ("curve 1");
1429 rPlotFile.addEzsetCommand ("color 1");
1430 rPlotFile.addEzsetCommand ("dash 1");
1431 rPlotFile.addEzsetCommand ("curve 2");
1432 rPlotFile.addEzsetCommand ("color 4");
1433 rPlotFile.addEzsetCommand ("dash 3");
1434 rPlotFile.addEzsetCommand ("curve 3");
1435 rPlotFile.addEzsetCommand ("color 0");
1436 rPlotFile.addEzsetCommand ("solid");
1437 rPlotFile.addEzsetCommand ("box");
1438 rPlotFile.addEzsetCommand ("grid");
1439 rPlotFile.setCurveSize (4, ny);
1440 rPlotFile.addColumn (0, pX);
1441 rPlotFile.addColumn (1, pYReal);
1442 rPlotFile.addColumn (2, pYImag);
1443 rPlotFile.addColumn (3, pYMag);
1444 for (int iL = 0; iL < rIF.nLabels(); iL++)
1445 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1446 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1447 *theApp->getLog() << os.str().c_str() << "\n";
1448 rPlotFile.addDescription (os.str().c_str());
1457 pPlotDoc->Modify (true);
1458 pPlotDoc->UpdateAllViews ();
1459 pPlotDoc->getView()->OnUpdate (this, NULL);
1460 pPlotDoc->getView()->getFrame()->Show(true);
1466 ImageFileView::OnCompareCol (wxCommandEvent& event)
1468 int xCursor, yCursor;
1469 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1470 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1474 std::vector<ImageFileDocument*> vecIFDoc;
1475 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1476 if (vecIFDoc.size() == 0) {
1477 wxMessageBox ("No compatible images for Column Comparison", "Error");
1480 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1482 if (dialogGetCompare.ShowModal() == wxID_OK) {
1483 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1484 const ImageFile& rIF = GetDocument()->getImageFile();
1485 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1487 ImageFileArrayConst v1 = rIF.getArray();
1488 ImageFileArrayConst v2 = rCompareIF.getArray();
1492 if (v1 != NULL && xCursor < nx) {
1493 double* pX = new double [ny];
1494 double* pY1 = new double [ny];
1495 double* pY2 = new double [ny];
1496 for (int i = 0; i < ny; i++) {
1498 pY1[i] = v1[xCursor][i];
1499 pY2[i] = v2[xCursor][i];
1501 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1503 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1505 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1506 std::ostringstream os;
1507 os << "Column " << xCursor << " Comparison";
1508 std::string title("title ");
1510 rPlotFile.addEzsetCommand (title.c_str());
1511 rPlotFile.addEzsetCommand ("xlabel Row");
1512 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1513 rPlotFile.addEzsetCommand ("lxfrac 0");
1514 rPlotFile.addEzsetCommand ("curve 1");
1515 rPlotFile.addEzsetCommand ("color 2");
1516 rPlotFile.addEzsetCommand ("curve 2");
1517 rPlotFile.addEzsetCommand ("color 4");
1518 rPlotFile.addEzsetCommand ("dash 5");
1519 rPlotFile.addEzsetCommand ("box");
1520 rPlotFile.addEzsetCommand ("grid");
1521 rPlotFile.setCurveSize (3, ny);
1522 rPlotFile.addColumn (0, pX);
1523 rPlotFile.addColumn (1, pY1);
1524 rPlotFile.addColumn (2, pY2);
1527 for (iL = 0; iL < rIF.nLabels(); iL++) {
1528 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1530 s += rIF.labelGet(iL).getLabelString();
1531 rPlotFile.addDescription (s.c_str());
1533 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1534 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1536 s += rCompareIF.labelGet(iL).getLabelString();
1537 rPlotFile.addDescription (s.c_str());
1539 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1540 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1541 *theApp->getLog() << os.str().c_str() << "\n";
1542 rPlotFile.addDescription (os.str().c_str());
1547 pPlotDoc->Modify (true);
1548 pPlotDoc->UpdateAllViews ();
1549 pPlotDoc->getView()->OnUpdate (this, NULL);
1550 pPlotDoc->getView()->getFrame()->Show(true);
1556 ImageFileView::OnCompareRow (wxCommandEvent& event)
1558 int xCursor, yCursor;
1559 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1560 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1564 std::vector<ImageFileDocument*> vecIFDoc;
1565 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1567 if (vecIFDoc.size() == 0) {
1568 wxMessageBox ("No compatible images for Row Comparison", "Error");
1572 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1574 if (dialogGetCompare.ShowModal() == wxID_OK) {
1575 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1576 const ImageFile& rIF = GetDocument()->getImageFile();
1577 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1579 ImageFileArrayConst v1 = rIF.getArray();
1580 ImageFileArrayConst v2 = rCompareIF.getArray();
1584 if (v1 != NULL && yCursor < ny) {
1585 double* pX = new double [nx];
1586 double* pY1 = new double [nx];
1587 double* pY2 = new double [nx];
1588 for (int i = 0; i < nx; i++) {
1590 pY1[i] = v1[i][yCursor];
1591 pY2[i] = v2[i][yCursor];
1593 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1595 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1597 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1598 std::ostringstream os;
1599 os << "Row " << yCursor << " Comparison";
1600 std::string title("title ");
1602 rPlotFile.addEzsetCommand (title.c_str());
1603 rPlotFile.addEzsetCommand ("xlabel Column");
1604 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1605 rPlotFile.addEzsetCommand ("lxfrac 0");
1606 rPlotFile.addEzsetCommand ("curve 1");
1607 rPlotFile.addEzsetCommand ("color 2");
1608 rPlotFile.addEzsetCommand ("curve 2");
1609 rPlotFile.addEzsetCommand ("color 4");
1610 rPlotFile.addEzsetCommand ("dash 5");
1611 rPlotFile.addEzsetCommand ("box");
1612 rPlotFile.addEzsetCommand ("grid");
1613 rPlotFile.setCurveSize (3, nx);
1614 rPlotFile.addColumn (0, pX);
1615 rPlotFile.addColumn (1, pY1);
1616 rPlotFile.addColumn (2, pY2);
1618 for (iL = 0; iL < rIF.nLabels(); iL++) {
1619 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1621 s += rIF.labelGet(iL).getLabelString();
1622 rPlotFile.addDescription (s.c_str());
1624 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1625 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1627 s += rCompareIF.labelGet(iL).getLabelString();
1628 rPlotFile.addDescription (s.c_str());
1630 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1631 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1632 *theApp->getLog() << os.str().c_str() << "\n";
1633 rPlotFile.addDescription (os.str().c_str());
1638 pPlotDoc->Modify (true);
1639 pPlotDoc->UpdateAllViews ();
1640 pPlotDoc->getView()->OnUpdate (this, NULL);
1641 pPlotDoc->getView()->getFrame()->Show(true);
1646 static int NUMBER_HISTOGRAM_BINS = 256;
1649 ImageFileView::OnPlotHistogram (wxCommandEvent& event)
1651 const ImageFile& rIF = GetDocument()->getImageFile();
1652 ImageFileArrayConst v = rIF.getArray();
1656 if (v != NULL && nx > 0 && ny > 0) {
1657 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1659 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1663 double* pX = new double [NUMBER_HISTOGRAM_BINS];
1664 double* pY = new double [NUMBER_HISTOGRAM_BINS];
1666 rIF.getMinMax (dMin, dMax);
1667 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
1669 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
1670 pX[i] = dMin + (i + 0.5) * dBinWidth;
1673 for (int ix = 0; ix < nx; ix++)
1674 for (int iy = 0; iy < ny; iy++) {
1675 int iBin = nearest<int> ((v[ix][iy] - dMin) / dBinWidth);
1676 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
1680 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1681 std::ostringstream os;
1683 std::string title("title ");
1685 rPlotFile.addEzsetCommand (title.c_str());
1686 rPlotFile.addEzsetCommand ("xlabel Pixel Value");
1687 rPlotFile.addEzsetCommand ("ylabel Count");
1688 rPlotFile.addEzsetCommand ("box");
1689 rPlotFile.addEzsetCommand ("grid");
1690 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
1691 rPlotFile.addColumn (0, pX);
1692 rPlotFile.addColumn (1, pY);
1693 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++) {
1694 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1696 s += rIF.labelGet(iL).getLabelString();
1697 rPlotFile.addDescription (s.c_str());
1699 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1700 *theApp->getLog() << os.str().c_str() << "\n";
1701 rPlotFile.addDescription (os.str().c_str());
1704 pPlotDoc->Modify (true);
1705 pPlotDoc->UpdateAllViews ();
1706 pPlotDoc->getView()->OnUpdate (this, NULL);
1707 pPlotDoc->getView()->getFrame()->Show(true);
1714 PhantomCanvas::PhantomCanvas (PhantomFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1715 : wxScrolledWindow(frame, -1, pos, size, style)
1720 PhantomCanvas::~PhantomCanvas ()
1726 PhantomCanvas::OnDraw (wxDC& dc)
1729 m_pView->OnDraw(& dc);
1735 IMPLEMENT_DYNAMIC_CLASS(PhantomFileView, wxView)
1737 BEGIN_EVENT_TABLE(PhantomFileView, wxView)
1738 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomFileView::OnProperties)
1739 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomFileView::OnRasterize)
1740 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomFileView::OnProjections)
1743 PhantomFileView::PhantomFileView()
1744 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0)
1746 #if defined(DEBUG) || defined(_DEBUG)
1747 m_iDefaultNDet = 165;
1748 m_iDefaultNView = 180;
1750 m_iDefaultNDet = 367;
1751 m_iDefaultNView = 320;
1753 m_iDefaultNSample = 1;
1754 m_dDefaultRotation = 1;
1755 m_dDefaultFocalLength = 2;
1756 m_dDefaultFieldOfView = 1;
1757 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
1758 m_iDefaultTrace = Trace::TRACE_NONE;
1761 m_iDefaultRasterNX = 115;
1762 m_iDefaultRasterNY = 115;
1763 m_iDefaultRasterNSamples = 1;
1765 m_iDefaultRasterNX = 256;
1766 m_iDefaultRasterNY = 256;
1767 m_iDefaultRasterNSamples = 2;
1771 PhantomFileView::~PhantomFileView()
1773 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
1774 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
1778 PhantomFileView::OnProperties (wxCommandEvent& event)
1780 const int idPhantom = GetDocument()->getPhantomID();
1781 const wxString& namePhantom = GetDocument()->getPhantomName();
1782 std::ostringstream os;
1783 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")" << "\n";
1784 const Phantom& rPhantom = GetDocument()->getPhantom();
1785 rPhantom.printDefinitions (os);
1787 rPhantom.print (os);
1789 *theApp->getLog() << os.str().c_str() << "\n";
1790 wxMessageBox (os.str().c_str(), "Phantom Properties");
1795 PhantomFileView::OnProjections (wxCommandEvent& event)
1797 DialogGetProjectionParameters dialogProjection (getFrameForChild(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView, m_iDefaultGeometry, m_iDefaultTrace);
1798 int retVal = dialogProjection.ShowModal();
1799 if (retVal == wxID_OK) {
1800 m_iDefaultNDet = dialogProjection.getNDet();
1801 m_iDefaultNView = dialogProjection.getNView();
1802 m_iDefaultNSample = dialogProjection.getNSamples();
1803 m_iDefaultTrace = dialogProjection.getTrace();
1804 m_dDefaultRotation = dialogProjection.getRotAngle();
1805 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
1806 m_dDefaultFieldOfView = dialogProjection.getFieldOfViewRatio();
1807 wxString sGeometry = dialogProjection.getGeometry();
1808 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
1810 if (m_iDefaultNDet > 0 && m_iDefaultNView > 0 && sGeometry != "") {
1811 const Phantom& rPhantom = GetDocument()->getPhantom();
1812 ProjectionFileDocument* pProjectionDoc = theApp->newProjectionDoc();
1813 if (! pProjectionDoc) {
1814 sys_error (ERR_SEVERE, "Unable to create projection document");
1817 Projections& rProj = pProjectionDoc->getProjections();
1818 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView);
1819 if (theScanner.fail()) {
1820 *theApp->getLog() << "Failed making scanner: " << theScanner.failMessage().c_str() << "\n";
1823 rProj.initFromScanner (theScanner);
1824 m_dDefaultRotation /= PI; // convert back to PI units
1827 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
1828 ProjectionsDialog dialogProjections (theScanner, rProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(getFrameForChild()));
1829 for (int iView = 0; iView < rProj.nView(); iView++) {
1831 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
1832 pProjectionDoc->getView()->getFrame()->Show(true);
1833 GetDocumentManager()->ActivateView (pProjectionDoc->getView(), true, false);
1834 pProjectionDoc->getView()->getFrame()->SetFocus();
1835 wxCommandEvent event;
1836 GetDocumentManager()->OnFileClose (event);
1837 GetDocumentManager()->ActivateView (this, true, false);
1838 getFrame()->SetFocus();
1842 while (dialogProjections.isPaused()) {
1848 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT);
1849 for (int i = 0; i < rProj.nView(); i++) {
1850 theScanner.collectProjections (rProj, rPhantom, i, 1, true, m_iDefaultTrace);
1851 if (! dlgProgress.Update (i+1)) {
1852 pProjectionDoc->getView()->getFrame()->Show(true);
1853 GetDocumentManager()->ActivateView (pProjectionDoc->getView(), true, false);
1854 pProjectionDoc->getView()->getFrame()->SetFocus();
1855 wxCommandEvent event;
1856 GetDocumentManager()->OnFileClose (event);
1857 GetDocumentManager()->ActivateView (this, true, false);
1858 getFrame()->SetFocus();
1864 std::ostringstream os;
1865 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();
1866 rProj.setCalcTime (timer.timerEnd());
1867 rProj.setRemark (os.str());
1868 *theApp->getLog() << os.str().c_str() << "\n";
1871 ProjectionFileView* projView = pProjectionDoc->getView();
1873 projView->OnUpdate (projView, NULL);
1874 if (projView->getCanvas())
1875 projView->getCanvas()->SetClientSize (m_iDefaultNDet, m_iDefaultNView);
1876 if (wxFrame* pFrame = projView->getFrame()) {
1881 GetDocumentManager()->ActivateView (projView, true, false);
1884 pProjectionDoc-> Modify(true);
1885 pProjectionDoc->UpdateAllViews (this);
1892 PhantomFileView::OnRasterize (wxCommandEvent& event)
1894 DialogGetRasterParameters dialogRaster (getFrameForChild(), m_iDefaultRasterNX, m_iDefaultRasterNY, m_iDefaultRasterNSamples);
1895 int retVal = dialogRaster.ShowModal();
1896 if (retVal == wxID_OK) {
1897 m_iDefaultRasterNX = dialogRaster.getXSize();
1898 m_iDefaultRasterNY = dialogRaster.getYSize();
1899 m_iDefaultRasterNSamples = dialogRaster.getNSamples();
1900 if (m_iDefaultRasterNSamples < 1)
1901 m_iDefaultRasterNSamples = 1;
1902 if (m_iDefaultRasterNX > 0 && m_iDefaultRasterNY > 0) {
1903 const Phantom& rPhantom = GetDocument()->getPhantom();
1904 ImageFileDocument* pRasterDoc = theApp->newImageDoc();
1906 sys_error (ERR_SEVERE, "Unable to create image file");
1909 ImageFile& imageFile = pRasterDoc->getImageFile();
1911 imageFile.setArraySize (m_iDefaultRasterNX, m_iDefaultRasterNY);
1912 wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"), imageFile.nx() + 1, getFrameForChild(), wxPD_CAN_ABORT);
1914 for (unsigned int i = 0; i < imageFile.nx(); i++) {
1915 rPhantom.convertToImagefile (imageFile, m_iDefaultRasterNSamples, Trace::TRACE_NONE, i, 1, true);
1916 if (! dlgProgress.Update (i+1)) {
1917 GetDocumentManager()->ActivateView (pRasterDoc->getView(), true, true);
1918 pRasterDoc->getView()->getFrame()->SetFocus();
1919 wxCommandEvent event;
1920 GetDocumentManager()->OnFileClose (event);
1921 GetDocumentManager()->ActivateView (this, true, false);
1922 getFrame()->SetFocus();
1926 pRasterDoc->Modify (true);
1927 pRasterDoc->UpdateAllViews (this);
1928 pRasterDoc->getView()->getFrame()->Show(true);
1929 std::ostringstream os;
1930 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << m_iDefaultRasterNX << ", YSize="
1931 << m_iDefaultRasterNY << ", nSamples=" << m_iDefaultRasterNSamples;
1932 *theApp->getLog() << os.str().c_str() << "\n";
1933 imageFile.labelAdd (os.str().c_str(), timer.timerEnd());
1934 ImageFileView* rasterView = pRasterDoc->getView();
1936 rasterView->getFrame()->SetFocus();
1937 rasterView->OnUpdate (rasterView, NULL);
1946 PhantomFileView::CreateCanvas (wxFrame *parent)
1948 PhantomCanvas* pCanvas;
1950 parent->GetClientSize(&width, &height);
1952 pCanvas = new PhantomCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
1954 pCanvas->SetBackgroundColour(*wxWHITE);
1965 PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view)
1968 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
1970 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
1972 theApp->setIconForFrame (subframe);
1974 wxMenu *m_pFileMenu = new wxMenu;
1976 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
1977 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
1978 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
1979 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
1980 m_pFileMenu->Append(wxID_CLOSE, "&Close");
1982 m_pFileMenu->AppendSeparator();
1983 m_pFileMenu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties");
1985 m_pFileMenu->AppendSeparator();
1986 m_pFileMenu->Append(wxID_PRINT, "&Print...");
1987 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
1988 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
1990 m_pFileMenu->AppendSeparator();
1991 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
1993 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
1994 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
1996 wxMenu *process_menu = new wxMenu;
1997 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...\tCtrl-R");
1998 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...\tCtrl-J");
2000 wxMenu *help_menu = new wxMenu;
2001 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2002 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
2003 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2005 wxMenuBar *menu_bar = new wxMenuBar;
2007 menu_bar->Append(m_pFileMenu, "&File");
2008 menu_bar->Append(process_menu, "&Process");
2009 menu_bar->Append(help_menu, "&Help");
2011 subframe->SetMenuBar(menu_bar);
2012 subframe->Centre(wxBOTH);
2014 wxAcceleratorEntry accelEntries[8];
2015 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
2016 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
2017 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
2018 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
2019 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
2020 accelEntries[5].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
2021 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('J'), PHMMENU_PROCESS_PROJECTIONS);
2022 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('R'), PHMMENU_PROCESS_RASTERIZE);
2023 wxAcceleratorTable accelTable (8, accelEntries);
2024 subframe->SetAcceleratorTable (accelTable);
2031 PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2033 m_pFrame = CreateChildFrame(doc, this);
2037 m_pFrame->GetClientSize(&width, &height);
2038 m_pFrame->SetTitle("PhantomFileView");
2039 m_pCanvas = CreateCanvas (m_pFrame);
2042 int x, y; // X requires a forced resize
2043 m_pFrame->GetSize(&x, &y);
2044 m_pFrame->SetSize(-1, -1, x, y);
2047 m_pFrame->Show(true);
2054 PhantomFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2057 m_pCanvas->Refresh();
2061 PhantomFileView::OnClose (bool deleteWindow)
2063 GetDocumentManager()->ActivateView (this, false, true);
2064 if (! GetDocument() || ! GetDocument()->Close())
2068 m_pCanvas->Show(false);
2069 m_pCanvas->setView(NULL);
2072 m_pFrame->Show(false);
2073 wxString s(wxTheApp->GetAppName());
2075 m_pFrame->SetTitle(s);
2082 m_pFrame->Destroy();
2091 PhantomFileView::OnDraw (wxDC* dc)
2094 m_pCanvas->GetClientSize (&xsize, &ysize);
2095 SGPDriver driver (dc, xsize, ysize);
2097 const Phantom& rPhantom = GetDocument()->getPhantom();
2098 sgp.setColor (C_RED);
2099 rPhantom.show (sgp);
2104 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2105 : wxScrolledWindow(frame, -1, pos, size, style)
2110 ProjectionFileCanvas::~ProjectionFileCanvas ()
2116 ProjectionFileCanvas::OnDraw(wxDC& dc)
2119 m_pView->OnDraw(& dc);
2123 ProjectionFileCanvas::GetBestSize () const
2127 Projections& rProj = m_pView->GetDocument()->getProjections();
2128 best.Set (rProj.nDet(), rProj.nView());
2135 // ProjectionFileView
2137 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
2139 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
2140 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
2141 EVT_MENU(PJMENU_RECONSTRUCT_FBP, ProjectionFileView::OnReconstructFBP)
2142 EVT_MENU(PJMENU_CONVERT_POLAR, ProjectionFileView::OnConvertPolar)
2143 EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
2146 ProjectionFileView::ProjectionFileView()
2147 : wxView(), m_pCanvas(NULL), m_pFrame(NULL), m_pFileMenu(0)
2157 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
2158 m_dDefaultFilterParam = 1.;
2160 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
2161 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
2163 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
2164 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
2166 m_iDefaultZeropad = 1;
2167 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF3;
2168 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
2169 m_iDefaultInterpParam = 1;
2170 m_iDefaultTrace = Trace::TRACE_NONE;
2172 m_iDefaultPolarNX = 256;
2173 m_iDefaultPolarNY = 256;
2174 m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR;
2175 m_iDefaultPolarZeropad = 1;
2178 ProjectionFileView::~ProjectionFileView()
2180 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2181 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2185 ProjectionFileView::OnProperties (wxCommandEvent& event)
2187 const Projections& rProj = GetDocument()->getProjections();
2188 std::ostringstream os;
2189 rProj.printScanInfo(os);
2190 *theApp->getLog() << os.str().c_str();
2191 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
2192 dialogMsg.ShowModal();
2197 ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
2199 Projections& rProj = GetDocument()->getProjections();
2200 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2201 m_iDefaultPolarInterpolation, -1);
2202 if (dialogPolar.ShowModal() == wxID_OK) {
2203 wxString strInterpolation (dialogPolar.getInterpolationName());
2204 m_iDefaultPolarNX = dialogPolar.getXSize();
2205 m_iDefaultPolarNY = dialogPolar.getYSize();
2206 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2207 ImageFile& rIF = pPolarDoc->getImageFile();
2209 sys_error (ERR_SEVERE, "Unable to create image file");
2212 rIF.setArraySize (m_iDefaultPolarNX, m_iDefaultPolarNY);
2213 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2214 rProj.convertPolar (rIF, m_iDefaultPolarInterpolation);
2215 rIF.labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2216 std::ostringstream os;
2217 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to polar image: xSize="
2218 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2219 << strInterpolation.c_str();
2220 *theApp->getLog() << os.str().c_str() << "\n";
2221 rIF.labelAdd (os.str().c_str());
2222 pPolarDoc->Modify (true);
2223 pPolarDoc->UpdateAllViews ();
2224 pPolarDoc->getView()->OnUpdate (this, NULL);
2225 pPolarDoc->getView()->getFrame()->Show(true);
2230 ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
2232 Projections& rProj = GetDocument()->getProjections();
2233 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert to FFT Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2234 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad);
2235 if (dialogPolar.ShowModal() == wxID_OK) {
2236 wxString strInterpolation (dialogPolar.getInterpolationName());
2237 m_iDefaultPolarNX = dialogPolar.getXSize();
2238 m_iDefaultPolarNY = dialogPolar.getYSize();
2239 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2240 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2241 ImageFile& rIF = pPolarDoc->getImageFile();
2243 sys_error (ERR_SEVERE, "Unable to create image file");
2246 rIF.setArraySize (m_iDefaultPolarNX, m_iDefaultPolarNY);
2247 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2248 rProj.convertFFTPolar (rIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad);
2249 rIF.labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2250 std::ostringstream os;
2251 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to FFT polar image: xSize="
2252 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2253 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2254 *theApp->getLog() << os.str().c_str() << "\n";
2255 rIF.labelAdd (os.str().c_str());
2256 pPolarDoc->Modify (true);
2257 pPolarDoc->UpdateAllViews ();
2258 pPolarDoc->getView()->OnUpdate (this, NULL);
2259 pPolarDoc->getView()->getFrame()->Show(true);
2264 ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
2266 wxMessageBox ("Fourier Reconstruction is not yet supported", "Unimplemented function");
2270 ProjectionFileView::OnReconstructFBP (wxCommandEvent& event)
2272 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);
2274 int retVal = dialogReconstruction.ShowModal();
2275 if (retVal == wxID_OK) {
2276 m_iDefaultNX = dialogReconstruction.getXSize();
2277 m_iDefaultNY = dialogReconstruction.getYSize();
2278 wxString optFilterName = dialogReconstruction.getFilterName();
2279 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
2280 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
2281 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
2282 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
2283 m_iDefaultZeropad = dialogReconstruction.getZeropad();
2284 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
2285 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
2286 wxString optInterpName = dialogReconstruction.getInterpName();
2287 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
2288 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
2289 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
2290 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
2291 m_iDefaultTrace = dialogReconstruction.getTrace();
2292 if (m_iDefaultNX > 0 && m_iDefaultNY > 0) {
2293 ImageFileDocument* pReconDoc = theApp->newImageDoc();
2295 sys_error (ERR_SEVERE, "Unable to create image file");
2298 ImageFile& imageFile = pReconDoc->getImageFile();
2299 const Projections& rProj = GetDocument()->getProjections();
2300 imageFile.setArraySize (m_iDefaultNX, m_iDefaultNY);
2302 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);
2305 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2306 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstruct, rProj, imageFile, m_iDefaultTrace, getFrameForChild());
2307 for (int iView = 0; iView < rProj.nView(); iView++) {
2310 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView)) {
2311 delete pDlgReconstruct;
2312 delete pReconstruct;
2313 pReconDoc->getView()->getFrame()->Close(true);
2318 while (pDlgReconstruct->isPaused()) {
2323 delete pDlgReconstruct;
2325 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT);
2326 for (int i = 0; i < rProj.nView(); i++) {
2327 pReconstruct->reconstructView (i, 1);
2328 if (! dlgProgress.Update (i + 1)) {
2329 delete pReconstruct;
2330 GetDocumentManager()->ActivateView (pReconDoc->getView(), true, true);
2331 pReconDoc->getView()->getFrame()->SetFocus();
2332 wxCommandEvent event;
2333 GetDocumentManager()->OnFileClose (event);
2334 GetDocumentManager()->ActivateView (this, true, false);
2335 getFrame()->SetFocus();
2340 delete pReconstruct;
2341 pReconDoc->Modify (true);
2342 pReconDoc->UpdateAllViews (this);
2343 if (ImageFileView* rasterView = pReconDoc->getView()) {
2344 rasterView->OnUpdate (rasterView, NULL);
2345 rasterView->getFrame()->SetFocus();
2346 rasterView->getFrame()->Show(true);
2348 std::ostringstream os;
2349 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();
2350 *theApp->getLog() << os.str().c_str() << "\n";
2351 imageFile.labelAdd (rProj.getLabel());
2352 imageFile.labelAdd (os.str().c_str(), timerRecon.timerEnd());
2358 ProjectionFileCanvas*
2359 ProjectionFileView::CreateCanvas (wxFrame *parent)
2361 ProjectionFileCanvas* pCanvas;
2363 parent->GetClientSize(&width, &height);
2365 pCanvas = new ProjectionFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
2367 pCanvas->SetScrollbars(20, 20, 50, 50);
2368 pCanvas->SetBackgroundColour(*wxWHITE);
2379 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2382 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2384 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2386 theApp->setIconForFrame (subframe);
2388 wxMenu *m_pFileMenu = new wxMenu;
2390 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2391 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2392 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2393 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2394 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2395 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2397 m_pFileMenu->AppendSeparator();
2398 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
2400 m_pFileMenu->AppendSeparator();
2401 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2402 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2403 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2405 m_pFileMenu->AppendSeparator();
2406 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2408 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2409 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2411 wxMenu *convert_menu = new wxMenu;
2412 convert_menu->Append (PJMENU_CONVERT_POLAR, "&Polar Image...\tCtrl-L");
2413 convert_menu->Append (PJMENU_CONVERT_FFT_POLAR, "&FFT->Polar Image...\tCtrl-I");
2415 wxMenu *reconstruct_menu = new wxMenu;
2416 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP, "&Filtered Backprojection...\tCtrl-R", "Reconstruct image using filtered backprojection");
2417 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Fourier...\tCtrl-E", "Reconstruct image using inverse Fourier");
2418 reconstruct_menu->Enable (PJMENU_RECONSTRUCT_FOURIER, false);
2420 wxMenu *help_menu = new wxMenu;
2421 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2422 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
2423 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2425 wxMenuBar *menu_bar = new wxMenuBar;
2427 menu_bar->Append (m_pFileMenu, "&File");
2428 menu_bar->Append (convert_menu, "&Convert");
2429 menu_bar->Append (reconstruct_menu, "&Reconstruct");
2430 menu_bar->Append (help_menu, "&Help");
2432 subframe->SetMenuBar(menu_bar);
2433 subframe->Centre(wxBOTH);
2435 wxAcceleratorEntry accelEntries[11];
2436 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
2437 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
2438 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
2439 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
2440 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
2441 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
2442 accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
2443 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('L'), PJMENU_CONVERT_POLAR);
2444 accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('I'), PJMENU_CONVERT_FFT_POLAR);
2445 accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('R'), PJMENU_RECONSTRUCT_FBP);
2446 accelEntries[10].Set (wxACCEL_CTRL, static_cast<int>('E'), PJMENU_RECONSTRUCT_FOURIER);
2447 wxAcceleratorTable accelTable (11, accelEntries);
2448 subframe->SetAcceleratorTable (accelTable);
2455 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2457 m_pFrame = CreateChildFrame(doc, this);
2461 m_pFrame->GetClientSize (&width, &height);
2462 m_pFrame->SetTitle ("ProjectionFileView");
2463 m_pCanvas = CreateCanvas (m_pFrame);
2466 int x, y; // X requires a forced resize
2467 m_pFrame->GetSize(&x, &y);
2468 m_pFrame->SetSize(-1, -1, x, y);
2471 m_pFrame->Show(true);
2478 ProjectionFileView::OnDraw (wxDC* dc)
2480 wxSize clientSize = m_pFrame->GetClientSize();
2481 wxSize bestSize = m_pCanvas->GetBestSize();
2483 if (clientSize.x > bestSize.x || clientSize.y > bestSize.y)
2484 m_pFrame->SetClientSize (bestSize);
2487 dc->DrawBitmap (m_bitmap, 0, 0, false);
2492 ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2494 const Projections& rProj = GetDocument()->getProjections();
2495 const int nDet = rProj.nDet();
2496 const int nView = rProj.nView();
2497 if (nDet != 0 && nView != 0) {
2498 const DetectorArray& detarray = rProj.getDetectorArray(0);
2499 const DetectorValue* detval = detarray.detValues();
2500 double min = detval[0];
2501 double max = detval[0];
2502 for (int iy = 0; iy < nView; iy++) {
2503 const DetectorArray& detarray = rProj.getDetectorArray(iy);
2504 const DetectorValue* detval = detarray.detValues();
2505 for (int ix = 0; ix < nDet; ix++) {
2506 if (min > detval[ix])
2508 else if (max < detval[ix])
2513 unsigned char* imageData = new unsigned char [nDet * nView * 3];
2514 double scale = (max - min) / 255;
2515 for (int iy2 = 0; iy2 < nView; iy2++) {
2516 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
2517 const DetectorValue* detval = detarray.detValues();
2518 for (int ix = 0; ix < nDet; ix++) {
2519 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
2520 intensity = clamp(intensity, 0, 255);
2521 int baseAddr = (iy2 * nDet + ix) * 3;
2522 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
2525 wxImage image (nDet, nView, imageData, true);
2526 m_bitmap = image.ConvertToBitmap();
2530 xSize = clamp (xSize, 0, 800);
2531 ySize = clamp (ySize, 0, 800);
2532 m_pFrame->SetClientSize (xSize, ySize);
2533 m_pCanvas->SetScrollbars (20, 20, nDet/20, nView/20);
2537 m_pCanvas->Refresh();
2541 ProjectionFileView::OnClose (bool deleteWindow)
2543 GetDocumentManager()->ActivateView (this, false, true);
2544 if (! GetDocument() || ! GetDocument()->Close())
2548 m_pCanvas->Show(false);
2549 m_pCanvas->setView(NULL);
2552 m_pFrame->Show(false);
2553 wxString s(wxTheApp->GetAppName());
2555 m_pFrame->SetTitle(s);
2562 m_pFrame->Destroy();
2572 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2573 : wxScrolledWindow(frame, -1, pos, size, style)
2578 PlotFileCanvas::~PlotFileCanvas ()
2584 PlotFileCanvas::OnDraw(wxDC& dc)
2587 m_pView->OnDraw(& dc);
2593 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
2595 BEGIN_EVENT_TABLE(PlotFileView, wxView)
2596 EVT_MENU(PJMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
2597 EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
2598 EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
2599 EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
2602 PlotFileView::PlotFileView()
2603 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pEZPlot(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
2607 PlotFileView::~PlotFileView()
2612 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2616 PlotFileView::OnProperties (wxCommandEvent& event)
2618 const PlotFile& rPlot = GetDocument()->getPlotFile();
2619 std::ostringstream os;
2620 os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
2621 rPlot.printHeadersBrief (os);
2622 *theApp->getLog() << os.str().c_str();
2623 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
2624 dialogMsg.ShowModal();
2629 PlotFileView::OnScaleAuto (wxCommandEvent& event)
2631 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2632 double min, max, mean, mode, median, stddev;
2633 rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
2634 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
2635 int iRetVal = dialogAutoScale.ShowModal();
2636 if (iRetVal == wxID_OK) {
2637 m_bMinSpecified = true;
2638 m_bMaxSpecified = true;
2640 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
2643 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
2644 OnUpdate (this, NULL);
2650 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
2652 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2656 if (! m_bMinSpecified || ! m_bMaxSpecified) {
2657 if (! rPlotFile.getMinMax (1, min, max)) {
2658 *theApp->getLog() << "Error: unable to find Min/Max\n";
2663 if (m_bMinSpecified)
2665 if (m_bMaxSpecified)
2668 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Y-axis Minimum & Maximum", min, max);
2669 int retVal = dialogMinMax.ShowModal();
2670 if (retVal == wxID_OK) {
2671 m_bMinSpecified = true;
2672 m_bMaxSpecified = true;
2673 m_dMinPixel = dialogMinMax.getMinimum();
2674 m_dMaxPixel = dialogMinMax.getMaximum();
2675 OnUpdate (this, NULL);
2680 PlotFileView::OnScaleFull (wxCommandEvent& event)
2682 if (m_bMinSpecified || m_bMaxSpecified) {
2683 m_bMinSpecified = false;
2684 m_bMaxSpecified = false;
2685 OnUpdate (this, NULL);
2691 PlotFileView::CreateCanvas (wxFrame* parent)
2693 PlotFileCanvas* pCanvas;
2695 parent->GetClientSize(&width, &height);
2697 pCanvas = new PlotFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
2699 pCanvas->SetBackgroundColour(*wxWHITE);
2710 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2713 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2715 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2717 theApp->setIconForFrame (subframe);
2719 wxMenu *m_pFileMenu = new wxMenu;
2721 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2722 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2723 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2724 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2725 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2726 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2728 m_pFileMenu->AppendSeparator();
2729 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
2731 m_pFileMenu->AppendSeparator();
2732 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2733 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2734 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2736 m_pFileMenu->AppendSeparator();
2737 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2739 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2740 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2742 wxMenu *view_menu = new wxMenu;
2743 view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...\tCtrl-E");
2744 view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
2745 view_menu->Append(PLOTMENU_VIEW_SCALE_FULL, "Display &Full Scale\tCtrl-U");
2747 wxMenu *help_menu = new wxMenu;
2748 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2749 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
2750 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2752 wxMenuBar *menu_bar = new wxMenuBar;
2754 menu_bar->Append(m_pFileMenu, "&File");
2755 menu_bar->Append(view_menu, "&View");
2756 menu_bar->Append(help_menu, "&Help");
2758 subframe->SetMenuBar(menu_bar);
2759 subframe->Centre(wxBOTH);
2761 wxAcceleratorEntry accelEntries[10];
2762 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
2763 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
2764 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
2765 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
2766 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
2767 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
2768 accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
2769 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('E'), PLOTMENU_VIEW_SCALE_MINMAX);
2770 accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('A'), PLOTMENU_VIEW_SCALE_AUTO);
2771 accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('U'), PLOTMENU_VIEW_SCALE_FULL);
2772 wxAcceleratorTable accelTable (10, accelEntries);
2773 subframe->SetAcceleratorTable (accelTable);
2780 PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
2782 m_pFrame = CreateChildFrame(doc, this);
2785 m_bMinSpecified = false;
2786 m_bMaxSpecified = false;
2787 m_dAutoScaleFactor = 1.;
2790 m_pFrame->GetClientSize(&width, &height);
2791 m_pFrame->SetTitle ("Plot File");
2792 m_pCanvas = CreateCanvas (m_pFrame);
2795 int x, y; // X requires a forced resize
2796 m_pFrame->GetSize(&x, &y);
2797 m_pFrame->SetSize(-1, -1, x, y);
2800 m_pFrame->Show(true);
2807 PlotFileView::OnDraw (wxDC* dc)
2809 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2810 const int iNColumns = rPlotFile.getNumColumns();
2811 const int iNRecords = rPlotFile.getNumRecords();
2813 if (iNColumns > 0 && iNRecords > 0) {
2815 m_pCanvas->GetClientSize (&xsize, &ysize);
2816 SGPDriver driver (dc, xsize, ysize);
2819 m_pEZPlot->plot (&sgp);
2825 PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2827 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2828 const int iNColumns = rPlotFile.getNumColumns();
2829 const int iNRecords = rPlotFile.getNumRecords();
2831 if (iNColumns > 0 && iNRecords > 0) {
2834 m_pEZPlot = new EZPlot;
2836 for (unsigned int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)
2837 m_pEZPlot->ezset (rPlotFile.getEzsetCommand (iEzset));
2839 if (m_bMinSpecified) {
2840 std::ostringstream os;
2841 os << "ymin " << m_dMinPixel;
2842 m_pEZPlot->ezset (os.str());
2845 if (m_bMaxSpecified) {
2846 std::ostringstream os;
2847 os << "ymax " << m_dMaxPixel;
2848 m_pEZPlot->ezset (os.str());
2851 m_pEZPlot->ezset("box");
2852 m_pEZPlot->ezset("grid");
2854 double* pdXaxis = new double [iNRecords];
2855 rPlotFile.getColumn (0, pdXaxis);
2857 double* pdY = new double [iNRecords];
2858 for (int iCol = 1; iCol < iNColumns; iCol++) {
2859 rPlotFile.getColumn (iCol, pdY);
2860 m_pEZPlot->addCurve (pdXaxis, pdY, iNRecords);
2868 m_pCanvas->Refresh();
2872 PlotFileView::OnClose (bool deleteWindow)
2874 GetDocumentManager()->ActivateView (this, false, true);
2875 if (! GetDocument() || ! GetDocument()->Close())
2879 //m_pCanvas->Show(false);
2880 m_pCanvas->setView (NULL);
2883 //m_pFrame->Show(false);
2884 wxString s(wxTheApp->GetAppName());
2886 m_pFrame->SetTitle(s);
2890 m_pFrame->SetView(NULL);
2894 m_pFrame->Destroy();
2902 ////////////////////////////////////////////////////////////////
2905 IMPLEMENT_DYNAMIC_CLASS(TextFileView, wxView)
2907 TextFileView::~TextFileView()
2909 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2910 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2913 bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2915 m_pFrame = CreateChildFrame(doc, this);
2916 SetFrame (m_pFrame);
2919 m_pFrame->GetClientSize(&width, &height);
2920 m_pFrame->SetTitle("TextFile");
2921 m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
2922 m_pFrame->SetTitle("Log");
2925 // X seems to require a forced resize
2927 frame->GetSize(&x, &y);
2928 frame->SetSize(-1, -1, x, y);
2931 m_pFrame->Show (true);
2937 // Handled by wxTextWindow
2938 void TextFileView::OnDraw(wxDC *WXUNUSED(dc) )
2942 void TextFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2947 TextFileView::OnClose (bool deleteWindow)
2949 // if (m_pFrame && m_pFrame->GetTitle() == "Log")
2952 GetDocumentManager()->ActivateView (this, false, true);
2953 if (! GetDocument() || ! GetDocument()->Close())
2956 //m_pCanvas->Show(false);
2957 //m_pFrame->Show(false);
2961 m_pFrame->SetView(NULL);
2964 m_pFrame->Destroy();
2977 TextFileView::CreateChildFrame (wxDocument *doc, wxView *view)
2980 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE);
2982 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE);
2984 theApp->setIconForFrame (subframe);
2986 wxMenu *m_pFileMenu = new wxMenu;
2988 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2989 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2990 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2991 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2992 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2993 // m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2995 m_pFileMenu->AppendSeparator();
2996 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2997 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2998 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3000 m_pFileMenu->AppendSeparator();
3001 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3003 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3004 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3006 wxMenu *help_menu = new wxMenu;
3007 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3008 help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
3009 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3011 wxMenuBar *menu_bar = new wxMenuBar;
3013 menu_bar->Append(m_pFileMenu, "&File");
3014 menu_bar->Append(help_menu, "&Help");
3016 subframe->SetMenuBar(menu_bar);
3017 subframe->Centre(wxBOTH);
3019 wxAcceleratorEntry accelEntries[5];
3020 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
3021 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
3022 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
3023 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
3024 accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
3025 wxAcceleratorTable accelTable (5, accelEntries);
3026 subframe->SetAcceleratorTable (accelTable);
3032 // Define a constructor for my text subwindow
3033 TextFileCanvas::TextFileCanvas (TextFileView* v, wxFrame* frame, const wxPoint& pos, const wxSize& size, long style)
3034 : wxTextCtrl (frame, -1, "", pos, size, style), m_pView(v)
3038 TextFileCanvas::~TextFileCanvas ()