1 /*****************************************************************************
5 ** Purpose: View & Canvas routines for CTSim program
6 ** Programmer: Kevin Rosenberg
7 ** Date Started: July 2000
9 ** This is part of the CTSim program
10 ** Copyright (C) 1983-2000 Kevin Rosenberg
12 ** $Id: views.cpp,v 1.52 2001/01/06 15:33:15 kevin Exp $
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
28 // For compilers that support precompilation, includes "wx/wx.h".
29 #include "wx/wxprec.h"
39 #if !wxUSE_DOC_VIEW_ARCHITECTURE
40 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
44 #include "wx/progdlg.h"
51 #include "dlgprojections.h"
52 #include "dlgreconstruct.h"
53 #include "backprojectors.h"
54 #include "reconstruct.h"
57 #if defined(MSVC) || HAVE_SSTREAM
60 #include <sstream_subst>
66 BEGIN_EVENT_TABLE(ImageFileCanvas, wxScrolledWindow)
67 EVT_MOUSE_EVENTS(ImageFileCanvas::OnMouseEvent)
71 ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
72 : wxScrolledWindow(frame, -1, pos, size, style)
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 ImageFile& rIF = m_pView->GetDocument()->getImageFile();
125 ImageFileArrayConst v = rIF.getArray();
128 const int yPt = ny - 1 - pt.y;
129 if (event.RightIsDown()) {
130 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
131 std::ostringstream os;
132 os << "Image value (" << pt.x << "," << yPt << ") = " << v[pt.x][yPt];
133 if (rIF.isComplex()) {
134 double dImag = rIF.getImaginaryArray()[pt.x][yPt];
136 os << " - " << -dImag;
138 os << " + " << dImag;
142 *theApp->getLog() << os.str().c_str();
144 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
146 else if (event.LeftIsDown() || event.LeftUp() || event.RightUp()) {
147 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
148 if (m_xCursor >= 0 && m_yCursor >= 0) {
149 DrawRubberBandCursor (dc, m_xCursor, m_yCursor);
151 DrawRubberBandCursor (dc, pt.x, yPt);
155 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
157 if (event.LeftUp()) {
158 std::ostringstream os;
159 os << "Selected column " << pt.x << " , row " << yPt << "\n";
160 *theApp->getLog() << os.str().c_str();
166 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
168 BEGIN_EVENT_TABLE(ImageFileView, wxView)
169 EVT_MENU(IFMENU_FILE_EXPORT, ImageFileView::OnExport)
170 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
171 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
172 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
173 EVT_MENU(IFMENU_VIEW_SCALE_FULL, ImageFileView::OnScaleFull)
174 EVT_MENU(IFMENU_COMPARE_IMAGES, ImageFileView::OnCompare)
175 EVT_MENU(IFMENU_COMPARE_ROW, ImageFileView::OnCompareRow)
176 EVT_MENU(IFMENU_COMPARE_COL, ImageFileView::OnCompareCol)
177 EVT_MENU(IFMENU_FILTER_INVERTVALUES, ImageFileView::OnInvertValues)
178 EVT_MENU(IFMENU_FILTER_SQUARE, ImageFileView::OnSquare)
179 EVT_MENU(IFMENU_FILTER_SQRT, ImageFileView::OnSquareRoot)
180 EVT_MENU(IFMENU_FILTER_LOG, ImageFileView::OnLog)
181 EVT_MENU(IFMENU_FILTER_EXP, ImageFileView::OnExp)
182 EVT_MENU(IFMENU_FILTER_FOURIER, ImageFileView::OnFourier)
183 EVT_MENU(IFMENU_FILTER_INVERSE_FOURIER, ImageFileView::OnInverseFourier)
184 EVT_MENU(IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, ImageFileView::OnShuffleFourierToNaturalOrder)
185 EVT_MENU(IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, ImageFileView::OnShuffleNaturalToFourierOrder)
186 EVT_MENU(IFMENU_IMAGE_ADD, ImageFileView::OnAdd)
187 EVT_MENU(IFMENU_IMAGE_SUBTRACT, ImageFileView::OnSubtract)
188 EVT_MENU(IFMENU_IMAGE_MULTIPLY, ImageFileView::OnMultiply)
189 EVT_MENU(IFMENU_IMAGE_DIVIDE, ImageFileView::OnDivide)
190 EVT_MENU(IFMENU_IMAGE_SCALESIZE, ImageFileView::OnScaleSize)
192 EVT_MENU(IFMENU_FILTER_FFT, ImageFileView::OnFFT)
193 EVT_MENU(IFMENU_FILTER_IFFT, ImageFileView::OnIFFT)
194 EVT_MENU(IFMENU_FILTER_FFT_ROWS, ImageFileView::OnFFTRows)
195 EVT_MENU(IFMENU_FILTER_IFFT_ROWS, ImageFileView::OnIFFTRows)
196 EVT_MENU(IFMENU_FILTER_FFT_COLS, ImageFileView::OnFFTCols)
197 EVT_MENU(IFMENU_FILTER_IFFT_COLS, ImageFileView::OnIFFTCols)
199 EVT_MENU(IFMENU_FILTER_MAGNITUDE, ImageFileView::OnMagnitude)
200 EVT_MENU(IFMENU_FILTER_PHASE, ImageFileView::OnPhase)
201 EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)
202 EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol)
204 EVT_MENU(IFMENU_PLOT_FFT_ROW, ImageFileView::OnPlotFFTRow)
205 EVT_MENU(IFMENU_PLOT_FFT_COL, ImageFileView::OnPlotFFTCol)
207 EVT_MENU(IFMENU_PLOT_HISTOGRAM, ImageFileView::OnPlotHistogram)
210 ImageFileView::ImageFileView(void)
211 : wxView(), m_canvas(NULL), m_frame(NULL), m_bMinSpecified(false), m_bMaxSpecified(false)
213 m_iDefaultExportFormatID = ImageFile::FORMAT_PNG;
216 ImageFileView::~ImageFileView(void)
221 ImageFileView::OnProperties (wxCommandEvent& event)
223 const ImageFile& rIF = GetDocument()->getImageFile();
224 if (rIF.nx() == 0 || rIF.ny() == 0)
225 *theApp->getLog() << "Properties: empty imagefile\n";
227 const std::string& rFilename = rIF.getFilename();
228 std::ostringstream os;
229 double min, max, mean, mode, median, stddev;
230 rIF.statistics (rIF.getArray(), min, max, mean, mode, median, stddev);
231 os << "Filename: " << rFilename << "\n";
232 os << "Size: (" << rIF.nx() << "," << rIF.ny() << ")\n";
238 os << "\nMinimum: "<<min<<"\nMaximum: "<<max<<"\nMean: "<<mean<<"\nMedian: "<<median<<"\nMode: "<<mode<<"\nStandard Deviation: "<<stddev << "\n";
239 if (rIF.isComplex()) {
240 rIF.statistics (rIF.getImaginaryArray(), min, max, mean, mode, median, stddev);
241 os << "\nImaginary: min: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
243 if (rIF.nLabels() > 0) {
245 rIF.printLabelsBrief (os);
247 *theApp->getLog() << os.str().c_str();
248 wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
249 dialogMsg.ShowModal();
254 ImageFileView::OnScaleAuto (wxCommandEvent& event)
256 const ImageFile& rIF = GetDocument()->getImageFile();
257 double min, max, mean, mode, median, stddev;
258 rIF.statistics(min, max, mean, mode, median, stddev);
259 DialogAutoScaleParameters dialogAutoScale (m_frame, mean, mode, median, stddev, m_dAutoScaleFactor);
260 int iRetVal = dialogAutoScale.ShowModal();
261 if (iRetVal == wxID_OK) {
262 m_bMinSpecified = true;
263 m_bMaxSpecified = true;
265 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
268 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
269 OnUpdate (this, NULL);
275 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
277 const ImageFile& rIF = GetDocument()->getImageFile();
279 if (! m_bMinSpecified && ! m_bMaxSpecified)
280 rIF.getMinMax (min, max);
287 DialogGetMinMax dialogMinMax (m_frame, "Set Image Minimum & Maximum", min, max);
288 int retVal = dialogMinMax.ShowModal();
289 if (retVal == wxID_OK) {
290 m_bMinSpecified = true;
291 m_bMaxSpecified = true;
292 m_dMinPixel = dialogMinMax.getMinimum();
293 m_dMaxPixel = dialogMinMax.getMaximum();
294 OnUpdate (this, NULL);
299 ImageFileView::OnScaleFull (wxCommandEvent& event)
301 if (m_bMinSpecified || m_bMaxSpecified) {
302 m_bMinSpecified = false;
303 m_bMaxSpecified = false;
304 OnUpdate (this, NULL);
309 ImageFileView::OnCompare (wxCommandEvent& event)
311 std::vector<ImageFileDocument*> vecIF;
312 theApp->getCompatibleImages (GetDocument(), vecIF);
314 if (vecIF.size() == 0) {
315 wxMessageBox("There are no compatible image files open for comparision", "No comparison images");
317 DialogGetComparisonImage dialogGetCompare(m_frame, "Get Comparison Image", vecIF, true);
319 if (dialogGetCompare.ShowModal() == wxID_OK) {
320 const ImageFile& rIF = GetDocument()->getImageFile();
321 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
322 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
323 std::ostringstream os;
324 double min, max, mean, mode, median, stddev;
325 rIF.statistics (min, max, mean, mode, median, stddev);
326 os << GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
327 rCompareIF.statistics (min, max, mean, mode, median, stddev);
328 os << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
331 rIF.comparativeStatistics (rCompareIF, d, r, e);
332 os << "Comparative Statistics: d=" << d << ", r=" << r << ", e=" << e << "\n";
333 *theApp->getLog() << os.str().c_str();
334 if (dialogGetCompare.getMakeDifferenceImage()) {
335 ImageFileDocument* pDifferenceDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
336 if (! pDifferenceDoc) {
337 sys_error (ERR_SEVERE, "Unable to create image file");
340 ImageFile& differenceImage = pDifferenceDoc->getImageFile();
342 differenceImage.setArraySize (rIF.nx(), rIF.ny());
343 if (! rIF.subtractImages (rCompareIF, differenceImage)) {
344 pDifferenceDoc->DeleteAllViews();
348 wxString s = GetFrame()->GetTitle() + ": ";
349 differenceImage.labelsCopy (rIF, s.c_str());
350 s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
351 differenceImage.labelsCopy (rCompareIF, s.c_str());
352 std::ostringstream osLabel;
353 osLabel << "Compare image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str()
354 << " and " << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": "
356 differenceImage.labelAdd (os.str().c_str());
357 if (theApp->getSetModifyNewDocs())
358 pDifferenceDoc->Modify(true);
359 pDifferenceDoc->UpdateAllViews(this);
360 pDifferenceDoc->GetFirstView()->OnUpdate (this, NULL);
362 wxMessageBox(os.str().c_str(), "Image Comparison");
368 ImageFileView::OnInvertValues (wxCommandEvent& event)
370 ImageFile& rIF = GetDocument()->getImageFile();
371 rIF.invertPixelValues (rIF);
372 rIF.labelAdd ("Invert Pixel Values");
373 if (theApp->getSetModifyNewDocs())
374 GetDocument()->Modify(TRUE);
375 GetDocument()->UpdateAllViews(this);
379 ImageFileView::OnSquare (wxCommandEvent& event)
381 ImageFile& rIF = GetDocument()->getImageFile();
383 rIF.labelAdd ("Square Pixel Values");
384 if (theApp->getSetModifyNewDocs())
385 GetDocument()->Modify(TRUE);
386 GetDocument()->UpdateAllViews(this);
390 ImageFileView::OnSquareRoot (wxCommandEvent& event)
392 ImageFile& rIF = GetDocument()->getImageFile();
394 rIF.labelAdd ("Square-root Pixel Values");
395 if (theApp->getSetModifyNewDocs())
396 GetDocument()->Modify(TRUE);
397 GetDocument()->UpdateAllViews(this);
401 ImageFileView::OnLog (wxCommandEvent& event)
403 ImageFile& rIF = GetDocument()->getImageFile();
405 rIF.labelAdd ("Logrithm base-e Pixel Values");
406 if (theApp->getSetModifyNewDocs())
407 GetDocument()->Modify(TRUE);
408 GetDocument()->UpdateAllViews(this);
412 ImageFileView::OnExp (wxCommandEvent& event)
414 ImageFile& rIF = GetDocument()->getImageFile();
416 rIF.labelAdd ("Exponent base-e Pixel Values");
417 if (theApp->getSetModifyNewDocs())
418 GetDocument()->Modify(TRUE);
419 GetDocument()->UpdateAllViews(this);
423 ImageFileView::OnAdd (wxCommandEvent& event)
425 std::vector<ImageFileDocument*> vecIF;
426 theApp->getCompatibleImages (GetDocument(), vecIF);
428 if (vecIF.size() == 0) {
429 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
431 DialogGetComparisonImage dialogGetCompare (m_frame, "Get Image to Add", vecIF, false);
433 if (dialogGetCompare.ShowModal() == wxID_OK) {
434 ImageFile& rIF = GetDocument()->getImageFile();
435 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
436 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
437 ImageFileDocument* pNewDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
439 sys_error (ERR_SEVERE, "Unable to create image file");
442 ImageFile& newImage = pNewDoc->getImageFile();
443 newImage.setArraySize (rIF.nx(), rIF.ny());
444 rIF.addImages (rRHSIF, newImage);
445 std::ostringstream os;
446 os << "Add image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
447 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
448 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
449 newImage.labelsCopy (rIF, s.c_str());
450 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
451 newImage.labelsCopy (rRHSIF, s.c_str());
452 newImage.labelAdd (os.str().c_str());
453 *theApp->getLog() << os.str().c_str() << "\n";
454 if (theApp->getSetModifyNewDocs())
455 pNewDoc->Modify(TRUE);
456 pNewDoc->UpdateAllViews(this);
457 pNewDoc->GetFirstView()->OnUpdate (this, NULL);
463 ImageFileView::OnSubtract (wxCommandEvent& event)
465 std::vector<ImageFileDocument*> vecIF;
466 theApp->getCompatibleImages (GetDocument(), vecIF);
468 if (vecIF.size() == 0) {
469 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
471 DialogGetComparisonImage dialogGetCompare (m_frame, "Get Image to Subtract", vecIF, false);
473 if (dialogGetCompare.ShowModal() == wxID_OK) {
474 ImageFile& rIF = GetDocument()->getImageFile();
475 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
476 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
477 ImageFileDocument* pNewDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
479 sys_error (ERR_SEVERE, "Unable to create image file");
482 ImageFile& newImage = pNewDoc->getImageFile();
483 newImage.setArraySize (rIF.nx(), rIF.ny());
484 rIF.subtractImages (rRHSIF, newImage);
485 std::ostringstream os;
486 os << "Subtract image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
487 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
488 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
489 newImage.labelsCopy (rIF, s.c_str());
490 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
491 newImage.labelsCopy (rRHSIF, s.c_str());
492 newImage.labelAdd (os.str().c_str());
493 *theApp->getLog() << os.str().c_str() << "\n";
494 if (theApp->getSetModifyNewDocs())
495 pNewDoc->Modify(TRUE);
496 pNewDoc->UpdateAllViews(this);
497 pNewDoc->GetFirstView()->OnUpdate (this, NULL);
503 ImageFileView::OnMultiply (wxCommandEvent& event)
505 std::vector<ImageFileDocument*> vecIF;
506 theApp->getCompatibleImages (GetDocument(), vecIF);
508 if (vecIF.size() == 0) {
509 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
511 DialogGetComparisonImage dialogGetCompare (m_frame, "Get Image to Multiply", vecIF, false);
513 if (dialogGetCompare.ShowModal() == wxID_OK) {
514 ImageFile& rIF = GetDocument()->getImageFile();
515 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
516 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
517 ImageFileDocument* pNewDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
519 sys_error (ERR_SEVERE, "Unable to create image file");
522 ImageFile& newImage = pNewDoc->getImageFile();
523 newImage.setArraySize (rIF.nx(), rIF.ny());
524 rIF.multiplyImages (rRHSIF, newImage);
525 std::ostringstream os;
526 os << "Multiply image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
527 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
528 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
529 newImage.labelsCopy (rIF, s.c_str());
530 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
531 newImage.labelsCopy (rRHSIF, s.c_str());
532 newImage.labelAdd (os.str().c_str());
533 *theApp->getLog() << os.str().c_str() << "\n";
534 if (theApp->getSetModifyNewDocs())
535 pNewDoc->Modify(TRUE);
536 pNewDoc->UpdateAllViews(this);
537 pNewDoc->GetFirstView()->OnUpdate (this, NULL);
543 ImageFileView::OnDivide (wxCommandEvent& event)
545 std::vector<ImageFileDocument*> vecIF;
546 theApp->getCompatibleImages (GetDocument(), vecIF);
548 if (vecIF.size() == 0) {
549 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
551 DialogGetComparisonImage dialogGetCompare (m_frame, "Get Image to Divide", vecIF, false);
553 if (dialogGetCompare.ShowModal() == wxID_OK) {
554 ImageFile& rIF = GetDocument()->getImageFile();
555 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
556 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
557 ImageFileDocument* pNewDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
559 sys_error (ERR_SEVERE, "Unable to create image file");
562 ImageFile& newImage = pNewDoc->getImageFile();
563 newImage.setArraySize (rIF.nx(), rIF.ny());
564 rIF.divideImages (rRHSIF, newImage);
565 std::ostringstream os;
566 os << "Divide image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " by "
567 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
568 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
569 newImage.labelsCopy (rIF, s.c_str());
570 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
571 newImage.labelsCopy (rRHSIF, s.c_str());
572 newImage.labelAdd (os.str().c_str());
573 *theApp->getLog() << os.str().c_str() << "\n";
574 if (theApp->getSetModifyNewDocs())
575 pNewDoc->Modify(TRUE);
576 pNewDoc->UpdateAllViews(this);
577 pNewDoc->GetFirstView()->OnUpdate (this, NULL);
585 ImageFileView::OnFFT (wxCommandEvent& event)
587 ImageFile& rIF = GetDocument()->getImageFile();
589 rIF.labelAdd ("FFT Image");
590 m_bMinSpecified = false;
591 m_bMaxSpecified = false;
592 if (theApp->getSetModifyNewDocs())
593 GetDocument()->Modify(TRUE);
594 GetDocument()->UpdateAllViews(this);
598 ImageFileView::OnIFFT (wxCommandEvent& event)
600 ImageFile& rIF = GetDocument()->getImageFile();
602 rIF.labelAdd ("IFFT Image");
603 m_bMinSpecified = false;
604 m_bMaxSpecified = false;
605 if (theApp->getSetModifyNewDocs())
606 GetDocument()->Modify(TRUE);
607 GetDocument()->UpdateAllViews(this);
611 ImageFileView::OnFFTRows (wxCommandEvent& event)
613 ImageFile& rIF = GetDocument()->getImageFile();
615 rIF.labelAdd ("FFT Rows");
616 m_bMinSpecified = false;
617 m_bMaxSpecified = false;
618 if (theApp->getSetModifyNewDocs())
619 GetDocument()->Modify(TRUE);
620 GetDocument()->UpdateAllViews(this);
624 ImageFileView::OnIFFTRows (wxCommandEvent& event)
626 ImageFile& rIF = GetDocument()->getImageFile();
628 rIF.labelAdd ("IFFT Rows");
629 m_bMinSpecified = false;
630 m_bMaxSpecified = false;
631 if (theApp->getSetModifyNewDocs())
632 GetDocument()->Modify(TRUE);
633 GetDocument()->UpdateAllViews(this);
637 ImageFileView::OnFFTCols (wxCommandEvent& event)
639 ImageFile& rIF = GetDocument()->getImageFile();
641 rIF.labelAdd ("FFT Columns");
642 m_bMinSpecified = false;
643 m_bMaxSpecified = false;
644 if (theApp->getSetModifyNewDocs())
645 GetDocument()->Modify(TRUE);
646 GetDocument()->UpdateAllViews(this);
650 ImageFileView::OnIFFTCols (wxCommandEvent& event)
652 ImageFile& rIF = GetDocument()->getImageFile();
654 rIF.labelAdd ("IFFT Columns");
655 m_bMinSpecified = false;
656 m_bMaxSpecified = false;
657 if (theApp->getSetModifyNewDocs())
658 GetDocument()->Modify(TRUE);
659 GetDocument()->UpdateAllViews(this);
664 ImageFileView::OnFourier (wxCommandEvent& event)
666 ImageFile& rIF = GetDocument()->getImageFile();
667 wxProgressDialog dlgProgress (wxString("Fourier"), wxString("Fourier Progress"), 1, m_frame, wxPD_APP_MODAL);
669 rIF.labelAdd ("Fourier Image");
670 m_bMinSpecified = false;
671 m_bMaxSpecified = false;
672 if (theApp->getSetModifyNewDocs())
673 GetDocument()->Modify(TRUE);
674 GetDocument()->UpdateAllViews(this);
678 ImageFileView::OnInverseFourier (wxCommandEvent& event)
680 ImageFile& rIF = GetDocument()->getImageFile();
681 wxProgressDialog dlgProgress (wxString("Inverse Fourier"), wxString("Inverse Fourier Progress"), 1, m_frame, wxPD_APP_MODAL);
682 rIF.inverseFourier (rIF);
683 rIF.labelAdd ("Inverse Fourier Image");
684 m_bMinSpecified = false;
685 m_bMaxSpecified = false;
686 if (theApp->getSetModifyNewDocs())
687 GetDocument()->Modify(TRUE);
688 GetDocument()->UpdateAllViews(this);
692 ImageFileView::OnShuffleNaturalToFourierOrder (wxCommandEvent& event)
694 ImageFile& rIF = GetDocument()->getImageFile();
695 Fourier::shuffleNaturalToFourierOrder (rIF);
696 rIF.labelAdd ("Shuffle Natural To Fourier Order");
697 m_bMinSpecified = false;
698 m_bMaxSpecified = false;
699 if (theApp->getSetModifyNewDocs())
700 GetDocument()->Modify(TRUE);
701 GetDocument()->UpdateAllViews(this);
705 ImageFileView::OnShuffleFourierToNaturalOrder (wxCommandEvent& event)
707 ImageFile& rIF = GetDocument()->getImageFile();
708 Fourier::shuffleFourierToNaturalOrder (rIF);
709 rIF.labelAdd ("Shuffle Fourier To Natural Order");
710 m_bMinSpecified = false;
711 m_bMaxSpecified = false;
712 if (theApp->getSetModifyNewDocs())
713 GetDocument()->Modify(TRUE);
714 GetDocument()->UpdateAllViews(this);
718 ImageFileView::OnMagnitude (wxCommandEvent& event)
720 ImageFile& rIF = GetDocument()->getImageFile();
721 if (rIF.isComplex()) {
723 rIF.labelAdd ("Magnitude of complex-image");
724 m_bMinSpecified = false;
725 m_bMaxSpecified = false;
726 if (theApp->getSetModifyNewDocs())
727 GetDocument()->Modify(TRUE);
728 GetDocument()->UpdateAllViews(this);
733 ImageFileView::OnPhase (wxCommandEvent& event)
735 ImageFile& rIF = GetDocument()->getImageFile();
736 if (rIF.isComplex()) {
738 rIF.labelAdd ("Phase of complex-image");
739 m_bMinSpecified = false;
740 m_bMaxSpecified = false;
741 if (theApp->getSetModifyNewDocs())
742 GetDocument()->Modify(TRUE);
743 GetDocument()->UpdateAllViews(this);
749 ImageFileView::CreateCanvas (wxView *view, wxFrame *parent)
751 ImageFileCanvas* pCanvas;
753 parent->GetClientSize(&width, &height);
755 pCanvas = new ImageFileCanvas (dynamic_cast<ImageFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
757 pCanvas->SetScrollbars(20, 20, 50, 50);
758 pCanvas->SetBackgroundColour(*wxWHITE);
765 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
768 wxMDIChildFrame *subframe = new wxMDIChildFrame(theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
770 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
773 wxMenu *file_menu = new wxMenu;
775 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
776 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...");
777 file_menu->Append(wxID_OPEN, "&Open...");
778 file_menu->Append(wxID_SAVE, "&Save");
779 file_menu->Append(wxID_SAVEAS, "Save &As...");
780 file_menu->Append(wxID_CLOSE, "&Close");
782 file_menu->AppendSeparator();
783 file_menu->Append(IFMENU_FILE_PROPERTIES, "P&roperties");
784 file_menu->Append(IFMENU_FILE_EXPORT, "&Export...");
786 file_menu->AppendSeparator();
787 file_menu->Append(wxID_PRINT, "&Print...");
788 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
789 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
791 wxMenu *view_menu = new wxMenu;
792 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...");
793 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...");
794 view_menu->Append(IFMENU_VIEW_SCALE_FULL, "Display &Full Scale");
796 wxMenu* filter_menu = new wxMenu;
797 filter_menu->Append (IFMENU_FILTER_INVERTVALUES, "&Invert Values");
798 filter_menu->Append (IFMENU_FILTER_SQUARE, "&Square");
799 filter_menu->Append (IFMENU_FILTER_SQRT, "Square &Root");
800 filter_menu->Append (IFMENU_FILTER_LOG, "&Log");
801 filter_menu->Append (IFMENU_FILTER_EXP, "&Exp");
802 filter_menu->AppendSeparator();
804 filter_menu->Append (IFMENU_FILTER_FFT, "2D &FFT");
805 filter_menu->Append (IFMENU_FILTER_IFFT, "2D &IFFT");
806 filter_menu->Append (IFMENU_FILTER_FFT_ROWS, "FFT Rows");
807 filter_menu->Append (IFMENU_FILTER_IFFT_ROWS, "IFFT Rows");
808 filter_menu->Append (IFMENU_FILTER_FFT_COLS, "FFT Columns");
809 filter_menu->Append (IFMENU_FILTER_IFFT_COLS, "IFFT Columns");
810 filter_menu->Append (IFMENU_FILTER_FOURIER, "F&ourier");
811 filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "Inverse Fo&urier");
813 filter_menu->Append (IFMENU_FILTER_FOURIER, "&Fourier");
814 filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "&Inverse Fourier");
816 filter_menu->Append (IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, "S&huffle Fourier to Natural Order");
817 filter_menu->Append (IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, "Shu&ffle Natural to Fourier Order");
818 filter_menu->Append (IFMENU_FILTER_MAGNITUDE, "&Magnitude");
819 filter_menu->Append (IFMENU_FILTER_PHASE, "&Phase");
821 wxMenu* image_menu = new wxMenu;
822 image_menu->Append (IFMENU_IMAGE_ADD, "&Add...");
823 image_menu->Append (IFMENU_IMAGE_SUBTRACT, "&Subtract...");
824 image_menu->Append (IFMENU_IMAGE_MULTIPLY, "&Multiply...");
825 image_menu->Append (IFMENU_IMAGE_DIVIDE, "&Divide...");
826 image_menu->AppendSeparator();
827 image_menu->Append (IFMENU_IMAGE_SCALESIZE, "S&cale Size...");
829 wxMenu *analyze_menu = new wxMenu;
830 analyze_menu->Append (IFMENU_PLOT_ROW, "Plot &Row");
831 analyze_menu->Append (IFMENU_PLOT_COL, "Plot &Column");
832 analyze_menu->Append (IFMENU_PLOT_HISTOGRAM, "Plot &Histogram");
833 analyze_menu->AppendSeparator();
834 analyze_menu->Append (IFMENU_PLOT_FFT_ROW, "Plot FFT Row");
835 analyze_menu->Append (IFMENU_PLOT_FFT_COL, "Plot FFT Column");
836 analyze_menu->AppendSeparator();
837 analyze_menu->Append (IFMENU_COMPARE_IMAGES, "Compare &Images...");
838 analyze_menu->Append (IFMENU_COMPARE_ROW, "Compare &Row");
839 analyze_menu->Append (IFMENU_COMPARE_COL, "Compare &Column");
841 wxMenu *help_menu = new wxMenu;
842 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
844 wxMenuBar *menu_bar = new wxMenuBar;
846 menu_bar->Append(file_menu, "&File");
847 menu_bar->Append(view_menu, "&View");
848 menu_bar->Append(image_menu, "&Image");
849 menu_bar->Append(filter_menu, "Fi<er");
850 menu_bar->Append(analyze_menu, "&Analyze");
851 menu_bar->Append(help_menu, "&Help");
853 subframe->SetMenuBar(menu_bar);
855 subframe->Centre(wxBOTH);
862 ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
864 m_frame = CreateChildFrame(doc, this);
867 m_bMinSpecified = false;
868 m_bMaxSpecified = false;
869 m_dAutoScaleFactor = 1.;
872 m_frame->GetClientSize (&width, &height);
873 m_frame->SetTitle("ImageFileView");
874 m_canvas = CreateCanvas (this, m_frame);
876 int x, y; // X requires a forced resize
877 m_frame->GetSize(&x, &y);
878 m_frame->SetSize(-1, -1, x, y);
887 ImageFileView::OnDraw (wxDC* dc)
890 dc->DrawBitmap(m_bitmap, 0, 0, false);
892 int xCursor, yCursor;
893 if (m_canvas->GetCurrentCursor (xCursor, yCursor))
894 m_canvas->DrawRubberBandCursor (*dc, xCursor, yCursor);
899 ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
901 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
902 ImageFileArrayConst v = rIF.getArray();
905 if (v != NULL && nx != 0 && ny != 0) {
906 if (! m_bMinSpecified || ! m_bMaxSpecified) {
908 rIF.getMinMax (min, max);
909 if (! m_bMinSpecified)
911 if (! m_bMaxSpecified)
914 double scaleWidth = m_dMaxPixel - m_dMinPixel;
916 unsigned char* imageData = new unsigned char [nx * ny * 3];
917 for (int ix = 0; ix < nx; ix++) {
918 for (int iy = 0; iy < ny; iy++) {
919 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
920 int intensity = static_cast<int>(scaleValue + 0.5);
921 intensity = clamp (intensity, 0, 255);
922 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
923 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
926 wxImage image (nx, ny, imageData, true);
927 m_bitmap = image.ConvertToBitmap();
931 xSize = clamp (xSize, 0, 800);
932 ySize = clamp (ySize, 0, 800);
933 m_frame->SetClientSize (xSize, ySize);
934 m_canvas->SetScrollbars(20, 20, nx/20, ny/20);
935 m_canvas->SetBackgroundColour(*wxWHITE);
943 ImageFileView::OnClose (bool deleteWindow)
945 if (!GetDocument()->Close())
948 // m_canvas->Clear();
949 m_canvas->m_pView = NULL;
951 wxString s(theApp->GetAppName());
953 m_frame->SetTitle(s);
966 ImageFileView::OnExport (wxCommandEvent& event)
968 ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
969 ImageFileArrayConst v = rIF.getArray();
972 if (v != NULL && nx != 0 && ny != 0) {
973 if (! m_bMinSpecified || ! m_bMaxSpecified) {
975 rIF.getMinMax (min, max);
976 if (! m_bMinSpecified)
978 if (! m_bMaxSpecified)
982 DialogExportParameters dialogExport (m_frame, m_iDefaultExportFormatID);
983 if (dialogExport.ShowModal() == wxID_OK) {
984 wxString strFormatName (dialogExport.getFormatName ());
985 m_iDefaultExportFormatID = ImageFile::convertFormatNameToID (strFormatName.c_str());
988 wxString strWildcard;
989 if (m_iDefaultExportFormatID == ImageFile::FORMAT_PGM || m_iDefaultExportFormatID == ImageFile::FORMAT_PGMASCII) {
991 strWildcard = "PGM Files (*.pgm)|*.pgm";
994 else if (m_iDefaultExportFormatID == ImageFile::FORMAT_PNG || m_iDefaultExportFormatID == ImageFile::FORMAT_PNG16) {
996 strWildcard = "PNG Files (*.png)|*.png";
1000 const wxString& strFilename = wxFileSelector (wxString("Export Filename"), wxString(""),
1001 wxString(""), strExt, strWildcard, wxOVERWRITE_PROMPT | wxHIDE_READONLY | wxSAVE);
1003 rIF.exportImage (strFormatName.c_str(), strFilename.c_str(), 1, 1, m_dMinPixel, m_dMaxPixel);
1004 *theApp->getLog() << "Exported file " << strFilename << "\n";
1011 ImageFileView::OnScaleSize (wxCommandEvent& event)
1013 ImageFile& rIF = GetDocument()->getImageFile();
1014 unsigned int iOldNX = rIF.nx();
1015 unsigned int iOldNY = rIF.ny();
1017 DialogGetXYSize dialogGetXYSize (m_frame, "Set New X & Y Dimensions", iOldNX, iOldNY);
1018 if (dialogGetXYSize.ShowModal() == wxID_OK) {
1019 unsigned int iNewNX = dialogGetXYSize.getXSize();
1020 unsigned int iNewNY = dialogGetXYSize.getYSize();
1021 std::ostringstream os;
1022 os << "Scale Size from (" << iOldNX << "," << iOldNY << ") to (" << iNewNX << "," << iNewNY << ")";
1023 ImageFileDocument* pScaledDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
1025 sys_error (ERR_SEVERE, "Unable to create image file");
1028 ImageFile& rScaledIF = pScaledDoc->getImageFile();
1029 rScaledIF.setArraySize (iNewNX, iNewNY);
1030 rScaledIF.labelsCopy (rIF);
1031 rScaledIF.labelAdd (os.str().c_str());
1032 rIF.scaleImage (rScaledIF);
1033 *theApp->getLog() << os.str().c_str() << "\n";
1034 if (theApp->getSetModifyNewDocs())
1035 pScaledDoc->Modify(TRUE);
1036 pScaledDoc->UpdateAllViews (this);
1037 pScaledDoc->GetFirstView()->OnUpdate (this, NULL);
1042 ImageFileView::OnPlotRow (wxCommandEvent& event)
1044 int xCursor, yCursor;
1045 if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) {
1046 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1050 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
1051 ImageFileArrayConst v = rIF.getArray();
1055 if (v != NULL && yCursor < ny) {
1056 double* pX = new double [nx];
1057 double* pY = new double [nx];
1058 for (int i = 0; i < nx; i++) {
1060 pY[i] = v[i][yCursor];
1062 PlotFileDocument* pPlotDoc = dynamic_cast<PlotFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.plt", wxDOC_SILENT));
1064 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1066 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1067 std::ostringstream os;
1068 os << "Row " << yCursor;
1069 std::string title("title ");
1071 rPlotFile.addEzsetCommand (title.c_str());
1072 rPlotFile.addEzsetCommand ("xlabel Column");
1073 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1074 rPlotFile.addEzsetCommand ("lxfrac 0");
1075 rPlotFile.addEzsetCommand ("box");
1076 rPlotFile.addEzsetCommand ("grid");
1077 rPlotFile.setCurveSize (2, nx);
1078 rPlotFile.addColumn (0, pX);
1079 rPlotFile.addColumn (1, pY);
1083 if (theApp->getSetModifyNewDocs())
1084 pPlotDoc->Modify(true);
1085 pPlotDoc->UpdateAllViews();
1090 ImageFileView::OnPlotCol (wxCommandEvent& event)
1092 int xCursor, yCursor;
1093 if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) {
1094 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1098 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
1099 ImageFileArrayConst v = rIF.getArray();
1103 if (v != NULL && xCursor < nx) {
1104 double* pX = new double [ny];
1105 double* pY = new double [ny];
1106 for (int i = 0; i < ny; i++) {
1108 pY[i] = v[xCursor][i];
1110 PlotFileDocument* pPlotDoc = dynamic_cast<PlotFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.plt", wxDOC_SILENT));
1112 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1114 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1115 std::ostringstream os;
1116 os << "Column " << xCursor;
1117 std::string title("title ");
1119 rPlotFile.addEzsetCommand (title.c_str());
1120 rPlotFile.addEzsetCommand ("xlabel Row");
1121 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1122 rPlotFile.addEzsetCommand ("lxfrac 0");
1123 rPlotFile.addEzsetCommand ("box");
1124 rPlotFile.addEzsetCommand ("grid");
1125 rPlotFile.setCurveSize (2, nx);
1126 rPlotFile.addColumn (0, pX);
1127 rPlotFile.addColumn (1, pY);
1131 if (theApp->getSetModifyNewDocs())
1132 pPlotDoc->Modify(true);
1133 pPlotDoc->UpdateAllViews();
1139 ImageFileView::OnPlotFFTRow (wxCommandEvent& event)
1141 int xCursor, yCursor;
1142 if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) {
1143 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1147 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
1148 ImageFileArrayConst v = rIF.getArray();
1149 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1153 if (v != NULL && yCursor < ny) {
1154 fftw_complex* pcIn = new fftw_complex [nx];
1157 for (i = 0; i < nx; i++) {
1158 pcIn[i].re = v[i][yCursor];
1159 if (rIF.isComplex())
1160 pcIn[i].im = vImag[i][yCursor];
1165 fftw_plan plan = fftw_create_plan (nx, FFTW_FORWARD, FFTW_IN_PLACE);
1166 fftw_one (plan, pcIn, NULL);
1167 fftw_destroy_plan (plan);
1169 double* pX = new double [nx];
1170 double* pYReal = new double [nx];
1171 double* pYImag = new double [nx];
1172 double* pYMag = new double [nx];
1173 for (i = 0; i < nx; i++) {
1175 pYReal[i] = pcIn[i].re;
1176 pYImag[i] = pcIn[i].im;
1177 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1179 Fourier::shuffleFourierToNaturalOrder (pYReal, nx);
1180 Fourier::shuffleFourierToNaturalOrder (pYImag, nx);
1181 Fourier::shuffleFourierToNaturalOrder (pYMag, nx);
1183 PlotFileDocument* pPlotDoc = dynamic_cast<PlotFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.plt", wxDOC_SILENT));
1185 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1187 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1188 std::ostringstream os;
1189 os << "Row " << yCursor;
1190 std::string title("title ");
1192 rPlotFile.addEzsetCommand (title.c_str());
1193 rPlotFile.addEzsetCommand ("xlabel Column");
1194 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1195 rPlotFile.addEzsetCommand ("lxfrac 0");
1196 rPlotFile.addEzsetCommand ("curve 1");
1197 rPlotFile.addEzsetCommand ("color 1");
1198 rPlotFile.addEzsetCommand ("curve 2");
1199 rPlotFile.addEzsetCommand ("color 2");
1200 rPlotFile.addEzsetCommand ("dash 1");
1201 rPlotFile.addEzsetCommand ("curve 3");
1202 rPlotFile.addEzsetCommand ("dash 2");
1203 rPlotFile.addEzsetCommand ("color 3");
1204 rPlotFile.addEzsetCommand ("box");
1205 rPlotFile.addEzsetCommand ("grid");
1206 rPlotFile.setCurveSize (2, nx);
1207 rPlotFile.addColumn (0, pX);
1208 rPlotFile.addColumn (1, pYReal);
1209 rPlotFile.addColumn (2, pYImag);
1210 rPlotFile.addColumn (3, pYMag);
1218 if (theApp->getSetModifyNewDocs())
1219 pPlotDoc->Modify(true);
1220 pPlotDoc->UpdateAllViews();
1225 ImageFileView::OnPlotFFTCol (wxCommandEvent& event)
1227 int xCursor, yCursor;
1228 if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) {
1229 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1233 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
1234 ImageFileArrayConst v = rIF.getArray();
1238 if (v != NULL && xCursor < nx) {
1239 double* pX = new double [ny];
1240 double* pY = new double [ny];
1241 for (int i = 0; i < ny; i++) {
1243 pY[i] = v[xCursor][i];
1245 PlotFileDocument* pPlotDoc = dynamic_cast<PlotFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.plt", wxDOC_SILENT));
1247 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1249 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1250 std::ostringstream os;
1251 os << "Column " << xCursor;
1252 std::string title("title ");
1254 rPlotFile.addEzsetCommand (title.c_str());
1255 rPlotFile.addEzsetCommand ("xlabel Row");
1256 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1257 rPlotFile.addEzsetCommand ("lxfrac 0");
1258 rPlotFile.addEzsetCommand ("box");
1259 rPlotFile.addEzsetCommand ("grid");
1260 rPlotFile.setCurveSize (2, nx);
1261 rPlotFile.addColumn (0, pX);
1262 rPlotFile.addColumn (1, pY);
1266 if (theApp->getSetModifyNewDocs())
1267 pPlotDoc->Modify(true);
1268 pPlotDoc->UpdateAllViews();
1274 ImageFileView::OnCompareCol (wxCommandEvent& event)
1276 int xCursor, yCursor;
1277 if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) {
1278 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1282 std::vector<ImageFileDocument*> vecIFDoc;
1283 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1284 if (vecIFDoc.size() == 0) {
1285 wxMessageBox ("No compatible images for Column Comparison", "Error");
1288 DialogGetComparisonImage dialogGetCompare (m_frame, "Get Comparison Image", vecIFDoc, false);
1290 if (dialogGetCompare.ShowModal() == wxID_OK) {
1291 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1292 const ImageFile& rIF = GetDocument()->getImageFile();
1293 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1295 ImageFileArrayConst v1 = rIF.getArray();
1296 ImageFileArrayConst v2 = rCompareIF.getArray();
1300 if (v1 != NULL && xCursor < nx) {
1301 double* pX = new double [ny];
1302 double* pY1 = new double [ny];
1303 double* pY2 = new double [ny];
1304 for (int i = 0; i < ny; i++) {
1306 pY1[i] = v1[xCursor][i];
1307 pY2[i] = v2[xCursor][i];
1309 PlotFileDocument* pPlotDoc = dynamic_cast<PlotFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.plt", wxDOC_SILENT));
1311 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1313 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1314 std::ostringstream os;
1315 os << "Column " << xCursor << " Comparison";
1316 std::string title("title ");
1318 rPlotFile.addEzsetCommand (title.c_str());
1319 rPlotFile.addEzsetCommand ("xlabel Row");
1320 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1321 rPlotFile.addEzsetCommand ("lxfrac 0");
1322 rPlotFile.addEzsetCommand ("curve 1");
1323 rPlotFile.addEzsetCommand ("color 2");
1324 rPlotFile.addEzsetCommand ("curve 2");
1325 rPlotFile.addEzsetCommand ("color 4");
1326 rPlotFile.addEzsetCommand ("dash 5");
1327 rPlotFile.addEzsetCommand ("box");
1328 rPlotFile.addEzsetCommand ("grid");
1329 rPlotFile.setCurveSize (3, nx);
1330 rPlotFile.addColumn (0, pX);
1331 rPlotFile.addColumn (1, pY1);
1332 rPlotFile.addColumn (2, pY2);
1337 if (theApp->getSetModifyNewDocs())
1338 pPlotDoc->Modify(true);
1339 pPlotDoc->UpdateAllViews();
1345 ImageFileView::OnCompareRow (wxCommandEvent& event)
1347 int xCursor, yCursor;
1348 if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) {
1349 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1353 std::vector<ImageFileDocument*> vecIFDoc;
1354 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1356 if (vecIFDoc.size() == 0) {
1357 wxMessageBox ("No compatible images for Row Comparison", "Error");
1361 DialogGetComparisonImage dialogGetCompare (m_frame, "Get Comparison Image", vecIFDoc, false);
1363 if (dialogGetCompare.ShowModal() == wxID_OK) {
1364 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1365 const ImageFile& rIF = GetDocument()->getImageFile();
1366 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1368 ImageFileArrayConst v1 = rIF.getArray();
1369 ImageFileArrayConst v2 = rCompareIF.getArray();
1373 if (v1 != NULL && yCursor < ny) {
1374 double* pX = new double [nx];
1375 double* pY1 = new double [nx];
1376 double* pY2 = new double [nx];
1377 for (int i = 0; i < nx; i++) {
1379 pY1[i] = v1[i][yCursor];
1380 pY2[i] = v2[i][yCursor];
1382 PlotFileDocument* pPlotDoc = dynamic_cast<PlotFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.plt", wxDOC_SILENT));
1384 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1386 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1387 std::ostringstream os;
1388 os << "Row " << yCursor << " Comparison";
1389 std::string title("title ");
1391 rPlotFile.addEzsetCommand (title.c_str());
1392 rPlotFile.addEzsetCommand ("xlabel Column");
1393 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1394 rPlotFile.addEzsetCommand ("lxfrac 0");
1395 rPlotFile.addEzsetCommand ("curve 1");
1396 rPlotFile.addEzsetCommand ("color 2");
1397 rPlotFile.addEzsetCommand ("curve 2");
1398 rPlotFile.addEzsetCommand ("color 4");
1399 rPlotFile.addEzsetCommand ("dash 5");
1400 rPlotFile.addEzsetCommand ("box");
1401 rPlotFile.addEzsetCommand ("grid");
1402 rPlotFile.setCurveSize (3, ny);
1403 rPlotFile.addColumn (0, pX);
1404 rPlotFile.addColumn (1, pY1);
1405 rPlotFile.addColumn (2, pY2);
1410 if (theApp->getSetModifyNewDocs())
1411 pPlotDoc->Modify(true);
1412 pPlotDoc->UpdateAllViews();
1417 static int NUMBER_HISTOGRAM_BINS = 256;
1420 ImageFileView::OnPlotHistogram (wxCommandEvent& event)
1422 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
1423 ImageFileArrayConst v = rIF.getArray();
1427 if (v != NULL && nx > 0 && ny > 0) {
1428 PlotFileDocument* pPlotDoc = dynamic_cast<PlotFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.plt", wxDOC_SILENT));
1430 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1434 double* pX = new double [NUMBER_HISTOGRAM_BINS];
1435 double* pY = new double [NUMBER_HISTOGRAM_BINS];
1437 rIF.getMinMax (dMin, dMax);
1438 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
1440 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
1441 pX[i] = dMin + (i + 0.5) * dBinWidth;
1444 for (int ix = 0; ix < nx; ix++)
1445 for (int iy = 0; iy < ny; iy++) {
1446 int iBin = nearest<int> ((v[ix][iy] - dMin) / dBinWidth);
1447 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
1451 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1452 std::ostringstream os;
1454 std::string title("title ");
1456 rPlotFile.addEzsetCommand (title.c_str());
1457 rPlotFile.addEzsetCommand ("xlabel Pixel Value");
1458 rPlotFile.addEzsetCommand ("ylabel Count");
1459 rPlotFile.addEzsetCommand ("box");
1460 rPlotFile.addEzsetCommand ("grid");
1461 rPlotFile.setCurveSize (2, nx);
1462 rPlotFile.addColumn (0, pX);
1463 rPlotFile.addColumn (1, pY);
1466 if (theApp->getSetModifyNewDocs())
1467 pPlotDoc->Modify(true);
1468 pPlotDoc->UpdateAllViews();
1475 PhantomCanvas::PhantomCanvas (PhantomView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1476 : wxScrolledWindow(frame, -1, pos, size, style)
1482 PhantomCanvas::OnDraw (wxDC& dc)
1485 m_pView->OnDraw(& dc);
1491 IMPLEMENT_DYNAMIC_CLASS(PhantomView, wxView)
1493 BEGIN_EVENT_TABLE(PhantomView, wxView)
1494 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomView::OnProperties)
1495 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomView::OnRasterize)
1496 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomView::OnProjections)
1499 PhantomView::PhantomView(void)
1500 : wxView(), m_canvas(NULL), m_frame(NULL)
1502 m_iDefaultNDet = 367;
1503 m_iDefaultNView = 320;
1504 m_iDefaultNSample = 2;
1505 m_dDefaultRotation = 1;
1506 m_dDefaultFocalLength = 2;
1507 m_dDefaultFieldOfView = 1;
1508 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
1509 m_iDefaultTrace = Trace::TRACE_NONE;
1511 m_iDefaultRasterNX = 256;
1512 m_iDefaultRasterNY = 256;
1513 m_iDefaultRasterNSamples = 2;
1516 PhantomView::~PhantomView(void)
1521 PhantomView::OnProperties (wxCommandEvent& event)
1523 const int idPhantom = GetDocument()->getPhantomID();
1524 const wxString& namePhantom = GetDocument()->getPhantomName();
1525 std::ostringstream os;
1526 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")" << "\n";
1527 const Phantom& rPhantom = GetDocument()->getPhantom();
1528 rPhantom.printDefinitions (os);
1530 rPhantom.print (os);
1532 *theApp->getLog() << os.str().c_str() << "\n";
1533 wxMessageBox (os.str().c_str(), "Phantom Properties");
1538 PhantomView::OnProjections (wxCommandEvent& event)
1540 DialogGetProjectionParameters dialogProjection (m_frame, m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView, m_iDefaultGeometry, m_iDefaultTrace);
1541 int retVal = dialogProjection.ShowModal();
1542 if (retVal == wxID_OK) {
1543 m_iDefaultNDet = dialogProjection.getNDet();
1544 m_iDefaultNView = dialogProjection.getNView();
1545 m_iDefaultNSample = dialogProjection.getNSamples();
1546 m_iDefaultTrace = dialogProjection.getTrace();
1547 m_dDefaultRotation = dialogProjection.getRotAngle();
1548 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
1549 m_dDefaultFieldOfView = dialogProjection.getFieldOfViewRatio();
1550 wxString sGeometry = dialogProjection.getGeometry();
1551 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
1553 if (m_iDefaultNDet > 0 && m_iDefaultNView > 0 && sGeometry != "") {
1554 const Phantom& rPhantom = GetDocument()->getPhantom();
1555 ProjectionFileDocument* pProjectionDoc = dynamic_cast<ProjectionFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.pj", wxDOC_SILENT));
1556 if (! pProjectionDoc) {
1557 sys_error (ERR_SEVERE, "Unable to create projection document");
1560 Projections& rProj = pProjectionDoc->getProjections();
1561 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView);
1562 if (theScanner.fail()) {
1563 *theApp->getLog() << "Failed making scanner: " << theScanner.failMessage().c_str() << "\n";
1566 rProj.initFromScanner (theScanner);
1567 m_dDefaultRotation /= PI; // convert back to PI units
1570 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
1571 ProjectionsDialog dialogProjections (theScanner, rProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(m_frame));
1572 for (int iView = 0; iView < rProj.nView(); iView++) {
1575 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
1576 pProjectionDoc->DeleteAllViews();
1581 while (dialogProjections.isPaused()) {
1587 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), rProj.nView() + 1, m_frame, wxPD_CAN_ABORT);
1588 for (int i = 0; i < rProj.nView(); i++) {
1589 theScanner.collectProjections (rProj, rPhantom, i, 1, true, m_iDefaultTrace);
1590 if (! dlgProgress.Update (i+1)) {
1591 pProjectionDoc->DeleteAllViews();
1597 std::ostringstream os;
1598 os << "Projections for " << rPhantom.name() << ": nDet=" << m_iDefaultNDet << ", nView=" << m_iDefaultNView << ", nSamples=" << m_iDefaultNSample << ", RotAngle=" << m_dDefaultRotation << ", FocalLengthRatio=" << m_dDefaultFocalLength << ", FieldOfViewRatio=" << m_dDefaultFieldOfView << ", Geometry=" << sGeometry.c_str();
1599 rProj.setCalcTime (timer.timerEnd());
1600 rProj.setRemark (os.str());
1601 *theApp->getLog() << os.str().c_str() << "\n";
1605 ProjectionFileView* projView = dynamic_cast<ProjectionFileView*>(pProjectionDoc->GetFirstView());
1607 projView->getFrame()->SetFocus();
1608 projView->OnUpdate (projView, NULL);
1610 if (wxView* pView = pProjectionDoc->GetFirstView()) {
1611 if (wxFrame* pFrame = pView->GetFrame()) {
1615 theApp->getDocManager()->ActivateView (pView, true, false);
1618 if (theApp->getSetModifyNewDocs())
1619 pProjectionDoc->Modify(true);
1620 pProjectionDoc->UpdateAllViews(this);
1627 PhantomView::OnRasterize (wxCommandEvent& event)
1629 DialogGetRasterParameters dialogRaster (m_frame, m_iDefaultRasterNX, m_iDefaultRasterNY, m_iDefaultRasterNSamples);
1630 int retVal = dialogRaster.ShowModal();
1631 if (retVal == wxID_OK) {
1632 m_iDefaultRasterNX = dialogRaster.getXSize();
1633 m_iDefaultRasterNY = dialogRaster.getYSize();
1634 m_iDefaultRasterNSamples = dialogRaster.getNSamples();
1635 if (m_iDefaultRasterNSamples < 1)
1636 m_iDefaultRasterNSamples = 1;
1637 if (m_iDefaultRasterNX > 0 && m_iDefaultRasterNY > 0) {
1638 const Phantom& rPhantom = GetDocument()->getPhantom();
1639 ImageFileDocument* pRasterDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
1641 sys_error (ERR_SEVERE, "Unable to create image file");
1644 ImageFile& imageFile = pRasterDoc->getImageFile();
1646 imageFile.setArraySize (m_iDefaultRasterNX, m_iDefaultRasterNX);
1647 wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"), imageFile.nx() + 1, m_frame, wxPD_CAN_ABORT);
1649 for (unsigned int i = 0; i < imageFile.nx(); i++) {
1650 rPhantom.convertToImagefile (imageFile, m_iDefaultRasterNSamples, Trace::TRACE_NONE, i, 1, true);
1651 if (! dlgProgress.Update(i+1)) {
1652 pRasterDoc->DeleteAllViews();
1656 if (theApp->getSetModifyNewDocs())
1657 pRasterDoc->Modify(true);
1658 pRasterDoc->UpdateAllViews(this);
1659 std::ostringstream os;
1660 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << m_iDefaultRasterNX << ", YSize="
1661 << m_iDefaultRasterNY << ", nSamples=" << m_iDefaultRasterNSamples;
1662 *theApp->getLog() << os.str().c_str() << "\n";
1663 imageFile.labelAdd (os.str().c_str(), timer.timerEnd());
1664 ImageFileView* rasterView = dynamic_cast<ImageFileView*>(pRasterDoc->GetFirstView());
1666 rasterView->getFrame()->SetFocus();
1667 rasterView->OnUpdate (rasterView, NULL);
1676 PhantomView::CreateCanvas (wxView *view, wxFrame *parent)
1678 PhantomCanvas* pCanvas;
1680 parent->GetClientSize(&width, &height);
1682 pCanvas = new PhantomCanvas (dynamic_cast<PhantomView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
1684 pCanvas->SetBackgroundColour(*wxWHITE);
1691 PhantomView::CreateChildFrame(wxDocument *doc, wxView *view)
1694 wxMDIChildFrame *subframe = new wxMDIChildFrame(theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
1696 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
1699 wxMenu *file_menu = new wxMenu;
1701 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
1702 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...");
1703 file_menu->Append(wxID_OPEN, "&Open...");
1704 file_menu->Append(wxID_SAVEAS, "Save &As...");
1705 file_menu->Append(wxID_CLOSE, "&Close");
1707 file_menu->AppendSeparator();
1708 file_menu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties");
1710 file_menu->AppendSeparator();
1711 file_menu->Append(wxID_PRINT, "&Print...");
1712 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
1713 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
1715 wxMenu *process_menu = new wxMenu;
1716 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...");
1717 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...");
1719 wxMenu *help_menu = new wxMenu;
1720 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
1721 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
1723 wxMenuBar *menu_bar = new wxMenuBar;
1725 menu_bar->Append(file_menu, "&File");
1726 menu_bar->Append(process_menu, "&Process");
1727 menu_bar->Append(help_menu, "&Help");
1729 subframe->SetMenuBar(menu_bar);
1731 subframe->Centre(wxBOTH);
1738 PhantomView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
1740 m_frame = CreateChildFrame(doc, this);
1744 m_frame->GetClientSize(&width, &height);
1745 m_frame->SetTitle("PhantomView");
1746 m_canvas = CreateCanvas(this, m_frame);
1749 int x, y; // X requires a forced resize
1750 m_frame->GetSize(&x, &y);
1751 m_frame->SetSize(-1, -1, x, y);
1754 m_frame->Show(true);
1762 PhantomView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
1765 m_canvas->Refresh();
1769 PhantomView::OnClose (bool deleteWindow)
1771 if (!GetDocument()->Close())
1774 // m_canvas->Clear();
1775 m_canvas->m_pView = NULL;
1777 // wxString s(wxTheApp->GetAppName());
1779 // m_frame->SetTitle(s);
1793 PhantomView::OnDraw (wxDC* dc)
1796 m_canvas->GetClientSize (&xsize, &ysize);
1797 SGPDriver driver (dc, xsize, ysize);
1799 const Phantom& rPhantom = GetDocument()->getPhantom();
1800 sgp.setColor (C_RED);
1801 rPhantom.show (sgp);
1806 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1807 : wxScrolledWindow(frame, -1, pos, size, style)
1813 ProjectionFileCanvas::OnDraw(wxDC& dc)
1816 m_pView->OnDraw(& dc);
1819 // ProjectionFileView
1821 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
1823 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
1824 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
1825 EVT_MENU(PJMENU_RECONSTRUCT_FBP, ProjectionFileView::OnReconstructFBP)
1826 EVT_MENU(PJMENU_CONVERT_POLAR, ProjectionFileView::OnConvertPolar)
1827 EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
1830 ProjectionFileView::ProjectionFileView(void)
1831 : wxView(), m_canvas(NULL), m_frame(NULL)
1835 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
1836 m_dDefaultFilterParam = 1.;
1838 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
1839 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
1841 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
1842 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
1844 m_iDefaultZeropad = 1;
1845 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF3;
1846 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
1847 m_iDefaultInterpParam = 1;
1848 m_iDefaultTrace = Trace::TRACE_NONE;
1850 m_iDefaultPolarNX = 256;
1851 m_iDefaultPolarNY = 256;
1852 m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR;
1853 m_iDefaultPolarZeropad = 1;
1856 ProjectionFileView::~ProjectionFileView(void)
1861 ProjectionFileView::OnProperties (wxCommandEvent& event)
1863 const Projections& rProj = GetDocument()->getProjections();
1864 std::ostringstream os;
1865 rProj.printScanInfo(os);
1866 *theApp->getLog() << os.str().c_str();
1867 wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
1868 dialogMsg.ShowModal();
1873 ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
1875 Projections& rProj = GetDocument()->getProjections();
1876 DialogGetConvertPolarParameters dialogPolar (m_frame, "Convert Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
1877 m_iDefaultPolarInterpolation, -1);
1878 if (dialogPolar.ShowModal() == wxID_OK) {
1879 wxString strInterpolation (dialogPolar.getInterpolationName());
1880 m_iDefaultPolarNX = dialogPolar.getXSize();
1881 m_iDefaultPolarNY = dialogPolar.getYSize();
1882 ImageFileDocument* pPolarDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
1883 ImageFile& rIF = pPolarDoc->getImageFile();
1885 sys_error (ERR_SEVERE, "Unable to create image file");
1888 rIF.setArraySize (m_iDefaultPolarNX, m_iDefaultPolarNY);
1889 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
1890 rProj.convertPolar (rIF, m_iDefaultPolarInterpolation);
1891 rIF.labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
1892 std::ostringstream os;
1893 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to polar image: xSize="
1894 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
1895 << strInterpolation.c_str();
1896 *theApp->getLog() << os.str().c_str() << "\n";
1897 rIF.labelAdd (os.str().c_str());
1898 if (theApp->getSetModifyNewDocs())
1899 pPolarDoc->Modify(true);
1900 pPolarDoc->UpdateAllViews();
1901 pPolarDoc->GetFirstView()->OnUpdate (this, NULL);
1906 ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
1908 Projections& rProj = GetDocument()->getProjections();
1909 DialogGetConvertPolarParameters dialogPolar (m_frame, "Convert to FFT Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
1910 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad);
1911 if (dialogPolar.ShowModal() == wxID_OK) {
1912 wxString strInterpolation (dialogPolar.getInterpolationName());
1913 m_iDefaultPolarNX = dialogPolar.getXSize();
1914 m_iDefaultPolarNY = dialogPolar.getYSize();
1915 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
1916 ImageFileDocument* pPolarDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
1917 ImageFile& rIF = pPolarDoc->getImageFile();
1919 sys_error (ERR_SEVERE, "Unable to create image file");
1922 rIF.setArraySize (m_iDefaultPolarNX, m_iDefaultPolarNY);
1923 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
1924 rProj.convertFFTPolar (rIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad);
1925 rIF.labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
1926 std::ostringstream os;
1927 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to FFT polar image: xSize="
1928 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
1929 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
1930 *theApp->getLog() << os.str().c_str() << "\n";
1931 rIF.labelAdd (os.str().c_str());
1932 if (theApp->getSetModifyNewDocs())
1933 pPolarDoc->Modify(true);
1934 pPolarDoc->UpdateAllViews();
1935 pPolarDoc->GetFirstView()->OnUpdate (this, NULL);
1939 ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
1941 wxMessageBox ("Fourier Reconstruction is not yet supported", "Unimplemented function");
1945 ProjectionFileView::OnReconstructFBP (wxCommandEvent& event)
1947 DialogGetReconstructionParameters dialogReconstruction (m_frame, m_iDefaultNX, m_iDefaultNY, m_iDefaultFilter, m_dDefaultFilterParam, m_iDefaultFilterMethod, m_iDefaultFilterGeneration, m_iDefaultZeropad, m_iDefaultInterpolation, m_iDefaultInterpParam, m_iDefaultBackprojector, m_iDefaultTrace);
1949 int retVal = dialogReconstruction.ShowModal();
1950 if (retVal == wxID_OK) {
1951 m_iDefaultNX = dialogReconstruction.getXSize();
1952 m_iDefaultNY = dialogReconstruction.getYSize();
1953 wxString optFilterName = dialogReconstruction.getFilterName();
1954 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
1955 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
1956 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
1957 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
1958 m_iDefaultZeropad = dialogReconstruction.getZeropad();
1959 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
1960 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
1961 wxString optInterpName = dialogReconstruction.getInterpName();
1962 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
1963 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
1964 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
1965 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
1966 m_iDefaultTrace = dialogReconstruction.getTrace();
1967 if (m_iDefaultNX > 0 && m_iDefaultNY > 0) {
1968 ImageFileDocument* pReconDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
1970 sys_error (ERR_SEVERE, "Unable to create image file");
1973 ImageFile& imageFile = pReconDoc->getImageFile();
1974 const Projections& rProj = GetDocument()->getProjections();
1975 imageFile.setArraySize (m_iDefaultNX, m_iDefaultNY);
1977 if (m_iDefaultFilterMethod != ProcessSignal::FILTER_METHOD_CONVOLUTION && m_iDefaultFilterGeneration == ProcessSignal::FILTER_GENERATION_DIRECT && rProj.geometry() != Scanner::GEOMETRY_PARALLEL) {
1978 wxMessageBox ("Sorry!\nCurrently, frequency-based filtering with direct filter generation is not support for geometries other than parallel.\nAborting command.", "Not Supported", wxOK | wxICON_WARNING, m_frame);
1982 Reconstructor* pReconstruct = new Reconstructor (rProj, imageFile, optFilterName.c_str(), m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(), optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace);
1985 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
1986 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstruct, rProj, imageFile, m_iDefaultTrace, m_frame);
1987 for (int iView = 0; iView < rProj.nView(); iView++) {
1990 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView)) {
1991 delete pDlgReconstruct;
1992 delete pReconstruct;
1993 pReconDoc->DeleteAllViews();
1998 while (pDlgReconstruct->isPaused()) {
2003 delete pDlgReconstruct;
2005 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, m_frame, wxPD_CAN_ABORT);
2006 for (int i = 0; i < rProj.nView(); i++) {
2007 pReconstruct->reconstructView (i, 1);
2008 if (! dlgProgress.Update(i + 1)) {
2009 delete pReconstruct;
2010 pReconDoc->DeleteAllViews();
2015 delete pReconstruct;
2016 if (theApp->getSetModifyNewDocs())
2017 pReconDoc->Modify(true);
2018 pReconDoc->UpdateAllViews(this);
2019 ImageFileView* rasterView = dynamic_cast<ImageFileView*>(pReconDoc->GetFirstView());
2021 rasterView->getFrame()->SetFocus();
2022 rasterView->OnUpdate (rasterView, NULL);
2024 std::ostringstream os;
2025 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();
2026 *theApp->getLog() << os.str().c_str() << "\n";
2027 imageFile.labelAdd (rProj.getLabel());
2028 imageFile.labelAdd (os.str().c_str(), timerRecon.timerEnd());
2034 ProjectionFileCanvas*
2035 ProjectionFileView::CreateCanvas (wxView *view, wxFrame *parent)
2037 ProjectionFileCanvas* pCanvas;
2039 parent->GetClientSize(&width, &height);
2041 pCanvas = new ProjectionFileCanvas (dynamic_cast<ProjectionFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
2043 pCanvas->SetScrollbars(20, 20, 50, 50);
2044 pCanvas->SetBackgroundColour(*wxWHITE);
2051 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2054 wxMDIChildFrame *subframe = new wxMDIChildFrame (theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2056 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2059 wxMenu *file_menu = new wxMenu;
2061 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
2062 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...");
2063 file_menu->Append(wxID_OPEN, "&Open...");
2064 file_menu->Append(wxID_SAVE, "&Save");
2065 file_menu->Append(wxID_SAVEAS, "Save &As...");
2066 file_menu->Append(wxID_CLOSE, "&Close");
2068 file_menu->AppendSeparator();
2069 file_menu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
2071 file_menu->AppendSeparator();
2072 file_menu->Append(wxID_PRINT, "&Print...");
2073 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2074 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
2076 wxMenu *convert_menu = new wxMenu;
2077 convert_menu->Append (PJMENU_CONVERT_POLAR, "&Polar Image...");
2078 convert_menu->Append (PJMENU_CONVERT_FFT_POLAR, "&FFT->Polar Image...");
2080 wxMenu *reconstruct_menu = new wxMenu;
2081 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP, "&Filtered Backprojection...");
2082 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Fourier...");
2084 wxMenu *help_menu = new wxMenu;
2085 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
2086 help_menu->AppendSeparator();
2087 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2089 wxMenuBar *menu_bar = new wxMenuBar;
2091 menu_bar->Append (file_menu, "&File");
2092 menu_bar->Append (convert_menu, "&Convert");
2093 menu_bar->Append (reconstruct_menu, "&Reconstruct");
2094 menu_bar->Append (help_menu, "&Help");
2096 subframe->SetMenuBar(menu_bar);
2098 subframe->Centre(wxBOTH);
2105 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2107 m_frame = CreateChildFrame(doc, this);
2111 m_frame->GetClientSize(&width, &height);
2112 m_frame->SetTitle("ProjectionFileView");
2113 m_canvas = CreateCanvas(this, m_frame);
2116 int x, y; // X requires a forced resize
2117 m_frame->GetSize(&x, &y);
2118 m_frame->SetSize(-1, -1, x, y);
2121 m_frame->Show(true);
2128 ProjectionFileView::OnDraw (wxDC* dc)
2131 dc->DrawBitmap (m_bitmap, 0, 0, false);
2136 ProjectionFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2138 const Projections& rProj = GetDocument()->getProjections();
2139 const int nDet = rProj.nDet();
2140 const int nView = rProj.nView();
2141 if (nDet != 0 && nView != 0) {
2142 const DetectorArray& detarray = rProj.getDetectorArray(0);
2143 const DetectorValue* detval = detarray.detValues();
2144 double min = detval[0];
2145 double max = detval[0];
2146 for (int iy = 0; iy < nView; iy++) {
2147 const DetectorArray& detarray = rProj.getDetectorArray(iy);
2148 const DetectorValue* detval = detarray.detValues();
2149 for (int ix = 0; ix < nDet; ix++) {
2150 if (min > detval[ix])
2152 else if (max < detval[ix])
2157 unsigned char* imageData = new unsigned char [nDet * nView * 3];
2158 double scale = (max - min) / 255;
2159 for (int iy2 = 0; iy2 < nView; iy2++) {
2160 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
2161 const DetectorValue* detval = detarray.detValues();
2162 for (int ix = 0; ix < nDet; ix++) {
2163 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
2164 intensity = clamp(intensity, 0, 255);
2165 int baseAddr = (iy2 * nDet + ix) * 3;
2166 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
2169 wxImage image (nDet, nView, imageData, true);
2170 m_bitmap = image.ConvertToBitmap();
2174 xSize = clamp (xSize, 0, 800);
2175 ySize = clamp (ySize, 0, 800);
2176 m_frame->SetClientSize (xSize, ySize);
2177 m_canvas->SetScrollbars (20, 20, nDet/20, nView/20);
2181 m_canvas->Refresh();
2185 ProjectionFileView::OnClose (bool deleteWindow)
2187 if (!GetDocument()->Close())
2190 // m_canvas->Clear();
2191 m_canvas->m_pView = NULL;
2193 wxString s(wxTheApp->GetAppName());
2195 m_frame->SetTitle(s);
2210 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2211 : wxScrolledWindow(frame, -1, pos, size, style)
2217 PlotFileCanvas::OnDraw(wxDC& dc)
2220 m_pView->OnDraw(& dc);
2226 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
2228 BEGIN_EVENT_TABLE(PlotFileView, wxView)
2229 EVT_MENU(PJMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
2230 EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
2231 EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
2232 EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
2235 PlotFileView::PlotFileView(void)
2236 : wxView(), m_canvas(NULL), m_frame(NULL), m_pEZPlot(NULL)
2238 m_bMinSpecified = false;
2239 m_bMaxSpecified = false;
2242 PlotFileView::~PlotFileView(void)
2249 PlotFileView::OnProperties (wxCommandEvent& event)
2251 const PlotFile& rPlot = GetDocument()->getPlotFile();
2252 std::ostringstream os;
2253 os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
2254 rPlot.printHeaders (os);
2255 *theApp->getLog() << os.str().c_str();
2256 wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
2257 dialogMsg.ShowModal();
2262 PlotFileView::OnScaleAuto (wxCommandEvent& event)
2264 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2265 double min, max, mean, mode, median, stddev;
2266 rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
2267 DialogAutoScaleParameters dialogAutoScale (m_frame, mean, mode, median, stddev, m_dAutoScaleFactor);
2268 int iRetVal = dialogAutoScale.ShowModal();
2269 if (iRetVal == wxID_OK) {
2270 m_bMinSpecified = true;
2271 m_bMaxSpecified = true;
2273 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
2276 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
2277 OnUpdate (this, NULL);
2283 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
2285 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2289 if (! m_bMinSpecified || ! m_bMaxSpecified) {
2290 if (! rPlotFile.getMinMax (1, min, max)) {
2291 *theApp->getLog() << "Error: unable to find Min/Max\n";
2296 if (m_bMinSpecified)
2298 if (m_bMaxSpecified)
2301 DialogGetMinMax dialogMinMax (m_frame, "Set Y-axis Minimum & Maximum", min, max);
2302 int retVal = dialogMinMax.ShowModal();
2303 if (retVal == wxID_OK) {
2304 m_bMinSpecified = true;
2305 m_bMaxSpecified = true;
2306 m_dMinPixel = dialogMinMax.getMinimum();
2307 m_dMaxPixel = dialogMinMax.getMaximum();
2308 OnUpdate (this, NULL);
2313 PlotFileView::OnScaleFull (wxCommandEvent& event)
2315 if (m_bMinSpecified || m_bMaxSpecified) {
2316 m_bMinSpecified = false;
2317 m_bMaxSpecified = false;
2318 OnUpdate (this, NULL);
2324 PlotFileView::CreateCanvas (wxView *view, wxFrame *parent)
2326 PlotFileCanvas* pCanvas;
2328 parent->GetClientSize(&width, &height);
2330 pCanvas = new PlotFileCanvas (dynamic_cast<PlotFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
2332 pCanvas->SetBackgroundColour(*wxWHITE);
2339 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2342 wxMDIChildFrame *subframe = new wxMDIChildFrame (theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2344 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2347 wxMenu *file_menu = new wxMenu;
2349 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
2350 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...");
2351 file_menu->Append(wxID_OPEN, "&Open...");
2352 file_menu->Append(wxID_SAVE, "&Save");
2353 file_menu->Append(wxID_SAVEAS, "Save &As...");
2354 file_menu->Append(wxID_CLOSE, "&Close");
2356 file_menu->AppendSeparator();
2357 file_menu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
2359 file_menu->AppendSeparator();
2360 file_menu->Append(wxID_PRINT, "&Print...");
2361 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2362 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
2364 wxMenu *view_menu = new wxMenu;
2365 view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...");
2366 view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...");
2367 view_menu->Append(PLOTMENU_VIEW_SCALE_FULL, "Display &Full Scale");
2369 wxMenu *help_menu = new wxMenu;
2370 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
2371 help_menu->AppendSeparator();
2372 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2374 wxMenuBar *menu_bar = new wxMenuBar;
2376 menu_bar->Append(file_menu, "&File");
2377 menu_bar->Append(view_menu, "&View");
2378 menu_bar->Append(help_menu, "&Help");
2380 subframe->SetMenuBar(menu_bar);
2382 subframe->Centre(wxBOTH);
2389 PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
2391 m_frame = CreateChildFrame(doc, this);
2394 m_bMinSpecified = false;
2395 m_bMaxSpecified = false;
2396 m_dAutoScaleFactor = 1.;
2399 m_frame->GetClientSize(&width, &height);
2400 m_frame->SetTitle ("Plot File");
2401 m_canvas = CreateCanvas (this, m_frame);
2404 int x, y; // X requires a forced resize
2405 m_frame->GetSize(&x, &y);
2406 m_frame->SetSize(-1, -1, x, y);
2409 m_frame->Show(true);
2416 PlotFileView::OnDraw (wxDC* dc)
2418 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2419 const int iNColumns = rPlotFile.getNumColumns();
2420 const int iNRecords = rPlotFile.getNumRecords();
2422 if (iNColumns > 0 && iNRecords > 0) {
2424 m_canvas->GetClientSize (&xsize, &ysize);
2425 SGPDriver driver (dc, xsize, ysize);
2428 m_pEZPlot->plot (&sgp);
2434 PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2436 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2437 const int iNColumns = rPlotFile.getNumColumns();
2438 const int iNRecords = rPlotFile.getNumRecords();
2440 if (iNColumns > 0 && iNRecords > 0) {
2443 m_pEZPlot = new EZPlot;
2445 for (unsigned int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)
2446 m_pEZPlot->ezset (rPlotFile.getEzsetCommand (iEzset));
2448 if (m_bMinSpecified) {
2449 std::ostringstream os;
2450 os << "ymin " << m_dMinPixel;
2451 m_pEZPlot->ezset (os.str());
2454 if (m_bMaxSpecified) {
2455 std::ostringstream os;
2456 os << "ymax " << m_dMaxPixel;
2457 m_pEZPlot->ezset (os.str());
2460 m_pEZPlot->ezset("box");
2461 m_pEZPlot->ezset("grid");
2463 double* pdXaxis = new double [iNRecords];
2464 rPlotFile.getColumn (0, pdXaxis);
2466 double* pdY = new double [iNRecords];
2467 for (int iCol = 1; iCol < iNColumns; iCol++) {
2468 rPlotFile.getColumn (iCol, pdY);
2469 m_pEZPlot->addCurve (pdXaxis, pdY, iNRecords);
2477 m_canvas->Refresh();
2481 PlotFileView::OnClose (bool deleteWindow)
2483 if (!GetDocument()->Close())
2486 // m_canvas->Clear();
2487 m_canvas->m_pView = NULL;
2489 wxString s(wxTheApp->GetAppName());
2491 m_frame->SetTitle(s);