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.125 2001/03/02 21:11: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 #include "wx/wxprec.h"
33 #if !wxUSE_DOC_VIEW_ARCHITECTURE
34 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
38 #include "wx/progdlg.h"
45 #include "dlgprojections.h"
46 #include "dlgreconstruct.h"
47 #include "backprojectors.h"
48 #include "reconstruct.h"
50 #include "threadproj.h"
51 #include "threadrecon.h"
52 #include "threadraster.h"
54 #if defined(MSVC) || HAVE_SSTREAM
57 #include <sstream_subst>
63 BEGIN_EVENT_TABLE(ImageFileCanvas, wxScrolledWindow)
64 EVT_MOUSE_EVENTS(ImageFileCanvas::OnMouseEvent)
65 EVT_CHAR(ImageFileCanvas::OnChar)
69 ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
70 : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v), m_xCursor(-1), m_yCursor(-1)
74 ImageFileCanvas::~ImageFileCanvas()
80 ImageFileCanvas::OnDraw(wxDC& dc)
83 m_pView->OnDraw(& dc);
87 ImageFileCanvas::DrawRubberBandCursor (wxDC& dc, int x, int y)
89 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
94 dc.SetLogicalFunction (wxINVERT);
95 dc.SetPen (*wxGREEN_PEN);
96 dc.DrawLine (0, yPt, nx, yPt);
97 dc.DrawLine (x, 0, x, ny);
98 dc.SetLogicalFunction (wxCOPY);
102 ImageFileCanvas::GetCurrentCursor (int& x, int& y)
107 if (m_xCursor >= 0 && m_yCursor >= 0)
114 ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
123 wxPoint pt(event.GetLogicalPosition(dc));
125 const ImageFileDocument* pIFDoc = m_pView->GetDocument();
128 const ImageFile& rIF = pIFDoc->getImageFile();
129 ImageFileArrayConst v = rIF.getArray();
132 const int yPt = ny - 1 - pt.y;
133 if (event.RightIsDown()) {
134 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
135 std::ostringstream os;
136 os << "Image value (" << pt.x << "," << yPt << ") = " << v[pt.x][yPt];
137 if (rIF.isComplex()) {
138 double dImag = rIF.getImaginaryArray()[pt.x][yPt];
140 os << " - " << -dImag;
142 os << " + " << dImag;
146 *theApp->getLog() << os.str().c_str();
148 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
150 else if (event.LeftIsDown() || event.LeftUp() || event.RightUp()) {
151 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
152 if (m_xCursor >= 0 && m_yCursor >= 0) {
153 DrawRubberBandCursor (dc, m_xCursor, m_yCursor);
155 DrawRubberBandCursor (dc, pt.x, yPt);
158 wxMenu* pMenu = m_pView->getMenuAnalyze();
159 if (pMenu && ! pMenu->IsEnabled(IFMENU_PLOT_ROW)) {
160 pMenu->Enable (IFMENU_PLOT_ROW, true);
161 pMenu->Enable (IFMENU_PLOT_COL, true);
162 pMenu->Enable (IFMENU_COMPARE_ROW, true);
163 pMenu->Enable (IFMENU_COMPARE_COL, true);
164 pMenu->Enable (IFMENU_PLOT_FFT_ROW, true);
165 pMenu->Enable (IFMENU_PLOT_FFT_COL, true);
168 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
170 if (event.LeftUp()) {
171 std::ostringstream os;
172 os << "Selected column " << pt.x << " , row " << yPt << "\n";
173 *theApp->getLog() << os.str().c_str();
178 ImageFileCanvas::OnChar (wxKeyEvent& event)
180 if (event.GetKeyCode() == WXK_ESCAPE) {
184 m_pView->OnUpdate (NULL);
186 wxScrolledWindow::OnChar (event);
190 ImageFileCanvas::GetBestSize() const
195 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
196 return wxSize (rIF.nx(), rIF.ny());
202 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
204 BEGIN_EVENT_TABLE(ImageFileView, wxView)
205 EVT_MENU(IFMENU_FILE_EXPORT, ImageFileView::OnExport)
206 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
207 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
208 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
209 EVT_MENU(IFMENU_VIEW_SCALE_FULL, ImageFileView::OnScaleFull)
210 EVT_MENU(IFMENU_COMPARE_IMAGES, ImageFileView::OnCompare)
211 EVT_MENU(IFMENU_COMPARE_ROW, ImageFileView::OnCompareRow)
212 EVT_MENU(IFMENU_COMPARE_COL, ImageFileView::OnCompareCol)
213 EVT_MENU(IFMENU_FILTER_INVERTVALUES, ImageFileView::OnInvertValues)
214 EVT_MENU(IFMENU_FILTER_SQUARE, ImageFileView::OnSquare)
215 EVT_MENU(IFMENU_FILTER_SQRT, ImageFileView::OnSquareRoot)
216 EVT_MENU(IFMENU_FILTER_LOG, ImageFileView::OnLog)
217 EVT_MENU(IFMENU_FILTER_EXP, ImageFileView::OnExp)
218 EVT_MENU(IFMENU_FILTER_FOURIER, ImageFileView::OnFourier)
219 EVT_MENU(IFMENU_FILTER_INVERSE_FOURIER, ImageFileView::OnInverseFourier)
220 EVT_MENU(IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, ImageFileView::OnShuffleFourierToNaturalOrder)
221 EVT_MENU(IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, ImageFileView::OnShuffleNaturalToFourierOrder)
222 EVT_MENU(IFMENU_IMAGE_ADD, ImageFileView::OnAdd)
223 EVT_MENU(IFMENU_IMAGE_SUBTRACT, ImageFileView::OnSubtract)
224 EVT_MENU(IFMENU_IMAGE_MULTIPLY, ImageFileView::OnMultiply)
225 EVT_MENU(IFMENU_IMAGE_DIVIDE, ImageFileView::OnDivide)
226 EVT_MENU(IFMENU_IMAGE_SCALESIZE, ImageFileView::OnScaleSize)
228 EVT_MENU(IFMENU_IMAGE_CONVERT3D, ImageFileView::OnConvert3d)
231 EVT_MENU(IFMENU_FILTER_FFT, ImageFileView::OnFFT)
232 EVT_MENU(IFMENU_FILTER_IFFT, ImageFileView::OnIFFT)
233 EVT_MENU(IFMENU_FILTER_FFT_ROWS, ImageFileView::OnFFTRows)
234 EVT_MENU(IFMENU_FILTER_IFFT_ROWS, ImageFileView::OnIFFTRows)
235 EVT_MENU(IFMENU_FILTER_FFT_COLS, ImageFileView::OnFFTCols)
236 EVT_MENU(IFMENU_FILTER_IFFT_COLS, ImageFileView::OnIFFTCols)
238 EVT_MENU(IFMENU_FILTER_MAGNITUDE, ImageFileView::OnMagnitude)
239 EVT_MENU(IFMENU_FILTER_PHASE, ImageFileView::OnPhase)
240 EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)
241 EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol)
243 EVT_MENU(IFMENU_PLOT_FFT_ROW, ImageFileView::OnPlotFFTRow)
244 EVT_MENU(IFMENU_PLOT_FFT_COL, ImageFileView::OnPlotFFTCol)
246 EVT_MENU(IFMENU_PLOT_HISTOGRAM, ImageFileView::OnPlotHistogram)
249 ImageFileView::ImageFileView()
250 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
252 m_iDefaultExportFormatID = ImageFile::EXPORT_FORMAT_PNG;
255 ImageFileView::~ImageFileView()
257 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
258 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
263 ImageFileView::OnProperties (wxCommandEvent& event)
265 const ImageFile& rIF = GetDocument()->getImageFile();
266 if (rIF.nx() == 0 || rIF.ny() == 0)
267 *theApp->getLog() << "Properties: empty imagefile\n";
269 const std::string rFilename = m_pFrame->GetTitle().c_str();
270 std::ostringstream os;
271 double min, max, mean, mode, median, stddev;
272 rIF.statistics (rIF.getArray(), min, max, mean, mode, median, stddev);
273 os << "Filename: " << rFilename << "\n";
274 os << "Size: (" << rIF.nx() << "," << rIF.ny() << ")\n";
280 os << "Minimum: "<<min<<"\nMaximum: "<<max<<"\nMean: "<<mean<<"\nMedian: "<<median<<"\nMode: "<<mode<<"\nStandard Deviation: "<<stddev << "\n";
281 if (rIF.isComplex()) {
282 rIF.statistics (rIF.getImaginaryArray(), min, max, mean, mode, median, stddev);
283 os << "Imaginary: min: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
285 if (rIF.nLabels() > 0) {
286 rIF.printLabelsBrief (os);
288 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
289 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
290 dialogMsg.ShowModal();
295 ImageFileView::OnScaleAuto (wxCommandEvent& event)
297 const ImageFile& rIF = GetDocument()->getImageFile();
298 double min, max, mean, mode, median, stddev;
299 rIF.statistics(min, max, mean, mode, median, stddev);
300 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
301 int iRetVal = dialogAutoScale.ShowModal();
302 if (iRetVal == wxID_OK) {
303 m_bMinSpecified = true;
304 m_bMaxSpecified = true;
306 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
309 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
310 OnUpdate (this, NULL);
316 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
318 const ImageFile& rIF = GetDocument()->getImageFile();
320 if (! m_bMinSpecified && ! m_bMaxSpecified)
321 rIF.getMinMax (min, max);
328 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Image Minimum & Maximum", min, max);
329 int retVal = dialogMinMax.ShowModal();
330 if (retVal == wxID_OK) {
331 m_bMinSpecified = true;
332 m_bMaxSpecified = true;
333 m_dMinPixel = dialogMinMax.getMinimum();
334 m_dMaxPixel = dialogMinMax.getMaximum();
335 OnUpdate (this, NULL);
340 ImageFileView::OnScaleFull (wxCommandEvent& event)
342 if (m_bMinSpecified || m_bMaxSpecified) {
343 m_bMinSpecified = false;
344 m_bMaxSpecified = false;
345 OnUpdate (this, NULL);
350 ImageFileView::OnCompare (wxCommandEvent& event)
352 std::vector<ImageFileDocument*> vecIF;
353 theApp->getCompatibleImages (GetDocument(), vecIF);
355 if (vecIF.size() == 0) {
356 wxMessageBox("There are no compatible image files open for comparision", "No comparison images");
358 DialogGetComparisonImage dialogGetCompare(getFrameForChild(), "Get Comparison Image", vecIF, true);
360 if (dialogGetCompare.ShowModal() == wxID_OK) {
361 const ImageFile& rIF = GetDocument()->getImageFile();
362 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
363 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
364 std::ostringstream os;
365 double min, max, mean, mode, median, stddev;
366 rIF.statistics (min, max, mean, mode, median, stddev);
367 os << GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
368 rCompareIF.statistics (min, max, mean, mode, median, stddev);
369 os << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
371 rIF.comparativeStatistics (rCompareIF, d, r, e);
372 os << "Comparative Statistics: d=" << d << ", r=" << r << ", e=" << e << "\n";
373 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
374 if (dialogGetCompare.getMakeDifferenceImage()) {
375 ImageFile* pDifferenceImage = new ImageFile;
377 pDifferenceImage->setArraySize (rIF.nx(), rIF.ny());
378 if (! rIF.subtractImages (rCompareIF, *pDifferenceImage)) {
379 *theApp->getLog() << "Unable to subtract images\n";
380 delete pDifferenceImage;
383 ImageFileDocument* pDifferenceDoc = theApp->newImageDoc();
384 if (! pDifferenceDoc) {
385 sys_error (ERR_SEVERE, "Unable to create image file");
388 pDifferenceDoc->setImageFile (pDifferenceImage);
390 wxString s = GetFrame()->GetTitle() + ": ";
391 pDifferenceImage->labelsCopy (rIF, s.c_str());
392 s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
393 pDifferenceImage->labelsCopy (rCompareIF, s.c_str());
394 std::ostringstream osLabel;
395 osLabel << "Compare image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str()
396 << " and " << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": "
398 pDifferenceImage->labelAdd (os.str().c_str());
399 if (theApp->getAskDeleteNewDocs())
400 pDifferenceDoc->Modify (true);
401 pDifferenceDoc->UpdateAllViews (this);
402 pDifferenceDoc->getView()->OnUpdate (this, NULL);
403 pDifferenceDoc->getView()->getFrame()->Show(true);
405 wxMessageBox(os.str().c_str(), "Image Comparison");
411 ImageFileView::OnInvertValues (wxCommandEvent& event)
413 ImageFile& rIF = GetDocument()->getImageFile();
414 rIF.invertPixelValues (rIF);
415 rIF.labelAdd ("Invert Pixel Values");
416 if (theApp->getAskDeleteNewDocs())
417 GetDocument()->Modify (true);
418 GetDocument()->UpdateAllViews (this);
422 ImageFileView::OnSquare (wxCommandEvent& event)
424 ImageFile& rIF = GetDocument()->getImageFile();
426 rIF.labelAdd ("Square Pixel Values");
427 if (theApp->getAskDeleteNewDocs())
428 GetDocument()->Modify (true);
429 GetDocument()->UpdateAllViews (this);
433 ImageFileView::OnSquareRoot (wxCommandEvent& event)
435 ImageFile& rIF = GetDocument()->getImageFile();
437 rIF.labelAdd ("Square-root Pixel Values");
438 if (theApp->getAskDeleteNewDocs())
439 GetDocument()->Modify (true);
440 GetDocument()->UpdateAllViews (this);
444 ImageFileView::OnLog (wxCommandEvent& event)
446 ImageFile& rIF = GetDocument()->getImageFile();
448 rIF.labelAdd ("Logrithm base-e Pixel Values");
449 if (theApp->getAskDeleteNewDocs())
450 GetDocument()->Modify (true);
451 GetDocument()->UpdateAllViews (this);
455 ImageFileView::OnExp (wxCommandEvent& event)
457 ImageFile& rIF = GetDocument()->getImageFile();
459 rIF.labelAdd ("Exponent base-e Pixel Values");
460 if (theApp->getAskDeleteNewDocs())
461 GetDocument()->Modify (true);
462 GetDocument()->UpdateAllViews (this);
466 ImageFileView::OnAdd (wxCommandEvent& event)
468 std::vector<ImageFileDocument*> vecIF;
469 theApp->getCompatibleImages (GetDocument(), vecIF);
471 if (vecIF.size() == 0) {
472 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
474 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Add", vecIF, false);
476 if (dialogGetCompare.ShowModal() == wxID_OK) {
477 ImageFile& rIF = GetDocument()->getImageFile();
478 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
479 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
480 ImageFileDocument* pNewDoc = theApp->newImageDoc();
482 sys_error (ERR_SEVERE, "Unable to create image file");
485 ImageFile& newImage = pNewDoc->getImageFile();
486 newImage.setArraySize (rIF.nx(), rIF.ny());
487 rIF.addImages (rRHSIF, newImage);
488 std::ostringstream os;
489 os << "Add image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
490 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
491 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
492 newImage.labelsCopy (rIF, s.c_str());
493 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
494 newImage.labelsCopy (rRHSIF, s.c_str());
495 newImage.labelAdd (os.str().c_str());
496 *theApp->getLog() << os.str().c_str() << "\n";
497 if (theApp->getAskDeleteNewDocs())
498 pNewDoc->Modify (true);
499 pNewDoc->UpdateAllViews (this);
500 pNewDoc->getView()->OnUpdate (this, NULL);
501 pNewDoc->getView()->getFrame()->Show(true);
507 ImageFileView::OnSubtract (wxCommandEvent& event)
509 std::vector<ImageFileDocument*> vecIF;
510 theApp->getCompatibleImages (GetDocument(), vecIF);
512 if (vecIF.size() == 0) {
513 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
515 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Subtract", vecIF, false);
517 if (dialogGetCompare.ShowModal() == wxID_OK) {
518 ImageFile& rIF = GetDocument()->getImageFile();
519 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
520 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
521 ImageFileDocument* pNewDoc = theApp->newImageDoc();
523 sys_error (ERR_SEVERE, "Unable to create image file");
526 ImageFile& newImage = pNewDoc->getImageFile();
527 newImage.setArraySize (rIF.nx(), rIF.ny());
528 rIF.subtractImages (rRHSIF, newImage);
529 std::ostringstream os;
530 os << "Subtract image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
531 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
532 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
533 newImage.labelsCopy (rIF, s.c_str());
534 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
535 newImage.labelsCopy (rRHSIF, s.c_str());
536 newImage.labelAdd (os.str().c_str());
537 *theApp->getLog() << os.str().c_str() << "\n";
538 if (theApp->getAskDeleteNewDocs())
539 pNewDoc->Modify (true);
540 pNewDoc->UpdateAllViews (this);
541 pNewDoc->getView()->OnUpdate (this, NULL);
542 pNewDoc->getView()->getFrame()->Show(true);
548 ImageFileView::OnMultiply (wxCommandEvent& event)
550 std::vector<ImageFileDocument*> vecIF;
551 theApp->getCompatibleImages (GetDocument(), vecIF);
553 if (vecIF.size() == 0) {
554 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
556 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Multiply", vecIF, false);
558 if (dialogGetCompare.ShowModal() == wxID_OK) {
559 ImageFile& rIF = GetDocument()->getImageFile();
560 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
561 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
562 ImageFileDocument* pNewDoc = theApp->newImageDoc();
564 sys_error (ERR_SEVERE, "Unable to create image file");
567 ImageFile& newImage = pNewDoc->getImageFile();
568 newImage.setArraySize (rIF.nx(), rIF.ny());
569 rIF.multiplyImages (rRHSIF, newImage);
570 std::ostringstream os;
571 os << "Multiply image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
572 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
573 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
574 newImage.labelsCopy (rIF, s.c_str());
575 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
576 newImage.labelsCopy (rRHSIF, s.c_str());
577 newImage.labelAdd (os.str().c_str());
578 *theApp->getLog() << os.str().c_str() << "\n";
579 if (theApp->getAskDeleteNewDocs())
580 pNewDoc->Modify (true);
581 pNewDoc->UpdateAllViews (this);
582 pNewDoc->getView()->OnUpdate (this, NULL);
583 pNewDoc->getView()->getFrame()->Show(true);
589 ImageFileView::OnDivide (wxCommandEvent& event)
591 std::vector<ImageFileDocument*> vecIF;
592 theApp->getCompatibleImages (GetDocument(), vecIF);
594 if (vecIF.size() == 0) {
595 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
597 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Divide", vecIF, false);
599 if (dialogGetCompare.ShowModal() == wxID_OK) {
600 ImageFile& rIF = GetDocument()->getImageFile();
601 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
602 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
603 ImageFileDocument* pNewDoc = theApp->newImageDoc();
605 sys_error (ERR_SEVERE, "Unable to create image file");
608 ImageFile& newImage = pNewDoc->getImageFile();
609 newImage.setArraySize (rIF.nx(), rIF.ny());
610 rIF.divideImages (rRHSIF, newImage);
611 std::ostringstream os;
612 os << "Divide image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " by "
613 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
614 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
615 newImage.labelsCopy (rIF, s.c_str());
616 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
617 newImage.labelsCopy (rRHSIF, s.c_str());
618 newImage.labelAdd (os.str().c_str());
619 *theApp->getLog() << os.str().c_str() << "\n";
620 if (theApp->getAskDeleteNewDocs())
621 pNewDoc->Modify (true);
622 pNewDoc->UpdateAllViews (this);
623 pNewDoc->getView()->OnUpdate (this, NULL);
624 pNewDoc->getView()->getFrame()->Show(true);
632 ImageFileView::OnFFT (wxCommandEvent& event)
634 ImageFile& rIF = GetDocument()->getImageFile();
636 rIF.labelAdd ("FFT Image");
637 m_bMinSpecified = false;
638 m_bMaxSpecified = false;
639 if (theApp->getAskDeleteNewDocs())
640 GetDocument()->Modify (true);
641 GetDocument()->UpdateAllViews (this);
645 ImageFileView::OnIFFT (wxCommandEvent& event)
647 ImageFile& rIF = GetDocument()->getImageFile();
649 rIF.labelAdd ("IFFT Image");
650 m_bMinSpecified = false;
651 m_bMaxSpecified = false;
652 if (theApp->getAskDeleteNewDocs())
653 GetDocument()->Modify (true);
654 GetDocument()->UpdateAllViews (this);
658 ImageFileView::OnFFTRows (wxCommandEvent& event)
660 ImageFile& rIF = GetDocument()->getImageFile();
662 rIF.labelAdd ("FFT Rows");
663 m_bMinSpecified = false;
664 m_bMaxSpecified = false;
665 if (theApp->getAskDeleteNewDocs())
666 GetDocument()->Modify (true);
667 GetDocument()->UpdateAllViews (this);
671 ImageFileView::OnIFFTRows (wxCommandEvent& event)
673 ImageFile& rIF = GetDocument()->getImageFile();
675 rIF.labelAdd ("IFFT Rows");
676 m_bMinSpecified = false;
677 m_bMaxSpecified = false;
678 if (theApp->getAskDeleteNewDocs())
679 GetDocument()->Modify (true);
680 GetDocument()->UpdateAllViews (this);
684 ImageFileView::OnFFTCols (wxCommandEvent& event)
686 ImageFile& rIF = GetDocument()->getImageFile();
688 rIF.labelAdd ("FFT Columns");
689 m_bMinSpecified = false;
690 m_bMaxSpecified = false;
691 if (theApp->getAskDeleteNewDocs())
692 GetDocument()->Modify (true);
693 GetDocument()->UpdateAllViews (this);
697 ImageFileView::OnIFFTCols (wxCommandEvent& event)
699 ImageFile& rIF = GetDocument()->getImageFile();
701 rIF.labelAdd ("IFFT Columns");
702 m_bMinSpecified = false;
703 m_bMaxSpecified = false;
704 if (theApp->getAskDeleteNewDocs())
705 GetDocument()->Modify (true);
706 GetDocument()->UpdateAllViews (this);
711 ImageFileView::OnFourier (wxCommandEvent& event)
713 ImageFile& rIF = GetDocument()->getImageFile();
714 wxProgressDialog dlgProgress (wxString("Fourier"), wxString("Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
716 rIF.labelAdd ("Fourier Image");
717 m_bMinSpecified = false;
718 m_bMaxSpecified = false;
719 if (theApp->getAskDeleteNewDocs())
720 GetDocument()->Modify (true);
721 GetDocument()->UpdateAllViews (this);
725 ImageFileView::OnInverseFourier (wxCommandEvent& event)
727 ImageFile& rIF = GetDocument()->getImageFile();
728 wxProgressDialog dlgProgress (wxString("Inverse Fourier"), wxString("Inverse Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
729 rIF.inverseFourier (rIF);
730 rIF.labelAdd ("Inverse Fourier Image");
731 m_bMinSpecified = false;
732 m_bMaxSpecified = false;
733 if (theApp->getAskDeleteNewDocs())
734 GetDocument()->Modify (true);
735 GetDocument()->UpdateAllViews (this);
739 ImageFileView::OnShuffleNaturalToFourierOrder (wxCommandEvent& event)
741 ImageFile& rIF = GetDocument()->getImageFile();
742 Fourier::shuffleNaturalToFourierOrder (rIF);
743 rIF.labelAdd ("Shuffle Natural To Fourier Order");
744 m_bMinSpecified = false;
745 m_bMaxSpecified = false;
746 if (theApp->getAskDeleteNewDocs())
747 GetDocument()->Modify (true);
748 GetDocument()->UpdateAllViews (this);
752 ImageFileView::OnShuffleFourierToNaturalOrder (wxCommandEvent& event)
754 ImageFile& rIF = GetDocument()->getImageFile();
755 Fourier::shuffleFourierToNaturalOrder (rIF);
756 rIF.labelAdd ("Shuffle Fourier To Natural Order");
757 m_bMinSpecified = false;
758 m_bMaxSpecified = false;
759 if (theApp->getAskDeleteNewDocs())
760 GetDocument()->Modify (true);
761 GetDocument()->UpdateAllViews (this);
765 ImageFileView::OnMagnitude (wxCommandEvent& event)
767 ImageFile& rIF = GetDocument()->getImageFile();
768 if (rIF.isComplex()) {
770 rIF.labelAdd ("Magnitude of complex-image");
771 m_bMinSpecified = false;
772 m_bMaxSpecified = false;
773 if (theApp->getAskDeleteNewDocs())
774 GetDocument()->Modify (true);
775 GetDocument()->UpdateAllViews (this);
780 ImageFileView::OnPhase (wxCommandEvent& event)
782 ImageFile& rIF = GetDocument()->getImageFile();
783 if (rIF.isComplex()) {
785 rIF.labelAdd ("Phase of complex-image");
786 m_bMinSpecified = false;
787 m_bMaxSpecified = false;
788 if (theApp->getAskDeleteNewDocs())
789 GetDocument()->Modify (true);
790 GetDocument()->UpdateAllViews (this);
796 ImageFileView::CreateCanvas (wxFrame* parent)
798 ImageFileCanvas* pCanvas;
800 parent->GetClientSize(&width, &height);
802 pCanvas = new ImageFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
804 pCanvas->SetScrollbars(20, 20, 50, 50);
805 pCanvas->SetBackgroundColour(*wxWHITE);
816 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
819 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
821 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
823 theApp->setIconForFrame (subframe);
825 m_pFileMenu = new wxMenu;
827 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
828 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
829 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
830 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
831 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
832 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
833 m_pFileMenu->Append(wxID_REVERT, "Re&vert");
835 m_pFileMenu->AppendSeparator();
836 m_pFileMenu->Append(IFMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
837 m_pFileMenu->Append(IFMENU_FILE_EXPORT, "&Export...");
839 m_pFileMenu->AppendSeparator();
840 m_pFileMenu->Append(wxID_PRINT, "&Print...");
841 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
842 m_pFileMenu->Append(wxID_PREVIEW, "Print Preview");
843 m_pFileMenu->AppendSeparator();
844 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import\tCtrl-I...");
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, "P&lot FFT Row");
900 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_COL, "Plo&t FFT Column");
901 m_pMenuAnalyze->AppendSeparator();
902 m_pMenuAnalyze->Append (IFMENU_COMPARE_IMAGES, "Compare &Images...");
903 m_pMenuAnalyze->Append (IFMENU_COMPARE_ROW, "Compare Ro&w");
904 m_pMenuAnalyze->Append (IFMENU_COMPARE_COL, "Compare Colu&mn");
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[5];
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);
935 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), IFMENU_FILE_PROPERTIES);
937 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('3'), IFMENU_IMAGE_CONVERT3D);
938 wxAcceleratorTable accelTable (5, accelEntries);
940 wxAcceleratorTable accelTable (4, accelEntries);
943 subframe->SetAcceleratorTable (accelTable);
950 ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
952 m_pFrame = CreateChildFrame(doc, this);
954 m_bMinSpecified = false;
955 m_bMaxSpecified = false;
956 m_dAutoScaleFactor = 1.;
959 m_pFrame->GetClientSize (&width, &height);
960 m_pFrame->SetTitle("ImageFileView");
961 m_pCanvas = CreateCanvas (m_pFrame);
963 int x, y; // X requires a forced resize
964 m_pFrame->GetSize(&x, &y);
965 m_pFrame->SetSize(-1, -1, x, y);
966 m_pFrame->SetFocus();
967 m_pFrame->Show(true);
974 ImageFileView::OnDraw (wxDC* dc)
976 wxSize sizeWindow = m_pFrame->GetClientSize();
977 wxSize sizeBest = m_pCanvas->GetBestSize();
978 if (sizeWindow.x > sizeBest.x || sizeWindow.y > sizeBest.y)
979 m_pFrame->SetClientSize (sizeBest);
982 dc->DrawBitmap(m_bitmap, 0, 0, false);
984 int xCursor, yCursor;
985 if (m_pCanvas->GetCurrentCursor (xCursor, yCursor))
986 m_pCanvas->DrawRubberBandCursor (*dc, xCursor, yCursor);
991 ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
993 const ImageFile& rIF = GetDocument()->getImageFile();
994 ImageFileArrayConst v = rIF.getArray();
997 if (v != NULL && nx != 0 && ny != 0) {
998 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1000 rIF.getMinMax (min, max);
1001 if (! m_bMinSpecified)
1003 if (! m_bMaxSpecified)
1006 double scaleWidth = m_dMaxPixel - m_dMinPixel;
1008 unsigned char* imageData = new unsigned char [nx * ny * 3];
1010 sys_error (ERR_SEVERE, "Unable to allocate memory for Image display");
1013 for (int ix = 0; ix < nx; ix++) {
1014 for (int iy = 0; iy < ny; iy++) {
1015 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
1016 int intensity = static_cast<int>(scaleValue + 0.5);
1017 intensity = clamp (intensity, 0, 255);
1018 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
1019 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
1022 wxImage image (nx, ny, imageData, true);
1023 m_bitmap = image.ConvertToBitmap();
1027 ySize = clamp (ySize, 0, 800);
1028 m_pFrame->SetClientSize (xSize, ySize);
1029 m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20);
1030 m_pCanvas->SetBackgroundColour(*wxWHITE);
1034 m_pCanvas->Refresh();
1038 ImageFileView::OnClose (bool deleteWindow)
1040 //GetDocumentManager()->ActivateView (this, false, true);
1041 if (! GetDocument() || ! GetDocument()->Close())
1046 m_pCanvas->setView(NULL);
1049 wxString s(theApp->GetAppName());
1051 m_pFrame->SetTitle(s);
1058 if (GetDocument() && GetDocument()->getBadFileOpen())
1059 ::wxYield(); // wxWindows bug workaround
1066 ImageFileView::OnExport (wxCommandEvent& event)
1068 ImageFile& rIF = GetDocument()->getImageFile();
1069 ImageFileArrayConst v = rIF.getArray();
1072 if (v != NULL && nx != 0 && ny != 0) {
1073 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1075 rIF.getMinMax (min, max);
1076 if (! m_bMinSpecified)
1078 if (! m_bMaxSpecified)
1082 DialogExportParameters dialogExport (getFrameForChild(), m_iDefaultExportFormatID);
1083 if (dialogExport.ShowModal() == wxID_OK) {
1084 wxString strFormatName (dialogExport.getFormatName ());
1085 m_iDefaultExportFormatID = ImageFile::convertExportFormatNameToID (strFormatName.c_str());
1088 wxString strWildcard;
1089 if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PGM || m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PGMASCII) {
1091 strWildcard = "PGM Files (*.pgm)|*.pgm";
1094 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PNG || m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PNG16) {
1096 strWildcard = "PNG Files (*.png)|*.png";
1101 strWildcard = "Miscellaneous (*.*)|*.*";
1104 const wxString& strFilename = wxFileSelector (wxString("Export Filename"), wxString(""),
1105 wxString(""), strExt, strWildcard, wxOVERWRITE_PROMPT | wxHIDE_READONLY | wxSAVE);
1107 rIF.exportImage (strFormatName.c_str(), strFilename.c_str(), 1, 1, m_dMinPixel, m_dMaxPixel);
1108 *theApp->getLog() << "Exported file " << strFilename << "\n";
1115 ImageFileView::OnScaleSize (wxCommandEvent& event)
1117 ImageFile& rIF = GetDocument()->getImageFile();
1118 unsigned int iOldNX = rIF.nx();
1119 unsigned int iOldNY = rIF.ny();
1121 DialogGetXYSize dialogGetXYSize (getFrameForChild(), "Set New X & Y Dimensions", iOldNX, iOldNY);
1122 if (dialogGetXYSize.ShowModal() == wxID_OK) {
1123 unsigned int iNewNX = dialogGetXYSize.getXSize();
1124 unsigned int iNewNY = dialogGetXYSize.getYSize();
1125 std::ostringstream os;
1126 os << "Scale Size from (" << iOldNX << "," << iOldNY << ") to (" << iNewNX << "," << iNewNY << ")";
1127 ImageFileDocument* pScaledDoc = theApp->newImageDoc();
1129 sys_error (ERR_SEVERE, "Unable to create image file");
1132 ImageFile& rScaledIF = pScaledDoc->getImageFile();
1133 rScaledIF.setArraySize (iNewNX, iNewNY);
1134 rScaledIF.labelsCopy (rIF);
1135 rScaledIF.labelAdd (os.str().c_str());
1136 rIF.scaleImage (rScaledIF);
1137 *theApp->getLog() << os.str().c_str() << "\n";
1138 if (theApp->getAskDeleteNewDocs())
1139 pScaledDoc->Modify (true);
1140 pScaledDoc->UpdateAllViews (this);
1141 pScaledDoc->getView()->OnUpdate (this, NULL);
1142 pScaledDoc->getView()->getFrame()->Show(true);
1148 ImageFileView::OnConvert3d (wxCommandEvent& event)
1150 ImageFile& rIF = GetDocument()->getImageFile();
1151 Graph3dFileDocument* pGraph3d = theApp->newGraph3dDoc();
1152 pGraph3d->setBadFileOpen();
1153 pGraph3d->createFromImageFile (rIF);
1154 pGraph3d->getView()->OnUpdate (this, NULL);
1155 pGraph3d->UpdateAllViews();
1156 pGraph3d->getView()->getFrame()->SetClientSize (400, 400);
1157 pGraph3d->getView()->getFrame()->Show (true);
1158 GetDocumentManager()->ActivateView (pGraph3d->getView(), true, false);
1160 pGraph3d->getView()->getCanvas()->SetFocus();
1165 ImageFileView::OnPlotRow (wxCommandEvent& event)
1167 int xCursor, yCursor;
1168 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1169 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1173 const ImageFile& rIF = GetDocument()->getImageFile();
1174 ImageFileArrayConst v = rIF.getArray();
1175 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1179 if (v != NULL && yCursor < ny) {
1180 double* pX = new double [nx];
1181 double* pYReal = new double [nx];
1182 double *pYImag = NULL;
1183 double *pYMag = NULL;
1184 if (rIF.isComplex()) {
1185 pYImag = new double [nx];
1186 pYMag = new double [nx];
1188 for (int i = 0; i < nx; i++) {
1190 pYReal[i] = v[i][yCursor];
1191 if (rIF.isComplex()) {
1192 pYImag[i] = vImag[i][yCursor];
1193 pYMag[i] = ::sqrt (v[i][yCursor] * v[i][yCursor] + vImag[i][yCursor] * vImag[i][yCursor]);
1196 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1198 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1200 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1201 std::ostringstream os;
1202 os << "Row " << yCursor;
1203 std::string title("title ");
1205 rPlotFile.addEzsetCommand (title.c_str());
1206 rPlotFile.addEzsetCommand ("xlabel Column");
1207 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1208 rPlotFile.addEzsetCommand ("lxfrac 0");
1209 rPlotFile.addEzsetCommand ("box");
1210 rPlotFile.addEzsetCommand ("grid");
1211 rPlotFile.addEzsetCommand ("curve 1");
1212 rPlotFile.addEzsetCommand ("color 1");
1213 if (rIF.isComplex()) {
1214 rPlotFile.addEzsetCommand ("dash 1");
1215 rPlotFile.addEzsetCommand ("curve 2");
1216 rPlotFile.addEzsetCommand ("color 4");
1217 rPlotFile.addEzsetCommand ("dash 3");
1218 rPlotFile.addEzsetCommand ("curve 3");
1219 rPlotFile.addEzsetCommand ("color 0");
1220 rPlotFile.addEzsetCommand ("solid");
1221 rPlotFile.setCurveSize (4, nx);
1223 rPlotFile.setCurveSize (2, nx);
1224 rPlotFile.addColumn (0, pX);
1225 rPlotFile.addColumn (1, pYReal);
1226 if (rIF.isComplex()) {
1227 rPlotFile.addColumn (2, pYImag);
1228 rPlotFile.addColumn (3, pYMag);
1230 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1231 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1232 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1233 *theApp->getLog() << os.str().c_str() << "\n";
1234 rPlotFile.addDescription (os.str().c_str());
1238 if (rIF.isComplex()) {
1242 if (theApp->getAskDeleteNewDocs())
1243 pPlotDoc->Modify (true);
1244 pPlotDoc->UpdateAllViews ();
1245 pPlotDoc->getView()->OnUpdate (this, NULL);
1246 pPlotDoc->getView()->getFrame()->Show(true);
1251 ImageFileView::OnPlotCol (wxCommandEvent& event)
1253 int xCursor, yCursor;
1254 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1255 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1259 const ImageFile& rIF = GetDocument()->getImageFile();
1260 ImageFileArrayConst v = rIF.getArray();
1261 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1265 if (v != NULL && xCursor < nx) {
1266 double* pX = new double [ny];
1267 double* pYReal = new double [ny];
1268 double* pYImag = NULL;
1269 double* pYMag = NULL;
1270 if (rIF.isComplex()) {
1271 pYImag = new double [ny];
1272 pYMag = new double [ny];
1274 for (int i = 0; i < ny; i++) {
1276 pYReal[i] = v[xCursor][i];
1277 if (rIF.isComplex()) {
1278 pYImag[i] = vImag[xCursor][i];
1279 pYMag[i] = ::sqrt (v[xCursor][i] * v[xCursor][i] + vImag[xCursor][i] * vImag[xCursor][i]);
1282 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1284 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1286 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1287 std::ostringstream os;
1288 os << "Column " << xCursor;
1289 std::string title("title ");
1291 rPlotFile.addEzsetCommand (title.c_str());
1292 rPlotFile.addEzsetCommand ("xlabel Row");
1293 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1294 rPlotFile.addEzsetCommand ("lxfrac 0");
1295 rPlotFile.addEzsetCommand ("box");
1296 rPlotFile.addEzsetCommand ("grid");
1297 rPlotFile.addEzsetCommand ("curve 1");
1298 rPlotFile.addEzsetCommand ("color 1");
1299 if (rIF.isComplex()) {
1300 rPlotFile.addEzsetCommand ("dash 1");
1301 rPlotFile.addEzsetCommand ("curve 2");
1302 rPlotFile.addEzsetCommand ("color 4");
1303 rPlotFile.addEzsetCommand ("dash 3");
1304 rPlotFile.addEzsetCommand ("curve 3");
1305 rPlotFile.addEzsetCommand ("color 0");
1306 rPlotFile.addEzsetCommand ("solid");
1307 rPlotFile.setCurveSize (4, ny);
1309 rPlotFile.setCurveSize (2, ny);
1310 rPlotFile.addColumn (0, pX);
1311 rPlotFile.addColumn (1, pYReal);
1312 if (rIF.isComplex()) {
1313 rPlotFile.addColumn (2, pYImag);
1314 rPlotFile.addColumn (3, pYMag);
1316 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1317 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1318 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1319 *theApp->getLog() << os.str().c_str() << "\n";
1320 rPlotFile.addDescription (os.str().c_str());
1324 if (rIF.isComplex()) {
1328 if (theApp->getAskDeleteNewDocs())
1329 pPlotDoc->Modify (true);
1330 pPlotDoc->UpdateAllViews ();
1331 pPlotDoc->getView()->OnUpdate (this, NULL);
1332 pPlotDoc->getView()->getFrame()->Show(true);
1338 ImageFileView::OnPlotFFTRow (wxCommandEvent& event)
1340 int xCursor, yCursor;
1341 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1342 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1346 const ImageFile& rIF = GetDocument()->getImageFile();
1347 ImageFileArrayConst v = rIF.getArray();
1348 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1352 if (v != NULL && yCursor < ny) {
1353 fftw_complex* pcIn = new fftw_complex [nx];
1356 for (i = 0; i < nx; i++) {
1357 pcIn[i].re = v[i][yCursor];
1358 if (rIF.isComplex())
1359 pcIn[i].im = vImag[i][yCursor];
1364 fftw_plan plan = fftw_create_plan (nx, FFTW_FORWARD, FFTW_IN_PLACE);
1365 fftw_one (plan, pcIn, NULL);
1366 fftw_destroy_plan (plan);
1368 double* pX = new double [nx];
1369 double* pYReal = new double [nx];
1370 double* pYImag = new double [nx];
1371 double* pYMag = new double [nx];
1372 for (i = 0; i < nx; i++) {
1374 pYReal[i] = pcIn[i].re;
1375 pYImag[i] = pcIn[i].im;
1376 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1378 Fourier::shuffleFourierToNaturalOrder (pYReal, nx);
1379 Fourier::shuffleFourierToNaturalOrder (pYImag, nx);
1380 Fourier::shuffleFourierToNaturalOrder (pYMag, nx);
1382 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1384 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1386 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1387 std::ostringstream os;
1388 os << "Row " << yCursor;
1389 std::string title("title ");
1391 rPlotFile.addEzsetCommand (title.c_str());
1392 rPlotFile.addEzsetCommand ("xlabel Column");
1393 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1394 rPlotFile.addEzsetCommand ("lxfrac 0");
1395 rPlotFile.addEzsetCommand ("curve 1");
1396 rPlotFile.addEzsetCommand ("color 1");
1397 rPlotFile.addEzsetCommand ("dash 1");
1398 rPlotFile.addEzsetCommand ("curve 2");
1399 rPlotFile.addEzsetCommand ("color 4");
1400 rPlotFile.addEzsetCommand ("dash 3");
1401 rPlotFile.addEzsetCommand ("curve 3");
1402 rPlotFile.addEzsetCommand ("color 0");
1403 rPlotFile.addEzsetCommand ("solid");
1404 rPlotFile.addEzsetCommand ("box");
1405 rPlotFile.addEzsetCommand ("grid");
1406 rPlotFile.setCurveSize (4, nx);
1407 rPlotFile.addColumn (0, pX);
1408 rPlotFile.addColumn (1, pYReal);
1409 rPlotFile.addColumn (2, pYImag);
1410 rPlotFile.addColumn (3, pYMag);
1411 for (int iL = 0; iL < rIF.nLabels(); iL++)
1412 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1413 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1414 *theApp->getLog() << os.str().c_str() << "\n";
1415 rPlotFile.addDescription (os.str().c_str());
1423 if (theApp->getAskDeleteNewDocs())
1424 pPlotDoc->Modify (true);
1425 pPlotDoc->UpdateAllViews ();
1426 pPlotDoc->getView()->OnUpdate (this, NULL);
1427 pPlotDoc->getView()->getFrame()->Show(true);
1432 ImageFileView::OnPlotFFTCol (wxCommandEvent& event)
1434 int xCursor, yCursor;
1435 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1436 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1440 const ImageFile& rIF = GetDocument()->getImageFile();
1441 ImageFileArrayConst v = rIF.getArray();
1442 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1446 if (v != NULL && xCursor < nx) {
1447 fftw_complex* pcIn = new fftw_complex [ny];
1448 double *pdTemp = new double [ny];
1451 for (i = 0; i < ny; i++)
1452 pdTemp[i] = v[xCursor][i];
1453 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1454 for (i = 0; i < ny; i++)
1455 pcIn[i].re = pdTemp[i];
1457 for (i = 0; i < ny; i++) {
1458 if (rIF.isComplex())
1459 pdTemp[i] = vImag[xCursor][i];
1463 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1464 for (i = 0; i < ny; i++)
1465 pcIn[i].im = pdTemp[i];
1467 fftw_plan plan = fftw_create_plan (ny, FFTW_BACKWARD, FFTW_IN_PLACE);
1468 fftw_one (plan, pcIn, NULL);
1469 fftw_destroy_plan (plan);
1471 double* pX = new double [ny];
1472 double* pYReal = new double [ny];
1473 double* pYImag = new double [ny];
1474 double* pYMag = new double [ny];
1475 for (i = 0; i < ny; i++) {
1477 pYReal[i] = pcIn[i].re;
1478 pYImag[i] = pcIn[i].im;
1479 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1482 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1484 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1486 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1487 std::ostringstream os;
1488 os << "Column " << xCursor;
1489 std::string title("title ");
1491 rPlotFile.addEzsetCommand (title.c_str());
1492 rPlotFile.addEzsetCommand ("xlabel Column");
1493 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1494 rPlotFile.addEzsetCommand ("lxfrac 0");
1495 rPlotFile.addEzsetCommand ("curve 1");
1496 rPlotFile.addEzsetCommand ("color 1");
1497 rPlotFile.addEzsetCommand ("dash 1");
1498 rPlotFile.addEzsetCommand ("curve 2");
1499 rPlotFile.addEzsetCommand ("color 4");
1500 rPlotFile.addEzsetCommand ("dash 3");
1501 rPlotFile.addEzsetCommand ("curve 3");
1502 rPlotFile.addEzsetCommand ("color 0");
1503 rPlotFile.addEzsetCommand ("solid");
1504 rPlotFile.addEzsetCommand ("box");
1505 rPlotFile.addEzsetCommand ("grid");
1506 rPlotFile.setCurveSize (4, ny);
1507 rPlotFile.addColumn (0, pX);
1508 rPlotFile.addColumn (1, pYReal);
1509 rPlotFile.addColumn (2, pYImag);
1510 rPlotFile.addColumn (3, pYMag);
1511 for (int iL = 0; iL < rIF.nLabels(); iL++)
1512 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1513 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1514 *theApp->getLog() << os.str().c_str() << "\n";
1515 rPlotFile.addDescription (os.str().c_str());
1524 if (theApp->getAskDeleteNewDocs())
1525 pPlotDoc->Modify (true);
1526 pPlotDoc->UpdateAllViews ();
1527 pPlotDoc->getView()->OnUpdate (this, NULL);
1528 pPlotDoc->getView()->getFrame()->Show(true);
1534 ImageFileView::OnCompareCol (wxCommandEvent& event)
1536 int xCursor, yCursor;
1537 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1538 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1542 std::vector<ImageFileDocument*> vecIFDoc;
1543 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1544 if (vecIFDoc.size() == 0) {
1545 wxMessageBox ("No compatible images for Column Comparison", "Error");
1548 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1550 if (dialogGetCompare.ShowModal() == wxID_OK) {
1551 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1552 const ImageFile& rIF = GetDocument()->getImageFile();
1553 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1555 ImageFileArrayConst v1 = rIF.getArray();
1556 ImageFileArrayConst v2 = rCompareIF.getArray();
1560 if (v1 != NULL && xCursor < nx) {
1561 double* pX = new double [ny];
1562 double* pY1 = new double [ny];
1563 double* pY2 = new double [ny];
1564 for (int i = 0; i < ny; i++) {
1566 pY1[i] = v1[xCursor][i];
1567 pY2[i] = v2[xCursor][i];
1569 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1571 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1573 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1574 std::ostringstream os;
1575 os << "Column " << xCursor << " Comparison";
1576 std::string title("title ");
1578 rPlotFile.addEzsetCommand (title.c_str());
1579 rPlotFile.addEzsetCommand ("xlabel Row");
1580 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1581 rPlotFile.addEzsetCommand ("lxfrac 0");
1582 rPlotFile.addEzsetCommand ("curve 1");
1583 rPlotFile.addEzsetCommand ("color 2");
1584 rPlotFile.addEzsetCommand ("curve 2");
1585 rPlotFile.addEzsetCommand ("color 4");
1586 rPlotFile.addEzsetCommand ("dash 5");
1587 rPlotFile.addEzsetCommand ("box");
1588 rPlotFile.addEzsetCommand ("grid");
1589 rPlotFile.setCurveSize (3, ny);
1590 rPlotFile.addColumn (0, pX);
1591 rPlotFile.addColumn (1, pY1);
1592 rPlotFile.addColumn (2, pY2);
1595 for (iL = 0; iL < rIF.nLabels(); iL++) {
1596 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1598 s += rIF.labelGet(iL).getLabelString();
1599 rPlotFile.addDescription (s.c_str());
1601 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1602 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1604 s += rCompareIF.labelGet(iL).getLabelString();
1605 rPlotFile.addDescription (s.c_str());
1607 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1608 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1609 *theApp->getLog() << os.str().c_str() << "\n";
1610 rPlotFile.addDescription (os.str().c_str());
1615 if (theApp->getAskDeleteNewDocs())
1616 pPlotDoc->Modify (true);
1617 pPlotDoc->UpdateAllViews ();
1618 pPlotDoc->getView()->OnUpdate (this, NULL);
1619 pPlotDoc->getView()->getFrame()->Show(true);
1625 ImageFileView::OnCompareRow (wxCommandEvent& event)
1627 int xCursor, yCursor;
1628 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1629 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1633 std::vector<ImageFileDocument*> vecIFDoc;
1634 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1636 if (vecIFDoc.size() == 0) {
1637 wxMessageBox ("No compatible images for Row Comparison", "Error");
1641 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1643 if (dialogGetCompare.ShowModal() == wxID_OK) {
1644 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1645 const ImageFile& rIF = GetDocument()->getImageFile();
1646 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1648 ImageFileArrayConst v1 = rIF.getArray();
1649 ImageFileArrayConst v2 = rCompareIF.getArray();
1653 if (v1 != NULL && yCursor < ny) {
1654 double* pX = new double [nx];
1655 double* pY1 = new double [nx];
1656 double* pY2 = new double [nx];
1657 for (int i = 0; i < nx; i++) {
1659 pY1[i] = v1[i][yCursor];
1660 pY2[i] = v2[i][yCursor];
1662 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1664 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1666 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1667 std::ostringstream os;
1668 os << "Row " << yCursor << " Comparison";
1669 std::string title("title ");
1671 rPlotFile.addEzsetCommand (title.c_str());
1672 rPlotFile.addEzsetCommand ("xlabel Column");
1673 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1674 rPlotFile.addEzsetCommand ("lxfrac 0");
1675 rPlotFile.addEzsetCommand ("curve 1");
1676 rPlotFile.addEzsetCommand ("color 2");
1677 rPlotFile.addEzsetCommand ("curve 2");
1678 rPlotFile.addEzsetCommand ("color 4");
1679 rPlotFile.addEzsetCommand ("dash 5");
1680 rPlotFile.addEzsetCommand ("box");
1681 rPlotFile.addEzsetCommand ("grid");
1682 rPlotFile.setCurveSize (3, nx);
1683 rPlotFile.addColumn (0, pX);
1684 rPlotFile.addColumn (1, pY1);
1685 rPlotFile.addColumn (2, pY2);
1687 for (iL = 0; iL < rIF.nLabels(); iL++) {
1688 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1690 s += rIF.labelGet(iL).getLabelString();
1691 rPlotFile.addDescription (s.c_str());
1693 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1694 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1696 s += rCompareIF.labelGet(iL).getLabelString();
1697 rPlotFile.addDescription (s.c_str());
1699 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1700 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1701 *theApp->getLog() << os.str().c_str() << "\n";
1702 rPlotFile.addDescription (os.str().c_str());
1707 if (theApp->getAskDeleteNewDocs())
1708 pPlotDoc->Modify (true);
1709 pPlotDoc->UpdateAllViews ();
1710 pPlotDoc->getView()->OnUpdate (this, NULL);
1711 pPlotDoc->getView()->getFrame()->Show(true);
1716 static int NUMBER_HISTOGRAM_BINS = 256;
1719 ImageFileView::OnPlotHistogram (wxCommandEvent& event)
1721 const ImageFile& rIF = GetDocument()->getImageFile();
1722 ImageFileArrayConst v = rIF.getArray();
1726 if (v != NULL && nx > 0 && ny > 0) {
1727 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1729 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1733 double* pX = new double [NUMBER_HISTOGRAM_BINS];
1734 double* pY = new double [NUMBER_HISTOGRAM_BINS];
1736 rIF.getMinMax (dMin, dMax);
1737 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
1739 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
1740 pX[i] = dMin + (i + 0.5) * dBinWidth;
1743 for (int ix = 0; ix < nx; ix++)
1744 for (int iy = 0; iy < ny; iy++) {
1745 int iBin = nearest<int> ((v[ix][iy] - dMin) / dBinWidth);
1746 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
1750 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1751 std::ostringstream os;
1753 std::string title("title ");
1755 rPlotFile.addEzsetCommand (title.c_str());
1756 rPlotFile.addEzsetCommand ("xlabel Pixel Value");
1757 rPlotFile.addEzsetCommand ("ylabel Count");
1758 rPlotFile.addEzsetCommand ("box");
1759 rPlotFile.addEzsetCommand ("grid");
1760 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
1761 rPlotFile.addColumn (0, pX);
1762 rPlotFile.addColumn (1, pY);
1763 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++) {
1764 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1766 s += rIF.labelGet(iL).getLabelString();
1767 rPlotFile.addDescription (s.c_str());
1769 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1770 *theApp->getLog() << os.str().c_str() << "\n";
1771 rPlotFile.addDescription (os.str().c_str());
1774 if (theApp->getAskDeleteNewDocs())
1775 pPlotDoc->Modify (true);
1776 pPlotDoc->UpdateAllViews ();
1777 pPlotDoc->getView()->OnUpdate (this, NULL);
1778 pPlotDoc->getView()->getFrame()->Show(true);
1785 PhantomCanvas::PhantomCanvas (PhantomFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1786 : wxScrolledWindow(frame, -1, pos, size, style)
1791 PhantomCanvas::~PhantomCanvas ()
1797 PhantomCanvas::OnDraw (wxDC& dc)
1800 m_pView->OnDraw(& dc);
1804 PhantomCanvas::GetBestSize() const
1810 theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
1811 xSize = maxValue<int> (xSize, ySize);
1812 ySize = xSize = (xSize / 4);
1813 return wxSize (xSize, ySize);
1820 IMPLEMENT_DYNAMIC_CLASS(PhantomFileView, wxView)
1822 BEGIN_EVENT_TABLE(PhantomFileView, wxView)
1823 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomFileView::OnProperties)
1824 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomFileView::OnRasterize)
1825 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomFileView::OnProjections)
1828 PhantomFileView::PhantomFileView()
1829 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0)
1831 #if defined(DEBUG) || defined(_DEBUG)
1832 m_iDefaultNDet = 165;
1833 m_iDefaultNView = 180;
1834 m_iDefaultNSample = 1;
1836 m_iDefaultNDet = 367;
1837 m_iDefaultNView = 320;
1838 m_iDefaultNSample = 2;
1840 m_dDefaultRotation = 1;
1841 m_dDefaultFocalLength = 2;
1842 m_dDefaultCenterDetectorLength = 2;
1843 m_dDefaultViewRatio = 1;
1844 m_dDefaultScanRatio = 1;
1845 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
1846 m_iDefaultTrace = Trace::TRACE_NONE;
1849 m_iDefaultRasterNX = 115;
1850 m_iDefaultRasterNY = 115;
1851 m_iDefaultRasterNSamples = 1;
1853 m_iDefaultRasterNX = 256;
1854 m_iDefaultRasterNY = 256;
1855 m_iDefaultRasterNSamples = 2;
1857 m_dDefaultRasterViewRatio = 1;
1860 PhantomFileView::~PhantomFileView()
1862 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
1863 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
1867 PhantomFileView::OnProperties (wxCommandEvent& event)
1869 const int idPhantom = GetDocument()->getPhantomID();
1870 const wxString& namePhantom = GetDocument()->getPhantomName();
1871 std::ostringstream os;
1872 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")" << "\n";
1873 const Phantom& rPhantom = GetDocument()->getPhantom();
1874 rPhantom.printDefinitions (os);
1876 rPhantom.print (os);
1878 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
1879 wxMessageBox (os.str().c_str(), "Phantom Properties");
1884 PhantomFileView::OnProjections (wxCommandEvent& event)
1886 DialogGetProjectionParameters dialogProjection (getFrameForChild(),
1887 m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation,
1888 m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio,
1889 m_iDefaultGeometry, m_iDefaultTrace);
1890 int retVal = dialogProjection.ShowModal();
1891 if (retVal != wxID_OK)
1894 m_iDefaultNDet = dialogProjection.getNDet();
1895 m_iDefaultNView = dialogProjection.getNView();
1896 m_iDefaultNSample = dialogProjection.getNSamples();
1897 m_iDefaultTrace = dialogProjection.getTrace();
1898 m_dDefaultRotation = dialogProjection.getRotAngle();
1899 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
1900 m_dDefaultCenterDetectorLength = dialogProjection.getCenterDetectorLengthRatio();
1901 m_dDefaultViewRatio = dialogProjection.getViewRatio();
1902 m_dDefaultScanRatio = dialogProjection.getScanRatio();
1903 wxString sGeometry = dialogProjection.getGeometry();
1904 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
1905 double dRotationRadians = m_dDefaultRotation;
1906 m_dDefaultRotation /= TWOPI; // convert back to fraction of a circle
1908 if (m_iDefaultNDet <= 0 || m_iDefaultNView <= 0 || sGeometry == "")
1911 const Phantom& rPhantom = GetDocument()->getPhantom();
1912 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample,
1913 dRotationRadians, m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio);
1914 if (theScanner.fail()) {
1915 wxString msg = "Failed making scanner\n";
1916 msg += theScanner.failMessage().c_str();
1917 *theApp->getLog() << msg << "\n";
1918 wxMessageBox (msg, "Error");
1922 std::ostringstream os;
1923 os << "Projections for " << rPhantom.name() << ": nDet=" << m_iDefaultNDet
1924 << ", nView=" << m_iDefaultNView << ", nSamples=" << m_iDefaultNSample
1925 << ", RotAngle=" << m_dDefaultRotation << ", FocalLengthRatio=" << m_dDefaultFocalLength
1926 << ", CenterDetectorLengthRatio=" << m_dDefaultCenterDetectorLength
1927 << ", ViewRatio=" << m_dDefaultViewRatio << ", ScanRatio=" << m_dDefaultScanRatio
1928 << ", Geometry=" << sGeometry.c_str() << ", FanBeamAngle=" <<
1929 convertRadiansToDegrees (theScanner.fanBeamAngle());
1932 Projections* pProj = NULL;
1933 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
1934 pProj = new Projections;
1935 pProj->initFromScanner (theScanner);
1937 ProjectionsDialog dialogProjections (theScanner, *pProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(getFrameForChild()));
1938 for (int iView = 0; iView < pProj->nView(); iView++) {
1940 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
1945 while (dialogProjections.isPaused()) {
1952 if (theApp->getUseBackgroundTasks() || theApp->getNumberCPU() > 1) {
1953 ProjectorSupervisorThread* pProjector = new ProjectorSupervisorThread (this, m_iDefaultNDet,
1954 m_iDefaultNView, sGeometry.c_str(), m_iDefaultNSample, dRotationRadians,
1955 m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio, os.str().c_str());
1956 if (pProjector->Create() != wxTHREAD_NO_ERROR) {
1957 sys_error (ERR_SEVERE, "Error creating projector thread");
1961 pProjector->SetPriority(60);
1965 #endif // HAVE_WXTHREADS
1967 pProj = new Projections;
1968 pProj->initFromScanner (theScanner);
1969 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), pProj->nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
1970 for (int i = 0; i < pProj->nView(); i++) {
1971 theScanner.collectProjections (*pProj, rPhantom, i, 1, true, m_iDefaultTrace);
1972 if (! dlgProgress.Update (i+1)) {
1980 *theApp->getLog() << os.str().c_str() << "\n";
1981 pProj->setRemark (os.str());
1982 pProj->setCalcTime (timer.timerEnd());
1984 ProjectionFileDocument* pProjectionDoc = theApp->newProjectionDoc();
1985 if (! pProjectionDoc) {
1986 sys_error (ERR_SEVERE, "Unable to create projection document");
1989 pProjectionDoc->setProjections (pProj);
1990 ProjectionFileView* projView = pProjectionDoc->getView();
1992 projView->OnUpdate (projView, NULL);
1993 if (projView->getCanvas())
1994 projView->getCanvas()->SetClientSize (m_iDefaultNDet, m_iDefaultNView);
1995 if (wxFrame* pFrame = projView->getFrame()) {
2000 GetDocumentManager()->ActivateView (projView, true, false);
2002 if (theApp->getAskDeleteNewDocs())
2003 pProjectionDoc-> Modify(true);
2004 pProjectionDoc->UpdateAllViews (this);
2009 PhantomFileView::OnRasterize (wxCommandEvent& event)
2011 DialogGetRasterParameters dialogRaster (getFrameForChild(), m_iDefaultRasterNX, m_iDefaultRasterNY,
2012 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio);
2013 int retVal = dialogRaster.ShowModal();
2014 if (retVal != wxID_OK)
2017 m_iDefaultRasterNX = dialogRaster.getXSize();
2018 m_iDefaultRasterNY = dialogRaster.getYSize();
2019 m_iDefaultRasterNSamples = dialogRaster.getNSamples();
2020 m_dDefaultRasterViewRatio = dialogRaster.getViewRatio();
2021 if (m_iDefaultRasterNSamples < 1)
2022 m_iDefaultRasterNSamples = 1;
2023 if (m_dDefaultRasterViewRatio < 0)
2024 m_dDefaultRasterViewRatio = 0;
2025 if (m_iDefaultRasterNX <= 0 || m_iDefaultRasterNY <= 0)
2028 const Phantom& rPhantom = GetDocument()->getPhantom();
2029 std::ostringstream os;
2030 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << m_iDefaultRasterNX << ", YSize="
2031 << m_iDefaultRasterNY << ", ViewRatio=" << m_dDefaultRasterViewRatio << ", nSamples="
2032 << m_iDefaultRasterNSamples;;
2035 if (theApp->getUseBackgroundTasks() || theApp->getNumberCPU() > 1) {
2036 RasterizerSupervisorThread* pThread = new RasterizerSupervisorThread (this, m_iDefaultRasterNX, m_iDefaultRasterNY,
2037 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio, os.str().c_str());
2038 if (pThread->Create() != wxTHREAD_NO_ERROR) {
2039 *theApp->getLog() << "Error creating rasterizer thread\n";
2042 pThread->SetPriority (60);
2047 ImageFile* pImageFile = new ImageFile (m_iDefaultRasterNX, m_iDefaultRasterNY);
2048 wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"),
2049 pImageFile->nx() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2051 for (unsigned int i = 0; i < pImageFile->nx(); i++) {
2052 rPhantom.convertToImagefile (*pImageFile, m_dDefaultRasterViewRatio, m_iDefaultRasterNSamples, Trace::TRACE_NONE, i, 1, true);
2053 if (! dlgProgress.Update (i+1)) {
2059 ImageFileDocument* pRasterDoc = theApp->newImageDoc();
2061 sys_error (ERR_SEVERE, "Unable to create image file");
2064 pRasterDoc->setImageFile (pImageFile);
2065 if (theApp->getAskDeleteNewDocs())
2066 pRasterDoc->Modify (true);
2067 pRasterDoc->UpdateAllViews (this);
2068 pRasterDoc->getView()->getFrame()->Show(true);
2069 *theApp->getLog() << os.str().c_str() << "\n";
2070 pImageFile->labelAdd (os.str().c_str(), timer.timerEnd());
2071 ImageFileView* rasterView = pRasterDoc->getView();
2073 rasterView->getFrame()->SetFocus();
2074 rasterView->OnUpdate (rasterView, NULL);
2081 PhantomFileView::CreateCanvas (wxFrame *parent)
2083 PhantomCanvas* pCanvas;
2085 pCanvas = new PhantomCanvas (this, parent, wxPoint(0, 0), wxSize(0,0), 0);
2086 pCanvas->SetBackgroundColour(*wxWHITE);
2097 PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2100 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2102 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2104 theApp->setIconForFrame (subframe);
2106 m_pFileMenu = new wxMenu;
2108 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2109 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2110 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2111 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2112 m_pFileMenu->Append(wxID_CLOSE, "&Close");
2114 m_pFileMenu->AppendSeparator();
2115 m_pFileMenu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
2117 m_pFileMenu->AppendSeparator();
2118 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2119 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2120 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2121 m_pFileMenu->AppendSeparator();
2122 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import\tCtrl-I...");
2124 m_pFileMenu->AppendSeparator();
2125 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
2126 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2128 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2129 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2131 wxMenu *process_menu = new wxMenu;
2132 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...\tCtrl-R");
2133 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...\tCtrl-J");
2135 wxMenu *help_menu = new wxMenu;
2136 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2137 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
2138 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
2139 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2141 wxMenuBar *menu_bar = new wxMenuBar;
2143 menu_bar->Append(m_pFileMenu, "&File");
2144 menu_bar->Append(process_menu, "&Process");
2145 menu_bar->Append(help_menu, "&Help");
2147 subframe->SetMenuBar(menu_bar);
2148 subframe->Centre(wxBOTH);
2150 wxAcceleratorEntry accelEntries[3];
2151 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('J'), PHMMENU_PROCESS_PROJECTIONS);
2152 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('R'), PHMMENU_PROCESS_RASTERIZE);
2153 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('I'), PHMMENU_FILE_PROPERTIES);
2154 wxAcceleratorTable accelTable (3, accelEntries);
2155 subframe->SetAcceleratorTable (accelTable);
2162 PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2164 m_pFrame = CreateChildFrame(doc, this);
2166 m_pCanvas = CreateCanvas (m_pFrame);
2167 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
2168 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
2170 m_pFrame->SetTitle ("PhantomFileView");
2173 int x, y; // X requires a forced resize
2174 m_pFrame->GetSize(&x, &y);
2175 m_pFrame->SetSize(-1, -1, x, y);
2178 m_pFrame->Show(true);
2185 PhantomFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2188 m_pCanvas->Refresh();
2192 PhantomFileView::OnClose (bool deleteWindow)
2194 //GetDocumentManager()->ActivateView (this, false, true);
2195 if (! GetDocument() || ! GetDocument()->Close())
2200 m_pCanvas->setView(NULL);
2203 wxString s(wxTheApp->GetAppName());
2205 m_pFrame->SetTitle(s);
2212 if (GetDocument() && GetDocument()->getBadFileOpen())
2213 ::wxYield(); // wxWindows bug workaround
2220 PhantomFileView::OnDraw (wxDC* dc)
2223 m_pCanvas->GetClientSize (&xsize, &ysize);
2224 SGPDriver driver (dc, xsize, ysize);
2226 const Phantom& rPhantom = GetDocument()->getPhantom();
2227 sgp.setColor (C_RED);
2228 rPhantom.show (sgp);
2233 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2234 : wxScrolledWindow(frame, -1, pos, size, style)
2239 ProjectionFileCanvas::~ProjectionFileCanvas ()
2245 ProjectionFileCanvas::OnDraw(wxDC& dc)
2248 m_pView->OnDraw(& dc);
2252 ProjectionFileCanvas::GetBestSize () const
2256 Projections& rProj = m_pView->GetDocument()->getProjections();
2257 best.Set (rProj.nDet(), rProj.nView());
2264 // ProjectionFileView
2266 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
2268 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
2269 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
2270 EVT_MENU(PJMENU_RECONSTRUCT_FBP, ProjectionFileView::OnReconstructFBP)
2271 EVT_MENU(PJMENU_RECONSTRUCT_FOURIER, ProjectionFileView::OnReconstructFourier)
2272 EVT_MENU(PJMENU_CONVERT_POLAR, ProjectionFileView::OnConvertPolar)
2273 EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
2276 ProjectionFileView::ProjectionFileView()
2277 : wxView(), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0)
2287 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
2288 m_dDefaultFilterParam = 1.;
2290 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
2291 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
2293 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
2294 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
2296 m_iDefaultZeropad = 1;
2297 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF;
2298 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
2299 m_iDefaultInterpParam = 1;
2300 m_iDefaultTrace = Trace::TRACE_NONE;
2302 m_iDefaultPolarNX = 256;
2303 m_iDefaultPolarNY = 256;
2304 m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR;
2305 m_iDefaultPolarZeropad = 1;
2308 ProjectionFileView::~ProjectionFileView()
2310 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2311 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2315 ProjectionFileView::OnProperties (wxCommandEvent& event)
2317 const Projections& rProj = GetDocument()->getProjections();
2318 std::ostringstream os;
2319 rProj.printScanInfo(os);
2320 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2321 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
2322 dialogMsg.ShowModal();
2327 ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
2329 Projections& rProj = GetDocument()->getProjections();
2330 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2331 m_iDefaultPolarInterpolation, -1);
2332 if (dialogPolar.ShowModal() == wxID_OK) {
2333 wxString strInterpolation (dialogPolar.getInterpolationName());
2334 m_iDefaultPolarNX = dialogPolar.getXSize();
2335 m_iDefaultPolarNY = dialogPolar.getYSize();
2336 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2337 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2338 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2339 if (! rProj.convertPolar (*pIF, m_iDefaultPolarInterpolation)) {
2341 *theApp->getLog() << "Error converting to Polar\n";
2344 pPolarDoc = theApp->newImageDoc ();
2346 sys_error (ERR_SEVERE, "Unable to create image file");
2349 pPolarDoc->setImageFile (pIF);
2350 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2351 std::ostringstream os;
2352 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to polar image: xSize="
2353 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2354 << strInterpolation.c_str();
2355 *theApp->getLog() << os.str().c_str() << "\n";
2356 pIF->labelAdd (os.str().c_str());
2357 if (theApp->getAskDeleteNewDocs())
2358 pPolarDoc->Modify (true);
2359 pPolarDoc->UpdateAllViews ();
2360 pPolarDoc->getView()->OnUpdate (this, NULL);
2361 pPolarDoc->getView()->getFrame()->Show(true);
2366 ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
2368 Projections& rProj = GetDocument()->getProjections();
2369 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert to FFT Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2370 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad);
2371 if (dialogPolar.ShowModal() == wxID_OK) {
2372 wxString strInterpolation (dialogPolar.getInterpolationName());
2373 m_iDefaultPolarNX = dialogPolar.getXSize();
2374 m_iDefaultPolarNY = dialogPolar.getYSize();
2375 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2376 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2378 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2379 if (! rProj.convertFFTPolar (*pIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad)) {
2381 *theApp->getLog() << "Error converting to polar\n";
2384 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2386 sys_error (ERR_SEVERE, "Unable to create image file");
2389 pPolarDoc->setImageFile (pIF);
2390 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2391 std::ostringstream os;
2392 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to FFT polar image: xSize="
2393 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2394 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2395 *theApp->getLog() << os.str().c_str() << "\n";
2396 pIF->labelAdd (os.str().c_str());
2397 if (theApp->getAskDeleteNewDocs())
2398 pPolarDoc->Modify (true);
2399 pPolarDoc->UpdateAllViews ();
2400 pPolarDoc->getView()->OnUpdate (this, NULL);
2401 pPolarDoc->getView()->getFrame()->Show(true);
2406 ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
2408 wxMessageBox ("Fourier Reconstruction is not yet supported", "Unimplemented function");
2412 ProjectionFileView::OnReconstructFBP (wxCommandEvent& event)
2414 DialogGetReconstructionParameters dialogReconstruction (getFrameForChild(), m_iDefaultNX, m_iDefaultNY,
2415 m_iDefaultFilter, m_dDefaultFilterParam, m_iDefaultFilterMethod, m_iDefaultFilterGeneration,
2416 m_iDefaultZeropad, m_iDefaultInterpolation, m_iDefaultInterpParam, m_iDefaultBackprojector,
2419 int retVal = dialogReconstruction.ShowModal();
2420 if (retVal != wxID_OK)
2423 m_iDefaultNX = dialogReconstruction.getXSize();
2424 m_iDefaultNY = dialogReconstruction.getYSize();
2425 wxString optFilterName = dialogReconstruction.getFilterName();
2426 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
2427 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
2428 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
2429 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
2430 m_iDefaultZeropad = dialogReconstruction.getZeropad();
2431 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
2432 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
2433 wxString optInterpName = dialogReconstruction.getInterpName();
2434 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
2435 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
2436 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
2437 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
2438 m_iDefaultTrace = dialogReconstruction.getTrace();
2440 if (m_iDefaultNX <= 0 && m_iDefaultNY <= 0)
2443 const Projections& rProj = GetDocument()->getProjections();
2444 std::ostringstream os;
2445 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();
2448 ImageFile* pImageFile = NULL;
2449 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2450 pImageFile = new ImageFile (m_iDefaultNX, m_iDefaultNY);
2451 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2452 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2453 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace);
2455 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstructor, rProj, *pImageFile, m_iDefaultTrace, getFrameForChild());
2456 for (int iView = 0; iView < rProj.nView(); iView++) {
2458 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView, true)) {
2459 delete pDlgReconstruct;
2460 delete pReconstructor;
2465 while (pDlgReconstruct->isPaused()) {
2470 pReconstructor->postProcessing();
2471 delete pDlgReconstruct;
2472 delete pReconstructor;
2475 if (theApp->getUseBackgroundTasks() || theApp->getNumberCPU() > 1) {
2476 ReconstructorSupervisorThread* pReconstructor = new ReconstructorSupervisorThread (this,
2477 m_iDefaultNX, m_iDefaultNY, optFilterName.c_str(),
2478 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2479 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), os.str().c_str());
2480 if (pReconstructor->Create() != wxTHREAD_NO_ERROR) {
2481 sys_error (ERR_SEVERE, "Error creating reconstructor thread");
2482 delete pReconstructor;
2485 pReconstructor->SetPriority (60);
2486 pReconstructor->Run();
2491 pImageFile = new ImageFile (m_iDefaultNX, m_iDefaultNY);
2492 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2493 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2494 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace);
2496 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2497 for (int iView = 0; iView < rProj.nView(); iView++) {
2498 pReconstructor->reconstructView (iView, 1);
2499 if (! dlgProgress.Update (iView + 1)) {
2500 delete pReconstructor;
2501 return; // don't make new window, thread will do this
2504 pReconstructor->postProcessing();
2505 delete pReconstructor;
2508 ImageFileDocument* pReconDoc = theApp->newImageDoc();
2510 sys_error (ERR_SEVERE, "Unable to create image file");
2513 pReconDoc->setImageFile (pImageFile);
2514 if (theApp->getAskDeleteNewDocs())
2515 pReconDoc->Modify (true);
2516 pReconDoc->UpdateAllViews (this);
2517 if (ImageFileView* rasterView = pReconDoc->getView()) {
2518 rasterView->OnUpdate (rasterView, NULL);
2519 rasterView->getFrame()->SetFocus();
2520 rasterView->getFrame()->Show(true);
2522 *theApp->getLog() << os.str().c_str() << "\n";
2523 pImageFile->labelAdd (rProj.getLabel());
2524 pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd());
2528 ProjectionFileCanvas*
2529 ProjectionFileView::CreateCanvas (wxFrame *parent)
2531 ProjectionFileCanvas* pCanvas;
2533 parent->GetClientSize(&width, &height);
2535 pCanvas = new ProjectionFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
2537 pCanvas->SetScrollbars(20, 20, 50, 50);
2538 pCanvas->SetBackgroundColour(*wxWHITE);
2549 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2552 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2554 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2556 theApp->setIconForFrame (subframe);
2558 m_pFileMenu = new wxMenu;
2560 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2561 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2562 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2563 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2564 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2565 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2567 m_pFileMenu->AppendSeparator();
2568 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
2570 m_pFileMenu->AppendSeparator();
2571 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2572 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2573 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2574 m_pFileMenu->AppendSeparator();
2575 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import\tCtrl-I...");
2577 m_pFileMenu->AppendSeparator();
2578 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
2579 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2581 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2582 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2584 wxMenu *convert_menu = new wxMenu;
2585 convert_menu->Append (PJMENU_CONVERT_POLAR, "&Polar Image...\tCtrl-L");
2586 convert_menu->Append (PJMENU_CONVERT_FFT_POLAR, "&FFT->Polar Image...\tCtrl-M");
2588 wxMenu *reconstruct_menu = new wxMenu;
2589 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP, "&Filtered Backprojection...\tCtrl-R", "Reconstruct image using filtered backprojection");
2590 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Fourier...\tCtrl-E", "Reconstruct image using inverse Fourier");
2591 reconstruct_menu->Enable (PJMENU_RECONSTRUCT_FOURIER, false);
2593 wxMenu *help_menu = new wxMenu;
2594 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2595 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
2596 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
2597 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2599 wxMenuBar *menu_bar = new wxMenuBar;
2601 menu_bar->Append (m_pFileMenu, "&File");
2602 menu_bar->Append (convert_menu, "&Convert");
2603 menu_bar->Append (reconstruct_menu, "&Reconstruct");
2604 menu_bar->Append (help_menu, "&Help");
2606 subframe->SetMenuBar(menu_bar);
2607 subframe->Centre(wxBOTH);
2609 wxAcceleratorEntry accelEntries[5];
2610 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('L'), PJMENU_CONVERT_POLAR);
2611 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('M'), PJMENU_CONVERT_FFT_POLAR);
2612 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('R'), PJMENU_RECONSTRUCT_FBP);
2613 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('E'), PJMENU_RECONSTRUCT_FOURIER);
2614 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('I'), PJMENU_FILE_PROPERTIES);
2615 wxAcceleratorTable accelTable (5, accelEntries);
2616 subframe->SetAcceleratorTable (accelTable);
2623 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2625 m_pFrame = CreateChildFrame(doc, this);
2629 m_pFrame->GetClientSize (&width, &height);
2630 m_pFrame->SetTitle ("ProjectionFileView");
2631 m_pCanvas = CreateCanvas (m_pFrame);
2634 int x, y; // X requires a forced resize
2635 m_pFrame->GetSize(&x, &y);
2636 m_pFrame->SetSize(-1, -1, x, y);
2639 m_pFrame->Show(true);
2646 ProjectionFileView::OnDraw (wxDC* dc)
2648 wxSize clientSize = m_pFrame->GetClientSize();
2649 wxSize bestSize = m_pCanvas->GetBestSize();
2651 if (clientSize.x > bestSize.x || clientSize.y > bestSize.y)
2652 m_pFrame->SetClientSize (bestSize);
2655 dc->DrawBitmap (m_bitmap, 0, 0, false);
2660 ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2662 const Projections& rProj = GetDocument()->getProjections();
2663 const int nDet = rProj.nDet();
2664 const int nView = rProj.nView();
2665 if (nDet != 0 && nView != 0) {
2666 const DetectorArray& detarray = rProj.getDetectorArray(0);
2667 const DetectorValue* detval = detarray.detValues();
2668 double min = detval[0];
2669 double max = detval[0];
2670 for (int iy = 0; iy < nView; iy++) {
2671 const DetectorArray& detarray = rProj.getDetectorArray(iy);
2672 const DetectorValue* detval = detarray.detValues();
2673 for (int ix = 0; ix < nDet; ix++) {
2674 if (min > detval[ix])
2676 else if (max < detval[ix])
2681 unsigned char* imageData = new unsigned char [nDet * nView * 3];
2683 sys_error (ERR_SEVERE, "Unable to allocate memory for image display");
2686 double scale = (max - min) / 255;
2687 for (int iy2 = 0; iy2 < nView; iy2++) {
2688 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
2689 const DetectorValue* detval = detarray.detValues();
2690 for (int ix = 0; ix < nDet; ix++) {
2691 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
2692 intensity = clamp(intensity, 0, 255);
2693 int baseAddr = (iy2 * nDet + ix) * 3;
2694 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
2697 wxImage image (nDet, nView, imageData, true);
2698 m_bitmap = image.ConvertToBitmap();
2702 xSize = clamp (xSize, 0, 800);
2703 ySize = clamp (ySize, 0, 800);
2704 m_pFrame->SetClientSize (xSize, ySize);
2705 m_pCanvas->SetScrollbars (20, 20, nDet/20, nView/20);
2709 m_pCanvas->Refresh();
2713 ProjectionFileView::OnClose (bool deleteWindow)
2715 //GetDocumentManager()->ActivateView (this, false, true);
2716 if (! GetDocument() || ! GetDocument()->Close())
2721 m_pCanvas->setView(NULL);
2724 wxString s(wxTheApp->GetAppName());
2726 m_pFrame->SetTitle(s);
2733 if (GetDocument() && GetDocument()->getBadFileOpen())
2734 ::wxYield(); // wxWindows bug workaround
2743 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2744 : wxScrolledWindow(frame, -1, pos, size, style)
2749 PlotFileCanvas::~PlotFileCanvas ()
2755 PlotFileCanvas::OnDraw(wxDC& dc)
2758 m_pView->OnDraw(& dc);
2764 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
2766 BEGIN_EVENT_TABLE(PlotFileView, wxView)
2767 EVT_MENU(PLOTMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
2768 EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
2769 EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
2770 EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
2773 PlotFileView::PlotFileView()
2774 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pEZPlot(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
2778 PlotFileView::~PlotFileView()
2783 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2787 PlotFileView::OnProperties (wxCommandEvent& event)
2789 const PlotFile& rPlot = GetDocument()->getPlotFile();
2790 std::ostringstream os;
2791 os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
2792 rPlot.printHeadersBrief (os);
2793 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<<\n";
2794 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
2795 dialogMsg.ShowModal();
2800 PlotFileView::OnScaleAuto (wxCommandEvent& event)
2802 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2803 double min, max, mean, mode, median, stddev;
2804 rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
2805 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
2806 int iRetVal = dialogAutoScale.ShowModal();
2807 if (iRetVal == wxID_OK) {
2808 m_bMinSpecified = true;
2809 m_bMaxSpecified = true;
2811 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
2814 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
2815 OnUpdate (this, NULL);
2821 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
2823 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2827 if (! m_bMinSpecified || ! m_bMaxSpecified) {
2828 if (! rPlotFile.getMinMax (1, min, max)) {
2829 *theApp->getLog() << "Error: unable to find Min/Max\n";
2834 if (m_bMinSpecified)
2836 if (m_bMaxSpecified)
2839 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Y-axis Minimum & Maximum", min, max);
2840 int retVal = dialogMinMax.ShowModal();
2841 if (retVal == wxID_OK) {
2842 m_bMinSpecified = true;
2843 m_bMaxSpecified = true;
2844 m_dMinPixel = dialogMinMax.getMinimum();
2845 m_dMaxPixel = dialogMinMax.getMaximum();
2846 OnUpdate (this, NULL);
2851 PlotFileView::OnScaleFull (wxCommandEvent& event)
2853 if (m_bMinSpecified || m_bMaxSpecified) {
2854 m_bMinSpecified = false;
2855 m_bMaxSpecified = false;
2856 OnUpdate (this, NULL);
2862 PlotFileView::CreateCanvas (wxFrame* parent)
2864 PlotFileCanvas* pCanvas;
2866 parent->GetClientSize(&width, &height);
2868 pCanvas = new PlotFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
2870 pCanvas->SetBackgroundColour(*wxWHITE);
2881 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2884 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2886 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2888 theApp->setIconForFrame (subframe);
2890 m_pFileMenu = new wxMenu;
2892 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2893 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2894 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2895 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2896 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2897 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2899 m_pFileMenu->AppendSeparator();
2900 m_pFileMenu->Append(PLOTMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
2902 m_pFileMenu->AppendSeparator();
2903 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2904 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2905 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2906 m_pFileMenu->AppendSeparator();
2907 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import\tCtrl-I...");
2909 m_pFileMenu->AppendSeparator();
2910 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
2911 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2913 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2914 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2916 wxMenu *view_menu = new wxMenu;
2917 view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...\tCtrl-E");
2918 view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
2919 view_menu->Append(PLOTMENU_VIEW_SCALE_FULL, "Display &Full Scale\tCtrl-U");
2921 wxMenu *help_menu = new wxMenu;
2922 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2923 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
2924 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
2925 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2927 wxMenuBar *menu_bar = new wxMenuBar;
2929 menu_bar->Append(m_pFileMenu, "&File");
2930 menu_bar->Append(view_menu, "&View");
2931 menu_bar->Append(help_menu, "&Help");
2933 subframe->SetMenuBar(menu_bar);
2934 subframe->Centre(wxBOTH);
2936 wxAcceleratorEntry accelEntries[4];
2937 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('E'), PLOTMENU_VIEW_SCALE_MINMAX);
2938 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('A'), PLOTMENU_VIEW_SCALE_AUTO);
2939 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('U'), PLOTMENU_VIEW_SCALE_FULL);
2940 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), PLOTMENU_FILE_PROPERTIES);
2941 wxAcceleratorTable accelTable (4, accelEntries);
2942 subframe->SetAcceleratorTable (accelTable);
2949 PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
2951 m_pFrame = CreateChildFrame(doc, this);
2954 m_bMinSpecified = false;
2955 m_bMaxSpecified = false;
2956 m_dAutoScaleFactor = 1.;
2959 m_pFrame->GetClientSize(&width, &height);
2960 m_pFrame->SetTitle ("Plot File");
2961 m_pCanvas = CreateCanvas (m_pFrame);
2964 int x, y; // X requires a forced resize
2965 m_pFrame->GetSize(&x, &y);
2966 m_pFrame->SetSize(-1, -1, x, y);
2969 m_pFrame->Show(true);
2976 PlotFileView::OnDraw (wxDC* dc)
2978 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2979 const int iNColumns = rPlotFile.getNumColumns();
2980 const int iNRecords = rPlotFile.getNumRecords();
2982 if (iNColumns > 0 && iNRecords > 0) {
2984 m_pCanvas->GetClientSize (&xsize, &ysize);
2985 SGPDriver driver (dc, xsize, ysize);
2988 m_pEZPlot->plot (&sgp);
2994 PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2996 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2997 const int iNColumns = rPlotFile.getNumColumns();
2998 const int iNRecords = rPlotFile.getNumRecords();
3000 if (iNColumns > 0 && iNRecords > 0) {
3003 m_pEZPlot = new EZPlot;
3005 for (unsigned int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)
3006 m_pEZPlot->ezset (rPlotFile.getEzsetCommand (iEzset));
3008 if (m_bMinSpecified) {
3009 std::ostringstream os;
3010 os << "ymin " << m_dMinPixel;
3011 m_pEZPlot->ezset (os.str());
3014 if (m_bMaxSpecified) {
3015 std::ostringstream os;
3016 os << "ymax " << m_dMaxPixel;
3017 m_pEZPlot->ezset (os.str());
3020 m_pEZPlot->ezset("box");
3021 m_pEZPlot->ezset("grid");
3023 double* pdXaxis = new double [iNRecords];
3024 rPlotFile.getColumn (0, pdXaxis);
3026 double* pdY = new double [iNRecords];
3027 for (int iCol = 1; iCol < iNColumns; iCol++) {
3028 rPlotFile.getColumn (iCol, pdY);
3029 m_pEZPlot->addCurve (pdXaxis, pdY, iNRecords);
3037 m_pCanvas->Refresh();
3041 PlotFileView::OnClose (bool deleteWindow)
3043 //GetDocumentManager()->ActivateView (this, false, true);
3044 if (! GetDocument() || ! GetDocument()->Close())
3049 m_pCanvas->setView (NULL);
3052 wxString s(wxTheApp->GetAppName());
3054 m_pFrame->SetTitle(s);
3060 if (GetDocument() && GetDocument()->getBadFileOpen())
3061 ::wxYield(); // wxWindows bug workaround
3068 ////////////////////////////////////////////////////////////////
3071 IMPLEMENT_DYNAMIC_CLASS(TextFileView, wxView)
3073 TextFileView::~TextFileView()
3075 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
3076 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
3079 bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
3081 m_pFrame = CreateChildFrame(doc, this);
3082 SetFrame (m_pFrame);
3085 m_pFrame->GetClientSize(&width, &height);
3086 m_pFrame->SetTitle("TextFile");
3087 m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
3088 m_pFrame->SetTitle("Log");
3091 // X seems to require a forced resize
3093 frame->GetSize(&x, &y);
3094 frame->SetSize(-1, -1, x, y);
3097 m_pFrame->Show (true);
3103 // Handled by wxTextWindow
3104 void TextFileView::OnDraw(wxDC *WXUNUSED(dc) )
3108 void TextFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3113 TextFileView::OnClose (bool deleteWindow)
3115 if (! theApp->getMainFrame()->getShuttingDown())
3119 //GetDocumentManager()->ActivateView (this, false, true);
3120 if (! GetDocument() || ! GetDocument()->Close())
3127 if (GetDocument() && GetDocument()->getBadFileOpen())
3128 ::wxYield(); // wxWindows bug workaround
3139 TextFileView::CreateChildFrame (wxDocument *doc, wxView *view)
3142 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(0,0), wxDEFAULT_FRAME_STYLE, "Log");
3144 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE, "Log");
3146 theApp->setIconForFrame (subframe);
3148 m_pFileMenu = new wxMenu;
3150 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3151 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3152 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3153 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3154 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3155 // m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3157 m_pFileMenu->AppendSeparator();
3158 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3159 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3160 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3161 m_pFileMenu->AppendSeparator();
3162 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import\tCtrl-I...");
3164 m_pFileMenu->AppendSeparator();
3165 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3166 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3168 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3169 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3171 wxMenu *help_menu = new wxMenu;
3172 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3173 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3174 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3175 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3177 wxMenuBar *menu_bar = new wxMenuBar;
3179 menu_bar->Append(m_pFileMenu, "&File");
3180 menu_bar->Append(help_menu, "&Help");
3182 subframe->SetMenuBar(menu_bar);
3183 subframe->Centre(wxBOTH);
3189 // Define a constructor for my text subwindow
3190 TextFileCanvas::TextFileCanvas (TextFileView* v, wxFrame* frame, const wxPoint& pos, const wxSize& size, long style)
3191 : wxTextCtrl (frame, -1, "", pos, size, style), m_pView(v)
3195 TextFileCanvas::~TextFileCanvas ()