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.167 2003/01/29 07:18:38 kevin Exp $
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
28 #include "wx/wxprec.h"
33 #if !wxUSE_DOC_VIEW_ARCHITECTURE
34 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
38 #include "wx/progdlg.h"
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>
61 // Used to reduce calls to progress bar update function
62 const short int ITER_PER_UPDATE = 10;
66 BEGIN_EVENT_TABLE(ImageFileCanvas, wxScrolledWindow)
67 EVT_MOUSE_EVENTS(ImageFileCanvas::OnMouseEvent)
68 EVT_CHAR(ImageFileCanvas::OnChar)
72 ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
73 : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v), m_xCursor(-1), m_yCursor(-1)
77 ImageFileCanvas::~ImageFileCanvas()
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);
191 ImageFileCanvas::GetBestSize() const
193 const int iMinX = 50;
194 const int iMinY = 20;
195 wxSize bestSize (iMinX,iMinY);
198 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
199 bestSize.Set (rIF.nx(), rIF.ny());
202 if (bestSize.x > 800)
204 if (bestSize.y > 800)
207 if (bestSize.y < iMinY)
209 if (bestSize.x < iMinX)
218 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
220 BEGIN_EVENT_TABLE(ImageFileView, wxView)
221 EVT_MENU(IFMENU_FILE_EXPORT, ImageFileView::OnExport)
222 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
223 EVT_MENU(IFMENU_EDIT_COPY, ImageFileView::OnEditCopy)
224 EVT_MENU(IFMENU_EDIT_CUT, ImageFileView::OnEditCut)
225 EVT_MENU(IFMENU_EDIT_PASTE, ImageFileView::OnEditPaste)
226 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
227 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
228 EVT_MENU(IFMENU_VIEW_SCALE_FULL, ImageFileView::OnScaleFull)
229 EVT_MENU(IFMENU_COMPARE_IMAGES, ImageFileView::OnCompare)
230 EVT_MENU(IFMENU_COMPARE_ROW, ImageFileView::OnCompareRow)
231 EVT_MENU(IFMENU_COMPARE_COL, ImageFileView::OnCompareCol)
232 EVT_MENU(IFMENU_FILTER_INVERTVALUES, ImageFileView::OnInvertValues)
233 EVT_MENU(IFMENU_FILTER_SQUARE, ImageFileView::OnSquare)
234 EVT_MENU(IFMENU_FILTER_SQRT, ImageFileView::OnSquareRoot)
235 EVT_MENU(IFMENU_FILTER_LOG, ImageFileView::OnLog)
236 EVT_MENU(IFMENU_FILTER_EXP, ImageFileView::OnExp)
237 EVT_MENU(IFMENU_FILTER_FOURIER, ImageFileView::OnFourier)
238 EVT_MENU(IFMENU_FILTER_INVERSE_FOURIER, ImageFileView::OnInverseFourier)
239 EVT_MENU(IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, ImageFileView::OnShuffleFourierToNaturalOrder)
240 EVT_MENU(IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, ImageFileView::OnShuffleNaturalToFourierOrder)
241 EVT_MENU(IFMENU_IMAGE_ADD, ImageFileView::OnAdd)
242 EVT_MENU(IFMENU_IMAGE_SUBTRACT, ImageFileView::OnSubtract)
243 EVT_MENU(IFMENU_IMAGE_MULTIPLY, ImageFileView::OnMultiply)
244 EVT_MENU(IFMENU_IMAGE_DIVIDE, ImageFileView::OnDivide)
245 EVT_MENU(IFMENU_IMAGE_SCALESIZE, ImageFileView::OnScaleSize)
247 EVT_MENU(IFMENU_IMAGE_CONVERT3D, ImageFileView::OnConvert3d)
250 EVT_MENU(IFMENU_FILTER_FFT, ImageFileView::OnFFT)
251 EVT_MENU(IFMENU_FILTER_IFFT, ImageFileView::OnIFFT)
252 EVT_MENU(IFMENU_FILTER_FFT_ROWS, ImageFileView::OnFFTRows)
253 EVT_MENU(IFMENU_FILTER_IFFT_ROWS, ImageFileView::OnIFFTRows)
254 EVT_MENU(IFMENU_FILTER_FFT_COLS, ImageFileView::OnFFTCols)
255 EVT_MENU(IFMENU_FILTER_IFFT_COLS, ImageFileView::OnIFFTCols)
257 EVT_MENU(IFMENU_FILTER_MAGNITUDE, ImageFileView::OnMagnitude)
258 EVT_MENU(IFMENU_FILTER_PHASE, ImageFileView::OnPhase)
259 EVT_MENU(IFMENU_FILTER_REAL, ImageFileView::OnReal)
260 EVT_MENU(IFMENU_FILTER_IMAGINARY, ImageFileView::OnImaginary)
261 EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)
262 EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol)
264 EVT_MENU(IFMENU_PLOT_FFT_ROW, ImageFileView::OnPlotFFTRow)
265 EVT_MENU(IFMENU_PLOT_FFT_COL, ImageFileView::OnPlotFFTCol)
267 EVT_MENU(IFMENU_PLOT_HISTOGRAM, ImageFileView::OnPlotHistogram)
270 ImageFileView::ImageFileView()
271 : wxView(), m_pBitmap(0), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0),
272 m_pFilterMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false),
273 m_iDefaultExportFormatID(ImageFile::EXPORT_FORMAT_PNG)
276 ImageFileView::~ImageFileView()
278 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
279 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
284 ImageFileView::OnProperties (wxCommandEvent& event)
286 const ImageFile& rIF = GetDocument()->getImageFile();
287 if (rIF.nx() == 0 || rIF.ny() == 0)
288 *theApp->getLog() << "Properties: empty imagefile\n";
290 const std::string rFilename = m_pFrame->GetTitle().c_str();
291 std::ostringstream os;
292 double min, max, mean, mode, median, stddev;
293 rIF.statistics (rIF.getArray(), min, max, mean, mode, median, stddev);
294 os << "Filename: " << rFilename << "\n";
295 os << "Size: (" << rIF.nx() << "," << rIF.ny() << ")\n";
301 os << "Minimum: "<<min<<"\nMaximum: "<<max<<"\nMean: "<<mean<<"\nMedian: "<<median<<"\nMode: "<<mode<<"\nStandard Deviation: "<<stddev << "\n";
302 if (rIF.isComplex()) {
303 rIF.statistics (rIF.getImaginaryArray(), min, max, mean, mode, median, stddev);
304 os << "Imaginary: min: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
306 if (rIF.nLabels() > 0) {
307 rIF.printLabelsBrief (os);
309 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
310 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
311 dialogMsg.ShowModal();
313 GetDocument()->Activate();
317 ImageFileView::OnScaleAuto (wxCommandEvent& event)
319 const ImageFile& rIF = GetDocument()->getImageFile();
320 double min, max, mean, mode, median, stddev;
321 rIF.statistics(min, max, mean, mode, median, stddev);
322 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
323 int iRetVal = dialogAutoScale.ShowModal();
324 if (iRetVal == wxID_OK) {
325 m_bMinSpecified = true;
326 m_bMaxSpecified = true;
328 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
331 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
332 OnUpdate(this, NULL);
333 GetDocument()->UpdateAllViews (this);
336 GetDocument()->Activate();
340 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
342 const ImageFile& rIF = GetDocument()->getImageFile();
344 if (! m_bMinSpecified && ! m_bMaxSpecified)
345 rIF.getMinMax (min, max);
352 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Image Minimum & Maximum", min, max);
353 int retVal = dialogMinMax.ShowModal();
354 if (retVal == wxID_OK) {
355 m_bMinSpecified = true;
356 m_bMaxSpecified = true;
357 m_dMinPixel = dialogMinMax.getMinimum();
358 m_dMaxPixel = dialogMinMax.getMaximum();
359 GetDocument()->UpdateAllViews (this);
361 GetDocument()->Activate();
365 ImageFileView::OnScaleFull (wxCommandEvent& event)
367 if (m_bMinSpecified || m_bMaxSpecified) {
368 m_bMinSpecified = false;
369 m_bMaxSpecified = false;
370 GetDocument()->UpdateAllViews (this);
372 GetDocument()->Activate();
376 ImageFileView::OnCompare (wxCommandEvent& event)
378 std::vector<ImageFileDocument*> vecIF;
379 theApp->getCompatibleImages (GetDocument(), vecIF);
381 if (vecIF.size() == 0) {
382 wxMessageBox("There are no compatible image files open for comparision", "No comparison images");
384 DialogGetComparisonImage dialogGetCompare(getFrameForChild(), "Get Comparison Image", vecIF, true);
386 if (dialogGetCompare.ShowModal() == wxID_OK) {
387 const ImageFile& rIF = GetDocument()->getImageFile();
388 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
389 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
390 std::ostringstream os;
391 double min, max, mean, mode, median, stddev;
392 rIF.statistics (min, max, mean, mode, median, stddev);
393 os << GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
394 rCompareIF.statistics (min, max, mean, mode, median, stddev);
395 os << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
397 rIF.comparativeStatistics (rCompareIF, d, r, e);
398 os << "Comparative Statistics: d=" << d << ", r=" << r << ", e=" << e << "\n";
399 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
400 if (dialogGetCompare.getMakeDifferenceImage()) {
401 ImageFile* pDifferenceImage = new ImageFile;
403 pDifferenceImage->setArraySize (rIF.nx(), rIF.ny());
404 if (! rIF.subtractImages (rCompareIF, *pDifferenceImage)) {
405 *theApp->getLog() << "Unable to subtract images\n";
406 delete pDifferenceImage;
409 ImageFileDocument* pDifferenceDoc = theApp->newImageDoc();
410 if (! pDifferenceDoc) {
411 sys_error (ERR_SEVERE, "Unable to create image file");
414 pDifferenceDoc->setImageFile (pDifferenceImage);
416 wxString s = GetFrame()->GetTitle() + ": ";
417 pDifferenceImage->labelsCopy (rIF, s.c_str());
418 s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
419 pDifferenceImage->labelsCopy (rCompareIF, s.c_str());
420 std::ostringstream osLabel;
421 osLabel << "Compare image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str()
422 << " and " << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": "
424 pDifferenceImage->labelAdd (os.str().c_str());
425 if (theApp->getAskDeleteNewDocs())
426 pDifferenceDoc->Modify (true);
427 pDifferenceDoc->UpdateAllViews(this);
428 pDifferenceDoc->getView()->setInitialClientSize();
429 pDifferenceDoc->Activate();
431 wxMessageBox(os.str().c_str(), "Image Comparison");
437 ImageFileView::OnInvertValues (wxCommandEvent& event)
439 ImageFile& rIF = GetDocument()->getImageFile();
440 rIF.invertPixelValues (rIF);
441 rIF.labelAdd ("Invert Pixel Values");
442 if (theApp->getAskDeleteNewDocs())
443 GetDocument()->Modify (true);
444 GetDocument()->UpdateAllViews (this);
445 GetDocument()->Activate();
449 ImageFileView::OnSquare (wxCommandEvent& event)
451 ImageFile& rIF = GetDocument()->getImageFile();
453 rIF.labelAdd ("Square Pixel Values");
454 if (theApp->getAskDeleteNewDocs())
455 GetDocument()->Modify (true);
456 GetDocument()->UpdateAllViews (this);
457 GetDocument()->Activate();
461 ImageFileView::OnSquareRoot (wxCommandEvent& event)
463 ImageFile& rIF = GetDocument()->getImageFile();
465 rIF.labelAdd ("Square-root Pixel Values");
466 if (theApp->getAskDeleteNewDocs())
467 GetDocument()->Modify (true);
468 GetDocument()->UpdateAllViews (this);
469 GetDocument()->Activate();
473 ImageFileView::OnLog (wxCommandEvent& event)
475 ImageFile& rIF = GetDocument()->getImageFile();
477 rIF.labelAdd ("Logrithm base-e Pixel Values");
478 if (theApp->getAskDeleteNewDocs())
479 GetDocument()->Modify (true);
480 GetDocument()->UpdateAllViews (this);
481 GetDocument()->Activate();
485 ImageFileView::OnExp (wxCommandEvent& event)
487 ImageFile& rIF = GetDocument()->getImageFile();
489 rIF.labelAdd ("Exponent base-e Pixel Values");
490 if (theApp->getAskDeleteNewDocs())
491 GetDocument()->Modify (true);
492 GetDocument()->UpdateAllViews (this);
493 GetDocument()->Activate();
497 ImageFileView::OnAdd (wxCommandEvent& event)
499 std::vector<ImageFileDocument*> vecIF;
500 theApp->getCompatibleImages (GetDocument(), vecIF);
502 if (vecIF.size() == 0) {
503 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
505 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Add", vecIF, false);
507 if (dialogGetCompare.ShowModal() == wxID_OK) {
508 ImageFile& rIF = GetDocument()->getImageFile();
509 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
510 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
511 ImageFileDocument* pNewDoc = theApp->newImageDoc();
513 sys_error (ERR_SEVERE, "Unable to create image file");
516 ImageFile& newImage = pNewDoc->getImageFile();
517 newImage.setArraySize (rIF.nx(), rIF.ny());
518 rIF.addImages (rRHSIF, newImage);
519 std::ostringstream os;
520 os << "Add image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
521 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
522 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
523 newImage.labelsCopy (rIF, s.c_str());
524 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
525 newImage.labelsCopy (rRHSIF, s.c_str());
526 newImage.labelAdd (os.str().c_str());
527 *theApp->getLog() << os.str().c_str() << "\n";
528 if (theApp->getAskDeleteNewDocs())
529 pNewDoc->Modify (true);
530 pNewDoc->UpdateAllViews (this);
531 pNewDoc->getView()->setInitialClientSize();
538 ImageFileView::OnSubtract (wxCommandEvent& event)
540 std::vector<ImageFileDocument*> vecIF;
541 theApp->getCompatibleImages (GetDocument(), vecIF);
543 if (vecIF.size() == 0) {
544 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
546 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Subtract", vecIF, false);
548 if (dialogGetCompare.ShowModal() == wxID_OK) {
549 ImageFile& rIF = GetDocument()->getImageFile();
550 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
551 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
552 ImageFileDocument* pNewDoc = theApp->newImageDoc();
554 sys_error (ERR_SEVERE, "Unable to create image file");
557 ImageFile& newImage = pNewDoc->getImageFile();
558 newImage.setArraySize (rIF.nx(), rIF.ny());
559 rIF.subtractImages (rRHSIF, newImage);
560 std::ostringstream os;
561 os << "Subtract image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
562 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
563 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
564 newImage.labelsCopy (rIF, s.c_str());
565 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
566 newImage.labelsCopy (rRHSIF, s.c_str());
567 newImage.labelAdd (os.str().c_str());
568 *theApp->getLog() << os.str().c_str() << "\n";
569 if (theApp->getAskDeleteNewDocs())
570 pNewDoc->Modify (true);
571 pNewDoc->UpdateAllViews (this);
572 pNewDoc->getView()->setInitialClientSize();
579 ImageFileView::OnMultiply (wxCommandEvent& event)
581 std::vector<ImageFileDocument*> vecIF;
582 theApp->getCompatibleImages (GetDocument(), vecIF);
584 if (vecIF.size() == 0) {
585 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
587 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Multiply", vecIF, false);
589 if (dialogGetCompare.ShowModal() == wxID_OK) {
590 ImageFile& rIF = GetDocument()->getImageFile();
591 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
592 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
593 ImageFileDocument* pNewDoc = theApp->newImageDoc();
595 sys_error (ERR_SEVERE, "Unable to create image file");
598 ImageFile& newImage = pNewDoc->getImageFile();
599 newImage.setArraySize (rIF.nx(), rIF.ny());
600 rIF.multiplyImages (rRHSIF, newImage);
601 std::ostringstream os;
602 os << "Multiply image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
603 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
604 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
605 newImage.labelsCopy (rIF, s.c_str());
606 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
607 newImage.labelsCopy (rRHSIF, s.c_str());
608 newImage.labelAdd (os.str().c_str());
609 *theApp->getLog() << os.str().c_str() << "\n";
610 if (theApp->getAskDeleteNewDocs())
611 pNewDoc->Modify (true);
612 pNewDoc->UpdateAllViews (this);
613 pNewDoc->getView()->setInitialClientSize();
620 ImageFileView::OnDivide (wxCommandEvent& event)
622 std::vector<ImageFileDocument*> vecIF;
623 theApp->getCompatibleImages (GetDocument(), vecIF);
625 if (vecIF.size() == 0) {
626 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
628 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Divide", vecIF, false);
630 if (dialogGetCompare.ShowModal() == wxID_OK) {
631 ImageFile& rIF = GetDocument()->getImageFile();
632 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
633 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
634 ImageFileDocument* pNewDoc = theApp->newImageDoc();
636 sys_error (ERR_SEVERE, "Unable to create image file");
639 ImageFile& newImage = pNewDoc->getImageFile();
640 newImage.setArraySize (rIF.nx(), rIF.ny());
641 rIF.divideImages (rRHSIF, newImage);
642 std::ostringstream os;
643 os << "Divide image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " by "
644 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
645 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
646 newImage.labelsCopy (rIF, s.c_str());
647 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
648 newImage.labelsCopy (rRHSIF, s.c_str());
649 newImage.labelAdd (os.str().c_str());
650 *theApp->getLog() << os.str().c_str() << "\n";
651 if (theApp->getAskDeleteNewDocs())
652 pNewDoc->Modify (true);
653 pNewDoc->UpdateAllViews (this);
654 pNewDoc->getView()->setInitialClientSize();
663 ImageFileView::OnFFT (wxCommandEvent& event)
665 ImageFile& rIF = GetDocument()->getImageFile();
667 rIF.labelAdd ("FFT Image");
668 m_bMinSpecified = false;
669 m_bMaxSpecified = false;
670 if (theApp->getAskDeleteNewDocs())
671 GetDocument()->Modify (true);
672 GetDocument()->UpdateAllViews (this);
673 GetDocument()->Activate();
677 ImageFileView::OnIFFT (wxCommandEvent& event)
679 ImageFile& rIF = GetDocument()->getImageFile();
681 rIF.labelAdd ("IFFT Image");
682 m_bMinSpecified = false;
683 m_bMaxSpecified = false;
684 if (theApp->getAskDeleteNewDocs())
685 GetDocument()->Modify (true);
686 GetDocument()->UpdateAllViews (this);
687 GetDocument()->Activate();
691 ImageFileView::OnFFTRows (wxCommandEvent& event)
693 ImageFile& rIF = GetDocument()->getImageFile();
695 rIF.labelAdd ("FFT Rows");
696 m_bMinSpecified = false;
697 m_bMaxSpecified = false;
698 if (theApp->getAskDeleteNewDocs())
699 GetDocument()->Modify (true);
700 GetDocument()->UpdateAllViews (this);
701 GetDocument()->Activate();
705 ImageFileView::OnIFFTRows (wxCommandEvent& event)
707 ImageFile& rIF = GetDocument()->getImageFile();
709 rIF.labelAdd ("IFFT Rows");
710 m_bMinSpecified = false;
711 m_bMaxSpecified = false;
712 if (theApp->getAskDeleteNewDocs())
713 GetDocument()->Modify (true);
714 GetDocument()->UpdateAllViews (this);
715 GetDocument()->Activate();
719 ImageFileView::OnFFTCols (wxCommandEvent& event)
721 ImageFile& rIF = GetDocument()->getImageFile();
723 rIF.labelAdd ("FFT Columns");
724 m_bMinSpecified = false;
725 m_bMaxSpecified = false;
726 if (theApp->getAskDeleteNewDocs())
727 GetDocument()->Modify (true);
728 GetDocument()->UpdateAllViews (this);
729 GetDocument()->Activate();
733 ImageFileView::OnIFFTCols (wxCommandEvent& event)
735 ImageFile& rIF = GetDocument()->getImageFile();
737 rIF.labelAdd ("IFFT Columns");
738 m_bMinSpecified = false;
739 m_bMaxSpecified = false;
740 if (theApp->getAskDeleteNewDocs())
741 GetDocument()->Modify (true);
742 GetDocument()->UpdateAllViews (this);
743 GetDocument()->Activate();
748 ImageFileView::OnFourier (wxCommandEvent& event)
750 ImageFile& rIF = GetDocument()->getImageFile();
751 wxProgressDialog dlgProgress (wxString("Fourier"), wxString("Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
753 rIF.labelAdd ("Fourier Image");
754 m_bMinSpecified = false;
755 m_bMaxSpecified = false;
756 if (theApp->getAskDeleteNewDocs())
757 GetDocument()->Modify (true);
758 GetDocument()->UpdateAllViews (this);
759 GetDocument()->Activate();
763 ImageFileView::OnInverseFourier (wxCommandEvent& event)
765 ImageFile& rIF = GetDocument()->getImageFile();
766 wxProgressDialog dlgProgress (wxString("Inverse Fourier"), wxString("Inverse Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
767 rIF.inverseFourier (rIF);
768 rIF.labelAdd ("Inverse Fourier Image");
769 m_bMinSpecified = false;
770 m_bMaxSpecified = false;
771 if (theApp->getAskDeleteNewDocs())
772 GetDocument()->Modify (true);
773 GetDocument()->UpdateAllViews (this);
774 GetDocument()->Activate();
778 ImageFileView::OnShuffleNaturalToFourierOrder (wxCommandEvent& event)
780 ImageFile& rIF = GetDocument()->getImageFile();
781 Fourier::shuffleNaturalToFourierOrder (rIF);
782 rIF.labelAdd ("Shuffle Natural To Fourier Order");
783 m_bMinSpecified = false;
784 m_bMaxSpecified = false;
785 if (theApp->getAskDeleteNewDocs())
786 GetDocument()->Modify (true);
787 GetDocument()->UpdateAllViews (this);
788 GetDocument()->Activate();
792 ImageFileView::OnShuffleFourierToNaturalOrder (wxCommandEvent& event)
794 ImageFile& rIF = GetDocument()->getImageFile();
795 Fourier::shuffleFourierToNaturalOrder (rIF);
796 rIF.labelAdd ("Shuffle Fourier To Natural Order");
797 m_bMinSpecified = false;
798 m_bMaxSpecified = false;
799 if (theApp->getAskDeleteNewDocs())
800 GetDocument()->Modify (true);
801 GetDocument()->UpdateAllViews (this);
802 GetDocument()->Activate();
806 ImageFileView::OnMagnitude (wxCommandEvent& event)
808 ImageFile& rIF = GetDocument()->getImageFile();
810 rIF.labelAdd ("Magnitude");
811 m_bMinSpecified = false;
812 m_bMaxSpecified = false;
813 if (theApp->getAskDeleteNewDocs())
814 GetDocument()->Modify (true);
815 GetDocument()->UpdateAllViews (this);
816 GetDocument()->Activate();
820 ImageFileView::OnPhase (wxCommandEvent& event)
822 ImageFile& rIF = GetDocument()->getImageFile();
823 if (rIF.isComplex()) {
825 rIF.labelAdd ("Phase of complex-image");
826 m_bMinSpecified = false;
827 m_bMaxSpecified = false;
828 if (theApp->getAskDeleteNewDocs())
829 GetDocument()->Modify (true);
830 GetDocument()->UpdateAllViews (this);
832 GetDocument()->Activate();
836 ImageFileView::OnReal (wxCommandEvent& event)
838 ImageFile& rIF = GetDocument()->getImageFile();
839 if (rIF.isComplex()) {
841 rIF.labelAdd ("Real component of complex-image");
842 m_bMinSpecified = false;
843 m_bMaxSpecified = false;
844 if (theApp->getAskDeleteNewDocs())
845 GetDocument()->Modify (true);
846 GetDocument()->UpdateAllViews (this);
848 GetDocument()->Activate();
852 ImageFileView::OnImaginary (wxCommandEvent& event)
854 ImageFile& rIF = GetDocument()->getImageFile();
855 if (rIF.isComplex()) {
857 rIF.labelAdd ("Imaginary component of complex-image");
858 m_bMinSpecified = false;
859 m_bMaxSpecified = false;
860 if (theApp->getAskDeleteNewDocs())
861 GetDocument()->Modify (true);
862 GetDocument()->UpdateAllViews (this);
864 GetDocument()->Activate();
869 ImageFileView::CreateCanvas (wxFrame* parent)
871 ImageFileCanvas* pCanvas = new ImageFileCanvas (this, parent, wxPoint(-1,-1),
873 pCanvas->SetBackgroundColour(*wxWHITE);
884 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
887 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
889 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
891 theApp->setIconForFrame (subframe);
893 m_pFileMenu = new wxMenu;
894 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
895 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
896 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
897 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
898 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
899 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
900 m_pFileMenu->Append(wxID_REVERT, "Re&vert");
902 m_pFileMenu->AppendSeparator();
903 m_pFileMenu->Append(IFMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
904 m_pFileMenu->Append(IFMENU_FILE_EXPORT, "Expor&t...");
906 m_pFileMenu->AppendSeparator();
907 m_pFileMenu->Append(wxID_PRINT, "&Print...");
908 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
909 m_pFileMenu->Append(wxID_PREVIEW, "Print Preview");
910 m_pFileMenu->AppendSeparator();
911 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
912 m_pFileMenu->AppendSeparator();
913 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
914 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
915 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
916 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
918 wxMenu* edit_menu = new wxMenu;
919 edit_menu->Append(IFMENU_EDIT_COPY, "Copy\tCtrl-C");
920 edit_menu->Append(IFMENU_EDIT_CUT, "Cut\tCtrl-X");
921 edit_menu->Append(IFMENU_EDIT_PASTE, "Paste\tCtrl-V");
923 wxMenu *view_menu = new wxMenu;
924 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale S&et...\tCtrl-E");
925 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
926 view_menu->Append(IFMENU_VIEW_SCALE_FULL, "Display F&ull Scale\tCtrl-U");
928 m_pFilterMenu = new wxMenu;
929 m_pFilterMenu->Append (IFMENU_FILTER_INVERTVALUES, "In&vert Values");
930 m_pFilterMenu->Append (IFMENU_FILTER_SQUARE, "&Square");
931 m_pFilterMenu->Append (IFMENU_FILTER_SQRT, "Square &Root");
932 m_pFilterMenu->Append (IFMENU_FILTER_LOG, "&Log");
933 m_pFilterMenu->Append (IFMENU_FILTER_EXP, "E&xp");
934 m_pFilterMenu->AppendSeparator();
936 m_pFilterMenu->Append (IFMENU_FILTER_FFT, "2-D &FFT\tCtrl-2");
937 m_pFilterMenu->Append (IFMENU_FILTER_IFFT, "2-D &IFFT\tAlt-2");
938 m_pFilterMenu->Append (IFMENU_FILTER_FFT_ROWS, "FFT Rows");
939 m_pFilterMenu->Append (IFMENU_FILTER_IFFT_ROWS, "IFFT Rows");
940 m_pFilterMenu->Append (IFMENU_FILTER_FFT_COLS, "FFT Columns");
941 m_pFilterMenu->Append (IFMENU_FILTER_IFFT_COLS, "IFFT Columns");
942 m_pFilterMenu->Append (IFMENU_FILTER_FOURIER, "2-D F&ourier");
943 m_pFilterMenu->Append (IFMENU_FILTER_INVERSE_FOURIER, "2-D Inverse Fo&urier");
945 m_pFilterMenu->Append (IFMENU_FILTER_FOURIER, "&Fourier");
946 m_pFilterMenu->Append (IFMENU_FILTER_INVERSE_FOURIER, "&Inverse Fourier");
948 m_pFilterMenu->Append (IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, "Shuffl&e Fourier to Natural Order");
949 m_pFilterMenu->Append (IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, "Shuffle &Natural to Fourier Order");
950 m_pFilterMenu->AppendSeparator();
951 m_pFilterMenu->Append (IFMENU_FILTER_MAGNITUDE, "&Magnitude");
952 m_pFilterMenu->Append (IFMENU_FILTER_PHASE, "&Phase");
953 m_pFilterMenu->Append (IFMENU_FILTER_REAL, "Re&al");
954 m_pFilterMenu->Append (IFMENU_FILTER_IMAGINARY, "Ima&ginary");
956 wxMenu* image_menu = new wxMenu;
957 image_menu->Append (IFMENU_IMAGE_ADD, "&Add...");
958 image_menu->Append (IFMENU_IMAGE_SUBTRACT, "&Subtract...");
959 image_menu->Append (IFMENU_IMAGE_MULTIPLY, "&Multiply...");
960 image_menu->Append (IFMENU_IMAGE_DIVIDE, "&Divide...");
961 image_menu->AppendSeparator();
962 image_menu->Append (IFMENU_IMAGE_SCALESIZE, "S&cale Size...");
964 image_menu->Append (IFMENU_IMAGE_CONVERT3D, "Convert &3-D\tCtrl-3");
967 m_pMenuAnalyze = new wxMenu;
968 m_pMenuAnalyze->Append (IFMENU_PLOT_ROW, "Plot &Row");
969 m_pMenuAnalyze->Append (IFMENU_PLOT_COL, "Plot &Column");
970 m_pMenuAnalyze->Append (IFMENU_PLOT_HISTOGRAM, "Plot &Histogram");
971 m_pMenuAnalyze->AppendSeparator();
972 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_ROW, "P&lot FFT Row");
973 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_COL, "Plo&t FFT Column");
974 m_pMenuAnalyze->AppendSeparator();
975 m_pMenuAnalyze->Append (IFMENU_COMPARE_IMAGES, "Compare &Images...");
976 m_pMenuAnalyze->Append (IFMENU_COMPARE_ROW, "Compare Ro&w");
977 m_pMenuAnalyze->Append (IFMENU_COMPARE_COL, "Compare Colu&mn");
978 m_pMenuAnalyze->Enable (IFMENU_PLOT_ROW, false);
979 m_pMenuAnalyze->Enable (IFMENU_PLOT_COL, false);
980 m_pMenuAnalyze->Enable (IFMENU_COMPARE_ROW, false);
981 m_pMenuAnalyze->Enable (IFMENU_COMPARE_COL, false);
982 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_ROW, false);
983 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_COL, false);
985 wxMenu *help_menu = new wxMenu;
986 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
987 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
988 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
989 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
991 wxMenuBar *menu_bar = new wxMenuBar;
993 menu_bar->Append(m_pFileMenu, "&File");
994 menu_bar->Append(edit_menu, "&Edit");
995 menu_bar->Append(view_menu, "&View");
996 menu_bar->Append(image_menu, "&Image");
997 menu_bar->Append(m_pFilterMenu, "Fi<er");
998 menu_bar->Append(m_pMenuAnalyze, "&Analyze");
999 menu_bar->Append(help_menu, "&Help");
1001 subframe->SetMenuBar(menu_bar);
1003 subframe->Centre(wxBOTH);
1005 wxAcceleratorEntry accelEntries[10];
1006 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('A'), IFMENU_VIEW_SCALE_AUTO);
1007 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('U'), IFMENU_VIEW_SCALE_FULL);
1008 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('E'), IFMENU_VIEW_SCALE_MINMAX);
1009 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), IFMENU_FILE_PROPERTIES);
1010 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('C'), IFMENU_EDIT_COPY);
1011 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('X'), IFMENU_EDIT_CUT);
1012 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('V'), IFMENU_EDIT_PASTE);
1015 accelEntries[iEntry++].Set (wxACCEL_CTRL, static_cast<int>('2'), IFMENU_FILTER_FFT);
1016 accelEntries[iEntry++].Set (wxACCEL_ALT, static_cast<int>('2'), IFMENU_FILTER_IFFT);
1019 accelEntries[iEntry++].Set (wxACCEL_CTRL, static_cast<int>('3'), IFMENU_IMAGE_CONVERT3D);
1022 wxAcceleratorTable accelTable (iEntry, accelEntries);
1023 subframe->SetAcceleratorTable (accelTable);
1030 ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
1032 m_bMinSpecified = false;
1033 m_bMaxSpecified = false;
1034 m_dAutoScaleFactor = 1.;
1036 m_pFrame = CreateChildFrame(doc, this);
1037 SetFrame (m_pFrame);
1038 m_pCanvas = CreateCanvas (m_pFrame);
1039 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
1040 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
1041 m_pFrame->SetTitle("ImageFileView");
1043 m_pFrame->Show(true);
1050 ImageFileView::setInitialClientSize ()
1052 if (m_pFrame && m_pCanvas) {
1053 wxSize bestSize = m_pCanvas->GetBestSize();
1055 m_pFrame->SetClientSize (bestSize);
1056 m_pFrame->Show (true);
1057 m_pFrame->SetFocus();
1062 ImageFileView::OnDraw (wxDC* dc)
1064 if (m_pBitmap && m_pBitmap->Ok()) {
1065 *theApp->getLog() << "Drawing bitmap";
1066 dc->DrawBitmap(*m_pBitmap, 0, 0, false);
1069 int xCursor, yCursor;
1070 if (m_pCanvas->GetCurrentCursor (xCursor, yCursor))
1071 m_pCanvas->DrawRubberBandCursor (*dc, xCursor, yCursor);
1076 ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
1078 const ImageFile& rIF = GetDocument()->getImageFile();
1079 if (m_pFilterMenu && rIF.isComplex()) {
1080 m_pFilterMenu->Enable(IFMENU_FILTER_REAL, true);
1081 m_pFilterMenu->Enable(IFMENU_FILTER_IMAGINARY, true);
1082 m_pFilterMenu->Enable(IFMENU_FILTER_PHASE, true);
1084 m_pFilterMenu->Enable(IFMENU_FILTER_REAL, false);
1085 m_pFilterMenu->Enable(IFMENU_FILTER_IMAGINARY, false);
1086 m_pFilterMenu->Enable(IFMENU_FILTER_PHASE, false);
1088 ImageFileArrayConst v = rIF.getArray();
1091 if (v != NULL && nx != 0 && ny != 0) {
1092 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1094 rIF.getMinMax (min, max);
1095 if (! m_bMinSpecified)
1097 if (! m_bMaxSpecified)
1100 double scaleWidth = m_dMaxPixel - m_dMinPixel;
1102 unsigned char* imageData = new unsigned char [nx * ny * 3];
1104 sys_error (ERR_SEVERE, "Unable to allocate memory for Image display");
1107 for (int ix = 0; ix < nx; ix++) {
1108 for (int iy = 0; iy < ny; iy++) {
1109 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
1110 int intensity = static_cast<int>(scaleValue + 0.5);
1111 intensity = clamp (intensity, 0, 255);
1112 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
1113 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
1116 wxImage image (nx, ny, imageData, true);
1121 *theApp->getLog() << "Making new bitmap bitmap";
1122 m_pBitmap = new wxBitmap (image);
1124 m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20);
1125 m_pCanvas->SetBackgroundColour(*wxWHITE);
1129 m_pCanvas->Refresh();
1133 ImageFileView::OnClose (bool deleteWindow)
1135 if (! GetDocument() || ! GetDocument()->Close())
1140 m_pCanvas->setView(NULL);
1143 wxString s(theApp->GetAppName());
1145 m_pFrame->SetTitle(s);
1152 if (GetDocument() && GetDocument()->getBadFileOpen())
1153 ::wxYield(); // wxWindows bug workaround
1160 ImageFileView::OnEditCopy (wxCommandEvent& event)
1162 wxBitmapDataObject *pBitmapObject = new wxBitmapDataObject;
1165 pBitmapObject->SetBitmap (*m_pBitmap);
1167 if (wxTheClipboard->Open()) {
1168 wxTheClipboard->SetData (pBitmapObject);
1169 wxTheClipboard->Close();
1174 ImageFileView::OnEditCut (wxCommandEvent& event)
1177 ImageFile& rIF = GetDocument()->getImageFile();
1180 ImageFile* pIF = new ImageFile (nx, ny);
1181 pIF->arrayDataClear();
1182 GetDocument()->setImageFile (pIF); // deletes old IF
1183 OnUpdate(this, NULL);
1184 GetDocument()->UpdateAllViews();
1185 if (theApp->getAskDeleteNewDocs())
1186 GetDocument()->Modify (true);
1190 ImageFileView::OnEditPaste (wxCommandEvent& event)
1192 ImageFile& rIF = GetDocument()->getImageFile();
1194 if (wxTheClipboard->Open()) {
1196 if (wxTheClipboard->IsSupported (wxDF_BITMAP)) {
1197 wxBitmapDataObject bitmapObject;
1198 wxTheClipboard->GetData (bitmapObject);
1199 bitmap = bitmapObject.GetBitmap ();
1201 wxTheClipboard->Close();
1205 bool bMonochrome = false;
1207 if (bitmap.Ok() == true && bitmap.GetWidth() == nx && bitmap.GetHeight() == ny) {
1208 wxImage image (bitmap.ConvertToImage());
1209 double dScale3 = 3 * 255;
1210 unsigned char* pixels = image.GetData();
1211 ImageFileArray v = rIF.getArray();
1212 for (unsigned int ix = 0; ix < rIF.nx(); ix++) {
1213 for (unsigned int iy = 0; iy < rIF.ny(); iy++) {
1214 unsigned int iBase = 3 * (iy * nx + ix);
1215 if (ix == 0 && iy == 0 && (pixels[iBase] == pixels[iBase+1] && pixels[iBase+1] == pixels[iBase+2]))
1218 v[ix][ny - 1 - iy] = (pixels[iBase]+pixels[iBase+1]+pixels[iBase+2]) / dScale3;
1220 double dR = pixels[iBase] / 255.;
1221 double dG = pixels[iBase+1] / 255.;
1222 double dB = pixels[iBase+2] / 255.;
1223 v[ix][ny - 1 - iy] = ImageFile::colorToGrayscale (dR, dG, dB);
1227 OnUpdate(this, NULL);
1228 GetDocument()->UpdateAllViews();
1229 if (theApp->getAskDeleteNewDocs())
1230 GetDocument()->Modify(true);
1236 ImageFileView::OnExport (wxCommandEvent& event)
1238 ImageFile& rIF = GetDocument()->getImageFile();
1239 ImageFileArrayConst v = rIF.getArray();
1242 if (v != NULL && nx != 0 && ny != 0) {
1243 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1245 rIF.getMinMax (min, max);
1246 if (! m_bMinSpecified)
1248 if (! m_bMaxSpecified)
1252 DialogExportParameters dialogExport (getFrameForChild(), m_iDefaultExportFormatID);
1253 if (dialogExport.ShowModal() == wxID_OK) {
1254 wxString strFormatName (dialogExport.getFormatName ());
1255 m_iDefaultExportFormatID = ImageFile::convertExportFormatNameToID (strFormatName.c_str());
1258 wxString strWildcard;
1259 if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PGM || m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PGMASCII) {
1261 strWildcard = "PGM Files (*.pgm)|*.pgm";
1264 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PNG || m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PNG16) {
1266 strWildcard = "PNG Files (*.png)|*.png";
1269 #ifdef HAVE_CTN_DICOM
1270 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_DICOM) {
1272 strWildcard = "DICOM Files (*.*)|*.*";
1275 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_TEXT) {
1277 strWildcard = "Text (*.txt)|*.txt";
1281 strWildcard = "Miscellaneous (*.*)|*.*";
1284 const wxString& strFilename = wxFileSelector (wxString("Export Filename"), wxString(""),
1285 wxString(""), strExt, strWildcard, wxOVERWRITE_PROMPT | wxHIDE_READONLY | wxSAVE);
1287 rIF.exportImage (strFormatName.c_str(), strFilename.c_str(), 1, 1, m_dMinPixel, m_dMaxPixel);
1288 *theApp->getLog() << "Exported file " << strFilename << "\n";
1295 ImageFileView::OnScaleSize (wxCommandEvent& event)
1297 ImageFile& rIF = GetDocument()->getImageFile();
1298 unsigned int iOldNX = rIF.nx();
1299 unsigned int iOldNY = rIF.ny();
1301 DialogGetXYSize dialogGetXYSize (getFrameForChild(), "Set New X & Y Dimensions", iOldNX, iOldNY);
1302 if (dialogGetXYSize.ShowModal() == wxID_OK) {
1303 unsigned int iNewNX = dialogGetXYSize.getXSize();
1304 unsigned int iNewNY = dialogGetXYSize.getYSize();
1305 std::ostringstream os;
1306 os << "Scale Size from (" << iOldNX << "," << iOldNY << ") to (" << iNewNX << "," << iNewNY << ")";
1307 ImageFileDocument* pScaledDoc = theApp->newImageDoc();
1309 sys_error (ERR_SEVERE, "Unable to create image file");
1312 ImageFile& rScaledIF = pScaledDoc->getImageFile();
1313 rScaledIF.setArraySize (iNewNX, iNewNY);
1314 rScaledIF.labelsCopy (rIF);
1315 rScaledIF.labelAdd (os.str().c_str());
1316 rIF.scaleImage (rScaledIF);
1317 *theApp->getLog() << os.str().c_str() << "\n";
1318 if (theApp->getAskDeleteNewDocs())
1319 pScaledDoc->Modify (true);
1320 pScaledDoc->UpdateAllViews (this);
1321 pScaledDoc->getView()->setInitialClientSize();
1322 pScaledDoc->Activate();
1328 ImageFileView::OnConvert3d (wxCommandEvent& event)
1330 ImageFile& rIF = GetDocument()->getImageFile();
1331 Graph3dFileDocument* pGraph3d = theApp->newGraph3dDoc();
1332 pGraph3d->getView()->getFrame()->Show (false);
1333 pGraph3d->setBadFileOpen();
1334 pGraph3d->createFromImageFile (rIF);
1335 pGraph3d->UpdateAllViews();
1336 pGraph3d->getView()->getFrame()->Show (true);
1337 pGraph3d->getView()->Activate(true);
1339 pGraph3d->getView()->getCanvas()->SetFocus();
1344 ImageFileView::OnPlotRow (wxCommandEvent& event)
1346 int xCursor, yCursor;
1347 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1348 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1352 const ImageFile& rIF = GetDocument()->getImageFile();
1353 ImageFileArrayConst v = rIF.getArray();
1354 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1358 if (v != NULL && yCursor < ny) {
1359 double* pX = new double [nx];
1360 double* pYReal = new double [nx];
1361 double *pYImag = NULL;
1362 double *pYMag = NULL;
1363 if (rIF.isComplex()) {
1364 pYImag = new double [nx];
1365 pYMag = new double [nx];
1367 for (int i = 0; i < nx; i++) {
1369 pYReal[i] = v[i][yCursor];
1370 if (rIF.isComplex()) {
1371 pYImag[i] = vImag[i][yCursor];
1372 pYMag[i] = ::sqrt (v[i][yCursor] * v[i][yCursor] + vImag[i][yCursor] * vImag[i][yCursor]);
1375 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1377 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1379 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1380 std::ostringstream os;
1381 os << "Row " << yCursor;
1382 std::string title("title ");
1384 rPlotFile.addEzsetCommand (title.c_str());
1385 rPlotFile.addEzsetCommand ("xlabel Column");
1386 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1387 rPlotFile.addEzsetCommand ("lxfrac 0");
1388 rPlotFile.addEzsetCommand ("box");
1389 rPlotFile.addEzsetCommand ("grid");
1390 rPlotFile.addEzsetCommand ("curve 1");
1391 rPlotFile.addEzsetCommand ("color 1");
1392 if (rIF.isComplex()) {
1393 rPlotFile.addEzsetCommand ("dash 1");
1394 rPlotFile.addEzsetCommand ("curve 2");
1395 rPlotFile.addEzsetCommand ("color 4");
1396 rPlotFile.addEzsetCommand ("dash 3");
1397 rPlotFile.addEzsetCommand ("curve 3");
1398 rPlotFile.addEzsetCommand ("color 0");
1399 rPlotFile.addEzsetCommand ("solid");
1400 rPlotFile.setCurveSize (4, nx);
1402 rPlotFile.setCurveSize (2, nx);
1403 rPlotFile.addColumn (0, pX);
1404 rPlotFile.addColumn (1, pYReal);
1405 if (rIF.isComplex()) {
1406 rPlotFile.addColumn (2, pYImag);
1407 rPlotFile.addColumn (3, pYMag);
1409 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1410 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1411 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1412 *theApp->getLog() << os.str().c_str() << "\n";
1413 rPlotFile.addDescription (os.str().c_str());
1417 if (rIF.isComplex()) {
1421 if (theApp->getAskDeleteNewDocs())
1422 pPlotDoc->Modify (true);
1423 pPlotDoc->getView()->getFrame()->Show(true);
1424 pPlotDoc->UpdateAllViews ();
1425 pPlotDoc->Activate();
1430 ImageFileView::OnPlotCol (wxCommandEvent& event)
1432 int xCursor, yCursor;
1433 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1434 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1438 const ImageFile& rIF = GetDocument()->getImageFile();
1439 ImageFileArrayConst v = rIF.getArray();
1440 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1444 if (v != NULL && xCursor < nx) {
1445 double* pX = new double [ny];
1446 double* pYReal = new double [ny];
1447 double* pYImag = NULL;
1448 double* pYMag = NULL;
1449 if (rIF.isComplex()) {
1450 pYImag = new double [ny];
1451 pYMag = new double [ny];
1453 for (int i = 0; i < ny; i++) {
1455 pYReal[i] = v[xCursor][i];
1456 if (rIF.isComplex()) {
1457 pYImag[i] = vImag[xCursor][i];
1458 pYMag[i] = ::sqrt (v[xCursor][i] * v[xCursor][i] + vImag[xCursor][i] * vImag[xCursor][i]);
1461 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1463 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1465 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1466 std::ostringstream os;
1467 os << "Column " << xCursor;
1468 std::string title("title ");
1470 rPlotFile.addEzsetCommand (title.c_str());
1471 rPlotFile.addEzsetCommand ("xlabel Row");
1472 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1473 rPlotFile.addEzsetCommand ("lxfrac 0");
1474 rPlotFile.addEzsetCommand ("box");
1475 rPlotFile.addEzsetCommand ("grid");
1476 rPlotFile.addEzsetCommand ("curve 1");
1477 rPlotFile.addEzsetCommand ("color 1");
1478 if (rIF.isComplex()) {
1479 rPlotFile.addEzsetCommand ("dash 1");
1480 rPlotFile.addEzsetCommand ("curve 2");
1481 rPlotFile.addEzsetCommand ("color 4");
1482 rPlotFile.addEzsetCommand ("dash 3");
1483 rPlotFile.addEzsetCommand ("curve 3");
1484 rPlotFile.addEzsetCommand ("color 0");
1485 rPlotFile.addEzsetCommand ("solid");
1486 rPlotFile.setCurveSize (4, ny);
1488 rPlotFile.setCurveSize (2, ny);
1489 rPlotFile.addColumn (0, pX);
1490 rPlotFile.addColumn (1, pYReal);
1491 if (rIF.isComplex()) {
1492 rPlotFile.addColumn (2, pYImag);
1493 rPlotFile.addColumn (3, pYMag);
1495 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1496 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1497 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1498 *theApp->getLog() << os.str().c_str() << "\n";
1499 rPlotFile.addDescription (os.str().c_str());
1503 if (rIF.isComplex()) {
1507 if (theApp->getAskDeleteNewDocs())
1508 pPlotDoc->Modify (true);
1509 pPlotDoc->getView()->getFrame()->Show(true);
1510 pPlotDoc->UpdateAllViews ();
1511 pPlotDoc->Activate();
1517 ImageFileView::OnPlotFFTRow (wxCommandEvent& event)
1519 int xCursor, yCursor;
1520 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1521 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1525 const ImageFile& rIF = GetDocument()->getImageFile();
1526 ImageFileArrayConst v = rIF.getArray();
1527 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1531 if (v != NULL && yCursor < ny) {
1532 fftw_complex* pcIn = new fftw_complex [nx];
1535 for (i = 0; i < nx; i++) {
1536 pcIn[i].re = v[i][yCursor];
1537 if (rIF.isComplex())
1538 pcIn[i].im = vImag[i][yCursor];
1543 fftw_plan plan = fftw_create_plan (nx, FFTW_FORWARD, FFTW_IN_PLACE | FFTW_ESTIMATE | FFTW_USE_WISDOM);
1544 fftw_one (plan, pcIn, NULL);
1545 fftw_destroy_plan (plan);
1547 double* pX = new double [nx];
1548 double* pYReal = new double [nx];
1549 double* pYImag = new double [nx];
1550 double* pYMag = new double [nx];
1551 for (i = 0; i < nx; i++) {
1553 pYReal[i] = pcIn[i].re / nx;
1554 pYImag[i] = pcIn[i].im / nx;
1555 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1557 Fourier::shuffleFourierToNaturalOrder (pYReal, nx);
1558 Fourier::shuffleFourierToNaturalOrder (pYImag, nx);
1559 Fourier::shuffleFourierToNaturalOrder (pYMag, nx);
1561 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1563 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1565 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1566 std::ostringstream os;
1567 os << "Row " << yCursor;
1568 std::string title("title ");
1570 rPlotFile.addEzsetCommand (title.c_str());
1571 rPlotFile.addEzsetCommand ("xlabel Column");
1572 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1573 rPlotFile.addEzsetCommand ("lxfrac 0");
1574 rPlotFile.addEzsetCommand ("curve 1");
1575 rPlotFile.addEzsetCommand ("color 1");
1576 rPlotFile.addEzsetCommand ("dash 1");
1577 rPlotFile.addEzsetCommand ("curve 2");
1578 rPlotFile.addEzsetCommand ("color 4");
1579 rPlotFile.addEzsetCommand ("dash 3");
1580 rPlotFile.addEzsetCommand ("curve 3");
1581 rPlotFile.addEzsetCommand ("color 0");
1582 rPlotFile.addEzsetCommand ("solid");
1583 rPlotFile.addEzsetCommand ("box");
1584 rPlotFile.addEzsetCommand ("grid");
1585 rPlotFile.setCurveSize (4, nx);
1586 rPlotFile.addColumn (0, pX);
1587 rPlotFile.addColumn (1, pYReal);
1588 rPlotFile.addColumn (2, pYImag);
1589 rPlotFile.addColumn (3, pYMag);
1590 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1591 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1592 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1593 *theApp->getLog() << os.str().c_str() << "\n";
1594 rPlotFile.addDescription (os.str().c_str());
1602 if (theApp->getAskDeleteNewDocs())
1603 pPlotDoc->Modify (true);
1604 pPlotDoc->getView()->getFrame()->Show(true);
1605 pPlotDoc->UpdateAllViews ();
1606 pPlotDoc->Activate();
1611 ImageFileView::OnPlotFFTCol (wxCommandEvent& event)
1613 int xCursor, yCursor;
1614 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1615 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1619 const ImageFile& rIF = GetDocument()->getImageFile();
1620 ImageFileArrayConst v = rIF.getArray();
1621 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1625 if (v != NULL && xCursor < nx) {
1626 fftw_complex* pcIn = new fftw_complex [ny];
1627 double *pdTemp = new double [ny];
1630 for (i = 0; i < ny; i++)
1631 pdTemp[i] = v[xCursor][i];
1632 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1633 for (i = 0; i < ny; i++)
1634 pcIn[i].re = pdTemp[i];
1636 for (i = 0; i < ny; i++) {
1637 if (rIF.isComplex())
1638 pdTemp[i] = vImag[xCursor][i];
1642 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1643 for (i = 0; i < ny; i++)
1644 pcIn[i].im = pdTemp[i];
1646 fftw_plan plan = fftw_create_plan (ny, FFTW_BACKWARD, FFTW_IN_PLACE | FFTW_ESTIMATE | FFTW_USE_WISDOM);
1647 fftw_one (plan, pcIn, NULL);
1648 fftw_destroy_plan (plan);
1650 double* pX = new double [ny];
1651 double* pYReal = new double [ny];
1652 double* pYImag = new double [ny];
1653 double* pYMag = new double [ny];
1654 for (i = 0; i < ny; i++) {
1656 pYReal[i] = pcIn[i].re / ny;
1657 pYImag[i] = pcIn[i].im / ny;
1658 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1661 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1663 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1665 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1666 std::ostringstream os;
1667 os << "Column " << xCursor;
1668 std::string title("title ");
1670 rPlotFile.addEzsetCommand (title.c_str());
1671 rPlotFile.addEzsetCommand ("xlabel Column");
1672 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1673 rPlotFile.addEzsetCommand ("lxfrac 0");
1674 rPlotFile.addEzsetCommand ("curve 1");
1675 rPlotFile.addEzsetCommand ("color 1");
1676 rPlotFile.addEzsetCommand ("dash 1");
1677 rPlotFile.addEzsetCommand ("curve 2");
1678 rPlotFile.addEzsetCommand ("color 4");
1679 rPlotFile.addEzsetCommand ("dash 3");
1680 rPlotFile.addEzsetCommand ("curve 3");
1681 rPlotFile.addEzsetCommand ("color 0");
1682 rPlotFile.addEzsetCommand ("solid");
1683 rPlotFile.addEzsetCommand ("box");
1684 rPlotFile.addEzsetCommand ("grid");
1685 rPlotFile.setCurveSize (4, ny);
1686 rPlotFile.addColumn (0, pX);
1687 rPlotFile.addColumn (1, pYReal);
1688 rPlotFile.addColumn (2, pYImag);
1689 rPlotFile.addColumn (3, pYMag);
1690 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1691 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1692 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1693 *theApp->getLog() << os.str().c_str() << "\n";
1694 rPlotFile.addDescription (os.str().c_str());
1703 if (theApp->getAskDeleteNewDocs())
1704 pPlotDoc->Modify (true);
1705 pPlotDoc->getView()->getFrame()->Show(true);
1706 pPlotDoc->UpdateAllViews ();
1707 pPlotDoc->Activate();
1713 ImageFileView::OnCompareCol (wxCommandEvent& event)
1715 int xCursor, yCursor;
1716 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1717 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1721 std::vector<ImageFileDocument*> vecIFDoc;
1722 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1723 if (vecIFDoc.size() == 0) {
1724 wxMessageBox ("No compatible images for Column Comparison", "Error");
1727 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1729 if (dialogGetCompare.ShowModal() == wxID_OK) {
1730 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1731 const ImageFile& rIF = GetDocument()->getImageFile();
1732 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1734 ImageFileArrayConst v1 = rIF.getArray();
1735 ImageFileArrayConst v2 = rCompareIF.getArray();
1739 if (v1 != NULL && xCursor < nx) {
1740 double* pX = new double [ny];
1741 double* pY1 = new double [ny];
1742 double* pY2 = new double [ny];
1743 for (int i = 0; i < ny; i++) {
1745 pY1[i] = v1[xCursor][i];
1746 pY2[i] = v2[xCursor][i];
1748 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1750 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1752 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1753 std::ostringstream os;
1754 os << "Column " << xCursor << " Comparison";
1755 std::string title("title ");
1757 rPlotFile.addEzsetCommand (title.c_str());
1758 rPlotFile.addEzsetCommand ("xlabel Row");
1759 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1760 rPlotFile.addEzsetCommand ("lxfrac 0");
1761 rPlotFile.addEzsetCommand ("curve 1");
1762 rPlotFile.addEzsetCommand ("color 2");
1763 rPlotFile.addEzsetCommand ("curve 2");
1764 rPlotFile.addEzsetCommand ("color 4");
1765 rPlotFile.addEzsetCommand ("dash 5");
1766 rPlotFile.addEzsetCommand ("box");
1767 rPlotFile.addEzsetCommand ("grid");
1768 rPlotFile.setCurveSize (3, ny);
1769 rPlotFile.addColumn (0, pX);
1770 rPlotFile.addColumn (1, pY1);
1771 rPlotFile.addColumn (2, pY2);
1774 for (iL = 0; iL < rIF.nLabels(); iL++) {
1775 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1777 s += rIF.labelGet(iL).getLabelString();
1778 rPlotFile.addDescription (s.c_str());
1780 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1781 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1783 s += rCompareIF.labelGet(iL).getLabelString();
1784 rPlotFile.addDescription (s.c_str());
1786 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1787 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1788 *theApp->getLog() << os.str().c_str() << "\n";
1789 rPlotFile.addDescription (os.str().c_str());
1794 if (theApp->getAskDeleteNewDocs())
1795 pPlotDoc->Modify (true);
1796 pPlotDoc->getView()->getFrame()->Show(true);
1797 pPlotDoc->UpdateAllViews ();
1798 pPlotDoc->Activate();
1804 ImageFileView::OnCompareRow (wxCommandEvent& event)
1806 int xCursor, yCursor;
1807 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1808 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1812 std::vector<ImageFileDocument*> vecIFDoc;
1813 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1815 if (vecIFDoc.size() == 0) {
1816 wxMessageBox ("No compatible images for Row Comparison", "Error");
1820 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1822 if (dialogGetCompare.ShowModal() == wxID_OK) {
1823 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1824 const ImageFile& rIF = GetDocument()->getImageFile();
1825 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1827 ImageFileArrayConst v1 = rIF.getArray();
1828 ImageFileArrayConst v2 = rCompareIF.getArray();
1832 if (v1 != NULL && yCursor < ny) {
1833 double* pX = new double [nx];
1834 double* pY1 = new double [nx];
1835 double* pY2 = new double [nx];
1836 for (int i = 0; i < nx; i++) {
1838 pY1[i] = v1[i][yCursor];
1839 pY2[i] = v2[i][yCursor];
1841 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1843 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1845 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1846 std::ostringstream os;
1847 os << "Row " << yCursor << " Comparison";
1848 std::string title("title ");
1850 rPlotFile.addEzsetCommand (title.c_str());
1851 rPlotFile.addEzsetCommand ("xlabel Column");
1852 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1853 rPlotFile.addEzsetCommand ("lxfrac 0");
1854 rPlotFile.addEzsetCommand ("curve 1");
1855 rPlotFile.addEzsetCommand ("color 2");
1856 rPlotFile.addEzsetCommand ("curve 2");
1857 rPlotFile.addEzsetCommand ("color 4");
1858 rPlotFile.addEzsetCommand ("dash 5");
1859 rPlotFile.addEzsetCommand ("box");
1860 rPlotFile.addEzsetCommand ("grid");
1861 rPlotFile.setCurveSize (3, nx);
1862 rPlotFile.addColumn (0, pX);
1863 rPlotFile.addColumn (1, pY1);
1864 rPlotFile.addColumn (2, pY2);
1866 for (iL = 0; iL < rIF.nLabels(); iL++) {
1867 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1869 s += rIF.labelGet(iL).getLabelString();
1870 rPlotFile.addDescription (s.c_str());
1872 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1873 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1875 s += rCompareIF.labelGet(iL).getLabelString();
1876 rPlotFile.addDescription (s.c_str());
1878 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1879 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1880 *theApp->getLog() << os.str().c_str() << "\n";
1881 rPlotFile.addDescription (os.str().c_str());
1886 if (theApp->getAskDeleteNewDocs())
1887 pPlotDoc->Modify (true);
1888 pPlotDoc->getView()->getFrame()->Show(true);
1889 pPlotDoc->UpdateAllViews ();
1890 pPlotDoc->Activate();
1895 static int NUMBER_HISTOGRAM_BINS = 256;
1898 ImageFileView::OnPlotHistogram (wxCommandEvent& event)
1900 const ImageFile& rIF = GetDocument()->getImageFile();
1901 ImageFileArrayConst v = rIF.getArray();
1905 if (v != NULL && nx > 0 && ny > 0) {
1906 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1908 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1912 double* pX = new double [NUMBER_HISTOGRAM_BINS];
1913 double* pY = new double [NUMBER_HISTOGRAM_BINS];
1915 rIF.getMinMax (dMin, dMax);
1916 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
1918 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
1919 pX[i] = dMin + (i + 0.5) * dBinWidth;
1922 for (int ix = 0; ix < nx; ix++)
1923 for (int iy = 0; iy < ny; iy++) {
1924 int iBin = nearest<int> ((v[ix][iy] - dMin) / dBinWidth);
1925 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
1929 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1930 std::ostringstream os;
1932 std::string title("title ");
1934 rPlotFile.addEzsetCommand (title.c_str());
1935 rPlotFile.addEzsetCommand ("xlabel Pixel Value");
1936 rPlotFile.addEzsetCommand ("ylabel Count");
1937 rPlotFile.addEzsetCommand ("box");
1938 rPlotFile.addEzsetCommand ("grid");
1939 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
1940 rPlotFile.addColumn (0, pX);
1941 rPlotFile.addColumn (1, pY);
1942 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++) {
1943 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1945 s += rIF.labelGet(iL).getLabelString();
1946 rPlotFile.addDescription (s.c_str());
1948 os << " plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1949 *theApp->getLog() << os.str().c_str() << "\n";
1950 rPlotFile.addDescription (os.str().c_str());
1953 if (theApp->getAskDeleteNewDocs())
1954 pPlotDoc->Modify (true);
1955 pPlotDoc->getView()->getFrame()->Show(true);
1956 pPlotDoc->UpdateAllViews ();
1957 pPlotDoc->Activate();
1964 PhantomCanvas::PhantomCanvas (PhantomFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1965 : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v)
1969 PhantomCanvas::~PhantomCanvas ()
1975 PhantomCanvas::OnDraw (wxDC& dc)
1978 m_pView->OnDraw(& dc);
1982 PhantomCanvas::GetBestSize() const
1988 theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
1989 xSize = maxValue<int> (xSize, ySize);
1991 ySize = xSize = (xSize / 4);
1993 xSize = ySize = static_cast<int>(ySize * .7);
1996 return wxSize (xSize, ySize);
2003 IMPLEMENT_DYNAMIC_CLASS(PhantomFileView, wxView)
2005 BEGIN_EVENT_TABLE(PhantomFileView, wxView)
2006 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomFileView::OnProperties)
2007 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomFileView::OnRasterize)
2008 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomFileView::OnProjections)
2011 PhantomFileView::PhantomFileView()
2012 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0)
2014 #if defined(DEBUG) || defined(_DEBUG)
2015 m_iDefaultNDet = 165;
2016 m_iDefaultNView = 180;
2017 m_iDefaultNSample = 1;
2019 m_iDefaultNDet = 367;
2020 m_iDefaultNView = 320;
2021 m_iDefaultNSample = 2;
2023 m_iDefaultOffsetView = 0;
2024 m_dDefaultRotation = 1;
2025 m_dDefaultFocalLength = 2;
2026 m_dDefaultCenterDetectorLength = 2;
2027 m_dDefaultViewRatio = 1;
2028 m_dDefaultScanRatio = 1;
2029 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
2030 m_iDefaultTrace = Trace::TRACE_NONE;
2033 m_iDefaultRasterNX = 115;
2034 m_iDefaultRasterNY = 115;
2035 m_iDefaultRasterNSamples = 1;
2037 m_iDefaultRasterNX = 256;
2038 m_iDefaultRasterNY = 256;
2039 m_iDefaultRasterNSamples = 2;
2041 m_dDefaultRasterViewRatio = 1;
2044 PhantomFileView::~PhantomFileView()
2046 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2047 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
2051 PhantomFileView::OnProperties (wxCommandEvent& event)
2053 const int idPhantom = GetDocument()->getPhantomID();
2054 const wxString& namePhantom = GetDocument()->getPhantomName();
2055 std::ostringstream os;
2056 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")" << "\n";
2057 const Phantom& rPhantom = GetDocument()->getPhantom();
2058 rPhantom.printDefinitions (os);
2060 rPhantom.print (os);
2062 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2063 wxMessageBox (os.str().c_str(), "Phantom Properties");
2064 GetDocument()->Activate();
2069 PhantomFileView::OnProjections (wxCommandEvent& event)
2071 DialogGetProjectionParameters dialogProjection (getFrameForChild(),
2072 m_iDefaultNDet, m_iDefaultNView, m_iDefaultOffsetView, m_iDefaultNSample, m_dDefaultRotation,
2073 m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio,
2074 m_iDefaultGeometry, m_iDefaultTrace);
2075 int retVal = dialogProjection.ShowModal();
2076 if (retVal != wxID_OK)
2079 m_iDefaultNDet = dialogProjection.getNDet();
2080 m_iDefaultNView = dialogProjection.getNView();
2081 m_iDefaultOffsetView = dialogProjection.getOffsetView();
2082 m_iDefaultNSample = dialogProjection.getNSamples();
2083 m_iDefaultTrace = dialogProjection.getTrace();
2084 m_dDefaultRotation = dialogProjection.getRotAngle();
2085 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
2086 m_dDefaultCenterDetectorLength = dialogProjection.getCenterDetectorLengthRatio();
2087 m_dDefaultViewRatio = dialogProjection.getViewRatio();
2088 m_dDefaultScanRatio = dialogProjection.getScanRatio();
2089 wxString sGeometry = dialogProjection.getGeometry();
2090 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
2091 double dRotationRadians = m_dDefaultRotation;
2092 m_dDefaultRotation /= TWOPI; // convert back to fraction of a circle
2094 if (m_iDefaultNDet <= 0 || m_iDefaultNView <= 0 || sGeometry == "")
2097 const Phantom& rPhantom = GetDocument()->getPhantom();
2098 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultOffsetView, m_iDefaultNSample,
2099 dRotationRadians, m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio);
2100 if (theScanner.fail()) {
2101 wxString msg = "Failed making scanner\n";
2102 msg += theScanner.failMessage().c_str();
2103 *theApp->getLog() << msg << "\n";
2104 wxMessageBox (msg, "Error");
2108 std::ostringstream os;
2109 os << "Projections for " << rPhantom.name()
2110 << ": nDet=" << m_iDefaultNDet
2111 << ", nView=" << m_iDefaultNView
2112 << ", gantry offset=" << m_iDefaultOffsetView
2113 << ", nSamples=" << m_iDefaultNSample
2114 << ", RotAngle=" << m_dDefaultRotation
2115 << ", FocalLengthRatio=" << m_dDefaultFocalLength
2116 << ", CenterDetectorLengthRatio=" << m_dDefaultCenterDetectorLength
2117 << ", ViewRatio=" << m_dDefaultViewRatio
2118 << ", ScanRatio=" << m_dDefaultScanRatio
2119 << ", Geometry=" << sGeometry.c_str()
2120 << ", FanBeamAngle=" << convertRadiansToDegrees (theScanner.fanBeamAngle());
2123 Projections* pProj = NULL;
2124 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2125 pProj = new Projections;
2126 pProj->initFromScanner (theScanner);
2128 ProjectionsDialog dialogProjections (theScanner, *pProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(getFrameForChild()));
2129 for (int iView = 0; iView < pProj->nView(); iView++) {
2131 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
2136 while (dialogProjections.isPaused()) {
2143 if (theApp->getUseBackgroundTasks()) {
2144 ProjectorSupervisorThread* pProjector = new ProjectorSupervisorThread (this, m_iDefaultNDet,
2145 m_iDefaultNView, m_iDefaultOffsetView, sGeometry.c_str(), m_iDefaultNSample, dRotationRadians,
2146 m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio, os.str().c_str());
2147 if (pProjector->Create() != wxTHREAD_NO_ERROR) {
2148 sys_error (ERR_SEVERE, "Error creating projector thread");
2152 pProjector->SetPriority(60);
2156 #endif // HAVE_WXTHREADS
2158 pProj = new Projections;
2159 pProj->initFromScanner (theScanner);
2160 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), pProj->nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2161 for (int i = 0; i < pProj->nView(); i++) {
2162 //theScanner.collectProjections (*pProj, rPhantom, i, 1, true, m_iDefaultTrace);
2163 theScanner.collectProjections (*pProj, rPhantom, i, 1, theScanner.offsetView(), true, m_iDefaultTrace);
2164 if ((i + 1) % ITER_PER_UPDATE == 0)
2165 if (! dlgProgress.Update (i+1)) {
2173 *theApp->getLog() << os.str().c_str() << "\n";
2174 pProj->setRemark (os.str());
2175 pProj->setCalcTime (timer.timerEnd());
2177 ProjectionFileDocument* pProjectionDoc = theApp->newProjectionDoc();
2178 if (! pProjectionDoc) {
2179 sys_error (ERR_SEVERE, "Unable to create projection document");
2182 pProjectionDoc->setProjections (pProj);
2183 if (theApp->getAskDeleteNewDocs())
2184 pProjectionDoc-> Modify(true);
2185 pProjectionDoc->UpdateAllViews (this);
2186 pProjectionDoc->getView()->setInitialClientSize();
2187 pProjectionDoc->Activate();
2192 PhantomFileView::OnRasterize (wxCommandEvent& event)
2194 DialogGetRasterParameters dialogRaster (getFrameForChild(), m_iDefaultRasterNX, m_iDefaultRasterNY,
2195 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio);
2196 int retVal = dialogRaster.ShowModal();
2197 if (retVal != wxID_OK)
2200 m_iDefaultRasterNX = dialogRaster.getXSize();
2201 m_iDefaultRasterNY = dialogRaster.getYSize();
2202 m_iDefaultRasterNSamples = dialogRaster.getNSamples();
2203 m_dDefaultRasterViewRatio = dialogRaster.getViewRatio();
2204 if (m_iDefaultRasterNSamples < 1)
2205 m_iDefaultRasterNSamples = 1;
2206 if (m_dDefaultRasterViewRatio < 0)
2207 m_dDefaultRasterViewRatio = 0;
2208 if (m_iDefaultRasterNX <= 0 || m_iDefaultRasterNY <= 0)
2211 const Phantom& rPhantom = GetDocument()->getPhantom();
2212 std::ostringstream os;
2213 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << m_iDefaultRasterNX << ", YSize="
2214 << m_iDefaultRasterNY << ", ViewRatio=" << m_dDefaultRasterViewRatio << ", nSamples="
2215 << m_iDefaultRasterNSamples;;
2218 if (theApp->getUseBackgroundTasks()) {
2219 RasterizerSupervisorThread* pThread = new RasterizerSupervisorThread (this, m_iDefaultRasterNX, m_iDefaultRasterNY,
2220 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio, os.str().c_str());
2221 if (pThread->Create() != wxTHREAD_NO_ERROR) {
2222 *theApp->getLog() << "Error creating rasterizer thread\n";
2225 pThread->SetPriority (60);
2230 ImageFile* pImageFile = new ImageFile (m_iDefaultRasterNX, m_iDefaultRasterNY);
2232 wxProgressDialog dlgProgress (wxString("Rasterize"),
2233 wxString("Rasterization Progress"),
2234 pImageFile->nx() + 1,
2238 for (unsigned int i = 0; i < pImageFile->nx(); i++) {
2239 rPhantom.convertToImagefile (*pImageFile, m_dDefaultRasterViewRatio,
2240 m_iDefaultRasterNSamples, Trace::TRACE_NONE,
2242 if ((i + 1) % ITER_PER_UPDATE == 0)
2243 if (! dlgProgress.Update (i+1)) {
2249 ImageFileDocument* pRasterDoc = theApp->newImageDoc();
2251 sys_error (ERR_SEVERE, "Unable to create image file");
2254 pRasterDoc->setImageFile (pImageFile);
2255 if (theApp->getAskDeleteNewDocs())
2256 pRasterDoc->Modify (true);
2257 *theApp->getLog() << os.str().c_str() << "\n";
2258 pImageFile->labelAdd (os.str().c_str(), timer.timerEnd());
2260 pRasterDoc->UpdateAllViews(this);
2261 pRasterDoc->getView()->setInitialClientSize();
2262 pRasterDoc->Activate();
2268 PhantomFileView::CreateCanvas (wxFrame *parent)
2270 PhantomCanvas* pCanvas = new PhantomCanvas (this, parent, wxPoint(-1,-1),
2272 pCanvas->SetBackgroundColour(*wxWHITE);
2283 PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2286 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
2288 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
2290 theApp->setIconForFrame (subframe);
2292 m_pFileMenu = new wxMenu;
2294 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2295 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2296 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2297 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2298 m_pFileMenu->Append(wxID_CLOSE, "&Close");
2300 m_pFileMenu->AppendSeparator();
2301 m_pFileMenu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
2303 m_pFileMenu->AppendSeparator();
2304 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2305 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2306 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2307 m_pFileMenu->AppendSeparator();
2308 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
2309 m_pFileMenu->AppendSeparator();
2310 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
2311 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2312 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2313 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2315 wxMenu *process_menu = new wxMenu;
2316 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...\tCtrl-R");
2317 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...\tCtrl-J");
2319 wxMenu *help_menu = new wxMenu;
2320 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2321 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
2322 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
2323 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2325 wxMenuBar *menu_bar = new wxMenuBar;
2327 menu_bar->Append(m_pFileMenu, "&File");
2328 menu_bar->Append(process_menu, "&Process");
2329 menu_bar->Append(help_menu, "&Help");
2331 subframe->SetMenuBar(menu_bar);
2332 subframe->Centre(wxBOTH);
2334 wxAcceleratorEntry accelEntries[3];
2335 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('J'), PHMMENU_PROCESS_PROJECTIONS);
2336 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('R'), PHMMENU_PROCESS_RASTERIZE);
2337 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('I'), PHMMENU_FILE_PROPERTIES);
2338 wxAcceleratorTable accelTable (3, accelEntries);
2339 subframe->SetAcceleratorTable (accelTable);
2346 PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2348 m_pFrame = CreateChildFrame(doc, this);
2350 m_pCanvas = CreateCanvas (m_pFrame);
2351 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
2352 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
2353 m_pFrame->SetTitle ("PhantomFileView");
2355 m_pFrame->Show(true);
2362 PhantomFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2365 m_pCanvas->Refresh();
2369 PhantomFileView::OnClose (bool deleteWindow)
2371 if (! GetDocument() || ! GetDocument()->Close())
2376 m_pCanvas->setView(NULL);
2379 wxString s(wxTheApp->GetAppName());
2381 m_pFrame->SetTitle(s);
2388 if (GetDocument() && GetDocument()->getBadFileOpen())
2389 ::wxYield(); // wxWindows bug workaround
2396 PhantomFileView::OnDraw (wxDC* dc)
2399 m_pCanvas->GetClientSize (&xsize, &ysize);
2400 SGPDriver driver (dc, xsize, ysize);
2402 const Phantom& rPhantom = GetDocument()->getPhantom();
2403 sgp.setColor (C_RED);
2404 rPhantom.show (sgp);
2409 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2410 : wxScrolledWindow(frame, -1, pos, size, style)
2415 ProjectionFileCanvas::~ProjectionFileCanvas ()
2421 ProjectionFileCanvas::OnDraw(wxDC& dc)
2424 m_pView->OnDraw(& dc);
2428 ProjectionFileCanvas::GetBestSize () const
2430 const int iMinX = 50;
2431 const int iMinY = 20;
2432 wxSize bestSize (iMinX,iMinY);
2435 Projections& rProj = m_pView->GetDocument()->getProjections();
2436 bestSize.Set (rProj.nDet(), rProj.nView());
2439 if (bestSize.x > 800)
2441 if (bestSize.y > 800)
2444 if (bestSize.x < iMinX)
2446 if (bestSize.y < iMinY)
2453 // ProjectionFileView
2455 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
2457 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
2458 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
2459 EVT_MENU(PJMENU_RECONSTRUCT_FBP, ProjectionFileView::OnReconstructFBP)
2460 EVT_MENU(PJMENU_RECONSTRUCT_FBP_REBIN, ProjectionFileView::OnReconstructFBPRebin)
2461 EVT_MENU(PJMENU_RECONSTRUCT_FOURIER, ProjectionFileView::OnReconstructFourier)
2462 EVT_MENU(PJMENU_CONVERT_RECTANGULAR, ProjectionFileView::OnConvertRectangular)
2463 EVT_MENU(PJMENU_CONVERT_POLAR, ProjectionFileView::OnConvertPolar)
2464 EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
2465 EVT_MENU(PJMENU_CONVERT_PARALLEL, ProjectionFileView::OnConvertParallel)
2466 EVT_MENU(PJMENU_PLOT_TTHETA_SAMPLING, ProjectionFileView::OnPlotTThetaSampling)
2467 EVT_MENU(PJMENU_PLOT_HISTOGRAM, ProjectionFileView::OnPlotHistogram)
2468 // EVT_MENU(PJMENU_ARTIFACT_REDUCTION, ProjectionFileView::OnArtifactReduction)
2472 ProjectionFileView::ProjectionFileView()
2473 : wxView(), m_pBitmap(0), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0)
2483 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
2484 m_dDefaultFilterParam = 1.;
2486 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
2487 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
2489 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
2490 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
2492 m_iDefaultZeropad = 1;
2493 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF;
2494 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
2495 m_iDefaultInterpParam = 1;
2496 m_iDefaultTrace = Trace::TRACE_NONE;
2498 m_iDefaultPolarNX = 256;
2499 m_iDefaultPolarNY = 256;
2500 m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR;
2501 m_iDefaultPolarZeropad = 1;
2504 ProjectionFileView::~ProjectionFileView()
2506 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2507 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2511 ProjectionFileView::OnProperties (wxCommandEvent& event)
2513 const Projections& rProj = GetDocument()->getProjections();
2514 std::ostringstream os;
2515 rProj.printScanInfo(os);
2516 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2517 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
2518 dialogMsg.ShowModal();
2519 GetDocument()->Activate();
2524 ProjectionFileView::OnConvertRectangular (wxCommandEvent& event)
2526 Projections& rProj = GetDocument()->getProjections();
2528 int nDet = rProj.nDet();
2529 int nView = rProj.nView();
2530 ImageFile* pIF = new ImageFile (nDet, nView);
2531 ImageFileArray v = pIF->getArray();
2532 for (int iv = 0; iv < nView; iv++) {
2533 DetectorValue* detval = rProj.getDetectorArray(iv).detValues();
2535 for (int id = 0; id < nDet; id++)
2536 v[id][iv] = detval[id];
2539 ImageFileDocument* pRectDoc = theApp->newImageDoc ();
2541 sys_error (ERR_SEVERE, "Unable to create image file");
2544 pRectDoc->setImageFile (pIF);
2545 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2546 std::ostringstream os;
2547 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to rectangular image";
2548 *theApp->getLog() << os.str().c_str() << "\n";
2549 pIF->labelAdd (os.str().c_str());
2550 if (theApp->getAskDeleteNewDocs())
2551 pRectDoc->Modify (true);
2552 pRectDoc->UpdateAllViews();
2553 pRectDoc->getView()->setInitialClientSize();
2554 pRectDoc->Activate();
2558 ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
2560 Projections& rProj = GetDocument()->getProjections();
2561 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2562 m_iDefaultPolarInterpolation, -1, IDH_DLG_POLAR);
2563 if (dialogPolar.ShowModal() == wxID_OK) {
2564 wxProgressDialog dlgProgress (wxString("Convert Polar"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2565 wxString strInterpolation (dialogPolar.getInterpolationName());
2566 m_iDefaultPolarNX = dialogPolar.getXSize();
2567 m_iDefaultPolarNY = dialogPolar.getYSize();
2568 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2569 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2570 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2572 if (! rProj.convertPolar (*pIF, m_iDefaultPolarInterpolation)) {
2574 *theApp->getLog() << "Error converting to Polar\n";
2578 pPolarDoc = theApp->newImageDoc ();
2580 sys_error (ERR_SEVERE, "Unable to create image file");
2583 pPolarDoc->setImageFile (pIF);
2584 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2585 std::ostringstream os;
2586 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to polar image: xSize="
2587 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2588 << strInterpolation.c_str();
2589 *theApp->getLog() << os.str().c_str() << "\n";
2590 pIF->labelAdd (os.str().c_str());
2591 if (theApp->getAskDeleteNewDocs())
2592 pPolarDoc->Modify (true);
2593 pPolarDoc->UpdateAllViews ();
2594 pPolarDoc->getView()->setInitialClientSize();
2595 pPolarDoc->Activate();
2600 ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
2602 Projections& rProj = GetDocument()->getProjections();
2603 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert to FFT Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2604 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad, IDH_DLG_FFT_POLAR);
2605 if (dialogPolar.ShowModal() == wxID_OK) {
2606 wxProgressDialog dlgProgress (wxString("Convert FFT Polar"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2607 wxString strInterpolation (dialogPolar.getInterpolationName());
2608 m_iDefaultPolarNX = dialogPolar.getXSize();
2609 m_iDefaultPolarNY = dialogPolar.getYSize();
2610 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2611 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2613 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2614 if (! rProj.convertFFTPolar (*pIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad)) {
2616 *theApp->getLog() << "Error converting to polar\n";
2619 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2621 sys_error (ERR_SEVERE, "Unable to create image file");
2624 pPolarDoc->setImageFile (pIF);
2625 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2626 std::ostringstream os;
2627 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to FFT polar image: xSize="
2628 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2629 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2630 *theApp->getLog() << os.str().c_str() << "\n";
2631 pIF->labelAdd (os.str().c_str());
2632 if (theApp->getAskDeleteNewDocs())
2633 pPolarDoc->Modify (true);
2634 pPolarDoc->UpdateAllViews (this);
2635 pPolarDoc->getView()->setInitialClientSize();
2636 pPolarDoc->Activate();
2641 ProjectionFileView::OnPlotTThetaSampling (wxCommandEvent& event)
2643 DialogGetThetaRange dlgTheta (this->getFrame(), ParallelRaysums::THETA_RANGE_UNCONSTRAINED);
2644 if (dlgTheta.ShowModal() != wxID_OK)
2647 int iThetaRange = dlgTheta.getThetaRange();
2649 Projections& rProj = GetDocument()->getProjections();
2650 ParallelRaysums parallel (&rProj, iThetaRange);
2651 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
2652 PlotFile& rPlot = pPlotDoc->getPlotFile();
2653 ParallelRaysums::CoordinateContainer& coordContainer = parallel.getCoordinates();
2654 double* pdT = new double [parallel.getNumCoordinates()];
2655 double* pdTheta = new double [parallel.getNumCoordinates()];
2657 for (int i = 0; i < parallel.getNumCoordinates(); i++) {
2658 pdT[i] = coordContainer[i]->m_dT;
2659 pdTheta[i] = coordContainer[i]->m_dTheta;
2661 rPlot.setCurveSize (2, parallel.getNumCoordinates(), true);
2662 rPlot.addEzsetCommand ("title T-Theta Sampling");
2663 rPlot.addEzsetCommand ("xlabel T");
2664 rPlot.addEzsetCommand ("ylabel Theta");
2665 rPlot.addEzsetCommand ("curve 1");
2666 if (rProj.nDet() < 50 && rProj.nView() < 50)
2667 rPlot.addEzsetCommand ("symbol 1"); // x symbol
2669 rPlot.addEzsetCommand ("symbol 6"); // point symbol
2670 rPlot.addEzsetCommand ("noline");
2671 rPlot.addColumn (0, pdT);
2672 rPlot.addColumn (1, pdTheta);
2675 if (theApp->getAskDeleteNewDocs())
2676 pPlotDoc->Modify (true);
2677 pPlotDoc->getView()->getFrame()->Show(true);
2678 pPlotDoc->UpdateAllViews ();
2679 pPlotDoc->Activate();
2684 ProjectionFileView::OnPlotHistogram (wxCommandEvent& event)
2686 Projections& rProj = GetDocument()->getProjections();
2687 int nDet = rProj.nDet();
2688 int nView = rProj.nView();
2690 if (nDet < 1 || nView < 1)
2693 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
2695 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
2699 DetectorValue* pdDetval = rProj.getDetectorArray(0).detValues();
2700 double dMin = pdDetval[0], dMax = pdDetval[0];
2702 for (int iv = 0; iv < nView; iv++) {
2703 pdDetval = rProj.getDetectorArray(iv).detValues();
2704 for (int id = 0; id < nDet; id++) {
2705 double dV = pdDetval[id];
2713 double* pX = new double [NUMBER_HISTOGRAM_BINS];
2714 double* pY = new double [NUMBER_HISTOGRAM_BINS];
2715 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
2717 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
2718 pX[i] = dMin + (i + 0.5) * dBinWidth;
2721 for (int j = 0; j < nView; j++) {
2722 pdDetval = rProj.getDetectorArray(j).detValues();
2723 for (int id = 0; id < nDet; id++) {
2724 int iBin = nearest<int> ((pdDetval[id] - dMin) / dBinWidth);
2725 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
2729 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
2730 std::ostringstream os;
2732 std::string title("title ");
2734 rPlotFile.addEzsetCommand (title.c_str());
2735 rPlotFile.addEzsetCommand ("xlabel Detector Value");
2736 rPlotFile.addEzsetCommand ("ylabel Count");
2737 rPlotFile.addEzsetCommand ("box");
2738 rPlotFile.addEzsetCommand ("grid");
2739 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
2740 rPlotFile.addColumn (0, pX);
2741 rPlotFile.addColumn (1, pY);
2742 rPlotFile.addDescription (rProj.remark());
2743 os << " plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
2744 *theApp->getLog() << os.str().c_str() << "\n";
2745 rPlotFile.addDescription (os.str().c_str());
2748 if (theApp->getAskDeleteNewDocs())
2749 pPlotDoc->Modify (true);
2750 pPlotDoc->getView()->getFrame()->Show(true);
2751 pPlotDoc->UpdateAllViews ();
2752 pPlotDoc->Activate();
2757 ProjectionFileView::OnConvertParallel (wxCommandEvent& event)
2759 Projections& rProj = GetDocument()->getProjections();
2760 if (rProj.geometry() == Scanner::GEOMETRY_PARALLEL) {
2761 wxMessageBox ("Projections are already parallel", "Error");
2764 wxProgressDialog dlgProgress (wxString("Convert to Parallel"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2765 Projections* pProjNew = rProj.interpolateToParallel();
2766 ProjectionFileDocument* pProjDocNew = theApp->newProjectionDoc();
2767 pProjDocNew->setProjections (pProjNew);
2769 if (ProjectionFileView* projView = pProjDocNew->getView()) {
2770 projView->OnUpdate (projView, NULL);
2771 if (projView->getCanvas())
2772 projView->getCanvas()->SetClientSize (pProjNew->nDet(), pProjNew->nView());
2773 if (wxFrame* pFrame = projView->getFrame()) {
2778 GetDocumentManager()->ActivateView (projView, true, false);
2780 if (theApp->getAskDeleteNewDocs())
2781 pProjDocNew-> Modify(true);
2782 pProjDocNew->UpdateAllViews (this);
2783 pProjDocNew->getView()->setInitialClientSize();
2784 pProjDocNew->Activate();
2788 ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
2790 Projections& rProj = GetDocument()->getProjections();
2791 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Fourier Reconstruction", m_iDefaultPolarNX, m_iDefaultPolarNY,
2792 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad, IDH_DLG_RECON_FOURIER);
2793 if (dialogPolar.ShowModal() == wxID_OK) {
2794 wxProgressDialog dlgProgress (wxString("Reconstruction Fourier"), wxString("Reconstruction Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2795 wxString strInterpolation (dialogPolar.getInterpolationName());
2796 m_iDefaultPolarNX = dialogPolar.getXSize();
2797 m_iDefaultPolarNY = dialogPolar.getYSize();
2798 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2799 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2801 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2802 if (! rProj.convertFFTPolar (*pIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad)) {
2804 *theApp->getLog() << "Error converting to polar\n";
2810 pIF->magnitude(*pIF);
2811 Fourier::shuffleFourierToNaturalOrder (*pIF);
2813 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2815 sys_error (ERR_SEVERE, "Unable to create image file");
2818 pPolarDoc->setImageFile (pIF);
2819 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2820 std::ostringstream os;
2821 os << "Reconstruct Fourier " << GetFrame()->GetTitle().c_str() << ": xSize="
2822 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2823 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2824 *theApp->getLog() << os.str().c_str() << "\n";
2825 pIF->labelAdd (os.str().c_str());
2826 if (theApp->getAskDeleteNewDocs())
2827 pPolarDoc->Modify (true);
2828 pPolarDoc->UpdateAllViews ();
2829 pPolarDoc->getView()->setInitialClientSize();
2830 pPolarDoc->Activate();
2835 ProjectionFileView::OnReconstructFBPRebin (wxCommandEvent& event)
2837 Projections& rProj = GetDocument()->getProjections();
2838 doReconstructFBP (rProj, true);
2842 ProjectionFileView::OnReconstructFBP (wxCommandEvent& event)
2844 Projections& rProj = GetDocument()->getProjections();
2845 doReconstructFBP (rProj, false);
2849 ProjectionFileView::doReconstructFBP (const Projections& rProj, bool bRebinToParallel)
2851 ReconstructionROI defaultROI;
2852 defaultROI.m_dXMin = -rProj.phmLen() / 2;
2853 defaultROI.m_dXMax = defaultROI.m_dXMin + rProj.phmLen();
2854 defaultROI.m_dYMin = -rProj.phmLen() / 2;
2855 defaultROI.m_dYMax = defaultROI.m_dYMin + rProj.phmLen();
2857 DialogGetReconstructionParameters dialogReconstruction (getFrameForChild(), m_iDefaultNX, m_iDefaultNY,
2858 m_iDefaultFilter, m_dDefaultFilterParam, m_iDefaultFilterMethod, m_iDefaultFilterGeneration,
2859 m_iDefaultZeropad, m_iDefaultInterpolation, m_iDefaultInterpParam, m_iDefaultBackprojector,
2860 m_iDefaultTrace, &defaultROI);
2862 int retVal = dialogReconstruction.ShowModal();
2863 if (retVal != wxID_OK)
2866 m_iDefaultNX = dialogReconstruction.getXSize();
2867 m_iDefaultNY = dialogReconstruction.getYSize();
2868 wxString optFilterName = dialogReconstruction.getFilterName();
2869 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
2870 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
2871 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
2872 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
2873 m_iDefaultZeropad = dialogReconstruction.getZeropad();
2874 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
2875 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
2876 wxString optInterpName = dialogReconstruction.getInterpName();
2877 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
2878 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
2879 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
2880 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
2881 m_iDefaultTrace = dialogReconstruction.getTrace();
2882 dialogReconstruction.getROI (&defaultROI);
2884 if (m_iDefaultNX <= 0 && m_iDefaultNY <= 0)
2887 std::ostringstream os;
2888 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();
2889 if (bRebinToParallel)
2890 os << "; Interpolate to Parallel";
2893 ImageFile* pImageFile = NULL;
2894 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2895 pImageFile = new ImageFile (m_iDefaultNX, m_iDefaultNY);
2896 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2897 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2898 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace,
2899 &defaultROI, bRebinToParallel);
2901 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstructor, rProj, *pImageFile, m_iDefaultTrace, getFrameForChild());
2902 for (int iView = 0; iView < rProj.nView(); iView++) {
2904 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView, true)) {
2905 delete pDlgReconstruct;
2906 delete pReconstructor;
2911 while (pDlgReconstruct->isPaused()) {
2916 pReconstructor->postProcessing();
2917 delete pDlgReconstruct;
2918 delete pReconstructor;
2921 if (theApp->getUseBackgroundTasks()) {
2922 ReconstructorSupervisorThread* pReconstructor = new ReconstructorSupervisorThread (this, m_iDefaultNX,
2923 m_iDefaultNY, optFilterName.c_str(), m_dDefaultFilterParam, optFilterMethodName.c_str(),
2924 m_iDefaultZeropad, optFilterGenerationName.c_str(), optInterpName.c_str(), m_iDefaultInterpParam,
2925 optBackprojectName.c_str(), os.str().c_str(), &defaultROI, bRebinToParallel);
2926 if (pReconstructor->Create() != wxTHREAD_NO_ERROR) {
2927 sys_error (ERR_SEVERE, "Error creating reconstructor thread");
2928 delete pReconstructor;
2931 pReconstructor->SetPriority (60);
2932 pReconstructor->Run();
2937 pImageFile = new ImageFile (m_iDefaultNX, m_iDefaultNY);
2938 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2939 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2940 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2941 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace,
2942 &defaultROI, bRebinToParallel);
2944 for (int iView = 0; iView < rProj.nView(); iView++) {
2945 pReconstructor->reconstructView (iView, 1);
2946 if ((iView + 1) % ITER_PER_UPDATE == 0)
2947 if (! dlgProgress.Update (iView + 1)) {
2948 delete pReconstructor;
2949 return; // don't make new window, thread will do this
2952 pReconstructor->postProcessing();
2953 delete pReconstructor;
2956 ImageFileDocument* pReconDoc = theApp->newImageDoc();
2958 sys_error (ERR_SEVERE, "Unable to create image file");
2961 *theApp->getLog() << os.str().c_str() << "\n";
2962 pImageFile->labelAdd (rProj.getLabel());
2963 pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd());
2965 pReconDoc->setImageFile (pImageFile);
2966 if (theApp->getAskDeleteNewDocs())
2967 pReconDoc->Modify (true);
2968 pReconDoc->UpdateAllViews();
2969 pReconDoc->getView()->setInitialClientSize();
2970 pReconDoc->Activate();
2975 ProjectionFileView::OnArtifactReduction (wxCommandEvent& event)
2980 ProjectionFileCanvas*
2981 ProjectionFileView::CreateCanvas (wxFrame *parent)
2983 ProjectionFileCanvas* pCanvas;
2985 parent->GetClientSize(&width, &height);
2987 pCanvas = new ProjectionFileCanvas (this, parent, wxPoint(-1,-1), wxSize(width, height), 0);
2989 pCanvas->SetScrollbars(20, 20, 50, 50);
2990 pCanvas->SetBackgroundColour(*wxWHITE);
3001 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
3004 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
3006 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
3008 theApp->setIconForFrame (subframe);
3010 m_pFileMenu = new wxMenu;
3012 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3013 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3014 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3015 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3016 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3017 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3019 m_pFileMenu->AppendSeparator();
3020 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
3022 m_pFileMenu->AppendSeparator();
3023 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3024 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3025 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3026 m_pFileMenu->AppendSeparator();
3027 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3028 m_pFileMenu->AppendSeparator();
3029 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3030 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3031 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3032 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3034 wxMenu *convert_menu = new wxMenu;
3035 convert_menu->Append (PJMENU_CONVERT_RECTANGULAR, "&Rectangular Image");
3036 convert_menu->Append (PJMENU_CONVERT_POLAR, "&Polar Image...\tCtrl-L");
3037 convert_menu->Append (PJMENU_CONVERT_FFT_POLAR, "FF&T->Polar Image...\tCtrl-T");
3038 convert_menu->AppendSeparator();
3039 convert_menu->Append (PJMENU_CONVERT_PARALLEL, "&Interpolate to Parallel");
3041 // wxMenu* filter_menu = new wxMenu;
3042 // filter_menu->Append (PJMENU_ARTIFACT_REDUCTION, "&Artifact Reduction");
3044 wxMenu* analyze_menu = new wxMenu;
3045 analyze_menu->Append (PJMENU_PLOT_HISTOGRAM, "&Plot Histogram");
3046 analyze_menu->Append (PJMENU_PLOT_TTHETA_SAMPLING, "Plot T-T&heta Sampling...\tCtrl-H");
3048 wxMenu *reconstruct_menu = new wxMenu;
3049 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP, "&Filtered Backprojection...\tCtrl-R", "Reconstruct image using filtered backprojection");
3050 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP_REBIN, "Filtered &Backprojection (Rebin to Parallel)...\tCtrl-B", "Reconstruct image using filtered backprojection");
3052 // reconstruct_menu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Fourier...\tCtrl-E", "Reconstruct image using inverse Fourier");
3054 wxMenu *help_menu = new wxMenu;
3055 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3056 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3057 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3058 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3060 wxMenuBar *menu_bar = new wxMenuBar;
3062 menu_bar->Append (m_pFileMenu, "&File");
3063 menu_bar->Append (convert_menu, "&Convert");
3064 // menu_bar->Append (filter_menu, "Fi<er");
3065 menu_bar->Append (analyze_menu, "&Analyze");
3066 menu_bar->Append (reconstruct_menu, "&Reconstruct");
3067 menu_bar->Append (help_menu, "&Help");
3069 subframe->SetMenuBar(menu_bar);
3070 subframe->Centre(wxBOTH);
3072 wxAcceleratorEntry accelEntries[7];
3073 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('L'), PJMENU_CONVERT_POLAR);
3074 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('T'), PJMENU_CONVERT_FFT_POLAR);
3075 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('R'), PJMENU_RECONSTRUCT_FBP);
3076 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('B'), PJMENU_RECONSTRUCT_FBP_REBIN);
3077 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('E'), PJMENU_RECONSTRUCT_FOURIER);
3078 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('I'), PJMENU_FILE_PROPERTIES);
3079 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('H'), PJMENU_PLOT_TTHETA_SAMPLING);
3080 wxAcceleratorTable accelTable (7, accelEntries);
3081 subframe->SetAcceleratorTable (accelTable);
3088 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
3090 m_pFrame = CreateChildFrame(doc, this);
3092 m_pCanvas = CreateCanvas (m_pFrame);
3093 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
3094 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
3095 m_pFrame->SetTitle ("ProjectionFileView");
3097 m_pFrame->Show(true);
3104 ProjectionFileView::OnDraw (wxDC* dc)
3106 if (m_pBitmap && m_pBitmap->Ok())
3107 dc->DrawBitmap (*m_pBitmap, 0, 0, false);
3112 ProjectionFileView::setInitialClientSize ()
3114 if (m_pFrame && m_pCanvas) {
3115 wxSize bestSize = m_pCanvas->GetBestSize();
3117 m_pFrame->SetClientSize (bestSize);
3118 m_pFrame->Show (true);
3119 m_pFrame->SetFocus();
3124 ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3126 const Projections& rProj = GetDocument()->getProjections();
3127 const int nDet = rProj.nDet();
3128 const int nView = rProj.nView();
3129 if (nDet != 0 && nView != 0) {
3130 const DetectorArray& detarray = rProj.getDetectorArray(0);
3131 const DetectorValue* detval = detarray.detValues();
3132 double min = detval[0];
3133 double max = detval[0];
3134 for (int iy = 0; iy < nView; iy++) {
3135 const DetectorArray& detarray = rProj.getDetectorArray(iy);
3136 const DetectorValue* detval = detarray.detValues();
3137 for (int ix = 0; ix < nDet; ix++) {
3138 if (min > detval[ix])
3140 else if (max < detval[ix])
3145 unsigned char* imageData = new unsigned char [nDet * nView * 3];
3147 sys_error (ERR_SEVERE, "Unable to allocate memory for image display");
3150 double scale = (max - min) / 255;
3151 for (int iy2 = 0; iy2 < nView; iy2++) {
3152 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
3153 const DetectorValue* detval = detarray.detValues();
3154 for (int ix = 0; ix < nDet; ix++) {
3155 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
3156 intensity = clamp(intensity, 0, 255);
3157 int baseAddr = (iy2 * nDet + ix) * 3;
3158 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
3161 wxImage image (nDet, nView, imageData, true);
3166 m_pBitmap = new wxBitmap (image);
3170 m_pCanvas->SetScrollbars(20, 20, nDet/20, nView/20);
3171 m_pCanvas->SetBackgroundColour(*wxWHITE);
3174 m_pCanvas->Refresh();
3178 ProjectionFileView::OnClose (bool deleteWindow)
3180 //GetDocumentManager()->ActivateView (this, false, true);
3181 if (! GetDocument() || ! GetDocument()->Close())
3186 m_pCanvas->setView(NULL);
3189 wxString s(wxTheApp->GetAppName());
3191 m_pFrame->SetTitle(s);
3198 if (GetDocument() && GetDocument()->getBadFileOpen())
3199 ::wxYield(); // wxWindows bug workaround
3208 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
3209 : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v)
3213 PlotFileCanvas::~PlotFileCanvas ()
3218 PlotFileCanvas::GetBestSize() const
3220 return wxSize (500, 300);
3225 PlotFileCanvas::OnDraw(wxDC& dc)
3228 m_pView->OnDraw(& dc);
3234 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
3236 BEGIN_EVENT_TABLE(PlotFileView, wxView)
3237 EVT_MENU(PLOTMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
3238 EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
3239 EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
3240 EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
3243 PlotFileView::PlotFileView()
3244 : wxView(), m_pFrame(0), m_pCanvas(0), m_pEZPlot(0), m_pFileMenu(0),
3245 m_bMinSpecified(false), m_bMaxSpecified(false)
3249 PlotFileView::~PlotFileView()
3254 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
3255 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
3259 PlotFileView::OnProperties (wxCommandEvent& event)
3261 const PlotFile& rPlot = GetDocument()->getPlotFile();
3262 std::ostringstream os;
3263 os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
3264 rPlot.printHeadersBrief (os);
3265 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<<\n";
3266 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
3267 dialogMsg.ShowModal();
3268 GetDocument()->Activate();
3273 PlotFileView::OnScaleAuto (wxCommandEvent& event)
3275 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3276 double min, max, mean, mode, median, stddev;
3277 rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
3278 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
3279 int iRetVal = dialogAutoScale.ShowModal();
3280 if (iRetVal == wxID_OK) {
3281 m_bMinSpecified = true;
3282 m_bMaxSpecified = true;
3284 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
3287 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
3288 OnUpdate (this, NULL);
3291 GetDocument()->Activate();
3295 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
3297 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3301 if (! m_bMinSpecified || ! m_bMaxSpecified) {
3302 if (! rPlotFile.getMinMax (1, min, max)) {
3303 *theApp->getLog() << "Error: unable to find Min/Max\n";
3308 if (m_bMinSpecified)
3310 if (m_bMaxSpecified)
3313 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Y-axis Minimum & Maximum", min, max);
3314 int retVal = dialogMinMax.ShowModal();
3315 if (retVal == wxID_OK) {
3316 m_bMinSpecified = true;
3317 m_bMaxSpecified = true;
3318 m_dMinPixel = dialogMinMax.getMinimum();
3319 m_dMaxPixel = dialogMinMax.getMaximum();
3320 OnUpdate (this, NULL);
3322 GetDocument()->Activate();
3326 PlotFileView::OnScaleFull (wxCommandEvent& event)
3328 if (m_bMinSpecified || m_bMaxSpecified) {
3329 m_bMinSpecified = false;
3330 m_bMaxSpecified = false;
3331 OnUpdate (this, NULL);
3333 GetDocument()->Activate();
3338 PlotFileView::CreateCanvas (wxFrame* parent)
3340 PlotFileCanvas* pCanvas;
3342 pCanvas = new PlotFileCanvas (this, parent, wxPoint(-1,-1), wxSize(-1,-1), 0);
3343 pCanvas->SetBackgroundColour(*wxWHITE);
3354 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
3357 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
3359 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
3361 theApp->setIconForFrame (subframe);
3363 m_pFileMenu = new wxMenu;
3365 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3366 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3367 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3368 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3369 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3370 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3372 m_pFileMenu->AppendSeparator();
3373 m_pFileMenu->Append(PLOTMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
3375 m_pFileMenu->AppendSeparator();
3376 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3377 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3378 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3379 m_pFileMenu->AppendSeparator();
3380 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3381 m_pFileMenu->AppendSeparator();
3382 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3383 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3384 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3385 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3387 wxMenu *view_menu = new wxMenu;
3388 view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...\tCtrl-E");
3389 view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
3390 view_menu->Append(PLOTMENU_VIEW_SCALE_FULL, "Display &Full Scale\tCtrl-U");
3392 wxMenu *help_menu = new wxMenu;
3393 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3394 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3395 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3396 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3398 wxMenuBar *menu_bar = new wxMenuBar;
3400 menu_bar->Append(m_pFileMenu, "&File");
3401 menu_bar->Append(view_menu, "&View");
3402 menu_bar->Append(help_menu, "&Help");
3404 subframe->SetMenuBar(menu_bar);
3405 subframe->Centre(wxBOTH);
3407 wxAcceleratorEntry accelEntries[4];
3408 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('E'), PLOTMENU_VIEW_SCALE_MINMAX);
3409 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('A'), PLOTMENU_VIEW_SCALE_AUTO);
3410 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('U'), PLOTMENU_VIEW_SCALE_FULL);
3411 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), PLOTMENU_FILE_PROPERTIES);
3412 wxAcceleratorTable accelTable (4, accelEntries);
3413 subframe->SetAcceleratorTable (accelTable);
3420 PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
3422 m_bMinSpecified = false;
3423 m_bMaxSpecified = false;
3424 m_dAutoScaleFactor = 1.;
3426 m_pFrame = CreateChildFrame(doc, this);
3428 m_pCanvas = CreateCanvas (m_pFrame);
3429 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
3430 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
3431 m_pFrame->SetTitle ("Plot File");
3433 m_pFrame->Show(true);
3440 PlotFileView::setInitialClientSize ()
3442 if (m_pFrame && m_pCanvas) {
3443 wxSize bestSize = m_pCanvas->GetBestSize();
3445 m_pFrame->SetClientSize (bestSize);
3446 m_pFrame->Show (true);
3447 m_pFrame->SetFocus();
3453 PlotFileView::OnDraw (wxDC* dc)
3455 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3456 const int iNColumns = rPlotFile.getNumColumns();
3457 const int iNRecords = rPlotFile.getNumRecords();
3459 if (iNColumns > 0 && iNRecords > 0) {
3461 m_pCanvas->GetClientSize (&xsize, &ysize);
3462 SGPDriver driver (dc, xsize, ysize);
3465 m_pEZPlot->plot (&sgp);
3471 PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3473 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3474 const int iNColumns = rPlotFile.getNumColumns();
3475 const int iNRecords = rPlotFile.getNumRecords();
3476 const bool bScatterPlot = rPlotFile.getIsScatterPlot();
3478 if (iNColumns > 0 && iNRecords > 0) {
3481 m_pEZPlot = new EZPlot;
3483 for (unsigned int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)
3484 m_pEZPlot->ezset (rPlotFile.getEzsetCommand (iEzset));
3486 if (m_bMinSpecified) {
3487 std::ostringstream os;
3488 os << "ymin " << m_dMinPixel;
3489 m_pEZPlot->ezset (os.str());
3492 if (m_bMaxSpecified) {
3493 std::ostringstream os;
3494 os << "ymax " << m_dMaxPixel;
3495 m_pEZPlot->ezset (os.str());
3498 m_pEZPlot->ezset("box");
3499 m_pEZPlot->ezset("grid");
3501 double* pdX = new double [iNRecords];
3502 double* pdY = new double [iNRecords];
3503 if (! bScatterPlot) {
3504 rPlotFile.getColumn (0, pdX);
3506 for (int iCol = 1; iCol < iNColumns; iCol++) {
3507 rPlotFile.getColumn (iCol, pdY);
3508 m_pEZPlot->addCurve (pdX, pdY, iNRecords);
3511 rPlotFile.getColumn (0, pdX);
3512 rPlotFile.getColumn (1, pdY);
3513 m_pEZPlot->addCurve (pdX, pdY, iNRecords);
3520 m_pCanvas->Refresh();
3524 PlotFileView::OnClose (bool deleteWindow)
3526 if (! GetDocument() || ! GetDocument()->Close())
3531 m_pCanvas->setView (NULL);
3534 wxString s(wxTheApp->GetAppName());
3536 m_pFrame->SetTitle(s);
3542 if (GetDocument() && GetDocument()->getBadFileOpen())
3543 ::wxYield(); // wxWindows bug workaround
3550 ////////////////////////////////////////////////////////////////
3553 IMPLEMENT_DYNAMIC_CLASS(TextFileView, wxView)
3555 TextFileView::~TextFileView()
3557 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
3558 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
3561 bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
3563 m_pFrame = CreateChildFrame(doc, this);
3564 SetFrame (m_pFrame);
3567 m_pFrame->GetClientSize(&width, &height);
3568 m_pFrame->SetTitle("TextFile");
3569 m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(-1,-1), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
3570 m_pFrame->SetTitle("Log");
3572 m_pFrame->Show (true);
3578 // Handled by wxTextWindow
3579 void TextFileView::OnDraw(wxDC *WXUNUSED(dc) )
3583 void TextFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3588 TextFileView::OnClose (bool deleteWindow)
3590 if (! theApp->getMainFrame()->getShuttingDown())
3594 //GetDocumentManager()->ActivateView (this, false, true);
3595 if (! GetDocument() || ! GetDocument()->Close())
3602 if (GetDocument() && GetDocument()->getBadFileOpen())
3603 ::wxYield(); // wxWindows bug workaround
3614 TextFileView::CreateChildFrame (wxDocument *doc, wxView *view)
3617 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE, "Log");
3619 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE, "Log");
3621 theApp->setIconForFrame (subframe);
3623 m_pFileMenu = new wxMenu;
3625 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3626 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3627 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3628 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3629 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3630 // m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3632 m_pFileMenu->AppendSeparator();
3633 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3634 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3635 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3636 m_pFileMenu->AppendSeparator();
3637 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3638 m_pFileMenu->AppendSeparator();
3639 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3640 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3641 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3642 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3644 wxMenu *help_menu = new wxMenu;
3645 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3646 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3647 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3648 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3650 wxMenuBar *menu_bar = new wxMenuBar;
3652 menu_bar->Append(m_pFileMenu, "&File");
3653 menu_bar->Append(help_menu, "&Help");
3655 subframe->SetMenuBar(menu_bar);
3656 subframe->Centre(wxBOTH);
3662 // Define a constructor for my text subwindow
3663 TextFileCanvas::TextFileCanvas (TextFileView* v, wxFrame* frame, const wxPoint& pos, const wxSize& size, long style)
3664 : wxTextCtrl (frame, -1, "", pos, size, style), m_pView(v)
3668 TextFileCanvas::~TextFileCanvas ()
3674 TextFileCanvas::GetBestSize() const
3677 theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
3678 xSize = maxValue<int> (xSize, ySize);
3680 ySize = xSize = (xSize / 4);
3684 return wxSize (xSize, ySize);