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.112 2001/02/22 11:05:38 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 "threadrecon.h"
52 #define CTSIM_THREADS 1
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)
122 wxPoint pt(event.GetLogicalPosition(dc));
124 const ImageFileDocument* pIFDoc = m_pView->GetDocument();
127 const ImageFile& rIF = pIFDoc->getImageFile();
128 ImageFileArrayConst v = rIF.getArray();
131 const int yPt = ny - 1 - pt.y;
132 if (event.RightIsDown()) {
133 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
134 std::ostringstream os;
135 os << "Image value (" << pt.x << "," << yPt << ") = " << v[pt.x][yPt];
136 if (rIF.isComplex()) {
137 double dImag = rIF.getImaginaryArray()[pt.x][yPt];
139 os << " - " << -dImag;
141 os << " + " << dImag;
145 *theApp->getLog() << os.str().c_str();
147 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
149 else if (event.LeftIsDown() || event.LeftUp() || event.RightUp()) {
150 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
151 if (m_xCursor >= 0 && m_yCursor >= 0) {
152 DrawRubberBandCursor (dc, m_xCursor, m_yCursor);
154 DrawRubberBandCursor (dc, pt.x, yPt);
157 wxMenu* pMenu = m_pView->getMenuAnalyze();
158 if (pMenu && ! pMenu->IsEnabled(IFMENU_PLOT_ROW)) {
159 pMenu->Enable (IFMENU_PLOT_ROW, true);
160 pMenu->Enable (IFMENU_PLOT_COL, true);
161 pMenu->Enable (IFMENU_COMPARE_ROW, true);
162 pMenu->Enable (IFMENU_COMPARE_COL, true);
163 pMenu->Enable (IFMENU_PLOT_FFT_ROW, true);
164 pMenu->Enable (IFMENU_PLOT_FFT_COL, true);
167 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
169 if (event.LeftUp()) {
170 std::ostringstream os;
171 os << "Selected column " << pt.x << " , row " << yPt << "\n";
172 *theApp->getLog() << os.str().c_str();
177 ImageFileCanvas::OnChar (wxKeyEvent& event)
179 if (event.GetKeyCode() == WXK_ESCAPE) {
183 m_pView->OnUpdate (NULL);
185 wxScrolledWindow::OnChar (event);
189 ImageFileCanvas::GetBestSize() const
194 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
195 return wxSize (rIF.nx(), rIF.ny());
201 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
203 BEGIN_EVENT_TABLE(ImageFileView, wxView)
204 EVT_MENU(IFMENU_FILE_EXPORT, ImageFileView::OnExport)
205 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
206 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
207 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
208 EVT_MENU(IFMENU_VIEW_SCALE_FULL, ImageFileView::OnScaleFull)
209 EVT_MENU(IFMENU_COMPARE_IMAGES, ImageFileView::OnCompare)
210 EVT_MENU(IFMENU_COMPARE_ROW, ImageFileView::OnCompareRow)
211 EVT_MENU(IFMENU_COMPARE_COL, ImageFileView::OnCompareCol)
212 EVT_MENU(IFMENU_FILTER_INVERTVALUES, ImageFileView::OnInvertValues)
213 EVT_MENU(IFMENU_FILTER_SQUARE, ImageFileView::OnSquare)
214 EVT_MENU(IFMENU_FILTER_SQRT, ImageFileView::OnSquareRoot)
215 EVT_MENU(IFMENU_FILTER_LOG, ImageFileView::OnLog)
216 EVT_MENU(IFMENU_FILTER_EXP, ImageFileView::OnExp)
217 EVT_MENU(IFMENU_FILTER_FOURIER, ImageFileView::OnFourier)
218 EVT_MENU(IFMENU_FILTER_INVERSE_FOURIER, ImageFileView::OnInverseFourier)
219 EVT_MENU(IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, ImageFileView::OnShuffleFourierToNaturalOrder)
220 EVT_MENU(IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, ImageFileView::OnShuffleNaturalToFourierOrder)
221 EVT_MENU(IFMENU_IMAGE_ADD, ImageFileView::OnAdd)
222 EVT_MENU(IFMENU_IMAGE_SUBTRACT, ImageFileView::OnSubtract)
223 EVT_MENU(IFMENU_IMAGE_MULTIPLY, ImageFileView::OnMultiply)
224 EVT_MENU(IFMENU_IMAGE_DIVIDE, ImageFileView::OnDivide)
225 EVT_MENU(IFMENU_IMAGE_SCALESIZE, ImageFileView::OnScaleSize)
227 EVT_MENU(IFMENU_IMAGE_CONVERT3D, ImageFileView::OnConvert3d)
230 EVT_MENU(IFMENU_FILTER_FFT, ImageFileView::OnFFT)
231 EVT_MENU(IFMENU_FILTER_IFFT, ImageFileView::OnIFFT)
232 EVT_MENU(IFMENU_FILTER_FFT_ROWS, ImageFileView::OnFFTRows)
233 EVT_MENU(IFMENU_FILTER_IFFT_ROWS, ImageFileView::OnIFFTRows)
234 EVT_MENU(IFMENU_FILTER_FFT_COLS, ImageFileView::OnFFTCols)
235 EVT_MENU(IFMENU_FILTER_IFFT_COLS, ImageFileView::OnIFFTCols)
237 EVT_MENU(IFMENU_FILTER_MAGNITUDE, ImageFileView::OnMagnitude)
238 EVT_MENU(IFMENU_FILTER_PHASE, ImageFileView::OnPhase)
239 EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)
240 EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol)
242 EVT_MENU(IFMENU_PLOT_FFT_ROW, ImageFileView::OnPlotFFTRow)
243 EVT_MENU(IFMENU_PLOT_FFT_COL, ImageFileView::OnPlotFFTCol)
245 EVT_MENU(IFMENU_PLOT_HISTOGRAM, ImageFileView::OnPlotHistogram)
248 ImageFileView::ImageFileView()
249 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
251 m_iDefaultExportFormatID = ImageFile::FORMAT_PNG;
254 ImageFileView::~ImageFileView()
256 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
257 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
262 ImageFileView::OnProperties (wxCommandEvent& event)
264 const ImageFile& rIF = GetDocument()->getImageFile();
265 if (rIF.nx() == 0 || rIF.ny() == 0)
266 *theApp->getLog() << "Properties: empty imagefile\n";
268 const std::string rFilename = m_pFrame->GetTitle().c_str();
269 std::ostringstream os;
270 double min, max, mean, mode, median, stddev;
271 rIF.statistics (rIF.getArray(), min, max, mean, mode, median, stddev);
272 os << "Filename: " << rFilename << "\n";
273 os << "Size: (" << rIF.nx() << "," << rIF.ny() << ")\n";
279 os << "Minimum: "<<min<<"\nMaximum: "<<max<<"\nMean: "<<mean<<"\nMedian: "<<median<<"\nMode: "<<mode<<"\nStandard Deviation: "<<stddev << "\n";
280 if (rIF.isComplex()) {
281 rIF.statistics (rIF.getImaginaryArray(), min, max, mean, mode, median, stddev);
282 os << "Imaginary: min: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
284 if (rIF.nLabels() > 0) {
285 rIF.printLabelsBrief (os);
287 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
288 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
289 dialogMsg.ShowModal();
294 ImageFileView::OnScaleAuto (wxCommandEvent& event)
296 const ImageFile& rIF = GetDocument()->getImageFile();
297 double min, max, mean, mode, median, stddev;
298 rIF.statistics(min, max, mean, mode, median, stddev);
299 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
300 int iRetVal = dialogAutoScale.ShowModal();
301 if (iRetVal == wxID_OK) {
302 m_bMinSpecified = true;
303 m_bMaxSpecified = true;
305 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
308 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
309 OnUpdate (this, NULL);
315 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
317 const ImageFile& rIF = GetDocument()->getImageFile();
319 if (! m_bMinSpecified && ! m_bMaxSpecified)
320 rIF.getMinMax (min, max);
327 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Image Minimum & Maximum", min, max);
328 int retVal = dialogMinMax.ShowModal();
329 if (retVal == wxID_OK) {
330 m_bMinSpecified = true;
331 m_bMaxSpecified = true;
332 m_dMinPixel = dialogMinMax.getMinimum();
333 m_dMaxPixel = dialogMinMax.getMaximum();
334 OnUpdate (this, NULL);
339 ImageFileView::OnScaleFull (wxCommandEvent& event)
341 if (m_bMinSpecified || m_bMaxSpecified) {
342 m_bMinSpecified = false;
343 m_bMaxSpecified = false;
344 OnUpdate (this, NULL);
349 ImageFileView::OnCompare (wxCommandEvent& event)
351 std::vector<ImageFileDocument*> vecIF;
352 theApp->getCompatibleImages (GetDocument(), vecIF);
354 if (vecIF.size() == 0) {
355 wxMessageBox("There are no compatible image files open for comparision", "No comparison images");
357 DialogGetComparisonImage dialogGetCompare(getFrameForChild(), "Get Comparison Image", vecIF, true);
359 if (dialogGetCompare.ShowModal() == wxID_OK) {
360 const ImageFile& rIF = GetDocument()->getImageFile();
361 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
362 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
363 std::ostringstream os;
364 double min, max, mean, mode, median, stddev;
365 rIF.statistics (min, max, mean, mode, median, stddev);
366 os << GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
367 rCompareIF.statistics (min, max, mean, mode, median, stddev);
368 os << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
370 rIF.comparativeStatistics (rCompareIF, d, r, e);
371 os << "Comparative Statistics: d=" << d << ", r=" << r << ", e=" << e << "\n";
372 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
373 if (dialogGetCompare.getMakeDifferenceImage()) {
374 ImageFile* pDifferenceImage = new ImageFile;
376 pDifferenceImage->setArraySize (rIF.nx(), rIF.ny());
377 if (! rIF.subtractImages (rCompareIF, *pDifferenceImage)) {
378 *theApp->getLog() << "Unable to subtract images\n";
379 delete pDifferenceImage;
382 ImageFileDocument* pDifferenceDoc = theApp->newImageDoc();
383 if (! pDifferenceDoc) {
384 sys_error (ERR_SEVERE, "Unable to create image file");
387 pDifferenceDoc->setImageFile (pDifferenceImage);
389 wxString s = GetFrame()->GetTitle() + ": ";
390 pDifferenceImage->labelsCopy (rIF, s.c_str());
391 s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
392 pDifferenceImage->labelsCopy (rCompareIF, s.c_str());
393 std::ostringstream osLabel;
394 osLabel << "Compare image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str()
395 << " and " << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": "
397 pDifferenceImage->labelAdd (os.str().c_str());
398 if (theApp->getAskDeleteNewDocs())
399 pDifferenceDoc->Modify (true);
400 pDifferenceDoc->UpdateAllViews (this);
401 pDifferenceDoc->getView()->OnUpdate (this, NULL);
402 pDifferenceDoc->getView()->getFrame()->Show(true);
404 wxMessageBox(os.str().c_str(), "Image Comparison");
410 ImageFileView::OnInvertValues (wxCommandEvent& event)
412 ImageFile& rIF = GetDocument()->getImageFile();
413 rIF.invertPixelValues (rIF);
414 rIF.labelAdd ("Invert Pixel Values");
415 if (theApp->getAskDeleteNewDocs())
416 GetDocument()->Modify (true);
417 GetDocument()->UpdateAllViews (this);
421 ImageFileView::OnSquare (wxCommandEvent& event)
423 ImageFile& rIF = GetDocument()->getImageFile();
425 rIF.labelAdd ("Square Pixel Values");
426 if (theApp->getAskDeleteNewDocs())
427 GetDocument()->Modify (true);
428 GetDocument()->UpdateAllViews (this);
432 ImageFileView::OnSquareRoot (wxCommandEvent& event)
434 ImageFile& rIF = GetDocument()->getImageFile();
436 rIF.labelAdd ("Square-root Pixel Values");
437 if (theApp->getAskDeleteNewDocs())
438 GetDocument()->Modify (true);
439 GetDocument()->UpdateAllViews (this);
443 ImageFileView::OnLog (wxCommandEvent& event)
445 ImageFile& rIF = GetDocument()->getImageFile();
447 rIF.labelAdd ("Logrithm base-e Pixel Values");
448 if (theApp->getAskDeleteNewDocs())
449 GetDocument()->Modify (true);
450 GetDocument()->UpdateAllViews (this);
454 ImageFileView::OnExp (wxCommandEvent& event)
456 ImageFile& rIF = GetDocument()->getImageFile();
458 rIF.labelAdd ("Exponent base-e Pixel Values");
459 if (theApp->getAskDeleteNewDocs())
460 GetDocument()->Modify (true);
461 GetDocument()->UpdateAllViews (this);
465 ImageFileView::OnAdd (wxCommandEvent& event)
467 std::vector<ImageFileDocument*> vecIF;
468 theApp->getCompatibleImages (GetDocument(), vecIF);
470 if (vecIF.size() == 0) {
471 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
473 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Add", vecIF, false);
475 if (dialogGetCompare.ShowModal() == wxID_OK) {
476 ImageFile& rIF = GetDocument()->getImageFile();
477 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
478 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
479 ImageFileDocument* pNewDoc = theApp->newImageDoc();
481 sys_error (ERR_SEVERE, "Unable to create image file");
484 ImageFile& newImage = pNewDoc->getImageFile();
485 newImage.setArraySize (rIF.nx(), rIF.ny());
486 rIF.addImages (rRHSIF, newImage);
487 std::ostringstream os;
488 os << "Add image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
489 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
490 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
491 newImage.labelsCopy (rIF, s.c_str());
492 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
493 newImage.labelsCopy (rRHSIF, s.c_str());
494 newImage.labelAdd (os.str().c_str());
495 *theApp->getLog() << os.str().c_str() << "\n";
496 if (theApp->getAskDeleteNewDocs())
497 pNewDoc->Modify (true);
498 pNewDoc->UpdateAllViews (this);
499 pNewDoc->getView()->OnUpdate (this, NULL);
500 pNewDoc->getView()->getFrame()->Show(true);
506 ImageFileView::OnSubtract (wxCommandEvent& event)
508 std::vector<ImageFileDocument*> vecIF;
509 theApp->getCompatibleImages (GetDocument(), vecIF);
511 if (vecIF.size() == 0) {
512 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
514 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Subtract", vecIF, false);
516 if (dialogGetCompare.ShowModal() == wxID_OK) {
517 ImageFile& rIF = GetDocument()->getImageFile();
518 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
519 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
520 ImageFileDocument* pNewDoc = theApp->newImageDoc();
522 sys_error (ERR_SEVERE, "Unable to create image file");
525 ImageFile& newImage = pNewDoc->getImageFile();
526 newImage.setArraySize (rIF.nx(), rIF.ny());
527 rIF.subtractImages (rRHSIF, newImage);
528 std::ostringstream os;
529 os << "Subtract image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
530 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
531 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
532 newImage.labelsCopy (rIF, s.c_str());
533 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
534 newImage.labelsCopy (rRHSIF, s.c_str());
535 newImage.labelAdd (os.str().c_str());
536 *theApp->getLog() << os.str().c_str() << "\n";
537 if (theApp->getAskDeleteNewDocs())
538 pNewDoc->Modify (true);
539 pNewDoc->UpdateAllViews (this);
540 pNewDoc->getView()->OnUpdate (this, NULL);
541 pNewDoc->getView()->getFrame()->Show(true);
547 ImageFileView::OnMultiply (wxCommandEvent& event)
549 std::vector<ImageFileDocument*> vecIF;
550 theApp->getCompatibleImages (GetDocument(), vecIF);
552 if (vecIF.size() == 0) {
553 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
555 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Multiply", vecIF, false);
557 if (dialogGetCompare.ShowModal() == wxID_OK) {
558 ImageFile& rIF = GetDocument()->getImageFile();
559 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
560 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
561 ImageFileDocument* pNewDoc = theApp->newImageDoc();
563 sys_error (ERR_SEVERE, "Unable to create image file");
566 ImageFile& newImage = pNewDoc->getImageFile();
567 newImage.setArraySize (rIF.nx(), rIF.ny());
568 rIF.multiplyImages (rRHSIF, newImage);
569 std::ostringstream os;
570 os << "Multiply image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
571 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
572 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
573 newImage.labelsCopy (rIF, s.c_str());
574 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
575 newImage.labelsCopy (rRHSIF, s.c_str());
576 newImage.labelAdd (os.str().c_str());
577 *theApp->getLog() << os.str().c_str() << "\n";
578 if (theApp->getAskDeleteNewDocs())
579 pNewDoc->Modify (true);
580 pNewDoc->UpdateAllViews (this);
581 pNewDoc->getView()->OnUpdate (this, NULL);
582 pNewDoc->getView()->getFrame()->Show(true);
588 ImageFileView::OnDivide (wxCommandEvent& event)
590 std::vector<ImageFileDocument*> vecIF;
591 theApp->getCompatibleImages (GetDocument(), vecIF);
593 if (vecIF.size() == 0) {
594 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
596 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Divide", vecIF, false);
598 if (dialogGetCompare.ShowModal() == wxID_OK) {
599 ImageFile& rIF = GetDocument()->getImageFile();
600 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
601 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
602 ImageFileDocument* pNewDoc = theApp->newImageDoc();
604 sys_error (ERR_SEVERE, "Unable to create image file");
607 ImageFile& newImage = pNewDoc->getImageFile();
608 newImage.setArraySize (rIF.nx(), rIF.ny());
609 rIF.divideImages (rRHSIF, newImage);
610 std::ostringstream os;
611 os << "Divide image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " by "
612 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
613 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
614 newImage.labelsCopy (rIF, s.c_str());
615 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
616 newImage.labelsCopy (rRHSIF, s.c_str());
617 newImage.labelAdd (os.str().c_str());
618 *theApp->getLog() << os.str().c_str() << "\n";
619 if (theApp->getAskDeleteNewDocs())
620 pNewDoc->Modify (true);
621 pNewDoc->UpdateAllViews (this);
622 pNewDoc->getView()->OnUpdate (this, NULL);
623 pNewDoc->getView()->getFrame()->Show(true);
631 ImageFileView::OnFFT (wxCommandEvent& event)
633 ImageFile& rIF = GetDocument()->getImageFile();
635 rIF.labelAdd ("FFT Image");
636 m_bMinSpecified = false;
637 m_bMaxSpecified = false;
638 if (theApp->getAskDeleteNewDocs())
639 GetDocument()->Modify (true);
640 GetDocument()->UpdateAllViews (this);
644 ImageFileView::OnIFFT (wxCommandEvent& event)
646 ImageFile& rIF = GetDocument()->getImageFile();
648 rIF.labelAdd ("IFFT Image");
649 m_bMinSpecified = false;
650 m_bMaxSpecified = false;
651 if (theApp->getAskDeleteNewDocs())
652 GetDocument()->Modify (true);
653 GetDocument()->UpdateAllViews (this);
657 ImageFileView::OnFFTRows (wxCommandEvent& event)
659 ImageFile& rIF = GetDocument()->getImageFile();
661 rIF.labelAdd ("FFT Rows");
662 m_bMinSpecified = false;
663 m_bMaxSpecified = false;
664 if (theApp->getAskDeleteNewDocs())
665 GetDocument()->Modify (true);
666 GetDocument()->UpdateAllViews (this);
670 ImageFileView::OnIFFTRows (wxCommandEvent& event)
672 ImageFile& rIF = GetDocument()->getImageFile();
674 rIF.labelAdd ("IFFT Rows");
675 m_bMinSpecified = false;
676 m_bMaxSpecified = false;
677 if (theApp->getAskDeleteNewDocs())
678 GetDocument()->Modify (true);
679 GetDocument()->UpdateAllViews (this);
683 ImageFileView::OnFFTCols (wxCommandEvent& event)
685 ImageFile& rIF = GetDocument()->getImageFile();
687 rIF.labelAdd ("FFT Columns");
688 m_bMinSpecified = false;
689 m_bMaxSpecified = false;
690 if (theApp->getAskDeleteNewDocs())
691 GetDocument()->Modify (true);
692 GetDocument()->UpdateAllViews (this);
696 ImageFileView::OnIFFTCols (wxCommandEvent& event)
698 ImageFile& rIF = GetDocument()->getImageFile();
700 rIF.labelAdd ("IFFT Columns");
701 m_bMinSpecified = false;
702 m_bMaxSpecified = false;
703 if (theApp->getAskDeleteNewDocs())
704 GetDocument()->Modify (true);
705 GetDocument()->UpdateAllViews (this);
710 ImageFileView::OnFourier (wxCommandEvent& event)
712 ImageFile& rIF = GetDocument()->getImageFile();
713 wxProgressDialog dlgProgress (wxString("Fourier"), wxString("Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
715 rIF.labelAdd ("Fourier Image");
716 m_bMinSpecified = false;
717 m_bMaxSpecified = false;
718 if (theApp->getAskDeleteNewDocs())
719 GetDocument()->Modify (true);
720 GetDocument()->UpdateAllViews (this);
724 ImageFileView::OnInverseFourier (wxCommandEvent& event)
726 ImageFile& rIF = GetDocument()->getImageFile();
727 wxProgressDialog dlgProgress (wxString("Inverse Fourier"), wxString("Inverse Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
728 rIF.inverseFourier (rIF);
729 rIF.labelAdd ("Inverse Fourier Image");
730 m_bMinSpecified = false;
731 m_bMaxSpecified = false;
732 if (theApp->getAskDeleteNewDocs())
733 GetDocument()->Modify (true);
734 GetDocument()->UpdateAllViews (this);
738 ImageFileView::OnShuffleNaturalToFourierOrder (wxCommandEvent& event)
740 ImageFile& rIF = GetDocument()->getImageFile();
741 Fourier::shuffleNaturalToFourierOrder (rIF);
742 rIF.labelAdd ("Shuffle Natural To Fourier Order");
743 m_bMinSpecified = false;
744 m_bMaxSpecified = false;
745 if (theApp->getAskDeleteNewDocs())
746 GetDocument()->Modify (true);
747 GetDocument()->UpdateAllViews (this);
751 ImageFileView::OnShuffleFourierToNaturalOrder (wxCommandEvent& event)
753 ImageFile& rIF = GetDocument()->getImageFile();
754 Fourier::shuffleFourierToNaturalOrder (rIF);
755 rIF.labelAdd ("Shuffle Fourier To Natural Order");
756 m_bMinSpecified = false;
757 m_bMaxSpecified = false;
758 if (theApp->getAskDeleteNewDocs())
759 GetDocument()->Modify (true);
760 GetDocument()->UpdateAllViews (this);
764 ImageFileView::OnMagnitude (wxCommandEvent& event)
766 ImageFile& rIF = GetDocument()->getImageFile();
767 if (rIF.isComplex()) {
769 rIF.labelAdd ("Magnitude of complex-image");
770 m_bMinSpecified = false;
771 m_bMaxSpecified = false;
772 if (theApp->getAskDeleteNewDocs())
773 GetDocument()->Modify (true);
774 GetDocument()->UpdateAllViews (this);
779 ImageFileView::OnPhase (wxCommandEvent& event)
781 ImageFile& rIF = GetDocument()->getImageFile();
782 if (rIF.isComplex()) {
784 rIF.labelAdd ("Phase of complex-image");
785 m_bMinSpecified = false;
786 m_bMaxSpecified = false;
787 if (theApp->getAskDeleteNewDocs())
788 GetDocument()->Modify (true);
789 GetDocument()->UpdateAllViews (this);
795 ImageFileView::CreateCanvas (wxFrame* parent)
797 ImageFileCanvas* pCanvas;
799 parent->GetClientSize(&width, &height);
801 pCanvas = new ImageFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
803 pCanvas->SetScrollbars(20, 20, 50, 50);
804 pCanvas->SetBackgroundColour(*wxWHITE);
815 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
818 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
820 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
822 theApp->setIconForFrame (subframe);
824 m_pFileMenu = new wxMenu;
826 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
827 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
828 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
829 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
830 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
831 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
832 m_pFileMenu->Append(wxID_REVERT, "Re&vert");
834 m_pFileMenu->AppendSeparator();
835 m_pFileMenu->Append(IFMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
836 m_pFileMenu->Append(IFMENU_FILE_EXPORT, "&Export...");
838 m_pFileMenu->AppendSeparator();
839 m_pFileMenu->Append(wxID_PRINT, "&Print...");
840 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
841 m_pFileMenu->Append(wxID_PREVIEW, "Print Preview");
843 m_pFileMenu->AppendSeparator();
844 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
845 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
847 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
848 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
850 wxMenu *view_menu = new wxMenu;
851 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale S&et...\tCtrl-E");
852 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
853 view_menu->Append(IFMENU_VIEW_SCALE_FULL, "Display F&ull Scale\tCtrl-U");
855 wxMenu* filter_menu = new wxMenu;
856 filter_menu->Append (IFMENU_FILTER_INVERTVALUES, "&Invert Values");
857 filter_menu->Append (IFMENU_FILTER_SQUARE, "&Square");
858 filter_menu->Append (IFMENU_FILTER_SQRT, "Square &Root");
859 filter_menu->Append (IFMENU_FILTER_LOG, "&Log");
860 filter_menu->Append (IFMENU_FILTER_EXP, "&Exp");
861 filter_menu->AppendSeparator();
863 filter_menu->Append (IFMENU_FILTER_FFT, "2-D &FFT");
864 filter_menu->Append (IFMENU_FILTER_IFFT, "2-D &IFFT");
865 filter_menu->Append (IFMENU_FILTER_FFT_ROWS, "FFT Rows");
866 filter_menu->Append (IFMENU_FILTER_IFFT_ROWS, "IFFT Rows");
867 filter_menu->Append (IFMENU_FILTER_FFT_COLS, "FFT Columns");
868 filter_menu->Append (IFMENU_FILTER_IFFT_COLS, "IFFT Columns");
869 filter_menu->Append (IFMENU_FILTER_FOURIER, "2-D F&ourier");
870 filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "2-D Inverse Fo&urier");
872 filter_menu->Append (IFMENU_FILTER_FOURIER, "&Fourier");
873 filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "&Inverse Fourier");
875 filter_menu->Append (IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, "S&huffle Fourier to Natural Order");
876 filter_menu->Append (IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, "Shu&ffle Natural to Fourier Order");
877 filter_menu->Append (IFMENU_FILTER_MAGNITUDE, "&Magnitude");
878 filter_menu->Append (IFMENU_FILTER_PHASE, "&Phase");
880 wxMenu* image_menu = new wxMenu;
881 image_menu->Append (IFMENU_IMAGE_ADD, "&Add...");
882 image_menu->Append (IFMENU_IMAGE_SUBTRACT, "&Subtract...");
883 image_menu->Append (IFMENU_IMAGE_MULTIPLY, "&Multiply...");
884 image_menu->Append (IFMENU_IMAGE_DIVIDE, "&Divide...");
885 image_menu->AppendSeparator();
886 image_menu->Append (IFMENU_IMAGE_SCALESIZE, "S&cale Size...");
888 image_menu->Append (IFMENU_IMAGE_CONVERT3D, "Convert &3-D\tCtrl-3");
891 m_pMenuAnalyze = new wxMenu;
892 m_pMenuAnalyze->Append (IFMENU_PLOT_ROW, "Plot &Row");
893 m_pMenuAnalyze->Append (IFMENU_PLOT_COL, "Plot &Column");
894 m_pMenuAnalyze->Append (IFMENU_PLOT_HISTOGRAM, "Plot &Histogram");
895 m_pMenuAnalyze->AppendSeparator();
896 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_ROW, "Plot FFT Row");
897 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_COL, "Plot FFT Column");
898 m_pMenuAnalyze->AppendSeparator();
899 m_pMenuAnalyze->Append (IFMENU_COMPARE_IMAGES, "Compare &Images...");
900 m_pMenuAnalyze->Append (IFMENU_COMPARE_ROW, "Compare &Row");
901 m_pMenuAnalyze->Append (IFMENU_COMPARE_COL, "Compare &Column");
902 m_pMenuAnalyze->Enable (IFMENU_PLOT_ROW, false);
903 m_pMenuAnalyze->Enable (IFMENU_PLOT_COL, false);
904 m_pMenuAnalyze->Enable (IFMENU_COMPARE_ROW, false);
905 m_pMenuAnalyze->Enable (IFMENU_COMPARE_COL, false);
906 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_ROW, false);
907 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_COL, false);
909 wxMenu *help_menu = new wxMenu;
910 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
911 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
912 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
913 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
915 wxMenuBar *menu_bar = new wxMenuBar;
917 menu_bar->Append(m_pFileMenu, "&File");
918 menu_bar->Append(view_menu, "&View");
919 menu_bar->Append(image_menu, "&Image");
920 menu_bar->Append(filter_menu, "Fi<er");
921 menu_bar->Append(m_pMenuAnalyze, "&Analyze");
922 menu_bar->Append(help_menu, "&Help");
924 subframe->SetMenuBar(menu_bar);
926 subframe->Centre(wxBOTH);
928 wxAcceleratorEntry accelEntries[5];
929 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('A'), IFMENU_VIEW_SCALE_AUTO);
930 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('U'), IFMENU_VIEW_SCALE_FULL);
931 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('E'), IFMENU_VIEW_SCALE_MINMAX);
932 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), IFMENU_FILE_PROPERTIES);
934 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('3'), IFMENU_IMAGE_CONVERT3D);
935 wxAcceleratorTable accelTable (5, accelEntries);
937 wxAcceleratorTable accelTable (4, accelEntries);
940 subframe->SetAcceleratorTable (accelTable);
947 ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
949 m_pFrame = CreateChildFrame(doc, this);
951 m_bMinSpecified = false;
952 m_bMaxSpecified = false;
953 m_dAutoScaleFactor = 1.;
956 m_pFrame->GetClientSize (&width, &height);
957 m_pFrame->SetTitle("ImageFileView");
958 m_pCanvas = CreateCanvas (m_pFrame);
960 int x, y; // X requires a forced resize
961 m_pFrame->GetSize(&x, &y);
962 m_pFrame->SetSize(-1, -1, x, y);
963 m_pFrame->SetFocus();
964 m_pFrame->Show(true);
971 ImageFileView::OnDraw (wxDC* dc)
973 wxSize sizeWindow = m_pFrame->GetClientSize();
974 wxSize sizeBest = m_pCanvas->GetBestSize();
975 if (sizeWindow.x > sizeBest.x || sizeWindow.y > sizeBest.y)
976 m_pFrame->SetClientSize (sizeBest);
979 dc->DrawBitmap(m_bitmap, 0, 0, false);
981 int xCursor, yCursor;
982 if (m_pCanvas->GetCurrentCursor (xCursor, yCursor))
983 m_pCanvas->DrawRubberBandCursor (*dc, xCursor, yCursor);
988 ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
990 const ImageFile& rIF = GetDocument()->getImageFile();
991 ImageFileArrayConst v = rIF.getArray();
994 if (v != NULL && nx != 0 && ny != 0) {
995 if (! m_bMinSpecified || ! m_bMaxSpecified) {
997 rIF.getMinMax (min, max);
998 if (! m_bMinSpecified)
1000 if (! m_bMaxSpecified)
1003 double scaleWidth = m_dMaxPixel - m_dMinPixel;
1005 unsigned char* imageData = new unsigned char [nx * ny * 3];
1006 for (int ix = 0; ix < nx; ix++) {
1007 for (int iy = 0; iy < ny; iy++) {
1008 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
1009 int intensity = static_cast<int>(scaleValue + 0.5);
1010 intensity = clamp (intensity, 0, 255);
1011 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
1012 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
1015 wxImage image (nx, ny, imageData, true);
1016 m_bitmap = image.ConvertToBitmap();
1020 ySize = clamp (ySize, 0, 800);
1021 m_pFrame->SetClientSize (xSize, ySize);
1022 m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20);
1023 m_pCanvas->SetBackgroundColour(*wxWHITE);
1027 m_pCanvas->Refresh();
1031 ImageFileView::OnClose (bool deleteWindow)
1033 //GetDocumentManager()->ActivateView (this, false, true);
1034 if (! GetDocument() || ! GetDocument()->Close())
1039 m_pCanvas->setView(NULL);
1042 wxString s(theApp->GetAppName());
1044 m_pFrame->SetTitle(s);
1051 if (GetDocument() && GetDocument()->getBadFileOpen())
1052 ::wxYield(); // wxWindows bug workaround
1059 ImageFileView::OnExport (wxCommandEvent& event)
1061 ImageFile& rIF = GetDocument()->getImageFile();
1062 ImageFileArrayConst v = rIF.getArray();
1065 if (v != NULL && nx != 0 && ny != 0) {
1066 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1068 rIF.getMinMax (min, max);
1069 if (! m_bMinSpecified)
1071 if (! m_bMaxSpecified)
1075 DialogExportParameters dialogExport (getFrameForChild(), m_iDefaultExportFormatID);
1076 if (dialogExport.ShowModal() == wxID_OK) {
1077 wxString strFormatName (dialogExport.getFormatName ());
1078 m_iDefaultExportFormatID = ImageFile::convertFormatNameToID (strFormatName.c_str());
1081 wxString strWildcard;
1082 if (m_iDefaultExportFormatID == ImageFile::FORMAT_PGM || m_iDefaultExportFormatID == ImageFile::FORMAT_PGMASCII) {
1084 strWildcard = "PGM Files (*.pgm)|*.pgm";
1087 else if (m_iDefaultExportFormatID == ImageFile::FORMAT_PNG || m_iDefaultExportFormatID == ImageFile::FORMAT_PNG16) {
1089 strWildcard = "PNG Files (*.png)|*.png";
1093 const wxString& strFilename = wxFileSelector (wxString("Export Filename"), wxString(""),
1094 wxString(""), strExt, strWildcard, wxOVERWRITE_PROMPT | wxHIDE_READONLY | wxSAVE);
1096 rIF.exportImage (strFormatName.c_str(), strFilename.c_str(), 1, 1, m_dMinPixel, m_dMaxPixel);
1097 *theApp->getLog() << "Exported file " << strFilename << "\n";
1104 ImageFileView::OnScaleSize (wxCommandEvent& event)
1106 ImageFile& rIF = GetDocument()->getImageFile();
1107 unsigned int iOldNX = rIF.nx();
1108 unsigned int iOldNY = rIF.ny();
1110 DialogGetXYSize dialogGetXYSize (getFrameForChild(), "Set New X & Y Dimensions", iOldNX, iOldNY);
1111 if (dialogGetXYSize.ShowModal() == wxID_OK) {
1112 unsigned int iNewNX = dialogGetXYSize.getXSize();
1113 unsigned int iNewNY = dialogGetXYSize.getYSize();
1114 std::ostringstream os;
1115 os << "Scale Size from (" << iOldNX << "," << iOldNY << ") to (" << iNewNX << "," << iNewNY << ")";
1116 ImageFileDocument* pScaledDoc = theApp->newImageDoc();
1118 sys_error (ERR_SEVERE, "Unable to create image file");
1121 ImageFile& rScaledIF = pScaledDoc->getImageFile();
1122 rScaledIF.setArraySize (iNewNX, iNewNY);
1123 rScaledIF.labelsCopy (rIF);
1124 rScaledIF.labelAdd (os.str().c_str());
1125 rIF.scaleImage (rScaledIF);
1126 *theApp->getLog() << os.str().c_str() << "\n";
1127 if (theApp->getAskDeleteNewDocs())
1128 pScaledDoc->Modify (true);
1129 pScaledDoc->UpdateAllViews (this);
1130 pScaledDoc->getView()->OnUpdate (this, NULL);
1131 pScaledDoc->getView()->getFrame()->Show(true);
1137 ImageFileView::OnConvert3d (wxCommandEvent& event)
1139 ImageFile& rIF = GetDocument()->getImageFile();
1140 Graph3dFileDocument* pGraph3d = theApp->newGraph3dDoc();
1141 pGraph3d->setBadFileOpen();
1142 pGraph3d->createFromImageFile (rIF);
1143 pGraph3d->getView()->OnUpdate (this, NULL);
1144 pGraph3d->UpdateAllViews();
1145 pGraph3d->getView()->getFrame()->SetClientSize (400, 400);
1146 pGraph3d->getView()->getFrame()->Show (true);
1147 GetDocumentManager()->ActivateView (pGraph3d->getView(), true, false);
1149 pGraph3d->getView()->getCanvas()->SetFocus();
1154 ImageFileView::OnPlotRow (wxCommandEvent& event)
1156 int xCursor, yCursor;
1157 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1158 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1162 const ImageFile& rIF = GetDocument()->getImageFile();
1163 ImageFileArrayConst v = rIF.getArray();
1164 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1168 if (v != NULL && yCursor < ny) {
1169 double* pX = new double [nx];
1170 double* pYReal = new double [nx];
1171 double *pYImag = NULL;
1172 double *pYMag = NULL;
1173 if (rIF.isComplex()) {
1174 pYImag = new double [nx];
1175 pYMag = new double [nx];
1177 for (int i = 0; i < nx; i++) {
1179 pYReal[i] = v[i][yCursor];
1180 if (rIF.isComplex()) {
1181 pYImag[i] = vImag[i][yCursor];
1182 pYMag[i] = ::sqrt (v[i][yCursor] * v[i][yCursor] + vImag[i][yCursor] * vImag[i][yCursor]);
1185 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1187 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1189 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1190 std::ostringstream os;
1191 os << "Row " << yCursor;
1192 std::string title("title ");
1194 rPlotFile.addEzsetCommand (title.c_str());
1195 rPlotFile.addEzsetCommand ("xlabel Column");
1196 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1197 rPlotFile.addEzsetCommand ("lxfrac 0");
1198 rPlotFile.addEzsetCommand ("box");
1199 rPlotFile.addEzsetCommand ("grid");
1200 rPlotFile.addEzsetCommand ("curve 1");
1201 rPlotFile.addEzsetCommand ("color 1");
1202 if (rIF.isComplex()) {
1203 rPlotFile.addEzsetCommand ("dash 1");
1204 rPlotFile.addEzsetCommand ("curve 2");
1205 rPlotFile.addEzsetCommand ("color 4");
1206 rPlotFile.addEzsetCommand ("dash 3");
1207 rPlotFile.addEzsetCommand ("curve 3");
1208 rPlotFile.addEzsetCommand ("color 0");
1209 rPlotFile.addEzsetCommand ("solid");
1210 rPlotFile.setCurveSize (4, nx);
1212 rPlotFile.setCurveSize (2, nx);
1213 rPlotFile.addColumn (0, pX);
1214 rPlotFile.addColumn (1, pYReal);
1215 if (rIF.isComplex()) {
1216 rPlotFile.addColumn (2, pYImag);
1217 rPlotFile.addColumn (3, pYMag);
1219 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1220 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1221 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1222 *theApp->getLog() << os.str().c_str() << "\n";
1223 rPlotFile.addDescription (os.str().c_str());
1227 if (rIF.isComplex()) {
1231 if (theApp->getAskDeleteNewDocs())
1232 pPlotDoc->Modify (true);
1233 pPlotDoc->UpdateAllViews ();
1234 pPlotDoc->getView()->OnUpdate (this, NULL);
1235 pPlotDoc->getView()->getFrame()->Show(true);
1240 ImageFileView::OnPlotCol (wxCommandEvent& event)
1242 int xCursor, yCursor;
1243 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1244 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1248 const ImageFile& rIF = GetDocument()->getImageFile();
1249 ImageFileArrayConst v = rIF.getArray();
1250 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1254 if (v != NULL && xCursor < nx) {
1255 double* pX = new double [ny];
1256 double* pYReal = new double [ny];
1257 double* pYImag = NULL;
1258 double* pYMag = NULL;
1259 if (rIF.isComplex()) {
1260 pYImag = new double [ny];
1261 pYMag = new double [ny];
1263 for (int i = 0; i < ny; i++) {
1265 pYReal[i] = v[xCursor][i];
1266 if (rIF.isComplex()) {
1267 pYImag[i] = vImag[xCursor][i];
1268 pYMag[i] = ::sqrt (v[xCursor][i] * v[xCursor][i] + vImag[xCursor][i] * vImag[xCursor][i]);
1271 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1273 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1275 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1276 std::ostringstream os;
1277 os << "Column " << xCursor;
1278 std::string title("title ");
1280 rPlotFile.addEzsetCommand (title.c_str());
1281 rPlotFile.addEzsetCommand ("xlabel Row");
1282 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1283 rPlotFile.addEzsetCommand ("lxfrac 0");
1284 rPlotFile.addEzsetCommand ("box");
1285 rPlotFile.addEzsetCommand ("grid");
1286 rPlotFile.addEzsetCommand ("curve 1");
1287 rPlotFile.addEzsetCommand ("color 1");
1288 if (rIF.isComplex()) {
1289 rPlotFile.addEzsetCommand ("dash 1");
1290 rPlotFile.addEzsetCommand ("curve 2");
1291 rPlotFile.addEzsetCommand ("color 4");
1292 rPlotFile.addEzsetCommand ("dash 3");
1293 rPlotFile.addEzsetCommand ("curve 3");
1294 rPlotFile.addEzsetCommand ("color 0");
1295 rPlotFile.addEzsetCommand ("solid");
1296 rPlotFile.setCurveSize (4, ny);
1298 rPlotFile.setCurveSize (2, ny);
1299 rPlotFile.addColumn (0, pX);
1300 rPlotFile.addColumn (1, pYReal);
1301 if (rIF.isComplex()) {
1302 rPlotFile.addColumn (2, pYImag);
1303 rPlotFile.addColumn (3, pYMag);
1305 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1306 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1307 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1308 *theApp->getLog() << os.str().c_str() << "\n";
1309 rPlotFile.addDescription (os.str().c_str());
1313 if (rIF.isComplex()) {
1317 if (theApp->getAskDeleteNewDocs())
1318 pPlotDoc->Modify (true);
1319 pPlotDoc->UpdateAllViews ();
1320 pPlotDoc->getView()->OnUpdate (this, NULL);
1321 pPlotDoc->getView()->getFrame()->Show(true);
1327 ImageFileView::OnPlotFFTRow (wxCommandEvent& event)
1329 int xCursor, yCursor;
1330 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1331 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1335 const ImageFile& rIF = GetDocument()->getImageFile();
1336 ImageFileArrayConst v = rIF.getArray();
1337 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1341 if (v != NULL && yCursor < ny) {
1342 fftw_complex* pcIn = new fftw_complex [nx];
1345 for (i = 0; i < nx; i++) {
1346 pcIn[i].re = v[i][yCursor];
1347 if (rIF.isComplex())
1348 pcIn[i].im = vImag[i][yCursor];
1353 fftw_plan plan = fftw_create_plan (nx, FFTW_FORWARD, FFTW_IN_PLACE);
1354 fftw_one (plan, pcIn, NULL);
1355 fftw_destroy_plan (plan);
1357 double* pX = new double [nx];
1358 double* pYReal = new double [nx];
1359 double* pYImag = new double [nx];
1360 double* pYMag = new double [nx];
1361 for (i = 0; i < nx; i++) {
1363 pYReal[i] = pcIn[i].re;
1364 pYImag[i] = pcIn[i].im;
1365 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1367 Fourier::shuffleFourierToNaturalOrder (pYReal, nx);
1368 Fourier::shuffleFourierToNaturalOrder (pYImag, nx);
1369 Fourier::shuffleFourierToNaturalOrder (pYMag, nx);
1371 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1373 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1375 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1376 std::ostringstream os;
1377 os << "Row " << yCursor;
1378 std::string title("title ");
1380 rPlotFile.addEzsetCommand (title.c_str());
1381 rPlotFile.addEzsetCommand ("xlabel Column");
1382 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1383 rPlotFile.addEzsetCommand ("lxfrac 0");
1384 rPlotFile.addEzsetCommand ("curve 1");
1385 rPlotFile.addEzsetCommand ("color 1");
1386 rPlotFile.addEzsetCommand ("dash 1");
1387 rPlotFile.addEzsetCommand ("curve 2");
1388 rPlotFile.addEzsetCommand ("color 4");
1389 rPlotFile.addEzsetCommand ("dash 3");
1390 rPlotFile.addEzsetCommand ("curve 3");
1391 rPlotFile.addEzsetCommand ("color 0");
1392 rPlotFile.addEzsetCommand ("solid");
1393 rPlotFile.addEzsetCommand ("box");
1394 rPlotFile.addEzsetCommand ("grid");
1395 rPlotFile.setCurveSize (4, nx);
1396 rPlotFile.addColumn (0, pX);
1397 rPlotFile.addColumn (1, pYReal);
1398 rPlotFile.addColumn (2, pYImag);
1399 rPlotFile.addColumn (3, pYMag);
1400 for (int iL = 0; iL < rIF.nLabels(); iL++)
1401 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1402 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1403 *theApp->getLog() << os.str().c_str() << "\n";
1404 rPlotFile.addDescription (os.str().c_str());
1412 if (theApp->getAskDeleteNewDocs())
1413 pPlotDoc->Modify (true);
1414 pPlotDoc->UpdateAllViews ();
1415 pPlotDoc->getView()->OnUpdate (this, NULL);
1416 pPlotDoc->getView()->getFrame()->Show(true);
1421 ImageFileView::OnPlotFFTCol (wxCommandEvent& event)
1423 int xCursor, yCursor;
1424 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1425 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1429 const ImageFile& rIF = GetDocument()->getImageFile();
1430 ImageFileArrayConst v = rIF.getArray();
1431 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1435 if (v != NULL && xCursor < nx) {
1436 fftw_complex* pcIn = new fftw_complex [ny];
1437 double *pdTemp = new double [ny];
1440 for (i = 0; i < ny; i++)
1441 pdTemp[i] = v[xCursor][i];
1442 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1443 for (i = 0; i < ny; i++)
1444 pcIn[i].re = pdTemp[i];
1446 for (i = 0; i < ny; i++) {
1447 if (rIF.isComplex())
1448 pdTemp[i] = vImag[xCursor][i];
1452 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1453 for (i = 0; i < ny; i++)
1454 pcIn[i].im = pdTemp[i];
1456 fftw_plan plan = fftw_create_plan (ny, FFTW_BACKWARD, FFTW_IN_PLACE);
1457 fftw_one (plan, pcIn, NULL);
1458 fftw_destroy_plan (plan);
1460 double* pX = new double [ny];
1461 double* pYReal = new double [ny];
1462 double* pYImag = new double [ny];
1463 double* pYMag = new double [ny];
1464 for (i = 0; i < ny; i++) {
1466 pYReal[i] = pcIn[i].re;
1467 pYImag[i] = pcIn[i].im;
1468 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1471 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1473 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1475 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1476 std::ostringstream os;
1477 os << "Column " << xCursor;
1478 std::string title("title ");
1480 rPlotFile.addEzsetCommand (title.c_str());
1481 rPlotFile.addEzsetCommand ("xlabel Column");
1482 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1483 rPlotFile.addEzsetCommand ("lxfrac 0");
1484 rPlotFile.addEzsetCommand ("curve 1");
1485 rPlotFile.addEzsetCommand ("color 1");
1486 rPlotFile.addEzsetCommand ("dash 1");
1487 rPlotFile.addEzsetCommand ("curve 2");
1488 rPlotFile.addEzsetCommand ("color 4");
1489 rPlotFile.addEzsetCommand ("dash 3");
1490 rPlotFile.addEzsetCommand ("curve 3");
1491 rPlotFile.addEzsetCommand ("color 0");
1492 rPlotFile.addEzsetCommand ("solid");
1493 rPlotFile.addEzsetCommand ("box");
1494 rPlotFile.addEzsetCommand ("grid");
1495 rPlotFile.setCurveSize (4, ny);
1496 rPlotFile.addColumn (0, pX);
1497 rPlotFile.addColumn (1, pYReal);
1498 rPlotFile.addColumn (2, pYImag);
1499 rPlotFile.addColumn (3, pYMag);
1500 for (int iL = 0; iL < rIF.nLabels(); iL++)
1501 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1502 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1503 *theApp->getLog() << os.str().c_str() << "\n";
1504 rPlotFile.addDescription (os.str().c_str());
1513 if (theApp->getAskDeleteNewDocs())
1514 pPlotDoc->Modify (true);
1515 pPlotDoc->UpdateAllViews ();
1516 pPlotDoc->getView()->OnUpdate (this, NULL);
1517 pPlotDoc->getView()->getFrame()->Show(true);
1523 ImageFileView::OnCompareCol (wxCommandEvent& event)
1525 int xCursor, yCursor;
1526 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1527 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1531 std::vector<ImageFileDocument*> vecIFDoc;
1532 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1533 if (vecIFDoc.size() == 0) {
1534 wxMessageBox ("No compatible images for Column Comparison", "Error");
1537 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1539 if (dialogGetCompare.ShowModal() == wxID_OK) {
1540 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1541 const ImageFile& rIF = GetDocument()->getImageFile();
1542 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1544 ImageFileArrayConst v1 = rIF.getArray();
1545 ImageFileArrayConst v2 = rCompareIF.getArray();
1549 if (v1 != NULL && xCursor < nx) {
1550 double* pX = new double [ny];
1551 double* pY1 = new double [ny];
1552 double* pY2 = new double [ny];
1553 for (int i = 0; i < ny; i++) {
1555 pY1[i] = v1[xCursor][i];
1556 pY2[i] = v2[xCursor][i];
1558 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1560 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1562 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1563 std::ostringstream os;
1564 os << "Column " << xCursor << " Comparison";
1565 std::string title("title ");
1567 rPlotFile.addEzsetCommand (title.c_str());
1568 rPlotFile.addEzsetCommand ("xlabel Row");
1569 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1570 rPlotFile.addEzsetCommand ("lxfrac 0");
1571 rPlotFile.addEzsetCommand ("curve 1");
1572 rPlotFile.addEzsetCommand ("color 2");
1573 rPlotFile.addEzsetCommand ("curve 2");
1574 rPlotFile.addEzsetCommand ("color 4");
1575 rPlotFile.addEzsetCommand ("dash 5");
1576 rPlotFile.addEzsetCommand ("box");
1577 rPlotFile.addEzsetCommand ("grid");
1578 rPlotFile.setCurveSize (3, ny);
1579 rPlotFile.addColumn (0, pX);
1580 rPlotFile.addColumn (1, pY1);
1581 rPlotFile.addColumn (2, pY2);
1584 for (iL = 0; iL < rIF.nLabels(); iL++) {
1585 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1587 s += rIF.labelGet(iL).getLabelString();
1588 rPlotFile.addDescription (s.c_str());
1590 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1591 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1593 s += rCompareIF.labelGet(iL).getLabelString();
1594 rPlotFile.addDescription (s.c_str());
1596 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1597 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1598 *theApp->getLog() << os.str().c_str() << "\n";
1599 rPlotFile.addDescription (os.str().c_str());
1604 if (theApp->getAskDeleteNewDocs())
1605 pPlotDoc->Modify (true);
1606 pPlotDoc->UpdateAllViews ();
1607 pPlotDoc->getView()->OnUpdate (this, NULL);
1608 pPlotDoc->getView()->getFrame()->Show(true);
1614 ImageFileView::OnCompareRow (wxCommandEvent& event)
1616 int xCursor, yCursor;
1617 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1618 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1622 std::vector<ImageFileDocument*> vecIFDoc;
1623 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1625 if (vecIFDoc.size() == 0) {
1626 wxMessageBox ("No compatible images for Row Comparison", "Error");
1630 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1632 if (dialogGetCompare.ShowModal() == wxID_OK) {
1633 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1634 const ImageFile& rIF = GetDocument()->getImageFile();
1635 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1637 ImageFileArrayConst v1 = rIF.getArray();
1638 ImageFileArrayConst v2 = rCompareIF.getArray();
1642 if (v1 != NULL && yCursor < ny) {
1643 double* pX = new double [nx];
1644 double* pY1 = new double [nx];
1645 double* pY2 = new double [nx];
1646 for (int i = 0; i < nx; i++) {
1648 pY1[i] = v1[i][yCursor];
1649 pY2[i] = v2[i][yCursor];
1651 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1653 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1655 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1656 std::ostringstream os;
1657 os << "Row " << yCursor << " Comparison";
1658 std::string title("title ");
1660 rPlotFile.addEzsetCommand (title.c_str());
1661 rPlotFile.addEzsetCommand ("xlabel Column");
1662 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1663 rPlotFile.addEzsetCommand ("lxfrac 0");
1664 rPlotFile.addEzsetCommand ("curve 1");
1665 rPlotFile.addEzsetCommand ("color 2");
1666 rPlotFile.addEzsetCommand ("curve 2");
1667 rPlotFile.addEzsetCommand ("color 4");
1668 rPlotFile.addEzsetCommand ("dash 5");
1669 rPlotFile.addEzsetCommand ("box");
1670 rPlotFile.addEzsetCommand ("grid");
1671 rPlotFile.setCurveSize (3, nx);
1672 rPlotFile.addColumn (0, pX);
1673 rPlotFile.addColumn (1, pY1);
1674 rPlotFile.addColumn (2, pY2);
1676 for (iL = 0; iL < rIF.nLabels(); iL++) {
1677 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1679 s += rIF.labelGet(iL).getLabelString();
1680 rPlotFile.addDescription (s.c_str());
1682 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1683 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1685 s += rCompareIF.labelGet(iL).getLabelString();
1686 rPlotFile.addDescription (s.c_str());
1688 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1689 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1690 *theApp->getLog() << os.str().c_str() << "\n";
1691 rPlotFile.addDescription (os.str().c_str());
1696 if (theApp->getAskDeleteNewDocs())
1697 pPlotDoc->Modify (true);
1698 pPlotDoc->UpdateAllViews ();
1699 pPlotDoc->getView()->OnUpdate (this, NULL);
1700 pPlotDoc->getView()->getFrame()->Show(true);
1705 static int NUMBER_HISTOGRAM_BINS = 256;
1708 ImageFileView::OnPlotHistogram (wxCommandEvent& event)
1710 const ImageFile& rIF = GetDocument()->getImageFile();
1711 ImageFileArrayConst v = rIF.getArray();
1715 if (v != NULL && nx > 0 && ny > 0) {
1716 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1718 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1722 double* pX = new double [NUMBER_HISTOGRAM_BINS];
1723 double* pY = new double [NUMBER_HISTOGRAM_BINS];
1725 rIF.getMinMax (dMin, dMax);
1726 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
1728 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
1729 pX[i] = dMin + (i + 0.5) * dBinWidth;
1732 for (int ix = 0; ix < nx; ix++)
1733 for (int iy = 0; iy < ny; iy++) {
1734 int iBin = nearest<int> ((v[ix][iy] - dMin) / dBinWidth);
1735 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
1739 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1740 std::ostringstream os;
1742 std::string title("title ");
1744 rPlotFile.addEzsetCommand (title.c_str());
1745 rPlotFile.addEzsetCommand ("xlabel Pixel Value");
1746 rPlotFile.addEzsetCommand ("ylabel Count");
1747 rPlotFile.addEzsetCommand ("box");
1748 rPlotFile.addEzsetCommand ("grid");
1749 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
1750 rPlotFile.addColumn (0, pX);
1751 rPlotFile.addColumn (1, pY);
1752 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++) {
1753 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1755 s += rIF.labelGet(iL).getLabelString();
1756 rPlotFile.addDescription (s.c_str());
1758 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1759 *theApp->getLog() << os.str().c_str() << "\n";
1760 rPlotFile.addDescription (os.str().c_str());
1763 if (theApp->getAskDeleteNewDocs())
1764 pPlotDoc->Modify (true);
1765 pPlotDoc->UpdateAllViews ();
1766 pPlotDoc->getView()->OnUpdate (this, NULL);
1767 pPlotDoc->getView()->getFrame()->Show(true);
1774 PhantomCanvas::PhantomCanvas (PhantomFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1775 : wxScrolledWindow(frame, -1, pos, size, style)
1780 PhantomCanvas::~PhantomCanvas ()
1786 PhantomCanvas::OnDraw (wxDC& dc)
1789 m_pView->OnDraw(& dc);
1793 PhantomCanvas::GetBestSize() const
1799 theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
1800 xSize = maxValue<int> (xSize, ySize);
1801 ySize = xSize = (xSize / 3);
1802 return wxSize (xSize, ySize);
1809 IMPLEMENT_DYNAMIC_CLASS(PhantomFileView, wxView)
1811 BEGIN_EVENT_TABLE(PhantomFileView, wxView)
1812 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomFileView::OnProperties)
1813 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomFileView::OnRasterize)
1814 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomFileView::OnProjections)
1817 PhantomFileView::PhantomFileView()
1818 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0)
1820 #if defined(DEBUG) || defined(_DEBUG)
1821 m_iDefaultNDet = 165;
1822 m_iDefaultNView = 180;
1824 m_iDefaultNDet = 367;
1825 m_iDefaultNView = 320;
1827 m_iDefaultNSample = 2;
1828 m_dDefaultRotation = 1;
1829 m_dDefaultFocalLength = 2;
1830 m_dDefaultViewRatio = 1;
1831 m_dDefaultScanRatio = 1;
1832 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
1833 m_iDefaultTrace = Trace::TRACE_NONE;
1836 m_iDefaultRasterNX = 115;
1837 m_iDefaultRasterNY = 115;
1838 m_iDefaultRasterNSamples = 1;
1840 m_iDefaultRasterNX = 256;
1841 m_iDefaultRasterNY = 256;
1842 m_iDefaultRasterNSamples = 2;
1844 m_dDefaultRasterViewRatio = 1;
1847 PhantomFileView::~PhantomFileView()
1849 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
1850 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
1854 PhantomFileView::OnProperties (wxCommandEvent& event)
1856 const int idPhantom = GetDocument()->getPhantomID();
1857 const wxString& namePhantom = GetDocument()->getPhantomName();
1858 std::ostringstream os;
1859 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")" << "\n";
1860 const Phantom& rPhantom = GetDocument()->getPhantom();
1861 rPhantom.printDefinitions (os);
1863 rPhantom.print (os);
1865 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
1866 wxMessageBox (os.str().c_str(), "Phantom Properties");
1871 PhantomFileView::OnProjections (wxCommandEvent& event)
1873 DialogGetProjectionParameters dialogProjection (getFrameForChild(),
1874 m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation,
1875 m_dDefaultFocalLength, m_dDefaultViewRatio, m_dDefaultScanRatio, m_iDefaultGeometry,
1877 int retVal = dialogProjection.ShowModal();
1878 if (retVal == wxID_OK) {
1879 m_iDefaultNDet = dialogProjection.getNDet();
1880 m_iDefaultNView = dialogProjection.getNView();
1881 m_iDefaultNSample = dialogProjection.getNSamples();
1882 m_iDefaultTrace = dialogProjection.getTrace();
1883 m_dDefaultRotation = dialogProjection.getRotAngle();
1884 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
1885 m_dDefaultViewRatio = dialogProjection.getViewRatio();
1886 m_dDefaultScanRatio = dialogProjection.getScanRatio();
1887 wxString sGeometry = dialogProjection.getGeometry();
1888 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
1890 if (m_iDefaultNDet > 0 && m_iDefaultNView > 0 && sGeometry != "") {
1891 const Phantom& rPhantom = GetDocument()->getPhantom();
1892 Projections* pProj = new Projections;
1893 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample,
1894 m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultViewRatio, m_dDefaultScanRatio);
1895 if (theScanner.fail()) {
1896 wxString msg = "Failed making scanner\n";
1897 msg += theScanner.failMessage().c_str();
1898 *theApp->getLog() << msg << "\n";
1899 wxMessageBox (msg, "Error");
1902 pProj->initFromScanner (theScanner);
1903 m_dDefaultRotation /= TWOPI; // convert back to fraction of a circle
1906 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
1907 ProjectionsDialog dialogProjections (theScanner, *pProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(getFrameForChild()));
1908 for (int iView = 0; iView < pProj->nView(); iView++) {
1910 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
1915 while (dialogProjections.isPaused()) {
1921 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), pProj->nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
1922 for (int i = 0; i < pProj->nView(); i++) {
1923 theScanner.collectProjections (*pProj, rPhantom, i, 1, true, m_iDefaultTrace);
1924 if (! dlgProgress.Update (i+1)) {
1931 std::ostringstream os;
1932 os << "Projections for " << rPhantom.name() << ": nDet=" << m_iDefaultNDet
1933 << ", nView=" << m_iDefaultNView << ", nSamples=" << m_iDefaultNSample
1934 << ", RotAngle=" << m_dDefaultRotation << ", FocalLengthRatio=" << m_dDefaultFocalLength
1935 << ", ViewRatio=" << m_dDefaultViewRatio << ", ScanRatio=" << m_dDefaultScanRatio
1936 << ", Geometry=" << sGeometry.c_str() << ", FanBeamAngle=" <<
1937 convertRadiansToDegrees (theScanner.fanBeamAngle());
1938 pProj->setCalcTime (timer.timerEnd());
1939 pProj->setRemark (os.str());
1940 *theApp->getLog() << os.str().c_str() << "\n";
1943 ProjectionFileDocument* pProjectionDoc = theApp->newProjectionDoc();
1944 if (! pProjectionDoc) {
1945 sys_error (ERR_SEVERE, "Unable to create projection document");
1948 pProjectionDoc->setProjections (pProj);
1949 ProjectionFileView* projView = pProjectionDoc->getView();
1951 projView->OnUpdate (projView, NULL);
1952 if (projView->getCanvas())
1953 projView->getCanvas()->SetClientSize (m_iDefaultNDet, m_iDefaultNView);
1954 if (wxFrame* pFrame = projView->getFrame()) {
1959 GetDocumentManager()->ActivateView (projView, true, false);
1962 if (theApp->getAskDeleteNewDocs())
1963 pProjectionDoc-> Modify(true);
1964 pProjectionDoc->UpdateAllViews (this);
1971 PhantomFileView::OnRasterize (wxCommandEvent& event)
1973 DialogGetRasterParameters dialogRaster (getFrameForChild(), m_iDefaultRasterNX, m_iDefaultRasterNY,
1974 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio);
1975 int retVal = dialogRaster.ShowModal();
1976 if (retVal == wxID_OK) {
1977 m_iDefaultRasterNX = dialogRaster.getXSize();
1978 m_iDefaultRasterNY = dialogRaster.getYSize();
1979 m_iDefaultRasterNSamples = dialogRaster.getNSamples();
1980 m_dDefaultRasterViewRatio = dialogRaster.getViewRatio();
1981 if (m_iDefaultRasterNSamples < 1)
1982 m_iDefaultRasterNSamples = 1;
1983 if (m_dDefaultRasterViewRatio < 0)
1984 m_dDefaultRasterViewRatio = 0;
1985 if (m_iDefaultRasterNX > 0 && m_iDefaultRasterNY > 0) {
1986 const Phantom& rPhantom = GetDocument()->getPhantom();
1988 ImageFile* pImageFile = new ImageFile;
1990 pImageFile->setArraySize (m_iDefaultRasterNX, m_iDefaultRasterNY);
1991 wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"),
1992 pImageFile->nx() + 1, getFrameForChild(), wxPD_CAN_ABORT );
1994 for (unsigned int i = 0; i < pImageFile->nx(); i++) {
1995 rPhantom.convertToImagefile (*pImageFile, m_dDefaultRasterViewRatio, m_iDefaultRasterNSamples,
1996 Trace::TRACE_NONE, i, 1, true);
1997 if (! dlgProgress.Update (i+1)) {
2003 ImageFileDocument* pRasterDoc = theApp->newImageDoc();
2005 sys_error (ERR_SEVERE, "Unable to create image file");
2008 pRasterDoc->setImageFile (pImageFile);
2010 if (theApp->getAskDeleteNewDocs())
2011 pRasterDoc->Modify (true);
2012 pRasterDoc->UpdateAllViews (this);
2013 pRasterDoc->getView()->getFrame()->Show(true);
2014 std::ostringstream os;
2015 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << m_iDefaultRasterNX << ", YSize="
2016 << m_iDefaultRasterNY << ", ViewRatio=" << m_dDefaultRasterViewRatio << ", nSamples="
2017 << m_iDefaultRasterNSamples;;
2018 *theApp->getLog() << os.str().c_str() << "\n";
2019 pImageFile->labelAdd (os.str().c_str(), timer.timerEnd());
2020 ImageFileView* rasterView = pRasterDoc->getView();
2022 rasterView->getFrame()->SetFocus();
2023 rasterView->OnUpdate (rasterView, NULL);
2032 PhantomFileView::CreateCanvas (wxFrame *parent)
2034 PhantomCanvas* pCanvas;
2036 pCanvas = new PhantomCanvas (this, parent, wxPoint(0, 0), wxSize(0,0), 0);
2037 pCanvas->SetBackgroundColour(*wxWHITE);
2048 PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2051 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2053 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2055 theApp->setIconForFrame (subframe);
2057 m_pFileMenu = new wxMenu;
2059 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2060 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2061 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2062 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2063 m_pFileMenu->Append(wxID_CLOSE, "&Close");
2065 m_pFileMenu->AppendSeparator();
2066 m_pFileMenu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
2068 m_pFileMenu->AppendSeparator();
2069 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2070 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2071 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2073 m_pFileMenu->AppendSeparator();
2074 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
2075 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2077 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2078 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2080 wxMenu *process_menu = new wxMenu;
2081 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...\tCtrl-R");
2082 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...\tCtrl-J");
2084 wxMenu *help_menu = new wxMenu;
2085 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2086 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
2087 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
2088 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2090 wxMenuBar *menu_bar = new wxMenuBar;
2092 menu_bar->Append(m_pFileMenu, "&File");
2093 menu_bar->Append(process_menu, "&Process");
2094 menu_bar->Append(help_menu, "&Help");
2096 subframe->SetMenuBar(menu_bar);
2097 subframe->Centre(wxBOTH);
2099 wxAcceleratorEntry accelEntries[3];
2100 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('J'), PHMMENU_PROCESS_PROJECTIONS);
2101 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('R'), PHMMENU_PROCESS_RASTERIZE);
2102 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('I'), PHMMENU_FILE_PROPERTIES);
2103 wxAcceleratorTable accelTable (3, accelEntries);
2104 subframe->SetAcceleratorTable (accelTable);
2111 PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2113 m_pFrame = CreateChildFrame(doc, this);
2115 m_pCanvas = CreateCanvas (m_pFrame);
2116 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
2117 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
2119 m_pFrame->SetTitle ("PhantomFileView");
2122 int x, y; // X requires a forced resize
2123 m_pFrame->GetSize(&x, &y);
2124 m_pFrame->SetSize(-1, -1, x, y);
2127 m_pFrame->Show(true);
2134 PhantomFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2137 m_pCanvas->Refresh();
2141 PhantomFileView::OnClose (bool deleteWindow)
2143 //GetDocumentManager()->ActivateView (this, false, true);
2144 if (! GetDocument() || ! GetDocument()->Close())
2149 m_pCanvas->setView(NULL);
2152 wxString s(wxTheApp->GetAppName());
2154 m_pFrame->SetTitle(s);
2161 if (GetDocument() && GetDocument()->getBadFileOpen())
2162 ::wxYield(); // wxWindows bug workaround
2169 PhantomFileView::OnDraw (wxDC* dc)
2172 m_pCanvas->GetClientSize (&xsize, &ysize);
2173 SGPDriver driver (dc, xsize, ysize);
2175 const Phantom& rPhantom = GetDocument()->getPhantom();
2176 sgp.setColor (C_RED);
2177 rPhantom.show (sgp);
2182 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2183 : wxScrolledWindow(frame, -1, pos, size, style)
2188 ProjectionFileCanvas::~ProjectionFileCanvas ()
2194 ProjectionFileCanvas::OnDraw(wxDC& dc)
2197 m_pView->OnDraw(& dc);
2201 ProjectionFileCanvas::GetBestSize () const
2205 Projections& rProj = m_pView->GetDocument()->getProjections();
2206 best.Set (rProj.nDet(), rProj.nView());
2213 // ProjectionFileView
2215 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
2217 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
2218 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
2219 EVT_MENU(PJMENU_RECONSTRUCT_FBP, ProjectionFileView::OnReconstructFBP)
2220 EVT_MENU(PJMENU_RECONSTRUCT_FOURIER, ProjectionFileView::OnReconstructFourier)
2221 EVT_MENU(PJMENU_CONVERT_POLAR, ProjectionFileView::OnConvertPolar)
2222 EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
2225 ProjectionFileView::ProjectionFileView()
2226 : wxView(), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0)
2236 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
2237 m_dDefaultFilterParam = 1.;
2239 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
2240 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
2242 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
2243 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
2245 m_iDefaultZeropad = 1;
2246 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF;
2247 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
2248 m_iDefaultInterpParam = 1;
2249 m_iDefaultTrace = Trace::TRACE_NONE;
2251 m_iDefaultPolarNX = 256;
2252 m_iDefaultPolarNY = 256;
2253 m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR;
2254 m_iDefaultPolarZeropad = 1;
2257 ProjectionFileView::~ProjectionFileView()
2259 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2260 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2264 ProjectionFileView::OnProperties (wxCommandEvent& event)
2266 const Projections& rProj = GetDocument()->getProjections();
2267 std::ostringstream os;
2268 rProj.printScanInfo(os);
2269 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2270 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
2271 dialogMsg.ShowModal();
2276 ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
2278 Projections& rProj = GetDocument()->getProjections();
2279 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2280 m_iDefaultPolarInterpolation, -1);
2281 if (dialogPolar.ShowModal() == wxID_OK) {
2282 wxString strInterpolation (dialogPolar.getInterpolationName());
2283 m_iDefaultPolarNX = dialogPolar.getXSize();
2284 m_iDefaultPolarNY = dialogPolar.getYSize();
2285 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2286 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2287 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2288 if (! rProj.convertPolar (*pIF, m_iDefaultPolarInterpolation)) {
2290 *theApp->getLog() << "Error converting to Polar\n";
2293 pPolarDoc = theApp->newImageDoc ();
2295 sys_error (ERR_SEVERE, "Unable to create image file");
2298 pPolarDoc->setImageFile (pIF);
2299 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2300 std::ostringstream os;
2301 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to polar image: xSize="
2302 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2303 << strInterpolation.c_str();
2304 *theApp->getLog() << os.str().c_str() << "\n";
2305 pIF->labelAdd (os.str().c_str());
2306 if (theApp->getAskDeleteNewDocs())
2307 pPolarDoc->Modify (true);
2308 pPolarDoc->UpdateAllViews ();
2309 pPolarDoc->getView()->OnUpdate (this, NULL);
2310 pPolarDoc->getView()->getFrame()->Show(true);
2315 ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
2317 Projections& rProj = GetDocument()->getProjections();
2318 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert to FFT Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2319 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad);
2320 if (dialogPolar.ShowModal() == wxID_OK) {
2321 wxString strInterpolation (dialogPolar.getInterpolationName());
2322 m_iDefaultPolarNX = dialogPolar.getXSize();
2323 m_iDefaultPolarNY = dialogPolar.getYSize();
2324 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2325 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2327 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2328 if (! rProj.convertFFTPolar (*pIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad)) {
2330 *theApp->getLog() << "Error converting to polar\n";
2333 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2335 sys_error (ERR_SEVERE, "Unable to create image file");
2338 pPolarDoc->setImageFile (pIF);
2339 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2340 std::ostringstream os;
2341 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to FFT polar image: xSize="
2342 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2343 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2344 *theApp->getLog() << os.str().c_str() << "\n";
2345 pIF->labelAdd (os.str().c_str());
2346 if (theApp->getAskDeleteNewDocs())
2347 pPolarDoc->Modify (true);
2348 pPolarDoc->UpdateAllViews ();
2349 pPolarDoc->getView()->OnUpdate (this, NULL);
2350 pPolarDoc->getView()->getFrame()->Show(true);
2355 ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
2358 DialogGetReconstructionParameters dialogReconstruction (getFrameForChild(), m_iDefaultNX, m_iDefaultNY,
2359 m_iDefaultFilter, m_dDefaultFilterParam, m_iDefaultFilterMethod, m_iDefaultFilterGeneration,
2360 m_iDefaultZeropad, m_iDefaultInterpolation, m_iDefaultInterpParam, m_iDefaultBackprojector,
2363 int retVal = dialogReconstruction.ShowModal();
2364 if (retVal == wxID_OK) {
2365 m_iDefaultNX = dialogReconstruction.getXSize();
2366 m_iDefaultNY = dialogReconstruction.getYSize();
2367 wxString optFilterName = dialogReconstruction.getFilterName();
2368 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
2369 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
2370 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
2371 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
2372 m_iDefaultZeropad = dialogReconstruction.getZeropad();
2373 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
2374 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
2375 wxString optInterpName = dialogReconstruction.getInterpName();
2376 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
2377 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
2378 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
2379 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
2380 m_iDefaultTrace = dialogReconstruction.getTrace();
2382 if (m_iDefaultNX > 0 && m_iDefaultNY > 0) {
2383 const Projections& rProj = GetDocument()->getProjections();
2384 ImageFile* pImageFile = new ImageFile;
2385 pImageFile->setArraySize (m_iDefaultNX, m_iDefaultNY);
2386 std::ostringstream os;
2387 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();
2390 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2391 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2392 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2393 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace);
2395 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstructor, rProj, *pImageFile, m_iDefaultTrace, getFrameForChild());
2396 for (int iView = 0; iView < rProj.nView(); iView++) {
2398 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView, true)) {
2399 delete pDlgReconstruct;
2400 delete pReconstructor;
2406 while (pDlgReconstruct->isPaused()) {
2411 delete pDlgReconstruct;
2412 delete pReconstructor;
2413 ImageFileDocument* pReconDoc = theApp->newImageDoc();
2415 sys_error (ERR_SEVERE, "Unable to create image file");
2418 pReconDoc->setImageFile (pImageFile);
2419 if (theApp->getAskDeleteNewDocs())
2420 pReconDoc->Modify (true);
2421 pReconDoc->UpdateAllViews (this);
2422 if (ImageFileView* rasterView = pReconDoc->getView()) {
2423 rasterView->OnUpdate (rasterView, NULL);
2424 rasterView->getFrame()->SetFocus();
2425 rasterView->getFrame()->Show(true);
2427 *theApp->getLog() << os.str().c_str() << "\n";
2428 pImageFile->labelAdd (rProj.getLabel());
2429 pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd());
2433 ThreadedReconstructor* pReconstructor = new ThreadedReconstructor (this,
2434 m_iDefaultNX, m_iDefaultNY, optFilterName.c_str(),
2435 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2436 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), os.str().c_str());
2437 if (! pReconstructor->start()) {
2439 delete pReconstructor;
2443 // delete pReconstructor;
2445 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2446 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2447 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace);
2449 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2450 for (int iView = 0; iView < rProj.nView(); iView++) {
2451 pReconstructor->reconstructView (iView, 1);
2452 if (! dlgProgress.Update (iView + 1)) {
2453 delete pReconstructor;
2458 delete pReconstructor;
2459 ImageFileDocument* pReconDoc = theApp->newImageDoc();
2461 sys_error (ERR_SEVERE, "Unable to create image file");
2464 pReconDoc->setImageFile (pImageFile);
2465 if (theApp->getAskDeleteNewDocs())
2466 pReconDoc->Modify (true);
2467 pReconDoc->UpdateAllViews (this);
2468 if (ImageFileView* rasterView = pReconDoc->getView()) {
2469 rasterView->OnUpdate (rasterView, NULL);
2470 rasterView->getFrame()->SetFocus();
2471 rasterView->getFrame()->Show(true);
2473 *theApp->getLog() << os.str().c_str() << "\n";
2474 pImageFile->labelAdd (rProj.getLabel());
2475 pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd());
2481 wxMessageBox ("Fourier Reconstruction is not yet supported", "Unimplemented function");
2486 ProjectionFileView::OnReconstructFBP (wxCommandEvent& event)
2488 DialogGetReconstructionParameters dialogReconstruction (getFrameForChild(), m_iDefaultNX, m_iDefaultNY,
2489 m_iDefaultFilter, m_dDefaultFilterParam, m_iDefaultFilterMethod, m_iDefaultFilterGeneration,
2490 m_iDefaultZeropad, m_iDefaultInterpolation, m_iDefaultInterpParam, m_iDefaultBackprojector,
2493 int retVal = dialogReconstruction.ShowModal();
2494 if (retVal == wxID_OK) {
2495 m_iDefaultNX = dialogReconstruction.getXSize();
2496 m_iDefaultNY = dialogReconstruction.getYSize();
2497 wxString optFilterName = dialogReconstruction.getFilterName();
2498 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
2499 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
2500 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
2501 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
2502 m_iDefaultZeropad = dialogReconstruction.getZeropad();
2503 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
2504 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
2505 wxString optInterpName = dialogReconstruction.getInterpName();
2506 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
2507 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
2508 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
2509 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
2510 m_iDefaultTrace = dialogReconstruction.getTrace();
2512 if (m_iDefaultNX > 0 && m_iDefaultNY > 0) {
2513 const Projections& rProj = GetDocument()->getProjections();
2514 ImageFile* pImageFile = new ImageFile;
2515 pImageFile->setArraySize (m_iDefaultNX, m_iDefaultNY);
2517 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2518 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2519 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace);
2522 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2523 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstructor, rProj, *pImageFile, m_iDefaultTrace, getFrameForChild());
2524 for (int iView = 0; iView < rProj.nView(); iView++) {
2526 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView, true)) {
2527 delete pDlgReconstruct;
2528 delete pReconstructor;
2534 while (pDlgReconstruct->isPaused()) {
2539 delete pDlgReconstruct;
2541 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2542 for (int iView = 0; iView < rProj.nView(); iView++) {
2543 pReconstructor->reconstructView (iView, 1);
2544 if (! dlgProgress.Update (iView + 1)) {
2545 delete pReconstructor;
2551 delete pReconstructor;
2552 ImageFileDocument* pReconDoc = theApp->newImageDoc();
2554 sys_error (ERR_SEVERE, "Unable to create image file");
2557 pReconDoc->setImageFile (pImageFile);
2558 if (theApp->getAskDeleteNewDocs())
2559 pReconDoc->Modify (true);
2560 pReconDoc->UpdateAllViews (this);
2561 if (ImageFileView* rasterView = pReconDoc->getView()) {
2562 rasterView->OnUpdate (rasterView, NULL);
2563 rasterView->getFrame()->SetFocus();
2564 rasterView->getFrame()->Show(true);
2566 std::ostringstream os;
2567 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();
2568 *theApp->getLog() << os.str().c_str() << "\n";
2569 pImageFile->labelAdd (rProj.getLabel());
2570 pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd());
2576 ProjectionFileCanvas*
2577 ProjectionFileView::CreateCanvas (wxFrame *parent)
2579 ProjectionFileCanvas* pCanvas;
2581 parent->GetClientSize(&width, &height);
2583 pCanvas = new ProjectionFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
2585 pCanvas->SetScrollbars(20, 20, 50, 50);
2586 pCanvas->SetBackgroundColour(*wxWHITE);
2597 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2600 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2602 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2604 theApp->setIconForFrame (subframe);
2606 m_pFileMenu = new wxMenu;
2608 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2609 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2610 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2611 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2612 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2613 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2615 m_pFileMenu->AppendSeparator();
2616 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
2618 m_pFileMenu->AppendSeparator();
2619 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2620 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2621 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2623 m_pFileMenu->AppendSeparator();
2624 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
2625 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2627 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2628 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2630 wxMenu *convert_menu = new wxMenu;
2631 convert_menu->Append (PJMENU_CONVERT_POLAR, "&Polar Image...\tCtrl-L");
2632 convert_menu->Append (PJMENU_CONVERT_FFT_POLAR, "&FFT->Polar Image...\tCtrl-M");
2634 wxMenu *reconstruct_menu = new wxMenu;
2635 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP, "&Filtered Backprojection...\tCtrl-R", "Reconstruct image using filtered backprojection");
2636 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Fourier...\tCtrl-E", "Reconstruct image using inverse Fourier");
2637 #ifndef CTSIM_THREADS
2638 reconstruct_menu->Enable (PJMENU_RECONSTRUCT_FOURIER, false);
2641 wxMenu *help_menu = new wxMenu;
2642 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2643 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
2644 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
2645 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2647 wxMenuBar *menu_bar = new wxMenuBar;
2649 menu_bar->Append (m_pFileMenu, "&File");
2650 menu_bar->Append (convert_menu, "&Convert");
2651 menu_bar->Append (reconstruct_menu, "&Reconstruct");
2652 menu_bar->Append (help_menu, "&Help");
2654 subframe->SetMenuBar(menu_bar);
2655 subframe->Centre(wxBOTH);
2657 wxAcceleratorEntry accelEntries[5];
2658 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('L'), PJMENU_CONVERT_POLAR);
2659 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('M'), PJMENU_CONVERT_FFT_POLAR);
2660 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('R'), PJMENU_RECONSTRUCT_FBP);
2661 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('E'), PJMENU_RECONSTRUCT_FOURIER);
2662 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('I'), PJMENU_FILE_PROPERTIES);
2663 wxAcceleratorTable accelTable (5, accelEntries);
2664 subframe->SetAcceleratorTable (accelTable);
2671 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2673 m_pFrame = CreateChildFrame(doc, this);
2677 m_pFrame->GetClientSize (&width, &height);
2678 m_pFrame->SetTitle ("ProjectionFileView");
2679 m_pCanvas = CreateCanvas (m_pFrame);
2682 int x, y; // X requires a forced resize
2683 m_pFrame->GetSize(&x, &y);
2684 m_pFrame->SetSize(-1, -1, x, y);
2687 m_pFrame->Show(true);
2694 ProjectionFileView::OnDraw (wxDC* dc)
2696 wxSize clientSize = m_pFrame->GetClientSize();
2697 wxSize bestSize = m_pCanvas->GetBestSize();
2699 if (clientSize.x > bestSize.x || clientSize.y > bestSize.y)
2700 m_pFrame->SetClientSize (bestSize);
2703 dc->DrawBitmap (m_bitmap, 0, 0, false);
2708 ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2710 const Projections& rProj = GetDocument()->getProjections();
2711 const int nDet = rProj.nDet();
2712 const int nView = rProj.nView();
2713 if (nDet != 0 && nView != 0) {
2714 const DetectorArray& detarray = rProj.getDetectorArray(0);
2715 const DetectorValue* detval = detarray.detValues();
2716 double min = detval[0];
2717 double max = detval[0];
2718 for (int iy = 0; iy < nView; iy++) {
2719 const DetectorArray& detarray = rProj.getDetectorArray(iy);
2720 const DetectorValue* detval = detarray.detValues();
2721 for (int ix = 0; ix < nDet; ix++) {
2722 if (min > detval[ix])
2724 else if (max < detval[ix])
2729 unsigned char* imageData = new unsigned char [nDet * nView * 3];
2730 double scale = (max - min) / 255;
2731 for (int iy2 = 0; iy2 < nView; iy2++) {
2732 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
2733 const DetectorValue* detval = detarray.detValues();
2734 for (int ix = 0; ix < nDet; ix++) {
2735 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
2736 intensity = clamp(intensity, 0, 255);
2737 int baseAddr = (iy2 * nDet + ix) * 3;
2738 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
2741 wxImage image (nDet, nView, imageData, true);
2742 m_bitmap = image.ConvertToBitmap();
2746 xSize = clamp (xSize, 0, 800);
2747 ySize = clamp (ySize, 0, 800);
2748 m_pFrame->SetClientSize (xSize, ySize);
2749 m_pCanvas->SetScrollbars (20, 20, nDet/20, nView/20);
2753 m_pCanvas->Refresh();
2757 ProjectionFileView::OnClose (bool deleteWindow)
2759 //GetDocumentManager()->ActivateView (this, false, true);
2760 if (! GetDocument() || ! GetDocument()->Close())
2765 m_pCanvas->setView(NULL);
2768 wxString s(wxTheApp->GetAppName());
2770 m_pFrame->SetTitle(s);
2777 if (GetDocument() && GetDocument()->getBadFileOpen())
2778 ::wxYield(); // wxWindows bug workaround
2787 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2788 : wxScrolledWindow(frame, -1, pos, size, style)
2793 PlotFileCanvas::~PlotFileCanvas ()
2799 PlotFileCanvas::OnDraw(wxDC& dc)
2802 m_pView->OnDraw(& dc);
2808 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
2810 BEGIN_EVENT_TABLE(PlotFileView, wxView)
2811 EVT_MENU(PLOTMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
2812 EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
2813 EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
2814 EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
2817 PlotFileView::PlotFileView()
2818 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pEZPlot(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
2822 PlotFileView::~PlotFileView()
2827 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2831 PlotFileView::OnProperties (wxCommandEvent& event)
2833 const PlotFile& rPlot = GetDocument()->getPlotFile();
2834 std::ostringstream os;
2835 os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
2836 rPlot.printHeadersBrief (os);
2837 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<<\n";
2838 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
2839 dialogMsg.ShowModal();
2844 PlotFileView::OnScaleAuto (wxCommandEvent& event)
2846 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2847 double min, max, mean, mode, median, stddev;
2848 rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
2849 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
2850 int iRetVal = dialogAutoScale.ShowModal();
2851 if (iRetVal == wxID_OK) {
2852 m_bMinSpecified = true;
2853 m_bMaxSpecified = true;
2855 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
2858 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
2859 OnUpdate (this, NULL);
2865 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
2867 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2871 if (! m_bMinSpecified || ! m_bMaxSpecified) {
2872 if (! rPlotFile.getMinMax (1, min, max)) {
2873 *theApp->getLog() << "Error: unable to find Min/Max\n";
2878 if (m_bMinSpecified)
2880 if (m_bMaxSpecified)
2883 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Y-axis Minimum & Maximum", min, max);
2884 int retVal = dialogMinMax.ShowModal();
2885 if (retVal == wxID_OK) {
2886 m_bMinSpecified = true;
2887 m_bMaxSpecified = true;
2888 m_dMinPixel = dialogMinMax.getMinimum();
2889 m_dMaxPixel = dialogMinMax.getMaximum();
2890 OnUpdate (this, NULL);
2895 PlotFileView::OnScaleFull (wxCommandEvent& event)
2897 if (m_bMinSpecified || m_bMaxSpecified) {
2898 m_bMinSpecified = false;
2899 m_bMaxSpecified = false;
2900 OnUpdate (this, NULL);
2906 PlotFileView::CreateCanvas (wxFrame* parent)
2908 PlotFileCanvas* pCanvas;
2910 parent->GetClientSize(&width, &height);
2912 pCanvas = new PlotFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
2914 pCanvas->SetBackgroundColour(*wxWHITE);
2925 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2928 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2930 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2932 theApp->setIconForFrame (subframe);
2934 m_pFileMenu = new wxMenu;
2936 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2937 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2938 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2939 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2940 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2941 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2943 m_pFileMenu->AppendSeparator();
2944 m_pFileMenu->Append(PLOTMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
2946 m_pFileMenu->AppendSeparator();
2947 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2948 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2949 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2951 m_pFileMenu->AppendSeparator();
2952 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
2953 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2955 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2956 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2958 wxMenu *view_menu = new wxMenu;
2959 view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...\tCtrl-E");
2960 view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
2961 view_menu->Append(PLOTMENU_VIEW_SCALE_FULL, "Display &Full Scale\tCtrl-U");
2963 wxMenu *help_menu = new wxMenu;
2964 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2965 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
2966 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
2967 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2969 wxMenuBar *menu_bar = new wxMenuBar;
2971 menu_bar->Append(m_pFileMenu, "&File");
2972 menu_bar->Append(view_menu, "&View");
2973 menu_bar->Append(help_menu, "&Help");
2975 subframe->SetMenuBar(menu_bar);
2976 subframe->Centre(wxBOTH);
2978 wxAcceleratorEntry accelEntries[4];
2979 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('E'), PLOTMENU_VIEW_SCALE_MINMAX);
2980 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('A'), PLOTMENU_VIEW_SCALE_AUTO);
2981 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('U'), PLOTMENU_VIEW_SCALE_FULL);
2982 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), PLOTMENU_FILE_PROPERTIES);
2983 wxAcceleratorTable accelTable (4, accelEntries);
2984 subframe->SetAcceleratorTable (accelTable);
2991 PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
2993 m_pFrame = CreateChildFrame(doc, this);
2996 m_bMinSpecified = false;
2997 m_bMaxSpecified = false;
2998 m_dAutoScaleFactor = 1.;
3001 m_pFrame->GetClientSize(&width, &height);
3002 m_pFrame->SetTitle ("Plot File");
3003 m_pCanvas = CreateCanvas (m_pFrame);
3006 int x, y; // X requires a forced resize
3007 m_pFrame->GetSize(&x, &y);
3008 m_pFrame->SetSize(-1, -1, x, y);
3011 m_pFrame->Show(true);
3018 PlotFileView::OnDraw (wxDC* dc)
3020 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3021 const int iNColumns = rPlotFile.getNumColumns();
3022 const int iNRecords = rPlotFile.getNumRecords();
3024 if (iNColumns > 0 && iNRecords > 0) {
3026 m_pCanvas->GetClientSize (&xsize, &ysize);
3027 SGPDriver driver (dc, xsize, ysize);
3030 m_pEZPlot->plot (&sgp);
3036 PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3038 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3039 const int iNColumns = rPlotFile.getNumColumns();
3040 const int iNRecords = rPlotFile.getNumRecords();
3042 if (iNColumns > 0 && iNRecords > 0) {
3045 m_pEZPlot = new EZPlot;
3047 for (unsigned int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)
3048 m_pEZPlot->ezset (rPlotFile.getEzsetCommand (iEzset));
3050 if (m_bMinSpecified) {
3051 std::ostringstream os;
3052 os << "ymin " << m_dMinPixel;
3053 m_pEZPlot->ezset (os.str());
3056 if (m_bMaxSpecified) {
3057 std::ostringstream os;
3058 os << "ymax " << m_dMaxPixel;
3059 m_pEZPlot->ezset (os.str());
3062 m_pEZPlot->ezset("box");
3063 m_pEZPlot->ezset("grid");
3065 double* pdXaxis = new double [iNRecords];
3066 rPlotFile.getColumn (0, pdXaxis);
3068 double* pdY = new double [iNRecords];
3069 for (int iCol = 1; iCol < iNColumns; iCol++) {
3070 rPlotFile.getColumn (iCol, pdY);
3071 m_pEZPlot->addCurve (pdXaxis, pdY, iNRecords);
3079 m_pCanvas->Refresh();
3083 PlotFileView::OnClose (bool deleteWindow)
3085 //GetDocumentManager()->ActivateView (this, false, true);
3086 if (! GetDocument() || ! GetDocument()->Close())
3091 m_pCanvas->setView (NULL);
3094 wxString s(wxTheApp->GetAppName());
3096 m_pFrame->SetTitle(s);
3102 if (GetDocument() && GetDocument()->getBadFileOpen())
3103 ::wxYield(); // wxWindows bug workaround
3110 ////////////////////////////////////////////////////////////////
3113 IMPLEMENT_DYNAMIC_CLASS(TextFileView, wxView)
3115 TextFileView::~TextFileView()
3117 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
3118 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
3121 bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
3123 m_pFrame = CreateChildFrame(doc, this);
3124 SetFrame (m_pFrame);
3127 m_pFrame->GetClientSize(&width, &height);
3128 m_pFrame->SetTitle("TextFile");
3129 m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
3130 m_pFrame->SetTitle("Log");
3133 // X seems to require a forced resize
3135 frame->GetSize(&x, &y);
3136 frame->SetSize(-1, -1, x, y);
3139 m_pFrame->Show (true);
3145 // Handled by wxTextWindow
3146 void TextFileView::OnDraw(wxDC *WXUNUSED(dc) )
3150 void TextFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3155 TextFileView::OnClose (bool deleteWindow)
3157 if (! theApp->getMainFrame()->getShuttingDown())
3161 //GetDocumentManager()->ActivateView (this, false, true);
3162 if (! GetDocument() || ! GetDocument()->Close())
3169 if (GetDocument() && GetDocument()->getBadFileOpen())
3170 ::wxYield(); // wxWindows bug workaround
3181 TextFileView::CreateChildFrame (wxDocument *doc, wxView *view)
3184 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(0,0), wxDEFAULT_FRAME_STYLE, "Log");
3186 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE, "Log");
3188 theApp->setIconForFrame (subframe);
3190 m_pFileMenu = new wxMenu;
3192 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3193 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3194 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3195 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3196 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3197 // m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3199 m_pFileMenu->AppendSeparator();
3200 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3201 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3202 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3204 m_pFileMenu->AppendSeparator();
3205 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3206 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3208 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3209 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3211 wxMenu *help_menu = new wxMenu;
3212 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3213 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3214 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3215 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3217 wxMenuBar *menu_bar = new wxMenuBar;
3219 menu_bar->Append(m_pFileMenu, "&File");
3220 menu_bar->Append(help_menu, "&Help");
3222 subframe->SetMenuBar(menu_bar);
3223 subframe->Centre(wxBOTH);
3229 // Define a constructor for my text subwindow
3230 TextFileCanvas::TextFileCanvas (TextFileView* v, wxFrame* frame, const wxPoint& pos, const wxSize& size, long style)
3231 : wxTextCtrl (frame, -1, "", pos, size, style), m_pView(v)
3235 TextFileCanvas::~TextFileCanvas ()