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.137 2001/03/13 08:24:41 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"
39 #include "wx/clipbrd.h"
46 #include "dlgprojections.h"
47 #include "dlgreconstruct.h"
48 #include "backprojectors.h"
49 #include "reconstruct.h"
51 #include "threadproj.h"
52 #include "threadrecon.h"
53 #include "threadraster.h"
55 #if defined(MSVC) || HAVE_SSTREAM
58 #include <sstream_subst>
64 BEGIN_EVENT_TABLE(ImageFileCanvas, wxScrolledWindow)
65 EVT_MOUSE_EVENTS(ImageFileCanvas::OnMouseEvent)
66 EVT_CHAR(ImageFileCanvas::OnChar)
70 ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
71 : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v), m_xCursor(-1), m_yCursor(-1)
75 ImageFileCanvas::~ImageFileCanvas()
81 ImageFileCanvas::OnDraw(wxDC& dc)
84 m_pView->OnDraw(& dc);
88 ImageFileCanvas::DrawRubberBandCursor (wxDC& dc, int x, int y)
90 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
95 dc.SetLogicalFunction (wxINVERT);
96 dc.SetPen (*wxGREEN_PEN);
97 dc.DrawLine (0, yPt, nx, yPt);
98 dc.DrawLine (x, 0, x, ny);
99 dc.SetLogicalFunction (wxCOPY);
103 ImageFileCanvas::GetCurrentCursor (int& x, int& y)
108 if (m_xCursor >= 0 && m_yCursor >= 0)
115 ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
124 wxPoint pt(event.GetLogicalPosition(dc));
126 const ImageFileDocument* pIFDoc = m_pView->GetDocument();
129 const ImageFile& rIF = pIFDoc->getImageFile();
130 ImageFileArrayConst v = rIF.getArray();
133 const int yPt = ny - 1 - pt.y;
134 if (event.RightIsDown()) {
135 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
136 std::ostringstream os;
137 os << "Image value (" << pt.x << "," << yPt << ") = " << v[pt.x][yPt];
138 if (rIF.isComplex()) {
139 double dImag = rIF.getImaginaryArray()[pt.x][yPt];
141 os << " - " << -dImag;
143 os << " + " << dImag;
147 *theApp->getLog() << os.str().c_str();
149 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
151 else if (event.LeftIsDown() || event.LeftUp() || event.RightUp()) {
152 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
153 if (m_xCursor >= 0 && m_yCursor >= 0) {
154 DrawRubberBandCursor (dc, m_xCursor, m_yCursor);
156 DrawRubberBandCursor (dc, pt.x, yPt);
159 wxMenu* pMenu = m_pView->getMenuAnalyze();
160 if (pMenu && ! pMenu->IsEnabled(IFMENU_PLOT_ROW)) {
161 pMenu->Enable (IFMENU_PLOT_ROW, true);
162 pMenu->Enable (IFMENU_PLOT_COL, true);
163 pMenu->Enable (IFMENU_COMPARE_ROW, true);
164 pMenu->Enable (IFMENU_COMPARE_COL, true);
165 pMenu->Enable (IFMENU_PLOT_FFT_ROW, true);
166 pMenu->Enable (IFMENU_PLOT_FFT_COL, true);
169 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
171 if (event.LeftUp()) {
172 std::ostringstream os;
173 os << "Selected column " << pt.x << " , row " << yPt << "\n";
174 *theApp->getLog() << os.str().c_str();
179 ImageFileCanvas::OnChar (wxKeyEvent& event)
181 if (event.GetKeyCode() == WXK_ESCAPE) {
185 m_pView->OnUpdate (NULL);
187 wxScrolledWindow::OnChar (event);
191 ImageFileCanvas::GetBestSize() const
196 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
197 return wxSize (rIF.nx(), rIF.ny());
203 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
205 BEGIN_EVENT_TABLE(ImageFileView, wxView)
206 EVT_MENU(IFMENU_FILE_EXPORT, ImageFileView::OnExport)
207 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
208 EVT_MENU(IFMENU_EDIT_COPY, ImageFileView::OnEditCopy)
209 EVT_MENU(IFMENU_EDIT_CUT, ImageFileView::OnEditCut)
210 EVT_MENU(IFMENU_EDIT_PASTE, ImageFileView::OnEditPaste)
211 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
212 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
213 EVT_MENU(IFMENU_VIEW_SCALE_FULL, ImageFileView::OnScaleFull)
214 EVT_MENU(IFMENU_COMPARE_IMAGES, ImageFileView::OnCompare)
215 EVT_MENU(IFMENU_COMPARE_ROW, ImageFileView::OnCompareRow)
216 EVT_MENU(IFMENU_COMPARE_COL, ImageFileView::OnCompareCol)
217 EVT_MENU(IFMENU_FILTER_INVERTVALUES, ImageFileView::OnInvertValues)
218 EVT_MENU(IFMENU_FILTER_SQUARE, ImageFileView::OnSquare)
219 EVT_MENU(IFMENU_FILTER_SQRT, ImageFileView::OnSquareRoot)
220 EVT_MENU(IFMENU_FILTER_LOG, ImageFileView::OnLog)
221 EVT_MENU(IFMENU_FILTER_EXP, ImageFileView::OnExp)
222 EVT_MENU(IFMENU_FILTER_FOURIER, ImageFileView::OnFourier)
223 EVT_MENU(IFMENU_FILTER_INVERSE_FOURIER, ImageFileView::OnInverseFourier)
224 EVT_MENU(IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, ImageFileView::OnShuffleFourierToNaturalOrder)
225 EVT_MENU(IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, ImageFileView::OnShuffleNaturalToFourierOrder)
226 EVT_MENU(IFMENU_IMAGE_ADD, ImageFileView::OnAdd)
227 EVT_MENU(IFMENU_IMAGE_SUBTRACT, ImageFileView::OnSubtract)
228 EVT_MENU(IFMENU_IMAGE_MULTIPLY, ImageFileView::OnMultiply)
229 EVT_MENU(IFMENU_IMAGE_DIVIDE, ImageFileView::OnDivide)
230 EVT_MENU(IFMENU_IMAGE_SCALESIZE, ImageFileView::OnScaleSize)
232 EVT_MENU(IFMENU_IMAGE_CONVERT3D, ImageFileView::OnConvert3d)
235 EVT_MENU(IFMENU_FILTER_FFT, ImageFileView::OnFFT)
236 EVT_MENU(IFMENU_FILTER_IFFT, ImageFileView::OnIFFT)
237 EVT_MENU(IFMENU_FILTER_FFT_ROWS, ImageFileView::OnFFTRows)
238 EVT_MENU(IFMENU_FILTER_IFFT_ROWS, ImageFileView::OnIFFTRows)
239 EVT_MENU(IFMENU_FILTER_FFT_COLS, ImageFileView::OnFFTCols)
240 EVT_MENU(IFMENU_FILTER_IFFT_COLS, ImageFileView::OnIFFTCols)
242 EVT_MENU(IFMENU_FILTER_MAGNITUDE, ImageFileView::OnMagnitude)
243 EVT_MENU(IFMENU_FILTER_PHASE, ImageFileView::OnPhase)
244 EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)
245 EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol)
247 EVT_MENU(IFMENU_PLOT_FFT_ROW, ImageFileView::OnPlotFFTRow)
248 EVT_MENU(IFMENU_PLOT_FFT_COL, ImageFileView::OnPlotFFTCol)
250 EVT_MENU(IFMENU_PLOT_HISTOGRAM, ImageFileView::OnPlotHistogram)
253 ImageFileView::ImageFileView()
254 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
256 m_iDefaultExportFormatID = ImageFile::EXPORT_FORMAT_PNG;
259 ImageFileView::~ImageFileView()
261 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
262 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
267 ImageFileView::OnProperties (wxCommandEvent& event)
269 const ImageFile& rIF = GetDocument()->getImageFile();
270 if (rIF.nx() == 0 || rIF.ny() == 0)
271 *theApp->getLog() << "Properties: empty imagefile\n";
273 const std::string rFilename = m_pFrame->GetTitle().c_str();
274 std::ostringstream os;
275 double min, max, mean, mode, median, stddev;
276 rIF.statistics (rIF.getArray(), min, max, mean, mode, median, stddev);
277 os << "Filename: " << rFilename << "\n";
278 os << "Size: (" << rIF.nx() << "," << rIF.ny() << ")\n";
284 os << "Minimum: "<<min<<"\nMaximum: "<<max<<"\nMean: "<<mean<<"\nMedian: "<<median<<"\nMode: "<<mode<<"\nStandard Deviation: "<<stddev << "\n";
285 if (rIF.isComplex()) {
286 rIF.statistics (rIF.getImaginaryArray(), min, max, mean, mode, median, stddev);
287 os << "Imaginary: min: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
289 if (rIF.nLabels() > 0) {
290 rIF.printLabelsBrief (os);
292 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
293 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
294 dialogMsg.ShowModal();
296 GetDocument()->Activate();
300 ImageFileView::OnScaleAuto (wxCommandEvent& event)
302 const ImageFile& rIF = GetDocument()->getImageFile();
303 double min, max, mean, mode, median, stddev;
304 rIF.statistics(min, max, mean, mode, median, stddev);
305 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
306 int iRetVal = dialogAutoScale.ShowModal();
307 if (iRetVal == wxID_OK) {
308 m_bMinSpecified = true;
309 m_bMaxSpecified = true;
311 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
314 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
315 GetDocument()->UpdateAllViews (this);
318 GetDocument()->Activate();
322 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
324 const ImageFile& rIF = GetDocument()->getImageFile();
326 if (! m_bMinSpecified && ! m_bMaxSpecified)
327 rIF.getMinMax (min, max);
334 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Image Minimum & Maximum", min, max);
335 int retVal = dialogMinMax.ShowModal();
336 if (retVal == wxID_OK) {
337 m_bMinSpecified = true;
338 m_bMaxSpecified = true;
339 m_dMinPixel = dialogMinMax.getMinimum();
340 m_dMaxPixel = dialogMinMax.getMaximum();
341 GetDocument()->UpdateAllViews (this);
343 GetDocument()->Activate();
347 ImageFileView::OnScaleFull (wxCommandEvent& event)
349 if (m_bMinSpecified || m_bMaxSpecified) {
350 m_bMinSpecified = false;
351 m_bMaxSpecified = false;
352 GetDocument()->UpdateAllViews (this);
354 GetDocument()->Activate();
358 ImageFileView::OnCompare (wxCommandEvent& event)
360 std::vector<ImageFileDocument*> vecIF;
361 theApp->getCompatibleImages (GetDocument(), vecIF);
363 if (vecIF.size() == 0) {
364 wxMessageBox("There are no compatible image files open for comparision", "No comparison images");
366 DialogGetComparisonImage dialogGetCompare(getFrameForChild(), "Get Comparison Image", vecIF, true);
368 if (dialogGetCompare.ShowModal() == wxID_OK) {
369 const ImageFile& rIF = GetDocument()->getImageFile();
370 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
371 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
372 std::ostringstream os;
373 double min, max, mean, mode, median, stddev;
374 rIF.statistics (min, max, mean, mode, median, stddev);
375 os << GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
376 rCompareIF.statistics (min, max, mean, mode, median, stddev);
377 os << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
379 rIF.comparativeStatistics (rCompareIF, d, r, e);
380 os << "Comparative Statistics: d=" << d << ", r=" << r << ", e=" << e << "\n";
381 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
382 if (dialogGetCompare.getMakeDifferenceImage()) {
383 ImageFile* pDifferenceImage = new ImageFile;
385 pDifferenceImage->setArraySize (rIF.nx(), rIF.ny());
386 if (! rIF.subtractImages (rCompareIF, *pDifferenceImage)) {
387 *theApp->getLog() << "Unable to subtract images\n";
388 delete pDifferenceImage;
391 ImageFileDocument* pDifferenceDoc = theApp->newImageDoc();
392 if (! pDifferenceDoc) {
393 sys_error (ERR_SEVERE, "Unable to create image file");
396 pDifferenceDoc->setImageFile (pDifferenceImage);
398 wxString s = GetFrame()->GetTitle() + ": ";
399 pDifferenceImage->labelsCopy (rIF, s.c_str());
400 s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
401 pDifferenceImage->labelsCopy (rCompareIF, s.c_str());
402 std::ostringstream osLabel;
403 osLabel << "Compare image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str()
404 << " and " << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": "
406 pDifferenceImage->labelAdd (os.str().c_str());
407 if (theApp->getAskDeleteNewDocs())
408 pDifferenceDoc->Modify (true);
409 pDifferenceDoc->UpdateAllViews (this);
410 pDifferenceDoc->getView()->OnUpdate (this, NULL);
411 pDifferenceDoc->getView()->getFrame()->Show(true);
412 pDifferenceDoc->Activate();
414 wxMessageBox(os.str().c_str(), "Image Comparison");
420 ImageFileView::OnInvertValues (wxCommandEvent& event)
422 ImageFile& rIF = GetDocument()->getImageFile();
423 rIF.invertPixelValues (rIF);
424 rIF.labelAdd ("Invert Pixel Values");
425 if (theApp->getAskDeleteNewDocs())
426 GetDocument()->Modify (true);
427 GetDocument()->UpdateAllViews (this);
428 GetDocument()->Activate();
432 ImageFileView::OnSquare (wxCommandEvent& event)
434 ImageFile& rIF = GetDocument()->getImageFile();
436 rIF.labelAdd ("Square Pixel Values");
437 if (theApp->getAskDeleteNewDocs())
438 GetDocument()->Modify (true);
439 GetDocument()->UpdateAllViews (this);
440 GetDocument()->Activate();
444 ImageFileView::OnSquareRoot (wxCommandEvent& event)
446 ImageFile& rIF = GetDocument()->getImageFile();
448 rIF.labelAdd ("Square-root Pixel Values");
449 if (theApp->getAskDeleteNewDocs())
450 GetDocument()->Modify (true);
451 GetDocument()->UpdateAllViews (this);
452 GetDocument()->Activate();
456 ImageFileView::OnLog (wxCommandEvent& event)
458 ImageFile& rIF = GetDocument()->getImageFile();
460 rIF.labelAdd ("Logrithm base-e Pixel Values");
461 if (theApp->getAskDeleteNewDocs())
462 GetDocument()->Modify (true);
463 GetDocument()->UpdateAllViews (this);
464 GetDocument()->Activate();
468 ImageFileView::OnExp (wxCommandEvent& event)
470 ImageFile& rIF = GetDocument()->getImageFile();
472 rIF.labelAdd ("Exponent base-e Pixel Values");
473 if (theApp->getAskDeleteNewDocs())
474 GetDocument()->Modify (true);
475 GetDocument()->UpdateAllViews (this);
476 GetDocument()->Activate();
480 ImageFileView::OnAdd (wxCommandEvent& event)
482 std::vector<ImageFileDocument*> vecIF;
483 theApp->getCompatibleImages (GetDocument(), vecIF);
485 if (vecIF.size() == 0) {
486 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
488 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Add", vecIF, false);
490 if (dialogGetCompare.ShowModal() == wxID_OK) {
491 ImageFile& rIF = GetDocument()->getImageFile();
492 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
493 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
494 ImageFileDocument* pNewDoc = theApp->newImageDoc();
496 sys_error (ERR_SEVERE, "Unable to create image file");
499 ImageFile& newImage = pNewDoc->getImageFile();
500 newImage.setArraySize (rIF.nx(), rIF.ny());
501 rIF.addImages (rRHSIF, newImage);
502 std::ostringstream os;
503 os << "Add image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
504 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
505 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
506 newImage.labelsCopy (rIF, s.c_str());
507 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
508 newImage.labelsCopy (rRHSIF, s.c_str());
509 newImage.labelAdd (os.str().c_str());
510 *theApp->getLog() << os.str().c_str() << "\n";
511 if (theApp->getAskDeleteNewDocs())
512 pNewDoc->Modify (true);
513 pNewDoc->UpdateAllViews (this);
514 pNewDoc->getView()->getFrame()->Show(true);
521 ImageFileView::OnSubtract (wxCommandEvent& event)
523 std::vector<ImageFileDocument*> vecIF;
524 theApp->getCompatibleImages (GetDocument(), vecIF);
526 if (vecIF.size() == 0) {
527 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
529 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Subtract", vecIF, false);
531 if (dialogGetCompare.ShowModal() == wxID_OK) {
532 ImageFile& rIF = GetDocument()->getImageFile();
533 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
534 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
535 ImageFileDocument* pNewDoc = theApp->newImageDoc();
537 sys_error (ERR_SEVERE, "Unable to create image file");
540 ImageFile& newImage = pNewDoc->getImageFile();
541 newImage.setArraySize (rIF.nx(), rIF.ny());
542 rIF.subtractImages (rRHSIF, newImage);
543 std::ostringstream os;
544 os << "Subtract image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
545 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
546 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
547 newImage.labelsCopy (rIF, s.c_str());
548 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
549 newImage.labelsCopy (rRHSIF, s.c_str());
550 newImage.labelAdd (os.str().c_str());
551 *theApp->getLog() << os.str().c_str() << "\n";
552 if (theApp->getAskDeleteNewDocs())
553 pNewDoc->Modify (true);
554 pNewDoc->UpdateAllViews (this);
555 pNewDoc->getView()->getFrame()->Show(true);
562 ImageFileView::OnMultiply (wxCommandEvent& event)
564 std::vector<ImageFileDocument*> vecIF;
565 theApp->getCompatibleImages (GetDocument(), vecIF);
567 if (vecIF.size() == 0) {
568 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
570 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Multiply", vecIF, false);
572 if (dialogGetCompare.ShowModal() == wxID_OK) {
573 ImageFile& rIF = GetDocument()->getImageFile();
574 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
575 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
576 ImageFileDocument* pNewDoc = theApp->newImageDoc();
578 sys_error (ERR_SEVERE, "Unable to create image file");
581 ImageFile& newImage = pNewDoc->getImageFile();
582 newImage.setArraySize (rIF.nx(), rIF.ny());
583 rIF.multiplyImages (rRHSIF, newImage);
584 std::ostringstream os;
585 os << "Multiply image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
586 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
587 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
588 newImage.labelsCopy (rIF, s.c_str());
589 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
590 newImage.labelsCopy (rRHSIF, s.c_str());
591 newImage.labelAdd (os.str().c_str());
592 *theApp->getLog() << os.str().c_str() << "\n";
593 if (theApp->getAskDeleteNewDocs())
594 pNewDoc->Modify (true);
595 pNewDoc->UpdateAllViews (this);
596 pNewDoc->getView()->getFrame()->Show(true);
603 ImageFileView::OnDivide (wxCommandEvent& event)
605 std::vector<ImageFileDocument*> vecIF;
606 theApp->getCompatibleImages (GetDocument(), vecIF);
608 if (vecIF.size() == 0) {
609 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
611 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Divide", vecIF, false);
613 if (dialogGetCompare.ShowModal() == wxID_OK) {
614 ImageFile& rIF = GetDocument()->getImageFile();
615 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
616 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
617 ImageFileDocument* pNewDoc = theApp->newImageDoc();
619 sys_error (ERR_SEVERE, "Unable to create image file");
622 ImageFile& newImage = pNewDoc->getImageFile();
623 newImage.setArraySize (rIF.nx(), rIF.ny());
624 rIF.divideImages (rRHSIF, newImage);
625 std::ostringstream os;
626 os << "Divide image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " by "
627 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
628 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
629 newImage.labelsCopy (rIF, s.c_str());
630 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
631 newImage.labelsCopy (rRHSIF, s.c_str());
632 newImage.labelAdd (os.str().c_str());
633 *theApp->getLog() << os.str().c_str() << "\n";
634 if (theApp->getAskDeleteNewDocs())
635 pNewDoc->Modify (true);
636 pNewDoc->UpdateAllViews (this);
637 pNewDoc->getView()->getFrame()->Show(true);
646 ImageFileView::OnFFT (wxCommandEvent& event)
648 ImageFile& rIF = GetDocument()->getImageFile();
650 rIF.labelAdd ("FFT Image");
651 m_bMinSpecified = false;
652 m_bMaxSpecified = false;
653 if (theApp->getAskDeleteNewDocs())
654 GetDocument()->Modify (true);
655 GetDocument()->UpdateAllViews (this);
656 GetDocument()->Activate();
660 ImageFileView::OnIFFT (wxCommandEvent& event)
662 ImageFile& rIF = GetDocument()->getImageFile();
664 rIF.labelAdd ("IFFT Image");
665 m_bMinSpecified = false;
666 m_bMaxSpecified = false;
667 if (theApp->getAskDeleteNewDocs())
668 GetDocument()->Modify (true);
669 GetDocument()->UpdateAllViews (this);
670 GetDocument()->Activate();
674 ImageFileView::OnFFTRows (wxCommandEvent& event)
676 ImageFile& rIF = GetDocument()->getImageFile();
678 rIF.labelAdd ("FFT Rows");
679 m_bMinSpecified = false;
680 m_bMaxSpecified = false;
681 if (theApp->getAskDeleteNewDocs())
682 GetDocument()->Modify (true);
683 GetDocument()->UpdateAllViews (this);
684 GetDocument()->Activate();
688 ImageFileView::OnIFFTRows (wxCommandEvent& event)
690 ImageFile& rIF = GetDocument()->getImageFile();
692 rIF.labelAdd ("IFFT Rows");
693 m_bMinSpecified = false;
694 m_bMaxSpecified = false;
695 if (theApp->getAskDeleteNewDocs())
696 GetDocument()->Modify (true);
697 GetDocument()->UpdateAllViews (this);
698 GetDocument()->Activate();
702 ImageFileView::OnFFTCols (wxCommandEvent& event)
704 ImageFile& rIF = GetDocument()->getImageFile();
706 rIF.labelAdd ("FFT Columns");
707 m_bMinSpecified = false;
708 m_bMaxSpecified = false;
709 if (theApp->getAskDeleteNewDocs())
710 GetDocument()->Modify (true);
711 GetDocument()->UpdateAllViews (this);
712 GetDocument()->Activate();
716 ImageFileView::OnIFFTCols (wxCommandEvent& event)
718 ImageFile& rIF = GetDocument()->getImageFile();
720 rIF.labelAdd ("IFFT Columns");
721 m_bMinSpecified = false;
722 m_bMaxSpecified = false;
723 if (theApp->getAskDeleteNewDocs())
724 GetDocument()->Modify (true);
725 GetDocument()->UpdateAllViews (this);
726 GetDocument()->Activate();
731 ImageFileView::OnFourier (wxCommandEvent& event)
733 ImageFile& rIF = GetDocument()->getImageFile();
734 wxProgressDialog dlgProgress (wxString("Fourier"), wxString("Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
736 rIF.labelAdd ("Fourier Image");
737 m_bMinSpecified = false;
738 m_bMaxSpecified = false;
739 if (theApp->getAskDeleteNewDocs())
740 GetDocument()->Modify (true);
741 GetDocument()->UpdateAllViews (this);
742 GetDocument()->Activate();
746 ImageFileView::OnInverseFourier (wxCommandEvent& event)
748 ImageFile& rIF = GetDocument()->getImageFile();
749 wxProgressDialog dlgProgress (wxString("Inverse Fourier"), wxString("Inverse Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
750 rIF.inverseFourier (rIF);
751 rIF.labelAdd ("Inverse Fourier Image");
752 m_bMinSpecified = false;
753 m_bMaxSpecified = false;
754 if (theApp->getAskDeleteNewDocs())
755 GetDocument()->Modify (true);
756 GetDocument()->UpdateAllViews (this);
757 GetDocument()->Activate();
761 ImageFileView::OnShuffleNaturalToFourierOrder (wxCommandEvent& event)
763 ImageFile& rIF = GetDocument()->getImageFile();
764 Fourier::shuffleNaturalToFourierOrder (rIF);
765 rIF.labelAdd ("Shuffle Natural To Fourier Order");
766 m_bMinSpecified = false;
767 m_bMaxSpecified = false;
768 if (theApp->getAskDeleteNewDocs())
769 GetDocument()->Modify (true);
770 GetDocument()->UpdateAllViews (this);
771 GetDocument()->Activate();
775 ImageFileView::OnShuffleFourierToNaturalOrder (wxCommandEvent& event)
777 ImageFile& rIF = GetDocument()->getImageFile();
778 Fourier::shuffleFourierToNaturalOrder (rIF);
779 rIF.labelAdd ("Shuffle Fourier To Natural Order");
780 m_bMinSpecified = false;
781 m_bMaxSpecified = false;
782 if (theApp->getAskDeleteNewDocs())
783 GetDocument()->Modify (true);
784 GetDocument()->UpdateAllViews (this);
785 GetDocument()->Activate();
789 ImageFileView::OnMagnitude (wxCommandEvent& event)
791 ImageFile& rIF = GetDocument()->getImageFile();
792 if (rIF.isComplex()) {
794 rIF.labelAdd ("Magnitude of complex-image");
795 m_bMinSpecified = false;
796 m_bMaxSpecified = false;
797 if (theApp->getAskDeleteNewDocs())
798 GetDocument()->Modify (true);
799 GetDocument()->UpdateAllViews (this);
801 GetDocument()->Activate();
805 ImageFileView::OnPhase (wxCommandEvent& event)
807 ImageFile& rIF = GetDocument()->getImageFile();
808 if (rIF.isComplex()) {
810 rIF.labelAdd ("Phase of complex-image");
811 m_bMinSpecified = false;
812 m_bMaxSpecified = false;
813 if (theApp->getAskDeleteNewDocs())
814 GetDocument()->Modify (true);
815 GetDocument()->UpdateAllViews (this);
817 GetDocument()->Activate();
822 ImageFileView::CreateCanvas (wxFrame* parent)
824 ImageFileCanvas* pCanvas;
826 parent->GetClientSize(&width, &height);
828 pCanvas = new ImageFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
830 pCanvas->SetScrollbars(20, 20, 50, 50);
831 pCanvas->SetBackgroundColour(*wxWHITE);
842 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
845 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
847 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
849 theApp->setIconForFrame (subframe);
851 m_pFileMenu = new wxMenu;
853 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
854 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
855 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
856 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
857 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
858 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
859 m_pFileMenu->Append(wxID_REVERT, "Re&vert");
861 m_pFileMenu->AppendSeparator();
862 m_pFileMenu->Append(IFMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
863 m_pFileMenu->Append(IFMENU_FILE_EXPORT, "&Export...");
865 m_pFileMenu->AppendSeparator();
866 m_pFileMenu->Append(wxID_PRINT, "&Print...");
867 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
868 m_pFileMenu->Append(wxID_PREVIEW, "Print Preview");
869 m_pFileMenu->AppendSeparator();
870 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
872 m_pFileMenu->AppendSeparator();
873 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
874 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
876 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
877 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
879 wxMenu* edit_menu = new wxMenu;
880 edit_menu->Append(IFMENU_EDIT_COPY, "Copy\tCtrl-C");
881 edit_menu->Append(IFMENU_EDIT_CUT, "Cut\tCtrl-X");
882 edit_menu->Append(IFMENU_EDIT_PASTE, "Paste\tCtrl-V");
884 wxMenu *view_menu = new wxMenu;
885 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale S&et...\tCtrl-E");
886 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
887 view_menu->Append(IFMENU_VIEW_SCALE_FULL, "Display F&ull Scale\tCtrl-U");
889 wxMenu* filter_menu = new wxMenu;
890 filter_menu->Append (IFMENU_FILTER_INVERTVALUES, "&Invert Values");
891 filter_menu->Append (IFMENU_FILTER_SQUARE, "&Square");
892 filter_menu->Append (IFMENU_FILTER_SQRT, "Square &Root");
893 filter_menu->Append (IFMENU_FILTER_LOG, "&Log");
894 filter_menu->Append (IFMENU_FILTER_EXP, "&Exp");
895 filter_menu->AppendSeparator();
897 filter_menu->Append (IFMENU_FILTER_FFT, "2-D &FFT");
898 filter_menu->Append (IFMENU_FILTER_IFFT, "2-D &IFFT");
899 filter_menu->Append (IFMENU_FILTER_FFT_ROWS, "FFT Rows");
900 filter_menu->Append (IFMENU_FILTER_IFFT_ROWS, "IFFT Rows");
901 filter_menu->Append (IFMENU_FILTER_FFT_COLS, "FFT Columns");
902 filter_menu->Append (IFMENU_FILTER_IFFT_COLS, "IFFT Columns");
903 filter_menu->Append (IFMENU_FILTER_FOURIER, "2-D F&ourier");
904 filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "2-D Inverse Fo&urier");
906 filter_menu->Append (IFMENU_FILTER_FOURIER, "&Fourier");
907 filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "&Inverse Fourier");
909 filter_menu->Append (IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, "S&huffle Fourier to Natural Order");
910 filter_menu->Append (IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, "Shu&ffle Natural to Fourier Order");
911 filter_menu->Append (IFMENU_FILTER_MAGNITUDE, "&Magnitude");
912 filter_menu->Append (IFMENU_FILTER_PHASE, "&Phase");
914 wxMenu* image_menu = new wxMenu;
915 image_menu->Append (IFMENU_IMAGE_ADD, "&Add...");
916 image_menu->Append (IFMENU_IMAGE_SUBTRACT, "&Subtract...");
917 image_menu->Append (IFMENU_IMAGE_MULTIPLY, "&Multiply...");
918 image_menu->Append (IFMENU_IMAGE_DIVIDE, "&Divide...");
919 image_menu->AppendSeparator();
920 image_menu->Append (IFMENU_IMAGE_SCALESIZE, "S&cale Size...");
922 image_menu->Append (IFMENU_IMAGE_CONVERT3D, "Convert &3-D\tCtrl-3");
925 m_pMenuAnalyze = new wxMenu;
926 m_pMenuAnalyze->Append (IFMENU_PLOT_ROW, "Plot &Row");
927 m_pMenuAnalyze->Append (IFMENU_PLOT_COL, "Plot &Column");
928 m_pMenuAnalyze->Append (IFMENU_PLOT_HISTOGRAM, "Plot &Histogram");
929 m_pMenuAnalyze->AppendSeparator();
930 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_ROW, "P&lot FFT Row");
931 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_COL, "Plo&t FFT Column");
932 m_pMenuAnalyze->AppendSeparator();
933 m_pMenuAnalyze->Append (IFMENU_COMPARE_IMAGES, "Compare &Images...");
934 m_pMenuAnalyze->Append (IFMENU_COMPARE_ROW, "Compare Ro&w");
935 m_pMenuAnalyze->Append (IFMENU_COMPARE_COL, "Compare Colu&mn");
936 m_pMenuAnalyze->Enable (IFMENU_PLOT_ROW, false);
937 m_pMenuAnalyze->Enable (IFMENU_PLOT_COL, false);
938 m_pMenuAnalyze->Enable (IFMENU_COMPARE_ROW, false);
939 m_pMenuAnalyze->Enable (IFMENU_COMPARE_COL, false);
940 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_ROW, false);
941 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_COL, false);
943 wxMenu *help_menu = new wxMenu;
944 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
945 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
946 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
947 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
949 wxMenuBar *menu_bar = new wxMenuBar;
951 menu_bar->Append(m_pFileMenu, "&File");
952 menu_bar->Append(edit_menu, "&Edit");
953 menu_bar->Append(view_menu, "&View");
954 menu_bar->Append(image_menu, "&Image");
955 menu_bar->Append(filter_menu, "Fi<er");
956 menu_bar->Append(m_pMenuAnalyze, "&Analyze");
957 menu_bar->Append(help_menu, "&Help");
959 subframe->SetMenuBar(menu_bar);
961 subframe->Centre(wxBOTH);
963 wxAcceleratorEntry accelEntries[8];
964 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('A'), IFMENU_VIEW_SCALE_AUTO);
965 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('U'), IFMENU_VIEW_SCALE_FULL);
966 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('E'), IFMENU_VIEW_SCALE_MINMAX);
967 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), IFMENU_FILE_PROPERTIES);
968 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('C'), IFMENU_EDIT_COPY);
969 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('X'), IFMENU_EDIT_CUT);
970 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('V'), IFMENU_EDIT_PASTE);
972 accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('3'), IFMENU_IMAGE_CONVERT3D);
973 wxAcceleratorTable accelTable (8, accelEntries);
975 wxAcceleratorTable accelTable (7, accelEntries);
978 subframe->SetAcceleratorTable (accelTable);
985 ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
987 m_pFrame = CreateChildFrame(doc, this);
989 m_bMinSpecified = false;
990 m_bMaxSpecified = false;
991 m_dAutoScaleFactor = 1.;
994 m_pFrame->GetClientSize (&width, &height);
995 m_pFrame->SetTitle("ImageFileView");
996 m_pCanvas = CreateCanvas (m_pFrame);
998 int x, y; // X requires a forced resize
999 m_pFrame->GetSize(&x, &y);
1000 m_pFrame->SetSize(-1, -1, x, y);
1001 m_pFrame->SetFocus();
1002 m_pFrame->Show(true);
1009 ImageFileView::OnDraw (wxDC* dc)
1011 wxSize sizeWindow = m_pFrame->GetClientSize();
1012 wxSize sizeBest = m_pCanvas->GetBestSize();
1013 if (sizeWindow.x > sizeBest.x || sizeWindow.y > sizeBest.y)
1014 m_pFrame->SetClientSize (sizeBest);
1017 dc->DrawBitmap(m_bitmap, 0, 0, false);
1019 int xCursor, yCursor;
1020 if (m_pCanvas->GetCurrentCursor (xCursor, yCursor))
1021 m_pCanvas->DrawRubberBandCursor (*dc, xCursor, yCursor);
1026 ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
1028 const ImageFile& rIF = GetDocument()->getImageFile();
1029 ImageFileArrayConst v = rIF.getArray();
1032 if (v != NULL && nx != 0 && ny != 0) {
1033 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1035 rIF.getMinMax (min, max);
1036 if (! m_bMinSpecified)
1038 if (! m_bMaxSpecified)
1041 double scaleWidth = m_dMaxPixel - m_dMinPixel;
1043 unsigned char* imageData = new unsigned char [nx * ny * 3];
1045 sys_error (ERR_SEVERE, "Unable to allocate memory for Image display");
1048 for (int ix = 0; ix < nx; ix++) {
1049 for (int iy = 0; iy < ny; iy++) {
1050 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
1051 int intensity = static_cast<int>(scaleValue + 0.5);
1052 intensity = clamp (intensity, 0, 255);
1053 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
1054 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
1057 wxImage image (nx, ny, imageData, true);
1058 m_bitmap = image.ConvertToBitmap();
1062 ySize = clamp (ySize, 0, 800);
1063 m_pFrame->SetClientSize (xSize, ySize);
1064 m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20);
1065 m_pCanvas->SetBackgroundColour(*wxWHITE);
1069 m_pCanvas->Refresh();
1073 ImageFileView::OnClose (bool deleteWindow)
1075 //GetDocumentManager()->ActivateView (this, false, true);
1076 if (! GetDocument() || ! GetDocument()->Close())
1081 m_pCanvas->setView(NULL);
1084 wxString s(theApp->GetAppName());
1086 m_pFrame->SetTitle(s);
1093 if (GetDocument() && GetDocument()->getBadFileOpen())
1094 ::wxYield(); // wxWindows bug workaround
1101 ImageFileView::OnEditCopy (wxCommandEvent& event)
1103 wxBitmapDataObject *pBitmapObject = new wxBitmapDataObject;
1105 pBitmapObject->SetBitmap (m_bitmap);
1107 if (wxTheClipboard->Open()) {
1108 wxTheClipboard->SetData (pBitmapObject);
1109 wxTheClipboard->Close();
1114 ImageFileView::OnEditCut (wxCommandEvent& event)
1117 ImageFile& rIF = GetDocument()->getImageFile();
1120 ImageFile* pIF = new ImageFile (nx, ny);
1121 pIF->arrayDataClear();
1122 GetDocument()->setImageFile (pIF); // deletes old IF
1123 OnUpdate(this, NULL);
1124 GetDocument()->UpdateAllViews();
1125 if (theApp->getAskDeleteNewDocs())
1126 GetDocument()->Modify (true);
1130 ImageFileView::OnEditPaste (wxCommandEvent& event)
1132 ImageFile& rIF = GetDocument()->getImageFile();
1134 if (wxTheClipboard->Open()) {
1136 if (wxTheClipboard->IsSupported (wxDF_BITMAP)) {
1137 wxBitmapDataObject bitmapObject;
1138 wxTheClipboard->GetData (bitmapObject);
1139 bitmap = bitmapObject.GetBitmap ();
1141 wxTheClipboard->Close();
1145 if (bitmap.Ok() == true && bitmap.GetWidth() == nx && bitmap.GetHeight() == ny) {
1146 wxImage image (bitmap);
1147 unsigned char* pixels = image.GetData();
1148 ImageFileArray v = rIF.getArray();
1149 for (int ix = 0; ix < rIF.nx(); ix++) {
1150 for (int iy = 0; iy < rIF.ny(); iy++) {
1151 unsigned int iBase = 3 * (iy * nx + ix);
1152 double dR = pixels[iBase] / 255.;
1153 double dG = pixels[iBase+1] / 255.;
1154 double dB = pixels[iBase+2] / 255.;
1155 v[ix][ny - 1 - iy] = ImageFile::colorToGrayscale (dR, dG, dB);
1158 OnUpdate(this, NULL);
1159 GetDocument()->UpdateAllViews();
1160 if (theApp->getAskDeleteNewDocs())
1161 GetDocument()->Modify(true);
1167 ImageFileView::OnExport (wxCommandEvent& event)
1169 ImageFile& rIF = GetDocument()->getImageFile();
1170 ImageFileArrayConst v = rIF.getArray();
1173 if (v != NULL && nx != 0 && ny != 0) {
1174 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1176 rIF.getMinMax (min, max);
1177 if (! m_bMinSpecified)
1179 if (! m_bMaxSpecified)
1183 DialogExportParameters dialogExport (getFrameForChild(), m_iDefaultExportFormatID);
1184 if (dialogExport.ShowModal() == wxID_OK) {
1185 wxString strFormatName (dialogExport.getFormatName ());
1186 m_iDefaultExportFormatID = ImageFile::convertExportFormatNameToID (strFormatName.c_str());
1189 wxString strWildcard;
1190 if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PGM || m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PGMASCII) {
1192 strWildcard = "PGM Files (*.pgm)|*.pgm";
1195 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PNG || m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PNG16) {
1197 strWildcard = "PNG Files (*.png)|*.png";
1200 #ifdef HAVE_CTN_DICOM
1201 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_DICOM) {
1203 strWildcard = "DICOM Files (*.*)|*.*";
1208 strWildcard = "Miscellaneous (*.*)|*.*";
1211 const wxString& strFilename = wxFileSelector (wxString("Export Filename"), wxString(""),
1212 wxString(""), strExt, strWildcard, wxOVERWRITE_PROMPT | wxHIDE_READONLY | wxSAVE);
1214 rIF.exportImage (strFormatName.c_str(), strFilename.c_str(), 1, 1, m_dMinPixel, m_dMaxPixel);
1215 *theApp->getLog() << "Exported file " << strFilename << "\n";
1222 ImageFileView::OnScaleSize (wxCommandEvent& event)
1224 ImageFile& rIF = GetDocument()->getImageFile();
1225 unsigned int iOldNX = rIF.nx();
1226 unsigned int iOldNY = rIF.ny();
1228 DialogGetXYSize dialogGetXYSize (getFrameForChild(), "Set New X & Y Dimensions", iOldNX, iOldNY);
1229 if (dialogGetXYSize.ShowModal() == wxID_OK) {
1230 unsigned int iNewNX = dialogGetXYSize.getXSize();
1231 unsigned int iNewNY = dialogGetXYSize.getYSize();
1232 std::ostringstream os;
1233 os << "Scale Size from (" << iOldNX << "," << iOldNY << ") to (" << iNewNX << "," << iNewNY << ")";
1234 ImageFileDocument* pScaledDoc = theApp->newImageDoc();
1236 sys_error (ERR_SEVERE, "Unable to create image file");
1239 ImageFile& rScaledIF = pScaledDoc->getImageFile();
1240 rScaledIF.setArraySize (iNewNX, iNewNY);
1241 rScaledIF.labelsCopy (rIF);
1242 rScaledIF.labelAdd (os.str().c_str());
1243 rIF.scaleImage (rScaledIF);
1244 *theApp->getLog() << os.str().c_str() << "\n";
1245 if (theApp->getAskDeleteNewDocs())
1246 pScaledDoc->Modify (true);
1247 pScaledDoc->UpdateAllViews (this);
1248 pScaledDoc->getView()->getFrame()->Show(true);
1249 pScaledDoc->Activate();
1255 ImageFileView::OnConvert3d (wxCommandEvent& event)
1257 ImageFile& rIF = GetDocument()->getImageFile();
1258 Graph3dFileDocument* pGraph3d = theApp->newGraph3dDoc();
1259 pGraph3d->setBadFileOpen();
1260 pGraph3d->createFromImageFile (rIF);
1261 pGraph3d->getView()->OnUpdate (this, NULL);
1262 pGraph3d->UpdateAllViews();
1263 pGraph3d->getView()->getFrame()->SetClientSize (400, 400);
1264 pGraph3d->getView()->getFrame()->Show (true);
1265 GetDocumentManager()->ActivateView (pGraph3d->getView(), true, false);
1267 pGraph3d->getView()->getCanvas()->SetFocus();
1272 ImageFileView::OnPlotRow (wxCommandEvent& event)
1274 int xCursor, yCursor;
1275 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1276 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1280 const ImageFile& rIF = GetDocument()->getImageFile();
1281 ImageFileArrayConst v = rIF.getArray();
1282 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1286 if (v != NULL && yCursor < ny) {
1287 double* pX = new double [nx];
1288 double* pYReal = new double [nx];
1289 double *pYImag = NULL;
1290 double *pYMag = NULL;
1291 if (rIF.isComplex()) {
1292 pYImag = new double [nx];
1293 pYMag = new double [nx];
1295 for (int i = 0; i < nx; i++) {
1297 pYReal[i] = v[i][yCursor];
1298 if (rIF.isComplex()) {
1299 pYImag[i] = vImag[i][yCursor];
1300 pYMag[i] = ::sqrt (v[i][yCursor] * v[i][yCursor] + vImag[i][yCursor] * vImag[i][yCursor]);
1303 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1305 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1307 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1308 std::ostringstream os;
1309 os << "Row " << yCursor;
1310 std::string title("title ");
1312 rPlotFile.addEzsetCommand (title.c_str());
1313 rPlotFile.addEzsetCommand ("xlabel Column");
1314 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1315 rPlotFile.addEzsetCommand ("lxfrac 0");
1316 rPlotFile.addEzsetCommand ("box");
1317 rPlotFile.addEzsetCommand ("grid");
1318 rPlotFile.addEzsetCommand ("curve 1");
1319 rPlotFile.addEzsetCommand ("color 1");
1320 if (rIF.isComplex()) {
1321 rPlotFile.addEzsetCommand ("dash 1");
1322 rPlotFile.addEzsetCommand ("curve 2");
1323 rPlotFile.addEzsetCommand ("color 4");
1324 rPlotFile.addEzsetCommand ("dash 3");
1325 rPlotFile.addEzsetCommand ("curve 3");
1326 rPlotFile.addEzsetCommand ("color 0");
1327 rPlotFile.addEzsetCommand ("solid");
1328 rPlotFile.setCurveSize (4, nx);
1330 rPlotFile.setCurveSize (2, nx);
1331 rPlotFile.addColumn (0, pX);
1332 rPlotFile.addColumn (1, pYReal);
1333 if (rIF.isComplex()) {
1334 rPlotFile.addColumn (2, pYImag);
1335 rPlotFile.addColumn (3, pYMag);
1337 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1338 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1339 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1340 *theApp->getLog() << os.str().c_str() << "\n";
1341 rPlotFile.addDescription (os.str().c_str());
1345 if (rIF.isComplex()) {
1349 if (theApp->getAskDeleteNewDocs())
1350 pPlotDoc->Modify (true);
1351 pPlotDoc->getView()->getFrame()->Show(true);
1352 pPlotDoc->UpdateAllViews ();
1353 pPlotDoc->Activate();
1358 ImageFileView::OnPlotCol (wxCommandEvent& event)
1360 int xCursor, yCursor;
1361 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1362 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1366 const ImageFile& rIF = GetDocument()->getImageFile();
1367 ImageFileArrayConst v = rIF.getArray();
1368 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1372 if (v != NULL && xCursor < nx) {
1373 double* pX = new double [ny];
1374 double* pYReal = new double [ny];
1375 double* pYImag = NULL;
1376 double* pYMag = NULL;
1377 if (rIF.isComplex()) {
1378 pYImag = new double [ny];
1379 pYMag = new double [ny];
1381 for (int i = 0; i < ny; i++) {
1383 pYReal[i] = v[xCursor][i];
1384 if (rIF.isComplex()) {
1385 pYImag[i] = vImag[xCursor][i];
1386 pYMag[i] = ::sqrt (v[xCursor][i] * v[xCursor][i] + vImag[xCursor][i] * vImag[xCursor][i]);
1389 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1391 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1393 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1394 std::ostringstream os;
1395 os << "Column " << xCursor;
1396 std::string title("title ");
1398 rPlotFile.addEzsetCommand (title.c_str());
1399 rPlotFile.addEzsetCommand ("xlabel Row");
1400 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1401 rPlotFile.addEzsetCommand ("lxfrac 0");
1402 rPlotFile.addEzsetCommand ("box");
1403 rPlotFile.addEzsetCommand ("grid");
1404 rPlotFile.addEzsetCommand ("curve 1");
1405 rPlotFile.addEzsetCommand ("color 1");
1406 if (rIF.isComplex()) {
1407 rPlotFile.addEzsetCommand ("dash 1");
1408 rPlotFile.addEzsetCommand ("curve 2");
1409 rPlotFile.addEzsetCommand ("color 4");
1410 rPlotFile.addEzsetCommand ("dash 3");
1411 rPlotFile.addEzsetCommand ("curve 3");
1412 rPlotFile.addEzsetCommand ("color 0");
1413 rPlotFile.addEzsetCommand ("solid");
1414 rPlotFile.setCurveSize (4, ny);
1416 rPlotFile.setCurveSize (2, ny);
1417 rPlotFile.addColumn (0, pX);
1418 rPlotFile.addColumn (1, pYReal);
1419 if (rIF.isComplex()) {
1420 rPlotFile.addColumn (2, pYImag);
1421 rPlotFile.addColumn (3, pYMag);
1423 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1424 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1425 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1426 *theApp->getLog() << os.str().c_str() << "\n";
1427 rPlotFile.addDescription (os.str().c_str());
1431 if (rIF.isComplex()) {
1435 if (theApp->getAskDeleteNewDocs())
1436 pPlotDoc->Modify (true);
1437 pPlotDoc->getView()->getFrame()->Show(true);
1438 pPlotDoc->UpdateAllViews ();
1439 pPlotDoc->Activate();
1445 ImageFileView::OnPlotFFTRow (wxCommandEvent& event)
1447 int xCursor, yCursor;
1448 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1449 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1453 const ImageFile& rIF = GetDocument()->getImageFile();
1454 ImageFileArrayConst v = rIF.getArray();
1455 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1459 if (v != NULL && yCursor < ny) {
1460 fftw_complex* pcIn = new fftw_complex [nx];
1463 for (i = 0; i < nx; i++) {
1464 pcIn[i].re = v[i][yCursor];
1465 if (rIF.isComplex())
1466 pcIn[i].im = vImag[i][yCursor];
1471 fftw_plan plan = fftw_create_plan (nx, FFTW_FORWARD, FFTW_IN_PLACE);
1472 fftw_one (plan, pcIn, NULL);
1473 fftw_destroy_plan (plan);
1475 double* pX = new double [nx];
1476 double* pYReal = new double [nx];
1477 double* pYImag = new double [nx];
1478 double* pYMag = new double [nx];
1479 for (i = 0; i < nx; i++) {
1481 pYReal[i] = pcIn[i].re;
1482 pYImag[i] = pcIn[i].im;
1483 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1485 Fourier::shuffleFourierToNaturalOrder (pYReal, nx);
1486 Fourier::shuffleFourierToNaturalOrder (pYImag, nx);
1487 Fourier::shuffleFourierToNaturalOrder (pYMag, nx);
1489 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1491 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1493 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1494 std::ostringstream os;
1495 os << "Row " << yCursor;
1496 std::string title("title ");
1498 rPlotFile.addEzsetCommand (title.c_str());
1499 rPlotFile.addEzsetCommand ("xlabel Column");
1500 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1501 rPlotFile.addEzsetCommand ("lxfrac 0");
1502 rPlotFile.addEzsetCommand ("curve 1");
1503 rPlotFile.addEzsetCommand ("color 1");
1504 rPlotFile.addEzsetCommand ("dash 1");
1505 rPlotFile.addEzsetCommand ("curve 2");
1506 rPlotFile.addEzsetCommand ("color 4");
1507 rPlotFile.addEzsetCommand ("dash 3");
1508 rPlotFile.addEzsetCommand ("curve 3");
1509 rPlotFile.addEzsetCommand ("color 0");
1510 rPlotFile.addEzsetCommand ("solid");
1511 rPlotFile.addEzsetCommand ("box");
1512 rPlotFile.addEzsetCommand ("grid");
1513 rPlotFile.setCurveSize (4, nx);
1514 rPlotFile.addColumn (0, pX);
1515 rPlotFile.addColumn (1, pYReal);
1516 rPlotFile.addColumn (2, pYImag);
1517 rPlotFile.addColumn (3, pYMag);
1518 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1519 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1520 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1521 *theApp->getLog() << os.str().c_str() << "\n";
1522 rPlotFile.addDescription (os.str().c_str());
1530 if (theApp->getAskDeleteNewDocs())
1531 pPlotDoc->Modify (true);
1532 pPlotDoc->getView()->getFrame()->Show(true);
1533 pPlotDoc->UpdateAllViews ();
1534 pPlotDoc->Activate();
1539 ImageFileView::OnPlotFFTCol (wxCommandEvent& event)
1541 int xCursor, yCursor;
1542 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1543 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1547 const ImageFile& rIF = GetDocument()->getImageFile();
1548 ImageFileArrayConst v = rIF.getArray();
1549 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1553 if (v != NULL && xCursor < nx) {
1554 fftw_complex* pcIn = new fftw_complex [ny];
1555 double *pdTemp = new double [ny];
1558 for (i = 0; i < ny; i++)
1559 pdTemp[i] = v[xCursor][i];
1560 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1561 for (i = 0; i < ny; i++)
1562 pcIn[i].re = pdTemp[i];
1564 for (i = 0; i < ny; i++) {
1565 if (rIF.isComplex())
1566 pdTemp[i] = vImag[xCursor][i];
1570 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1571 for (i = 0; i < ny; i++)
1572 pcIn[i].im = pdTemp[i];
1574 fftw_plan plan = fftw_create_plan (ny, FFTW_BACKWARD, FFTW_IN_PLACE);
1575 fftw_one (plan, pcIn, NULL);
1576 fftw_destroy_plan (plan);
1578 double* pX = new double [ny];
1579 double* pYReal = new double [ny];
1580 double* pYImag = new double [ny];
1581 double* pYMag = new double [ny];
1582 for (i = 0; i < ny; i++) {
1584 pYReal[i] = pcIn[i].re;
1585 pYImag[i] = pcIn[i].im;
1586 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1589 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1591 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1593 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1594 std::ostringstream os;
1595 os << "Column " << xCursor;
1596 std::string title("title ");
1598 rPlotFile.addEzsetCommand (title.c_str());
1599 rPlotFile.addEzsetCommand ("xlabel Column");
1600 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1601 rPlotFile.addEzsetCommand ("lxfrac 0");
1602 rPlotFile.addEzsetCommand ("curve 1");
1603 rPlotFile.addEzsetCommand ("color 1");
1604 rPlotFile.addEzsetCommand ("dash 1");
1605 rPlotFile.addEzsetCommand ("curve 2");
1606 rPlotFile.addEzsetCommand ("color 4");
1607 rPlotFile.addEzsetCommand ("dash 3");
1608 rPlotFile.addEzsetCommand ("curve 3");
1609 rPlotFile.addEzsetCommand ("color 0");
1610 rPlotFile.addEzsetCommand ("solid");
1611 rPlotFile.addEzsetCommand ("box");
1612 rPlotFile.addEzsetCommand ("grid");
1613 rPlotFile.setCurveSize (4, ny);
1614 rPlotFile.addColumn (0, pX);
1615 rPlotFile.addColumn (1, pYReal);
1616 rPlotFile.addColumn (2, pYImag);
1617 rPlotFile.addColumn (3, pYMag);
1618 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1619 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1620 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1621 *theApp->getLog() << os.str().c_str() << "\n";
1622 rPlotFile.addDescription (os.str().c_str());
1631 if (theApp->getAskDeleteNewDocs())
1632 pPlotDoc->Modify (true);
1633 pPlotDoc->getView()->getFrame()->Show(true);
1634 pPlotDoc->UpdateAllViews ();
1635 pPlotDoc->Activate();
1641 ImageFileView::OnCompareCol (wxCommandEvent& event)
1643 int xCursor, yCursor;
1644 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1645 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1649 std::vector<ImageFileDocument*> vecIFDoc;
1650 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1651 if (vecIFDoc.size() == 0) {
1652 wxMessageBox ("No compatible images for Column Comparison", "Error");
1655 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1657 if (dialogGetCompare.ShowModal() == wxID_OK) {
1658 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1659 const ImageFile& rIF = GetDocument()->getImageFile();
1660 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1662 ImageFileArrayConst v1 = rIF.getArray();
1663 ImageFileArrayConst v2 = rCompareIF.getArray();
1667 if (v1 != NULL && xCursor < nx) {
1668 double* pX = new double [ny];
1669 double* pY1 = new double [ny];
1670 double* pY2 = new double [ny];
1671 for (int i = 0; i < ny; i++) {
1673 pY1[i] = v1[xCursor][i];
1674 pY2[i] = v2[xCursor][i];
1676 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1678 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1680 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1681 std::ostringstream os;
1682 os << "Column " << xCursor << " Comparison";
1683 std::string title("title ");
1685 rPlotFile.addEzsetCommand (title.c_str());
1686 rPlotFile.addEzsetCommand ("xlabel Row");
1687 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1688 rPlotFile.addEzsetCommand ("lxfrac 0");
1689 rPlotFile.addEzsetCommand ("curve 1");
1690 rPlotFile.addEzsetCommand ("color 2");
1691 rPlotFile.addEzsetCommand ("curve 2");
1692 rPlotFile.addEzsetCommand ("color 4");
1693 rPlotFile.addEzsetCommand ("dash 5");
1694 rPlotFile.addEzsetCommand ("box");
1695 rPlotFile.addEzsetCommand ("grid");
1696 rPlotFile.setCurveSize (3, ny);
1697 rPlotFile.addColumn (0, pX);
1698 rPlotFile.addColumn (1, pY1);
1699 rPlotFile.addColumn (2, pY2);
1702 for (iL = 0; iL < rIF.nLabels(); iL++) {
1703 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1705 s += rIF.labelGet(iL).getLabelString();
1706 rPlotFile.addDescription (s.c_str());
1708 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1709 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1711 s += rCompareIF.labelGet(iL).getLabelString();
1712 rPlotFile.addDescription (s.c_str());
1714 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1715 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1716 *theApp->getLog() << os.str().c_str() << "\n";
1717 rPlotFile.addDescription (os.str().c_str());
1722 if (theApp->getAskDeleteNewDocs())
1723 pPlotDoc->Modify (true);
1724 pPlotDoc->getView()->getFrame()->Show(true);
1725 pPlotDoc->UpdateAllViews ();
1726 pPlotDoc->Activate();
1732 ImageFileView::OnCompareRow (wxCommandEvent& event)
1734 int xCursor, yCursor;
1735 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1736 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1740 std::vector<ImageFileDocument*> vecIFDoc;
1741 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1743 if (vecIFDoc.size() == 0) {
1744 wxMessageBox ("No compatible images for Row Comparison", "Error");
1748 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1750 if (dialogGetCompare.ShowModal() == wxID_OK) {
1751 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1752 const ImageFile& rIF = GetDocument()->getImageFile();
1753 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1755 ImageFileArrayConst v1 = rIF.getArray();
1756 ImageFileArrayConst v2 = rCompareIF.getArray();
1760 if (v1 != NULL && yCursor < ny) {
1761 double* pX = new double [nx];
1762 double* pY1 = new double [nx];
1763 double* pY2 = new double [nx];
1764 for (int i = 0; i < nx; i++) {
1766 pY1[i] = v1[i][yCursor];
1767 pY2[i] = v2[i][yCursor];
1769 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1771 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1773 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1774 std::ostringstream os;
1775 os << "Row " << yCursor << " Comparison";
1776 std::string title("title ");
1778 rPlotFile.addEzsetCommand (title.c_str());
1779 rPlotFile.addEzsetCommand ("xlabel Column");
1780 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1781 rPlotFile.addEzsetCommand ("lxfrac 0");
1782 rPlotFile.addEzsetCommand ("curve 1");
1783 rPlotFile.addEzsetCommand ("color 2");
1784 rPlotFile.addEzsetCommand ("curve 2");
1785 rPlotFile.addEzsetCommand ("color 4");
1786 rPlotFile.addEzsetCommand ("dash 5");
1787 rPlotFile.addEzsetCommand ("box");
1788 rPlotFile.addEzsetCommand ("grid");
1789 rPlotFile.setCurveSize (3, nx);
1790 rPlotFile.addColumn (0, pX);
1791 rPlotFile.addColumn (1, pY1);
1792 rPlotFile.addColumn (2, pY2);
1794 for (iL = 0; iL < rIF.nLabels(); iL++) {
1795 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1797 s += rIF.labelGet(iL).getLabelString();
1798 rPlotFile.addDescription (s.c_str());
1800 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1801 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1803 s += rCompareIF.labelGet(iL).getLabelString();
1804 rPlotFile.addDescription (s.c_str());
1806 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1807 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1808 *theApp->getLog() << os.str().c_str() << "\n";
1809 rPlotFile.addDescription (os.str().c_str());
1814 if (theApp->getAskDeleteNewDocs())
1815 pPlotDoc->Modify (true);
1816 pPlotDoc->getView()->getFrame()->Show(true);
1817 pPlotDoc->UpdateAllViews ();
1818 pPlotDoc->Activate();
1823 static int NUMBER_HISTOGRAM_BINS = 256;
1826 ImageFileView::OnPlotHistogram (wxCommandEvent& event)
1828 const ImageFile& rIF = GetDocument()->getImageFile();
1829 ImageFileArrayConst v = rIF.getArray();
1833 if (v != NULL && nx > 0 && ny > 0) {
1834 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1836 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1840 double* pX = new double [NUMBER_HISTOGRAM_BINS];
1841 double* pY = new double [NUMBER_HISTOGRAM_BINS];
1843 rIF.getMinMax (dMin, dMax);
1844 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
1846 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
1847 pX[i] = dMin + (i + 0.5) * dBinWidth;
1850 for (int ix = 0; ix < nx; ix++)
1851 for (int iy = 0; iy < ny; iy++) {
1852 int iBin = nearest<int> ((v[ix][iy] - dMin) / dBinWidth);
1853 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
1857 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1858 std::ostringstream os;
1860 std::string title("title ");
1862 rPlotFile.addEzsetCommand (title.c_str());
1863 rPlotFile.addEzsetCommand ("xlabel Pixel Value");
1864 rPlotFile.addEzsetCommand ("ylabel Count");
1865 rPlotFile.addEzsetCommand ("box");
1866 rPlotFile.addEzsetCommand ("grid");
1867 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
1868 rPlotFile.addColumn (0, pX);
1869 rPlotFile.addColumn (1, pY);
1870 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++) {
1871 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1873 s += rIF.labelGet(iL).getLabelString();
1874 rPlotFile.addDescription (s.c_str());
1876 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1877 *theApp->getLog() << os.str().c_str() << "\n";
1878 rPlotFile.addDescription (os.str().c_str());
1881 if (theApp->getAskDeleteNewDocs())
1882 pPlotDoc->Modify (true);
1883 pPlotDoc->getView()->getFrame()->Show(true);
1884 pPlotDoc->UpdateAllViews ();
1885 pPlotDoc->Activate();
1892 PhantomCanvas::PhantomCanvas (PhantomFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1893 : wxScrolledWindow(frame, -1, pos, size, style)
1898 PhantomCanvas::~PhantomCanvas ()
1904 PhantomCanvas::OnDraw (wxDC& dc)
1907 m_pView->OnDraw(& dc);
1911 PhantomCanvas::GetBestSize() const
1917 theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
1918 xSize = maxValue<int> (xSize, ySize);
1919 ySize = xSize = (xSize / 4);
1920 return wxSize (xSize, ySize);
1927 IMPLEMENT_DYNAMIC_CLASS(PhantomFileView, wxView)
1929 BEGIN_EVENT_TABLE(PhantomFileView, wxView)
1930 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomFileView::OnProperties)
1931 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomFileView::OnRasterize)
1932 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomFileView::OnProjections)
1935 PhantomFileView::PhantomFileView()
1936 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0)
1938 #if defined(DEBUG) || defined(_DEBUG)
1939 m_iDefaultNDet = 165;
1940 m_iDefaultNView = 180;
1941 m_iDefaultNSample = 1;
1943 m_iDefaultNDet = 367;
1944 m_iDefaultNView = 320;
1945 m_iDefaultNSample = 2;
1947 m_dDefaultRotation = 1;
1948 m_dDefaultFocalLength = 2;
1949 m_dDefaultCenterDetectorLength = 2;
1950 m_dDefaultViewRatio = 1;
1951 m_dDefaultScanRatio = 1;
1952 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
1953 m_iDefaultTrace = Trace::TRACE_NONE;
1956 m_iDefaultRasterNX = 115;
1957 m_iDefaultRasterNY = 115;
1958 m_iDefaultRasterNSamples = 1;
1960 m_iDefaultRasterNX = 256;
1961 m_iDefaultRasterNY = 256;
1962 m_iDefaultRasterNSamples = 2;
1964 m_dDefaultRasterViewRatio = 1;
1967 PhantomFileView::~PhantomFileView()
1969 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
1970 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
1974 PhantomFileView::OnProperties (wxCommandEvent& event)
1976 const int idPhantom = GetDocument()->getPhantomID();
1977 const wxString& namePhantom = GetDocument()->getPhantomName();
1978 std::ostringstream os;
1979 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")" << "\n";
1980 const Phantom& rPhantom = GetDocument()->getPhantom();
1981 rPhantom.printDefinitions (os);
1983 rPhantom.print (os);
1985 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
1986 wxMessageBox (os.str().c_str(), "Phantom Properties");
1987 GetDocument()->Activate();
1992 PhantomFileView::OnProjections (wxCommandEvent& event)
1994 DialogGetProjectionParameters dialogProjection (getFrameForChild(),
1995 m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation,
1996 m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio,
1997 m_iDefaultGeometry, m_iDefaultTrace);
1998 int retVal = dialogProjection.ShowModal();
1999 if (retVal != wxID_OK)
2002 m_iDefaultNDet = dialogProjection.getNDet();
2003 m_iDefaultNView = dialogProjection.getNView();
2004 m_iDefaultNSample = dialogProjection.getNSamples();
2005 m_iDefaultTrace = dialogProjection.getTrace();
2006 m_dDefaultRotation = dialogProjection.getRotAngle();
2007 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
2008 m_dDefaultCenterDetectorLength = dialogProjection.getCenterDetectorLengthRatio();
2009 m_dDefaultViewRatio = dialogProjection.getViewRatio();
2010 m_dDefaultScanRatio = dialogProjection.getScanRatio();
2011 wxString sGeometry = dialogProjection.getGeometry();
2012 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
2013 double dRotationRadians = m_dDefaultRotation;
2014 m_dDefaultRotation /= TWOPI; // convert back to fraction of a circle
2016 if (m_iDefaultNDet <= 0 || m_iDefaultNView <= 0 || sGeometry == "")
2019 const Phantom& rPhantom = GetDocument()->getPhantom();
2020 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample,
2021 dRotationRadians, m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio);
2022 if (theScanner.fail()) {
2023 wxString msg = "Failed making scanner\n";
2024 msg += theScanner.failMessage().c_str();
2025 *theApp->getLog() << msg << "\n";
2026 wxMessageBox (msg, "Error");
2030 std::ostringstream os;
2031 os << "Projections for " << rPhantom.name() << ": nDet=" << m_iDefaultNDet
2032 << ", nView=" << m_iDefaultNView << ", nSamples=" << m_iDefaultNSample
2033 << ", RotAngle=" << m_dDefaultRotation << ", FocalLengthRatio=" << m_dDefaultFocalLength
2034 << ", CenterDetectorLengthRatio=" << m_dDefaultCenterDetectorLength
2035 << ", ViewRatio=" << m_dDefaultViewRatio << ", ScanRatio=" << m_dDefaultScanRatio
2036 << ", Geometry=" << sGeometry.c_str() << ", FanBeamAngle=" <<
2037 convertRadiansToDegrees (theScanner.fanBeamAngle());
2040 Projections* pProj = NULL;
2041 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2042 pProj = new Projections;
2043 pProj->initFromScanner (theScanner);
2045 ProjectionsDialog dialogProjections (theScanner, *pProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(getFrameForChild()));
2046 for (int iView = 0; iView < pProj->nView(); iView++) {
2048 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
2053 while (dialogProjections.isPaused()) {
2060 if (theApp->getUseBackgroundTasks()) {
2061 ProjectorSupervisorThread* pProjector = new ProjectorSupervisorThread (this, m_iDefaultNDet,
2062 m_iDefaultNView, sGeometry.c_str(), m_iDefaultNSample, dRotationRadians,
2063 m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio, os.str().c_str());
2064 if (pProjector->Create() != wxTHREAD_NO_ERROR) {
2065 sys_error (ERR_SEVERE, "Error creating projector thread");
2069 pProjector->SetPriority(60);
2073 #endif // HAVE_WXTHREADS
2075 pProj = new Projections;
2076 pProj->initFromScanner (theScanner);
2077 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), pProj->nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2078 for (int i = 0; i < pProj->nView(); i++) {
2079 theScanner.collectProjections (*pProj, rPhantom, i, 1, true, m_iDefaultTrace);
2080 if (! dlgProgress.Update (i+1)) {
2088 *theApp->getLog() << os.str().c_str() << "\n";
2089 pProj->setRemark (os.str());
2090 pProj->setCalcTime (timer.timerEnd());
2092 ProjectionFileDocument* pProjectionDoc = theApp->newProjectionDoc();
2093 if (! pProjectionDoc) {
2094 sys_error (ERR_SEVERE, "Unable to create projection document");
2097 pProjectionDoc->setProjections (pProj);
2098 ProjectionFileView* projView = pProjectionDoc->getView();
2100 projView->OnUpdate (projView, NULL);
2101 if (projView->getCanvas())
2102 projView->getCanvas()->SetClientSize (m_iDefaultNDet, m_iDefaultNView);
2103 if (wxFrame* pFrame = projView->getFrame()) {
2108 GetDocumentManager()->ActivateView (projView, true, false);
2110 if (theApp->getAskDeleteNewDocs())
2111 pProjectionDoc-> Modify(true);
2112 pProjectionDoc->UpdateAllViews (this);
2113 pProjectionDoc->Activate();
2118 PhantomFileView::OnRasterize (wxCommandEvent& event)
2120 DialogGetRasterParameters dialogRaster (getFrameForChild(), m_iDefaultRasterNX, m_iDefaultRasterNY,
2121 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio);
2122 int retVal = dialogRaster.ShowModal();
2123 if (retVal != wxID_OK)
2126 m_iDefaultRasterNX = dialogRaster.getXSize();
2127 m_iDefaultRasterNY = dialogRaster.getYSize();
2128 m_iDefaultRasterNSamples = dialogRaster.getNSamples();
2129 m_dDefaultRasterViewRatio = dialogRaster.getViewRatio();
2130 if (m_iDefaultRasterNSamples < 1)
2131 m_iDefaultRasterNSamples = 1;
2132 if (m_dDefaultRasterViewRatio < 0)
2133 m_dDefaultRasterViewRatio = 0;
2134 if (m_iDefaultRasterNX <= 0 || m_iDefaultRasterNY <= 0)
2137 const Phantom& rPhantom = GetDocument()->getPhantom();
2138 std::ostringstream os;
2139 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << m_iDefaultRasterNX << ", YSize="
2140 << m_iDefaultRasterNY << ", ViewRatio=" << m_dDefaultRasterViewRatio << ", nSamples="
2141 << m_iDefaultRasterNSamples;;
2144 if (theApp->getUseBackgroundTasks()) {
2145 RasterizerSupervisorThread* pThread = new RasterizerSupervisorThread (this, m_iDefaultRasterNX, m_iDefaultRasterNY,
2146 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio, os.str().c_str());
2147 if (pThread->Create() != wxTHREAD_NO_ERROR) {
2148 *theApp->getLog() << "Error creating rasterizer thread\n";
2151 pThread->SetPriority (60);
2156 ImageFile* pImageFile = new ImageFile (m_iDefaultRasterNX, m_iDefaultRasterNY);
2157 wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"),
2158 pImageFile->nx() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2160 for (unsigned int i = 0; i < pImageFile->nx(); i++) {
2161 rPhantom.convertToImagefile (*pImageFile, m_dDefaultRasterViewRatio, m_iDefaultRasterNSamples, Trace::TRACE_NONE, i, 1, true);
2162 if (! dlgProgress.Update (i+1)) {
2168 ImageFileDocument* pRasterDoc = theApp->newImageDoc();
2170 sys_error (ERR_SEVERE, "Unable to create image file");
2173 pRasterDoc->setImageFile (pImageFile);
2174 if (theApp->getAskDeleteNewDocs())
2175 pRasterDoc->Modify (true);
2176 pRasterDoc->UpdateAllViews (this);
2177 pRasterDoc->getView()->getFrame()->Show(true);
2178 *theApp->getLog() << os.str().c_str() << "\n";
2179 pImageFile->labelAdd (os.str().c_str(), timer.timerEnd());
2180 ImageFileView* rasterView = pRasterDoc->getView();
2182 rasterView->getFrame()->SetFocus();
2183 rasterView->OnUpdate (rasterView, NULL);
2185 pRasterDoc->Activate();
2191 PhantomFileView::CreateCanvas (wxFrame *parent)
2193 PhantomCanvas* pCanvas;
2195 pCanvas = new PhantomCanvas (this, parent, wxPoint(0, 0), wxSize(0,0), 0);
2196 pCanvas->SetBackgroundColour(*wxWHITE);
2207 PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2210 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2212 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2214 theApp->setIconForFrame (subframe);
2216 m_pFileMenu = new wxMenu;
2218 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2219 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2220 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2221 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2222 m_pFileMenu->Append(wxID_CLOSE, "&Close");
2224 m_pFileMenu->AppendSeparator();
2225 m_pFileMenu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
2227 m_pFileMenu->AppendSeparator();
2228 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2229 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2230 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2231 m_pFileMenu->AppendSeparator();
2232 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
2234 m_pFileMenu->AppendSeparator();
2235 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
2236 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2238 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2239 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2241 wxMenu *process_menu = new wxMenu;
2242 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...\tCtrl-R");
2243 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...\tCtrl-J");
2245 wxMenu *help_menu = new wxMenu;
2246 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2247 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
2248 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
2249 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2251 wxMenuBar *menu_bar = new wxMenuBar;
2253 menu_bar->Append(m_pFileMenu, "&File");
2254 menu_bar->Append(process_menu, "&Process");
2255 menu_bar->Append(help_menu, "&Help");
2257 subframe->SetMenuBar(menu_bar);
2258 subframe->Centre(wxBOTH);
2260 wxAcceleratorEntry accelEntries[3];
2261 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('J'), PHMMENU_PROCESS_PROJECTIONS);
2262 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('R'), PHMMENU_PROCESS_RASTERIZE);
2263 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('I'), PHMMENU_FILE_PROPERTIES);
2264 wxAcceleratorTable accelTable (3, accelEntries);
2265 subframe->SetAcceleratorTable (accelTable);
2272 PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2274 m_pFrame = CreateChildFrame(doc, this);
2276 m_pCanvas = CreateCanvas (m_pFrame);
2277 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
2278 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
2280 m_pFrame->SetTitle ("PhantomFileView");
2283 int x, y; // X requires a forced resize
2284 m_pFrame->GetSize(&x, &y);
2285 m_pFrame->SetSize(-1, -1, x, y);
2288 m_pFrame->Show(true);
2295 PhantomFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2298 m_pCanvas->Refresh();
2302 PhantomFileView::OnClose (bool deleteWindow)
2304 //GetDocumentManager()->ActivateView (this, false, true);
2305 if (! GetDocument() || ! GetDocument()->Close())
2310 m_pCanvas->setView(NULL);
2313 wxString s(wxTheApp->GetAppName());
2315 m_pFrame->SetTitle(s);
2322 if (GetDocument() && GetDocument()->getBadFileOpen())
2323 ::wxYield(); // wxWindows bug workaround
2330 PhantomFileView::OnDraw (wxDC* dc)
2333 m_pCanvas->GetClientSize (&xsize, &ysize);
2334 SGPDriver driver (dc, xsize, ysize);
2336 const Phantom& rPhantom = GetDocument()->getPhantom();
2337 sgp.setColor (C_RED);
2338 rPhantom.show (sgp);
2343 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2344 : wxScrolledWindow(frame, -1, pos, size, style)
2349 ProjectionFileCanvas::~ProjectionFileCanvas ()
2355 ProjectionFileCanvas::OnDraw(wxDC& dc)
2358 m_pView->OnDraw(& dc);
2362 ProjectionFileCanvas::GetBestSize () const
2366 Projections& rProj = m_pView->GetDocument()->getProjections();
2367 best.Set (rProj.nDet(), rProj.nView());
2374 // ProjectionFileView
2376 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
2378 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
2379 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
2380 EVT_MENU(PJMENU_RECONSTRUCT_FBP, ProjectionFileView::OnReconstructFBP)
2381 EVT_MENU(PJMENU_RECONSTRUCT_FBP_REBIN, ProjectionFileView::OnReconstructFBPRebin)
2382 EVT_MENU(PJMENU_RECONSTRUCT_FOURIER, ProjectionFileView::OnReconstructFourier)
2383 EVT_MENU(PJMENU_CONVERT_POLAR, ProjectionFileView::OnConvertPolar)
2384 EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
2385 EVT_MENU(PJMENU_CONVERT_PARALLEL, ProjectionFileView::OnConvertParallel)
2386 EVT_MENU(PJMENU_PLOT_TTHETA_SAMPLING, ProjectionFileView::OnPlotTThetaSampling)
2387 EVT_MENU(PJMENU_ARTIFACT_REDUCTION, ProjectionFileView::OnArtifactReduction)
2391 ProjectionFileView::ProjectionFileView()
2392 : wxView(), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0)
2402 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
2403 m_dDefaultFilterParam = 1.;
2405 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
2406 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
2408 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
2409 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
2411 m_iDefaultZeropad = 1;
2412 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF;
2413 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
2414 m_iDefaultInterpParam = 1;
2415 m_iDefaultTrace = Trace::TRACE_NONE;
2417 m_iDefaultPolarNX = 256;
2418 m_iDefaultPolarNY = 256;
2419 m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR;
2420 m_iDefaultPolarZeropad = 1;
2423 ProjectionFileView::~ProjectionFileView()
2425 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2426 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2430 ProjectionFileView::OnProperties (wxCommandEvent& event)
2432 const Projections& rProj = GetDocument()->getProjections();
2433 std::ostringstream os;
2434 rProj.printScanInfo(os);
2435 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2436 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
2437 dialogMsg.ShowModal();
2438 GetDocument()->Activate();
2443 ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
2445 Projections& rProj = GetDocument()->getProjections();
2446 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2447 m_iDefaultPolarInterpolation, -1);
2448 if (dialogPolar.ShowModal() == wxID_OK) {
2449 wxProgressDialog dlgProgress (wxString("Convert Polar"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2450 wxString strInterpolation (dialogPolar.getInterpolationName());
2451 m_iDefaultPolarNX = dialogPolar.getXSize();
2452 m_iDefaultPolarNY = dialogPolar.getYSize();
2453 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2454 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2455 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2457 if (! rProj.convertPolar (*pIF, m_iDefaultPolarInterpolation)) {
2459 *theApp->getLog() << "Error converting to Polar\n";
2463 pPolarDoc = theApp->newImageDoc ();
2465 sys_error (ERR_SEVERE, "Unable to create image file");
2468 pPolarDoc->setImageFile (pIF);
2469 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2470 std::ostringstream os;
2471 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to polar image: xSize="
2472 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2473 << strInterpolation.c_str();
2474 *theApp->getLog() << os.str().c_str() << "\n";
2475 pIF->labelAdd (os.str().c_str());
2476 if (theApp->getAskDeleteNewDocs())
2477 pPolarDoc->Modify (true);
2478 pPolarDoc->getView()->getFrame()->Show(true);
2479 pPolarDoc->UpdateAllViews ();
2480 pPolarDoc->Activate();
2485 ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
2487 Projections& rProj = GetDocument()->getProjections();
2488 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert to FFT Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2489 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad);
2490 if (dialogPolar.ShowModal() == wxID_OK) {
2491 wxProgressDialog dlgProgress (wxString("Convert FFT Polar"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2492 wxString strInterpolation (dialogPolar.getInterpolationName());
2493 m_iDefaultPolarNX = dialogPolar.getXSize();
2494 m_iDefaultPolarNY = dialogPolar.getYSize();
2495 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2496 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2498 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2499 if (! rProj.convertFFTPolar (*pIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad)) {
2501 *theApp->getLog() << "Error converting to polar\n";
2504 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2506 sys_error (ERR_SEVERE, "Unable to create image file");
2509 pPolarDoc->setImageFile (pIF);
2510 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2511 std::ostringstream os;
2512 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to FFT polar image: xSize="
2513 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2514 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2515 *theApp->getLog() << os.str().c_str() << "\n";
2516 pIF->labelAdd (os.str().c_str());
2517 if (theApp->getAskDeleteNewDocs())
2518 pPolarDoc->Modify (true);
2519 pPolarDoc->getView()->getFrame()->Show(true);
2520 pPolarDoc->UpdateAllViews ();
2521 pPolarDoc->Activate();
2526 ProjectionFileView::OnPlotTThetaSampling (wxCommandEvent& event)
2528 DialogGetThetaRange dlgTheta (this->getFrame(), ParallelRaysums::THETA_RANGE_UNCONSTRAINED);
2529 if (dlgTheta.ShowModal() != wxID_OK)
2532 int iThetaRange = dlgTheta.getThetaRange();
2534 Projections& rProj = GetDocument()->getProjections();
2535 ParallelRaysums parallel (&rProj, iThetaRange);
2536 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
2537 PlotFile& rPlot = pPlotDoc->getPlotFile();
2538 ParallelRaysums::CoordinateContainer& coordContainer = parallel.getCoordinates();
2539 double* pdT = new double [parallel.getNumCoordinates()];
2540 double* pdTheta = new double [parallel.getNumCoordinates()];
2542 for (int i = 0; i < parallel.getNumCoordinates(); i++) {
2543 pdT[i] = coordContainer[i]->m_dT;
2544 pdTheta[i] = coordContainer[i]->m_dTheta;
2546 rPlot.setCurveSize (2, parallel.getNumCoordinates(), true);
2547 rPlot.addEzsetCommand ("title T-Theta Sampling");
2548 rPlot.addEzsetCommand ("xlabel T");
2549 rPlot.addEzsetCommand ("ylabel Theta");
2550 rPlot.addEzsetCommand ("curve 1");
2551 if (rProj.nDet() < 50 && rProj.nView() < 50)
2552 rPlot.addEzsetCommand ("symbol 1"); // x symbol
2554 rPlot.addEzsetCommand ("symbol 6"); // point symbol
2555 rPlot.addEzsetCommand ("noline");
2556 rPlot.addColumn (0, pdT);
2557 rPlot.addColumn (1, pdTheta);
2560 if (theApp->getAskDeleteNewDocs())
2561 pPlotDoc->Modify (true);
2562 pPlotDoc->getView()->getFrame()->Show(true);
2563 pPlotDoc->UpdateAllViews ();
2564 pPlotDoc->Activate();
2568 ProjectionFileView::OnConvertParallel (wxCommandEvent& event)
2570 Projections& rProj = GetDocument()->getProjections();
2571 if (rProj.geometry() == Scanner::GEOMETRY_PARALLEL) {
2572 wxMessageBox ("Projections are already parallel", "Error");
2575 wxProgressDialog dlgProgress (wxString("Convert to Parallel"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2576 Projections* pProjNew = rProj.interpolateToParallel();
2577 ProjectionFileDocument* pProjDocNew = theApp->newProjectionDoc();
2578 pProjDocNew->setProjections (pProjNew);
2580 if (ProjectionFileView* projView = pProjDocNew->getView()) {
2581 projView->OnUpdate (projView, NULL);
2582 if (projView->getCanvas())
2583 projView->getCanvas()->SetClientSize (pProjNew->nDet(), pProjNew->nView());
2584 if (wxFrame* pFrame = projView->getFrame()) {
2589 GetDocumentManager()->ActivateView (projView, true, false);
2591 if (theApp->getAskDeleteNewDocs())
2592 pProjDocNew-> Modify(true);
2593 pProjDocNew->UpdateAllViews (this);
2594 pProjDocNew->Activate();
2598 ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
2600 wxMessageBox ("Fourier Reconstruction is not yet supported", "Unimplemented function");
2604 ProjectionFileView::OnReconstructFBPRebin (wxCommandEvent& event)
2606 Projections& rProj = GetDocument()->getProjections();
2607 doReconstructFBP (rProj, true);
2611 ProjectionFileView::OnReconstructFBP (wxCommandEvent& event)
2613 Projections& rProj = GetDocument()->getProjections();
2614 doReconstructFBP (rProj, false);
2618 ProjectionFileView::doReconstructFBP (const Projections& rProj, bool bRebinToParallel)
2620 ReconstructionROI defaultROI;
2621 defaultROI.m_dXMin = -rProj.phmLen() / 2;
2622 defaultROI.m_dXMax = defaultROI.m_dXMin + rProj.phmLen();
2623 defaultROI.m_dYMin = -rProj.phmLen() / 2;
2624 defaultROI.m_dYMax = defaultROI.m_dYMin + rProj.phmLen();
2626 DialogGetReconstructionParameters dialogReconstruction (getFrameForChild(), m_iDefaultNX, m_iDefaultNY,
2627 m_iDefaultFilter, m_dDefaultFilterParam, m_iDefaultFilterMethod, m_iDefaultFilterGeneration,
2628 m_iDefaultZeropad, m_iDefaultInterpolation, m_iDefaultInterpParam, m_iDefaultBackprojector,
2629 m_iDefaultTrace, &defaultROI);
2631 int retVal = dialogReconstruction.ShowModal();
2632 if (retVal != wxID_OK)
2635 m_iDefaultNX = dialogReconstruction.getXSize();
2636 m_iDefaultNY = dialogReconstruction.getYSize();
2637 wxString optFilterName = dialogReconstruction.getFilterName();
2638 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
2639 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
2640 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
2641 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
2642 m_iDefaultZeropad = dialogReconstruction.getZeropad();
2643 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
2644 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
2645 wxString optInterpName = dialogReconstruction.getInterpName();
2646 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
2647 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
2648 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
2649 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
2650 m_iDefaultTrace = dialogReconstruction.getTrace();
2651 dialogReconstruction.getROI (&defaultROI);
2653 if (m_iDefaultNX <= 0 && m_iDefaultNY <= 0)
2656 std::ostringstream os;
2657 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();
2658 if (bRebinToParallel)
2659 os << "; Interpolate to Parallel";
2662 ImageFile* pImageFile = NULL;
2663 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2664 pImageFile = new ImageFile (m_iDefaultNX, m_iDefaultNY);
2665 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2666 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2667 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace,
2668 &defaultROI, bRebinToParallel);
2670 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstructor, rProj, *pImageFile, m_iDefaultTrace, getFrameForChild());
2671 for (int iView = 0; iView < rProj.nView(); iView++) {
2673 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView, true)) {
2674 delete pDlgReconstruct;
2675 delete pReconstructor;
2680 while (pDlgReconstruct->isPaused()) {
2685 pReconstructor->postProcessing();
2686 delete pDlgReconstruct;
2687 delete pReconstructor;
2690 if (theApp->getUseBackgroundTasks()) {
2691 ReconstructorSupervisorThread* pReconstructor = new ReconstructorSupervisorThread (this, m_iDefaultNX,
2692 m_iDefaultNY, optFilterName.c_str(), m_dDefaultFilterParam, optFilterMethodName.c_str(),
2693 m_iDefaultZeropad, optFilterGenerationName.c_str(), optInterpName.c_str(), m_iDefaultInterpParam,
2694 optBackprojectName.c_str(), os.str().c_str(), &defaultROI, bRebinToParallel);
2695 if (pReconstructor->Create() != wxTHREAD_NO_ERROR) {
2696 sys_error (ERR_SEVERE, "Error creating reconstructor thread");
2697 delete pReconstructor;
2700 pReconstructor->SetPriority (60);
2701 pReconstructor->Run();
2706 pImageFile = new ImageFile (m_iDefaultNX, m_iDefaultNY);
2707 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2708 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2709 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2710 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace,
2711 &defaultROI, bRebinToParallel);
2713 for (int iView = 0; iView < rProj.nView(); iView++) {
2714 pReconstructor->reconstructView (iView, 1);
2715 if (! dlgProgress.Update (iView + 1)) {
2716 delete pReconstructor;
2717 return; // don't make new window, thread will do this
2720 pReconstructor->postProcessing();
2721 delete pReconstructor;
2724 ImageFileDocument* pReconDoc = theApp->newImageDoc();
2726 sys_error (ERR_SEVERE, "Unable to create image file");
2729 pReconDoc->setImageFile (pImageFile);
2730 if (theApp->getAskDeleteNewDocs())
2731 pReconDoc->Modify (true);
2732 pReconDoc->UpdateAllViews (this);
2733 pReconDoc->Activate();
2734 if (ImageFileView* rasterView = pReconDoc->getView()) {
2735 rasterView->OnUpdate (rasterView, NULL);
2736 rasterView->getFrame()->SetFocus();
2737 rasterView->getFrame()->Show(true);
2739 *theApp->getLog() << os.str().c_str() << "\n";
2740 pImageFile->labelAdd (rProj.getLabel());
2741 pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd());
2746 ProjectionFileView::OnArtifactReduction (wxCommandEvent& event)
2751 ProjectionFileCanvas*
2752 ProjectionFileView::CreateCanvas (wxFrame *parent)
2754 ProjectionFileCanvas* pCanvas;
2756 parent->GetClientSize(&width, &height);
2758 pCanvas = new ProjectionFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
2760 pCanvas->SetScrollbars(20, 20, 50, 50);
2761 pCanvas->SetBackgroundColour(*wxWHITE);
2772 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2775 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2777 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2779 theApp->setIconForFrame (subframe);
2781 m_pFileMenu = new wxMenu;
2783 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2784 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2785 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2786 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2787 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2788 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2790 m_pFileMenu->AppendSeparator();
2791 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
2793 m_pFileMenu->AppendSeparator();
2794 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2795 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2796 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2797 m_pFileMenu->AppendSeparator();
2798 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
2800 m_pFileMenu->AppendSeparator();
2801 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
2802 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2804 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2805 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2807 wxMenu *convert_menu = new wxMenu;
2808 convert_menu->Append (PJMENU_CONVERT_POLAR, "&Polar Image...\tCtrl-L");
2809 convert_menu->Append (PJMENU_CONVERT_FFT_POLAR, "&FFT->Polar Image...\tCtrl-M");
2810 convert_menu->AppendSeparator();
2811 convert_menu->Append (PJMENU_CONVERT_PARALLEL, "&Interpolate to Parallel");
2813 wxMenu* filter_menu = new wxMenu;
2814 filter_menu->Append (PJMENU_ARTIFACT_REDUCTION, "&Artifact Reduction");
2816 wxMenu* analyze_menu = new wxMenu;
2817 analyze_menu->Append (PJMENU_PLOT_TTHETA_SAMPLING, "&Plot T-Theta Sampling\tCtrl-T");
2819 wxMenu *reconstruct_menu = new wxMenu;
2820 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP, "&Filtered Backprojection...\tCtrl-R", "Reconstruct image using filtered backprojection");
2821 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP_REBIN, "Filtered &Backprojection (Rebin to Parallel)...\tCtrl-B", "Reconstruct image using filtered backprojection");
2822 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Fourier...\tCtrl-E", "Reconstruct image using inverse Fourier");
2823 reconstruct_menu->Enable (PJMENU_RECONSTRUCT_FOURIER, false);
2825 wxMenu *help_menu = new wxMenu;
2826 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2827 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
2828 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
2829 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2831 wxMenuBar *menu_bar = new wxMenuBar;
2833 menu_bar->Append (m_pFileMenu, "&File");
2834 menu_bar->Append (convert_menu, "&Convert");
2835 menu_bar->Append (filter_menu, "Fi<er");
2836 menu_bar->Append (analyze_menu, "&Analyze");
2837 menu_bar->Append (reconstruct_menu, "&Reconstruct");
2838 menu_bar->Append (help_menu, "&Help");
2840 subframe->SetMenuBar(menu_bar);
2841 subframe->Centre(wxBOTH);
2843 wxAcceleratorEntry accelEntries[7];
2844 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('L'), PJMENU_CONVERT_POLAR);
2845 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('M'), PJMENU_CONVERT_FFT_POLAR);
2846 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('R'), PJMENU_RECONSTRUCT_FBP);
2847 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('B'), PJMENU_RECONSTRUCT_FBP_REBIN);
2848 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('E'), PJMENU_RECONSTRUCT_FOURIER);
2849 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('I'), PJMENU_FILE_PROPERTIES);
2850 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('T'), PJMENU_PLOT_TTHETA_SAMPLING);
2851 wxAcceleratorTable accelTable (7, accelEntries);
2852 subframe->SetAcceleratorTable (accelTable);
2859 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2861 m_pFrame = CreateChildFrame(doc, this);
2865 m_pFrame->GetClientSize (&width, &height);
2866 m_pFrame->SetTitle ("ProjectionFileView");
2867 m_pCanvas = CreateCanvas (m_pFrame);
2870 int x, y; // X requires a forced resize
2871 m_pFrame->GetSize(&x, &y);
2872 m_pFrame->SetSize(-1, -1, x, y);
2875 m_pFrame->Show(true);
2882 ProjectionFileView::OnDraw (wxDC* dc)
2884 wxSize clientSize = m_pFrame->GetClientSize();
2885 wxSize bestSize = m_pCanvas->GetBestSize();
2887 if (clientSize.x > bestSize.x || clientSize.y > bestSize.y)
2888 m_pFrame->SetClientSize (bestSize);
2891 dc->DrawBitmap (m_bitmap, 0, 0, false);
2896 ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2898 const Projections& rProj = GetDocument()->getProjections();
2899 const int nDet = rProj.nDet();
2900 const int nView = rProj.nView();
2901 if (nDet != 0 && nView != 0) {
2902 const DetectorArray& detarray = rProj.getDetectorArray(0);
2903 const DetectorValue* detval = detarray.detValues();
2904 double min = detval[0];
2905 double max = detval[0];
2906 for (int iy = 0; iy < nView; iy++) {
2907 const DetectorArray& detarray = rProj.getDetectorArray(iy);
2908 const DetectorValue* detval = detarray.detValues();
2909 for (int ix = 0; ix < nDet; ix++) {
2910 if (min > detval[ix])
2912 else if (max < detval[ix])
2917 unsigned char* imageData = new unsigned char [nDet * nView * 3];
2919 sys_error (ERR_SEVERE, "Unable to allocate memory for image display");
2922 double scale = (max - min) / 255;
2923 for (int iy2 = 0; iy2 < nView; iy2++) {
2924 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
2925 const DetectorValue* detval = detarray.detValues();
2926 for (int ix = 0; ix < nDet; ix++) {
2927 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
2928 intensity = clamp(intensity, 0, 255);
2929 int baseAddr = (iy2 * nDet + ix) * 3;
2930 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
2933 wxImage image (nDet, nView, imageData, true);
2934 m_bitmap = image.ConvertToBitmap();
2938 xSize = clamp (xSize, 0, 800);
2939 ySize = clamp (ySize, 0, 800);
2940 m_pFrame->SetClientSize (xSize, ySize);
2941 m_pCanvas->SetScrollbars (20, 20, nDet/20, nView/20);
2945 m_pCanvas->Refresh();
2949 ProjectionFileView::OnClose (bool deleteWindow)
2951 //GetDocumentManager()->ActivateView (this, false, true);
2952 if (! GetDocument() || ! GetDocument()->Close())
2957 m_pCanvas->setView(NULL);
2960 wxString s(wxTheApp->GetAppName());
2962 m_pFrame->SetTitle(s);
2969 if (GetDocument() && GetDocument()->getBadFileOpen())
2970 ::wxYield(); // wxWindows bug workaround
2979 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2980 : wxScrolledWindow(frame, -1, pos, size, style)
2985 PlotFileCanvas::~PlotFileCanvas ()
2991 PlotFileCanvas::OnDraw(wxDC& dc)
2994 m_pView->OnDraw(& dc);
3000 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
3002 BEGIN_EVENT_TABLE(PlotFileView, wxView)
3003 EVT_MENU(PLOTMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
3004 EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
3005 EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
3006 EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
3009 PlotFileView::PlotFileView()
3010 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pEZPlot(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
3014 PlotFileView::~PlotFileView()
3019 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
3023 PlotFileView::OnProperties (wxCommandEvent& event)
3025 const PlotFile& rPlot = GetDocument()->getPlotFile();
3026 std::ostringstream os;
3027 os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
3028 rPlot.printHeadersBrief (os);
3029 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<<\n";
3030 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
3031 dialogMsg.ShowModal();
3032 GetDocument()->Activate();
3037 PlotFileView::OnScaleAuto (wxCommandEvent& event)
3039 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3040 double min, max, mean, mode, median, stddev;
3041 rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
3042 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
3043 int iRetVal = dialogAutoScale.ShowModal();
3044 if (iRetVal == wxID_OK) {
3045 m_bMinSpecified = true;
3046 m_bMaxSpecified = true;
3048 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
3051 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
3052 OnUpdate (this, NULL);
3055 GetDocument()->Activate();
3059 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
3061 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3065 if (! m_bMinSpecified || ! m_bMaxSpecified) {
3066 if (! rPlotFile.getMinMax (1, min, max)) {
3067 *theApp->getLog() << "Error: unable to find Min/Max\n";
3072 if (m_bMinSpecified)
3074 if (m_bMaxSpecified)
3077 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Y-axis Minimum & Maximum", min, max);
3078 int retVal = dialogMinMax.ShowModal();
3079 if (retVal == wxID_OK) {
3080 m_bMinSpecified = true;
3081 m_bMaxSpecified = true;
3082 m_dMinPixel = dialogMinMax.getMinimum();
3083 m_dMaxPixel = dialogMinMax.getMaximum();
3084 OnUpdate (this, NULL);
3086 GetDocument()->Activate();
3090 PlotFileView::OnScaleFull (wxCommandEvent& event)
3092 if (m_bMinSpecified || m_bMaxSpecified) {
3093 m_bMinSpecified = false;
3094 m_bMaxSpecified = false;
3095 OnUpdate (this, NULL);
3097 GetDocument()->Activate();
3102 PlotFileView::CreateCanvas (wxFrame* parent)
3104 PlotFileCanvas* pCanvas;
3106 parent->GetClientSize(&width, &height);
3108 pCanvas = new PlotFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
3110 pCanvas->SetBackgroundColour(*wxWHITE);
3121 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
3124 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
3126 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
3128 theApp->setIconForFrame (subframe);
3130 m_pFileMenu = new wxMenu;
3132 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3133 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3134 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3135 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3136 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3137 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3139 m_pFileMenu->AppendSeparator();
3140 m_pFileMenu->Append(PLOTMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
3142 m_pFileMenu->AppendSeparator();
3143 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3144 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3145 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3146 m_pFileMenu->AppendSeparator();
3147 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3149 m_pFileMenu->AppendSeparator();
3150 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3151 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3153 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3154 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3156 wxMenu *view_menu = new wxMenu;
3157 view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...\tCtrl-E");
3158 view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
3159 view_menu->Append(PLOTMENU_VIEW_SCALE_FULL, "Display &Full Scale\tCtrl-U");
3161 wxMenu *help_menu = new wxMenu;
3162 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3163 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3164 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3165 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3167 wxMenuBar *menu_bar = new wxMenuBar;
3169 menu_bar->Append(m_pFileMenu, "&File");
3170 menu_bar->Append(view_menu, "&View");
3171 menu_bar->Append(help_menu, "&Help");
3173 subframe->SetMenuBar(menu_bar);
3174 subframe->Centre(wxBOTH);
3176 wxAcceleratorEntry accelEntries[4];
3177 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('E'), PLOTMENU_VIEW_SCALE_MINMAX);
3178 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('A'), PLOTMENU_VIEW_SCALE_AUTO);
3179 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('U'), PLOTMENU_VIEW_SCALE_FULL);
3180 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), PLOTMENU_FILE_PROPERTIES);
3181 wxAcceleratorTable accelTable (4, accelEntries);
3182 subframe->SetAcceleratorTable (accelTable);
3189 PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
3191 m_pFrame = CreateChildFrame(doc, this);
3194 m_bMinSpecified = false;
3195 m_bMaxSpecified = false;
3196 m_dAutoScaleFactor = 1.;
3199 m_pFrame->GetClientSize(&width, &height);
3200 m_pFrame->SetTitle ("Plot File");
3201 m_pCanvas = CreateCanvas (m_pFrame);
3204 int x, y; // X requires a forced resize
3205 m_pFrame->GetSize(&x, &y);
3206 m_pFrame->SetSize(-1, -1, x, y);
3209 m_pFrame->Show(true);
3216 PlotFileView::OnDraw (wxDC* dc)
3218 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3219 const int iNColumns = rPlotFile.getNumColumns();
3220 const int iNRecords = rPlotFile.getNumRecords();
3222 if (iNColumns > 0 && iNRecords > 0) {
3224 m_pCanvas->GetClientSize (&xsize, &ysize);
3225 SGPDriver driver (dc, xsize, ysize);
3228 m_pEZPlot->plot (&sgp);
3234 PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3236 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3237 const int iNColumns = rPlotFile.getNumColumns();
3238 const int iNRecords = rPlotFile.getNumRecords();
3239 const bool bScatterPlot = rPlotFile.getIsScatterPlot();
3241 if (iNColumns > 0 && iNRecords > 0) {
3244 m_pEZPlot = new EZPlot;
3246 for (unsigned int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)
3247 m_pEZPlot->ezset (rPlotFile.getEzsetCommand (iEzset));
3249 if (m_bMinSpecified) {
3250 std::ostringstream os;
3251 os << "ymin " << m_dMinPixel;
3252 m_pEZPlot->ezset (os.str());
3255 if (m_bMaxSpecified) {
3256 std::ostringstream os;
3257 os << "ymax " << m_dMaxPixel;
3258 m_pEZPlot->ezset (os.str());
3261 m_pEZPlot->ezset("box");
3262 m_pEZPlot->ezset("grid");
3264 double* pdX = new double [iNRecords];
3265 double* pdY = new double [iNRecords];
3266 if (! bScatterPlot) {
3267 rPlotFile.getColumn (0, pdX);
3269 for (int iCol = 1; iCol < iNColumns; iCol++) {
3270 rPlotFile.getColumn (iCol, pdY);
3271 m_pEZPlot->addCurve (pdX, pdY, iNRecords);
3274 rPlotFile.getColumn (0, pdX);
3275 rPlotFile.getColumn (1, pdY);
3276 m_pEZPlot->addCurve (pdX, pdY, iNRecords);
3283 m_pCanvas->Refresh();
3287 PlotFileView::OnClose (bool deleteWindow)
3289 //GetDocumentManager()->ActivateView (this, false, true);
3290 if (! GetDocument() || ! GetDocument()->Close())
3295 m_pCanvas->setView (NULL);
3298 wxString s(wxTheApp->GetAppName());
3300 m_pFrame->SetTitle(s);
3306 if (GetDocument() && GetDocument()->getBadFileOpen())
3307 ::wxYield(); // wxWindows bug workaround
3314 ////////////////////////////////////////////////////////////////
3317 IMPLEMENT_DYNAMIC_CLASS(TextFileView, wxView)
3319 TextFileView::~TextFileView()
3321 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
3322 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
3325 bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
3327 m_pFrame = CreateChildFrame(doc, this);
3328 SetFrame (m_pFrame);
3331 m_pFrame->GetClientSize(&width, &height);
3332 m_pFrame->SetTitle("TextFile");
3333 m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
3334 m_pFrame->SetTitle("Log");
3337 // X seems to require a forced resize
3339 frame->GetSize(&x, &y);
3340 frame->SetSize(-1, -1, x, y);
3343 m_pFrame->Show (true);
3349 // Handled by wxTextWindow
3350 void TextFileView::OnDraw(wxDC *WXUNUSED(dc) )
3354 void TextFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3359 TextFileView::OnClose (bool deleteWindow)
3361 if (! theApp->getMainFrame()->getShuttingDown())
3365 //GetDocumentManager()->ActivateView (this, false, true);
3366 if (! GetDocument() || ! GetDocument()->Close())
3373 if (GetDocument() && GetDocument()->getBadFileOpen())
3374 ::wxYield(); // wxWindows bug workaround
3385 TextFileView::CreateChildFrame (wxDocument *doc, wxView *view)
3388 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(0,0), wxDEFAULT_FRAME_STYLE, "Log");
3390 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE, "Log");
3392 theApp->setIconForFrame (subframe);
3394 m_pFileMenu = new wxMenu;
3396 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3397 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3398 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3399 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3400 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3401 // m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3403 m_pFileMenu->AppendSeparator();
3404 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3405 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3406 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3407 m_pFileMenu->AppendSeparator();
3408 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3410 m_pFileMenu->AppendSeparator();
3411 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3412 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3414 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3415 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3417 wxMenu *help_menu = new wxMenu;
3418 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3419 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3420 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3421 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3423 wxMenuBar *menu_bar = new wxMenuBar;
3425 menu_bar->Append(m_pFileMenu, "&File");
3426 menu_bar->Append(help_menu, "&Help");
3428 subframe->SetMenuBar(menu_bar);
3429 subframe->Centre(wxBOTH);
3435 // Define a constructor for my text subwindow
3436 TextFileCanvas::TextFileCanvas (TextFileView* v, wxFrame* frame, const wxPoint& pos, const wxSize& size, long style)
3437 : wxTextCtrl (frame, -1, "", pos, size, style), m_pView(v)
3441 TextFileCanvas::~TextFileCanvas ()