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.149 2002/04/30 18:13:40 kevin Exp $
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
28 #include "wx/wxprec.h"
33 #if !wxUSE_DOC_VIEW_ARCHITECTURE
34 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
38 #include "wx/progdlg.h"
39 #include "wx/clipbrd.h"
46 #include "dlgprojections.h"
47 #include "dlgreconstruct.h"
48 #include "backprojectors.h"
49 #include "reconstruct.h"
51 #include "threadproj.h"
52 #include "threadrecon.h"
53 #include "threadraster.h"
55 #if defined(MSVC) || HAVE_SSTREAM
58 #include <sstream_subst>
64 BEGIN_EVENT_TABLE(ImageFileCanvas, wxScrolledWindow)
65 EVT_MOUSE_EVENTS(ImageFileCanvas::OnMouseEvent)
66 EVT_CHAR(ImageFileCanvas::OnChar)
70 ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
71 : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v), m_xCursor(-1), m_yCursor(-1)
75 ImageFileCanvas::~ImageFileCanvas()
81 ImageFileCanvas::OnDraw(wxDC& dc)
84 m_pView->OnDraw(& dc);
88 ImageFileCanvas::DrawRubberBandCursor (wxDC& dc, int x, int y)
90 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
95 dc.SetLogicalFunction (wxINVERT);
96 dc.SetPen (*wxGREEN_PEN);
97 dc.DrawLine (0, yPt, nx, yPt);
98 dc.DrawLine (x, 0, x, ny);
99 dc.SetLogicalFunction (wxCOPY);
103 ImageFileCanvas::GetCurrentCursor (int& x, int& y)
108 if (m_xCursor >= 0 && m_yCursor >= 0)
115 ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
124 wxPoint pt(event.GetLogicalPosition(dc));
126 const ImageFileDocument* pIFDoc = m_pView->GetDocument();
129 const ImageFile& rIF = pIFDoc->getImageFile();
130 ImageFileArrayConst v = rIF.getArray();
133 const int yPt = ny - 1 - pt.y;
134 if (event.RightIsDown()) {
135 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
136 std::ostringstream os;
137 os << "Image value (" << pt.x << "," << yPt << ") = " << v[pt.x][yPt];
138 if (rIF.isComplex()) {
139 double dImag = rIF.getImaginaryArray()[pt.x][yPt];
141 os << " - " << -dImag;
143 os << " + " << dImag;
147 *theApp->getLog() << os.str().c_str();
149 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
151 else if (event.LeftIsDown() || event.LeftUp() || event.RightUp()) {
152 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
153 if (m_xCursor >= 0 && m_yCursor >= 0) {
154 DrawRubberBandCursor (dc, m_xCursor, m_yCursor);
156 DrawRubberBandCursor (dc, pt.x, yPt);
159 wxMenu* pMenu = m_pView->getMenuAnalyze();
160 if (pMenu && ! pMenu->IsEnabled(IFMENU_PLOT_ROW)) {
161 pMenu->Enable (IFMENU_PLOT_ROW, true);
162 pMenu->Enable (IFMENU_PLOT_COL, true);
163 pMenu->Enable (IFMENU_COMPARE_ROW, true);
164 pMenu->Enable (IFMENU_COMPARE_COL, true);
165 pMenu->Enable (IFMENU_PLOT_FFT_ROW, true);
166 pMenu->Enable (IFMENU_PLOT_FFT_COL, true);
169 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
171 if (event.LeftUp()) {
172 std::ostringstream os;
173 os << "Selected column " << pt.x << " , row " << yPt << "\n";
174 *theApp->getLog() << os.str().c_str();
179 ImageFileCanvas::OnChar (wxKeyEvent& event)
181 if (event.GetKeyCode() == WXK_ESCAPE) {
185 m_pView->OnUpdate (NULL);
187 wxScrolledWindow::OnChar (event);
191 ImageFileCanvas::GetBestSize() const
196 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
197 return wxSize (rIF.nx(), rIF.ny());
203 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
205 BEGIN_EVENT_TABLE(ImageFileView, wxView)
206 EVT_MENU(IFMENU_FILE_EXPORT, ImageFileView::OnExport)
207 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
208 EVT_MENU(IFMENU_EDIT_COPY, ImageFileView::OnEditCopy)
209 EVT_MENU(IFMENU_EDIT_CUT, ImageFileView::OnEditCut)
210 EVT_MENU(IFMENU_EDIT_PASTE, ImageFileView::OnEditPaste)
211 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
212 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
213 EVT_MENU(IFMENU_VIEW_SCALE_FULL, ImageFileView::OnScaleFull)
214 EVT_MENU(IFMENU_COMPARE_IMAGES, ImageFileView::OnCompare)
215 EVT_MENU(IFMENU_COMPARE_ROW, ImageFileView::OnCompareRow)
216 EVT_MENU(IFMENU_COMPARE_COL, ImageFileView::OnCompareCol)
217 EVT_MENU(IFMENU_FILTER_INVERTVALUES, ImageFileView::OnInvertValues)
218 EVT_MENU(IFMENU_FILTER_SQUARE, ImageFileView::OnSquare)
219 EVT_MENU(IFMENU_FILTER_SQRT, ImageFileView::OnSquareRoot)
220 EVT_MENU(IFMENU_FILTER_LOG, ImageFileView::OnLog)
221 EVT_MENU(IFMENU_FILTER_EXP, ImageFileView::OnExp)
222 EVT_MENU(IFMENU_FILTER_FOURIER, ImageFileView::OnFourier)
223 EVT_MENU(IFMENU_FILTER_INVERSE_FOURIER, ImageFileView::OnInverseFourier)
224 EVT_MENU(IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, ImageFileView::OnShuffleFourierToNaturalOrder)
225 EVT_MENU(IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, ImageFileView::OnShuffleNaturalToFourierOrder)
226 EVT_MENU(IFMENU_IMAGE_ADD, ImageFileView::OnAdd)
227 EVT_MENU(IFMENU_IMAGE_SUBTRACT, ImageFileView::OnSubtract)
228 EVT_MENU(IFMENU_IMAGE_MULTIPLY, ImageFileView::OnMultiply)
229 EVT_MENU(IFMENU_IMAGE_DIVIDE, ImageFileView::OnDivide)
230 EVT_MENU(IFMENU_IMAGE_SCALESIZE, ImageFileView::OnScaleSize)
232 EVT_MENU(IFMENU_IMAGE_CONVERT3D, ImageFileView::OnConvert3d)
235 EVT_MENU(IFMENU_FILTER_FFT, ImageFileView::OnFFT)
236 EVT_MENU(IFMENU_FILTER_IFFT, ImageFileView::OnIFFT)
237 EVT_MENU(IFMENU_FILTER_FFT_ROWS, ImageFileView::OnFFTRows)
238 EVT_MENU(IFMENU_FILTER_IFFT_ROWS, ImageFileView::OnIFFTRows)
239 EVT_MENU(IFMENU_FILTER_FFT_COLS, ImageFileView::OnFFTCols)
240 EVT_MENU(IFMENU_FILTER_IFFT_COLS, ImageFileView::OnIFFTCols)
242 EVT_MENU(IFMENU_FILTER_MAGNITUDE, ImageFileView::OnMagnitude)
243 EVT_MENU(IFMENU_FILTER_PHASE, ImageFileView::OnPhase)
244 EVT_MENU(IFMENU_FILTER_REAL, ImageFileView::OnReal)
245 EVT_MENU(IFMENU_FILTER_IMAGINARY, ImageFileView::OnImaginary)
246 EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)
247 EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol)
249 EVT_MENU(IFMENU_PLOT_FFT_ROW, ImageFileView::OnPlotFFTRow)
250 EVT_MENU(IFMENU_PLOT_FFT_COL, ImageFileView::OnPlotFFTCol)
252 EVT_MENU(IFMENU_PLOT_HISTOGRAM, ImageFileView::OnPlotHistogram)
255 ImageFileView::ImageFileView()
256 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0), m_pFilterMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
258 m_iDefaultExportFormatID = ImageFile::EXPORT_FORMAT_PNG;
261 ImageFileView::~ImageFileView()
263 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
264 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
269 ImageFileView::OnProperties (wxCommandEvent& event)
271 const ImageFile& rIF = GetDocument()->getImageFile();
272 if (rIF.nx() == 0 || rIF.ny() == 0)
273 *theApp->getLog() << "Properties: empty imagefile\n";
275 const std::string rFilename = m_pFrame->GetTitle().c_str();
276 std::ostringstream os;
277 double min, max, mean, mode, median, stddev;
278 rIF.statistics (rIF.getArray(), min, max, mean, mode, median, stddev);
279 os << "Filename: " << rFilename << "\n";
280 os << "Size: (" << rIF.nx() << "," << rIF.ny() << ")\n";
286 os << "Minimum: "<<min<<"\nMaximum: "<<max<<"\nMean: "<<mean<<"\nMedian: "<<median<<"\nMode: "<<mode<<"\nStandard Deviation: "<<stddev << "\n";
287 if (rIF.isComplex()) {
288 rIF.statistics (rIF.getImaginaryArray(), min, max, mean, mode, median, stddev);
289 os << "Imaginary: min: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
291 if (rIF.nLabels() > 0) {
292 rIF.printLabelsBrief (os);
294 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
295 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
296 dialogMsg.ShowModal();
298 GetDocument()->Activate();
302 ImageFileView::OnScaleAuto (wxCommandEvent& event)
304 const ImageFile& rIF = GetDocument()->getImageFile();
305 double min, max, mean, mode, median, stddev;
306 rIF.statistics(min, max, mean, mode, median, stddev);
307 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
308 int iRetVal = dialogAutoScale.ShowModal();
309 if (iRetVal == wxID_OK) {
310 m_bMinSpecified = true;
311 m_bMaxSpecified = true;
313 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
316 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
317 GetDocument()->UpdateAllViews (this);
320 GetDocument()->Activate();
324 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
326 const ImageFile& rIF = GetDocument()->getImageFile();
328 if (! m_bMinSpecified && ! m_bMaxSpecified)
329 rIF.getMinMax (min, max);
336 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Image Minimum & Maximum", min, max);
337 int retVal = dialogMinMax.ShowModal();
338 if (retVal == wxID_OK) {
339 m_bMinSpecified = true;
340 m_bMaxSpecified = true;
341 m_dMinPixel = dialogMinMax.getMinimum();
342 m_dMaxPixel = dialogMinMax.getMaximum();
343 GetDocument()->UpdateAllViews (this);
345 GetDocument()->Activate();
349 ImageFileView::OnScaleFull (wxCommandEvent& event)
351 if (m_bMinSpecified || m_bMaxSpecified) {
352 m_bMinSpecified = false;
353 m_bMaxSpecified = false;
354 GetDocument()->UpdateAllViews (this);
356 GetDocument()->Activate();
360 ImageFileView::OnCompare (wxCommandEvent& event)
362 std::vector<ImageFileDocument*> vecIF;
363 theApp->getCompatibleImages (GetDocument(), vecIF);
365 if (vecIF.size() == 0) {
366 wxMessageBox("There are no compatible image files open for comparision", "No comparison images");
368 DialogGetComparisonImage dialogGetCompare(getFrameForChild(), "Get Comparison Image", vecIF, true);
370 if (dialogGetCompare.ShowModal() == wxID_OK) {
371 const ImageFile& rIF = GetDocument()->getImageFile();
372 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
373 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
374 std::ostringstream os;
375 double min, max, mean, mode, median, stddev;
376 rIF.statistics (min, max, mean, mode, median, stddev);
377 os << GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
378 rCompareIF.statistics (min, max, mean, mode, median, stddev);
379 os << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
381 rIF.comparativeStatistics (rCompareIF, d, r, e);
382 os << "Comparative Statistics: d=" << d << ", r=" << r << ", e=" << e << "\n";
383 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
384 if (dialogGetCompare.getMakeDifferenceImage()) {
385 ImageFile* pDifferenceImage = new ImageFile;
387 pDifferenceImage->setArraySize (rIF.nx(), rIF.ny());
388 if (! rIF.subtractImages (rCompareIF, *pDifferenceImage)) {
389 *theApp->getLog() << "Unable to subtract images\n";
390 delete pDifferenceImage;
393 ImageFileDocument* pDifferenceDoc = theApp->newImageDoc();
394 if (! pDifferenceDoc) {
395 sys_error (ERR_SEVERE, "Unable to create image file");
398 pDifferenceDoc->setImageFile (pDifferenceImage);
400 wxString s = GetFrame()->GetTitle() + ": ";
401 pDifferenceImage->labelsCopy (rIF, s.c_str());
402 s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
403 pDifferenceImage->labelsCopy (rCompareIF, s.c_str());
404 std::ostringstream osLabel;
405 osLabel << "Compare image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str()
406 << " and " << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": "
408 pDifferenceImage->labelAdd (os.str().c_str());
409 if (theApp->getAskDeleteNewDocs())
410 pDifferenceDoc->Modify (true);
411 pDifferenceDoc->UpdateAllViews (this);
412 pDifferenceDoc->getView()->OnUpdate (this, NULL);
413 pDifferenceDoc->getView()->getFrame()->Show(true);
414 pDifferenceDoc->Activate();
416 wxMessageBox(os.str().c_str(), "Image Comparison");
422 ImageFileView::OnInvertValues (wxCommandEvent& event)
424 ImageFile& rIF = GetDocument()->getImageFile();
425 rIF.invertPixelValues (rIF);
426 rIF.labelAdd ("Invert Pixel Values");
427 if (theApp->getAskDeleteNewDocs())
428 GetDocument()->Modify (true);
429 GetDocument()->UpdateAllViews (this);
430 GetDocument()->Activate();
434 ImageFileView::OnSquare (wxCommandEvent& event)
436 ImageFile& rIF = GetDocument()->getImageFile();
438 rIF.labelAdd ("Square Pixel Values");
439 if (theApp->getAskDeleteNewDocs())
440 GetDocument()->Modify (true);
441 GetDocument()->UpdateAllViews (this);
442 GetDocument()->Activate();
446 ImageFileView::OnSquareRoot (wxCommandEvent& event)
448 ImageFile& rIF = GetDocument()->getImageFile();
450 rIF.labelAdd ("Square-root Pixel Values");
451 if (theApp->getAskDeleteNewDocs())
452 GetDocument()->Modify (true);
453 GetDocument()->UpdateAllViews (this);
454 GetDocument()->Activate();
458 ImageFileView::OnLog (wxCommandEvent& event)
460 ImageFile& rIF = GetDocument()->getImageFile();
462 rIF.labelAdd ("Logrithm base-e Pixel Values");
463 if (theApp->getAskDeleteNewDocs())
464 GetDocument()->Modify (true);
465 GetDocument()->UpdateAllViews (this);
466 GetDocument()->Activate();
470 ImageFileView::OnExp (wxCommandEvent& event)
472 ImageFile& rIF = GetDocument()->getImageFile();
474 rIF.labelAdd ("Exponent base-e Pixel Values");
475 if (theApp->getAskDeleteNewDocs())
476 GetDocument()->Modify (true);
477 GetDocument()->UpdateAllViews (this);
478 GetDocument()->Activate();
482 ImageFileView::OnAdd (wxCommandEvent& event)
484 std::vector<ImageFileDocument*> vecIF;
485 theApp->getCompatibleImages (GetDocument(), vecIF);
487 if (vecIF.size() == 0) {
488 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
490 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Add", vecIF, false);
492 if (dialogGetCompare.ShowModal() == wxID_OK) {
493 ImageFile& rIF = GetDocument()->getImageFile();
494 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
495 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
496 ImageFileDocument* pNewDoc = theApp->newImageDoc();
498 sys_error (ERR_SEVERE, "Unable to create image file");
501 ImageFile& newImage = pNewDoc->getImageFile();
502 newImage.setArraySize (rIF.nx(), rIF.ny());
503 rIF.addImages (rRHSIF, newImage);
504 std::ostringstream os;
505 os << "Add image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
506 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
507 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
508 newImage.labelsCopy (rIF, s.c_str());
509 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
510 newImage.labelsCopy (rRHSIF, s.c_str());
511 newImage.labelAdd (os.str().c_str());
512 *theApp->getLog() << os.str().c_str() << "\n";
513 if (theApp->getAskDeleteNewDocs())
514 pNewDoc->Modify (true);
515 pNewDoc->UpdateAllViews (this);
516 pNewDoc->getView()->getFrame()->Show(true);
523 ImageFileView::OnSubtract (wxCommandEvent& event)
525 std::vector<ImageFileDocument*> vecIF;
526 theApp->getCompatibleImages (GetDocument(), vecIF);
528 if (vecIF.size() == 0) {
529 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
531 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Subtract", vecIF, false);
533 if (dialogGetCompare.ShowModal() == wxID_OK) {
534 ImageFile& rIF = GetDocument()->getImageFile();
535 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
536 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
537 ImageFileDocument* pNewDoc = theApp->newImageDoc();
539 sys_error (ERR_SEVERE, "Unable to create image file");
542 ImageFile& newImage = pNewDoc->getImageFile();
543 newImage.setArraySize (rIF.nx(), rIF.ny());
544 rIF.subtractImages (rRHSIF, newImage);
545 std::ostringstream os;
546 os << "Subtract image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
547 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
548 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
549 newImage.labelsCopy (rIF, s.c_str());
550 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
551 newImage.labelsCopy (rRHSIF, s.c_str());
552 newImage.labelAdd (os.str().c_str());
553 *theApp->getLog() << os.str().c_str() << "\n";
554 if (theApp->getAskDeleteNewDocs())
555 pNewDoc->Modify (true);
556 pNewDoc->UpdateAllViews (this);
557 pNewDoc->getView()->getFrame()->Show(true);
564 ImageFileView::OnMultiply (wxCommandEvent& event)
566 std::vector<ImageFileDocument*> vecIF;
567 theApp->getCompatibleImages (GetDocument(), vecIF);
569 if (vecIF.size() == 0) {
570 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
572 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Multiply", vecIF, false);
574 if (dialogGetCompare.ShowModal() == wxID_OK) {
575 ImageFile& rIF = GetDocument()->getImageFile();
576 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
577 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
578 ImageFileDocument* pNewDoc = theApp->newImageDoc();
580 sys_error (ERR_SEVERE, "Unable to create image file");
583 ImageFile& newImage = pNewDoc->getImageFile();
584 newImage.setArraySize (rIF.nx(), rIF.ny());
585 rIF.multiplyImages (rRHSIF, newImage);
586 std::ostringstream os;
587 os << "Multiply image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
588 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
589 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
590 newImage.labelsCopy (rIF, s.c_str());
591 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
592 newImage.labelsCopy (rRHSIF, s.c_str());
593 newImage.labelAdd (os.str().c_str());
594 *theApp->getLog() << os.str().c_str() << "\n";
595 if (theApp->getAskDeleteNewDocs())
596 pNewDoc->Modify (true);
597 pNewDoc->UpdateAllViews (this);
598 pNewDoc->getView()->getFrame()->Show(true);
605 ImageFileView::OnDivide (wxCommandEvent& event)
607 std::vector<ImageFileDocument*> vecIF;
608 theApp->getCompatibleImages (GetDocument(), vecIF);
610 if (vecIF.size() == 0) {
611 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
613 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Divide", vecIF, false);
615 if (dialogGetCompare.ShowModal() == wxID_OK) {
616 ImageFile& rIF = GetDocument()->getImageFile();
617 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
618 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
619 ImageFileDocument* pNewDoc = theApp->newImageDoc();
621 sys_error (ERR_SEVERE, "Unable to create image file");
624 ImageFile& newImage = pNewDoc->getImageFile();
625 newImage.setArraySize (rIF.nx(), rIF.ny());
626 rIF.divideImages (rRHSIF, newImage);
627 std::ostringstream os;
628 os << "Divide image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " by "
629 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
630 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
631 newImage.labelsCopy (rIF, s.c_str());
632 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
633 newImage.labelsCopy (rRHSIF, s.c_str());
634 newImage.labelAdd (os.str().c_str());
635 *theApp->getLog() << os.str().c_str() << "\n";
636 if (theApp->getAskDeleteNewDocs())
637 pNewDoc->Modify (true);
638 pNewDoc->UpdateAllViews (this);
639 pNewDoc->getView()->getFrame()->Show(true);
648 ImageFileView::OnFFT (wxCommandEvent& event)
650 ImageFile& rIF = GetDocument()->getImageFile();
652 rIF.labelAdd ("FFT Image");
653 m_bMinSpecified = false;
654 m_bMaxSpecified = false;
655 if (theApp->getAskDeleteNewDocs())
656 GetDocument()->Modify (true);
657 GetDocument()->UpdateAllViews (this);
658 GetDocument()->Activate();
662 ImageFileView::OnIFFT (wxCommandEvent& event)
664 ImageFile& rIF = GetDocument()->getImageFile();
666 rIF.labelAdd ("IFFT Image");
667 m_bMinSpecified = false;
668 m_bMaxSpecified = false;
669 if (theApp->getAskDeleteNewDocs())
670 GetDocument()->Modify (true);
671 GetDocument()->UpdateAllViews (this);
672 GetDocument()->Activate();
676 ImageFileView::OnFFTRows (wxCommandEvent& event)
678 ImageFile& rIF = GetDocument()->getImageFile();
680 rIF.labelAdd ("FFT Rows");
681 m_bMinSpecified = false;
682 m_bMaxSpecified = false;
683 if (theApp->getAskDeleteNewDocs())
684 GetDocument()->Modify (true);
685 GetDocument()->UpdateAllViews (this);
686 GetDocument()->Activate();
690 ImageFileView::OnIFFTRows (wxCommandEvent& event)
692 ImageFile& rIF = GetDocument()->getImageFile();
694 rIF.labelAdd ("IFFT Rows");
695 m_bMinSpecified = false;
696 m_bMaxSpecified = false;
697 if (theApp->getAskDeleteNewDocs())
698 GetDocument()->Modify (true);
699 GetDocument()->UpdateAllViews (this);
700 GetDocument()->Activate();
704 ImageFileView::OnFFTCols (wxCommandEvent& event)
706 ImageFile& rIF = GetDocument()->getImageFile();
708 rIF.labelAdd ("FFT Columns");
709 m_bMinSpecified = false;
710 m_bMaxSpecified = false;
711 if (theApp->getAskDeleteNewDocs())
712 GetDocument()->Modify (true);
713 GetDocument()->UpdateAllViews (this);
714 GetDocument()->Activate();
718 ImageFileView::OnIFFTCols (wxCommandEvent& event)
720 ImageFile& rIF = GetDocument()->getImageFile();
722 rIF.labelAdd ("IFFT Columns");
723 m_bMinSpecified = false;
724 m_bMaxSpecified = false;
725 if (theApp->getAskDeleteNewDocs())
726 GetDocument()->Modify (true);
727 GetDocument()->UpdateAllViews (this);
728 GetDocument()->Activate();
733 ImageFileView::OnFourier (wxCommandEvent& event)
735 ImageFile& rIF = GetDocument()->getImageFile();
736 wxProgressDialog dlgProgress (wxString("Fourier"), wxString("Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
738 rIF.labelAdd ("Fourier Image");
739 m_bMinSpecified = false;
740 m_bMaxSpecified = false;
741 if (theApp->getAskDeleteNewDocs())
742 GetDocument()->Modify (true);
743 GetDocument()->UpdateAllViews (this);
744 GetDocument()->Activate();
748 ImageFileView::OnInverseFourier (wxCommandEvent& event)
750 ImageFile& rIF = GetDocument()->getImageFile();
751 wxProgressDialog dlgProgress (wxString("Inverse Fourier"), wxString("Inverse Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
752 rIF.inverseFourier (rIF);
753 rIF.labelAdd ("Inverse 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::OnShuffleNaturalToFourierOrder (wxCommandEvent& event)
765 ImageFile& rIF = GetDocument()->getImageFile();
766 Fourier::shuffleNaturalToFourierOrder (rIF);
767 rIF.labelAdd ("Shuffle Natural To Fourier Order");
768 m_bMinSpecified = false;
769 m_bMaxSpecified = false;
770 if (theApp->getAskDeleteNewDocs())
771 GetDocument()->Modify (true);
772 GetDocument()->UpdateAllViews (this);
773 GetDocument()->Activate();
777 ImageFileView::OnShuffleFourierToNaturalOrder (wxCommandEvent& event)
779 ImageFile& rIF = GetDocument()->getImageFile();
780 Fourier::shuffleFourierToNaturalOrder (rIF);
781 rIF.labelAdd ("Shuffle Fourier To Natural Order");
782 m_bMinSpecified = false;
783 m_bMaxSpecified = false;
784 if (theApp->getAskDeleteNewDocs())
785 GetDocument()->Modify (true);
786 GetDocument()->UpdateAllViews (this);
787 GetDocument()->Activate();
791 ImageFileView::OnMagnitude (wxCommandEvent& event)
793 ImageFile& rIF = GetDocument()->getImageFile();
795 rIF.labelAdd ("Magnitude");
796 m_bMinSpecified = false;
797 m_bMaxSpecified = false;
798 if (theApp->getAskDeleteNewDocs())
799 GetDocument()->Modify (true);
800 GetDocument()->UpdateAllViews (this);
801 GetDocument()->Activate();
805 ImageFileView::OnPhase (wxCommandEvent& event)
807 ImageFile& rIF = GetDocument()->getImageFile();
808 if (rIF.isComplex()) {
810 rIF.labelAdd ("Phase of complex-image");
811 m_bMinSpecified = false;
812 m_bMaxSpecified = false;
813 if (theApp->getAskDeleteNewDocs())
814 GetDocument()->Modify (true);
815 GetDocument()->UpdateAllViews (this);
817 GetDocument()->Activate();
821 ImageFileView::OnReal (wxCommandEvent& event)
823 ImageFile& rIF = GetDocument()->getImageFile();
824 if (rIF.isComplex()) {
826 rIF.labelAdd ("Real component of complex-image");
827 m_bMinSpecified = false;
828 m_bMaxSpecified = false;
829 if (theApp->getAskDeleteNewDocs())
830 GetDocument()->Modify (true);
831 GetDocument()->UpdateAllViews (this);
833 GetDocument()->Activate();
837 ImageFileView::OnImaginary (wxCommandEvent& event)
839 ImageFile& rIF = GetDocument()->getImageFile();
840 if (rIF.isComplex()) {
842 rIF.labelAdd ("Imaginary component of complex-image");
843 m_bMinSpecified = false;
844 m_bMaxSpecified = false;
845 if (theApp->getAskDeleteNewDocs())
846 GetDocument()->Modify (true);
847 GetDocument()->UpdateAllViews (this);
849 GetDocument()->Activate();
854 ImageFileView::CreateCanvas (wxFrame* parent)
856 ImageFileCanvas* pCanvas;
858 parent->GetClientSize(&width, &height);
860 pCanvas = new ImageFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
862 pCanvas->SetScrollbars(20, 20, 50, 50);
863 pCanvas->SetBackgroundColour(*wxWHITE);
874 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
877 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
879 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
881 theApp->setIconForFrame (subframe);
883 m_pFileMenu = new wxMenu;
884 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
885 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
886 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
887 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
888 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
889 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
890 m_pFileMenu->Append(wxID_REVERT, "Re&vert");
892 m_pFileMenu->AppendSeparator();
893 m_pFileMenu->Append(IFMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
894 m_pFileMenu->Append(IFMENU_FILE_EXPORT, "Expor&t...");
896 m_pFileMenu->AppendSeparator();
897 m_pFileMenu->Append(wxID_PRINT, "&Print...");
898 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
899 m_pFileMenu->Append(wxID_PREVIEW, "Print Preview");
900 m_pFileMenu->AppendSeparator();
901 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
903 m_pFileMenu->AppendSeparator();
904 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
905 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
907 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
908 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
910 wxMenu* edit_menu = new wxMenu;
911 edit_menu->Append(IFMENU_EDIT_COPY, "Copy\tCtrl-C");
912 edit_menu->Append(IFMENU_EDIT_CUT, "Cut\tCtrl-X");
913 edit_menu->Append(IFMENU_EDIT_PASTE, "Paste\tCtrl-V");
915 wxMenu *view_menu = new wxMenu;
916 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale S&et...\tCtrl-E");
917 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
918 view_menu->Append(IFMENU_VIEW_SCALE_FULL, "Display F&ull Scale\tCtrl-U");
920 m_pFilterMenu = new wxMenu;
921 m_pFilterMenu->Append (IFMENU_FILTER_INVERTVALUES, "In&vert Values");
922 m_pFilterMenu->Append (IFMENU_FILTER_SQUARE, "&Square");
923 m_pFilterMenu->Append (IFMENU_FILTER_SQRT, "Square &Root");
924 m_pFilterMenu->Append (IFMENU_FILTER_LOG, "&Log");
925 m_pFilterMenu->Append (IFMENU_FILTER_EXP, "E&xp");
926 m_pFilterMenu->AppendSeparator();
928 m_pFilterMenu->Append (IFMENU_FILTER_FFT, "2-D &FFT\tCtrl-2");
929 m_pFilterMenu->Append (IFMENU_FILTER_IFFT, "2-D &IFFT\tAlt-2");
930 m_pFilterMenu->Append (IFMENU_FILTER_FFT_ROWS, "FFT Rows");
931 m_pFilterMenu->Append (IFMENU_FILTER_IFFT_ROWS, "IFFT Rows");
932 m_pFilterMenu->Append (IFMENU_FILTER_FFT_COLS, "FFT Columns");
933 m_pFilterMenu->Append (IFMENU_FILTER_IFFT_COLS, "IFFT Columns");
934 m_pFilterMenu->Append (IFMENU_FILTER_FOURIER, "2-D F&ourier");
935 m_pFilterMenu->Append (IFMENU_FILTER_INVERSE_FOURIER, "2-D Inverse Fo&urier");
937 m_pFilterMenu->Append (IFMENU_FILTER_FOURIER, "&Fourier");
938 m_pFilterMenu->Append (IFMENU_FILTER_INVERSE_FOURIER, "&Inverse Fourier");
940 m_pFilterMenu->Append (IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, "Shuffl&e Fourier to Natural Order");
941 m_pFilterMenu->Append (IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, "Shuffle &Natural to Fourier Order");
942 m_pFilterMenu->AppendSeparator();
943 m_pFilterMenu->Append (IFMENU_FILTER_MAGNITUDE, "&Magnitude");
944 m_pFilterMenu->Append (IFMENU_FILTER_PHASE, "&Phase");
945 m_pFilterMenu->Append (IFMENU_FILTER_REAL, "Re&al");
946 m_pFilterMenu->Append (IFMENU_FILTER_IMAGINARY, "Ima&ginary");
948 wxMenu* image_menu = new wxMenu;
949 image_menu->Append (IFMENU_IMAGE_ADD, "&Add...");
950 image_menu->Append (IFMENU_IMAGE_SUBTRACT, "&Subtract...");
951 image_menu->Append (IFMENU_IMAGE_MULTIPLY, "&Multiply...");
952 image_menu->Append (IFMENU_IMAGE_DIVIDE, "&Divide...");
953 image_menu->AppendSeparator();
954 image_menu->Append (IFMENU_IMAGE_SCALESIZE, "S&cale Size...");
956 image_menu->Append (IFMENU_IMAGE_CONVERT3D, "Convert &3-D\tCtrl-3");
959 m_pMenuAnalyze = new wxMenu;
960 m_pMenuAnalyze->Append (IFMENU_PLOT_ROW, "Plot &Row");
961 m_pMenuAnalyze->Append (IFMENU_PLOT_COL, "Plot &Column");
962 m_pMenuAnalyze->Append (IFMENU_PLOT_HISTOGRAM, "Plot &Histogram");
963 m_pMenuAnalyze->AppendSeparator();
964 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_ROW, "P&lot FFT Row");
965 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_COL, "Plo&t FFT Column");
966 m_pMenuAnalyze->AppendSeparator();
967 m_pMenuAnalyze->Append (IFMENU_COMPARE_IMAGES, "Compare &Images...");
968 m_pMenuAnalyze->Append (IFMENU_COMPARE_ROW, "Compare Ro&w");
969 m_pMenuAnalyze->Append (IFMENU_COMPARE_COL, "Compare Colu&mn");
970 m_pMenuAnalyze->Enable (IFMENU_PLOT_ROW, false);
971 m_pMenuAnalyze->Enable (IFMENU_PLOT_COL, false);
972 m_pMenuAnalyze->Enable (IFMENU_COMPARE_ROW, false);
973 m_pMenuAnalyze->Enable (IFMENU_COMPARE_COL, false);
974 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_ROW, false);
975 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_COL, false);
977 wxMenu *help_menu = new wxMenu;
978 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
979 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
980 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
981 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
983 wxMenuBar *menu_bar = new wxMenuBar;
985 menu_bar->Append(m_pFileMenu, "&File");
986 menu_bar->Append(edit_menu, "&Edit");
987 menu_bar->Append(view_menu, "&View");
988 menu_bar->Append(image_menu, "&Image");
989 menu_bar->Append(m_pFilterMenu, "Fi<er");
990 menu_bar->Append(m_pMenuAnalyze, "&Analyze");
991 menu_bar->Append(help_menu, "&Help");
993 subframe->SetMenuBar(menu_bar);
995 subframe->Centre(wxBOTH);
997 wxAcceleratorEntry accelEntries[10];
998 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('A'), IFMENU_VIEW_SCALE_AUTO);
999 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('U'), IFMENU_VIEW_SCALE_FULL);
1000 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('E'), IFMENU_VIEW_SCALE_MINMAX);
1001 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), IFMENU_FILE_PROPERTIES);
1002 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('C'), IFMENU_EDIT_COPY);
1003 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('X'), IFMENU_EDIT_CUT);
1004 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('V'), IFMENU_EDIT_PASTE);
1007 accelEntries[iEntry++].Set (wxACCEL_CTRL, static_cast<int>('2'), IFMENU_FILTER_FFT);
1008 accelEntries[iEntry++].Set (wxACCEL_ALT, static_cast<int>('2'), IFMENU_FILTER_IFFT);
1011 accelEntries[iEntry++].Set (wxACCEL_CTRL, static_cast<int>('3'), IFMENU_IMAGE_CONVERT3D);
1013 wxAcceleratorTable accelTable (iEntry, accelEntries);
1015 subframe->SetAcceleratorTable (accelTable);
1022 ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
1024 m_pFrame = CreateChildFrame(doc, this);
1026 m_bMinSpecified = false;
1027 m_bMaxSpecified = false;
1028 m_dAutoScaleFactor = 1.;
1030 // int width, height;
1031 // m_pFrame->GetClientSize (&width, &height);
1032 m_pFrame->SetTitle("ImageFileView");
1033 m_pCanvas = CreateCanvas (m_pFrame);
1035 // int x, y; // X requires a forced resize
1036 // m_pFrame->GetSize(&x, &y);
1037 // m_pFrame->SetSize(-1, -1, x, y);
1038 m_pFrame->SetFocus();
1039 m_pFrame->Show(true);
1046 ImageFileView::OnDraw (wxDC* dc)
1048 wxSize sizeWindow = m_pFrame->GetClientSize();
1049 wxSize sizeBest = m_pCanvas->GetBestSize();
1050 if (sizeWindow.x > sizeBest.x || sizeWindow.y > sizeBest.y)
1051 m_pFrame->SetClientSize (sizeBest);
1054 dc->DrawBitmap(m_bitmap, 0, 0, false);
1056 int xCursor, yCursor;
1057 if (m_pCanvas->GetCurrentCursor (xCursor, yCursor))
1058 m_pCanvas->DrawRubberBandCursor (*dc, xCursor, yCursor);
1063 ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
1065 const ImageFile& rIF = GetDocument()->getImageFile();
1066 if (m_pFilterMenu && rIF.isComplex()) {
1067 m_pFilterMenu->Enable(IFMENU_FILTER_REAL, true);
1068 m_pFilterMenu->Enable(IFMENU_FILTER_IMAGINARY, true);
1069 m_pFilterMenu->Enable(IFMENU_FILTER_PHASE, true);
1071 m_pFilterMenu->Enable(IFMENU_FILTER_REAL, false);
1072 m_pFilterMenu->Enable(IFMENU_FILTER_IMAGINARY, false);
1073 m_pFilterMenu->Enable(IFMENU_FILTER_PHASE, false);
1075 ImageFileArrayConst v = rIF.getArray();
1078 if (v != NULL && nx != 0 && ny != 0) {
1079 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1081 rIF.getMinMax (min, max);
1082 if (! m_bMinSpecified)
1084 if (! m_bMaxSpecified)
1087 double scaleWidth = m_dMaxPixel - m_dMinPixel;
1089 unsigned char* imageData = new unsigned char [nx * ny * 3];
1091 sys_error (ERR_SEVERE, "Unable to allocate memory for Image display");
1094 for (int ix = 0; ix < nx; ix++) {
1095 for (int iy = 0; iy < ny; iy++) {
1096 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
1097 int intensity = static_cast<int>(scaleValue + 0.5);
1098 intensity = clamp (intensity, 0, 255);
1099 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
1100 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
1103 wxImage image (nx, ny, imageData, true);
1104 m_bitmap = image.ConvertToBitmap();
1108 ySize = clamp (ySize, 0, 800);
1109 // m_pFrame->SetClientSize (xSize, ySize); // KMR
1110 m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20);
1111 m_pCanvas->SetBackgroundColour(*wxWHITE);
1115 m_pCanvas->Refresh();
1119 ImageFileView::OnClose (bool deleteWindow)
1121 //GetDocumentManager()->ActivateView (this, false, true);
1122 if (! GetDocument() || ! GetDocument()->Close())
1127 m_pCanvas->setView(NULL);
1130 wxString s(theApp->GetAppName());
1132 m_pFrame->SetTitle(s);
1139 if (GetDocument() && GetDocument()->getBadFileOpen())
1140 ::wxYield(); // wxWindows bug workaround
1147 ImageFileView::OnEditCopy (wxCommandEvent& event)
1149 wxBitmapDataObject *pBitmapObject = new wxBitmapDataObject;
1151 pBitmapObject->SetBitmap (m_bitmap);
1153 if (wxTheClipboard->Open()) {
1154 wxTheClipboard->SetData (pBitmapObject);
1155 wxTheClipboard->Close();
1160 ImageFileView::OnEditCut (wxCommandEvent& event)
1163 ImageFile& rIF = GetDocument()->getImageFile();
1166 ImageFile* pIF = new ImageFile (nx, ny);
1167 pIF->arrayDataClear();
1168 GetDocument()->setImageFile (pIF); // deletes old IF
1169 OnUpdate(this, NULL);
1170 GetDocument()->UpdateAllViews();
1171 if (theApp->getAskDeleteNewDocs())
1172 GetDocument()->Modify (true);
1176 ImageFileView::OnEditPaste (wxCommandEvent& event)
1178 ImageFile& rIF = GetDocument()->getImageFile();
1180 if (wxTheClipboard->Open()) {
1182 if (wxTheClipboard->IsSupported (wxDF_BITMAP)) {
1183 wxBitmapDataObject bitmapObject;
1184 wxTheClipboard->GetData (bitmapObject);
1185 bitmap = bitmapObject.GetBitmap ();
1187 wxTheClipboard->Close();
1191 bool bMonochrome = false;
1193 if (bitmap.Ok() == true && bitmap.GetWidth() == nx && bitmap.GetHeight() == ny) {
1194 wxImage image (bitmap);
1195 double dScale3 = 3 * 255;
1196 unsigned char* pixels = image.GetData();
1197 ImageFileArray v = rIF.getArray();
1198 for (unsigned int ix = 0; ix < rIF.nx(); ix++) {
1199 for (unsigned int iy = 0; iy < rIF.ny(); iy++) {
1200 unsigned int iBase = 3 * (iy * nx + ix);
1201 if (ix == 0 && iy == 0 && (pixels[iBase] == pixels[iBase+1] && pixels[iBase+1] == pixels[iBase+2]))
1204 v[ix][ny - 1 - iy] = (pixels[iBase]+pixels[iBase+1]+pixels[iBase+2]) / dScale3;
1206 double dR = pixels[iBase] / 255.;
1207 double dG = pixels[iBase+1] / 255.;
1208 double dB = pixels[iBase+2] / 255.;
1209 v[ix][ny - 1 - iy] = ImageFile::colorToGrayscale (dR, dG, dB);
1213 OnUpdate(this, NULL);
1214 GetDocument()->UpdateAllViews();
1215 if (theApp->getAskDeleteNewDocs())
1216 GetDocument()->Modify(true);
1222 ImageFileView::OnExport (wxCommandEvent& event)
1224 ImageFile& rIF = GetDocument()->getImageFile();
1225 ImageFileArrayConst v = rIF.getArray();
1228 if (v != NULL && nx != 0 && ny != 0) {
1229 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1231 rIF.getMinMax (min, max);
1232 if (! m_bMinSpecified)
1234 if (! m_bMaxSpecified)
1238 DialogExportParameters dialogExport (getFrameForChild(), m_iDefaultExportFormatID);
1239 if (dialogExport.ShowModal() == wxID_OK) {
1240 wxString strFormatName (dialogExport.getFormatName ());
1241 m_iDefaultExportFormatID = ImageFile::convertExportFormatNameToID (strFormatName.c_str());
1244 wxString strWildcard;
1245 if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PGM || m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PGMASCII) {
1247 strWildcard = "PGM Files (*.pgm)|*.pgm";
1250 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PNG || m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PNG16) {
1252 strWildcard = "PNG Files (*.png)|*.png";
1255 #ifdef HAVE_CTN_DICOM
1256 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_DICOM) {
1258 strWildcard = "DICOM Files (*.*)|*.*";
1261 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_TEXT) {
1263 strWildcard = "Text (*.txt)|*.txt";
1267 strWildcard = "Miscellaneous (*.*)|*.*";
1270 const wxString& strFilename = wxFileSelector (wxString("Export Filename"), wxString(""),
1271 wxString(""), strExt, strWildcard, wxOVERWRITE_PROMPT | wxHIDE_READONLY | wxSAVE);
1273 rIF.exportImage (strFormatName.c_str(), strFilename.c_str(), 1, 1, m_dMinPixel, m_dMaxPixel);
1274 *theApp->getLog() << "Exported file " << strFilename << "\n";
1281 ImageFileView::OnScaleSize (wxCommandEvent& event)
1283 ImageFile& rIF = GetDocument()->getImageFile();
1284 unsigned int iOldNX = rIF.nx();
1285 unsigned int iOldNY = rIF.ny();
1287 DialogGetXYSize dialogGetXYSize (getFrameForChild(), "Set New X & Y Dimensions", iOldNX, iOldNY);
1288 if (dialogGetXYSize.ShowModal() == wxID_OK) {
1289 unsigned int iNewNX = dialogGetXYSize.getXSize();
1290 unsigned int iNewNY = dialogGetXYSize.getYSize();
1291 std::ostringstream os;
1292 os << "Scale Size from (" << iOldNX << "," << iOldNY << ") to (" << iNewNX << "," << iNewNY << ")";
1293 ImageFileDocument* pScaledDoc = theApp->newImageDoc();
1295 sys_error (ERR_SEVERE, "Unable to create image file");
1298 ImageFile& rScaledIF = pScaledDoc->getImageFile();
1299 rScaledIF.setArraySize (iNewNX, iNewNY);
1300 rScaledIF.labelsCopy (rIF);
1301 rScaledIF.labelAdd (os.str().c_str());
1302 rIF.scaleImage (rScaledIF);
1303 *theApp->getLog() << os.str().c_str() << "\n";
1304 if (theApp->getAskDeleteNewDocs())
1305 pScaledDoc->Modify (true);
1306 pScaledDoc->UpdateAllViews (this);
1307 pScaledDoc->getView()->getFrame()->Show(true);
1308 pScaledDoc->Activate();
1314 ImageFileView::OnConvert3d (wxCommandEvent& event)
1316 ImageFile& rIF = GetDocument()->getImageFile();
1317 Graph3dFileDocument* pGraph3d = theApp->newGraph3dDoc();
1318 pGraph3d->setBadFileOpen();
1319 pGraph3d->createFromImageFile (rIF);
1320 pGraph3d->getView()->OnUpdate (this, NULL);
1321 pGraph3d->UpdateAllViews();
1322 pGraph3d->getView()->getFrame()->SetClientSize (400, 400);
1323 pGraph3d->getView()->getFrame()->Show (true);
1324 GetDocumentManager()->ActivateView (pGraph3d->getView(), true, false);
1326 pGraph3d->getView()->getCanvas()->SetFocus();
1331 ImageFileView::OnPlotRow (wxCommandEvent& event)
1333 int xCursor, yCursor;
1334 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1335 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1339 const ImageFile& rIF = GetDocument()->getImageFile();
1340 ImageFileArrayConst v = rIF.getArray();
1341 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1345 if (v != NULL && yCursor < ny) {
1346 double* pX = new double [nx];
1347 double* pYReal = new double [nx];
1348 double *pYImag = NULL;
1349 double *pYMag = NULL;
1350 if (rIF.isComplex()) {
1351 pYImag = new double [nx];
1352 pYMag = new double [nx];
1354 for (int i = 0; i < nx; i++) {
1356 pYReal[i] = v[i][yCursor];
1357 if (rIF.isComplex()) {
1358 pYImag[i] = vImag[i][yCursor];
1359 pYMag[i] = ::sqrt (v[i][yCursor] * v[i][yCursor] + vImag[i][yCursor] * vImag[i][yCursor]);
1362 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1364 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1366 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1367 std::ostringstream os;
1368 os << "Row " << yCursor;
1369 std::string title("title ");
1371 rPlotFile.addEzsetCommand (title.c_str());
1372 rPlotFile.addEzsetCommand ("xlabel Column");
1373 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1374 rPlotFile.addEzsetCommand ("lxfrac 0");
1375 rPlotFile.addEzsetCommand ("box");
1376 rPlotFile.addEzsetCommand ("grid");
1377 rPlotFile.addEzsetCommand ("curve 1");
1378 rPlotFile.addEzsetCommand ("color 1");
1379 if (rIF.isComplex()) {
1380 rPlotFile.addEzsetCommand ("dash 1");
1381 rPlotFile.addEzsetCommand ("curve 2");
1382 rPlotFile.addEzsetCommand ("color 4");
1383 rPlotFile.addEzsetCommand ("dash 3");
1384 rPlotFile.addEzsetCommand ("curve 3");
1385 rPlotFile.addEzsetCommand ("color 0");
1386 rPlotFile.addEzsetCommand ("solid");
1387 rPlotFile.setCurveSize (4, nx);
1389 rPlotFile.setCurveSize (2, nx);
1390 rPlotFile.addColumn (0, pX);
1391 rPlotFile.addColumn (1, pYReal);
1392 if (rIF.isComplex()) {
1393 rPlotFile.addColumn (2, pYImag);
1394 rPlotFile.addColumn (3, pYMag);
1396 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1397 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1398 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1399 *theApp->getLog() << os.str().c_str() << "\n";
1400 rPlotFile.addDescription (os.str().c_str());
1404 if (rIF.isComplex()) {
1408 if (theApp->getAskDeleteNewDocs())
1409 pPlotDoc->Modify (true);
1410 pPlotDoc->getView()->getFrame()->Show(true);
1411 pPlotDoc->UpdateAllViews ();
1412 pPlotDoc->Activate();
1417 ImageFileView::OnPlotCol (wxCommandEvent& event)
1419 int xCursor, yCursor;
1420 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1421 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1425 const ImageFile& rIF = GetDocument()->getImageFile();
1426 ImageFileArrayConst v = rIF.getArray();
1427 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1431 if (v != NULL && xCursor < nx) {
1432 double* pX = new double [ny];
1433 double* pYReal = new double [ny];
1434 double* pYImag = NULL;
1435 double* pYMag = NULL;
1436 if (rIF.isComplex()) {
1437 pYImag = new double [ny];
1438 pYMag = new double [ny];
1440 for (int i = 0; i < ny; i++) {
1442 pYReal[i] = v[xCursor][i];
1443 if (rIF.isComplex()) {
1444 pYImag[i] = vImag[xCursor][i];
1445 pYMag[i] = ::sqrt (v[xCursor][i] * v[xCursor][i] + vImag[xCursor][i] * vImag[xCursor][i]);
1448 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1450 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1452 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1453 std::ostringstream os;
1454 os << "Column " << xCursor;
1455 std::string title("title ");
1457 rPlotFile.addEzsetCommand (title.c_str());
1458 rPlotFile.addEzsetCommand ("xlabel Row");
1459 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1460 rPlotFile.addEzsetCommand ("lxfrac 0");
1461 rPlotFile.addEzsetCommand ("box");
1462 rPlotFile.addEzsetCommand ("grid");
1463 rPlotFile.addEzsetCommand ("curve 1");
1464 rPlotFile.addEzsetCommand ("color 1");
1465 if (rIF.isComplex()) {
1466 rPlotFile.addEzsetCommand ("dash 1");
1467 rPlotFile.addEzsetCommand ("curve 2");
1468 rPlotFile.addEzsetCommand ("color 4");
1469 rPlotFile.addEzsetCommand ("dash 3");
1470 rPlotFile.addEzsetCommand ("curve 3");
1471 rPlotFile.addEzsetCommand ("color 0");
1472 rPlotFile.addEzsetCommand ("solid");
1473 rPlotFile.setCurveSize (4, ny);
1475 rPlotFile.setCurveSize (2, ny);
1476 rPlotFile.addColumn (0, pX);
1477 rPlotFile.addColumn (1, pYReal);
1478 if (rIF.isComplex()) {
1479 rPlotFile.addColumn (2, pYImag);
1480 rPlotFile.addColumn (3, pYMag);
1482 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1483 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1484 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1485 *theApp->getLog() << os.str().c_str() << "\n";
1486 rPlotFile.addDescription (os.str().c_str());
1490 if (rIF.isComplex()) {
1494 if (theApp->getAskDeleteNewDocs())
1495 pPlotDoc->Modify (true);
1496 pPlotDoc->getView()->getFrame()->Show(true);
1497 pPlotDoc->UpdateAllViews ();
1498 pPlotDoc->Activate();
1504 ImageFileView::OnPlotFFTRow (wxCommandEvent& event)
1506 int xCursor, yCursor;
1507 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1508 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1512 const ImageFile& rIF = GetDocument()->getImageFile();
1513 ImageFileArrayConst v = rIF.getArray();
1514 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1518 if (v != NULL && yCursor < ny) {
1519 fftw_complex* pcIn = new fftw_complex [nx];
1522 for (i = 0; i < nx; i++) {
1523 pcIn[i].re = v[i][yCursor];
1524 if (rIF.isComplex())
1525 pcIn[i].im = vImag[i][yCursor];
1530 fftw_plan plan = fftw_create_plan (nx, FFTW_FORWARD, FFTW_IN_PLACE | FFTW_ESTIMATE | FFTW_USE_WISDOM);
1531 fftw_one (plan, pcIn, NULL);
1532 fftw_destroy_plan (plan);
1534 double* pX = new double [nx];
1535 double* pYReal = new double [nx];
1536 double* pYImag = new double [nx];
1537 double* pYMag = new double [nx];
1538 for (i = 0; i < nx; i++) {
1540 pYReal[i] = pcIn[i].re / nx;
1541 pYImag[i] = pcIn[i].im / nx;
1542 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1544 Fourier::shuffleFourierToNaturalOrder (pYReal, nx);
1545 Fourier::shuffleFourierToNaturalOrder (pYImag, nx);
1546 Fourier::shuffleFourierToNaturalOrder (pYMag, nx);
1548 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1550 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1552 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1553 std::ostringstream os;
1554 os << "Row " << yCursor;
1555 std::string title("title ");
1557 rPlotFile.addEzsetCommand (title.c_str());
1558 rPlotFile.addEzsetCommand ("xlabel Column");
1559 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1560 rPlotFile.addEzsetCommand ("lxfrac 0");
1561 rPlotFile.addEzsetCommand ("curve 1");
1562 rPlotFile.addEzsetCommand ("color 1");
1563 rPlotFile.addEzsetCommand ("dash 1");
1564 rPlotFile.addEzsetCommand ("curve 2");
1565 rPlotFile.addEzsetCommand ("color 4");
1566 rPlotFile.addEzsetCommand ("dash 3");
1567 rPlotFile.addEzsetCommand ("curve 3");
1568 rPlotFile.addEzsetCommand ("color 0");
1569 rPlotFile.addEzsetCommand ("solid");
1570 rPlotFile.addEzsetCommand ("box");
1571 rPlotFile.addEzsetCommand ("grid");
1572 rPlotFile.setCurveSize (4, nx);
1573 rPlotFile.addColumn (0, pX);
1574 rPlotFile.addColumn (1, pYReal);
1575 rPlotFile.addColumn (2, pYImag);
1576 rPlotFile.addColumn (3, pYMag);
1577 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1578 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1579 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1580 *theApp->getLog() << os.str().c_str() << "\n";
1581 rPlotFile.addDescription (os.str().c_str());
1589 if (theApp->getAskDeleteNewDocs())
1590 pPlotDoc->Modify (true);
1591 pPlotDoc->getView()->getFrame()->Show(true);
1592 pPlotDoc->UpdateAllViews ();
1593 pPlotDoc->Activate();
1598 ImageFileView::OnPlotFFTCol (wxCommandEvent& event)
1600 int xCursor, yCursor;
1601 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1602 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1606 const ImageFile& rIF = GetDocument()->getImageFile();
1607 ImageFileArrayConst v = rIF.getArray();
1608 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1612 if (v != NULL && xCursor < nx) {
1613 fftw_complex* pcIn = new fftw_complex [ny];
1614 double *pdTemp = new double [ny];
1617 for (i = 0; i < ny; i++)
1618 pdTemp[i] = v[xCursor][i];
1619 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1620 for (i = 0; i < ny; i++)
1621 pcIn[i].re = pdTemp[i];
1623 for (i = 0; i < ny; i++) {
1624 if (rIF.isComplex())
1625 pdTemp[i] = vImag[xCursor][i];
1629 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1630 for (i = 0; i < ny; i++)
1631 pcIn[i].im = pdTemp[i];
1633 fftw_plan plan = fftw_create_plan (ny, FFTW_BACKWARD, FFTW_IN_PLACE | FFTW_ESTIMATE | FFTW_USE_WISDOM);
1634 fftw_one (plan, pcIn, NULL);
1635 fftw_destroy_plan (plan);
1637 double* pX = new double [ny];
1638 double* pYReal = new double [ny];
1639 double* pYImag = new double [ny];
1640 double* pYMag = new double [ny];
1641 for (i = 0; i < ny; i++) {
1643 pYReal[i] = pcIn[i].re / ny;
1644 pYImag[i] = pcIn[i].im / ny;
1645 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1648 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1650 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1652 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1653 std::ostringstream os;
1654 os << "Column " << xCursor;
1655 std::string title("title ");
1657 rPlotFile.addEzsetCommand (title.c_str());
1658 rPlotFile.addEzsetCommand ("xlabel Column");
1659 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1660 rPlotFile.addEzsetCommand ("lxfrac 0");
1661 rPlotFile.addEzsetCommand ("curve 1");
1662 rPlotFile.addEzsetCommand ("color 1");
1663 rPlotFile.addEzsetCommand ("dash 1");
1664 rPlotFile.addEzsetCommand ("curve 2");
1665 rPlotFile.addEzsetCommand ("color 4");
1666 rPlotFile.addEzsetCommand ("dash 3");
1667 rPlotFile.addEzsetCommand ("curve 3");
1668 rPlotFile.addEzsetCommand ("color 0");
1669 rPlotFile.addEzsetCommand ("solid");
1670 rPlotFile.addEzsetCommand ("box");
1671 rPlotFile.addEzsetCommand ("grid");
1672 rPlotFile.setCurveSize (4, ny);
1673 rPlotFile.addColumn (0, pX);
1674 rPlotFile.addColumn (1, pYReal);
1675 rPlotFile.addColumn (2, pYImag);
1676 rPlotFile.addColumn (3, pYMag);
1677 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1678 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1679 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1680 *theApp->getLog() << os.str().c_str() << "\n";
1681 rPlotFile.addDescription (os.str().c_str());
1690 if (theApp->getAskDeleteNewDocs())
1691 pPlotDoc->Modify (true);
1692 pPlotDoc->getView()->getFrame()->Show(true);
1693 pPlotDoc->UpdateAllViews ();
1694 pPlotDoc->Activate();
1700 ImageFileView::OnCompareCol (wxCommandEvent& event)
1702 int xCursor, yCursor;
1703 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1704 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1708 std::vector<ImageFileDocument*> vecIFDoc;
1709 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1710 if (vecIFDoc.size() == 0) {
1711 wxMessageBox ("No compatible images for Column Comparison", "Error");
1714 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1716 if (dialogGetCompare.ShowModal() == wxID_OK) {
1717 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1718 const ImageFile& rIF = GetDocument()->getImageFile();
1719 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1721 ImageFileArrayConst v1 = rIF.getArray();
1722 ImageFileArrayConst v2 = rCompareIF.getArray();
1726 if (v1 != NULL && xCursor < nx) {
1727 double* pX = new double [ny];
1728 double* pY1 = new double [ny];
1729 double* pY2 = new double [ny];
1730 for (int i = 0; i < ny; i++) {
1732 pY1[i] = v1[xCursor][i];
1733 pY2[i] = v2[xCursor][i];
1735 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1737 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1739 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1740 std::ostringstream os;
1741 os << "Column " << xCursor << " Comparison";
1742 std::string title("title ");
1744 rPlotFile.addEzsetCommand (title.c_str());
1745 rPlotFile.addEzsetCommand ("xlabel Row");
1746 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1747 rPlotFile.addEzsetCommand ("lxfrac 0");
1748 rPlotFile.addEzsetCommand ("curve 1");
1749 rPlotFile.addEzsetCommand ("color 2");
1750 rPlotFile.addEzsetCommand ("curve 2");
1751 rPlotFile.addEzsetCommand ("color 4");
1752 rPlotFile.addEzsetCommand ("dash 5");
1753 rPlotFile.addEzsetCommand ("box");
1754 rPlotFile.addEzsetCommand ("grid");
1755 rPlotFile.setCurveSize (3, ny);
1756 rPlotFile.addColumn (0, pX);
1757 rPlotFile.addColumn (1, pY1);
1758 rPlotFile.addColumn (2, pY2);
1761 for (iL = 0; iL < rIF.nLabels(); iL++) {
1762 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1764 s += rIF.labelGet(iL).getLabelString();
1765 rPlotFile.addDescription (s.c_str());
1767 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1768 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1770 s += rCompareIF.labelGet(iL).getLabelString();
1771 rPlotFile.addDescription (s.c_str());
1773 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1774 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1775 *theApp->getLog() << os.str().c_str() << "\n";
1776 rPlotFile.addDescription (os.str().c_str());
1781 if (theApp->getAskDeleteNewDocs())
1782 pPlotDoc->Modify (true);
1783 pPlotDoc->getView()->getFrame()->Show(true);
1784 pPlotDoc->UpdateAllViews ();
1785 pPlotDoc->Activate();
1791 ImageFileView::OnCompareRow (wxCommandEvent& event)
1793 int xCursor, yCursor;
1794 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1795 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1799 std::vector<ImageFileDocument*> vecIFDoc;
1800 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1802 if (vecIFDoc.size() == 0) {
1803 wxMessageBox ("No compatible images for Row Comparison", "Error");
1807 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1809 if (dialogGetCompare.ShowModal() == wxID_OK) {
1810 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1811 const ImageFile& rIF = GetDocument()->getImageFile();
1812 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1814 ImageFileArrayConst v1 = rIF.getArray();
1815 ImageFileArrayConst v2 = rCompareIF.getArray();
1819 if (v1 != NULL && yCursor < ny) {
1820 double* pX = new double [nx];
1821 double* pY1 = new double [nx];
1822 double* pY2 = new double [nx];
1823 for (int i = 0; i < nx; i++) {
1825 pY1[i] = v1[i][yCursor];
1826 pY2[i] = v2[i][yCursor];
1828 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1830 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1832 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1833 std::ostringstream os;
1834 os << "Row " << yCursor << " Comparison";
1835 std::string title("title ");
1837 rPlotFile.addEzsetCommand (title.c_str());
1838 rPlotFile.addEzsetCommand ("xlabel Column");
1839 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1840 rPlotFile.addEzsetCommand ("lxfrac 0");
1841 rPlotFile.addEzsetCommand ("curve 1");
1842 rPlotFile.addEzsetCommand ("color 2");
1843 rPlotFile.addEzsetCommand ("curve 2");
1844 rPlotFile.addEzsetCommand ("color 4");
1845 rPlotFile.addEzsetCommand ("dash 5");
1846 rPlotFile.addEzsetCommand ("box");
1847 rPlotFile.addEzsetCommand ("grid");
1848 rPlotFile.setCurveSize (3, nx);
1849 rPlotFile.addColumn (0, pX);
1850 rPlotFile.addColumn (1, pY1);
1851 rPlotFile.addColumn (2, pY2);
1853 for (iL = 0; iL < rIF.nLabels(); iL++) {
1854 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1856 s += rIF.labelGet(iL).getLabelString();
1857 rPlotFile.addDescription (s.c_str());
1859 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1860 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1862 s += rCompareIF.labelGet(iL).getLabelString();
1863 rPlotFile.addDescription (s.c_str());
1865 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1866 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1867 *theApp->getLog() << os.str().c_str() << "\n";
1868 rPlotFile.addDescription (os.str().c_str());
1873 if (theApp->getAskDeleteNewDocs())
1874 pPlotDoc->Modify (true);
1875 pPlotDoc->getView()->getFrame()->Show(true);
1876 pPlotDoc->UpdateAllViews ();
1877 pPlotDoc->Activate();
1882 static int NUMBER_HISTOGRAM_BINS = 256;
1885 ImageFileView::OnPlotHistogram (wxCommandEvent& event)
1887 const ImageFile& rIF = GetDocument()->getImageFile();
1888 ImageFileArrayConst v = rIF.getArray();
1892 if (v != NULL && nx > 0 && ny > 0) {
1893 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1895 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1899 double* pX = new double [NUMBER_HISTOGRAM_BINS];
1900 double* pY = new double [NUMBER_HISTOGRAM_BINS];
1902 rIF.getMinMax (dMin, dMax);
1903 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
1905 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
1906 pX[i] = dMin + (i + 0.5) * dBinWidth;
1909 for (int ix = 0; ix < nx; ix++)
1910 for (int iy = 0; iy < ny; iy++) {
1911 int iBin = nearest<int> ((v[ix][iy] - dMin) / dBinWidth);
1912 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
1916 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1917 std::ostringstream os;
1919 std::string title("title ");
1921 rPlotFile.addEzsetCommand (title.c_str());
1922 rPlotFile.addEzsetCommand ("xlabel Pixel Value");
1923 rPlotFile.addEzsetCommand ("ylabel Count");
1924 rPlotFile.addEzsetCommand ("box");
1925 rPlotFile.addEzsetCommand ("grid");
1926 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
1927 rPlotFile.addColumn (0, pX);
1928 rPlotFile.addColumn (1, pY);
1929 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++) {
1930 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1932 s += rIF.labelGet(iL).getLabelString();
1933 rPlotFile.addDescription (s.c_str());
1935 os << " plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1936 *theApp->getLog() << os.str().c_str() << "\n";
1937 rPlotFile.addDescription (os.str().c_str());
1940 if (theApp->getAskDeleteNewDocs())
1941 pPlotDoc->Modify (true);
1942 pPlotDoc->getView()->getFrame()->Show(true);
1943 pPlotDoc->UpdateAllViews ();
1944 pPlotDoc->Activate();
1951 PhantomCanvas::PhantomCanvas (PhantomFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1952 : wxScrolledWindow(frame, -1, pos, size, style)
1957 PhantomCanvas::~PhantomCanvas ()
1963 PhantomCanvas::OnDraw (wxDC& dc)
1966 m_pView->OnDraw(& dc);
1970 PhantomCanvas::GetBestSize() const
1976 theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
1977 xSize = maxValue<int> (xSize, ySize);
1979 ySize = xSize = (xSize / 4);
1983 return wxSize (xSize, ySize);
1990 IMPLEMENT_DYNAMIC_CLASS(PhantomFileView, wxView)
1992 BEGIN_EVENT_TABLE(PhantomFileView, wxView)
1993 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomFileView::OnProperties)
1994 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomFileView::OnRasterize)
1995 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomFileView::OnProjections)
1998 PhantomFileView::PhantomFileView()
1999 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0)
2001 #if defined(DEBUG) || defined(_DEBUG)
2002 m_iDefaultNDet = 165;
2003 m_iDefaultNView = 180;
2004 m_iDefaultNSample = 1;
2006 m_iDefaultNDet = 367;
2007 m_iDefaultNView = 320;
2008 m_iDefaultNSample = 2;
2010 m_iDefaultOffsetView = 0;
2011 m_dDefaultRotation = 1;
2012 m_dDefaultFocalLength = 2;
2013 m_dDefaultCenterDetectorLength = 2;
2014 m_dDefaultViewRatio = 1;
2015 m_dDefaultScanRatio = 1;
2016 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
2017 m_iDefaultTrace = Trace::TRACE_NONE;
2020 m_iDefaultRasterNX = 115;
2021 m_iDefaultRasterNY = 115;
2022 m_iDefaultRasterNSamples = 1;
2024 m_iDefaultRasterNX = 256;
2025 m_iDefaultRasterNY = 256;
2026 m_iDefaultRasterNSamples = 2;
2028 m_dDefaultRasterViewRatio = 1;
2031 PhantomFileView::~PhantomFileView()
2033 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2034 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
2038 PhantomFileView::OnProperties (wxCommandEvent& event)
2040 const int idPhantom = GetDocument()->getPhantomID();
2041 const wxString& namePhantom = GetDocument()->getPhantomName();
2042 std::ostringstream os;
2043 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")" << "\n";
2044 const Phantom& rPhantom = GetDocument()->getPhantom();
2045 rPhantom.printDefinitions (os);
2047 rPhantom.print (os);
2049 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2050 wxMessageBox (os.str().c_str(), "Phantom Properties");
2051 GetDocument()->Activate();
2056 PhantomFileView::OnProjections (wxCommandEvent& event)
2058 DialogGetProjectionParameters dialogProjection (getFrameForChild(),
2059 m_iDefaultNDet, m_iDefaultNView, m_iDefaultOffsetView, m_iDefaultNSample, m_dDefaultRotation,
2060 m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio,
2061 m_iDefaultGeometry, m_iDefaultTrace);
2062 int retVal = dialogProjection.ShowModal();
2063 if (retVal != wxID_OK)
2066 m_iDefaultNDet = dialogProjection.getNDet();
2067 m_iDefaultNView = dialogProjection.getNView();
2068 m_iDefaultOffsetView = dialogProjection.getOffsetView();
2069 m_iDefaultNSample = dialogProjection.getNSamples();
2070 m_iDefaultTrace = dialogProjection.getTrace();
2071 m_dDefaultRotation = dialogProjection.getRotAngle();
2072 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
2073 m_dDefaultCenterDetectorLength = dialogProjection.getCenterDetectorLengthRatio();
2074 m_dDefaultViewRatio = dialogProjection.getViewRatio();
2075 m_dDefaultScanRatio = dialogProjection.getScanRatio();
2076 wxString sGeometry = dialogProjection.getGeometry();
2077 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
2078 double dRotationRadians = m_dDefaultRotation;
2079 m_dDefaultRotation /= TWOPI; // convert back to fraction of a circle
2081 if (m_iDefaultNDet <= 0 || m_iDefaultNView <= 0 || sGeometry == "")
2084 const Phantom& rPhantom = GetDocument()->getPhantom();
2085 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultOffsetView, m_iDefaultNSample,
2086 dRotationRadians, m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio);
2087 if (theScanner.fail()) {
2088 wxString msg = "Failed making scanner\n";
2089 msg += theScanner.failMessage().c_str();
2090 *theApp->getLog() << msg << "\n";
2091 wxMessageBox (msg, "Error");
2095 std::ostringstream os;
2096 os << "Projections for " << rPhantom.name()
2097 << ": nDet=" << m_iDefaultNDet
2098 << ", nView=" << m_iDefaultNView
2099 << ", gantry offset=" << m_iDefaultOffsetView
2100 << ", nSamples=" << m_iDefaultNSample
2101 << ", RotAngle=" << m_dDefaultRotation
2102 << ", FocalLengthRatio=" << m_dDefaultFocalLength
2103 << ", CenterDetectorLengthRatio=" << m_dDefaultCenterDetectorLength
2104 << ", ViewRatio=" << m_dDefaultViewRatio
2105 << ", ScanRatio=" << m_dDefaultScanRatio
2106 << ", Geometry=" << sGeometry.c_str()
2107 << ", FanBeamAngle=" << convertRadiansToDegrees (theScanner.fanBeamAngle());
2110 Projections* pProj = NULL;
2111 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2112 pProj = new Projections;
2113 pProj->initFromScanner (theScanner);
2115 ProjectionsDialog dialogProjections (theScanner, *pProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(getFrameForChild()));
2116 for (int iView = 0; iView < pProj->nView(); iView++) {
2118 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
2123 while (dialogProjections.isPaused()) {
2130 if (theApp->getUseBackgroundTasks()) {
2131 ProjectorSupervisorThread* pProjector = new ProjectorSupervisorThread (this, m_iDefaultNDet,
2132 m_iDefaultNView, m_iDefaultOffsetView, sGeometry.c_str(), m_iDefaultNSample, dRotationRadians,
2133 m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio, os.str().c_str());
2134 if (pProjector->Create() != wxTHREAD_NO_ERROR) {
2135 sys_error (ERR_SEVERE, "Error creating projector thread");
2139 pProjector->SetPriority(60);
2143 #endif // HAVE_WXTHREADS
2145 pProj = new Projections;
2146 pProj->initFromScanner (theScanner);
2147 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), pProj->nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2148 for (int i = 0; i < pProj->nView(); i++) {
2149 //theScanner.collectProjections (*pProj, rPhantom, i, 1, true, m_iDefaultTrace);
2150 theScanner.collectProjections (*pProj, rPhantom, i, 1, theScanner.offsetView(), true, m_iDefaultTrace);
2151 if (! dlgProgress.Update (i+1)) {
2159 *theApp->getLog() << os.str().c_str() << "\n";
2160 pProj->setRemark (os.str());
2161 pProj->setCalcTime (timer.timerEnd());
2163 ProjectionFileDocument* pProjectionDoc = theApp->newProjectionDoc();
2164 if (! pProjectionDoc) {
2165 sys_error (ERR_SEVERE, "Unable to create projection document");
2168 pProjectionDoc->setProjections (pProj);
2169 ProjectionFileView* projView = pProjectionDoc->getView();
2171 projView->OnUpdate (projView, NULL);
2172 if (projView->getCanvas())
2173 projView->getCanvas()->SetClientSize (m_iDefaultNDet, m_iDefaultNView);
2174 if (wxFrame* pFrame = projView->getFrame()) {
2179 GetDocumentManager()->ActivateView (projView, true, false);
2181 if (theApp->getAskDeleteNewDocs())
2182 pProjectionDoc-> Modify(true);
2183 pProjectionDoc->UpdateAllViews (this);
2184 pProjectionDoc->Activate();
2189 PhantomFileView::OnRasterize (wxCommandEvent& event)
2191 DialogGetRasterParameters dialogRaster (getFrameForChild(), m_iDefaultRasterNX, m_iDefaultRasterNY,
2192 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio);
2193 int retVal = dialogRaster.ShowModal();
2194 if (retVal != wxID_OK)
2197 m_iDefaultRasterNX = dialogRaster.getXSize();
2198 m_iDefaultRasterNY = dialogRaster.getYSize();
2199 m_iDefaultRasterNSamples = dialogRaster.getNSamples();
2200 m_dDefaultRasterViewRatio = dialogRaster.getViewRatio();
2201 if (m_iDefaultRasterNSamples < 1)
2202 m_iDefaultRasterNSamples = 1;
2203 if (m_dDefaultRasterViewRatio < 0)
2204 m_dDefaultRasterViewRatio = 0;
2205 if (m_iDefaultRasterNX <= 0 || m_iDefaultRasterNY <= 0)
2208 const Phantom& rPhantom = GetDocument()->getPhantom();
2209 std::ostringstream os;
2210 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << m_iDefaultRasterNX << ", YSize="
2211 << m_iDefaultRasterNY << ", ViewRatio=" << m_dDefaultRasterViewRatio << ", nSamples="
2212 << m_iDefaultRasterNSamples;;
2215 if (theApp->getUseBackgroundTasks()) {
2216 RasterizerSupervisorThread* pThread = new RasterizerSupervisorThread (this, m_iDefaultRasterNX, m_iDefaultRasterNY,
2217 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio, os.str().c_str());
2218 if (pThread->Create() != wxTHREAD_NO_ERROR) {
2219 *theApp->getLog() << "Error creating rasterizer thread\n";
2222 pThread->SetPriority (60);
2227 ImageFile* pImageFile = new ImageFile (m_iDefaultRasterNX, m_iDefaultRasterNY);
2229 wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"),
2230 pImageFile->nx() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2232 for (unsigned int i = 0; i < pImageFile->nx(); i++) {
2233 rPhantom.convertToImagefile (*pImageFile, m_dDefaultRasterViewRatio, m_iDefaultRasterNSamples, Trace::TRACE_NONE, i, 1, true);
2234 if (! dlgProgress.Update (i+1)) {
2240 ImageFileDocument* pRasterDoc = theApp->newImageDoc();
2242 sys_error (ERR_SEVERE, "Unable to create image file");
2245 pRasterDoc->setImageFile (pImageFile);
2246 if (theApp->getAskDeleteNewDocs())
2247 pRasterDoc->Modify (true);
2248 *theApp->getLog() << os.str().c_str() << "\n";
2249 pImageFile->labelAdd (os.str().c_str(), timer.timerEnd());
2251 if (ImageFileView* rasterView = pRasterDoc->getView()) {
2252 rasterView->getFrame()->Show(true);
2253 rasterView->getFrame()->SetFocus();
2254 rasterView->OnUpdate (rasterView, NULL);
2256 // Causes loss of frame in wxGTK
2257 // pRasterDoc->UpdateAllViews (this);
2258 // pRasterDoc->Activate();
2264 PhantomFileView::CreateCanvas (wxFrame *parent)
2266 PhantomCanvas* pCanvas;
2268 pCanvas = new PhantomCanvas (this, parent, wxPoint(0, 0), wxSize(0,0), 0);
2269 pCanvas->SetBackgroundColour(*wxWHITE);
2280 PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2283 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2285 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2287 theApp->setIconForFrame (subframe);
2289 m_pFileMenu = new wxMenu;
2291 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2292 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2293 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2294 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2295 m_pFileMenu->Append(wxID_CLOSE, "&Close");
2297 m_pFileMenu->AppendSeparator();
2298 m_pFileMenu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
2300 m_pFileMenu->AppendSeparator();
2301 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2302 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2303 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2304 m_pFileMenu->AppendSeparator();
2305 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
2307 m_pFileMenu->AppendSeparator();
2308 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
2309 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2311 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2312 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2314 wxMenu *process_menu = new wxMenu;
2315 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...\tCtrl-R");
2316 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...\tCtrl-J");
2318 wxMenu *help_menu = new wxMenu;
2319 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2320 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
2321 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
2322 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2324 wxMenuBar *menu_bar = new wxMenuBar;
2326 menu_bar->Append(m_pFileMenu, "&File");
2327 menu_bar->Append(process_menu, "&Process");
2328 menu_bar->Append(help_menu, "&Help");
2330 subframe->SetMenuBar(menu_bar);
2331 subframe->Centre(wxBOTH);
2333 wxAcceleratorEntry accelEntries[3];
2334 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('J'), PHMMENU_PROCESS_PROJECTIONS);
2335 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('R'), PHMMENU_PROCESS_RASTERIZE);
2336 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('I'), PHMMENU_FILE_PROPERTIES);
2337 wxAcceleratorTable accelTable (3, accelEntries);
2338 subframe->SetAcceleratorTable (accelTable);
2345 PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2347 m_pFrame = CreateChildFrame(doc, this);
2349 m_pCanvas = CreateCanvas (m_pFrame);
2350 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
2351 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
2353 m_pFrame->SetTitle ("PhantomFileView");
2356 int x, y; // X requires a forced resize
2357 m_pFrame->GetSize(&x, &y);
2358 m_pFrame->SetSize(-1, -1, x, y);
2361 m_pFrame->Show(true);
2368 PhantomFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2371 m_pCanvas->Refresh();
2375 PhantomFileView::OnClose (bool deleteWindow)
2377 //GetDocumentManager()->ActivateView (this, false, true);
2378 if (! GetDocument() || ! GetDocument()->Close())
2383 m_pCanvas->setView(NULL);
2386 wxString s(wxTheApp->GetAppName());
2388 m_pFrame->SetTitle(s);
2395 if (GetDocument() && GetDocument()->getBadFileOpen())
2396 ::wxYield(); // wxWindows bug workaround
2403 PhantomFileView::OnDraw (wxDC* dc)
2406 m_pCanvas->GetClientSize (&xsize, &ysize);
2407 SGPDriver driver (dc, xsize, ysize);
2409 const Phantom& rPhantom = GetDocument()->getPhantom();
2410 sgp.setColor (C_RED);
2411 rPhantom.show (sgp);
2416 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2417 : wxScrolledWindow(frame, -1, pos, size, style)
2422 ProjectionFileCanvas::~ProjectionFileCanvas ()
2428 ProjectionFileCanvas::OnDraw(wxDC& dc)
2431 m_pView->OnDraw(& dc);
2435 ProjectionFileCanvas::GetBestSize () const
2439 Projections& rProj = m_pView->GetDocument()->getProjections();
2440 best.Set (rProj.nDet(), rProj.nView());
2447 // ProjectionFileView
2449 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
2451 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
2452 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
2453 EVT_MENU(PJMENU_RECONSTRUCT_FBP, ProjectionFileView::OnReconstructFBP)
2454 EVT_MENU(PJMENU_RECONSTRUCT_FBP_REBIN, ProjectionFileView::OnReconstructFBPRebin)
2455 EVT_MENU(PJMENU_RECONSTRUCT_FOURIER, ProjectionFileView::OnReconstructFourier)
2456 EVT_MENU(PJMENU_CONVERT_RECTANGULAR, ProjectionFileView::OnConvertRectangular)
2457 EVT_MENU(PJMENU_CONVERT_POLAR, ProjectionFileView::OnConvertPolar)
2458 EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
2459 EVT_MENU(PJMENU_CONVERT_PARALLEL, ProjectionFileView::OnConvertParallel)
2460 EVT_MENU(PJMENU_PLOT_TTHETA_SAMPLING, ProjectionFileView::OnPlotTThetaSampling)
2461 EVT_MENU(PJMENU_PLOT_HISTOGRAM, ProjectionFileView::OnPlotHistogram)
2462 // EVT_MENU(PJMENU_ARTIFACT_REDUCTION, ProjectionFileView::OnArtifactReduction)
2466 ProjectionFileView::ProjectionFileView()
2467 : wxView(), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0)
2477 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
2478 m_dDefaultFilterParam = 1.;
2480 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
2481 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
2483 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
2484 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
2486 m_iDefaultZeropad = 1;
2487 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF;
2488 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
2489 m_iDefaultInterpParam = 1;
2490 m_iDefaultTrace = Trace::TRACE_NONE;
2492 m_iDefaultPolarNX = 256;
2493 m_iDefaultPolarNY = 256;
2494 m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR;
2495 m_iDefaultPolarZeropad = 1;
2498 ProjectionFileView::~ProjectionFileView()
2500 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2501 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2505 ProjectionFileView::OnProperties (wxCommandEvent& event)
2507 const Projections& rProj = GetDocument()->getProjections();
2508 std::ostringstream os;
2509 rProj.printScanInfo(os);
2510 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2511 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
2512 dialogMsg.ShowModal();
2513 GetDocument()->Activate();
2518 ProjectionFileView::OnConvertRectangular (wxCommandEvent& event)
2520 Projections& rProj = GetDocument()->getProjections();
2522 int nDet = rProj.nDet();
2523 int nView = rProj.nView();
2524 ImageFile* pIF = new ImageFile (nDet, nView);
2525 ImageFileArray v = pIF->getArray();
2526 for (int iv = 0; iv < nView; iv++) {
2527 DetectorValue* detval = rProj.getDetectorArray(iv).detValues();
2529 for (int id = 0; id < nDet; id++)
2530 v[id][iv] = detval[id];
2533 ImageFileDocument* pRectDoc = theApp->newImageDoc ();
2535 sys_error (ERR_SEVERE, "Unable to create image file");
2538 pRectDoc->setImageFile (pIF);
2539 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2540 std::ostringstream os;
2541 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to rectangular image";
2542 *theApp->getLog() << os.str().c_str() << "\n";
2543 pIF->labelAdd (os.str().c_str());
2544 if (theApp->getAskDeleteNewDocs())
2545 pRectDoc->Modify (true);
2546 pRectDoc->getView()->getFrame()->Show(true);
2547 pRectDoc->UpdateAllViews ();
2548 pRectDoc->Activate();
2552 ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
2554 Projections& rProj = GetDocument()->getProjections();
2555 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2556 m_iDefaultPolarInterpolation, -1, IDH_DLG_POLAR);
2557 if (dialogPolar.ShowModal() == wxID_OK) {
2558 wxProgressDialog dlgProgress (wxString("Convert Polar"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2559 wxString strInterpolation (dialogPolar.getInterpolationName());
2560 m_iDefaultPolarNX = dialogPolar.getXSize();
2561 m_iDefaultPolarNY = dialogPolar.getYSize();
2562 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2563 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2564 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2566 if (! rProj.convertPolar (*pIF, m_iDefaultPolarInterpolation)) {
2568 *theApp->getLog() << "Error converting to Polar\n";
2572 pPolarDoc = theApp->newImageDoc ();
2574 sys_error (ERR_SEVERE, "Unable to create image file");
2577 pPolarDoc->setImageFile (pIF);
2578 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2579 std::ostringstream os;
2580 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to polar image: xSize="
2581 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2582 << strInterpolation.c_str();
2583 *theApp->getLog() << os.str().c_str() << "\n";
2584 pIF->labelAdd (os.str().c_str());
2585 if (theApp->getAskDeleteNewDocs())
2586 pPolarDoc->Modify (true);
2587 pPolarDoc->getView()->getFrame()->Show(true);
2588 pPolarDoc->UpdateAllViews ();
2589 pPolarDoc->Activate();
2594 ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
2596 Projections& rProj = GetDocument()->getProjections();
2597 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert to FFT Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2598 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad, IDH_DLG_FFT_POLAR);
2599 if (dialogPolar.ShowModal() == wxID_OK) {
2600 wxProgressDialog dlgProgress (wxString("Convert FFT Polar"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2601 wxString strInterpolation (dialogPolar.getInterpolationName());
2602 m_iDefaultPolarNX = dialogPolar.getXSize();
2603 m_iDefaultPolarNY = dialogPolar.getYSize();
2604 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2605 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2607 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2608 if (! rProj.convertFFTPolar (*pIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad)) {
2610 *theApp->getLog() << "Error converting to polar\n";
2613 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2615 sys_error (ERR_SEVERE, "Unable to create image file");
2618 pPolarDoc->setImageFile (pIF);
2619 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2620 std::ostringstream os;
2621 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to FFT polar image: xSize="
2622 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2623 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2624 *theApp->getLog() << os.str().c_str() << "\n";
2625 pIF->labelAdd (os.str().c_str());
2626 if (theApp->getAskDeleteNewDocs())
2627 pPolarDoc->Modify (true);
2628 pPolarDoc->getView()->getFrame()->Show(true);
2629 pPolarDoc->UpdateAllViews ();
2630 pPolarDoc->Activate();
2635 ProjectionFileView::OnPlotTThetaSampling (wxCommandEvent& event)
2637 DialogGetThetaRange dlgTheta (this->getFrame(), ParallelRaysums::THETA_RANGE_UNCONSTRAINED);
2638 if (dlgTheta.ShowModal() != wxID_OK)
2641 int iThetaRange = dlgTheta.getThetaRange();
2643 Projections& rProj = GetDocument()->getProjections();
2644 ParallelRaysums parallel (&rProj, iThetaRange);
2645 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
2646 PlotFile& rPlot = pPlotDoc->getPlotFile();
2647 ParallelRaysums::CoordinateContainer& coordContainer = parallel.getCoordinates();
2648 double* pdT = new double [parallel.getNumCoordinates()];
2649 double* pdTheta = new double [parallel.getNumCoordinates()];
2651 for (int i = 0; i < parallel.getNumCoordinates(); i++) {
2652 pdT[i] = coordContainer[i]->m_dT;
2653 pdTheta[i] = coordContainer[i]->m_dTheta;
2655 rPlot.setCurveSize (2, parallel.getNumCoordinates(), true);
2656 rPlot.addEzsetCommand ("title T-Theta Sampling");
2657 rPlot.addEzsetCommand ("xlabel T");
2658 rPlot.addEzsetCommand ("ylabel Theta");
2659 rPlot.addEzsetCommand ("curve 1");
2660 if (rProj.nDet() < 50 && rProj.nView() < 50)
2661 rPlot.addEzsetCommand ("symbol 1"); // x symbol
2663 rPlot.addEzsetCommand ("symbol 6"); // point symbol
2664 rPlot.addEzsetCommand ("noline");
2665 rPlot.addColumn (0, pdT);
2666 rPlot.addColumn (1, pdTheta);
2669 if (theApp->getAskDeleteNewDocs())
2670 pPlotDoc->Modify (true);
2671 pPlotDoc->getView()->getFrame()->Show(true);
2672 pPlotDoc->UpdateAllViews ();
2673 pPlotDoc->Activate();
2678 ProjectionFileView::OnPlotHistogram (wxCommandEvent& event)
2680 Projections& rProj = GetDocument()->getProjections();
2681 int nDet = rProj.nDet();
2682 int nView = rProj.nView();
2684 if (nDet < 1 || nView < 1)
2687 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
2689 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
2693 DetectorValue* pdDetval = rProj.getDetectorArray(0).detValues();
2694 double dMin = pdDetval[0], dMax = pdDetval[0];
2696 for (int iv = 0; iv < nView; iv++) {
2697 pdDetval = rProj.getDetectorArray(iv).detValues();
2698 for (int id = 0; id < nDet; id++) {
2699 double dV = pdDetval[id];
2707 double* pX = new double [NUMBER_HISTOGRAM_BINS];
2708 double* pY = new double [NUMBER_HISTOGRAM_BINS];
2709 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
2711 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
2712 pX[i] = dMin + (i + 0.5) * dBinWidth;
2715 for (int j = 0; j < nView; j++) {
2716 pdDetval = rProj.getDetectorArray(j).detValues();
2717 for (int id = 0; id < nDet; id++) {
2718 int iBin = nearest<int> ((pdDetval[id] - dMin) / dBinWidth);
2719 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
2723 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
2724 std::ostringstream os;
2726 std::string title("title ");
2728 rPlotFile.addEzsetCommand (title.c_str());
2729 rPlotFile.addEzsetCommand ("xlabel Detector Value");
2730 rPlotFile.addEzsetCommand ("ylabel Count");
2731 rPlotFile.addEzsetCommand ("box");
2732 rPlotFile.addEzsetCommand ("grid");
2733 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
2734 rPlotFile.addColumn (0, pX);
2735 rPlotFile.addColumn (1, pY);
2736 rPlotFile.addDescription (rProj.remark());
2737 os << " plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
2738 *theApp->getLog() << os.str().c_str() << "\n";
2739 rPlotFile.addDescription (os.str().c_str());
2742 if (theApp->getAskDeleteNewDocs())
2743 pPlotDoc->Modify (true);
2744 pPlotDoc->getView()->getFrame()->Show(true);
2745 pPlotDoc->UpdateAllViews ();
2746 pPlotDoc->Activate();
2751 ProjectionFileView::OnConvertParallel (wxCommandEvent& event)
2753 Projections& rProj = GetDocument()->getProjections();
2754 if (rProj.geometry() == Scanner::GEOMETRY_PARALLEL) {
2755 wxMessageBox ("Projections are already parallel", "Error");
2758 wxProgressDialog dlgProgress (wxString("Convert to Parallel"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2759 Projections* pProjNew = rProj.interpolateToParallel();
2760 ProjectionFileDocument* pProjDocNew = theApp->newProjectionDoc();
2761 pProjDocNew->setProjections (pProjNew);
2763 if (ProjectionFileView* projView = pProjDocNew->getView()) {
2764 projView->OnUpdate (projView, NULL);
2765 if (projView->getCanvas())
2766 projView->getCanvas()->SetClientSize (pProjNew->nDet(), pProjNew->nView());
2767 if (wxFrame* pFrame = projView->getFrame()) {
2772 GetDocumentManager()->ActivateView (projView, true, false);
2774 if (theApp->getAskDeleteNewDocs())
2775 pProjDocNew-> Modify(true);
2776 pProjDocNew->UpdateAllViews (this);
2777 pProjDocNew->Activate();
2781 ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
2783 Projections& rProj = GetDocument()->getProjections();
2784 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Fourier Reconstruction", m_iDefaultPolarNX, m_iDefaultPolarNY,
2785 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad, IDH_DLG_RECON_FOURIER);
2786 if (dialogPolar.ShowModal() == wxID_OK) {
2787 wxProgressDialog dlgProgress (wxString("Reconstruction Fourier"), wxString("Reconstruction Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2788 wxString strInterpolation (dialogPolar.getInterpolationName());
2789 m_iDefaultPolarNX = dialogPolar.getXSize();
2790 m_iDefaultPolarNY = dialogPolar.getYSize();
2791 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2792 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2794 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2795 if (! rProj.convertFFTPolar (*pIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad)) {
2797 *theApp->getLog() << "Error converting to polar\n";
2803 pIF->magnitude(*pIF);
2804 Fourier::shuffleFourierToNaturalOrder (*pIF);
2806 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2808 sys_error (ERR_SEVERE, "Unable to create image file");
2811 pPolarDoc->setImageFile (pIF);
2812 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2813 std::ostringstream os;
2814 os << "Reconstruct Fourier " << GetFrame()->GetTitle().c_str() << ": xSize="
2815 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2816 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2817 *theApp->getLog() << os.str().c_str() << "\n";
2818 pIF->labelAdd (os.str().c_str());
2819 if (theApp->getAskDeleteNewDocs())
2820 pPolarDoc->Modify (true);
2821 pPolarDoc->getView()->getFrame()->Show(true);
2822 pPolarDoc->UpdateAllViews ();
2823 pPolarDoc->Activate();
2828 ProjectionFileView::OnReconstructFBPRebin (wxCommandEvent& event)
2830 Projections& rProj = GetDocument()->getProjections();
2831 doReconstructFBP (rProj, true);
2835 ProjectionFileView::OnReconstructFBP (wxCommandEvent& event)
2837 Projections& rProj = GetDocument()->getProjections();
2838 doReconstructFBP (rProj, false);
2842 ProjectionFileView::doReconstructFBP (const Projections& rProj, bool bRebinToParallel)
2844 ReconstructionROI defaultROI;
2845 defaultROI.m_dXMin = -rProj.phmLen() / 2;
2846 defaultROI.m_dXMax = defaultROI.m_dXMin + rProj.phmLen();
2847 defaultROI.m_dYMin = -rProj.phmLen() / 2;
2848 defaultROI.m_dYMax = defaultROI.m_dYMin + rProj.phmLen();
2850 DialogGetReconstructionParameters dialogReconstruction (getFrameForChild(), m_iDefaultNX, m_iDefaultNY,
2851 m_iDefaultFilter, m_dDefaultFilterParam, m_iDefaultFilterMethod, m_iDefaultFilterGeneration,
2852 m_iDefaultZeropad, m_iDefaultInterpolation, m_iDefaultInterpParam, m_iDefaultBackprojector,
2853 m_iDefaultTrace, &defaultROI);
2855 int retVal = dialogReconstruction.ShowModal();
2856 if (retVal != wxID_OK)
2859 m_iDefaultNX = dialogReconstruction.getXSize();
2860 m_iDefaultNY = dialogReconstruction.getYSize();
2861 wxString optFilterName = dialogReconstruction.getFilterName();
2862 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
2863 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
2864 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
2865 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
2866 m_iDefaultZeropad = dialogReconstruction.getZeropad();
2867 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
2868 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
2869 wxString optInterpName = dialogReconstruction.getInterpName();
2870 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
2871 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
2872 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
2873 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
2874 m_iDefaultTrace = dialogReconstruction.getTrace();
2875 dialogReconstruction.getROI (&defaultROI);
2877 if (m_iDefaultNX <= 0 && m_iDefaultNY <= 0)
2880 std::ostringstream os;
2881 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();
2882 if (bRebinToParallel)
2883 os << "; Interpolate to Parallel";
2886 ImageFile* pImageFile = NULL;
2887 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2888 pImageFile = new ImageFile (m_iDefaultNX, m_iDefaultNY);
2889 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2890 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2891 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace,
2892 &defaultROI, bRebinToParallel);
2894 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstructor, rProj, *pImageFile, m_iDefaultTrace, getFrameForChild());
2895 for (int iView = 0; iView < rProj.nView(); iView++) {
2897 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView, true)) {
2898 delete pDlgReconstruct;
2899 delete pReconstructor;
2904 while (pDlgReconstruct->isPaused()) {
2909 pReconstructor->postProcessing();
2910 delete pDlgReconstruct;
2911 delete pReconstructor;
2914 if (theApp->getUseBackgroundTasks()) {
2915 ReconstructorSupervisorThread* pReconstructor = new ReconstructorSupervisorThread (this, m_iDefaultNX,
2916 m_iDefaultNY, optFilterName.c_str(), m_dDefaultFilterParam, optFilterMethodName.c_str(),
2917 m_iDefaultZeropad, optFilterGenerationName.c_str(), optInterpName.c_str(), m_iDefaultInterpParam,
2918 optBackprojectName.c_str(), os.str().c_str(), &defaultROI, bRebinToParallel);
2919 if (pReconstructor->Create() != wxTHREAD_NO_ERROR) {
2920 sys_error (ERR_SEVERE, "Error creating reconstructor thread");
2921 delete pReconstructor;
2924 pReconstructor->SetPriority (60);
2925 pReconstructor->Run();
2930 pImageFile = new ImageFile (m_iDefaultNX, m_iDefaultNY);
2931 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2932 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2933 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2934 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace,
2935 &defaultROI, bRebinToParallel);
2937 for (int iView = 0; iView < rProj.nView(); iView++) {
2938 pReconstructor->reconstructView (iView, 1);
2939 if (! dlgProgress.Update (iView + 1)) {
2940 delete pReconstructor;
2941 return; // don't make new window, thread will do this
2944 pReconstructor->postProcessing();
2945 delete pReconstructor;
2948 ImageFileDocument* pReconDoc = theApp->newImageDoc();
2950 sys_error (ERR_SEVERE, "Unable to create image file");
2953 pReconDoc->setImageFile (pImageFile);
2954 if (theApp->getAskDeleteNewDocs())
2955 pReconDoc->Modify (true);
2956 *theApp->getLog() << os.str().c_str() << "\n";
2957 pImageFile->labelAdd (rProj.getLabel());
2958 pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd());
2960 // if (ImageFileView* rasterView = pReconDoc->getView()) {
2961 // rasterView->getFrame()->Show(true);
2962 // rasterView->getFrame()->SetFocus();
2963 // rasterView->OnUpdate (rasterView, NULL);
2965 // causes loss of frame in wxGTK
2966 pReconDoc->GetFirstView()->GetFrame()->Show(true);
2967 pReconDoc->UpdateAllViews ();
2968 // pReconDoc->Activate();
2973 ProjectionFileView::OnArtifactReduction (wxCommandEvent& event)
2978 ProjectionFileCanvas*
2979 ProjectionFileView::CreateCanvas (wxFrame *parent)
2981 ProjectionFileCanvas* pCanvas;
2983 parent->GetClientSize(&width, &height);
2985 pCanvas = new ProjectionFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
2987 pCanvas->SetScrollbars(20, 20, 50, 50);
2988 pCanvas->SetBackgroundColour(*wxWHITE);
2999 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
3002 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
3004 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
3006 theApp->setIconForFrame (subframe);
3008 m_pFileMenu = new wxMenu;
3010 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3011 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3012 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3013 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3014 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3015 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3017 m_pFileMenu->AppendSeparator();
3018 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
3020 m_pFileMenu->AppendSeparator();
3021 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3022 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3023 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3024 m_pFileMenu->AppendSeparator();
3025 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3027 m_pFileMenu->AppendSeparator();
3028 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3029 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");
3051 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Fourier...\tCtrl-E", "Reconstruct image using inverse Fourier");
3053 wxMenu *help_menu = new wxMenu;
3054 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3055 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3056 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3057 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3059 wxMenuBar *menu_bar = new wxMenuBar;
3061 menu_bar->Append (m_pFileMenu, "&File");
3062 menu_bar->Append (convert_menu, "&Convert");
3063 // menu_bar->Append (filter_menu, "Fi<er");
3064 menu_bar->Append (analyze_menu, "&Analyze");
3065 menu_bar->Append (reconstruct_menu, "&Reconstruct");
3066 menu_bar->Append (help_menu, "&Help");
3068 subframe->SetMenuBar(menu_bar);
3069 subframe->Centre(wxBOTH);
3071 wxAcceleratorEntry accelEntries[7];
3072 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('L'), PJMENU_CONVERT_POLAR);
3073 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('T'), PJMENU_CONVERT_FFT_POLAR);
3074 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('R'), PJMENU_RECONSTRUCT_FBP);
3075 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('B'), PJMENU_RECONSTRUCT_FBP_REBIN);
3076 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('E'), PJMENU_RECONSTRUCT_FOURIER);
3077 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('I'), PJMENU_FILE_PROPERTIES);
3078 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('H'), PJMENU_PLOT_TTHETA_SAMPLING);
3079 wxAcceleratorTable accelTable (7, accelEntries);
3080 subframe->SetAcceleratorTable (accelTable);
3087 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
3089 m_pFrame = CreateChildFrame(doc, this);
3093 m_pFrame->GetClientSize (&width, &height);
3094 m_pFrame->SetTitle ("ProjectionFileView");
3095 m_pCanvas = CreateCanvas (m_pFrame);
3098 int x, y; // X requires a forced resize
3099 m_pFrame->GetSize(&x, &y);
3100 m_pFrame->SetSize(-1, -1, x, y);
3103 m_pFrame->Show(true);
3110 ProjectionFileView::OnDraw (wxDC* dc)
3112 wxSize clientSize = m_pFrame->GetClientSize();
3113 wxSize bestSize = m_pCanvas->GetBestSize();
3115 if (clientSize.x > bestSize.x || clientSize.y > bestSize.y)
3116 m_pFrame->SetClientSize (bestSize);
3119 dc->DrawBitmap (m_bitmap, 0, 0, false);
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);
3162 m_bitmap = image.ConvertToBitmap();
3166 xSize = clamp (xSize, 0, 800);
3167 ySize = clamp (ySize, 0, 800);
3168 m_pFrame->SetClientSize (xSize, ySize);
3169 m_pCanvas->SetScrollbars (20, 20, nDet/20, nView/20);
3173 m_pCanvas->Refresh();
3177 ProjectionFileView::OnClose (bool deleteWindow)
3179 //GetDocumentManager()->ActivateView (this, false, true);
3180 if (! GetDocument() || ! GetDocument()->Close())
3185 m_pCanvas->setView(NULL);
3188 wxString s(wxTheApp->GetAppName());
3190 m_pFrame->SetTitle(s);
3197 if (GetDocument() && GetDocument()->getBadFileOpen())
3198 ::wxYield(); // wxWindows bug workaround
3207 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
3208 : wxScrolledWindow(frame, -1, pos, size, style)
3213 PlotFileCanvas::~PlotFileCanvas ()
3219 PlotFileCanvas::OnDraw(wxDC& dc)
3222 m_pView->OnDraw(& dc);
3228 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
3230 BEGIN_EVENT_TABLE(PlotFileView, wxView)
3231 EVT_MENU(PLOTMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
3232 EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
3233 EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
3234 EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
3237 PlotFileView::PlotFileView()
3238 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pEZPlot(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
3242 PlotFileView::~PlotFileView()
3247 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
3251 PlotFileView::OnProperties (wxCommandEvent& event)
3253 const PlotFile& rPlot = GetDocument()->getPlotFile();
3254 std::ostringstream os;
3255 os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
3256 rPlot.printHeadersBrief (os);
3257 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<<\n";
3258 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
3259 dialogMsg.ShowModal();
3260 GetDocument()->Activate();
3265 PlotFileView::OnScaleAuto (wxCommandEvent& event)
3267 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3268 double min, max, mean, mode, median, stddev;
3269 rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
3270 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
3271 int iRetVal = dialogAutoScale.ShowModal();
3272 if (iRetVal == wxID_OK) {
3273 m_bMinSpecified = true;
3274 m_bMaxSpecified = true;
3276 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
3279 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
3280 OnUpdate (this, NULL);
3283 GetDocument()->Activate();
3287 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
3289 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3293 if (! m_bMinSpecified || ! m_bMaxSpecified) {
3294 if (! rPlotFile.getMinMax (1, min, max)) {
3295 *theApp->getLog() << "Error: unable to find Min/Max\n";
3300 if (m_bMinSpecified)
3302 if (m_bMaxSpecified)
3305 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Y-axis Minimum & Maximum", min, max);
3306 int retVal = dialogMinMax.ShowModal();
3307 if (retVal == wxID_OK) {
3308 m_bMinSpecified = true;
3309 m_bMaxSpecified = true;
3310 m_dMinPixel = dialogMinMax.getMinimum();
3311 m_dMaxPixel = dialogMinMax.getMaximum();
3312 OnUpdate (this, NULL);
3314 GetDocument()->Activate();
3318 PlotFileView::OnScaleFull (wxCommandEvent& event)
3320 if (m_bMinSpecified || m_bMaxSpecified) {
3321 m_bMinSpecified = false;
3322 m_bMaxSpecified = false;
3323 OnUpdate (this, NULL);
3325 GetDocument()->Activate();
3330 PlotFileView::CreateCanvas (wxFrame* parent)
3332 PlotFileCanvas* pCanvas;
3334 parent->GetClientSize(&width, &height);
3336 pCanvas = new PlotFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
3338 pCanvas->SetBackgroundColour(*wxWHITE);
3349 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
3352 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
3354 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
3356 theApp->setIconForFrame (subframe);
3358 m_pFileMenu = new wxMenu;
3360 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3361 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3362 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3363 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3364 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3365 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3367 m_pFileMenu->AppendSeparator();
3368 m_pFileMenu->Append(PLOTMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
3370 m_pFileMenu->AppendSeparator();
3371 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3372 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3373 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3374 m_pFileMenu->AppendSeparator();
3375 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3377 m_pFileMenu->AppendSeparator();
3378 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3379 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3381 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3382 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3384 wxMenu *view_menu = new wxMenu;
3385 view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...\tCtrl-E");
3386 view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
3387 view_menu->Append(PLOTMENU_VIEW_SCALE_FULL, "Display &Full Scale\tCtrl-U");
3389 wxMenu *help_menu = new wxMenu;
3390 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3391 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3392 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3393 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3395 wxMenuBar *menu_bar = new wxMenuBar;
3397 menu_bar->Append(m_pFileMenu, "&File");
3398 menu_bar->Append(view_menu, "&View");
3399 menu_bar->Append(help_menu, "&Help");
3401 subframe->SetMenuBar(menu_bar);
3402 subframe->Centre(wxBOTH);
3404 wxAcceleratorEntry accelEntries[4];
3405 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('E'), PLOTMENU_VIEW_SCALE_MINMAX);
3406 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('A'), PLOTMENU_VIEW_SCALE_AUTO);
3407 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('U'), PLOTMENU_VIEW_SCALE_FULL);
3408 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), PLOTMENU_FILE_PROPERTIES);
3409 wxAcceleratorTable accelTable (4, accelEntries);
3410 subframe->SetAcceleratorTable (accelTable);
3417 PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
3419 m_pFrame = CreateChildFrame(doc, this);
3422 m_bMinSpecified = false;
3423 m_bMaxSpecified = false;
3424 m_dAutoScaleFactor = 1.;
3427 m_pFrame->GetClientSize(&width, &height);
3428 m_pFrame->SetTitle ("Plot File");
3429 m_pCanvas = CreateCanvas (m_pFrame);
3432 int x, y; // X requires a forced resize
3433 m_pFrame->GetSize(&x, &y);
3434 m_pFrame->SetSize(-1, -1, x, y);
3437 m_pFrame->Show(true);
3444 PlotFileView::OnDraw (wxDC* dc)
3446 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3447 const int iNColumns = rPlotFile.getNumColumns();
3448 const int iNRecords = rPlotFile.getNumRecords();
3450 if (iNColumns > 0 && iNRecords > 0) {
3452 m_pCanvas->GetClientSize (&xsize, &ysize);
3453 SGPDriver driver (dc, xsize, ysize);
3456 m_pEZPlot->plot (&sgp);
3462 PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3464 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3465 const int iNColumns = rPlotFile.getNumColumns();
3466 const int iNRecords = rPlotFile.getNumRecords();
3467 const bool bScatterPlot = rPlotFile.getIsScatterPlot();
3469 if (iNColumns > 0 && iNRecords > 0) {
3472 m_pEZPlot = new EZPlot;
3474 for (unsigned int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)
3475 m_pEZPlot->ezset (rPlotFile.getEzsetCommand (iEzset));
3477 if (m_bMinSpecified) {
3478 std::ostringstream os;
3479 os << "ymin " << m_dMinPixel;
3480 m_pEZPlot->ezset (os.str());
3483 if (m_bMaxSpecified) {
3484 std::ostringstream os;
3485 os << "ymax " << m_dMaxPixel;
3486 m_pEZPlot->ezset (os.str());
3489 m_pEZPlot->ezset("box");
3490 m_pEZPlot->ezset("grid");
3492 double* pdX = new double [iNRecords];
3493 double* pdY = new double [iNRecords];
3494 if (! bScatterPlot) {
3495 rPlotFile.getColumn (0, pdX);
3497 for (int iCol = 1; iCol < iNColumns; iCol++) {
3498 rPlotFile.getColumn (iCol, pdY);
3499 m_pEZPlot->addCurve (pdX, pdY, iNRecords);
3502 rPlotFile.getColumn (0, pdX);
3503 rPlotFile.getColumn (1, pdY);
3504 m_pEZPlot->addCurve (pdX, pdY, iNRecords);
3511 m_pCanvas->Refresh();
3515 PlotFileView::OnClose (bool deleteWindow)
3517 //GetDocumentManager()->ActivateView (this, false, true);
3518 if (! GetDocument() || ! GetDocument()->Close())
3523 m_pCanvas->setView (NULL);
3526 wxString s(wxTheApp->GetAppName());
3528 m_pFrame->SetTitle(s);
3534 if (GetDocument() && GetDocument()->getBadFileOpen())
3535 ::wxYield(); // wxWindows bug workaround
3542 ////////////////////////////////////////////////////////////////
3545 IMPLEMENT_DYNAMIC_CLASS(TextFileView, wxView)
3547 TextFileView::~TextFileView()
3549 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
3550 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
3553 bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
3555 m_pFrame = CreateChildFrame(doc, this);
3556 SetFrame (m_pFrame);
3559 m_pFrame->GetClientSize(&width, &height);
3560 m_pFrame->SetTitle("TextFile");
3561 m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
3562 m_pFrame->SetTitle("Log");
3565 // X seems to require a forced resize
3567 frame->GetSize(&x, &y);
3568 frame->SetSize(-1, -1, x, y);
3571 m_pFrame->Show (true);
3577 // Handled by wxTextWindow
3578 void TextFileView::OnDraw(wxDC *WXUNUSED(dc) )
3582 void TextFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3587 TextFileView::OnClose (bool deleteWindow)
3589 if (! theApp->getMainFrame()->getShuttingDown())
3593 //GetDocumentManager()->ActivateView (this, false, true);
3594 if (! GetDocument() || ! GetDocument()->Close())
3601 if (GetDocument() && GetDocument()->getBadFileOpen())
3602 ::wxYield(); // wxWindows bug workaround
3613 TextFileView::CreateChildFrame (wxDocument *doc, wxView *view)
3616 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(0,0), wxDEFAULT_FRAME_STYLE, "Log");
3618 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE, "Log");
3620 theApp->setIconForFrame (subframe);
3622 m_pFileMenu = new wxMenu;
3624 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3625 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3626 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3627 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3628 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3629 // m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3631 m_pFileMenu->AppendSeparator();
3632 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3633 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3634 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3635 m_pFileMenu->AppendSeparator();
3636 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");
3642 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3643 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3645 wxMenu *help_menu = new wxMenu;
3646 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3647 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3648 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3649 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3651 wxMenuBar *menu_bar = new wxMenuBar;
3653 menu_bar->Append(m_pFileMenu, "&File");
3654 menu_bar->Append(help_menu, "&Help");
3656 subframe->SetMenuBar(menu_bar);
3657 subframe->Centre(wxBOTH);
3663 // Define a constructor for my text subwindow
3664 TextFileCanvas::TextFileCanvas (TextFileView* v, wxFrame* frame, const wxPoint& pos, const wxSize& size, long style)
3665 : wxTextCtrl (frame, -1, "", pos, size, style), m_pView(v)
3669 TextFileCanvas::~TextFileCanvas ()