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.111 2001/02/22 00:56:50 kevin Exp $
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
28 // For compilers that support precompilation, includes "wx/wx.h".
29 #include "wx/wxprec.h"
39 #if !wxUSE_DOC_VIEW_ARCHITECTURE
40 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
44 #include "wx/progdlg.h"
51 #include "dlgprojections.h"
52 #include "dlgreconstruct.h"
53 #include "backprojectors.h"
54 #include "reconstruct.h"
57 #if defined(MSVC) || HAVE_SSTREAM
60 #include <sstream_subst>
66 BEGIN_EVENT_TABLE(ImageFileCanvas, wxScrolledWindow)
67 EVT_MOUSE_EVENTS(ImageFileCanvas::OnMouseEvent)
68 EVT_CHAR(ImageFileCanvas::OnChar)
72 ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
73 : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v), m_xCursor(-1), m_yCursor(-1)
77 ImageFileCanvas::~ImageFileCanvas()
83 ImageFileCanvas::OnDraw(wxDC& dc)
86 m_pView->OnDraw(& dc);
90 ImageFileCanvas::DrawRubberBandCursor (wxDC& dc, int x, int y)
92 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
97 dc.SetLogicalFunction (wxINVERT);
98 dc.SetPen (*wxGREEN_PEN);
99 dc.DrawLine (0, yPt, nx, yPt);
100 dc.DrawLine (x, 0, x, ny);
101 dc.SetLogicalFunction (wxCOPY);
105 ImageFileCanvas::GetCurrentCursor (int& x, int& y)
110 if (m_xCursor >= 0 && m_yCursor >= 0)
117 ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
125 wxPoint pt(event.GetLogicalPosition(dc));
127 const ImageFileDocument* pIFDoc = m_pView->GetDocument();
130 const ImageFile& rIF = pIFDoc->getImageFile();
131 ImageFileArrayConst v = rIF.getArray();
134 const int yPt = ny - 1 - pt.y;
135 if (event.RightIsDown()) {
136 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
137 std::ostringstream os;
138 os << "Image value (" << pt.x << "," << yPt << ") = " << v[pt.x][yPt];
139 if (rIF.isComplex()) {
140 double dImag = rIF.getImaginaryArray()[pt.x][yPt];
142 os << " - " << -dImag;
144 os << " + " << dImag;
148 *theApp->getLog() << os.str().c_str();
150 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
152 else if (event.LeftIsDown() || event.LeftUp() || event.RightUp()) {
153 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
154 if (m_xCursor >= 0 && m_yCursor >= 0) {
155 DrawRubberBandCursor (dc, m_xCursor, m_yCursor);
157 DrawRubberBandCursor (dc, pt.x, yPt);
160 wxMenu* pMenu = m_pView->getMenuAnalyze();
161 if (pMenu && ! pMenu->IsEnabled(IFMENU_PLOT_ROW)) {
162 pMenu->Enable (IFMENU_PLOT_ROW, true);
163 pMenu->Enable (IFMENU_PLOT_COL, true);
164 pMenu->Enable (IFMENU_COMPARE_ROW, true);
165 pMenu->Enable (IFMENU_COMPARE_COL, true);
166 pMenu->Enable (IFMENU_PLOT_FFT_ROW, true);
167 pMenu->Enable (IFMENU_PLOT_FFT_COL, true);
170 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
172 if (event.LeftUp()) {
173 std::ostringstream os;
174 os << "Selected column " << pt.x << " , row " << yPt << "\n";
175 *theApp->getLog() << os.str().c_str();
180 ImageFileCanvas::OnChar (wxKeyEvent& event)
182 if (event.GetKeyCode() == WXK_ESCAPE) {
186 m_pView->OnUpdate (NULL);
188 wxScrolledWindow::OnChar (event);
192 ImageFileCanvas::GetBestSize() const
197 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
198 return wxSize (rIF.nx(), rIF.ny());
204 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
206 BEGIN_EVENT_TABLE(ImageFileView, wxView)
207 EVT_MENU(IFMENU_FILE_EXPORT, ImageFileView::OnExport)
208 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
209 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
210 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
211 EVT_MENU(IFMENU_VIEW_SCALE_FULL, ImageFileView::OnScaleFull)
212 EVT_MENU(IFMENU_COMPARE_IMAGES, ImageFileView::OnCompare)
213 EVT_MENU(IFMENU_COMPARE_ROW, ImageFileView::OnCompareRow)
214 EVT_MENU(IFMENU_COMPARE_COL, ImageFileView::OnCompareCol)
215 EVT_MENU(IFMENU_FILTER_INVERTVALUES, ImageFileView::OnInvertValues)
216 EVT_MENU(IFMENU_FILTER_SQUARE, ImageFileView::OnSquare)
217 EVT_MENU(IFMENU_FILTER_SQRT, ImageFileView::OnSquareRoot)
218 EVT_MENU(IFMENU_FILTER_LOG, ImageFileView::OnLog)
219 EVT_MENU(IFMENU_FILTER_EXP, ImageFileView::OnExp)
220 EVT_MENU(IFMENU_FILTER_FOURIER, ImageFileView::OnFourier)
221 EVT_MENU(IFMENU_FILTER_INVERSE_FOURIER, ImageFileView::OnInverseFourier)
222 EVT_MENU(IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, ImageFileView::OnShuffleFourierToNaturalOrder)
223 EVT_MENU(IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, ImageFileView::OnShuffleNaturalToFourierOrder)
224 EVT_MENU(IFMENU_IMAGE_ADD, ImageFileView::OnAdd)
225 EVT_MENU(IFMENU_IMAGE_SUBTRACT, ImageFileView::OnSubtract)
226 EVT_MENU(IFMENU_IMAGE_MULTIPLY, ImageFileView::OnMultiply)
227 EVT_MENU(IFMENU_IMAGE_DIVIDE, ImageFileView::OnDivide)
228 EVT_MENU(IFMENU_IMAGE_SCALESIZE, ImageFileView::OnScaleSize)
230 EVT_MENU(IFMENU_IMAGE_CONVERT3D, ImageFileView::OnConvert3d)
233 EVT_MENU(IFMENU_FILTER_FFT, ImageFileView::OnFFT)
234 EVT_MENU(IFMENU_FILTER_IFFT, ImageFileView::OnIFFT)
235 EVT_MENU(IFMENU_FILTER_FFT_ROWS, ImageFileView::OnFFTRows)
236 EVT_MENU(IFMENU_FILTER_IFFT_ROWS, ImageFileView::OnIFFTRows)
237 EVT_MENU(IFMENU_FILTER_FFT_COLS, ImageFileView::OnFFTCols)
238 EVT_MENU(IFMENU_FILTER_IFFT_COLS, ImageFileView::OnIFFTCols)
240 EVT_MENU(IFMENU_FILTER_MAGNITUDE, ImageFileView::OnMagnitude)
241 EVT_MENU(IFMENU_FILTER_PHASE, ImageFileView::OnPhase)
242 EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)
243 EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol)
245 EVT_MENU(IFMENU_PLOT_FFT_ROW, ImageFileView::OnPlotFFTRow)
246 EVT_MENU(IFMENU_PLOT_FFT_COL, ImageFileView::OnPlotFFTCol)
248 EVT_MENU(IFMENU_PLOT_HISTOGRAM, ImageFileView::OnPlotHistogram)
251 ImageFileView::ImageFileView()
252 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
254 m_iDefaultExportFormatID = ImageFile::FORMAT_PNG;
257 ImageFileView::~ImageFileView()
259 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
260 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
265 ImageFileView::OnProperties (wxCommandEvent& event)
267 const ImageFile& rIF = GetDocument()->getImageFile();
268 if (rIF.nx() == 0 || rIF.ny() == 0)
269 *theApp->getLog() << "Properties: empty imagefile\n";
271 const std::string rFilename = m_pFrame->GetTitle().c_str();
272 std::ostringstream os;
273 double min, max, mean, mode, median, stddev;
274 rIF.statistics (rIF.getArray(), min, max, mean, mode, median, stddev);
275 os << "Filename: " << rFilename << "\n";
276 os << "Size: (" << rIF.nx() << "," << rIF.ny() << ")\n";
282 os << "Minimum: "<<min<<"\nMaximum: "<<max<<"\nMean: "<<mean<<"\nMedian: "<<median<<"\nMode: "<<mode<<"\nStandard Deviation: "<<stddev << "\n";
283 if (rIF.isComplex()) {
284 rIF.statistics (rIF.getImaginaryArray(), min, max, mean, mode, median, stddev);
285 os << "Imaginary: min: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
287 if (rIF.nLabels() > 0) {
288 rIF.printLabelsBrief (os);
290 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
291 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
292 dialogMsg.ShowModal();
297 ImageFileView::OnScaleAuto (wxCommandEvent& event)
299 const ImageFile& rIF = GetDocument()->getImageFile();
300 double min, max, mean, mode, median, stddev;
301 rIF.statistics(min, max, mean, mode, median, stddev);
302 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
303 int iRetVal = dialogAutoScale.ShowModal();
304 if (iRetVal == wxID_OK) {
305 m_bMinSpecified = true;
306 m_bMaxSpecified = true;
308 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
311 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
312 OnUpdate (this, NULL);
318 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
320 const ImageFile& rIF = GetDocument()->getImageFile();
322 if (! m_bMinSpecified && ! m_bMaxSpecified)
323 rIF.getMinMax (min, max);
330 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Image Minimum & Maximum", min, max);
331 int retVal = dialogMinMax.ShowModal();
332 if (retVal == wxID_OK) {
333 m_bMinSpecified = true;
334 m_bMaxSpecified = true;
335 m_dMinPixel = dialogMinMax.getMinimum();
336 m_dMaxPixel = dialogMinMax.getMaximum();
337 OnUpdate (this, NULL);
342 ImageFileView::OnScaleFull (wxCommandEvent& event)
344 if (m_bMinSpecified || m_bMaxSpecified) {
345 m_bMinSpecified = false;
346 m_bMaxSpecified = false;
347 OnUpdate (this, NULL);
352 ImageFileView::OnCompare (wxCommandEvent& event)
354 std::vector<ImageFileDocument*> vecIF;
355 theApp->getCompatibleImages (GetDocument(), vecIF);
357 if (vecIF.size() == 0) {
358 wxMessageBox("There are no compatible image files open for comparision", "No comparison images");
360 DialogGetComparisonImage dialogGetCompare(getFrameForChild(), "Get Comparison Image", vecIF, true);
362 if (dialogGetCompare.ShowModal() == wxID_OK) {
363 const ImageFile& rIF = GetDocument()->getImageFile();
364 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
365 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
366 std::ostringstream os;
367 double min, max, mean, mode, median, stddev;
368 rIF.statistics (min, max, mean, mode, median, stddev);
369 os << GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
370 rCompareIF.statistics (min, max, mean, mode, median, stddev);
371 os << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
373 rIF.comparativeStatistics (rCompareIF, d, r, e);
374 os << "Comparative Statistics: d=" << d << ", r=" << r << ", e=" << e << "\n";
375 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
376 if (dialogGetCompare.getMakeDifferenceImage()) {
377 ImageFile* pDifferenceImage = new ImageFile;
379 pDifferenceImage->setArraySize (rIF.nx(), rIF.ny());
380 if (! rIF.subtractImages (rCompareIF, *pDifferenceImage)) {
381 *theApp->getLog() << "Unable to subtract images\n";
382 delete pDifferenceImage;
385 ImageFileDocument* pDifferenceDoc = theApp->newImageDoc();
386 if (! pDifferenceDoc) {
387 sys_error (ERR_SEVERE, "Unable to create image file");
390 pDifferenceDoc->setImageFile (pDifferenceImage);
392 wxString s = GetFrame()->GetTitle() + ": ";
393 pDifferenceImage->labelsCopy (rIF, s.c_str());
394 s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
395 pDifferenceImage->labelsCopy (rCompareIF, s.c_str());
396 std::ostringstream osLabel;
397 osLabel << "Compare image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str()
398 << " and " << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": "
400 pDifferenceImage->labelAdd (os.str().c_str());
401 if (theApp->getAskDeleteNewDocs())
402 pDifferenceDoc->Modify (true);
403 pDifferenceDoc->UpdateAllViews (this);
404 pDifferenceDoc->getView()->OnUpdate (this, NULL);
405 pDifferenceDoc->getView()->getFrame()->Show(true);
407 wxMessageBox(os.str().c_str(), "Image Comparison");
413 ImageFileView::OnInvertValues (wxCommandEvent& event)
415 ImageFile& rIF = GetDocument()->getImageFile();
416 rIF.invertPixelValues (rIF);
417 rIF.labelAdd ("Invert Pixel Values");
418 if (theApp->getAskDeleteNewDocs())
419 GetDocument()->Modify (true);
420 GetDocument()->UpdateAllViews (this);
424 ImageFileView::OnSquare (wxCommandEvent& event)
426 ImageFile& rIF = GetDocument()->getImageFile();
428 rIF.labelAdd ("Square Pixel Values");
429 if (theApp->getAskDeleteNewDocs())
430 GetDocument()->Modify (true);
431 GetDocument()->UpdateAllViews (this);
435 ImageFileView::OnSquareRoot (wxCommandEvent& event)
437 ImageFile& rIF = GetDocument()->getImageFile();
439 rIF.labelAdd ("Square-root Pixel Values");
440 if (theApp->getAskDeleteNewDocs())
441 GetDocument()->Modify (true);
442 GetDocument()->UpdateAllViews (this);
446 ImageFileView::OnLog (wxCommandEvent& event)
448 ImageFile& rIF = GetDocument()->getImageFile();
450 rIF.labelAdd ("Logrithm base-e Pixel Values");
451 if (theApp->getAskDeleteNewDocs())
452 GetDocument()->Modify (true);
453 GetDocument()->UpdateAllViews (this);
457 ImageFileView::OnExp (wxCommandEvent& event)
459 ImageFile& rIF = GetDocument()->getImageFile();
461 rIF.labelAdd ("Exponent base-e Pixel Values");
462 if (theApp->getAskDeleteNewDocs())
463 GetDocument()->Modify (true);
464 GetDocument()->UpdateAllViews (this);
468 ImageFileView::OnAdd (wxCommandEvent& event)
470 std::vector<ImageFileDocument*> vecIF;
471 theApp->getCompatibleImages (GetDocument(), vecIF);
473 if (vecIF.size() == 0) {
474 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
476 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Add", vecIF, false);
478 if (dialogGetCompare.ShowModal() == wxID_OK) {
479 ImageFile& rIF = GetDocument()->getImageFile();
480 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
481 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
482 ImageFileDocument* pNewDoc = theApp->newImageDoc();
484 sys_error (ERR_SEVERE, "Unable to create image file");
487 ImageFile& newImage = pNewDoc->getImageFile();
488 newImage.setArraySize (rIF.nx(), rIF.ny());
489 rIF.addImages (rRHSIF, newImage);
490 std::ostringstream os;
491 os << "Add image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
492 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
493 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
494 newImage.labelsCopy (rIF, s.c_str());
495 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
496 newImage.labelsCopy (rRHSIF, s.c_str());
497 newImage.labelAdd (os.str().c_str());
498 *theApp->getLog() << os.str().c_str() << "\n";
499 if (theApp->getAskDeleteNewDocs())
500 pNewDoc->Modify (true);
501 pNewDoc->UpdateAllViews (this);
502 pNewDoc->getView()->OnUpdate (this, NULL);
503 pNewDoc->getView()->getFrame()->Show(true);
509 ImageFileView::OnSubtract (wxCommandEvent& event)
511 std::vector<ImageFileDocument*> vecIF;
512 theApp->getCompatibleImages (GetDocument(), vecIF);
514 if (vecIF.size() == 0) {
515 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
517 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Subtract", vecIF, false);
519 if (dialogGetCompare.ShowModal() == wxID_OK) {
520 ImageFile& rIF = GetDocument()->getImageFile();
521 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
522 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
523 ImageFileDocument* pNewDoc = theApp->newImageDoc();
525 sys_error (ERR_SEVERE, "Unable to create image file");
528 ImageFile& newImage = pNewDoc->getImageFile();
529 newImage.setArraySize (rIF.nx(), rIF.ny());
530 rIF.subtractImages (rRHSIF, newImage);
531 std::ostringstream os;
532 os << "Subtract image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
533 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
534 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
535 newImage.labelsCopy (rIF, s.c_str());
536 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
537 newImage.labelsCopy (rRHSIF, s.c_str());
538 newImage.labelAdd (os.str().c_str());
539 *theApp->getLog() << os.str().c_str() << "\n";
540 if (theApp->getAskDeleteNewDocs())
541 pNewDoc->Modify (true);
542 pNewDoc->UpdateAllViews (this);
543 pNewDoc->getView()->OnUpdate (this, NULL);
544 pNewDoc->getView()->getFrame()->Show(true);
550 ImageFileView::OnMultiply (wxCommandEvent& event)
552 std::vector<ImageFileDocument*> vecIF;
553 theApp->getCompatibleImages (GetDocument(), vecIF);
555 if (vecIF.size() == 0) {
556 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
558 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Multiply", vecIF, false);
560 if (dialogGetCompare.ShowModal() == wxID_OK) {
561 ImageFile& rIF = GetDocument()->getImageFile();
562 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
563 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
564 ImageFileDocument* pNewDoc = theApp->newImageDoc();
566 sys_error (ERR_SEVERE, "Unable to create image file");
569 ImageFile& newImage = pNewDoc->getImageFile();
570 newImage.setArraySize (rIF.nx(), rIF.ny());
571 rIF.multiplyImages (rRHSIF, newImage);
572 std::ostringstream os;
573 os << "Multiply image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
574 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
575 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
576 newImage.labelsCopy (rIF, s.c_str());
577 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
578 newImage.labelsCopy (rRHSIF, s.c_str());
579 newImage.labelAdd (os.str().c_str());
580 *theApp->getLog() << os.str().c_str() << "\n";
581 if (theApp->getAskDeleteNewDocs())
582 pNewDoc->Modify (true);
583 pNewDoc->UpdateAllViews (this);
584 pNewDoc->getView()->OnUpdate (this, NULL);
585 pNewDoc->getView()->getFrame()->Show(true);
591 ImageFileView::OnDivide (wxCommandEvent& event)
593 std::vector<ImageFileDocument*> vecIF;
594 theApp->getCompatibleImages (GetDocument(), vecIF);
596 if (vecIF.size() == 0) {
597 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
599 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Divide", vecIF, false);
601 if (dialogGetCompare.ShowModal() == wxID_OK) {
602 ImageFile& rIF = GetDocument()->getImageFile();
603 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
604 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
605 ImageFileDocument* pNewDoc = theApp->newImageDoc();
607 sys_error (ERR_SEVERE, "Unable to create image file");
610 ImageFile& newImage = pNewDoc->getImageFile();
611 newImage.setArraySize (rIF.nx(), rIF.ny());
612 rIF.divideImages (rRHSIF, newImage);
613 std::ostringstream os;
614 os << "Divide image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " by "
615 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
616 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
617 newImage.labelsCopy (rIF, s.c_str());
618 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
619 newImage.labelsCopy (rRHSIF, s.c_str());
620 newImage.labelAdd (os.str().c_str());
621 *theApp->getLog() << os.str().c_str() << "\n";
622 if (theApp->getAskDeleteNewDocs())
623 pNewDoc->Modify (true);
624 pNewDoc->UpdateAllViews (this);
625 pNewDoc->getView()->OnUpdate (this, NULL);
626 pNewDoc->getView()->getFrame()->Show(true);
634 ImageFileView::OnFFT (wxCommandEvent& event)
636 ImageFile& rIF = GetDocument()->getImageFile();
638 rIF.labelAdd ("FFT Image");
639 m_bMinSpecified = false;
640 m_bMaxSpecified = false;
641 if (theApp->getAskDeleteNewDocs())
642 GetDocument()->Modify (true);
643 GetDocument()->UpdateAllViews (this);
647 ImageFileView::OnIFFT (wxCommandEvent& event)
649 ImageFile& rIF = GetDocument()->getImageFile();
651 rIF.labelAdd ("IFFT Image");
652 m_bMinSpecified = false;
653 m_bMaxSpecified = false;
654 if (theApp->getAskDeleteNewDocs())
655 GetDocument()->Modify (true);
656 GetDocument()->UpdateAllViews (this);
660 ImageFileView::OnFFTRows (wxCommandEvent& event)
662 ImageFile& rIF = GetDocument()->getImageFile();
664 rIF.labelAdd ("FFT Rows");
665 m_bMinSpecified = false;
666 m_bMaxSpecified = false;
667 if (theApp->getAskDeleteNewDocs())
668 GetDocument()->Modify (true);
669 GetDocument()->UpdateAllViews (this);
673 ImageFileView::OnIFFTRows (wxCommandEvent& event)
675 ImageFile& rIF = GetDocument()->getImageFile();
677 rIF.labelAdd ("IFFT Rows");
678 m_bMinSpecified = false;
679 m_bMaxSpecified = false;
680 if (theApp->getAskDeleteNewDocs())
681 GetDocument()->Modify (true);
682 GetDocument()->UpdateAllViews (this);
686 ImageFileView::OnFFTCols (wxCommandEvent& event)
688 ImageFile& rIF = GetDocument()->getImageFile();
690 rIF.labelAdd ("FFT Columns");
691 m_bMinSpecified = false;
692 m_bMaxSpecified = false;
693 if (theApp->getAskDeleteNewDocs())
694 GetDocument()->Modify (true);
695 GetDocument()->UpdateAllViews (this);
699 ImageFileView::OnIFFTCols (wxCommandEvent& event)
701 ImageFile& rIF = GetDocument()->getImageFile();
703 rIF.labelAdd ("IFFT Columns");
704 m_bMinSpecified = false;
705 m_bMaxSpecified = false;
706 if (theApp->getAskDeleteNewDocs())
707 GetDocument()->Modify (true);
708 GetDocument()->UpdateAllViews (this);
713 ImageFileView::OnFourier (wxCommandEvent& event)
715 ImageFile& rIF = GetDocument()->getImageFile();
716 wxProgressDialog dlgProgress (wxString("Fourier"), wxString("Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
718 rIF.labelAdd ("Fourier Image");
719 m_bMinSpecified = false;
720 m_bMaxSpecified = false;
721 if (theApp->getAskDeleteNewDocs())
722 GetDocument()->Modify (true);
723 GetDocument()->UpdateAllViews (this);
727 ImageFileView::OnInverseFourier (wxCommandEvent& event)
729 ImageFile& rIF = GetDocument()->getImageFile();
730 wxProgressDialog dlgProgress (wxString("Inverse Fourier"), wxString("Inverse Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
731 rIF.inverseFourier (rIF);
732 rIF.labelAdd ("Inverse Fourier Image");
733 m_bMinSpecified = false;
734 m_bMaxSpecified = false;
735 if (theApp->getAskDeleteNewDocs())
736 GetDocument()->Modify (true);
737 GetDocument()->UpdateAllViews (this);
741 ImageFileView::OnShuffleNaturalToFourierOrder (wxCommandEvent& event)
743 ImageFile& rIF = GetDocument()->getImageFile();
744 Fourier::shuffleNaturalToFourierOrder (rIF);
745 rIF.labelAdd ("Shuffle Natural To Fourier Order");
746 m_bMinSpecified = false;
747 m_bMaxSpecified = false;
748 if (theApp->getAskDeleteNewDocs())
749 GetDocument()->Modify (true);
750 GetDocument()->UpdateAllViews (this);
754 ImageFileView::OnShuffleFourierToNaturalOrder (wxCommandEvent& event)
756 ImageFile& rIF = GetDocument()->getImageFile();
757 Fourier::shuffleFourierToNaturalOrder (rIF);
758 rIF.labelAdd ("Shuffle Fourier To Natural Order");
759 m_bMinSpecified = false;
760 m_bMaxSpecified = false;
761 if (theApp->getAskDeleteNewDocs())
762 GetDocument()->Modify (true);
763 GetDocument()->UpdateAllViews (this);
767 ImageFileView::OnMagnitude (wxCommandEvent& event)
769 ImageFile& rIF = GetDocument()->getImageFile();
770 if (rIF.isComplex()) {
772 rIF.labelAdd ("Magnitude of complex-image");
773 m_bMinSpecified = false;
774 m_bMaxSpecified = false;
775 if (theApp->getAskDeleteNewDocs())
776 GetDocument()->Modify (true);
777 GetDocument()->UpdateAllViews (this);
782 ImageFileView::OnPhase (wxCommandEvent& event)
784 ImageFile& rIF = GetDocument()->getImageFile();
785 if (rIF.isComplex()) {
787 rIF.labelAdd ("Phase of complex-image");
788 m_bMinSpecified = false;
789 m_bMaxSpecified = false;
790 if (theApp->getAskDeleteNewDocs())
791 GetDocument()->Modify (true);
792 GetDocument()->UpdateAllViews (this);
798 ImageFileView::CreateCanvas (wxFrame* parent)
800 ImageFileCanvas* pCanvas;
802 parent->GetClientSize(&width, &height);
804 pCanvas = new ImageFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
806 pCanvas->SetScrollbars(20, 20, 50, 50);
807 pCanvas->SetBackgroundColour(*wxWHITE);
818 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
821 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
823 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
825 theApp->setIconForFrame (subframe);
827 m_pFileMenu = new wxMenu;
829 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
830 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
831 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
832 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
833 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
834 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
835 m_pFileMenu->Append(wxID_REVERT, "Re&vert");
837 m_pFileMenu->AppendSeparator();
838 m_pFileMenu->Append(IFMENU_FILE_PROPERTIES, "P&roperties");
839 m_pFileMenu->Append(IFMENU_FILE_EXPORT, "&Export...");
841 m_pFileMenu->AppendSeparator();
842 m_pFileMenu->Append(wxID_PRINT, "&Print...");
843 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
844 m_pFileMenu->Append(wxID_PREVIEW, "Print Preview");
846 m_pFileMenu->AppendSeparator();
847 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
848 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
850 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
851 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
853 wxMenu *view_menu = new wxMenu;
854 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale S&et...\tCtrl-E");
855 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
856 view_menu->Append(IFMENU_VIEW_SCALE_FULL, "Display F&ull Scale\tCtrl-U");
858 wxMenu* filter_menu = new wxMenu;
859 filter_menu->Append (IFMENU_FILTER_INVERTVALUES, "&Invert Values");
860 filter_menu->Append (IFMENU_FILTER_SQUARE, "&Square");
861 filter_menu->Append (IFMENU_FILTER_SQRT, "Square &Root");
862 filter_menu->Append (IFMENU_FILTER_LOG, "&Log");
863 filter_menu->Append (IFMENU_FILTER_EXP, "&Exp");
864 filter_menu->AppendSeparator();
866 filter_menu->Append (IFMENU_FILTER_FFT, "2-D &FFT");
867 filter_menu->Append (IFMENU_FILTER_IFFT, "2-D &IFFT");
868 filter_menu->Append (IFMENU_FILTER_FFT_ROWS, "FFT Rows");
869 filter_menu->Append (IFMENU_FILTER_IFFT_ROWS, "IFFT Rows");
870 filter_menu->Append (IFMENU_FILTER_FFT_COLS, "FFT Columns");
871 filter_menu->Append (IFMENU_FILTER_IFFT_COLS, "IFFT Columns");
872 filter_menu->Append (IFMENU_FILTER_FOURIER, "2-D F&ourier");
873 filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "2-D Inverse Fo&urier");
875 filter_menu->Append (IFMENU_FILTER_FOURIER, "&Fourier");
876 filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "&Inverse Fourier");
878 filter_menu->Append (IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, "S&huffle Fourier to Natural Order");
879 filter_menu->Append (IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, "Shu&ffle Natural to Fourier Order");
880 filter_menu->Append (IFMENU_FILTER_MAGNITUDE, "&Magnitude");
881 filter_menu->Append (IFMENU_FILTER_PHASE, "&Phase");
883 wxMenu* image_menu = new wxMenu;
884 image_menu->Append (IFMENU_IMAGE_ADD, "&Add...");
885 image_menu->Append (IFMENU_IMAGE_SUBTRACT, "&Subtract...");
886 image_menu->Append (IFMENU_IMAGE_MULTIPLY, "&Multiply...");
887 image_menu->Append (IFMENU_IMAGE_DIVIDE, "&Divide...");
888 image_menu->AppendSeparator();
889 image_menu->Append (IFMENU_IMAGE_SCALESIZE, "S&cale Size...");
891 image_menu->Append (IFMENU_IMAGE_CONVERT3D, "Convert &3-D\tCtrl-3");
894 m_pMenuAnalyze = new wxMenu;
895 m_pMenuAnalyze->Append (IFMENU_PLOT_ROW, "Plot &Row");
896 m_pMenuAnalyze->Append (IFMENU_PLOT_COL, "Plot &Column");
897 m_pMenuAnalyze->Append (IFMENU_PLOT_HISTOGRAM, "Plot &Histogram");
898 m_pMenuAnalyze->AppendSeparator();
899 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_ROW, "Plot FFT Row");
900 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_COL, "Plot FFT Column");
901 m_pMenuAnalyze->AppendSeparator();
902 m_pMenuAnalyze->Append (IFMENU_COMPARE_IMAGES, "Compare &Images...");
903 m_pMenuAnalyze->Append (IFMENU_COMPARE_ROW, "Compare &Row");
904 m_pMenuAnalyze->Append (IFMENU_COMPARE_COL, "Compare &Column");
905 m_pMenuAnalyze->Enable (IFMENU_PLOT_ROW, false);
906 m_pMenuAnalyze->Enable (IFMENU_PLOT_COL, false);
907 m_pMenuAnalyze->Enable (IFMENU_COMPARE_ROW, false);
908 m_pMenuAnalyze->Enable (IFMENU_COMPARE_COL, false);
909 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_ROW, false);
910 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_COL, false);
912 wxMenu *help_menu = new wxMenu;
913 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
914 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
915 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
916 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
918 wxMenuBar *menu_bar = new wxMenuBar;
920 menu_bar->Append(m_pFileMenu, "&File");
921 menu_bar->Append(view_menu, "&View");
922 menu_bar->Append(image_menu, "&Image");
923 menu_bar->Append(filter_menu, "Fi<er");
924 menu_bar->Append(m_pMenuAnalyze, "&Analyze");
925 menu_bar->Append(help_menu, "&Help");
927 subframe->SetMenuBar(menu_bar);
929 subframe->Centre(wxBOTH);
931 wxAcceleratorEntry accelEntries[4];
932 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('A'), IFMENU_VIEW_SCALE_AUTO);
933 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('U'), IFMENU_VIEW_SCALE_FULL);
934 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('E'), IFMENU_VIEW_SCALE_MINMAX);
936 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('3'), IFMENU_IMAGE_CONVERT3D);
937 wxAcceleratorTable accelTable (4, accelEntries);
939 wxAcceleratorTable accelTable (3, accelEntries);
942 subframe->SetAcceleratorTable (accelTable);
949 ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
951 m_pFrame = CreateChildFrame(doc, this);
953 m_bMinSpecified = false;
954 m_bMaxSpecified = false;
955 m_dAutoScaleFactor = 1.;
958 m_pFrame->GetClientSize (&width, &height);
959 m_pFrame->SetTitle("ImageFileView");
960 m_pCanvas = CreateCanvas (m_pFrame);
962 int x, y; // X requires a forced resize
963 m_pFrame->GetSize(&x, &y);
964 m_pFrame->SetSize(-1, -1, x, y);
965 m_pFrame->SetFocus();
966 m_pFrame->Show(true);
973 ImageFileView::OnDraw (wxDC* dc)
975 wxSize sizeWindow = m_pFrame->GetClientSize();
976 wxSize sizeBest = m_pCanvas->GetBestSize();
977 if (sizeWindow.x > sizeBest.x || sizeWindow.y > sizeBest.y)
978 m_pFrame->SetClientSize (sizeBest);
981 dc->DrawBitmap(m_bitmap, 0, 0, false);
983 int xCursor, yCursor;
984 if (m_pCanvas->GetCurrentCursor (xCursor, yCursor))
985 m_pCanvas->DrawRubberBandCursor (*dc, xCursor, yCursor);
990 ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
992 const ImageFile& rIF = GetDocument()->getImageFile();
993 ImageFileArrayConst v = rIF.getArray();
996 if (v != NULL && nx != 0 && ny != 0) {
997 if (! m_bMinSpecified || ! m_bMaxSpecified) {
999 rIF.getMinMax (min, max);
1000 if (! m_bMinSpecified)
1002 if (! m_bMaxSpecified)
1005 double scaleWidth = m_dMaxPixel - m_dMinPixel;
1007 unsigned char* imageData = new unsigned char [nx * ny * 3];
1008 for (int ix = 0; ix < nx; ix++) {
1009 for (int iy = 0; iy < ny; iy++) {
1010 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
1011 int intensity = static_cast<int>(scaleValue + 0.5);
1012 intensity = clamp (intensity, 0, 255);
1013 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
1014 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
1017 wxImage image (nx, ny, imageData, true);
1018 m_bitmap = image.ConvertToBitmap();
1022 ySize = clamp (ySize, 0, 800);
1023 m_pFrame->SetClientSize (xSize, ySize);
1024 m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20);
1025 m_pCanvas->SetBackgroundColour(*wxWHITE);
1029 m_pCanvas->Refresh();
1033 ImageFileView::OnClose (bool deleteWindow)
1035 //GetDocumentManager()->ActivateView (this, false, true);
1036 if (! GetDocument() || ! GetDocument()->Close())
1041 m_pCanvas->setView(NULL);
1044 wxString s(theApp->GetAppName());
1046 m_pFrame->SetTitle(s);
1053 if (GetDocument() && GetDocument()->getBadFileOpen())
1054 ::wxYield(); // wxWindows bug workaround
1061 ImageFileView::OnExport (wxCommandEvent& event)
1063 ImageFile& rIF = GetDocument()->getImageFile();
1064 ImageFileArrayConst v = rIF.getArray();
1067 if (v != NULL && nx != 0 && ny != 0) {
1068 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1070 rIF.getMinMax (min, max);
1071 if (! m_bMinSpecified)
1073 if (! m_bMaxSpecified)
1077 DialogExportParameters dialogExport (getFrameForChild(), m_iDefaultExportFormatID);
1078 if (dialogExport.ShowModal() == wxID_OK) {
1079 wxString strFormatName (dialogExport.getFormatName ());
1080 m_iDefaultExportFormatID = ImageFile::convertFormatNameToID (strFormatName.c_str());
1083 wxString strWildcard;
1084 if (m_iDefaultExportFormatID == ImageFile::FORMAT_PGM || m_iDefaultExportFormatID == ImageFile::FORMAT_PGMASCII) {
1086 strWildcard = "PGM Files (*.pgm)|*.pgm";
1089 else if (m_iDefaultExportFormatID == ImageFile::FORMAT_PNG || m_iDefaultExportFormatID == ImageFile::FORMAT_PNG16) {
1091 strWildcard = "PNG Files (*.png)|*.png";
1095 const wxString& strFilename = wxFileSelector (wxString("Export Filename"), wxString(""),
1096 wxString(""), strExt, strWildcard, wxOVERWRITE_PROMPT | wxHIDE_READONLY | wxSAVE);
1098 rIF.exportImage (strFormatName.c_str(), strFilename.c_str(), 1, 1, m_dMinPixel, m_dMaxPixel);
1099 *theApp->getLog() << "Exported file " << strFilename << "\n";
1106 ImageFileView::OnScaleSize (wxCommandEvent& event)
1108 ImageFile& rIF = GetDocument()->getImageFile();
1109 unsigned int iOldNX = rIF.nx();
1110 unsigned int iOldNY = rIF.ny();
1112 DialogGetXYSize dialogGetXYSize (getFrameForChild(), "Set New X & Y Dimensions", iOldNX, iOldNY);
1113 if (dialogGetXYSize.ShowModal() == wxID_OK) {
1114 unsigned int iNewNX = dialogGetXYSize.getXSize();
1115 unsigned int iNewNY = dialogGetXYSize.getYSize();
1116 std::ostringstream os;
1117 os << "Scale Size from (" << iOldNX << "," << iOldNY << ") to (" << iNewNX << "," << iNewNY << ")";
1118 ImageFileDocument* pScaledDoc = theApp->newImageDoc();
1120 sys_error (ERR_SEVERE, "Unable to create image file");
1123 ImageFile& rScaledIF = pScaledDoc->getImageFile();
1124 rScaledIF.setArraySize (iNewNX, iNewNY);
1125 rScaledIF.labelsCopy (rIF);
1126 rScaledIF.labelAdd (os.str().c_str());
1127 rIF.scaleImage (rScaledIF);
1128 *theApp->getLog() << os.str().c_str() << "\n";
1129 if (theApp->getAskDeleteNewDocs())
1130 pScaledDoc->Modify (true);
1131 pScaledDoc->UpdateAllViews (this);
1132 pScaledDoc->getView()->OnUpdate (this, NULL);
1133 pScaledDoc->getView()->getFrame()->Show(true);
1139 ImageFileView::OnConvert3d (wxCommandEvent& event)
1141 ImageFile& rIF = GetDocument()->getImageFile();
1142 Graph3dFileDocument* pGraph3d = theApp->newGraph3dDoc();
1143 pGraph3d->setBadFileOpen();
1144 pGraph3d->createFromImageFile (rIF);
1145 pGraph3d->getView()->OnUpdate (this, NULL);
1146 pGraph3d->UpdateAllViews();
1147 pGraph3d->getView()->getFrame()->SetClientSize (400, 400);
1148 pGraph3d->getView()->getFrame()->Show (true);
1149 GetDocumentManager()->ActivateView (pGraph3d->getView(), true, false);
1151 pGraph3d->getView()->getCanvas()->SetFocus();
1156 ImageFileView::OnPlotRow (wxCommandEvent& event)
1158 int xCursor, yCursor;
1159 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1160 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1164 const ImageFile& rIF = GetDocument()->getImageFile();
1165 ImageFileArrayConst v = rIF.getArray();
1166 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1170 if (v != NULL && yCursor < ny) {
1171 double* pX = new double [nx];
1172 double* pYReal = new double [nx];
1173 double *pYImag = NULL;
1174 double *pYMag = NULL;
1175 if (rIF.isComplex()) {
1176 pYImag = new double [nx];
1177 pYMag = new double [nx];
1179 for (int i = 0; i < nx; i++) {
1181 pYReal[i] = v[i][yCursor];
1182 if (rIF.isComplex()) {
1183 pYImag[i] = vImag[i][yCursor];
1184 pYMag[i] = ::sqrt (v[i][yCursor] * v[i][yCursor] + vImag[i][yCursor] * vImag[i][yCursor]);
1187 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1189 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1191 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1192 std::ostringstream os;
1193 os << "Row " << yCursor;
1194 std::string title("title ");
1196 rPlotFile.addEzsetCommand (title.c_str());
1197 rPlotFile.addEzsetCommand ("xlabel Column");
1198 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1199 rPlotFile.addEzsetCommand ("lxfrac 0");
1200 rPlotFile.addEzsetCommand ("box");
1201 rPlotFile.addEzsetCommand ("grid");
1202 rPlotFile.addEzsetCommand ("curve 1");
1203 rPlotFile.addEzsetCommand ("color 1");
1204 if (rIF.isComplex()) {
1205 rPlotFile.addEzsetCommand ("dash 1");
1206 rPlotFile.addEzsetCommand ("curve 2");
1207 rPlotFile.addEzsetCommand ("color 4");
1208 rPlotFile.addEzsetCommand ("dash 3");
1209 rPlotFile.addEzsetCommand ("curve 3");
1210 rPlotFile.addEzsetCommand ("color 0");
1211 rPlotFile.addEzsetCommand ("solid");
1212 rPlotFile.setCurveSize (4, nx);
1214 rPlotFile.setCurveSize (2, nx);
1215 rPlotFile.addColumn (0, pX);
1216 rPlotFile.addColumn (1, pYReal);
1217 if (rIF.isComplex()) {
1218 rPlotFile.addColumn (2, pYImag);
1219 rPlotFile.addColumn (3, pYMag);
1221 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1222 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1223 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1224 *theApp->getLog() << os.str().c_str() << "\n";
1225 rPlotFile.addDescription (os.str().c_str());
1229 if (rIF.isComplex()) {
1233 if (theApp->getAskDeleteNewDocs())
1234 pPlotDoc->Modify (true);
1235 pPlotDoc->UpdateAllViews ();
1236 pPlotDoc->getView()->OnUpdate (this, NULL);
1237 pPlotDoc->getView()->getFrame()->Show(true);
1242 ImageFileView::OnPlotCol (wxCommandEvent& event)
1244 int xCursor, yCursor;
1245 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1246 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1250 const ImageFile& rIF = GetDocument()->getImageFile();
1251 ImageFileArrayConst v = rIF.getArray();
1252 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1256 if (v != NULL && xCursor < nx) {
1257 double* pX = new double [ny];
1258 double* pYReal = new double [ny];
1259 double* pYImag = NULL;
1260 double* pYMag = NULL;
1261 if (rIF.isComplex()) {
1262 pYImag = new double [ny];
1263 pYMag = new double [ny];
1265 for (int i = 0; i < ny; i++) {
1267 pYReal[i] = v[xCursor][i];
1268 if (rIF.isComplex()) {
1269 pYImag[i] = vImag[xCursor][i];
1270 pYMag[i] = ::sqrt (v[xCursor][i] * v[xCursor][i] + vImag[xCursor][i] * vImag[xCursor][i]);
1273 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1275 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1277 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1278 std::ostringstream os;
1279 os << "Column " << xCursor;
1280 std::string title("title ");
1282 rPlotFile.addEzsetCommand (title.c_str());
1283 rPlotFile.addEzsetCommand ("xlabel Row");
1284 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1285 rPlotFile.addEzsetCommand ("lxfrac 0");
1286 rPlotFile.addEzsetCommand ("box");
1287 rPlotFile.addEzsetCommand ("grid");
1288 rPlotFile.addEzsetCommand ("curve 1");
1289 rPlotFile.addEzsetCommand ("color 1");
1290 if (rIF.isComplex()) {
1291 rPlotFile.addEzsetCommand ("dash 1");
1292 rPlotFile.addEzsetCommand ("curve 2");
1293 rPlotFile.addEzsetCommand ("color 4");
1294 rPlotFile.addEzsetCommand ("dash 3");
1295 rPlotFile.addEzsetCommand ("curve 3");
1296 rPlotFile.addEzsetCommand ("color 0");
1297 rPlotFile.addEzsetCommand ("solid");
1298 rPlotFile.setCurveSize (4, ny);
1300 rPlotFile.setCurveSize (2, ny);
1301 rPlotFile.addColumn (0, pX);
1302 rPlotFile.addColumn (1, pYReal);
1303 if (rIF.isComplex()) {
1304 rPlotFile.addColumn (2, pYImag);
1305 rPlotFile.addColumn (3, pYMag);
1307 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1308 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1309 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1310 *theApp->getLog() << os.str().c_str() << "\n";
1311 rPlotFile.addDescription (os.str().c_str());
1315 if (rIF.isComplex()) {
1319 if (theApp->getAskDeleteNewDocs())
1320 pPlotDoc->Modify (true);
1321 pPlotDoc->UpdateAllViews ();
1322 pPlotDoc->getView()->OnUpdate (this, NULL);
1323 pPlotDoc->getView()->getFrame()->Show(true);
1329 ImageFileView::OnPlotFFTRow (wxCommandEvent& event)
1331 int xCursor, yCursor;
1332 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1333 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1337 const ImageFile& rIF = GetDocument()->getImageFile();
1338 ImageFileArrayConst v = rIF.getArray();
1339 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1343 if (v != NULL && yCursor < ny) {
1344 fftw_complex* pcIn = new fftw_complex [nx];
1347 for (i = 0; i < nx; i++) {
1348 pcIn[i].re = v[i][yCursor];
1349 if (rIF.isComplex())
1350 pcIn[i].im = vImag[i][yCursor];
1355 fftw_plan plan = fftw_create_plan (nx, FFTW_FORWARD, FFTW_IN_PLACE);
1356 fftw_one (plan, pcIn, NULL);
1357 fftw_destroy_plan (plan);
1359 double* pX = new double [nx];
1360 double* pYReal = new double [nx];
1361 double* pYImag = new double [nx];
1362 double* pYMag = new double [nx];
1363 for (i = 0; i < nx; i++) {
1365 pYReal[i] = pcIn[i].re;
1366 pYImag[i] = pcIn[i].im;
1367 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1369 Fourier::shuffleFourierToNaturalOrder (pYReal, nx);
1370 Fourier::shuffleFourierToNaturalOrder (pYImag, nx);
1371 Fourier::shuffleFourierToNaturalOrder (pYMag, nx);
1373 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1375 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1377 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1378 std::ostringstream os;
1379 os << "Row " << yCursor;
1380 std::string title("title ");
1382 rPlotFile.addEzsetCommand (title.c_str());
1383 rPlotFile.addEzsetCommand ("xlabel Column");
1384 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1385 rPlotFile.addEzsetCommand ("lxfrac 0");
1386 rPlotFile.addEzsetCommand ("curve 1");
1387 rPlotFile.addEzsetCommand ("color 1");
1388 rPlotFile.addEzsetCommand ("dash 1");
1389 rPlotFile.addEzsetCommand ("curve 2");
1390 rPlotFile.addEzsetCommand ("color 4");
1391 rPlotFile.addEzsetCommand ("dash 3");
1392 rPlotFile.addEzsetCommand ("curve 3");
1393 rPlotFile.addEzsetCommand ("color 0");
1394 rPlotFile.addEzsetCommand ("solid");
1395 rPlotFile.addEzsetCommand ("box");
1396 rPlotFile.addEzsetCommand ("grid");
1397 rPlotFile.setCurveSize (4, nx);
1398 rPlotFile.addColumn (0, pX);
1399 rPlotFile.addColumn (1, pYReal);
1400 rPlotFile.addColumn (2, pYImag);
1401 rPlotFile.addColumn (3, pYMag);
1402 for (int iL = 0; iL < rIF.nLabels(); iL++)
1403 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1404 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1405 *theApp->getLog() << os.str().c_str() << "\n";
1406 rPlotFile.addDescription (os.str().c_str());
1414 if (theApp->getAskDeleteNewDocs())
1415 pPlotDoc->Modify (true);
1416 pPlotDoc->UpdateAllViews ();
1417 pPlotDoc->getView()->OnUpdate (this, NULL);
1418 pPlotDoc->getView()->getFrame()->Show(true);
1423 ImageFileView::OnPlotFFTCol (wxCommandEvent& event)
1425 int xCursor, yCursor;
1426 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1427 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1431 const ImageFile& rIF = GetDocument()->getImageFile();
1432 ImageFileArrayConst v = rIF.getArray();
1433 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1437 if (v != NULL && xCursor < nx) {
1438 fftw_complex* pcIn = new fftw_complex [ny];
1439 double *pdTemp = new double [ny];
1442 for (i = 0; i < ny; i++)
1443 pdTemp[i] = v[xCursor][i];
1444 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1445 for (i = 0; i < ny; i++)
1446 pcIn[i].re = pdTemp[i];
1448 for (i = 0; i < ny; i++) {
1449 if (rIF.isComplex())
1450 pdTemp[i] = vImag[xCursor][i];
1454 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1455 for (i = 0; i < ny; i++)
1456 pcIn[i].im = pdTemp[i];
1458 fftw_plan plan = fftw_create_plan (ny, FFTW_BACKWARD, FFTW_IN_PLACE);
1459 fftw_one (plan, pcIn, NULL);
1460 fftw_destroy_plan (plan);
1462 double* pX = new double [ny];
1463 double* pYReal = new double [ny];
1464 double* pYImag = new double [ny];
1465 double* pYMag = new double [ny];
1466 for (i = 0; i < ny; i++) {
1468 pYReal[i] = pcIn[i].re;
1469 pYImag[i] = pcIn[i].im;
1470 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1473 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1475 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1477 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1478 std::ostringstream os;
1479 os << "Column " << xCursor;
1480 std::string title("title ");
1482 rPlotFile.addEzsetCommand (title.c_str());
1483 rPlotFile.addEzsetCommand ("xlabel Column");
1484 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1485 rPlotFile.addEzsetCommand ("lxfrac 0");
1486 rPlotFile.addEzsetCommand ("curve 1");
1487 rPlotFile.addEzsetCommand ("color 1");
1488 rPlotFile.addEzsetCommand ("dash 1");
1489 rPlotFile.addEzsetCommand ("curve 2");
1490 rPlotFile.addEzsetCommand ("color 4");
1491 rPlotFile.addEzsetCommand ("dash 3");
1492 rPlotFile.addEzsetCommand ("curve 3");
1493 rPlotFile.addEzsetCommand ("color 0");
1494 rPlotFile.addEzsetCommand ("solid");
1495 rPlotFile.addEzsetCommand ("box");
1496 rPlotFile.addEzsetCommand ("grid");
1497 rPlotFile.setCurveSize (4, ny);
1498 rPlotFile.addColumn (0, pX);
1499 rPlotFile.addColumn (1, pYReal);
1500 rPlotFile.addColumn (2, pYImag);
1501 rPlotFile.addColumn (3, pYMag);
1502 for (int iL = 0; iL < rIF.nLabels(); iL++)
1503 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1504 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1505 *theApp->getLog() << os.str().c_str() << "\n";
1506 rPlotFile.addDescription (os.str().c_str());
1515 if (theApp->getAskDeleteNewDocs())
1516 pPlotDoc->Modify (true);
1517 pPlotDoc->UpdateAllViews ();
1518 pPlotDoc->getView()->OnUpdate (this, NULL);
1519 pPlotDoc->getView()->getFrame()->Show(true);
1525 ImageFileView::OnCompareCol (wxCommandEvent& event)
1527 int xCursor, yCursor;
1528 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1529 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1533 std::vector<ImageFileDocument*> vecIFDoc;
1534 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1535 if (vecIFDoc.size() == 0) {
1536 wxMessageBox ("No compatible images for Column Comparison", "Error");
1539 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1541 if (dialogGetCompare.ShowModal() == wxID_OK) {
1542 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1543 const ImageFile& rIF = GetDocument()->getImageFile();
1544 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1546 ImageFileArrayConst v1 = rIF.getArray();
1547 ImageFileArrayConst v2 = rCompareIF.getArray();
1551 if (v1 != NULL && xCursor < nx) {
1552 double* pX = new double [ny];
1553 double* pY1 = new double [ny];
1554 double* pY2 = new double [ny];
1555 for (int i = 0; i < ny; i++) {
1557 pY1[i] = v1[xCursor][i];
1558 pY2[i] = v2[xCursor][i];
1560 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1562 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1564 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1565 std::ostringstream os;
1566 os << "Column " << xCursor << " Comparison";
1567 std::string title("title ");
1569 rPlotFile.addEzsetCommand (title.c_str());
1570 rPlotFile.addEzsetCommand ("xlabel Row");
1571 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1572 rPlotFile.addEzsetCommand ("lxfrac 0");
1573 rPlotFile.addEzsetCommand ("curve 1");
1574 rPlotFile.addEzsetCommand ("color 2");
1575 rPlotFile.addEzsetCommand ("curve 2");
1576 rPlotFile.addEzsetCommand ("color 4");
1577 rPlotFile.addEzsetCommand ("dash 5");
1578 rPlotFile.addEzsetCommand ("box");
1579 rPlotFile.addEzsetCommand ("grid");
1580 rPlotFile.setCurveSize (3, ny);
1581 rPlotFile.addColumn (0, pX);
1582 rPlotFile.addColumn (1, pY1);
1583 rPlotFile.addColumn (2, pY2);
1586 for (iL = 0; iL < rIF.nLabels(); iL++) {
1587 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1589 s += rIF.labelGet(iL).getLabelString();
1590 rPlotFile.addDescription (s.c_str());
1592 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1593 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1595 s += rCompareIF.labelGet(iL).getLabelString();
1596 rPlotFile.addDescription (s.c_str());
1598 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1599 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1600 *theApp->getLog() << os.str().c_str() << "\n";
1601 rPlotFile.addDescription (os.str().c_str());
1606 if (theApp->getAskDeleteNewDocs())
1607 pPlotDoc->Modify (true);
1608 pPlotDoc->UpdateAllViews ();
1609 pPlotDoc->getView()->OnUpdate (this, NULL);
1610 pPlotDoc->getView()->getFrame()->Show(true);
1616 ImageFileView::OnCompareRow (wxCommandEvent& event)
1618 int xCursor, yCursor;
1619 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1620 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1624 std::vector<ImageFileDocument*> vecIFDoc;
1625 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1627 if (vecIFDoc.size() == 0) {
1628 wxMessageBox ("No compatible images for Row Comparison", "Error");
1632 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1634 if (dialogGetCompare.ShowModal() == wxID_OK) {
1635 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1636 const ImageFile& rIF = GetDocument()->getImageFile();
1637 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1639 ImageFileArrayConst v1 = rIF.getArray();
1640 ImageFileArrayConst v2 = rCompareIF.getArray();
1644 if (v1 != NULL && yCursor < ny) {
1645 double* pX = new double [nx];
1646 double* pY1 = new double [nx];
1647 double* pY2 = new double [nx];
1648 for (int i = 0; i < nx; i++) {
1650 pY1[i] = v1[i][yCursor];
1651 pY2[i] = v2[i][yCursor];
1653 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1655 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1657 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1658 std::ostringstream os;
1659 os << "Row " << yCursor << " Comparison";
1660 std::string title("title ");
1662 rPlotFile.addEzsetCommand (title.c_str());
1663 rPlotFile.addEzsetCommand ("xlabel Column");
1664 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1665 rPlotFile.addEzsetCommand ("lxfrac 0");
1666 rPlotFile.addEzsetCommand ("curve 1");
1667 rPlotFile.addEzsetCommand ("color 2");
1668 rPlotFile.addEzsetCommand ("curve 2");
1669 rPlotFile.addEzsetCommand ("color 4");
1670 rPlotFile.addEzsetCommand ("dash 5");
1671 rPlotFile.addEzsetCommand ("box");
1672 rPlotFile.addEzsetCommand ("grid");
1673 rPlotFile.setCurveSize (3, nx);
1674 rPlotFile.addColumn (0, pX);
1675 rPlotFile.addColumn (1, pY1);
1676 rPlotFile.addColumn (2, pY2);
1678 for (iL = 0; iL < rIF.nLabels(); iL++) {
1679 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1681 s += rIF.labelGet(iL).getLabelString();
1682 rPlotFile.addDescription (s.c_str());
1684 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1685 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1687 s += rCompareIF.labelGet(iL).getLabelString();
1688 rPlotFile.addDescription (s.c_str());
1690 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1691 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1692 *theApp->getLog() << os.str().c_str() << "\n";
1693 rPlotFile.addDescription (os.str().c_str());
1698 if (theApp->getAskDeleteNewDocs())
1699 pPlotDoc->Modify (true);
1700 pPlotDoc->UpdateAllViews ();
1701 pPlotDoc->getView()->OnUpdate (this, NULL);
1702 pPlotDoc->getView()->getFrame()->Show(true);
1707 static int NUMBER_HISTOGRAM_BINS = 256;
1710 ImageFileView::OnPlotHistogram (wxCommandEvent& event)
1712 const ImageFile& rIF = GetDocument()->getImageFile();
1713 ImageFileArrayConst v = rIF.getArray();
1717 if (v != NULL && nx > 0 && ny > 0) {
1718 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1720 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1724 double* pX = new double [NUMBER_HISTOGRAM_BINS];
1725 double* pY = new double [NUMBER_HISTOGRAM_BINS];
1727 rIF.getMinMax (dMin, dMax);
1728 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
1730 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
1731 pX[i] = dMin + (i + 0.5) * dBinWidth;
1734 for (int ix = 0; ix < nx; ix++)
1735 for (int iy = 0; iy < ny; iy++) {
1736 int iBin = nearest<int> ((v[ix][iy] - dMin) / dBinWidth);
1737 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
1741 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1742 std::ostringstream os;
1744 std::string title("title ");
1746 rPlotFile.addEzsetCommand (title.c_str());
1747 rPlotFile.addEzsetCommand ("xlabel Pixel Value");
1748 rPlotFile.addEzsetCommand ("ylabel Count");
1749 rPlotFile.addEzsetCommand ("box");
1750 rPlotFile.addEzsetCommand ("grid");
1751 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
1752 rPlotFile.addColumn (0, pX);
1753 rPlotFile.addColumn (1, pY);
1754 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++) {
1755 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1757 s += rIF.labelGet(iL).getLabelString();
1758 rPlotFile.addDescription (s.c_str());
1760 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1761 *theApp->getLog() << os.str().c_str() << "\n";
1762 rPlotFile.addDescription (os.str().c_str());
1765 if (theApp->getAskDeleteNewDocs())
1766 pPlotDoc->Modify (true);
1767 pPlotDoc->UpdateAllViews ();
1768 pPlotDoc->getView()->OnUpdate (this, NULL);
1769 pPlotDoc->getView()->getFrame()->Show(true);
1776 PhantomCanvas::PhantomCanvas (PhantomFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1777 : wxScrolledWindow(frame, -1, pos, size, style)
1782 PhantomCanvas::~PhantomCanvas ()
1788 PhantomCanvas::OnDraw (wxDC& dc)
1791 m_pView->OnDraw(& dc);
1795 PhantomCanvas::GetBestSize() const
1801 theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
1802 xSize = maxValue<int> (xSize, ySize);
1803 ySize = xSize = (xSize / 3);
1804 return wxSize (xSize, ySize);
1811 IMPLEMENT_DYNAMIC_CLASS(PhantomFileView, wxView)
1813 BEGIN_EVENT_TABLE(PhantomFileView, wxView)
1814 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomFileView::OnProperties)
1815 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomFileView::OnRasterize)
1816 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomFileView::OnProjections)
1819 PhantomFileView::PhantomFileView()
1820 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0)
1822 #if defined(DEBUG) || defined(_DEBUG)
1823 m_iDefaultNDet = 165;
1824 m_iDefaultNView = 180;
1826 m_iDefaultNDet = 367;
1827 m_iDefaultNView = 320;
1829 m_iDefaultNSample = 2;
1830 m_dDefaultRotation = 1;
1831 m_dDefaultFocalLength = 2;
1832 m_dDefaultViewRatio = 1;
1833 m_dDefaultScanRatio = 1;
1834 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
1835 m_iDefaultTrace = Trace::TRACE_NONE;
1838 m_iDefaultRasterNX = 115;
1839 m_iDefaultRasterNY = 115;
1840 m_iDefaultRasterNSamples = 1;
1842 m_iDefaultRasterNX = 256;
1843 m_iDefaultRasterNY = 256;
1844 m_iDefaultRasterNSamples = 2;
1846 m_dDefaultRasterViewRatio = 1;
1849 PhantomFileView::~PhantomFileView()
1851 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
1852 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
1856 PhantomFileView::OnProperties (wxCommandEvent& event)
1858 const int idPhantom = GetDocument()->getPhantomID();
1859 const wxString& namePhantom = GetDocument()->getPhantomName();
1860 std::ostringstream os;
1861 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")" << "\n";
1862 const Phantom& rPhantom = GetDocument()->getPhantom();
1863 rPhantom.printDefinitions (os);
1865 rPhantom.print (os);
1867 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
1868 wxMessageBox (os.str().c_str(), "Phantom Properties");
1873 PhantomFileView::OnProjections (wxCommandEvent& event)
1875 DialogGetProjectionParameters dialogProjection (getFrameForChild(),
1876 m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation,
1877 m_dDefaultFocalLength, m_dDefaultViewRatio, m_dDefaultScanRatio, m_iDefaultGeometry,
1879 int retVal = dialogProjection.ShowModal();
1880 if (retVal == wxID_OK) {
1881 m_iDefaultNDet = dialogProjection.getNDet();
1882 m_iDefaultNView = dialogProjection.getNView();
1883 m_iDefaultNSample = dialogProjection.getNSamples();
1884 m_iDefaultTrace = dialogProjection.getTrace();
1885 m_dDefaultRotation = dialogProjection.getRotAngle();
1886 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
1887 m_dDefaultViewRatio = dialogProjection.getViewRatio();
1888 m_dDefaultScanRatio = dialogProjection.getScanRatio();
1889 wxString sGeometry = dialogProjection.getGeometry();
1890 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
1892 if (m_iDefaultNDet > 0 && m_iDefaultNView > 0 && sGeometry != "") {
1893 const Phantom& rPhantom = GetDocument()->getPhantom();
1894 Projections* pProj = new Projections;
1895 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample,
1896 m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultViewRatio, m_dDefaultScanRatio);
1897 if (theScanner.fail()) {
1898 wxString msg = "Failed making scanner\n";
1899 msg += theScanner.failMessage().c_str();
1900 *theApp->getLog() << msg << "\n";
1901 wxMessageBox (msg, "Error");
1904 pProj->initFromScanner (theScanner);
1905 m_dDefaultRotation /= TWOPI; // convert back to fraction of a circle
1908 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
1909 ProjectionsDialog dialogProjections (theScanner, *pProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(getFrameForChild()));
1910 for (int iView = 0; iView < pProj->nView(); iView++) {
1912 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
1917 while (dialogProjections.isPaused()) {
1923 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), pProj->nView() + 1, getFrameForChild(), wxPD_CAN_ABORT);
1924 for (int i = 0; i < pProj->nView(); i++) {
1925 theScanner.collectProjections (*pProj, rPhantom, i, 1, true, m_iDefaultTrace);
1926 if (! dlgProgress.Update (i+1)) {
1933 std::ostringstream os;
1934 os << "Projections for " << rPhantom.name() << ": nDet=" << m_iDefaultNDet
1935 << ", nView=" << m_iDefaultNView << ", nSamples=" << m_iDefaultNSample
1936 << ", RotAngle=" << m_dDefaultRotation << ", FocalLengthRatio=" << m_dDefaultFocalLength
1937 << ", ViewRatio=" << m_dDefaultViewRatio << ", ScanRatio=" << m_dDefaultScanRatio
1938 << ", Geometry=" << sGeometry.c_str() << ", FanBeamAngle=" <<
1939 convertRadiansToDegrees (theScanner.fanBeamAngle());
1940 pProj->setCalcTime (timer.timerEnd());
1941 pProj->setRemark (os.str());
1942 *theApp->getLog() << os.str().c_str() << "\n";
1945 ProjectionFileDocument* pProjectionDoc = theApp->newProjectionDoc();
1946 if (! pProjectionDoc) {
1947 sys_error (ERR_SEVERE, "Unable to create projection document");
1950 pProjectionDoc->setProjections (pProj);
1951 ProjectionFileView* projView = pProjectionDoc->getView();
1953 projView->OnUpdate (projView, NULL);
1954 if (projView->getCanvas())
1955 projView->getCanvas()->SetClientSize (m_iDefaultNDet, m_iDefaultNView);
1956 if (wxFrame* pFrame = projView->getFrame()) {
1961 GetDocumentManager()->ActivateView (projView, true, false);
1964 if (theApp->getAskDeleteNewDocs())
1965 pProjectionDoc-> Modify(true);
1966 pProjectionDoc->UpdateAllViews (this);
1973 PhantomFileView::OnRasterize (wxCommandEvent& event)
1975 DialogGetRasterParameters dialogRaster (getFrameForChild(), m_iDefaultRasterNX, m_iDefaultRasterNY,
1976 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio);
1977 int retVal = dialogRaster.ShowModal();
1978 if (retVal == wxID_OK) {
1979 m_iDefaultRasterNX = dialogRaster.getXSize();
1980 m_iDefaultRasterNY = dialogRaster.getYSize();
1981 m_iDefaultRasterNSamples = dialogRaster.getNSamples();
1982 m_dDefaultRasterViewRatio = dialogRaster.getViewRatio();
1983 if (m_iDefaultRasterNSamples < 1)
1984 m_iDefaultRasterNSamples = 1;
1985 if (m_dDefaultRasterViewRatio < 0)
1986 m_dDefaultRasterViewRatio = 0;
1987 if (m_iDefaultRasterNX > 0 && m_iDefaultRasterNY > 0) {
1988 const Phantom& rPhantom = GetDocument()->getPhantom();
1990 ImageFile* pImageFile = new ImageFile;
1992 pImageFile->setArraySize (m_iDefaultRasterNX, m_iDefaultRasterNY);
1993 wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"),
1994 pImageFile->nx() + 1, getFrameForChild(), wxPD_CAN_ABORT);
1996 for (unsigned int i = 0; i < pImageFile->nx(); i++) {
1997 rPhantom.convertToImagefile (*pImageFile, m_dDefaultRasterViewRatio, m_iDefaultRasterNSamples,
1998 Trace::TRACE_NONE, i, 1, true);
1999 if (! dlgProgress.Update (i+1)) {
2005 ImageFileDocument* pRasterDoc = theApp->newImageDoc();
2007 sys_error (ERR_SEVERE, "Unable to create image file");
2010 pRasterDoc->setImageFile (pImageFile);
2012 if (theApp->getAskDeleteNewDocs())
2013 pRasterDoc->Modify (true);
2014 pRasterDoc->UpdateAllViews (this);
2015 pRasterDoc->getView()->getFrame()->Show(true);
2016 std::ostringstream os;
2017 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << m_iDefaultRasterNX << ", YSize="
2018 << m_iDefaultRasterNY << ", ViewRatio=" << m_dDefaultRasterViewRatio << ", nSamples="
2019 << m_iDefaultRasterNSamples;;
2020 *theApp->getLog() << os.str().c_str() << "\n";
2021 pImageFile->labelAdd (os.str().c_str(), timer.timerEnd());
2022 ImageFileView* rasterView = pRasterDoc->getView();
2024 rasterView->getFrame()->SetFocus();
2025 rasterView->OnUpdate (rasterView, NULL);
2034 PhantomFileView::CreateCanvas (wxFrame *parent)
2036 PhantomCanvas* pCanvas;
2038 pCanvas = new PhantomCanvas (this, parent, wxPoint(0, 0), wxSize(0,0), 0);
2039 pCanvas->SetBackgroundColour(*wxWHITE);
2050 PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2053 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2055 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2057 theApp->setIconForFrame (subframe);
2059 m_pFileMenu = new wxMenu;
2061 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2062 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2063 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2064 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2065 m_pFileMenu->Append(wxID_CLOSE, "&Close");
2067 m_pFileMenu->AppendSeparator();
2068 m_pFileMenu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties");
2070 m_pFileMenu->AppendSeparator();
2071 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2072 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2073 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2075 m_pFileMenu->AppendSeparator();
2076 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
2077 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2079 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2080 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2082 wxMenu *process_menu = new wxMenu;
2083 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...\tCtrl-R");
2084 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...\tCtrl-J");
2086 wxMenu *help_menu = new wxMenu;
2087 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2088 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
2089 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
2090 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2092 wxMenuBar *menu_bar = new wxMenuBar;
2094 menu_bar->Append(m_pFileMenu, "&File");
2095 menu_bar->Append(process_menu, "&Process");
2096 menu_bar->Append(help_menu, "&Help");
2098 subframe->SetMenuBar(menu_bar);
2099 subframe->Centre(wxBOTH);
2101 wxAcceleratorEntry accelEntries[2];
2102 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('J'), PHMMENU_PROCESS_PROJECTIONS);
2103 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('R'), PHMMENU_PROCESS_RASTERIZE);
2104 wxAcceleratorTable accelTable (2, accelEntries);
2105 subframe->SetAcceleratorTable (accelTable);
2112 PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2114 m_pFrame = CreateChildFrame(doc, this);
2116 m_pCanvas = CreateCanvas (m_pFrame);
2117 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
2118 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
2120 m_pFrame->SetTitle ("PhantomFileView");
2123 int x, y; // X requires a forced resize
2124 m_pFrame->GetSize(&x, &y);
2125 m_pFrame->SetSize(-1, -1, x, y);
2128 m_pFrame->Show(true);
2135 PhantomFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2138 m_pCanvas->Refresh();
2142 PhantomFileView::OnClose (bool deleteWindow)
2144 //GetDocumentManager()->ActivateView (this, false, true);
2145 if (! GetDocument() || ! GetDocument()->Close())
2150 m_pCanvas->setView(NULL);
2153 wxString s(wxTheApp->GetAppName());
2155 m_pFrame->SetTitle(s);
2162 if (GetDocument() && GetDocument()->getBadFileOpen())
2163 ::wxYield(); // wxWindows bug workaround
2170 PhantomFileView::OnDraw (wxDC* dc)
2173 m_pCanvas->GetClientSize (&xsize, &ysize);
2174 SGPDriver driver (dc, xsize, ysize);
2176 const Phantom& rPhantom = GetDocument()->getPhantom();
2177 sgp.setColor (C_RED);
2178 rPhantom.show (sgp);
2183 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2184 : wxScrolledWindow(frame, -1, pos, size, style)
2189 ProjectionFileCanvas::~ProjectionFileCanvas ()
2195 ProjectionFileCanvas::OnDraw(wxDC& dc)
2198 m_pView->OnDraw(& dc);
2202 ProjectionFileCanvas::GetBestSize () const
2206 Projections& rProj = m_pView->GetDocument()->getProjections();
2207 best.Set (rProj.nDet(), rProj.nView());
2214 // ProjectionFileView
2216 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
2218 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
2219 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
2220 EVT_MENU(PJMENU_RECONSTRUCT_FBP, ProjectionFileView::OnReconstructFBP)
2221 EVT_MENU(PJMENU_CONVERT_POLAR, ProjectionFileView::OnConvertPolar)
2222 EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
2225 ProjectionFileView::ProjectionFileView()
2226 : wxView(), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0)
2236 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
2237 m_dDefaultFilterParam = 1.;
2239 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
2240 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
2242 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
2243 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
2245 m_iDefaultZeropad = 1;
2246 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF;
2247 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
2248 m_iDefaultInterpParam = 1;
2249 m_iDefaultTrace = Trace::TRACE_NONE;
2251 m_iDefaultPolarNX = 256;
2252 m_iDefaultPolarNY = 256;
2253 m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR;
2254 m_iDefaultPolarZeropad = 1;
2257 ProjectionFileView::~ProjectionFileView()
2259 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2260 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2264 ProjectionFileView::OnProperties (wxCommandEvent& event)
2266 const Projections& rProj = GetDocument()->getProjections();
2267 std::ostringstream os;
2268 rProj.printScanInfo(os);
2269 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2270 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
2271 dialogMsg.ShowModal();
2276 ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
2278 Projections& rProj = GetDocument()->getProjections();
2279 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2280 m_iDefaultPolarInterpolation, -1);
2281 if (dialogPolar.ShowModal() == wxID_OK) {
2282 wxString strInterpolation (dialogPolar.getInterpolationName());
2283 m_iDefaultPolarNX = dialogPolar.getXSize();
2284 m_iDefaultPolarNY = dialogPolar.getYSize();
2285 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2286 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2287 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2288 if (! rProj.convertPolar (*pIF, m_iDefaultPolarInterpolation)) {
2290 *theApp->getLog() << "Error converting to Polar\n";
2293 pPolarDoc = theApp->newImageDoc ();
2295 sys_error (ERR_SEVERE, "Unable to create image file");
2298 pPolarDoc->setImageFile (pIF);
2299 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2300 std::ostringstream os;
2301 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to polar image: xSize="
2302 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2303 << strInterpolation.c_str();
2304 *theApp->getLog() << os.str().c_str() << "\n";
2305 pIF->labelAdd (os.str().c_str());
2306 if (theApp->getAskDeleteNewDocs())
2307 pPolarDoc->Modify (true);
2308 pPolarDoc->UpdateAllViews ();
2309 pPolarDoc->getView()->OnUpdate (this, NULL);
2310 pPolarDoc->getView()->getFrame()->Show(true);
2315 ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
2317 Projections& rProj = GetDocument()->getProjections();
2318 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert to FFT Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2319 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad);
2320 if (dialogPolar.ShowModal() == wxID_OK) {
2321 wxString strInterpolation (dialogPolar.getInterpolationName());
2322 m_iDefaultPolarNX = dialogPolar.getXSize();
2323 m_iDefaultPolarNY = dialogPolar.getYSize();
2324 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2325 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2327 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2328 if (! rProj.convertFFTPolar (*pIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad)) {
2330 *theApp->getLog() << "Error converting to polar\n";
2333 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2335 sys_error (ERR_SEVERE, "Unable to create image file");
2338 pPolarDoc->setImageFile (pIF);
2339 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2340 std::ostringstream os;
2341 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to FFT polar image: xSize="
2342 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2343 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2344 *theApp->getLog() << os.str().c_str() << "\n";
2345 pIF->labelAdd (os.str().c_str());
2346 if (theApp->getAskDeleteNewDocs())
2347 pPolarDoc->Modify (true);
2348 pPolarDoc->UpdateAllViews ();
2349 pPolarDoc->getView()->OnUpdate (this, NULL);
2350 pPolarDoc->getView()->getFrame()->Show(true);
2355 ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
2357 wxMessageBox ("Fourier Reconstruction is not yet supported", "Unimplemented function");
2361 ProjectionFileView::OnReconstructFBP (wxCommandEvent& event)
2363 DialogGetReconstructionParameters dialogReconstruction (getFrameForChild(), m_iDefaultNX, m_iDefaultNY,
2364 m_iDefaultFilter, m_dDefaultFilterParam, m_iDefaultFilterMethod, m_iDefaultFilterGeneration,
2365 m_iDefaultZeropad, m_iDefaultInterpolation, m_iDefaultInterpParam, m_iDefaultBackprojector,
2368 int retVal = dialogReconstruction.ShowModal();
2369 if (retVal == wxID_OK) {
2370 m_iDefaultNX = dialogReconstruction.getXSize();
2371 m_iDefaultNY = dialogReconstruction.getYSize();
2372 wxString optFilterName = dialogReconstruction.getFilterName();
2373 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
2374 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
2375 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
2376 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
2377 m_iDefaultZeropad = dialogReconstruction.getZeropad();
2378 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
2379 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
2380 wxString optInterpName = dialogReconstruction.getInterpName();
2381 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
2382 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
2383 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
2384 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
2385 m_iDefaultTrace = dialogReconstruction.getTrace();
2387 if (m_iDefaultNX > 0 && m_iDefaultNY > 0) {
2388 const Projections& rProj = GetDocument()->getProjections();
2389 ImageFile* pImageFile = new ImageFile;
2390 pImageFile->setArraySize (m_iDefaultNX, m_iDefaultNY);
2392 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2393 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2394 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace);
2397 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2398 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstructor, rProj, *pImageFile, m_iDefaultTrace, getFrameForChild());
2399 for (int iView = 0; iView < rProj.nView(); iView++) {
2401 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView, true)) {
2402 delete pDlgReconstruct;
2403 delete pReconstructor;
2409 while (pDlgReconstruct->isPaused()) {
2414 delete pDlgReconstruct;
2416 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT);
2417 for (int iView = 0; iView < rProj.nView(); iView++) {
2418 pReconstructor->reconstructView (iView, 1);
2419 if (! dlgProgress.Update (iView + 1)) {
2420 delete pReconstructor;
2426 delete pReconstructor;
2427 ImageFileDocument* pReconDoc = theApp->newImageDoc();
2429 sys_error (ERR_SEVERE, "Unable to create image file");
2432 pReconDoc->setImageFile (pImageFile);
2433 if (theApp->getAskDeleteNewDocs())
2434 pReconDoc->Modify (true);
2435 pReconDoc->UpdateAllViews (this);
2436 if (ImageFileView* rasterView = pReconDoc->getView()) {
2437 rasterView->OnUpdate (rasterView, NULL);
2438 rasterView->getFrame()->SetFocus();
2439 rasterView->getFrame()->Show(true);
2441 std::ostringstream os;
2442 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();
2443 *theApp->getLog() << os.str().c_str() << "\n";
2444 pImageFile->labelAdd (rProj.getLabel());
2445 pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd());
2451 ProjectionFileCanvas*
2452 ProjectionFileView::CreateCanvas (wxFrame *parent)
2454 ProjectionFileCanvas* pCanvas;
2456 parent->GetClientSize(&width, &height);
2458 pCanvas = new ProjectionFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
2460 pCanvas->SetScrollbars(20, 20, 50, 50);
2461 pCanvas->SetBackgroundColour(*wxWHITE);
2472 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2475 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2477 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2479 theApp->setIconForFrame (subframe);
2481 m_pFileMenu = new wxMenu;
2483 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2484 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2485 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2486 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2487 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2488 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2490 m_pFileMenu->AppendSeparator();
2491 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
2493 m_pFileMenu->AppendSeparator();
2494 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2495 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2496 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2498 m_pFileMenu->AppendSeparator();
2499 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
2500 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2502 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2503 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2505 wxMenu *convert_menu = new wxMenu;
2506 convert_menu->Append (PJMENU_CONVERT_POLAR, "&Polar Image...\tCtrl-L");
2507 convert_menu->Append (PJMENU_CONVERT_FFT_POLAR, "&FFT->Polar Image...\tCtrl-I");
2509 wxMenu *reconstruct_menu = new wxMenu;
2510 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP, "&Filtered Backprojection...\tCtrl-R", "Reconstruct image using filtered backprojection");
2511 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Fourier...\tCtrl-E", "Reconstruct image using inverse Fourier");
2512 reconstruct_menu->Enable (PJMENU_RECONSTRUCT_FOURIER, false);
2514 wxMenu *help_menu = new wxMenu;
2515 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2516 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
2517 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
2518 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2520 wxMenuBar *menu_bar = new wxMenuBar;
2522 menu_bar->Append (m_pFileMenu, "&File");
2523 menu_bar->Append (convert_menu, "&Convert");
2524 menu_bar->Append (reconstruct_menu, "&Reconstruct");
2525 menu_bar->Append (help_menu, "&Help");
2527 subframe->SetMenuBar(menu_bar);
2528 subframe->Centre(wxBOTH);
2530 wxAcceleratorEntry accelEntries[4];
2531 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('L'), PJMENU_CONVERT_POLAR);
2532 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('I'), PJMENU_CONVERT_FFT_POLAR);
2533 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('R'), PJMENU_RECONSTRUCT_FBP);
2534 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('E'), PJMENU_RECONSTRUCT_FOURIER);
2535 wxAcceleratorTable accelTable (4, accelEntries);
2536 subframe->SetAcceleratorTable (accelTable);
2543 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2545 m_pFrame = CreateChildFrame(doc, this);
2549 m_pFrame->GetClientSize (&width, &height);
2550 m_pFrame->SetTitle ("ProjectionFileView");
2551 m_pCanvas = CreateCanvas (m_pFrame);
2554 int x, y; // X requires a forced resize
2555 m_pFrame->GetSize(&x, &y);
2556 m_pFrame->SetSize(-1, -1, x, y);
2559 m_pFrame->Show(true);
2566 ProjectionFileView::OnDraw (wxDC* dc)
2568 wxSize clientSize = m_pFrame->GetClientSize();
2569 wxSize bestSize = m_pCanvas->GetBestSize();
2571 if (clientSize.x > bestSize.x || clientSize.y > bestSize.y)
2572 m_pFrame->SetClientSize (bestSize);
2575 dc->DrawBitmap (m_bitmap, 0, 0, false);
2580 ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2582 const Projections& rProj = GetDocument()->getProjections();
2583 const int nDet = rProj.nDet();
2584 const int nView = rProj.nView();
2585 if (nDet != 0 && nView != 0) {
2586 const DetectorArray& detarray = rProj.getDetectorArray(0);
2587 const DetectorValue* detval = detarray.detValues();
2588 double min = detval[0];
2589 double max = detval[0];
2590 for (int iy = 0; iy < nView; iy++) {
2591 const DetectorArray& detarray = rProj.getDetectorArray(iy);
2592 const DetectorValue* detval = detarray.detValues();
2593 for (int ix = 0; ix < nDet; ix++) {
2594 if (min > detval[ix])
2596 else if (max < detval[ix])
2601 unsigned char* imageData = new unsigned char [nDet * nView * 3];
2602 double scale = (max - min) / 255;
2603 for (int iy2 = 0; iy2 < nView; iy2++) {
2604 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
2605 const DetectorValue* detval = detarray.detValues();
2606 for (int ix = 0; ix < nDet; ix++) {
2607 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
2608 intensity = clamp(intensity, 0, 255);
2609 int baseAddr = (iy2 * nDet + ix) * 3;
2610 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
2613 wxImage image (nDet, nView, imageData, true);
2614 m_bitmap = image.ConvertToBitmap();
2618 xSize = clamp (xSize, 0, 800);
2619 ySize = clamp (ySize, 0, 800);
2620 m_pFrame->SetClientSize (xSize, ySize);
2621 m_pCanvas->SetScrollbars (20, 20, nDet/20, nView/20);
2625 m_pCanvas->Refresh();
2629 ProjectionFileView::OnClose (bool deleteWindow)
2631 //GetDocumentManager()->ActivateView (this, false, true);
2632 if (! GetDocument() || ! GetDocument()->Close())
2637 m_pCanvas->setView(NULL);
2640 wxString s(wxTheApp->GetAppName());
2642 m_pFrame->SetTitle(s);
2649 if (GetDocument() && GetDocument()->getBadFileOpen())
2650 ::wxYield(); // wxWindows bug workaround
2659 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2660 : wxScrolledWindow(frame, -1, pos, size, style)
2665 PlotFileCanvas::~PlotFileCanvas ()
2671 PlotFileCanvas::OnDraw(wxDC& dc)
2674 m_pView->OnDraw(& dc);
2680 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
2682 BEGIN_EVENT_TABLE(PlotFileView, wxView)
2683 EVT_MENU(PJMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
2684 EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
2685 EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
2686 EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
2689 PlotFileView::PlotFileView()
2690 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pEZPlot(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
2694 PlotFileView::~PlotFileView()
2699 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2703 PlotFileView::OnProperties (wxCommandEvent& event)
2705 const PlotFile& rPlot = GetDocument()->getPlotFile();
2706 std::ostringstream os;
2707 os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
2708 rPlot.printHeadersBrief (os);
2709 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<<\n";
2710 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
2711 dialogMsg.ShowModal();
2716 PlotFileView::OnScaleAuto (wxCommandEvent& event)
2718 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2719 double min, max, mean, mode, median, stddev;
2720 rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
2721 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
2722 int iRetVal = dialogAutoScale.ShowModal();
2723 if (iRetVal == wxID_OK) {
2724 m_bMinSpecified = true;
2725 m_bMaxSpecified = true;
2727 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
2730 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
2731 OnUpdate (this, NULL);
2737 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
2739 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2743 if (! m_bMinSpecified || ! m_bMaxSpecified) {
2744 if (! rPlotFile.getMinMax (1, min, max)) {
2745 *theApp->getLog() << "Error: unable to find Min/Max\n";
2750 if (m_bMinSpecified)
2752 if (m_bMaxSpecified)
2755 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Y-axis Minimum & Maximum", min, max);
2756 int retVal = dialogMinMax.ShowModal();
2757 if (retVal == wxID_OK) {
2758 m_bMinSpecified = true;
2759 m_bMaxSpecified = true;
2760 m_dMinPixel = dialogMinMax.getMinimum();
2761 m_dMaxPixel = dialogMinMax.getMaximum();
2762 OnUpdate (this, NULL);
2767 PlotFileView::OnScaleFull (wxCommandEvent& event)
2769 if (m_bMinSpecified || m_bMaxSpecified) {
2770 m_bMinSpecified = false;
2771 m_bMaxSpecified = false;
2772 OnUpdate (this, NULL);
2778 PlotFileView::CreateCanvas (wxFrame* parent)
2780 PlotFileCanvas* pCanvas;
2782 parent->GetClientSize(&width, &height);
2784 pCanvas = new PlotFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
2786 pCanvas->SetBackgroundColour(*wxWHITE);
2797 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2800 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2802 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2804 theApp->setIconForFrame (subframe);
2806 m_pFileMenu = new wxMenu;
2808 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2809 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2810 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2811 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2812 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2813 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2815 m_pFileMenu->AppendSeparator();
2816 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
2818 m_pFileMenu->AppendSeparator();
2819 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2820 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2821 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2823 m_pFileMenu->AppendSeparator();
2824 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
2825 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2827 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2828 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2830 wxMenu *view_menu = new wxMenu;
2831 view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...\tCtrl-E");
2832 view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
2833 view_menu->Append(PLOTMENU_VIEW_SCALE_FULL, "Display &Full Scale\tCtrl-U");
2835 wxMenu *help_menu = new wxMenu;
2836 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2837 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
2838 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
2839 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2841 wxMenuBar *menu_bar = new wxMenuBar;
2843 menu_bar->Append(m_pFileMenu, "&File");
2844 menu_bar->Append(view_menu, "&View");
2845 menu_bar->Append(help_menu, "&Help");
2847 subframe->SetMenuBar(menu_bar);
2848 subframe->Centre(wxBOTH);
2850 wxAcceleratorEntry accelEntries[3];
2851 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('E'), PLOTMENU_VIEW_SCALE_MINMAX);
2852 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('A'), PLOTMENU_VIEW_SCALE_AUTO);
2853 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('U'), PLOTMENU_VIEW_SCALE_FULL);
2854 wxAcceleratorTable accelTable (3, accelEntries);
2855 subframe->SetAcceleratorTable (accelTable);
2862 PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
2864 m_pFrame = CreateChildFrame(doc, this);
2867 m_bMinSpecified = false;
2868 m_bMaxSpecified = false;
2869 m_dAutoScaleFactor = 1.;
2872 m_pFrame->GetClientSize(&width, &height);
2873 m_pFrame->SetTitle ("Plot File");
2874 m_pCanvas = CreateCanvas (m_pFrame);
2877 int x, y; // X requires a forced resize
2878 m_pFrame->GetSize(&x, &y);
2879 m_pFrame->SetSize(-1, -1, x, y);
2882 m_pFrame->Show(true);
2889 PlotFileView::OnDraw (wxDC* dc)
2891 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2892 const int iNColumns = rPlotFile.getNumColumns();
2893 const int iNRecords = rPlotFile.getNumRecords();
2895 if (iNColumns > 0 && iNRecords > 0) {
2897 m_pCanvas->GetClientSize (&xsize, &ysize);
2898 SGPDriver driver (dc, xsize, ysize);
2901 m_pEZPlot->plot (&sgp);
2907 PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2909 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2910 const int iNColumns = rPlotFile.getNumColumns();
2911 const int iNRecords = rPlotFile.getNumRecords();
2913 if (iNColumns > 0 && iNRecords > 0) {
2916 m_pEZPlot = new EZPlot;
2918 for (unsigned int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)
2919 m_pEZPlot->ezset (rPlotFile.getEzsetCommand (iEzset));
2921 if (m_bMinSpecified) {
2922 std::ostringstream os;
2923 os << "ymin " << m_dMinPixel;
2924 m_pEZPlot->ezset (os.str());
2927 if (m_bMaxSpecified) {
2928 std::ostringstream os;
2929 os << "ymax " << m_dMaxPixel;
2930 m_pEZPlot->ezset (os.str());
2933 m_pEZPlot->ezset("box");
2934 m_pEZPlot->ezset("grid");
2936 double* pdXaxis = new double [iNRecords];
2937 rPlotFile.getColumn (0, pdXaxis);
2939 double* pdY = new double [iNRecords];
2940 for (int iCol = 1; iCol < iNColumns; iCol++) {
2941 rPlotFile.getColumn (iCol, pdY);
2942 m_pEZPlot->addCurve (pdXaxis, pdY, iNRecords);
2950 m_pCanvas->Refresh();
2954 PlotFileView::OnClose (bool deleteWindow)
2956 //GetDocumentManager()->ActivateView (this, false, true);
2957 if (! GetDocument() || ! GetDocument()->Close())
2962 m_pCanvas->setView (NULL);
2965 wxString s(wxTheApp->GetAppName());
2967 m_pFrame->SetTitle(s);
2973 if (GetDocument() && GetDocument()->getBadFileOpen())
2974 ::wxYield(); // wxWindows bug workaround
2981 ////////////////////////////////////////////////////////////////
2984 IMPLEMENT_DYNAMIC_CLASS(TextFileView, wxView)
2986 TextFileView::~TextFileView()
2988 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2989 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2992 bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2994 m_pFrame = CreateChildFrame(doc, this);
2995 SetFrame (m_pFrame);
2998 m_pFrame->GetClientSize(&width, &height);
2999 m_pFrame->SetTitle("TextFile");
3000 m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
3001 m_pFrame->SetTitle("Log");
3004 // X seems to require a forced resize
3006 frame->GetSize(&x, &y);
3007 frame->SetSize(-1, -1, x, y);
3010 m_pFrame->Show (true);
3016 // Handled by wxTextWindow
3017 void TextFileView::OnDraw(wxDC *WXUNUSED(dc) )
3021 void TextFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3026 TextFileView::OnClose (bool deleteWindow)
3028 if (! theApp->getMainFrame()->getShuttingDown())
3032 //GetDocumentManager()->ActivateView (this, false, true);
3033 if (! GetDocument() || ! GetDocument()->Close())
3040 if (GetDocument() && GetDocument()->getBadFileOpen())
3041 ::wxYield(); // wxWindows bug workaround
3052 TextFileView::CreateChildFrame (wxDocument *doc, wxView *view)
3055 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(0,0), wxDEFAULT_FRAME_STYLE, "Log");
3057 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE, "Log");
3059 theApp->setIconForFrame (subframe);
3061 m_pFileMenu = new wxMenu;
3063 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3064 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3065 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3066 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3067 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3068 // m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3070 m_pFileMenu->AppendSeparator();
3071 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3072 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3073 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3075 m_pFileMenu->AppendSeparator();
3076 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3077 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3079 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3080 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3082 wxMenu *help_menu = new wxMenu;
3083 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3084 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3085 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3086 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3088 wxMenuBar *menu_bar = new wxMenuBar;
3090 menu_bar->Append(m_pFileMenu, "&File");
3091 menu_bar->Append(help_menu, "&Help");
3093 subframe->SetMenuBar(menu_bar);
3094 subframe->Centre(wxBOTH);
3100 // Define a constructor for my text subwindow
3101 TextFileCanvas::TextFileCanvas (TextFileView* v, wxFrame* frame, const wxPoint& pos, const wxSize& size, long style)
3102 : wxTextCtrl (frame, -1, "", pos, size, style), m_pView(v)
3106 TextFileCanvas::~TextFileCanvas ()