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.145 2001/03/30 21:01:15 kevin Exp $
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
28 #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.;
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);
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);
1978 ySize = xSize = (xSize / 4);
1979 return wxSize (xSize, ySize);
1986 IMPLEMENT_DYNAMIC_CLASS(PhantomFileView, wxView)
1988 BEGIN_EVENT_TABLE(PhantomFileView, wxView)
1989 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomFileView::OnProperties)
1990 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomFileView::OnRasterize)
1991 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomFileView::OnProjections)
1994 PhantomFileView::PhantomFileView()
1995 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0)
1997 #if defined(DEBUG) || defined(_DEBUG)
1998 m_iDefaultNDet = 165;
1999 m_iDefaultNView = 180;
2000 m_iDefaultNSample = 1;
2002 m_iDefaultNDet = 367;
2003 m_iDefaultNView = 320;
2004 m_iDefaultNSample = 2;
2006 m_dDefaultRotation = 1;
2007 m_dDefaultFocalLength = 2;
2008 m_dDefaultCenterDetectorLength = 2;
2009 m_dDefaultViewRatio = 1;
2010 m_dDefaultScanRatio = 1;
2011 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
2012 m_iDefaultTrace = Trace::TRACE_NONE;
2015 m_iDefaultRasterNX = 115;
2016 m_iDefaultRasterNY = 115;
2017 m_iDefaultRasterNSamples = 1;
2019 m_iDefaultRasterNX = 256;
2020 m_iDefaultRasterNY = 256;
2021 m_iDefaultRasterNSamples = 2;
2023 m_dDefaultRasterViewRatio = 1;
2026 PhantomFileView::~PhantomFileView()
2028 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2029 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
2033 PhantomFileView::OnProperties (wxCommandEvent& event)
2035 const int idPhantom = GetDocument()->getPhantomID();
2036 const wxString& namePhantom = GetDocument()->getPhantomName();
2037 std::ostringstream os;
2038 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")" << "\n";
2039 const Phantom& rPhantom = GetDocument()->getPhantom();
2040 rPhantom.printDefinitions (os);
2042 rPhantom.print (os);
2044 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2045 wxMessageBox (os.str().c_str(), "Phantom Properties");
2046 GetDocument()->Activate();
2051 PhantomFileView::OnProjections (wxCommandEvent& event)
2053 DialogGetProjectionParameters dialogProjection (getFrameForChild(),
2054 m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation,
2055 m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio,
2056 m_iDefaultGeometry, m_iDefaultTrace);
2057 int retVal = dialogProjection.ShowModal();
2058 if (retVal != wxID_OK)
2061 m_iDefaultNDet = dialogProjection.getNDet();
2062 m_iDefaultNView = dialogProjection.getNView();
2063 m_iDefaultNSample = dialogProjection.getNSamples();
2064 m_iDefaultTrace = dialogProjection.getTrace();
2065 m_dDefaultRotation = dialogProjection.getRotAngle();
2066 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
2067 m_dDefaultCenterDetectorLength = dialogProjection.getCenterDetectorLengthRatio();
2068 m_dDefaultViewRatio = dialogProjection.getViewRatio();
2069 m_dDefaultScanRatio = dialogProjection.getScanRatio();
2070 wxString sGeometry = dialogProjection.getGeometry();
2071 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
2072 double dRotationRadians = m_dDefaultRotation;
2073 m_dDefaultRotation /= TWOPI; // convert back to fraction of a circle
2075 if (m_iDefaultNDet <= 0 || m_iDefaultNView <= 0 || sGeometry == "")
2078 const Phantom& rPhantom = GetDocument()->getPhantom();
2079 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample,
2080 dRotationRadians, m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio);
2081 if (theScanner.fail()) {
2082 wxString msg = "Failed making scanner\n";
2083 msg += theScanner.failMessage().c_str();
2084 *theApp->getLog() << msg << "\n";
2085 wxMessageBox (msg, "Error");
2089 std::ostringstream os;
2090 os << "Projections for " << rPhantom.name() << ": nDet=" << m_iDefaultNDet
2091 << ", nView=" << m_iDefaultNView << ", nSamples=" << m_iDefaultNSample
2092 << ", RotAngle=" << m_dDefaultRotation << ", FocalLengthRatio=" << m_dDefaultFocalLength
2093 << ", CenterDetectorLengthRatio=" << m_dDefaultCenterDetectorLength
2094 << ", ViewRatio=" << m_dDefaultViewRatio << ", ScanRatio=" << m_dDefaultScanRatio
2095 << ", Geometry=" << sGeometry.c_str() << ", FanBeamAngle=" <<
2096 convertRadiansToDegrees (theScanner.fanBeamAngle());
2099 Projections* pProj = NULL;
2100 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2101 pProj = new Projections;
2102 pProj->initFromScanner (theScanner);
2104 ProjectionsDialog dialogProjections (theScanner, *pProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(getFrameForChild()));
2105 for (int iView = 0; iView < pProj->nView(); iView++) {
2107 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
2112 while (dialogProjections.isPaused()) {
2119 if (theApp->getUseBackgroundTasks()) {
2120 ProjectorSupervisorThread* pProjector = new ProjectorSupervisorThread (this, m_iDefaultNDet,
2121 m_iDefaultNView, sGeometry.c_str(), m_iDefaultNSample, dRotationRadians,
2122 m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio, os.str().c_str());
2123 if (pProjector->Create() != wxTHREAD_NO_ERROR) {
2124 sys_error (ERR_SEVERE, "Error creating projector thread");
2128 pProjector->SetPriority(60);
2132 #endif // HAVE_WXTHREADS
2134 pProj = new Projections;
2135 pProj->initFromScanner (theScanner);
2136 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), pProj->nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2137 for (int i = 0; i < pProj->nView(); i++) {
2138 theScanner.collectProjections (*pProj, rPhantom, i, 1, true, m_iDefaultTrace);
2139 if (! dlgProgress.Update (i+1)) {
2147 *theApp->getLog() << os.str().c_str() << "\n";
2148 pProj->setRemark (os.str());
2149 pProj->setCalcTime (timer.timerEnd());
2151 ProjectionFileDocument* pProjectionDoc = theApp->newProjectionDoc();
2152 if (! pProjectionDoc) {
2153 sys_error (ERR_SEVERE, "Unable to create projection document");
2156 pProjectionDoc->setProjections (pProj);
2157 ProjectionFileView* projView = pProjectionDoc->getView();
2159 projView->OnUpdate (projView, NULL);
2160 if (projView->getCanvas())
2161 projView->getCanvas()->SetClientSize (m_iDefaultNDet, m_iDefaultNView);
2162 if (wxFrame* pFrame = projView->getFrame()) {
2167 GetDocumentManager()->ActivateView (projView, true, false);
2169 if (theApp->getAskDeleteNewDocs())
2170 pProjectionDoc-> Modify(true);
2171 pProjectionDoc->UpdateAllViews (this);
2172 pProjectionDoc->Activate();
2177 PhantomFileView::OnRasterize (wxCommandEvent& event)
2179 DialogGetRasterParameters dialogRaster (getFrameForChild(), m_iDefaultRasterNX, m_iDefaultRasterNY,
2180 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio);
2181 int retVal = dialogRaster.ShowModal();
2182 if (retVal != wxID_OK)
2185 m_iDefaultRasterNX = dialogRaster.getXSize();
2186 m_iDefaultRasterNY = dialogRaster.getYSize();
2187 m_iDefaultRasterNSamples = dialogRaster.getNSamples();
2188 m_dDefaultRasterViewRatio = dialogRaster.getViewRatio();
2189 if (m_iDefaultRasterNSamples < 1)
2190 m_iDefaultRasterNSamples = 1;
2191 if (m_dDefaultRasterViewRatio < 0)
2192 m_dDefaultRasterViewRatio = 0;
2193 if (m_iDefaultRasterNX <= 0 || m_iDefaultRasterNY <= 0)
2196 const Phantom& rPhantom = GetDocument()->getPhantom();
2197 std::ostringstream os;
2198 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << m_iDefaultRasterNX << ", YSize="
2199 << m_iDefaultRasterNY << ", ViewRatio=" << m_dDefaultRasterViewRatio << ", nSamples="
2200 << m_iDefaultRasterNSamples;;
2203 if (theApp->getUseBackgroundTasks()) {
2204 RasterizerSupervisorThread* pThread = new RasterizerSupervisorThread (this, m_iDefaultRasterNX, m_iDefaultRasterNY,
2205 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio, os.str().c_str());
2206 if (pThread->Create() != wxTHREAD_NO_ERROR) {
2207 *theApp->getLog() << "Error creating rasterizer thread\n";
2210 pThread->SetPriority (60);
2215 ImageFile* pImageFile = new ImageFile (m_iDefaultRasterNX, m_iDefaultRasterNY);
2216 wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"),
2217 pImageFile->nx() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2219 for (unsigned int i = 0; i < pImageFile->nx(); i++) {
2220 rPhantom.convertToImagefile (*pImageFile, m_dDefaultRasterViewRatio, m_iDefaultRasterNSamples, Trace::TRACE_NONE, i, 1, true);
2221 if (! dlgProgress.Update (i+1)) {
2227 ImageFileDocument* pRasterDoc = theApp->newImageDoc();
2229 sys_error (ERR_SEVERE, "Unable to create image file");
2232 pRasterDoc->setImageFile (pImageFile);
2233 if (theApp->getAskDeleteNewDocs())
2234 pRasterDoc->Modify (true);
2235 pRasterDoc->UpdateAllViews (this);
2236 pRasterDoc->getView()->getFrame()->Show(true);
2237 *theApp->getLog() << os.str().c_str() << "\n";
2238 pImageFile->labelAdd (os.str().c_str(), timer.timerEnd());
2239 ImageFileView* rasterView = pRasterDoc->getView();
2241 rasterView->getFrame()->SetFocus();
2242 rasterView->OnUpdate (rasterView, NULL);
2244 pRasterDoc->Activate();
2250 PhantomFileView::CreateCanvas (wxFrame *parent)
2252 PhantomCanvas* pCanvas;
2254 pCanvas = new PhantomCanvas (this, parent, wxPoint(0, 0), wxSize(0,0), 0);
2255 pCanvas->SetBackgroundColour(*wxWHITE);
2266 PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2269 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2271 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2273 theApp->setIconForFrame (subframe);
2275 m_pFileMenu = new wxMenu;
2277 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2278 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2279 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2280 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2281 m_pFileMenu->Append(wxID_CLOSE, "&Close");
2283 m_pFileMenu->AppendSeparator();
2284 m_pFileMenu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
2286 m_pFileMenu->AppendSeparator();
2287 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2288 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2289 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2290 m_pFileMenu->AppendSeparator();
2291 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
2293 m_pFileMenu->AppendSeparator();
2294 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
2295 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2297 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2298 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2300 wxMenu *process_menu = new wxMenu;
2301 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...\tCtrl-R");
2302 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...\tCtrl-J");
2304 wxMenu *help_menu = new wxMenu;
2305 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2306 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
2307 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
2308 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2310 wxMenuBar *menu_bar = new wxMenuBar;
2312 menu_bar->Append(m_pFileMenu, "&File");
2313 menu_bar->Append(process_menu, "&Process");
2314 menu_bar->Append(help_menu, "&Help");
2316 subframe->SetMenuBar(menu_bar);
2317 subframe->Centre(wxBOTH);
2319 wxAcceleratorEntry accelEntries[3];
2320 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('J'), PHMMENU_PROCESS_PROJECTIONS);
2321 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('R'), PHMMENU_PROCESS_RASTERIZE);
2322 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('I'), PHMMENU_FILE_PROPERTIES);
2323 wxAcceleratorTable accelTable (3, accelEntries);
2324 subframe->SetAcceleratorTable (accelTable);
2331 PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2333 m_pFrame = CreateChildFrame(doc, this);
2335 m_pCanvas = CreateCanvas (m_pFrame);
2336 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
2337 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
2339 m_pFrame->SetTitle ("PhantomFileView");
2342 int x, y; // X requires a forced resize
2343 m_pFrame->GetSize(&x, &y);
2344 m_pFrame->SetSize(-1, -1, x, y);
2347 m_pFrame->Show(true);
2354 PhantomFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2357 m_pCanvas->Refresh();
2361 PhantomFileView::OnClose (bool deleteWindow)
2363 //GetDocumentManager()->ActivateView (this, false, true);
2364 if (! GetDocument() || ! GetDocument()->Close())
2369 m_pCanvas->setView(NULL);
2372 wxString s(wxTheApp->GetAppName());
2374 m_pFrame->SetTitle(s);
2381 if (GetDocument() && GetDocument()->getBadFileOpen())
2382 ::wxYield(); // wxWindows bug workaround
2389 PhantomFileView::OnDraw (wxDC* dc)
2392 m_pCanvas->GetClientSize (&xsize, &ysize);
2393 SGPDriver driver (dc, xsize, ysize);
2395 const Phantom& rPhantom = GetDocument()->getPhantom();
2396 sgp.setColor (C_RED);
2397 rPhantom.show (sgp);
2402 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2403 : wxScrolledWindow(frame, -1, pos, size, style)
2408 ProjectionFileCanvas::~ProjectionFileCanvas ()
2414 ProjectionFileCanvas::OnDraw(wxDC& dc)
2417 m_pView->OnDraw(& dc);
2421 ProjectionFileCanvas::GetBestSize () const
2425 Projections& rProj = m_pView->GetDocument()->getProjections();
2426 best.Set (rProj.nDet(), rProj.nView());
2433 // ProjectionFileView
2435 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
2437 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
2438 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
2439 EVT_MENU(PJMENU_RECONSTRUCT_FBP, ProjectionFileView::OnReconstructFBP)
2440 EVT_MENU(PJMENU_RECONSTRUCT_FBP_REBIN, ProjectionFileView::OnReconstructFBPRebin)
2441 EVT_MENU(PJMENU_RECONSTRUCT_FOURIER, ProjectionFileView::OnReconstructFourier)
2442 EVT_MENU(PJMENU_CONVERT_RECTANGULAR, ProjectionFileView::OnConvertRectangular)
2443 EVT_MENU(PJMENU_CONVERT_POLAR, ProjectionFileView::OnConvertPolar)
2444 EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
2445 EVT_MENU(PJMENU_CONVERT_PARALLEL, ProjectionFileView::OnConvertParallel)
2446 EVT_MENU(PJMENU_PLOT_TTHETA_SAMPLING, ProjectionFileView::OnPlotTThetaSampling)
2447 EVT_MENU(PJMENU_PLOT_HISTOGRAM, ProjectionFileView::OnPlotHistogram)
2448 EVT_MENU(PJMENU_ARTIFACT_REDUCTION, ProjectionFileView::OnArtifactReduction)
2452 ProjectionFileView::ProjectionFileView()
2453 : wxView(), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0)
2463 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
2464 m_dDefaultFilterParam = 1.;
2466 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
2467 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
2469 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
2470 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
2472 m_iDefaultZeropad = 1;
2473 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF;
2474 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
2475 m_iDefaultInterpParam = 1;
2476 m_iDefaultTrace = Trace::TRACE_NONE;
2478 m_iDefaultPolarNX = 256;
2479 m_iDefaultPolarNY = 256;
2480 m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR;
2481 m_iDefaultPolarZeropad = 1;
2484 ProjectionFileView::~ProjectionFileView()
2486 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2487 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2491 ProjectionFileView::OnProperties (wxCommandEvent& event)
2493 const Projections& rProj = GetDocument()->getProjections();
2494 std::ostringstream os;
2495 rProj.printScanInfo(os);
2496 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2497 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
2498 dialogMsg.ShowModal();
2499 GetDocument()->Activate();
2504 ProjectionFileView::OnConvertRectangular (wxCommandEvent& event)
2506 Projections& rProj = GetDocument()->getProjections();
2508 int nDet = rProj.nDet();
2509 int nView = rProj.nView();
2510 ImageFile* pIF = new ImageFile (nDet, nView);
2511 ImageFileArray v = pIF->getArray();
2512 for (int iv = 0; iv < nView; iv++) {
2513 DetectorValue* detval = rProj.getDetectorArray(iv).detValues();
2515 for (int id = 0; id < nDet; id++)
2516 v[id][iv] = detval[id];
2519 ImageFileDocument* pRectDoc = theApp->newImageDoc ();
2521 sys_error (ERR_SEVERE, "Unable to create image file");
2524 pRectDoc->setImageFile (pIF);
2525 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2526 std::ostringstream os;
2527 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to rectangular image";
2528 *theApp->getLog() << os.str().c_str() << "\n";
2529 pIF->labelAdd (os.str().c_str());
2530 if (theApp->getAskDeleteNewDocs())
2531 pRectDoc->Modify (true);
2532 pRectDoc->getView()->getFrame()->Show(true);
2533 pRectDoc->UpdateAllViews ();
2534 pRectDoc->Activate();
2538 ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
2540 Projections& rProj = GetDocument()->getProjections();
2541 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2542 m_iDefaultPolarInterpolation, -1, IDH_DLG_POLAR);
2543 if (dialogPolar.ShowModal() == wxID_OK) {
2544 wxProgressDialog dlgProgress (wxString("Convert Polar"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2545 wxString strInterpolation (dialogPolar.getInterpolationName());
2546 m_iDefaultPolarNX = dialogPolar.getXSize();
2547 m_iDefaultPolarNY = dialogPolar.getYSize();
2548 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2549 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2550 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2552 if (! rProj.convertPolar (*pIF, m_iDefaultPolarInterpolation)) {
2554 *theApp->getLog() << "Error converting to Polar\n";
2558 pPolarDoc = theApp->newImageDoc ();
2560 sys_error (ERR_SEVERE, "Unable to create image file");
2563 pPolarDoc->setImageFile (pIF);
2564 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2565 std::ostringstream os;
2566 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to polar image: xSize="
2567 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2568 << strInterpolation.c_str();
2569 *theApp->getLog() << os.str().c_str() << "\n";
2570 pIF->labelAdd (os.str().c_str());
2571 if (theApp->getAskDeleteNewDocs())
2572 pPolarDoc->Modify (true);
2573 pPolarDoc->getView()->getFrame()->Show(true);
2574 pPolarDoc->UpdateAllViews ();
2575 pPolarDoc->Activate();
2580 ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
2582 Projections& rProj = GetDocument()->getProjections();
2583 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert to FFT Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2584 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad, IDH_DLG_FFT_POLAR);
2585 if (dialogPolar.ShowModal() == wxID_OK) {
2586 wxProgressDialog dlgProgress (wxString("Convert FFT Polar"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2587 wxString strInterpolation (dialogPolar.getInterpolationName());
2588 m_iDefaultPolarNX = dialogPolar.getXSize();
2589 m_iDefaultPolarNY = dialogPolar.getYSize();
2590 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2591 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2593 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2594 if (! rProj.convertFFTPolar (*pIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad)) {
2596 *theApp->getLog() << "Error converting to polar\n";
2599 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2601 sys_error (ERR_SEVERE, "Unable to create image file");
2604 pPolarDoc->setImageFile (pIF);
2605 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2606 std::ostringstream os;
2607 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to FFT polar image: xSize="
2608 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2609 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2610 *theApp->getLog() << os.str().c_str() << "\n";
2611 pIF->labelAdd (os.str().c_str());
2612 if (theApp->getAskDeleteNewDocs())
2613 pPolarDoc->Modify (true);
2614 pPolarDoc->getView()->getFrame()->Show(true);
2615 pPolarDoc->UpdateAllViews ();
2616 pPolarDoc->Activate();
2621 ProjectionFileView::OnPlotTThetaSampling (wxCommandEvent& event)
2623 DialogGetThetaRange dlgTheta (this->getFrame(), ParallelRaysums::THETA_RANGE_UNCONSTRAINED);
2624 if (dlgTheta.ShowModal() != wxID_OK)
2627 int iThetaRange = dlgTheta.getThetaRange();
2629 Projections& rProj = GetDocument()->getProjections();
2630 ParallelRaysums parallel (&rProj, iThetaRange);
2631 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
2632 PlotFile& rPlot = pPlotDoc->getPlotFile();
2633 ParallelRaysums::CoordinateContainer& coordContainer = parallel.getCoordinates();
2634 double* pdT = new double [parallel.getNumCoordinates()];
2635 double* pdTheta = new double [parallel.getNumCoordinates()];
2637 for (int i = 0; i < parallel.getNumCoordinates(); i++) {
2638 pdT[i] = coordContainer[i]->m_dT;
2639 pdTheta[i] = coordContainer[i]->m_dTheta;
2641 rPlot.setCurveSize (2, parallel.getNumCoordinates(), true);
2642 rPlot.addEzsetCommand ("title T-Theta Sampling");
2643 rPlot.addEzsetCommand ("xlabel T");
2644 rPlot.addEzsetCommand ("ylabel Theta");
2645 rPlot.addEzsetCommand ("curve 1");
2646 if (rProj.nDet() < 50 && rProj.nView() < 50)
2647 rPlot.addEzsetCommand ("symbol 1"); // x symbol
2649 rPlot.addEzsetCommand ("symbol 6"); // point symbol
2650 rPlot.addEzsetCommand ("noline");
2651 rPlot.addColumn (0, pdT);
2652 rPlot.addColumn (1, pdTheta);
2655 if (theApp->getAskDeleteNewDocs())
2656 pPlotDoc->Modify (true);
2657 pPlotDoc->getView()->getFrame()->Show(true);
2658 pPlotDoc->UpdateAllViews ();
2659 pPlotDoc->Activate();
2664 ProjectionFileView::OnPlotHistogram (wxCommandEvent& event)
2666 Projections& rProj = GetDocument()->getProjections();
2667 int nDet = rProj.nDet();
2668 int nView = rProj.nView();
2670 if (nDet < 1 || nView < 1)
2673 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
2675 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
2679 DetectorValue* pdDetval = rProj.getDetectorArray(0).detValues();
2680 double dMin = pdDetval[0], dMax = pdDetval[0];
2682 for (int iv = 0; iv < nView; iv++) {
2683 pdDetval = rProj.getDetectorArray(iv).detValues();
2684 for (int id = 0; id < nDet; id++) {
2685 double dV = pdDetval[id];
2693 double* pX = new double [NUMBER_HISTOGRAM_BINS];
2694 double* pY = new double [NUMBER_HISTOGRAM_BINS];
2695 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
2697 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
2698 pX[i] = dMin + (i + 0.5) * dBinWidth;
2701 for (int j = 0; j < nView; j++) {
2702 pdDetval = rProj.getDetectorArray(j).detValues();
2703 for (int id = 0; id < nDet; id++) {
2704 int iBin = nearest<int> ((pdDetval[id] - dMin) / dBinWidth);
2705 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
2709 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
2710 std::ostringstream os;
2712 std::string title("title ");
2714 rPlotFile.addEzsetCommand (title.c_str());
2715 rPlotFile.addEzsetCommand ("xlabel Detector Value");
2716 rPlotFile.addEzsetCommand ("ylabel Count");
2717 rPlotFile.addEzsetCommand ("box");
2718 rPlotFile.addEzsetCommand ("grid");
2719 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
2720 rPlotFile.addColumn (0, pX);
2721 rPlotFile.addColumn (1, pY);
2722 rPlotFile.addDescription (rProj.remark());
2723 os << " plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
2724 *theApp->getLog() << os.str().c_str() << "\n";
2725 rPlotFile.addDescription (os.str().c_str());
2728 if (theApp->getAskDeleteNewDocs())
2729 pPlotDoc->Modify (true);
2730 pPlotDoc->getView()->getFrame()->Show(true);
2731 pPlotDoc->UpdateAllViews ();
2732 pPlotDoc->Activate();
2737 ProjectionFileView::OnConvertParallel (wxCommandEvent& event)
2739 Projections& rProj = GetDocument()->getProjections();
2740 if (rProj.geometry() == Scanner::GEOMETRY_PARALLEL) {
2741 wxMessageBox ("Projections are already parallel", "Error");
2744 wxProgressDialog dlgProgress (wxString("Convert to Parallel"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2745 Projections* pProjNew = rProj.interpolateToParallel();
2746 ProjectionFileDocument* pProjDocNew = theApp->newProjectionDoc();
2747 pProjDocNew->setProjections (pProjNew);
2749 if (ProjectionFileView* projView = pProjDocNew->getView()) {
2750 projView->OnUpdate (projView, NULL);
2751 if (projView->getCanvas())
2752 projView->getCanvas()->SetClientSize (pProjNew->nDet(), pProjNew->nView());
2753 if (wxFrame* pFrame = projView->getFrame()) {
2758 GetDocumentManager()->ActivateView (projView, true, false);
2760 if (theApp->getAskDeleteNewDocs())
2761 pProjDocNew-> Modify(true);
2762 pProjDocNew->UpdateAllViews (this);
2763 pProjDocNew->Activate();
2767 ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
2769 Projections& rProj = GetDocument()->getProjections();
2770 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Fourier Reconstruction", m_iDefaultPolarNX, m_iDefaultPolarNY,
2771 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad, IDH_DLG_RECON_FOURIER);
2772 if (dialogPolar.ShowModal() == wxID_OK) {
2773 wxProgressDialog dlgProgress (wxString("Reconstruction Fourier"), wxString("Reconstruction Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2774 wxString strInterpolation (dialogPolar.getInterpolationName());
2775 m_iDefaultPolarNX = dialogPolar.getXSize();
2776 m_iDefaultPolarNY = dialogPolar.getYSize();
2777 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2778 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2780 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2781 if (! rProj.convertFFTPolar (*pIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad)) {
2783 *theApp->getLog() << "Error converting to polar\n";
2789 pIF->magnitude(*pIF);
2790 Fourier::shuffleFourierToNaturalOrder (*pIF);
2792 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2794 sys_error (ERR_SEVERE, "Unable to create image file");
2797 pPolarDoc->setImageFile (pIF);
2798 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2799 std::ostringstream os;
2800 os << "Reconstruct Fourier " << GetFrame()->GetTitle().c_str() << ": xSize="
2801 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2802 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2803 *theApp->getLog() << os.str().c_str() << "\n";
2804 pIF->labelAdd (os.str().c_str());
2805 if (theApp->getAskDeleteNewDocs())
2806 pPolarDoc->Modify (true);
2807 pPolarDoc->getView()->getFrame()->Show(true);
2808 pPolarDoc->UpdateAllViews ();
2809 pPolarDoc->Activate();
2814 ProjectionFileView::OnReconstructFBPRebin (wxCommandEvent& event)
2816 Projections& rProj = GetDocument()->getProjections();
2817 doReconstructFBP (rProj, true);
2821 ProjectionFileView::OnReconstructFBP (wxCommandEvent& event)
2823 Projections& rProj = GetDocument()->getProjections();
2824 doReconstructFBP (rProj, false);
2828 ProjectionFileView::doReconstructFBP (const Projections& rProj, bool bRebinToParallel)
2830 ReconstructionROI defaultROI;
2831 defaultROI.m_dXMin = -rProj.phmLen() / 2;
2832 defaultROI.m_dXMax = defaultROI.m_dXMin + rProj.phmLen();
2833 defaultROI.m_dYMin = -rProj.phmLen() / 2;
2834 defaultROI.m_dYMax = defaultROI.m_dYMin + rProj.phmLen();
2836 DialogGetReconstructionParameters dialogReconstruction (getFrameForChild(), m_iDefaultNX, m_iDefaultNY,
2837 m_iDefaultFilter, m_dDefaultFilterParam, m_iDefaultFilterMethod, m_iDefaultFilterGeneration,
2838 m_iDefaultZeropad, m_iDefaultInterpolation, m_iDefaultInterpParam, m_iDefaultBackprojector,
2839 m_iDefaultTrace, &defaultROI);
2841 int retVal = dialogReconstruction.ShowModal();
2842 if (retVal != wxID_OK)
2845 m_iDefaultNX = dialogReconstruction.getXSize();
2846 m_iDefaultNY = dialogReconstruction.getYSize();
2847 wxString optFilterName = dialogReconstruction.getFilterName();
2848 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
2849 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
2850 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
2851 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
2852 m_iDefaultZeropad = dialogReconstruction.getZeropad();
2853 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
2854 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
2855 wxString optInterpName = dialogReconstruction.getInterpName();
2856 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
2857 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
2858 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
2859 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
2860 m_iDefaultTrace = dialogReconstruction.getTrace();
2861 dialogReconstruction.getROI (&defaultROI);
2863 if (m_iDefaultNX <= 0 && m_iDefaultNY <= 0)
2866 std::ostringstream os;
2867 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();
2868 if (bRebinToParallel)
2869 os << "; Interpolate to Parallel";
2872 ImageFile* pImageFile = NULL;
2873 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2874 pImageFile = new ImageFile (m_iDefaultNX, m_iDefaultNY);
2875 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2876 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2877 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace,
2878 &defaultROI, bRebinToParallel);
2880 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstructor, rProj, *pImageFile, m_iDefaultTrace, getFrameForChild());
2881 for (int iView = 0; iView < rProj.nView(); iView++) {
2883 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView, true)) {
2884 delete pDlgReconstruct;
2885 delete pReconstructor;
2890 while (pDlgReconstruct->isPaused()) {
2895 pReconstructor->postProcessing();
2896 delete pDlgReconstruct;
2897 delete pReconstructor;
2900 if (theApp->getUseBackgroundTasks()) {
2901 ReconstructorSupervisorThread* pReconstructor = new ReconstructorSupervisorThread (this, m_iDefaultNX,
2902 m_iDefaultNY, optFilterName.c_str(), m_dDefaultFilterParam, optFilterMethodName.c_str(),
2903 m_iDefaultZeropad, optFilterGenerationName.c_str(), optInterpName.c_str(), m_iDefaultInterpParam,
2904 optBackprojectName.c_str(), os.str().c_str(), &defaultROI, bRebinToParallel);
2905 if (pReconstructor->Create() != wxTHREAD_NO_ERROR) {
2906 sys_error (ERR_SEVERE, "Error creating reconstructor thread");
2907 delete pReconstructor;
2910 pReconstructor->SetPriority (60);
2911 pReconstructor->Run();
2916 pImageFile = new ImageFile (m_iDefaultNX, m_iDefaultNY);
2917 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2918 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2919 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2920 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace,
2921 &defaultROI, bRebinToParallel);
2923 for (int iView = 0; iView < rProj.nView(); iView++) {
2924 pReconstructor->reconstructView (iView, 1);
2925 if (! dlgProgress.Update (iView + 1)) {
2926 delete pReconstructor;
2927 return; // don't make new window, thread will do this
2930 pReconstructor->postProcessing();
2931 delete pReconstructor;
2934 ImageFileDocument* pReconDoc = theApp->newImageDoc();
2936 sys_error (ERR_SEVERE, "Unable to create image file");
2939 pReconDoc->setImageFile (pImageFile);
2940 if (theApp->getAskDeleteNewDocs())
2941 pReconDoc->Modify (true);
2942 pReconDoc->UpdateAllViews (this);
2943 pReconDoc->Activate();
2944 if (ImageFileView* rasterView = pReconDoc->getView()) {
2945 rasterView->OnUpdate (rasterView, NULL);
2946 rasterView->getFrame()->SetFocus();
2947 rasterView->getFrame()->Show(true);
2949 *theApp->getLog() << os.str().c_str() << "\n";
2950 pImageFile->labelAdd (rProj.getLabel());
2951 pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd());
2956 ProjectionFileView::OnArtifactReduction (wxCommandEvent& event)
2961 ProjectionFileCanvas*
2962 ProjectionFileView::CreateCanvas (wxFrame *parent)
2964 ProjectionFileCanvas* pCanvas;
2966 parent->GetClientSize(&width, &height);
2968 pCanvas = new ProjectionFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
2970 pCanvas->SetScrollbars(20, 20, 50, 50);
2971 pCanvas->SetBackgroundColour(*wxWHITE);
2982 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2985 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2987 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2989 theApp->setIconForFrame (subframe);
2991 m_pFileMenu = new wxMenu;
2993 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2994 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2995 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2996 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2997 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2998 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3000 m_pFileMenu->AppendSeparator();
3001 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
3003 m_pFileMenu->AppendSeparator();
3004 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3005 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3006 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3007 m_pFileMenu->AppendSeparator();
3008 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3010 m_pFileMenu->AppendSeparator();
3011 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3012 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3014 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3015 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3017 wxMenu *convert_menu = new wxMenu;
3018 convert_menu->Append (PJMENU_CONVERT_RECTANGULAR, "&Rectangular Image");
3019 convert_menu->Append (PJMENU_CONVERT_POLAR, "&Polar Image...\tCtrl-L");
3020 convert_menu->Append (PJMENU_CONVERT_FFT_POLAR, "FF&T->Polar Image...\tCtrl-T");
3021 convert_menu->AppendSeparator();
3022 convert_menu->Append (PJMENU_CONVERT_PARALLEL, "&Interpolate to Parallel");
3024 wxMenu* filter_menu = new wxMenu;
3025 filter_menu->Append (PJMENU_ARTIFACT_REDUCTION, "&Artifact Reduction");
3027 wxMenu* analyze_menu = new wxMenu;
3028 analyze_menu->Append (PJMENU_PLOT_HISTOGRAM, "&Plot Histogram");
3029 analyze_menu->Append (PJMENU_PLOT_TTHETA_SAMPLING, "Plot T-T&heta Sampling...\tCtrl-H");
3031 wxMenu *reconstruct_menu = new wxMenu;
3032 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP, "&Filtered Backprojection...\tCtrl-R", "Reconstruct image using filtered backprojection");
3033 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP_REBIN, "Filtered &Backprojection (Rebin to Parallel)...\tCtrl-B", "Reconstruct image using filtered backprojection");
3034 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Fourier...\tCtrl-E", "Reconstruct image using inverse Fourier");
3036 wxMenu *help_menu = new wxMenu;
3037 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3038 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3039 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3040 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3042 wxMenuBar *menu_bar = new wxMenuBar;
3044 menu_bar->Append (m_pFileMenu, "&File");
3045 menu_bar->Append (convert_menu, "&Convert");
3046 menu_bar->Append (filter_menu, "Fi<er");
3047 menu_bar->Append (analyze_menu, "&Analyze");
3048 menu_bar->Append (reconstruct_menu, "&Reconstruct");
3049 menu_bar->Append (help_menu, "&Help");
3051 subframe->SetMenuBar(menu_bar);
3052 subframe->Centre(wxBOTH);
3054 wxAcceleratorEntry accelEntries[7];
3055 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('L'), PJMENU_CONVERT_POLAR);
3056 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('T'), PJMENU_CONVERT_FFT_POLAR);
3057 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('R'), PJMENU_RECONSTRUCT_FBP);
3058 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('B'), PJMENU_RECONSTRUCT_FBP_REBIN);
3059 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('E'), PJMENU_RECONSTRUCT_FOURIER);
3060 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('I'), PJMENU_FILE_PROPERTIES);
3061 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('H'), PJMENU_PLOT_TTHETA_SAMPLING);
3062 wxAcceleratorTable accelTable (7, accelEntries);
3063 subframe->SetAcceleratorTable (accelTable);
3070 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
3072 m_pFrame = CreateChildFrame(doc, this);
3076 m_pFrame->GetClientSize (&width, &height);
3077 m_pFrame->SetTitle ("ProjectionFileView");
3078 m_pCanvas = CreateCanvas (m_pFrame);
3081 int x, y; // X requires a forced resize
3082 m_pFrame->GetSize(&x, &y);
3083 m_pFrame->SetSize(-1, -1, x, y);
3086 m_pFrame->Show(true);
3093 ProjectionFileView::OnDraw (wxDC* dc)
3095 wxSize clientSize = m_pFrame->GetClientSize();
3096 wxSize bestSize = m_pCanvas->GetBestSize();
3098 if (clientSize.x > bestSize.x || clientSize.y > bestSize.y)
3099 m_pFrame->SetClientSize (bestSize);
3102 dc->DrawBitmap (m_bitmap, 0, 0, false);
3107 ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3109 const Projections& rProj = GetDocument()->getProjections();
3110 const int nDet = rProj.nDet();
3111 const int nView = rProj.nView();
3112 if (nDet != 0 && nView != 0) {
3113 const DetectorArray& detarray = rProj.getDetectorArray(0);
3114 const DetectorValue* detval = detarray.detValues();
3115 double min = detval[0];
3116 double max = detval[0];
3117 for (int iy = 0; iy < nView; iy++) {
3118 const DetectorArray& detarray = rProj.getDetectorArray(iy);
3119 const DetectorValue* detval = detarray.detValues();
3120 for (int ix = 0; ix < nDet; ix++) {
3121 if (min > detval[ix])
3123 else if (max < detval[ix])
3128 unsigned char* imageData = new unsigned char [nDet * nView * 3];
3130 sys_error (ERR_SEVERE, "Unable to allocate memory for image display");
3133 double scale = (max - min) / 255;
3134 for (int iy2 = 0; iy2 < nView; iy2++) {
3135 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
3136 const DetectorValue* detval = detarray.detValues();
3137 for (int ix = 0; ix < nDet; ix++) {
3138 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
3139 intensity = clamp(intensity, 0, 255);
3140 int baseAddr = (iy2 * nDet + ix) * 3;
3141 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
3144 wxImage image (nDet, nView, imageData, true);
3145 m_bitmap = image.ConvertToBitmap();
3149 xSize = clamp (xSize, 0, 800);
3150 ySize = clamp (ySize, 0, 800);
3151 m_pFrame->SetClientSize (xSize, ySize);
3152 m_pCanvas->SetScrollbars (20, 20, nDet/20, nView/20);
3156 m_pCanvas->Refresh();
3160 ProjectionFileView::OnClose (bool deleteWindow)
3162 //GetDocumentManager()->ActivateView (this, false, true);
3163 if (! GetDocument() || ! GetDocument()->Close())
3168 m_pCanvas->setView(NULL);
3171 wxString s(wxTheApp->GetAppName());
3173 m_pFrame->SetTitle(s);
3180 if (GetDocument() && GetDocument()->getBadFileOpen())
3181 ::wxYield(); // wxWindows bug workaround
3190 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
3191 : wxScrolledWindow(frame, -1, pos, size, style)
3196 PlotFileCanvas::~PlotFileCanvas ()
3202 PlotFileCanvas::OnDraw(wxDC& dc)
3205 m_pView->OnDraw(& dc);
3211 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
3213 BEGIN_EVENT_TABLE(PlotFileView, wxView)
3214 EVT_MENU(PLOTMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
3215 EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
3216 EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
3217 EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
3220 PlotFileView::PlotFileView()
3221 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pEZPlot(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
3225 PlotFileView::~PlotFileView()
3230 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
3234 PlotFileView::OnProperties (wxCommandEvent& event)
3236 const PlotFile& rPlot = GetDocument()->getPlotFile();
3237 std::ostringstream os;
3238 os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
3239 rPlot.printHeadersBrief (os);
3240 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<<\n";
3241 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
3242 dialogMsg.ShowModal();
3243 GetDocument()->Activate();
3248 PlotFileView::OnScaleAuto (wxCommandEvent& event)
3250 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3251 double min, max, mean, mode, median, stddev;
3252 rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
3253 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
3254 int iRetVal = dialogAutoScale.ShowModal();
3255 if (iRetVal == wxID_OK) {
3256 m_bMinSpecified = true;
3257 m_bMaxSpecified = true;
3259 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
3262 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
3263 OnUpdate (this, NULL);
3266 GetDocument()->Activate();
3270 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
3272 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3276 if (! m_bMinSpecified || ! m_bMaxSpecified) {
3277 if (! rPlotFile.getMinMax (1, min, max)) {
3278 *theApp->getLog() << "Error: unable to find Min/Max\n";
3283 if (m_bMinSpecified)
3285 if (m_bMaxSpecified)
3288 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Y-axis Minimum & Maximum", min, max);
3289 int retVal = dialogMinMax.ShowModal();
3290 if (retVal == wxID_OK) {
3291 m_bMinSpecified = true;
3292 m_bMaxSpecified = true;
3293 m_dMinPixel = dialogMinMax.getMinimum();
3294 m_dMaxPixel = dialogMinMax.getMaximum();
3295 OnUpdate (this, NULL);
3297 GetDocument()->Activate();
3301 PlotFileView::OnScaleFull (wxCommandEvent& event)
3303 if (m_bMinSpecified || m_bMaxSpecified) {
3304 m_bMinSpecified = false;
3305 m_bMaxSpecified = false;
3306 OnUpdate (this, NULL);
3308 GetDocument()->Activate();
3313 PlotFileView::CreateCanvas (wxFrame* parent)
3315 PlotFileCanvas* pCanvas;
3317 parent->GetClientSize(&width, &height);
3319 pCanvas = new PlotFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
3321 pCanvas->SetBackgroundColour(*wxWHITE);
3332 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
3335 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
3337 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
3339 theApp->setIconForFrame (subframe);
3341 m_pFileMenu = new wxMenu;
3343 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3344 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3345 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3346 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3347 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3348 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3350 m_pFileMenu->AppendSeparator();
3351 m_pFileMenu->Append(PLOTMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
3353 m_pFileMenu->AppendSeparator();
3354 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3355 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3356 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3357 m_pFileMenu->AppendSeparator();
3358 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3360 m_pFileMenu->AppendSeparator();
3361 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3362 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3364 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3365 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3367 wxMenu *view_menu = new wxMenu;
3368 view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...\tCtrl-E");
3369 view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
3370 view_menu->Append(PLOTMENU_VIEW_SCALE_FULL, "Display &Full Scale\tCtrl-U");
3372 wxMenu *help_menu = new wxMenu;
3373 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3374 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3375 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3376 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3378 wxMenuBar *menu_bar = new wxMenuBar;
3380 menu_bar->Append(m_pFileMenu, "&File");
3381 menu_bar->Append(view_menu, "&View");
3382 menu_bar->Append(help_menu, "&Help");
3384 subframe->SetMenuBar(menu_bar);
3385 subframe->Centre(wxBOTH);
3387 wxAcceleratorEntry accelEntries[4];
3388 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('E'), PLOTMENU_VIEW_SCALE_MINMAX);
3389 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('A'), PLOTMENU_VIEW_SCALE_AUTO);
3390 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('U'), PLOTMENU_VIEW_SCALE_FULL);
3391 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), PLOTMENU_FILE_PROPERTIES);
3392 wxAcceleratorTable accelTable (4, accelEntries);
3393 subframe->SetAcceleratorTable (accelTable);
3400 PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
3402 m_pFrame = CreateChildFrame(doc, this);
3405 m_bMinSpecified = false;
3406 m_bMaxSpecified = false;
3407 m_dAutoScaleFactor = 1.;
3410 m_pFrame->GetClientSize(&width, &height);
3411 m_pFrame->SetTitle ("Plot File");
3412 m_pCanvas = CreateCanvas (m_pFrame);
3415 int x, y; // X requires a forced resize
3416 m_pFrame->GetSize(&x, &y);
3417 m_pFrame->SetSize(-1, -1, x, y);
3420 m_pFrame->Show(true);
3427 PlotFileView::OnDraw (wxDC* dc)
3429 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3430 const int iNColumns = rPlotFile.getNumColumns();
3431 const int iNRecords = rPlotFile.getNumRecords();
3433 if (iNColumns > 0 && iNRecords > 0) {
3435 m_pCanvas->GetClientSize (&xsize, &ysize);
3436 SGPDriver driver (dc, xsize, ysize);
3439 m_pEZPlot->plot (&sgp);
3445 PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3447 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3448 const int iNColumns = rPlotFile.getNumColumns();
3449 const int iNRecords = rPlotFile.getNumRecords();
3450 const bool bScatterPlot = rPlotFile.getIsScatterPlot();
3452 if (iNColumns > 0 && iNRecords > 0) {
3455 m_pEZPlot = new EZPlot;
3457 for (unsigned int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)
3458 m_pEZPlot->ezset (rPlotFile.getEzsetCommand (iEzset));
3460 if (m_bMinSpecified) {
3461 std::ostringstream os;
3462 os << "ymin " << m_dMinPixel;
3463 m_pEZPlot->ezset (os.str());
3466 if (m_bMaxSpecified) {
3467 std::ostringstream os;
3468 os << "ymax " << m_dMaxPixel;
3469 m_pEZPlot->ezset (os.str());
3472 m_pEZPlot->ezset("box");
3473 m_pEZPlot->ezset("grid");
3475 double* pdX = new double [iNRecords];
3476 double* pdY = new double [iNRecords];
3477 if (! bScatterPlot) {
3478 rPlotFile.getColumn (0, pdX);
3480 for (int iCol = 1; iCol < iNColumns; iCol++) {
3481 rPlotFile.getColumn (iCol, pdY);
3482 m_pEZPlot->addCurve (pdX, pdY, iNRecords);
3485 rPlotFile.getColumn (0, pdX);
3486 rPlotFile.getColumn (1, pdY);
3487 m_pEZPlot->addCurve (pdX, pdY, iNRecords);
3494 m_pCanvas->Refresh();
3498 PlotFileView::OnClose (bool deleteWindow)
3500 //GetDocumentManager()->ActivateView (this, false, true);
3501 if (! GetDocument() || ! GetDocument()->Close())
3506 m_pCanvas->setView (NULL);
3509 wxString s(wxTheApp->GetAppName());
3511 m_pFrame->SetTitle(s);
3517 if (GetDocument() && GetDocument()->getBadFileOpen())
3518 ::wxYield(); // wxWindows bug workaround
3525 ////////////////////////////////////////////////////////////////
3528 IMPLEMENT_DYNAMIC_CLASS(TextFileView, wxView)
3530 TextFileView::~TextFileView()
3532 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
3533 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
3536 bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
3538 m_pFrame = CreateChildFrame(doc, this);
3539 SetFrame (m_pFrame);
3542 m_pFrame->GetClientSize(&width, &height);
3543 m_pFrame->SetTitle("TextFile");
3544 m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
3545 m_pFrame->SetTitle("Log");
3548 // X seems to require a forced resize
3550 frame->GetSize(&x, &y);
3551 frame->SetSize(-1, -1, x, y);
3554 m_pFrame->Show (true);
3560 // Handled by wxTextWindow
3561 void TextFileView::OnDraw(wxDC *WXUNUSED(dc) )
3565 void TextFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3570 TextFileView::OnClose (bool deleteWindow)
3572 if (! theApp->getMainFrame()->getShuttingDown())
3576 //GetDocumentManager()->ActivateView (this, false, true);
3577 if (! GetDocument() || ! GetDocument()->Close())
3584 if (GetDocument() && GetDocument()->getBadFileOpen())
3585 ::wxYield(); // wxWindows bug workaround
3596 TextFileView::CreateChildFrame (wxDocument *doc, wxView *view)
3599 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(0,0), wxDEFAULT_FRAME_STYLE, "Log");
3601 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE, "Log");
3603 theApp->setIconForFrame (subframe);
3605 m_pFileMenu = new wxMenu;
3607 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3608 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3609 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3610 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3611 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3612 // m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3614 m_pFileMenu->AppendSeparator();
3615 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3616 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3617 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3618 m_pFileMenu->AppendSeparator();
3619 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3621 m_pFileMenu->AppendSeparator();
3622 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3623 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3625 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3626 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3628 wxMenu *help_menu = new wxMenu;
3629 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3630 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3631 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3632 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3634 wxMenuBar *menu_bar = new wxMenuBar;
3636 menu_bar->Append(m_pFileMenu, "&File");
3637 menu_bar->Append(help_menu, "&Help");
3639 subframe->SetMenuBar(menu_bar);
3640 subframe->Centre(wxBOTH);
3646 // Define a constructor for my text subwindow
3647 TextFileCanvas::TextFileCanvas (TextFileView* v, wxFrame* frame, const wxPoint& pos, const wxSize& size, long style)
3648 : wxTextCtrl (frame, -1, "", pos, size, style), m_pView(v)
3652 TextFileCanvas::~TextFileCanvas ()