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.166 2003/01/29 07:11:17 kevin Exp $
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
28 #include "wx/wxprec.h"
33 #if !wxUSE_DOC_VIEW_ARCHITECTURE
34 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
38 #include "wx/progdlg.h"
39 #include "wx/clipbrd.h"
46 #include "dlgprojections.h"
47 #include "dlgreconstruct.h"
48 #include "backprojectors.h"
49 #include "reconstruct.h"
51 #include "threadproj.h"
52 #include "threadrecon.h"
53 #include "threadraster.h"
55 #if defined(MSVC) || HAVE_SSTREAM
58 #include <sstream_subst>
61 // Used to reduce calls to progress bar update function
62 const short int ITER_PER_UPDATE = 10;
66 BEGIN_EVENT_TABLE(ImageFileCanvas, wxScrolledWindow)
67 EVT_MOUSE_EVENTS(ImageFileCanvas::OnMouseEvent)
68 EVT_CHAR(ImageFileCanvas::OnChar)
72 ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
73 : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v), m_xCursor(-1), m_yCursor(-1)
77 ImageFileCanvas::~ImageFileCanvas()
81 ImageFileCanvas::OnDraw(wxDC& dc)
84 m_pView->OnDraw(& dc);
88 ImageFileCanvas::DrawRubberBandCursor (wxDC& dc, int x, int y)
90 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
95 dc.SetLogicalFunction (wxINVERT);
96 dc.SetPen (*wxGREEN_PEN);
97 dc.DrawLine (0, yPt, nx, yPt);
98 dc.DrawLine (x, 0, x, ny);
99 dc.SetLogicalFunction (wxCOPY);
103 ImageFileCanvas::GetCurrentCursor (int& x, int& y)
108 if (m_xCursor >= 0 && m_yCursor >= 0)
115 ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
124 wxPoint pt(event.GetLogicalPosition(dc));
126 const ImageFileDocument* pIFDoc = m_pView->GetDocument();
129 const ImageFile& rIF = pIFDoc->getImageFile();
130 ImageFileArrayConst v = rIF.getArray();
133 const int yPt = ny - 1 - pt.y;
134 if (event.RightIsDown()) {
135 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
136 std::ostringstream os;
137 os << "Image value (" << pt.x << "," << yPt << ") = " << v[pt.x][yPt];
138 if (rIF.isComplex()) {
139 double dImag = rIF.getImaginaryArray()[pt.x][yPt];
141 os << " - " << -dImag;
143 os << " + " << dImag;
147 *theApp->getLog() << os.str().c_str();
149 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
151 else if (event.LeftIsDown() || event.LeftUp() || event.RightUp()) {
152 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
153 if (m_xCursor >= 0 && m_yCursor >= 0) {
154 DrawRubberBandCursor (dc, m_xCursor, m_yCursor);
156 DrawRubberBandCursor (dc, pt.x, yPt);
159 wxMenu* pMenu = m_pView->getMenuAnalyze();
160 if (pMenu && ! pMenu->IsEnabled(IFMENU_PLOT_ROW)) {
161 pMenu->Enable (IFMENU_PLOT_ROW, true);
162 pMenu->Enable (IFMENU_PLOT_COL, true);
163 pMenu->Enable (IFMENU_COMPARE_ROW, true);
164 pMenu->Enable (IFMENU_COMPARE_COL, true);
165 pMenu->Enable (IFMENU_PLOT_FFT_ROW, true);
166 pMenu->Enable (IFMENU_PLOT_FFT_COL, true);
169 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
171 if (event.LeftUp()) {
172 std::ostringstream os;
173 os << "Selected column " << pt.x << " , row " << yPt << "\n";
174 *theApp->getLog() << os.str().c_str();
179 ImageFileCanvas::OnChar (wxKeyEvent& event)
181 if (event.GetKeyCode() == WXK_ESCAPE) {
185 m_pView->OnUpdate (NULL);
191 ImageFileCanvas::GetBestSize() const
193 const int iMinX = 50;
194 const int iMinY = 20;
195 wxSize bestSize (iMinX,iMinY);
198 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
199 bestSize.Set (rIF.nx(), rIF.ny());
202 if (bestSize.x > 800)
204 if (bestSize.y > 800)
207 if (bestSize.y < iMinY)
209 if (bestSize.x < iMinX)
218 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
220 BEGIN_EVENT_TABLE(ImageFileView, wxView)
221 EVT_MENU(IFMENU_FILE_EXPORT, ImageFileView::OnExport)
222 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
223 EVT_MENU(IFMENU_EDIT_COPY, ImageFileView::OnEditCopy)
224 EVT_MENU(IFMENU_EDIT_CUT, ImageFileView::OnEditCut)
225 EVT_MENU(IFMENU_EDIT_PASTE, ImageFileView::OnEditPaste)
226 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
227 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
228 EVT_MENU(IFMENU_VIEW_SCALE_FULL, ImageFileView::OnScaleFull)
229 EVT_MENU(IFMENU_COMPARE_IMAGES, ImageFileView::OnCompare)
230 EVT_MENU(IFMENU_COMPARE_ROW, ImageFileView::OnCompareRow)
231 EVT_MENU(IFMENU_COMPARE_COL, ImageFileView::OnCompareCol)
232 EVT_MENU(IFMENU_FILTER_INVERTVALUES, ImageFileView::OnInvertValues)
233 EVT_MENU(IFMENU_FILTER_SQUARE, ImageFileView::OnSquare)
234 EVT_MENU(IFMENU_FILTER_SQRT, ImageFileView::OnSquareRoot)
235 EVT_MENU(IFMENU_FILTER_LOG, ImageFileView::OnLog)
236 EVT_MENU(IFMENU_FILTER_EXP, ImageFileView::OnExp)
237 EVT_MENU(IFMENU_FILTER_FOURIER, ImageFileView::OnFourier)
238 EVT_MENU(IFMENU_FILTER_INVERSE_FOURIER, ImageFileView::OnInverseFourier)
239 EVT_MENU(IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, ImageFileView::OnShuffleFourierToNaturalOrder)
240 EVT_MENU(IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, ImageFileView::OnShuffleNaturalToFourierOrder)
241 EVT_MENU(IFMENU_IMAGE_ADD, ImageFileView::OnAdd)
242 EVT_MENU(IFMENU_IMAGE_SUBTRACT, ImageFileView::OnSubtract)
243 EVT_MENU(IFMENU_IMAGE_MULTIPLY, ImageFileView::OnMultiply)
244 EVT_MENU(IFMENU_IMAGE_DIVIDE, ImageFileView::OnDivide)
245 EVT_MENU(IFMENU_IMAGE_SCALESIZE, ImageFileView::OnScaleSize)
247 EVT_MENU(IFMENU_IMAGE_CONVERT3D, ImageFileView::OnConvert3d)
250 EVT_MENU(IFMENU_FILTER_FFT, ImageFileView::OnFFT)
251 EVT_MENU(IFMENU_FILTER_IFFT, ImageFileView::OnIFFT)
252 EVT_MENU(IFMENU_FILTER_FFT_ROWS, ImageFileView::OnFFTRows)
253 EVT_MENU(IFMENU_FILTER_IFFT_ROWS, ImageFileView::OnIFFTRows)
254 EVT_MENU(IFMENU_FILTER_FFT_COLS, ImageFileView::OnFFTCols)
255 EVT_MENU(IFMENU_FILTER_IFFT_COLS, ImageFileView::OnIFFTCols)
257 EVT_MENU(IFMENU_FILTER_MAGNITUDE, ImageFileView::OnMagnitude)
258 EVT_MENU(IFMENU_FILTER_PHASE, ImageFileView::OnPhase)
259 EVT_MENU(IFMENU_FILTER_REAL, ImageFileView::OnReal)
260 EVT_MENU(IFMENU_FILTER_IMAGINARY, ImageFileView::OnImaginary)
261 EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)
262 EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol)
264 EVT_MENU(IFMENU_PLOT_FFT_ROW, ImageFileView::OnPlotFFTRow)
265 EVT_MENU(IFMENU_PLOT_FFT_COL, ImageFileView::OnPlotFFTCol)
267 EVT_MENU(IFMENU_PLOT_HISTOGRAM, ImageFileView::OnPlotHistogram)
270 ImageFileView::ImageFileView()
271 : wxView(), m_pBitmap(0), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0),
272 m_pFilterMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false),
273 m_iDefaultExportFormatID(ImageFile::EXPORT_FORMAT_PNG)
276 ImageFileView::~ImageFileView()
278 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
279 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
284 ImageFileView::OnProperties (wxCommandEvent& event)
286 const ImageFile& rIF = GetDocument()->getImageFile();
287 if (rIF.nx() == 0 || rIF.ny() == 0)
288 *theApp->getLog() << "Properties: empty imagefile\n";
290 const std::string rFilename = m_pFrame->GetTitle().c_str();
291 std::ostringstream os;
292 double min, max, mean, mode, median, stddev;
293 rIF.statistics (rIF.getArray(), min, max, mean, mode, median, stddev);
294 os << "Filename: " << rFilename << "\n";
295 os << "Size: (" << rIF.nx() << "," << rIF.ny() << ")\n";
301 os << "Minimum: "<<min<<"\nMaximum: "<<max<<"\nMean: "<<mean<<"\nMedian: "<<median<<"\nMode: "<<mode<<"\nStandard Deviation: "<<stddev << "\n";
302 if (rIF.isComplex()) {
303 rIF.statistics (rIF.getImaginaryArray(), min, max, mean, mode, median, stddev);
304 os << "Imaginary: min: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
306 if (rIF.nLabels() > 0) {
307 rIF.printLabelsBrief (os);
309 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
310 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
311 dialogMsg.ShowModal();
313 GetDocument()->Activate();
317 ImageFileView::OnScaleAuto (wxCommandEvent& event)
319 const ImageFile& rIF = GetDocument()->getImageFile();
320 double min, max, mean, mode, median, stddev;
321 rIF.statistics(min, max, mean, mode, median, stddev);
322 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
323 int iRetVal = dialogAutoScale.ShowModal();
324 if (iRetVal == wxID_OK) {
325 m_bMinSpecified = true;
326 m_bMaxSpecified = true;
328 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
331 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
332 GetDocument()->UpdateAllViews (this);
335 GetDocument()->Activate();
339 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
341 const ImageFile& rIF = GetDocument()->getImageFile();
343 if (! m_bMinSpecified && ! m_bMaxSpecified)
344 rIF.getMinMax (min, max);
351 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Image Minimum & Maximum", min, max);
352 int retVal = dialogMinMax.ShowModal();
353 if (retVal == wxID_OK) {
354 m_bMinSpecified = true;
355 m_bMaxSpecified = true;
356 m_dMinPixel = dialogMinMax.getMinimum();
357 m_dMaxPixel = dialogMinMax.getMaximum();
358 GetDocument()->UpdateAllViews (this);
360 GetDocument()->Activate();
364 ImageFileView::OnScaleFull (wxCommandEvent& event)
366 if (m_bMinSpecified || m_bMaxSpecified) {
367 m_bMinSpecified = false;
368 m_bMaxSpecified = false;
369 GetDocument()->UpdateAllViews (this);
371 GetDocument()->Activate();
375 ImageFileView::OnCompare (wxCommandEvent& event)
377 std::vector<ImageFileDocument*> vecIF;
378 theApp->getCompatibleImages (GetDocument(), vecIF);
380 if (vecIF.size() == 0) {
381 wxMessageBox("There are no compatible image files open for comparision", "No comparison images");
383 DialogGetComparisonImage dialogGetCompare(getFrameForChild(), "Get Comparison Image", vecIF, true);
385 if (dialogGetCompare.ShowModal() == wxID_OK) {
386 const ImageFile& rIF = GetDocument()->getImageFile();
387 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
388 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
389 std::ostringstream os;
390 double min, max, mean, mode, median, stddev;
391 rIF.statistics (min, max, mean, mode, median, stddev);
392 os << GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
393 rCompareIF.statistics (min, max, mean, mode, median, stddev);
394 os << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
396 rIF.comparativeStatistics (rCompareIF, d, r, e);
397 os << "Comparative Statistics: d=" << d << ", r=" << r << ", e=" << e << "\n";
398 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
399 if (dialogGetCompare.getMakeDifferenceImage()) {
400 ImageFile* pDifferenceImage = new ImageFile;
402 pDifferenceImage->setArraySize (rIF.nx(), rIF.ny());
403 if (! rIF.subtractImages (rCompareIF, *pDifferenceImage)) {
404 *theApp->getLog() << "Unable to subtract images\n";
405 delete pDifferenceImage;
408 ImageFileDocument* pDifferenceDoc = theApp->newImageDoc();
409 if (! pDifferenceDoc) {
410 sys_error (ERR_SEVERE, "Unable to create image file");
413 pDifferenceDoc->setImageFile (pDifferenceImage);
415 wxString s = GetFrame()->GetTitle() + ": ";
416 pDifferenceImage->labelsCopy (rIF, s.c_str());
417 s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
418 pDifferenceImage->labelsCopy (rCompareIF, s.c_str());
419 std::ostringstream osLabel;
420 osLabel << "Compare image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str()
421 << " and " << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": "
423 pDifferenceImage->labelAdd (os.str().c_str());
424 if (theApp->getAskDeleteNewDocs())
425 pDifferenceDoc->Modify (true);
426 pDifferenceDoc->UpdateAllViews(this);
427 pDifferenceDoc->getView()->setInitialClientSize();
428 pDifferenceDoc->Activate();
430 wxMessageBox(os.str().c_str(), "Image Comparison");
436 ImageFileView::OnInvertValues (wxCommandEvent& event)
438 ImageFile& rIF = GetDocument()->getImageFile();
439 rIF.invertPixelValues (rIF);
440 rIF.labelAdd ("Invert Pixel Values");
441 if (theApp->getAskDeleteNewDocs())
442 GetDocument()->Modify (true);
443 GetDocument()->UpdateAllViews (this);
444 GetDocument()->Activate();
448 ImageFileView::OnSquare (wxCommandEvent& event)
450 ImageFile& rIF = GetDocument()->getImageFile();
452 rIF.labelAdd ("Square Pixel Values");
453 if (theApp->getAskDeleteNewDocs())
454 GetDocument()->Modify (true);
455 GetDocument()->UpdateAllViews (this);
456 GetDocument()->Activate();
460 ImageFileView::OnSquareRoot (wxCommandEvent& event)
462 ImageFile& rIF = GetDocument()->getImageFile();
464 rIF.labelAdd ("Square-root Pixel Values");
465 if (theApp->getAskDeleteNewDocs())
466 GetDocument()->Modify (true);
467 GetDocument()->UpdateAllViews (this);
468 GetDocument()->Activate();
472 ImageFileView::OnLog (wxCommandEvent& event)
474 ImageFile& rIF = GetDocument()->getImageFile();
476 rIF.labelAdd ("Logrithm base-e Pixel Values");
477 if (theApp->getAskDeleteNewDocs())
478 GetDocument()->Modify (true);
479 GetDocument()->UpdateAllViews (this);
480 GetDocument()->Activate();
484 ImageFileView::OnExp (wxCommandEvent& event)
486 ImageFile& rIF = GetDocument()->getImageFile();
488 rIF.labelAdd ("Exponent base-e Pixel Values");
489 if (theApp->getAskDeleteNewDocs())
490 GetDocument()->Modify (true);
491 GetDocument()->UpdateAllViews (this);
492 GetDocument()->Activate();
496 ImageFileView::OnAdd (wxCommandEvent& event)
498 std::vector<ImageFileDocument*> vecIF;
499 theApp->getCompatibleImages (GetDocument(), vecIF);
501 if (vecIF.size() == 0) {
502 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
504 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Add", vecIF, false);
506 if (dialogGetCompare.ShowModal() == wxID_OK) {
507 ImageFile& rIF = GetDocument()->getImageFile();
508 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
509 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
510 ImageFileDocument* pNewDoc = theApp->newImageDoc();
512 sys_error (ERR_SEVERE, "Unable to create image file");
515 ImageFile& newImage = pNewDoc->getImageFile();
516 newImage.setArraySize (rIF.nx(), rIF.ny());
517 rIF.addImages (rRHSIF, newImage);
518 std::ostringstream os;
519 os << "Add image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
520 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
521 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
522 newImage.labelsCopy (rIF, s.c_str());
523 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
524 newImage.labelsCopy (rRHSIF, s.c_str());
525 newImage.labelAdd (os.str().c_str());
526 *theApp->getLog() << os.str().c_str() << "\n";
527 if (theApp->getAskDeleteNewDocs())
528 pNewDoc->Modify (true);
529 pNewDoc->UpdateAllViews (this);
530 pNewDoc->getView()->setInitialClientSize();
537 ImageFileView::OnSubtract (wxCommandEvent& event)
539 std::vector<ImageFileDocument*> vecIF;
540 theApp->getCompatibleImages (GetDocument(), vecIF);
542 if (vecIF.size() == 0) {
543 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
545 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Subtract", vecIF, false);
547 if (dialogGetCompare.ShowModal() == wxID_OK) {
548 ImageFile& rIF = GetDocument()->getImageFile();
549 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
550 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
551 ImageFileDocument* pNewDoc = theApp->newImageDoc();
553 sys_error (ERR_SEVERE, "Unable to create image file");
556 ImageFile& newImage = pNewDoc->getImageFile();
557 newImage.setArraySize (rIF.nx(), rIF.ny());
558 rIF.subtractImages (rRHSIF, newImage);
559 std::ostringstream os;
560 os << "Subtract image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
561 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
562 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
563 newImage.labelsCopy (rIF, s.c_str());
564 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
565 newImage.labelsCopy (rRHSIF, s.c_str());
566 newImage.labelAdd (os.str().c_str());
567 *theApp->getLog() << os.str().c_str() << "\n";
568 if (theApp->getAskDeleteNewDocs())
569 pNewDoc->Modify (true);
570 pNewDoc->UpdateAllViews (this);
571 pNewDoc->getView()->setInitialClientSize();
578 ImageFileView::OnMultiply (wxCommandEvent& event)
580 std::vector<ImageFileDocument*> vecIF;
581 theApp->getCompatibleImages (GetDocument(), vecIF);
583 if (vecIF.size() == 0) {
584 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
586 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Multiply", vecIF, false);
588 if (dialogGetCompare.ShowModal() == wxID_OK) {
589 ImageFile& rIF = GetDocument()->getImageFile();
590 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
591 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
592 ImageFileDocument* pNewDoc = theApp->newImageDoc();
594 sys_error (ERR_SEVERE, "Unable to create image file");
597 ImageFile& newImage = pNewDoc->getImageFile();
598 newImage.setArraySize (rIF.nx(), rIF.ny());
599 rIF.multiplyImages (rRHSIF, newImage);
600 std::ostringstream os;
601 os << "Multiply image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
602 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
603 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
604 newImage.labelsCopy (rIF, s.c_str());
605 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
606 newImage.labelsCopy (rRHSIF, s.c_str());
607 newImage.labelAdd (os.str().c_str());
608 *theApp->getLog() << os.str().c_str() << "\n";
609 if (theApp->getAskDeleteNewDocs())
610 pNewDoc->Modify (true);
611 pNewDoc->UpdateAllViews (this);
612 pNewDoc->getView()->setInitialClientSize();
619 ImageFileView::OnDivide (wxCommandEvent& event)
621 std::vector<ImageFileDocument*> vecIF;
622 theApp->getCompatibleImages (GetDocument(), vecIF);
624 if (vecIF.size() == 0) {
625 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
627 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Divide", vecIF, false);
629 if (dialogGetCompare.ShowModal() == wxID_OK) {
630 ImageFile& rIF = GetDocument()->getImageFile();
631 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
632 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
633 ImageFileDocument* pNewDoc = theApp->newImageDoc();
635 sys_error (ERR_SEVERE, "Unable to create image file");
638 ImageFile& newImage = pNewDoc->getImageFile();
639 newImage.setArraySize (rIF.nx(), rIF.ny());
640 rIF.divideImages (rRHSIF, newImage);
641 std::ostringstream os;
642 os << "Divide image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " by "
643 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
644 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
645 newImage.labelsCopy (rIF, s.c_str());
646 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
647 newImage.labelsCopy (rRHSIF, s.c_str());
648 newImage.labelAdd (os.str().c_str());
649 *theApp->getLog() << os.str().c_str() << "\n";
650 if (theApp->getAskDeleteNewDocs())
651 pNewDoc->Modify (true);
652 pNewDoc->UpdateAllViews (this);
653 pNewDoc->getView()->setInitialClientSize();
662 ImageFileView::OnFFT (wxCommandEvent& event)
664 ImageFile& rIF = GetDocument()->getImageFile();
666 rIF.labelAdd ("FFT 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::OnIFFT (wxCommandEvent& event)
678 ImageFile& rIF = GetDocument()->getImageFile();
680 rIF.labelAdd ("IFFT Image");
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::OnFFTRows (wxCommandEvent& event)
692 ImageFile& rIF = GetDocument()->getImageFile();
694 rIF.labelAdd ("FFT 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::OnIFFTRows (wxCommandEvent& event)
706 ImageFile& rIF = GetDocument()->getImageFile();
708 rIF.labelAdd ("IFFT Rows");
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::OnFFTCols (wxCommandEvent& event)
720 ImageFile& rIF = GetDocument()->getImageFile();
722 rIF.labelAdd ("FFT Columns");
723 m_bMinSpecified = false;
724 m_bMaxSpecified = false;
725 if (theApp->getAskDeleteNewDocs())
726 GetDocument()->Modify (true);
727 GetDocument()->UpdateAllViews (this);
728 GetDocument()->Activate();
732 ImageFileView::OnIFFTCols (wxCommandEvent& event)
734 ImageFile& rIF = GetDocument()->getImageFile();
736 rIF.labelAdd ("IFFT Columns");
737 m_bMinSpecified = false;
738 m_bMaxSpecified = false;
739 if (theApp->getAskDeleteNewDocs())
740 GetDocument()->Modify (true);
741 GetDocument()->UpdateAllViews (this);
742 GetDocument()->Activate();
747 ImageFileView::OnFourier (wxCommandEvent& event)
749 ImageFile& rIF = GetDocument()->getImageFile();
750 wxProgressDialog dlgProgress (wxString("Fourier"), wxString("Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
752 rIF.labelAdd ("Fourier Image");
753 m_bMinSpecified = false;
754 m_bMaxSpecified = false;
755 if (theApp->getAskDeleteNewDocs())
756 GetDocument()->Modify (true);
757 GetDocument()->UpdateAllViews (this);
758 GetDocument()->Activate();
762 ImageFileView::OnInverseFourier (wxCommandEvent& event)
764 ImageFile& rIF = GetDocument()->getImageFile();
765 wxProgressDialog dlgProgress (wxString("Inverse Fourier"), wxString("Inverse Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
766 rIF.inverseFourier (rIF);
767 rIF.labelAdd ("Inverse Fourier Image");
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::OnShuffleNaturalToFourierOrder (wxCommandEvent& event)
779 ImageFile& rIF = GetDocument()->getImageFile();
780 Fourier::shuffleNaturalToFourierOrder (rIF);
781 rIF.labelAdd ("Shuffle Natural To Fourier 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::OnShuffleFourierToNaturalOrder (wxCommandEvent& event)
793 ImageFile& rIF = GetDocument()->getImageFile();
794 Fourier::shuffleFourierToNaturalOrder (rIF);
795 rIF.labelAdd ("Shuffle Fourier To Natural Order");
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::OnMagnitude (wxCommandEvent& event)
807 ImageFile& rIF = GetDocument()->getImageFile();
809 rIF.labelAdd ("Magnitude");
810 m_bMinSpecified = false;
811 m_bMaxSpecified = false;
812 if (theApp->getAskDeleteNewDocs())
813 GetDocument()->Modify (true);
814 GetDocument()->UpdateAllViews (this);
815 GetDocument()->Activate();
819 ImageFileView::OnPhase (wxCommandEvent& event)
821 ImageFile& rIF = GetDocument()->getImageFile();
822 if (rIF.isComplex()) {
824 rIF.labelAdd ("Phase of complex-image");
825 m_bMinSpecified = false;
826 m_bMaxSpecified = false;
827 if (theApp->getAskDeleteNewDocs())
828 GetDocument()->Modify (true);
829 GetDocument()->UpdateAllViews (this);
831 GetDocument()->Activate();
835 ImageFileView::OnReal (wxCommandEvent& event)
837 ImageFile& rIF = GetDocument()->getImageFile();
838 if (rIF.isComplex()) {
840 rIF.labelAdd ("Real component of complex-image");
841 m_bMinSpecified = false;
842 m_bMaxSpecified = false;
843 if (theApp->getAskDeleteNewDocs())
844 GetDocument()->Modify (true);
845 GetDocument()->UpdateAllViews (this);
847 GetDocument()->Activate();
851 ImageFileView::OnImaginary (wxCommandEvent& event)
853 ImageFile& rIF = GetDocument()->getImageFile();
854 if (rIF.isComplex()) {
856 rIF.labelAdd ("Imaginary component of complex-image");
857 m_bMinSpecified = false;
858 m_bMaxSpecified = false;
859 if (theApp->getAskDeleteNewDocs())
860 GetDocument()->Modify (true);
861 GetDocument()->UpdateAllViews (this);
863 GetDocument()->Activate();
868 ImageFileView::CreateCanvas (wxFrame* parent)
870 ImageFileCanvas* pCanvas = new ImageFileCanvas (this, parent, wxPoint(-1,-1),
872 pCanvas->SetBackgroundColour(*wxWHITE);
883 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
886 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
888 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
890 theApp->setIconForFrame (subframe);
892 m_pFileMenu = new wxMenu;
893 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
894 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
895 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
896 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
897 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
898 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
899 m_pFileMenu->Append(wxID_REVERT, "Re&vert");
901 m_pFileMenu->AppendSeparator();
902 m_pFileMenu->Append(IFMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
903 m_pFileMenu->Append(IFMENU_FILE_EXPORT, "Expor&t...");
905 m_pFileMenu->AppendSeparator();
906 m_pFileMenu->Append(wxID_PRINT, "&Print...");
907 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
908 m_pFileMenu->Append(wxID_PREVIEW, "Print Preview");
909 m_pFileMenu->AppendSeparator();
910 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
911 m_pFileMenu->AppendSeparator();
912 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
913 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
914 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
915 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
917 wxMenu* edit_menu = new wxMenu;
918 edit_menu->Append(IFMENU_EDIT_COPY, "Copy\tCtrl-C");
919 edit_menu->Append(IFMENU_EDIT_CUT, "Cut\tCtrl-X");
920 edit_menu->Append(IFMENU_EDIT_PASTE, "Paste\tCtrl-V");
922 wxMenu *view_menu = new wxMenu;
923 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale S&et...\tCtrl-E");
924 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
925 view_menu->Append(IFMENU_VIEW_SCALE_FULL, "Display F&ull Scale\tCtrl-U");
927 m_pFilterMenu = new wxMenu;
928 m_pFilterMenu->Append (IFMENU_FILTER_INVERTVALUES, "In&vert Values");
929 m_pFilterMenu->Append (IFMENU_FILTER_SQUARE, "&Square");
930 m_pFilterMenu->Append (IFMENU_FILTER_SQRT, "Square &Root");
931 m_pFilterMenu->Append (IFMENU_FILTER_LOG, "&Log");
932 m_pFilterMenu->Append (IFMENU_FILTER_EXP, "E&xp");
933 m_pFilterMenu->AppendSeparator();
935 m_pFilterMenu->Append (IFMENU_FILTER_FFT, "2-D &FFT\tCtrl-2");
936 m_pFilterMenu->Append (IFMENU_FILTER_IFFT, "2-D &IFFT\tAlt-2");
937 m_pFilterMenu->Append (IFMENU_FILTER_FFT_ROWS, "FFT Rows");
938 m_pFilterMenu->Append (IFMENU_FILTER_IFFT_ROWS, "IFFT Rows");
939 m_pFilterMenu->Append (IFMENU_FILTER_FFT_COLS, "FFT Columns");
940 m_pFilterMenu->Append (IFMENU_FILTER_IFFT_COLS, "IFFT Columns");
941 m_pFilterMenu->Append (IFMENU_FILTER_FOURIER, "2-D F&ourier");
942 m_pFilterMenu->Append (IFMENU_FILTER_INVERSE_FOURIER, "2-D Inverse Fo&urier");
944 m_pFilterMenu->Append (IFMENU_FILTER_FOURIER, "&Fourier");
945 m_pFilterMenu->Append (IFMENU_FILTER_INVERSE_FOURIER, "&Inverse Fourier");
947 m_pFilterMenu->Append (IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, "Shuffl&e Fourier to Natural Order");
948 m_pFilterMenu->Append (IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, "Shuffle &Natural to Fourier Order");
949 m_pFilterMenu->AppendSeparator();
950 m_pFilterMenu->Append (IFMENU_FILTER_MAGNITUDE, "&Magnitude");
951 m_pFilterMenu->Append (IFMENU_FILTER_PHASE, "&Phase");
952 m_pFilterMenu->Append (IFMENU_FILTER_REAL, "Re&al");
953 m_pFilterMenu->Append (IFMENU_FILTER_IMAGINARY, "Ima&ginary");
955 wxMenu* image_menu = new wxMenu;
956 image_menu->Append (IFMENU_IMAGE_ADD, "&Add...");
957 image_menu->Append (IFMENU_IMAGE_SUBTRACT, "&Subtract...");
958 image_menu->Append (IFMENU_IMAGE_MULTIPLY, "&Multiply...");
959 image_menu->Append (IFMENU_IMAGE_DIVIDE, "&Divide...");
960 image_menu->AppendSeparator();
961 image_menu->Append (IFMENU_IMAGE_SCALESIZE, "S&cale Size...");
963 image_menu->Append (IFMENU_IMAGE_CONVERT3D, "Convert &3-D\tCtrl-3");
966 m_pMenuAnalyze = new wxMenu;
967 m_pMenuAnalyze->Append (IFMENU_PLOT_ROW, "Plot &Row");
968 m_pMenuAnalyze->Append (IFMENU_PLOT_COL, "Plot &Column");
969 m_pMenuAnalyze->Append (IFMENU_PLOT_HISTOGRAM, "Plot &Histogram");
970 m_pMenuAnalyze->AppendSeparator();
971 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_ROW, "P&lot FFT Row");
972 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_COL, "Plo&t FFT Column");
973 m_pMenuAnalyze->AppendSeparator();
974 m_pMenuAnalyze->Append (IFMENU_COMPARE_IMAGES, "Compare &Images...");
975 m_pMenuAnalyze->Append (IFMENU_COMPARE_ROW, "Compare Ro&w");
976 m_pMenuAnalyze->Append (IFMENU_COMPARE_COL, "Compare Colu&mn");
977 m_pMenuAnalyze->Enable (IFMENU_PLOT_ROW, false);
978 m_pMenuAnalyze->Enable (IFMENU_PLOT_COL, false);
979 m_pMenuAnalyze->Enable (IFMENU_COMPARE_ROW, false);
980 m_pMenuAnalyze->Enable (IFMENU_COMPARE_COL, false);
981 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_ROW, false);
982 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_COL, false);
984 wxMenu *help_menu = new wxMenu;
985 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
986 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
987 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
988 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
990 wxMenuBar *menu_bar = new wxMenuBar;
992 menu_bar->Append(m_pFileMenu, "&File");
993 menu_bar->Append(edit_menu, "&Edit");
994 menu_bar->Append(view_menu, "&View");
995 menu_bar->Append(image_menu, "&Image");
996 menu_bar->Append(m_pFilterMenu, "Fi<er");
997 menu_bar->Append(m_pMenuAnalyze, "&Analyze");
998 menu_bar->Append(help_menu, "&Help");
1000 subframe->SetMenuBar(menu_bar);
1002 subframe->Centre(wxBOTH);
1004 wxAcceleratorEntry accelEntries[10];
1005 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('A'), IFMENU_VIEW_SCALE_AUTO);
1006 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('U'), IFMENU_VIEW_SCALE_FULL);
1007 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('E'), IFMENU_VIEW_SCALE_MINMAX);
1008 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), IFMENU_FILE_PROPERTIES);
1009 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('C'), IFMENU_EDIT_COPY);
1010 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('X'), IFMENU_EDIT_CUT);
1011 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('V'), IFMENU_EDIT_PASTE);
1014 accelEntries[iEntry++].Set (wxACCEL_CTRL, static_cast<int>('2'), IFMENU_FILTER_FFT);
1015 accelEntries[iEntry++].Set (wxACCEL_ALT, static_cast<int>('2'), IFMENU_FILTER_IFFT);
1018 accelEntries[iEntry++].Set (wxACCEL_CTRL, static_cast<int>('3'), IFMENU_IMAGE_CONVERT3D);
1021 wxAcceleratorTable accelTable (iEntry, accelEntries);
1022 subframe->SetAcceleratorTable (accelTable);
1029 ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
1031 m_bMinSpecified = false;
1032 m_bMaxSpecified = false;
1033 m_dAutoScaleFactor = 1.;
1035 m_pFrame = CreateChildFrame(doc, this);
1036 SetFrame (m_pFrame);
1037 m_pCanvas = CreateCanvas (m_pFrame);
1038 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
1039 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
1040 m_pFrame->SetTitle("ImageFileView");
1042 m_pFrame->Show(true);
1049 ImageFileView::setInitialClientSize ()
1051 if (m_pFrame && m_pCanvas) {
1052 wxSize bestSize = m_pCanvas->GetBestSize();
1054 m_pFrame->SetClientSize (bestSize);
1055 m_pFrame->Show (true);
1056 m_pFrame->SetFocus();
1061 ImageFileView::OnDraw (wxDC* dc)
1063 if (m_pBitmap && m_pBitmap->Ok()) {
1064 *theApp->getLog() << "Drawing bitmap";
1065 dc->DrawBitmap(*m_pBitmap, 0, 0, false);
1068 int xCursor, yCursor;
1069 if (m_pCanvas->GetCurrentCursor (xCursor, yCursor))
1070 m_pCanvas->DrawRubberBandCursor (*dc, xCursor, yCursor);
1075 ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
1077 const ImageFile& rIF = GetDocument()->getImageFile();
1078 if (m_pFilterMenu && rIF.isComplex()) {
1079 m_pFilterMenu->Enable(IFMENU_FILTER_REAL, true);
1080 m_pFilterMenu->Enable(IFMENU_FILTER_IMAGINARY, true);
1081 m_pFilterMenu->Enable(IFMENU_FILTER_PHASE, true);
1083 m_pFilterMenu->Enable(IFMENU_FILTER_REAL, false);
1084 m_pFilterMenu->Enable(IFMENU_FILTER_IMAGINARY, false);
1085 m_pFilterMenu->Enable(IFMENU_FILTER_PHASE, false);
1087 ImageFileArrayConst v = rIF.getArray();
1090 if (v != NULL && nx != 0 && ny != 0) {
1091 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1093 rIF.getMinMax (min, max);
1094 if (! m_bMinSpecified)
1096 if (! m_bMaxSpecified)
1099 double scaleWidth = m_dMaxPixel - m_dMinPixel;
1101 unsigned char* imageData = new unsigned char [nx * ny * 3];
1103 sys_error (ERR_SEVERE, "Unable to allocate memory for Image display");
1106 for (int ix = 0; ix < nx; ix++) {
1107 for (int iy = 0; iy < ny; iy++) {
1108 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
1109 int intensity = static_cast<int>(scaleValue + 0.5);
1110 intensity = clamp (intensity, 0, 255);
1111 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
1112 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
1115 wxImage image (nx, ny, imageData, true);
1120 *theApp->getLog() << "Making new bitmap bitmap";
1121 m_pBitmap = new wxBitmap (image);
1123 m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20);
1124 m_pCanvas->SetBackgroundColour(*wxWHITE);
1128 m_pCanvas->Refresh();
1132 ImageFileView::OnClose (bool deleteWindow)
1134 if (! GetDocument() || ! GetDocument()->Close())
1139 m_pCanvas->setView(NULL);
1142 wxString s(theApp->GetAppName());
1144 m_pFrame->SetTitle(s);
1151 if (GetDocument() && GetDocument()->getBadFileOpen())
1152 ::wxYield(); // wxWindows bug workaround
1159 ImageFileView::OnEditCopy (wxCommandEvent& event)
1161 wxBitmapDataObject *pBitmapObject = new wxBitmapDataObject;
1164 pBitmapObject->SetBitmap (*m_pBitmap);
1166 if (wxTheClipboard->Open()) {
1167 wxTheClipboard->SetData (pBitmapObject);
1168 wxTheClipboard->Close();
1173 ImageFileView::OnEditCut (wxCommandEvent& event)
1176 ImageFile& rIF = GetDocument()->getImageFile();
1179 ImageFile* pIF = new ImageFile (nx, ny);
1180 pIF->arrayDataClear();
1181 GetDocument()->setImageFile (pIF); // deletes old IF
1182 OnUpdate(this, NULL);
1183 GetDocument()->UpdateAllViews();
1184 if (theApp->getAskDeleteNewDocs())
1185 GetDocument()->Modify (true);
1189 ImageFileView::OnEditPaste (wxCommandEvent& event)
1191 ImageFile& rIF = GetDocument()->getImageFile();
1193 if (wxTheClipboard->Open()) {
1195 if (wxTheClipboard->IsSupported (wxDF_BITMAP)) {
1196 wxBitmapDataObject bitmapObject;
1197 wxTheClipboard->GetData (bitmapObject);
1198 bitmap = bitmapObject.GetBitmap ();
1200 wxTheClipboard->Close();
1204 bool bMonochrome = false;
1206 if (bitmap.Ok() == true && bitmap.GetWidth() == nx && bitmap.GetHeight() == ny) {
1207 wxImage image (bitmap.ConvertToImage());
1208 double dScale3 = 3 * 255;
1209 unsigned char* pixels = image.GetData();
1210 ImageFileArray v = rIF.getArray();
1211 for (unsigned int ix = 0; ix < rIF.nx(); ix++) {
1212 for (unsigned int iy = 0; iy < rIF.ny(); iy++) {
1213 unsigned int iBase = 3 * (iy * nx + ix);
1214 if (ix == 0 && iy == 0 && (pixels[iBase] == pixels[iBase+1] && pixels[iBase+1] == pixels[iBase+2]))
1217 v[ix][ny - 1 - iy] = (pixels[iBase]+pixels[iBase+1]+pixels[iBase+2]) / dScale3;
1219 double dR = pixels[iBase] / 255.;
1220 double dG = pixels[iBase+1] / 255.;
1221 double dB = pixels[iBase+2] / 255.;
1222 v[ix][ny - 1 - iy] = ImageFile::colorToGrayscale (dR, dG, dB);
1226 OnUpdate(this, NULL);
1227 GetDocument()->UpdateAllViews();
1228 if (theApp->getAskDeleteNewDocs())
1229 GetDocument()->Modify(true);
1235 ImageFileView::OnExport (wxCommandEvent& event)
1237 ImageFile& rIF = GetDocument()->getImageFile();
1238 ImageFileArrayConst v = rIF.getArray();
1241 if (v != NULL && nx != 0 && ny != 0) {
1242 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1244 rIF.getMinMax (min, max);
1245 if (! m_bMinSpecified)
1247 if (! m_bMaxSpecified)
1251 DialogExportParameters dialogExport (getFrameForChild(), m_iDefaultExportFormatID);
1252 if (dialogExport.ShowModal() == wxID_OK) {
1253 wxString strFormatName (dialogExport.getFormatName ());
1254 m_iDefaultExportFormatID = ImageFile::convertExportFormatNameToID (strFormatName.c_str());
1257 wxString strWildcard;
1258 if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PGM || m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PGMASCII) {
1260 strWildcard = "PGM Files (*.pgm)|*.pgm";
1263 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PNG || m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PNG16) {
1265 strWildcard = "PNG Files (*.png)|*.png";
1268 #ifdef HAVE_CTN_DICOM
1269 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_DICOM) {
1271 strWildcard = "DICOM Files (*.*)|*.*";
1274 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_TEXT) {
1276 strWildcard = "Text (*.txt)|*.txt";
1280 strWildcard = "Miscellaneous (*.*)|*.*";
1283 const wxString& strFilename = wxFileSelector (wxString("Export Filename"), wxString(""),
1284 wxString(""), strExt, strWildcard, wxOVERWRITE_PROMPT | wxHIDE_READONLY | wxSAVE);
1286 rIF.exportImage (strFormatName.c_str(), strFilename.c_str(), 1, 1, m_dMinPixel, m_dMaxPixel);
1287 *theApp->getLog() << "Exported file " << strFilename << "\n";
1294 ImageFileView::OnScaleSize (wxCommandEvent& event)
1296 ImageFile& rIF = GetDocument()->getImageFile();
1297 unsigned int iOldNX = rIF.nx();
1298 unsigned int iOldNY = rIF.ny();
1300 DialogGetXYSize dialogGetXYSize (getFrameForChild(), "Set New X & Y Dimensions", iOldNX, iOldNY);
1301 if (dialogGetXYSize.ShowModal() == wxID_OK) {
1302 unsigned int iNewNX = dialogGetXYSize.getXSize();
1303 unsigned int iNewNY = dialogGetXYSize.getYSize();
1304 std::ostringstream os;
1305 os << "Scale Size from (" << iOldNX << "," << iOldNY << ") to (" << iNewNX << "," << iNewNY << ")";
1306 ImageFileDocument* pScaledDoc = theApp->newImageDoc();
1308 sys_error (ERR_SEVERE, "Unable to create image file");
1311 ImageFile& rScaledIF = pScaledDoc->getImageFile();
1312 rScaledIF.setArraySize (iNewNX, iNewNY);
1313 rScaledIF.labelsCopy (rIF);
1314 rScaledIF.labelAdd (os.str().c_str());
1315 rIF.scaleImage (rScaledIF);
1316 *theApp->getLog() << os.str().c_str() << "\n";
1317 if (theApp->getAskDeleteNewDocs())
1318 pScaledDoc->Modify (true);
1319 pScaledDoc->UpdateAllViews (this);
1320 pScaledDoc->getView()->setInitialClientSize();
1321 pScaledDoc->Activate();
1327 ImageFileView::OnConvert3d (wxCommandEvent& event)
1329 ImageFile& rIF = GetDocument()->getImageFile();
1330 Graph3dFileDocument* pGraph3d = theApp->newGraph3dDoc();
1331 pGraph3d->getView()->getFrame()->Show (false);
1332 pGraph3d->setBadFileOpen();
1333 pGraph3d->createFromImageFile (rIF);
1334 pGraph3d->UpdateAllViews();
1335 pGraph3d->getView()->getFrame()->Show (true);
1336 pGraph3d->getView()->Activate(true);
1338 pGraph3d->getView()->getCanvas()->SetFocus();
1343 ImageFileView::OnPlotRow (wxCommandEvent& event)
1345 int xCursor, yCursor;
1346 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1347 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1351 const ImageFile& rIF = GetDocument()->getImageFile();
1352 ImageFileArrayConst v = rIF.getArray();
1353 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1357 if (v != NULL && yCursor < ny) {
1358 double* pX = new double [nx];
1359 double* pYReal = new double [nx];
1360 double *pYImag = NULL;
1361 double *pYMag = NULL;
1362 if (rIF.isComplex()) {
1363 pYImag = new double [nx];
1364 pYMag = new double [nx];
1366 for (int i = 0; i < nx; i++) {
1368 pYReal[i] = v[i][yCursor];
1369 if (rIF.isComplex()) {
1370 pYImag[i] = vImag[i][yCursor];
1371 pYMag[i] = ::sqrt (v[i][yCursor] * v[i][yCursor] + vImag[i][yCursor] * vImag[i][yCursor]);
1374 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1376 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1378 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1379 std::ostringstream os;
1380 os << "Row " << yCursor;
1381 std::string title("title ");
1383 rPlotFile.addEzsetCommand (title.c_str());
1384 rPlotFile.addEzsetCommand ("xlabel Column");
1385 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1386 rPlotFile.addEzsetCommand ("lxfrac 0");
1387 rPlotFile.addEzsetCommand ("box");
1388 rPlotFile.addEzsetCommand ("grid");
1389 rPlotFile.addEzsetCommand ("curve 1");
1390 rPlotFile.addEzsetCommand ("color 1");
1391 if (rIF.isComplex()) {
1392 rPlotFile.addEzsetCommand ("dash 1");
1393 rPlotFile.addEzsetCommand ("curve 2");
1394 rPlotFile.addEzsetCommand ("color 4");
1395 rPlotFile.addEzsetCommand ("dash 3");
1396 rPlotFile.addEzsetCommand ("curve 3");
1397 rPlotFile.addEzsetCommand ("color 0");
1398 rPlotFile.addEzsetCommand ("solid");
1399 rPlotFile.setCurveSize (4, nx);
1401 rPlotFile.setCurveSize (2, nx);
1402 rPlotFile.addColumn (0, pX);
1403 rPlotFile.addColumn (1, pYReal);
1404 if (rIF.isComplex()) {
1405 rPlotFile.addColumn (2, pYImag);
1406 rPlotFile.addColumn (3, pYMag);
1408 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1409 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1410 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1411 *theApp->getLog() << os.str().c_str() << "\n";
1412 rPlotFile.addDescription (os.str().c_str());
1416 if (rIF.isComplex()) {
1420 if (theApp->getAskDeleteNewDocs())
1421 pPlotDoc->Modify (true);
1422 pPlotDoc->getView()->getFrame()->Show(true);
1423 pPlotDoc->UpdateAllViews ();
1424 pPlotDoc->Activate();
1429 ImageFileView::OnPlotCol (wxCommandEvent& event)
1431 int xCursor, yCursor;
1432 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1433 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1437 const ImageFile& rIF = GetDocument()->getImageFile();
1438 ImageFileArrayConst v = rIF.getArray();
1439 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1443 if (v != NULL && xCursor < nx) {
1444 double* pX = new double [ny];
1445 double* pYReal = new double [ny];
1446 double* pYImag = NULL;
1447 double* pYMag = NULL;
1448 if (rIF.isComplex()) {
1449 pYImag = new double [ny];
1450 pYMag = new double [ny];
1452 for (int i = 0; i < ny; i++) {
1454 pYReal[i] = v[xCursor][i];
1455 if (rIF.isComplex()) {
1456 pYImag[i] = vImag[xCursor][i];
1457 pYMag[i] = ::sqrt (v[xCursor][i] * v[xCursor][i] + vImag[xCursor][i] * vImag[xCursor][i]);
1460 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1462 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1464 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1465 std::ostringstream os;
1466 os << "Column " << xCursor;
1467 std::string title("title ");
1469 rPlotFile.addEzsetCommand (title.c_str());
1470 rPlotFile.addEzsetCommand ("xlabel Row");
1471 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1472 rPlotFile.addEzsetCommand ("lxfrac 0");
1473 rPlotFile.addEzsetCommand ("box");
1474 rPlotFile.addEzsetCommand ("grid");
1475 rPlotFile.addEzsetCommand ("curve 1");
1476 rPlotFile.addEzsetCommand ("color 1");
1477 if (rIF.isComplex()) {
1478 rPlotFile.addEzsetCommand ("dash 1");
1479 rPlotFile.addEzsetCommand ("curve 2");
1480 rPlotFile.addEzsetCommand ("color 4");
1481 rPlotFile.addEzsetCommand ("dash 3");
1482 rPlotFile.addEzsetCommand ("curve 3");
1483 rPlotFile.addEzsetCommand ("color 0");
1484 rPlotFile.addEzsetCommand ("solid");
1485 rPlotFile.setCurveSize (4, ny);
1487 rPlotFile.setCurveSize (2, ny);
1488 rPlotFile.addColumn (0, pX);
1489 rPlotFile.addColumn (1, pYReal);
1490 if (rIF.isComplex()) {
1491 rPlotFile.addColumn (2, pYImag);
1492 rPlotFile.addColumn (3, pYMag);
1494 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1495 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1496 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1497 *theApp->getLog() << os.str().c_str() << "\n";
1498 rPlotFile.addDescription (os.str().c_str());
1502 if (rIF.isComplex()) {
1506 if (theApp->getAskDeleteNewDocs())
1507 pPlotDoc->Modify (true);
1508 pPlotDoc->getView()->getFrame()->Show(true);
1509 pPlotDoc->UpdateAllViews ();
1510 pPlotDoc->Activate();
1516 ImageFileView::OnPlotFFTRow (wxCommandEvent& event)
1518 int xCursor, yCursor;
1519 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1520 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1524 const ImageFile& rIF = GetDocument()->getImageFile();
1525 ImageFileArrayConst v = rIF.getArray();
1526 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1530 if (v != NULL && yCursor < ny) {
1531 fftw_complex* pcIn = new fftw_complex [nx];
1534 for (i = 0; i < nx; i++) {
1535 pcIn[i].re = v[i][yCursor];
1536 if (rIF.isComplex())
1537 pcIn[i].im = vImag[i][yCursor];
1542 fftw_plan plan = fftw_create_plan (nx, FFTW_FORWARD, FFTW_IN_PLACE | FFTW_ESTIMATE | FFTW_USE_WISDOM);
1543 fftw_one (plan, pcIn, NULL);
1544 fftw_destroy_plan (plan);
1546 double* pX = new double [nx];
1547 double* pYReal = new double [nx];
1548 double* pYImag = new double [nx];
1549 double* pYMag = new double [nx];
1550 for (i = 0; i < nx; i++) {
1552 pYReal[i] = pcIn[i].re / nx;
1553 pYImag[i] = pcIn[i].im / nx;
1554 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1556 Fourier::shuffleFourierToNaturalOrder (pYReal, nx);
1557 Fourier::shuffleFourierToNaturalOrder (pYImag, nx);
1558 Fourier::shuffleFourierToNaturalOrder (pYMag, nx);
1560 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1562 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1564 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1565 std::ostringstream os;
1566 os << "Row " << yCursor;
1567 std::string title("title ");
1569 rPlotFile.addEzsetCommand (title.c_str());
1570 rPlotFile.addEzsetCommand ("xlabel Column");
1571 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1572 rPlotFile.addEzsetCommand ("lxfrac 0");
1573 rPlotFile.addEzsetCommand ("curve 1");
1574 rPlotFile.addEzsetCommand ("color 1");
1575 rPlotFile.addEzsetCommand ("dash 1");
1576 rPlotFile.addEzsetCommand ("curve 2");
1577 rPlotFile.addEzsetCommand ("color 4");
1578 rPlotFile.addEzsetCommand ("dash 3");
1579 rPlotFile.addEzsetCommand ("curve 3");
1580 rPlotFile.addEzsetCommand ("color 0");
1581 rPlotFile.addEzsetCommand ("solid");
1582 rPlotFile.addEzsetCommand ("box");
1583 rPlotFile.addEzsetCommand ("grid");
1584 rPlotFile.setCurveSize (4, nx);
1585 rPlotFile.addColumn (0, pX);
1586 rPlotFile.addColumn (1, pYReal);
1587 rPlotFile.addColumn (2, pYImag);
1588 rPlotFile.addColumn (3, pYMag);
1589 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1590 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1591 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1592 *theApp->getLog() << os.str().c_str() << "\n";
1593 rPlotFile.addDescription (os.str().c_str());
1601 if (theApp->getAskDeleteNewDocs())
1602 pPlotDoc->Modify (true);
1603 pPlotDoc->getView()->getFrame()->Show(true);
1604 pPlotDoc->UpdateAllViews ();
1605 pPlotDoc->Activate();
1610 ImageFileView::OnPlotFFTCol (wxCommandEvent& event)
1612 int xCursor, yCursor;
1613 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1614 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1618 const ImageFile& rIF = GetDocument()->getImageFile();
1619 ImageFileArrayConst v = rIF.getArray();
1620 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1624 if (v != NULL && xCursor < nx) {
1625 fftw_complex* pcIn = new fftw_complex [ny];
1626 double *pdTemp = new double [ny];
1629 for (i = 0; i < ny; i++)
1630 pdTemp[i] = v[xCursor][i];
1631 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1632 for (i = 0; i < ny; i++)
1633 pcIn[i].re = pdTemp[i];
1635 for (i = 0; i < ny; i++) {
1636 if (rIF.isComplex())
1637 pdTemp[i] = vImag[xCursor][i];
1641 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1642 for (i = 0; i < ny; i++)
1643 pcIn[i].im = pdTemp[i];
1645 fftw_plan plan = fftw_create_plan (ny, FFTW_BACKWARD, FFTW_IN_PLACE | FFTW_ESTIMATE | FFTW_USE_WISDOM);
1646 fftw_one (plan, pcIn, NULL);
1647 fftw_destroy_plan (plan);
1649 double* pX = new double [ny];
1650 double* pYReal = new double [ny];
1651 double* pYImag = new double [ny];
1652 double* pYMag = new double [ny];
1653 for (i = 0; i < ny; i++) {
1655 pYReal[i] = pcIn[i].re / ny;
1656 pYImag[i] = pcIn[i].im / ny;
1657 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1660 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1662 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1664 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1665 std::ostringstream os;
1666 os << "Column " << xCursor;
1667 std::string title("title ");
1669 rPlotFile.addEzsetCommand (title.c_str());
1670 rPlotFile.addEzsetCommand ("xlabel Column");
1671 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1672 rPlotFile.addEzsetCommand ("lxfrac 0");
1673 rPlotFile.addEzsetCommand ("curve 1");
1674 rPlotFile.addEzsetCommand ("color 1");
1675 rPlotFile.addEzsetCommand ("dash 1");
1676 rPlotFile.addEzsetCommand ("curve 2");
1677 rPlotFile.addEzsetCommand ("color 4");
1678 rPlotFile.addEzsetCommand ("dash 3");
1679 rPlotFile.addEzsetCommand ("curve 3");
1680 rPlotFile.addEzsetCommand ("color 0");
1681 rPlotFile.addEzsetCommand ("solid");
1682 rPlotFile.addEzsetCommand ("box");
1683 rPlotFile.addEzsetCommand ("grid");
1684 rPlotFile.setCurveSize (4, ny);
1685 rPlotFile.addColumn (0, pX);
1686 rPlotFile.addColumn (1, pYReal);
1687 rPlotFile.addColumn (2, pYImag);
1688 rPlotFile.addColumn (3, pYMag);
1689 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1690 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1691 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1692 *theApp->getLog() << os.str().c_str() << "\n";
1693 rPlotFile.addDescription (os.str().c_str());
1702 if (theApp->getAskDeleteNewDocs())
1703 pPlotDoc->Modify (true);
1704 pPlotDoc->getView()->getFrame()->Show(true);
1705 pPlotDoc->UpdateAllViews ();
1706 pPlotDoc->Activate();
1712 ImageFileView::OnCompareCol (wxCommandEvent& event)
1714 int xCursor, yCursor;
1715 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1716 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1720 std::vector<ImageFileDocument*> vecIFDoc;
1721 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1722 if (vecIFDoc.size() == 0) {
1723 wxMessageBox ("No compatible images for Column Comparison", "Error");
1726 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1728 if (dialogGetCompare.ShowModal() == wxID_OK) {
1729 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1730 const ImageFile& rIF = GetDocument()->getImageFile();
1731 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1733 ImageFileArrayConst v1 = rIF.getArray();
1734 ImageFileArrayConst v2 = rCompareIF.getArray();
1738 if (v1 != NULL && xCursor < nx) {
1739 double* pX = new double [ny];
1740 double* pY1 = new double [ny];
1741 double* pY2 = new double [ny];
1742 for (int i = 0; i < ny; i++) {
1744 pY1[i] = v1[xCursor][i];
1745 pY2[i] = v2[xCursor][i];
1747 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1749 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1751 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1752 std::ostringstream os;
1753 os << "Column " << xCursor << " Comparison";
1754 std::string title("title ");
1756 rPlotFile.addEzsetCommand (title.c_str());
1757 rPlotFile.addEzsetCommand ("xlabel Row");
1758 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1759 rPlotFile.addEzsetCommand ("lxfrac 0");
1760 rPlotFile.addEzsetCommand ("curve 1");
1761 rPlotFile.addEzsetCommand ("color 2");
1762 rPlotFile.addEzsetCommand ("curve 2");
1763 rPlotFile.addEzsetCommand ("color 4");
1764 rPlotFile.addEzsetCommand ("dash 5");
1765 rPlotFile.addEzsetCommand ("box");
1766 rPlotFile.addEzsetCommand ("grid");
1767 rPlotFile.setCurveSize (3, ny);
1768 rPlotFile.addColumn (0, pX);
1769 rPlotFile.addColumn (1, pY1);
1770 rPlotFile.addColumn (2, pY2);
1773 for (iL = 0; iL < rIF.nLabels(); iL++) {
1774 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1776 s += rIF.labelGet(iL).getLabelString();
1777 rPlotFile.addDescription (s.c_str());
1779 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1780 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1782 s += rCompareIF.labelGet(iL).getLabelString();
1783 rPlotFile.addDescription (s.c_str());
1785 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1786 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1787 *theApp->getLog() << os.str().c_str() << "\n";
1788 rPlotFile.addDescription (os.str().c_str());
1793 if (theApp->getAskDeleteNewDocs())
1794 pPlotDoc->Modify (true);
1795 pPlotDoc->getView()->getFrame()->Show(true);
1796 pPlotDoc->UpdateAllViews ();
1797 pPlotDoc->Activate();
1803 ImageFileView::OnCompareRow (wxCommandEvent& event)
1805 int xCursor, yCursor;
1806 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1807 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1811 std::vector<ImageFileDocument*> vecIFDoc;
1812 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1814 if (vecIFDoc.size() == 0) {
1815 wxMessageBox ("No compatible images for Row Comparison", "Error");
1819 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1821 if (dialogGetCompare.ShowModal() == wxID_OK) {
1822 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1823 const ImageFile& rIF = GetDocument()->getImageFile();
1824 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1826 ImageFileArrayConst v1 = rIF.getArray();
1827 ImageFileArrayConst v2 = rCompareIF.getArray();
1831 if (v1 != NULL && yCursor < ny) {
1832 double* pX = new double [nx];
1833 double* pY1 = new double [nx];
1834 double* pY2 = new double [nx];
1835 for (int i = 0; i < nx; i++) {
1837 pY1[i] = v1[i][yCursor];
1838 pY2[i] = v2[i][yCursor];
1840 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1842 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1844 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1845 std::ostringstream os;
1846 os << "Row " << yCursor << " Comparison";
1847 std::string title("title ");
1849 rPlotFile.addEzsetCommand (title.c_str());
1850 rPlotFile.addEzsetCommand ("xlabel Column");
1851 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1852 rPlotFile.addEzsetCommand ("lxfrac 0");
1853 rPlotFile.addEzsetCommand ("curve 1");
1854 rPlotFile.addEzsetCommand ("color 2");
1855 rPlotFile.addEzsetCommand ("curve 2");
1856 rPlotFile.addEzsetCommand ("color 4");
1857 rPlotFile.addEzsetCommand ("dash 5");
1858 rPlotFile.addEzsetCommand ("box");
1859 rPlotFile.addEzsetCommand ("grid");
1860 rPlotFile.setCurveSize (3, nx);
1861 rPlotFile.addColumn (0, pX);
1862 rPlotFile.addColumn (1, pY1);
1863 rPlotFile.addColumn (2, pY2);
1865 for (iL = 0; iL < rIF.nLabels(); iL++) {
1866 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1868 s += rIF.labelGet(iL).getLabelString();
1869 rPlotFile.addDescription (s.c_str());
1871 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1872 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1874 s += rCompareIF.labelGet(iL).getLabelString();
1875 rPlotFile.addDescription (s.c_str());
1877 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1878 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1879 *theApp->getLog() << os.str().c_str() << "\n";
1880 rPlotFile.addDescription (os.str().c_str());
1885 if (theApp->getAskDeleteNewDocs())
1886 pPlotDoc->Modify (true);
1887 pPlotDoc->getView()->getFrame()->Show(true);
1888 pPlotDoc->UpdateAllViews ();
1889 pPlotDoc->Activate();
1894 static int NUMBER_HISTOGRAM_BINS = 256;
1897 ImageFileView::OnPlotHistogram (wxCommandEvent& event)
1899 const ImageFile& rIF = GetDocument()->getImageFile();
1900 ImageFileArrayConst v = rIF.getArray();
1904 if (v != NULL && nx > 0 && ny > 0) {
1905 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1907 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1911 double* pX = new double [NUMBER_HISTOGRAM_BINS];
1912 double* pY = new double [NUMBER_HISTOGRAM_BINS];
1914 rIF.getMinMax (dMin, dMax);
1915 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
1917 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
1918 pX[i] = dMin + (i + 0.5) * dBinWidth;
1921 for (int ix = 0; ix < nx; ix++)
1922 for (int iy = 0; iy < ny; iy++) {
1923 int iBin = nearest<int> ((v[ix][iy] - dMin) / dBinWidth);
1924 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
1928 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1929 std::ostringstream os;
1931 std::string title("title ");
1933 rPlotFile.addEzsetCommand (title.c_str());
1934 rPlotFile.addEzsetCommand ("xlabel Pixel Value");
1935 rPlotFile.addEzsetCommand ("ylabel Count");
1936 rPlotFile.addEzsetCommand ("box");
1937 rPlotFile.addEzsetCommand ("grid");
1938 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
1939 rPlotFile.addColumn (0, pX);
1940 rPlotFile.addColumn (1, pY);
1941 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++) {
1942 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1944 s += rIF.labelGet(iL).getLabelString();
1945 rPlotFile.addDescription (s.c_str());
1947 os << " plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1948 *theApp->getLog() << os.str().c_str() << "\n";
1949 rPlotFile.addDescription (os.str().c_str());
1952 if (theApp->getAskDeleteNewDocs())
1953 pPlotDoc->Modify (true);
1954 pPlotDoc->getView()->getFrame()->Show(true);
1955 pPlotDoc->UpdateAllViews ();
1956 pPlotDoc->Activate();
1963 PhantomCanvas::PhantomCanvas (PhantomFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1964 : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v)
1968 PhantomCanvas::~PhantomCanvas ()
1974 PhantomCanvas::OnDraw (wxDC& dc)
1977 m_pView->OnDraw(& dc);
1981 PhantomCanvas::GetBestSize() const
1987 theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
1988 xSize = maxValue<int> (xSize, ySize);
1990 ySize = xSize = (xSize / 4);
1992 xSize = ySize = static_cast<int>(ySize * .7);
1995 return wxSize (xSize, ySize);
2002 IMPLEMENT_DYNAMIC_CLASS(PhantomFileView, wxView)
2004 BEGIN_EVENT_TABLE(PhantomFileView, wxView)
2005 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomFileView::OnProperties)
2006 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomFileView::OnRasterize)
2007 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomFileView::OnProjections)
2010 PhantomFileView::PhantomFileView()
2011 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0)
2013 #if defined(DEBUG) || defined(_DEBUG)
2014 m_iDefaultNDet = 165;
2015 m_iDefaultNView = 180;
2016 m_iDefaultNSample = 1;
2018 m_iDefaultNDet = 367;
2019 m_iDefaultNView = 320;
2020 m_iDefaultNSample = 2;
2022 m_iDefaultOffsetView = 0;
2023 m_dDefaultRotation = 1;
2024 m_dDefaultFocalLength = 2;
2025 m_dDefaultCenterDetectorLength = 2;
2026 m_dDefaultViewRatio = 1;
2027 m_dDefaultScanRatio = 1;
2028 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
2029 m_iDefaultTrace = Trace::TRACE_NONE;
2032 m_iDefaultRasterNX = 115;
2033 m_iDefaultRasterNY = 115;
2034 m_iDefaultRasterNSamples = 1;
2036 m_iDefaultRasterNX = 256;
2037 m_iDefaultRasterNY = 256;
2038 m_iDefaultRasterNSamples = 2;
2040 m_dDefaultRasterViewRatio = 1;
2043 PhantomFileView::~PhantomFileView()
2045 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2046 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
2050 PhantomFileView::OnProperties (wxCommandEvent& event)
2052 const int idPhantom = GetDocument()->getPhantomID();
2053 const wxString& namePhantom = GetDocument()->getPhantomName();
2054 std::ostringstream os;
2055 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")" << "\n";
2056 const Phantom& rPhantom = GetDocument()->getPhantom();
2057 rPhantom.printDefinitions (os);
2059 rPhantom.print (os);
2061 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2062 wxMessageBox (os.str().c_str(), "Phantom Properties");
2063 GetDocument()->Activate();
2068 PhantomFileView::OnProjections (wxCommandEvent& event)
2070 DialogGetProjectionParameters dialogProjection (getFrameForChild(),
2071 m_iDefaultNDet, m_iDefaultNView, m_iDefaultOffsetView, m_iDefaultNSample, m_dDefaultRotation,
2072 m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio,
2073 m_iDefaultGeometry, m_iDefaultTrace);
2074 int retVal = dialogProjection.ShowModal();
2075 if (retVal != wxID_OK)
2078 m_iDefaultNDet = dialogProjection.getNDet();
2079 m_iDefaultNView = dialogProjection.getNView();
2080 m_iDefaultOffsetView = dialogProjection.getOffsetView();
2081 m_iDefaultNSample = dialogProjection.getNSamples();
2082 m_iDefaultTrace = dialogProjection.getTrace();
2083 m_dDefaultRotation = dialogProjection.getRotAngle();
2084 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
2085 m_dDefaultCenterDetectorLength = dialogProjection.getCenterDetectorLengthRatio();
2086 m_dDefaultViewRatio = dialogProjection.getViewRatio();
2087 m_dDefaultScanRatio = dialogProjection.getScanRatio();
2088 wxString sGeometry = dialogProjection.getGeometry();
2089 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
2090 double dRotationRadians = m_dDefaultRotation;
2091 m_dDefaultRotation /= TWOPI; // convert back to fraction of a circle
2093 if (m_iDefaultNDet <= 0 || m_iDefaultNView <= 0 || sGeometry == "")
2096 const Phantom& rPhantom = GetDocument()->getPhantom();
2097 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultOffsetView, m_iDefaultNSample,
2098 dRotationRadians, m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio);
2099 if (theScanner.fail()) {
2100 wxString msg = "Failed making scanner\n";
2101 msg += theScanner.failMessage().c_str();
2102 *theApp->getLog() << msg << "\n";
2103 wxMessageBox (msg, "Error");
2107 std::ostringstream os;
2108 os << "Projections for " << rPhantom.name()
2109 << ": nDet=" << m_iDefaultNDet
2110 << ", nView=" << m_iDefaultNView
2111 << ", gantry offset=" << m_iDefaultOffsetView
2112 << ", nSamples=" << m_iDefaultNSample
2113 << ", RotAngle=" << m_dDefaultRotation
2114 << ", FocalLengthRatio=" << m_dDefaultFocalLength
2115 << ", CenterDetectorLengthRatio=" << m_dDefaultCenterDetectorLength
2116 << ", ViewRatio=" << m_dDefaultViewRatio
2117 << ", ScanRatio=" << m_dDefaultScanRatio
2118 << ", Geometry=" << sGeometry.c_str()
2119 << ", FanBeamAngle=" << convertRadiansToDegrees (theScanner.fanBeamAngle());
2122 Projections* pProj = NULL;
2123 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2124 pProj = new Projections;
2125 pProj->initFromScanner (theScanner);
2127 ProjectionsDialog dialogProjections (theScanner, *pProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(getFrameForChild()));
2128 for (int iView = 0; iView < pProj->nView(); iView++) {
2130 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
2135 while (dialogProjections.isPaused()) {
2142 if (theApp->getUseBackgroundTasks()) {
2143 ProjectorSupervisorThread* pProjector = new ProjectorSupervisorThread (this, m_iDefaultNDet,
2144 m_iDefaultNView, m_iDefaultOffsetView, sGeometry.c_str(), m_iDefaultNSample, dRotationRadians,
2145 m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio, os.str().c_str());
2146 if (pProjector->Create() != wxTHREAD_NO_ERROR) {
2147 sys_error (ERR_SEVERE, "Error creating projector thread");
2151 pProjector->SetPriority(60);
2155 #endif // HAVE_WXTHREADS
2157 pProj = new Projections;
2158 pProj->initFromScanner (theScanner);
2159 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), pProj->nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2160 for (int i = 0; i < pProj->nView(); i++) {
2161 //theScanner.collectProjections (*pProj, rPhantom, i, 1, true, m_iDefaultTrace);
2162 theScanner.collectProjections (*pProj, rPhantom, i, 1, theScanner.offsetView(), true, m_iDefaultTrace);
2163 if ((i + 1) % ITER_PER_UPDATE == 0)
2164 if (! dlgProgress.Update (i+1)) {
2172 *theApp->getLog() << os.str().c_str() << "\n";
2173 pProj->setRemark (os.str());
2174 pProj->setCalcTime (timer.timerEnd());
2176 ProjectionFileDocument* pProjectionDoc = theApp->newProjectionDoc();
2177 if (! pProjectionDoc) {
2178 sys_error (ERR_SEVERE, "Unable to create projection document");
2181 pProjectionDoc->setProjections (pProj);
2182 if (theApp->getAskDeleteNewDocs())
2183 pProjectionDoc-> Modify(true);
2184 pProjectionDoc->UpdateAllViews (this);
2185 pProjectionDoc->getView()->setInitialClientSize();
2186 pProjectionDoc->Activate();
2191 PhantomFileView::OnRasterize (wxCommandEvent& event)
2193 DialogGetRasterParameters dialogRaster (getFrameForChild(), m_iDefaultRasterNX, m_iDefaultRasterNY,
2194 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio);
2195 int retVal = dialogRaster.ShowModal();
2196 if (retVal != wxID_OK)
2199 m_iDefaultRasterNX = dialogRaster.getXSize();
2200 m_iDefaultRasterNY = dialogRaster.getYSize();
2201 m_iDefaultRasterNSamples = dialogRaster.getNSamples();
2202 m_dDefaultRasterViewRatio = dialogRaster.getViewRatio();
2203 if (m_iDefaultRasterNSamples < 1)
2204 m_iDefaultRasterNSamples = 1;
2205 if (m_dDefaultRasterViewRatio < 0)
2206 m_dDefaultRasterViewRatio = 0;
2207 if (m_iDefaultRasterNX <= 0 || m_iDefaultRasterNY <= 0)
2210 const Phantom& rPhantom = GetDocument()->getPhantom();
2211 std::ostringstream os;
2212 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << m_iDefaultRasterNX << ", YSize="
2213 << m_iDefaultRasterNY << ", ViewRatio=" << m_dDefaultRasterViewRatio << ", nSamples="
2214 << m_iDefaultRasterNSamples;;
2217 if (theApp->getUseBackgroundTasks()) {
2218 RasterizerSupervisorThread* pThread = new RasterizerSupervisorThread (this, m_iDefaultRasterNX, m_iDefaultRasterNY,
2219 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio, os.str().c_str());
2220 if (pThread->Create() != wxTHREAD_NO_ERROR) {
2221 *theApp->getLog() << "Error creating rasterizer thread\n";
2224 pThread->SetPriority (60);
2229 ImageFile* pImageFile = new ImageFile (m_iDefaultRasterNX, m_iDefaultRasterNY);
2231 wxProgressDialog dlgProgress (wxString("Rasterize"),
2232 wxString("Rasterization Progress"),
2233 pImageFile->nx() + 1,
2237 for (unsigned int i = 0; i < pImageFile->nx(); i++) {
2238 rPhantom.convertToImagefile (*pImageFile, m_dDefaultRasterViewRatio,
2239 m_iDefaultRasterNSamples, Trace::TRACE_NONE,
2241 if ((i + 1) % ITER_PER_UPDATE == 0)
2242 if (! dlgProgress.Update (i+1)) {
2248 ImageFileDocument* pRasterDoc = theApp->newImageDoc();
2250 sys_error (ERR_SEVERE, "Unable to create image file");
2253 pRasterDoc->setImageFile (pImageFile);
2254 if (theApp->getAskDeleteNewDocs())
2255 pRasterDoc->Modify (true);
2256 *theApp->getLog() << os.str().c_str() << "\n";
2257 pImageFile->labelAdd (os.str().c_str(), timer.timerEnd());
2259 pRasterDoc->UpdateAllViews(this);
2260 pRasterDoc->getView()->setInitialClientSize();
2261 pRasterDoc->Activate();
2267 PhantomFileView::CreateCanvas (wxFrame *parent)
2269 PhantomCanvas* pCanvas = new PhantomCanvas (this, parent, wxPoint(-1,-1),
2271 pCanvas->SetBackgroundColour(*wxWHITE);
2282 PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2285 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
2287 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
2289 theApp->setIconForFrame (subframe);
2291 m_pFileMenu = new wxMenu;
2293 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2294 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2295 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2296 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2297 m_pFileMenu->Append(wxID_CLOSE, "&Close");
2299 m_pFileMenu->AppendSeparator();
2300 m_pFileMenu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
2302 m_pFileMenu->AppendSeparator();
2303 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2304 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2305 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2306 m_pFileMenu->AppendSeparator();
2307 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
2308 m_pFileMenu->AppendSeparator();
2309 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
2310 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2311 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2312 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2314 wxMenu *process_menu = new wxMenu;
2315 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...\tCtrl-R");
2316 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...\tCtrl-J");
2318 wxMenu *help_menu = new wxMenu;
2319 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2320 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
2321 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
2322 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2324 wxMenuBar *menu_bar = new wxMenuBar;
2326 menu_bar->Append(m_pFileMenu, "&File");
2327 menu_bar->Append(process_menu, "&Process");
2328 menu_bar->Append(help_menu, "&Help");
2330 subframe->SetMenuBar(menu_bar);
2331 subframe->Centre(wxBOTH);
2333 wxAcceleratorEntry accelEntries[3];
2334 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('J'), PHMMENU_PROCESS_PROJECTIONS);
2335 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('R'), PHMMENU_PROCESS_RASTERIZE);
2336 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('I'), PHMMENU_FILE_PROPERTIES);
2337 wxAcceleratorTable accelTable (3, accelEntries);
2338 subframe->SetAcceleratorTable (accelTable);
2345 PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2347 m_pFrame = CreateChildFrame(doc, this);
2349 m_pCanvas = CreateCanvas (m_pFrame);
2350 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
2351 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
2352 m_pFrame->SetTitle ("PhantomFileView");
2354 m_pFrame->Show(true);
2361 PhantomFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2364 m_pCanvas->Refresh();
2368 PhantomFileView::OnClose (bool deleteWindow)
2370 if (! GetDocument() || ! GetDocument()->Close())
2375 m_pCanvas->setView(NULL);
2378 wxString s(wxTheApp->GetAppName());
2380 m_pFrame->SetTitle(s);
2387 if (GetDocument() && GetDocument()->getBadFileOpen())
2388 ::wxYield(); // wxWindows bug workaround
2395 PhantomFileView::OnDraw (wxDC* dc)
2398 m_pCanvas->GetClientSize (&xsize, &ysize);
2399 SGPDriver driver (dc, xsize, ysize);
2401 const Phantom& rPhantom = GetDocument()->getPhantom();
2402 sgp.setColor (C_RED);
2403 rPhantom.show (sgp);
2408 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2409 : wxScrolledWindow(frame, -1, pos, size, style)
2414 ProjectionFileCanvas::~ProjectionFileCanvas ()
2420 ProjectionFileCanvas::OnDraw(wxDC& dc)
2423 m_pView->OnDraw(& dc);
2427 ProjectionFileCanvas::GetBestSize () const
2429 const int iMinX = 50;
2430 const int iMinY = 20;
2431 wxSize bestSize (iMinX,iMinY);
2434 Projections& rProj = m_pView->GetDocument()->getProjections();
2435 bestSize.Set (rProj.nDet(), rProj.nView());
2438 if (bestSize.x > 800)
2440 if (bestSize.y > 800)
2443 if (bestSize.x < iMinX)
2445 if (bestSize.y < iMinY)
2452 // ProjectionFileView
2454 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
2456 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
2457 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
2458 EVT_MENU(PJMENU_RECONSTRUCT_FBP, ProjectionFileView::OnReconstructFBP)
2459 EVT_MENU(PJMENU_RECONSTRUCT_FBP_REBIN, ProjectionFileView::OnReconstructFBPRebin)
2460 EVT_MENU(PJMENU_RECONSTRUCT_FOURIER, ProjectionFileView::OnReconstructFourier)
2461 EVT_MENU(PJMENU_CONVERT_RECTANGULAR, ProjectionFileView::OnConvertRectangular)
2462 EVT_MENU(PJMENU_CONVERT_POLAR, ProjectionFileView::OnConvertPolar)
2463 EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
2464 EVT_MENU(PJMENU_CONVERT_PARALLEL, ProjectionFileView::OnConvertParallel)
2465 EVT_MENU(PJMENU_PLOT_TTHETA_SAMPLING, ProjectionFileView::OnPlotTThetaSampling)
2466 EVT_MENU(PJMENU_PLOT_HISTOGRAM, ProjectionFileView::OnPlotHistogram)
2467 // EVT_MENU(PJMENU_ARTIFACT_REDUCTION, ProjectionFileView::OnArtifactReduction)
2471 ProjectionFileView::ProjectionFileView()
2472 : wxView(), m_pBitmap(0), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0)
2482 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
2483 m_dDefaultFilterParam = 1.;
2485 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
2486 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
2488 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
2489 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
2491 m_iDefaultZeropad = 1;
2492 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF;
2493 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
2494 m_iDefaultInterpParam = 1;
2495 m_iDefaultTrace = Trace::TRACE_NONE;
2497 m_iDefaultPolarNX = 256;
2498 m_iDefaultPolarNY = 256;
2499 m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR;
2500 m_iDefaultPolarZeropad = 1;
2503 ProjectionFileView::~ProjectionFileView()
2505 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2506 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2510 ProjectionFileView::OnProperties (wxCommandEvent& event)
2512 const Projections& rProj = GetDocument()->getProjections();
2513 std::ostringstream os;
2514 rProj.printScanInfo(os);
2515 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2516 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
2517 dialogMsg.ShowModal();
2518 GetDocument()->Activate();
2523 ProjectionFileView::OnConvertRectangular (wxCommandEvent& event)
2525 Projections& rProj = GetDocument()->getProjections();
2527 int nDet = rProj.nDet();
2528 int nView = rProj.nView();
2529 ImageFile* pIF = new ImageFile (nDet, nView);
2530 ImageFileArray v = pIF->getArray();
2531 for (int iv = 0; iv < nView; iv++) {
2532 DetectorValue* detval = rProj.getDetectorArray(iv).detValues();
2534 for (int id = 0; id < nDet; id++)
2535 v[id][iv] = detval[id];
2538 ImageFileDocument* pRectDoc = theApp->newImageDoc ();
2540 sys_error (ERR_SEVERE, "Unable to create image file");
2543 pRectDoc->setImageFile (pIF);
2544 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2545 std::ostringstream os;
2546 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to rectangular image";
2547 *theApp->getLog() << os.str().c_str() << "\n";
2548 pIF->labelAdd (os.str().c_str());
2549 if (theApp->getAskDeleteNewDocs())
2550 pRectDoc->Modify (true);
2551 pRectDoc->UpdateAllViews();
2552 pRectDoc->getView()->setInitialClientSize();
2553 pRectDoc->Activate();
2557 ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
2559 Projections& rProj = GetDocument()->getProjections();
2560 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2561 m_iDefaultPolarInterpolation, -1, IDH_DLG_POLAR);
2562 if (dialogPolar.ShowModal() == wxID_OK) {
2563 wxProgressDialog dlgProgress (wxString("Convert Polar"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2564 wxString strInterpolation (dialogPolar.getInterpolationName());
2565 m_iDefaultPolarNX = dialogPolar.getXSize();
2566 m_iDefaultPolarNY = dialogPolar.getYSize();
2567 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2568 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2569 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2571 if (! rProj.convertPolar (*pIF, m_iDefaultPolarInterpolation)) {
2573 *theApp->getLog() << "Error converting to Polar\n";
2577 pPolarDoc = theApp->newImageDoc ();
2579 sys_error (ERR_SEVERE, "Unable to create image file");
2582 pPolarDoc->setImageFile (pIF);
2583 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2584 std::ostringstream os;
2585 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to polar image: xSize="
2586 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2587 << strInterpolation.c_str();
2588 *theApp->getLog() << os.str().c_str() << "\n";
2589 pIF->labelAdd (os.str().c_str());
2590 if (theApp->getAskDeleteNewDocs())
2591 pPolarDoc->Modify (true);
2592 pPolarDoc->UpdateAllViews ();
2593 pPolarDoc->getView()->setInitialClientSize();
2594 pPolarDoc->Activate();
2599 ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
2601 Projections& rProj = GetDocument()->getProjections();
2602 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert to FFT Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2603 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad, IDH_DLG_FFT_POLAR);
2604 if (dialogPolar.ShowModal() == wxID_OK) {
2605 wxProgressDialog dlgProgress (wxString("Convert FFT Polar"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2606 wxString strInterpolation (dialogPolar.getInterpolationName());
2607 m_iDefaultPolarNX = dialogPolar.getXSize();
2608 m_iDefaultPolarNY = dialogPolar.getYSize();
2609 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2610 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2612 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2613 if (! rProj.convertFFTPolar (*pIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad)) {
2615 *theApp->getLog() << "Error converting to polar\n";
2618 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2620 sys_error (ERR_SEVERE, "Unable to create image file");
2623 pPolarDoc->setImageFile (pIF);
2624 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2625 std::ostringstream os;
2626 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to FFT polar image: xSize="
2627 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2628 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2629 *theApp->getLog() << os.str().c_str() << "\n";
2630 pIF->labelAdd (os.str().c_str());
2631 if (theApp->getAskDeleteNewDocs())
2632 pPolarDoc->Modify (true);
2633 pPolarDoc->UpdateAllViews (this);
2634 pPolarDoc->getView()->setInitialClientSize();
2635 pPolarDoc->Activate();
2640 ProjectionFileView::OnPlotTThetaSampling (wxCommandEvent& event)
2642 DialogGetThetaRange dlgTheta (this->getFrame(), ParallelRaysums::THETA_RANGE_UNCONSTRAINED);
2643 if (dlgTheta.ShowModal() != wxID_OK)
2646 int iThetaRange = dlgTheta.getThetaRange();
2648 Projections& rProj = GetDocument()->getProjections();
2649 ParallelRaysums parallel (&rProj, iThetaRange);
2650 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
2651 PlotFile& rPlot = pPlotDoc->getPlotFile();
2652 ParallelRaysums::CoordinateContainer& coordContainer = parallel.getCoordinates();
2653 double* pdT = new double [parallel.getNumCoordinates()];
2654 double* pdTheta = new double [parallel.getNumCoordinates()];
2656 for (int i = 0; i < parallel.getNumCoordinates(); i++) {
2657 pdT[i] = coordContainer[i]->m_dT;
2658 pdTheta[i] = coordContainer[i]->m_dTheta;
2660 rPlot.setCurveSize (2, parallel.getNumCoordinates(), true);
2661 rPlot.addEzsetCommand ("title T-Theta Sampling");
2662 rPlot.addEzsetCommand ("xlabel T");
2663 rPlot.addEzsetCommand ("ylabel Theta");
2664 rPlot.addEzsetCommand ("curve 1");
2665 if (rProj.nDet() < 50 && rProj.nView() < 50)
2666 rPlot.addEzsetCommand ("symbol 1"); // x symbol
2668 rPlot.addEzsetCommand ("symbol 6"); // point symbol
2669 rPlot.addEzsetCommand ("noline");
2670 rPlot.addColumn (0, pdT);
2671 rPlot.addColumn (1, pdTheta);
2674 if (theApp->getAskDeleteNewDocs())
2675 pPlotDoc->Modify (true);
2676 pPlotDoc->getView()->getFrame()->Show(true);
2677 pPlotDoc->UpdateAllViews ();
2678 pPlotDoc->Activate();
2683 ProjectionFileView::OnPlotHistogram (wxCommandEvent& event)
2685 Projections& rProj = GetDocument()->getProjections();
2686 int nDet = rProj.nDet();
2687 int nView = rProj.nView();
2689 if (nDet < 1 || nView < 1)
2692 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
2694 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
2698 DetectorValue* pdDetval = rProj.getDetectorArray(0).detValues();
2699 double dMin = pdDetval[0], dMax = pdDetval[0];
2701 for (int iv = 0; iv < nView; iv++) {
2702 pdDetval = rProj.getDetectorArray(iv).detValues();
2703 for (int id = 0; id < nDet; id++) {
2704 double dV = pdDetval[id];
2712 double* pX = new double [NUMBER_HISTOGRAM_BINS];
2713 double* pY = new double [NUMBER_HISTOGRAM_BINS];
2714 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
2716 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
2717 pX[i] = dMin + (i + 0.5) * dBinWidth;
2720 for (int j = 0; j < nView; j++) {
2721 pdDetval = rProj.getDetectorArray(j).detValues();
2722 for (int id = 0; id < nDet; id++) {
2723 int iBin = nearest<int> ((pdDetval[id] - dMin) / dBinWidth);
2724 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
2728 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
2729 std::ostringstream os;
2731 std::string title("title ");
2733 rPlotFile.addEzsetCommand (title.c_str());
2734 rPlotFile.addEzsetCommand ("xlabel Detector Value");
2735 rPlotFile.addEzsetCommand ("ylabel Count");
2736 rPlotFile.addEzsetCommand ("box");
2737 rPlotFile.addEzsetCommand ("grid");
2738 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
2739 rPlotFile.addColumn (0, pX);
2740 rPlotFile.addColumn (1, pY);
2741 rPlotFile.addDescription (rProj.remark());
2742 os << " plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
2743 *theApp->getLog() << os.str().c_str() << "\n";
2744 rPlotFile.addDescription (os.str().c_str());
2747 if (theApp->getAskDeleteNewDocs())
2748 pPlotDoc->Modify (true);
2749 pPlotDoc->getView()->getFrame()->Show(true);
2750 pPlotDoc->UpdateAllViews ();
2751 pPlotDoc->Activate();
2756 ProjectionFileView::OnConvertParallel (wxCommandEvent& event)
2758 Projections& rProj = GetDocument()->getProjections();
2759 if (rProj.geometry() == Scanner::GEOMETRY_PARALLEL) {
2760 wxMessageBox ("Projections are already parallel", "Error");
2763 wxProgressDialog dlgProgress (wxString("Convert to Parallel"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2764 Projections* pProjNew = rProj.interpolateToParallel();
2765 ProjectionFileDocument* pProjDocNew = theApp->newProjectionDoc();
2766 pProjDocNew->setProjections (pProjNew);
2768 if (ProjectionFileView* projView = pProjDocNew->getView()) {
2769 projView->OnUpdate (projView, NULL);
2770 if (projView->getCanvas())
2771 projView->getCanvas()->SetClientSize (pProjNew->nDet(), pProjNew->nView());
2772 if (wxFrame* pFrame = projView->getFrame()) {
2777 GetDocumentManager()->ActivateView (projView, true, false);
2779 if (theApp->getAskDeleteNewDocs())
2780 pProjDocNew-> Modify(true);
2781 pProjDocNew->UpdateAllViews (this);
2782 pProjDocNew->getView()->setInitialClientSize();
2783 pProjDocNew->Activate();
2787 ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
2789 Projections& rProj = GetDocument()->getProjections();
2790 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Fourier Reconstruction", m_iDefaultPolarNX, m_iDefaultPolarNY,
2791 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad, IDH_DLG_RECON_FOURIER);
2792 if (dialogPolar.ShowModal() == wxID_OK) {
2793 wxProgressDialog dlgProgress (wxString("Reconstruction Fourier"), wxString("Reconstruction Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2794 wxString strInterpolation (dialogPolar.getInterpolationName());
2795 m_iDefaultPolarNX = dialogPolar.getXSize();
2796 m_iDefaultPolarNY = dialogPolar.getYSize();
2797 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2798 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2800 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2801 if (! rProj.convertFFTPolar (*pIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad)) {
2803 *theApp->getLog() << "Error converting to polar\n";
2809 pIF->magnitude(*pIF);
2810 Fourier::shuffleFourierToNaturalOrder (*pIF);
2812 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2814 sys_error (ERR_SEVERE, "Unable to create image file");
2817 pPolarDoc->setImageFile (pIF);
2818 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2819 std::ostringstream os;
2820 os << "Reconstruct Fourier " << GetFrame()->GetTitle().c_str() << ": xSize="
2821 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2822 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2823 *theApp->getLog() << os.str().c_str() << "\n";
2824 pIF->labelAdd (os.str().c_str());
2825 if (theApp->getAskDeleteNewDocs())
2826 pPolarDoc->Modify (true);
2827 pPolarDoc->UpdateAllViews ();
2828 pPolarDoc->getView()->setInitialClientSize();
2829 pPolarDoc->Activate();
2834 ProjectionFileView::OnReconstructFBPRebin (wxCommandEvent& event)
2836 Projections& rProj = GetDocument()->getProjections();
2837 doReconstructFBP (rProj, true);
2841 ProjectionFileView::OnReconstructFBP (wxCommandEvent& event)
2843 Projections& rProj = GetDocument()->getProjections();
2844 doReconstructFBP (rProj, false);
2848 ProjectionFileView::doReconstructFBP (const Projections& rProj, bool bRebinToParallel)
2850 ReconstructionROI defaultROI;
2851 defaultROI.m_dXMin = -rProj.phmLen() / 2;
2852 defaultROI.m_dXMax = defaultROI.m_dXMin + rProj.phmLen();
2853 defaultROI.m_dYMin = -rProj.phmLen() / 2;
2854 defaultROI.m_dYMax = defaultROI.m_dYMin + rProj.phmLen();
2856 DialogGetReconstructionParameters dialogReconstruction (getFrameForChild(), m_iDefaultNX, m_iDefaultNY,
2857 m_iDefaultFilter, m_dDefaultFilterParam, m_iDefaultFilterMethod, m_iDefaultFilterGeneration,
2858 m_iDefaultZeropad, m_iDefaultInterpolation, m_iDefaultInterpParam, m_iDefaultBackprojector,
2859 m_iDefaultTrace, &defaultROI);
2861 int retVal = dialogReconstruction.ShowModal();
2862 if (retVal != wxID_OK)
2865 m_iDefaultNX = dialogReconstruction.getXSize();
2866 m_iDefaultNY = dialogReconstruction.getYSize();
2867 wxString optFilterName = dialogReconstruction.getFilterName();
2868 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
2869 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
2870 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
2871 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
2872 m_iDefaultZeropad = dialogReconstruction.getZeropad();
2873 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
2874 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
2875 wxString optInterpName = dialogReconstruction.getInterpName();
2876 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
2877 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
2878 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
2879 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
2880 m_iDefaultTrace = dialogReconstruction.getTrace();
2881 dialogReconstruction.getROI (&defaultROI);
2883 if (m_iDefaultNX <= 0 && m_iDefaultNY <= 0)
2886 std::ostringstream os;
2887 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();
2888 if (bRebinToParallel)
2889 os << "; Interpolate to Parallel";
2892 ImageFile* pImageFile = NULL;
2893 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2894 pImageFile = new ImageFile (m_iDefaultNX, m_iDefaultNY);
2895 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2896 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2897 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace,
2898 &defaultROI, bRebinToParallel);
2900 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstructor, rProj, *pImageFile, m_iDefaultTrace, getFrameForChild());
2901 for (int iView = 0; iView < rProj.nView(); iView++) {
2903 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView, true)) {
2904 delete pDlgReconstruct;
2905 delete pReconstructor;
2910 while (pDlgReconstruct->isPaused()) {
2915 pReconstructor->postProcessing();
2916 delete pDlgReconstruct;
2917 delete pReconstructor;
2920 if (theApp->getUseBackgroundTasks()) {
2921 ReconstructorSupervisorThread* pReconstructor = new ReconstructorSupervisorThread (this, m_iDefaultNX,
2922 m_iDefaultNY, optFilterName.c_str(), m_dDefaultFilterParam, optFilterMethodName.c_str(),
2923 m_iDefaultZeropad, optFilterGenerationName.c_str(), optInterpName.c_str(), m_iDefaultInterpParam,
2924 optBackprojectName.c_str(), os.str().c_str(), &defaultROI, bRebinToParallel);
2925 if (pReconstructor->Create() != wxTHREAD_NO_ERROR) {
2926 sys_error (ERR_SEVERE, "Error creating reconstructor thread");
2927 delete pReconstructor;
2930 pReconstructor->SetPriority (60);
2931 pReconstructor->Run();
2936 pImageFile = new ImageFile (m_iDefaultNX, m_iDefaultNY);
2937 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2938 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2939 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2940 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace,
2941 &defaultROI, bRebinToParallel);
2943 for (int iView = 0; iView < rProj.nView(); iView++) {
2944 pReconstructor->reconstructView (iView, 1);
2945 if ((iView + 1) % ITER_PER_UPDATE == 0)
2946 if (! dlgProgress.Update (iView + 1)) {
2947 delete pReconstructor;
2948 return; // don't make new window, thread will do this
2951 pReconstructor->postProcessing();
2952 delete pReconstructor;
2955 ImageFileDocument* pReconDoc = theApp->newImageDoc();
2957 sys_error (ERR_SEVERE, "Unable to create image file");
2960 *theApp->getLog() << os.str().c_str() << "\n";
2961 pImageFile->labelAdd (rProj.getLabel());
2962 pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd());
2964 pReconDoc->setImageFile (pImageFile);
2965 if (theApp->getAskDeleteNewDocs())
2966 pReconDoc->Modify (true);
2967 pReconDoc->UpdateAllViews();
2968 pReconDoc->getView()->setInitialClientSize();
2969 pReconDoc->Activate();
2974 ProjectionFileView::OnArtifactReduction (wxCommandEvent& event)
2979 ProjectionFileCanvas*
2980 ProjectionFileView::CreateCanvas (wxFrame *parent)
2982 ProjectionFileCanvas* pCanvas;
2984 parent->GetClientSize(&width, &height);
2986 pCanvas = new ProjectionFileCanvas (this, parent, wxPoint(-1,-1), wxSize(width, height), 0);
2988 pCanvas->SetScrollbars(20, 20, 50, 50);
2989 pCanvas->SetBackgroundColour(*wxWHITE);
3000 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
3003 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
3005 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
3007 theApp->setIconForFrame (subframe);
3009 m_pFileMenu = new wxMenu;
3011 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3012 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3013 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3014 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3015 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3016 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3018 m_pFileMenu->AppendSeparator();
3019 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
3021 m_pFileMenu->AppendSeparator();
3022 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3023 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3024 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3025 m_pFileMenu->AppendSeparator();
3026 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3027 m_pFileMenu->AppendSeparator();
3028 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3029 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3030 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3031 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3033 wxMenu *convert_menu = new wxMenu;
3034 convert_menu->Append (PJMENU_CONVERT_RECTANGULAR, "&Rectangular Image");
3035 convert_menu->Append (PJMENU_CONVERT_POLAR, "&Polar Image...\tCtrl-L");
3036 convert_menu->Append (PJMENU_CONVERT_FFT_POLAR, "FF&T->Polar Image...\tCtrl-T");
3037 convert_menu->AppendSeparator();
3038 convert_menu->Append (PJMENU_CONVERT_PARALLEL, "&Interpolate to Parallel");
3040 // wxMenu* filter_menu = new wxMenu;
3041 // filter_menu->Append (PJMENU_ARTIFACT_REDUCTION, "&Artifact Reduction");
3043 wxMenu* analyze_menu = new wxMenu;
3044 analyze_menu->Append (PJMENU_PLOT_HISTOGRAM, "&Plot Histogram");
3045 analyze_menu->Append (PJMENU_PLOT_TTHETA_SAMPLING, "Plot T-T&heta Sampling...\tCtrl-H");
3047 wxMenu *reconstruct_menu = new wxMenu;
3048 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP, "&Filtered Backprojection...\tCtrl-R", "Reconstruct image using filtered backprojection");
3049 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP_REBIN, "Filtered &Backprojection (Rebin to Parallel)...\tCtrl-B", "Reconstruct image using filtered backprojection");
3051 // reconstruct_menu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Fourier...\tCtrl-E", "Reconstruct image using inverse Fourier");
3053 wxMenu *help_menu = new wxMenu;
3054 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3055 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3056 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3057 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3059 wxMenuBar *menu_bar = new wxMenuBar;
3061 menu_bar->Append (m_pFileMenu, "&File");
3062 menu_bar->Append (convert_menu, "&Convert");
3063 // menu_bar->Append (filter_menu, "Fi<er");
3064 menu_bar->Append (analyze_menu, "&Analyze");
3065 menu_bar->Append (reconstruct_menu, "&Reconstruct");
3066 menu_bar->Append (help_menu, "&Help");
3068 subframe->SetMenuBar(menu_bar);
3069 subframe->Centre(wxBOTH);
3071 wxAcceleratorEntry accelEntries[7];
3072 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('L'), PJMENU_CONVERT_POLAR);
3073 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('T'), PJMENU_CONVERT_FFT_POLAR);
3074 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('R'), PJMENU_RECONSTRUCT_FBP);
3075 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('B'), PJMENU_RECONSTRUCT_FBP_REBIN);
3076 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('E'), PJMENU_RECONSTRUCT_FOURIER);
3077 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('I'), PJMENU_FILE_PROPERTIES);
3078 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('H'), PJMENU_PLOT_TTHETA_SAMPLING);
3079 wxAcceleratorTable accelTable (7, accelEntries);
3080 subframe->SetAcceleratorTable (accelTable);
3087 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
3089 m_pFrame = CreateChildFrame(doc, this);
3091 m_pCanvas = CreateCanvas (m_pFrame);
3092 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
3093 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
3094 m_pFrame->SetTitle ("ProjectionFileView");
3096 m_pFrame->Show(true);
3103 ProjectionFileView::OnDraw (wxDC* dc)
3105 if (m_pBitmap && m_pBitmap->Ok())
3106 dc->DrawBitmap (*m_pBitmap, 0, 0, false);
3111 ProjectionFileView::setInitialClientSize ()
3113 if (m_pFrame && m_pCanvas) {
3114 wxSize bestSize = m_pCanvas->GetBestSize();
3116 m_pFrame->SetClientSize (bestSize);
3117 m_pFrame->Show (true);
3118 m_pFrame->SetFocus();
3123 ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3125 const Projections& rProj = GetDocument()->getProjections();
3126 const int nDet = rProj.nDet();
3127 const int nView = rProj.nView();
3128 if (nDet != 0 && nView != 0) {
3129 const DetectorArray& detarray = rProj.getDetectorArray(0);
3130 const DetectorValue* detval = detarray.detValues();
3131 double min = detval[0];
3132 double max = detval[0];
3133 for (int iy = 0; iy < nView; iy++) {
3134 const DetectorArray& detarray = rProj.getDetectorArray(iy);
3135 const DetectorValue* detval = detarray.detValues();
3136 for (int ix = 0; ix < nDet; ix++) {
3137 if (min > detval[ix])
3139 else if (max < detval[ix])
3144 unsigned char* imageData = new unsigned char [nDet * nView * 3];
3146 sys_error (ERR_SEVERE, "Unable to allocate memory for image display");
3149 double scale = (max - min) / 255;
3150 for (int iy2 = 0; iy2 < nView; iy2++) {
3151 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
3152 const DetectorValue* detval = detarray.detValues();
3153 for (int ix = 0; ix < nDet; ix++) {
3154 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
3155 intensity = clamp(intensity, 0, 255);
3156 int baseAddr = (iy2 * nDet + ix) * 3;
3157 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
3160 wxImage image (nDet, nView, imageData, true);
3165 m_pBitmap = new wxBitmap (image);
3169 m_pCanvas->SetScrollbars(20, 20, nDet/20, nView/20);
3170 m_pCanvas->SetBackgroundColour(*wxWHITE);
3173 m_pCanvas->Refresh();
3177 ProjectionFileView::OnClose (bool deleteWindow)
3179 //GetDocumentManager()->ActivateView (this, false, true);
3180 if (! GetDocument() || ! GetDocument()->Close())
3185 m_pCanvas->setView(NULL);
3188 wxString s(wxTheApp->GetAppName());
3190 m_pFrame->SetTitle(s);
3197 if (GetDocument() && GetDocument()->getBadFileOpen())
3198 ::wxYield(); // wxWindows bug workaround
3207 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
3208 : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v)
3212 PlotFileCanvas::~PlotFileCanvas ()
3217 PlotFileCanvas::GetBestSize() const
3219 return wxSize (500, 300);
3224 PlotFileCanvas::OnDraw(wxDC& dc)
3227 m_pView->OnDraw(& dc);
3233 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
3235 BEGIN_EVENT_TABLE(PlotFileView, wxView)
3236 EVT_MENU(PLOTMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
3237 EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
3238 EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
3239 EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
3242 PlotFileView::PlotFileView()
3243 : wxView(), m_pFrame(0), m_pCanvas(0), m_pEZPlot(0), m_pFileMenu(0),
3244 m_bMinSpecified(false), m_bMaxSpecified(false)
3248 PlotFileView::~PlotFileView()
3253 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
3254 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
3258 PlotFileView::OnProperties (wxCommandEvent& event)
3260 const PlotFile& rPlot = GetDocument()->getPlotFile();
3261 std::ostringstream os;
3262 os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
3263 rPlot.printHeadersBrief (os);
3264 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<<\n";
3265 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
3266 dialogMsg.ShowModal();
3267 GetDocument()->Activate();
3272 PlotFileView::OnScaleAuto (wxCommandEvent& event)
3274 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3275 double min, max, mean, mode, median, stddev;
3276 rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
3277 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
3278 int iRetVal = dialogAutoScale.ShowModal();
3279 if (iRetVal == wxID_OK) {
3280 m_bMinSpecified = true;
3281 m_bMaxSpecified = true;
3283 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
3286 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
3287 OnUpdate (this, NULL);
3290 GetDocument()->Activate();
3294 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
3296 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3300 if (! m_bMinSpecified || ! m_bMaxSpecified) {
3301 if (! rPlotFile.getMinMax (1, min, max)) {
3302 *theApp->getLog() << "Error: unable to find Min/Max\n";
3307 if (m_bMinSpecified)
3309 if (m_bMaxSpecified)
3312 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Y-axis Minimum & Maximum", min, max);
3313 int retVal = dialogMinMax.ShowModal();
3314 if (retVal == wxID_OK) {
3315 m_bMinSpecified = true;
3316 m_bMaxSpecified = true;
3317 m_dMinPixel = dialogMinMax.getMinimum();
3318 m_dMaxPixel = dialogMinMax.getMaximum();
3319 OnUpdate (this, NULL);
3321 GetDocument()->Activate();
3325 PlotFileView::OnScaleFull (wxCommandEvent& event)
3327 if (m_bMinSpecified || m_bMaxSpecified) {
3328 m_bMinSpecified = false;
3329 m_bMaxSpecified = false;
3330 OnUpdate (this, NULL);
3332 GetDocument()->Activate();
3337 PlotFileView::CreateCanvas (wxFrame* parent)
3339 PlotFileCanvas* pCanvas;
3341 pCanvas = new PlotFileCanvas (this, parent, wxPoint(-1,-1), wxSize(-1,-1), 0);
3342 pCanvas->SetBackgroundColour(*wxWHITE);
3353 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
3356 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
3358 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
3360 theApp->setIconForFrame (subframe);
3362 m_pFileMenu = new wxMenu;
3364 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3365 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3366 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3367 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3368 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3369 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3371 m_pFileMenu->AppendSeparator();
3372 m_pFileMenu->Append(PLOTMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
3374 m_pFileMenu->AppendSeparator();
3375 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3376 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3377 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3378 m_pFileMenu->AppendSeparator();
3379 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3380 m_pFileMenu->AppendSeparator();
3381 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3382 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3383 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3384 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3386 wxMenu *view_menu = new wxMenu;
3387 view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...\tCtrl-E");
3388 view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
3389 view_menu->Append(PLOTMENU_VIEW_SCALE_FULL, "Display &Full Scale\tCtrl-U");
3391 wxMenu *help_menu = new wxMenu;
3392 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3393 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3394 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3395 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3397 wxMenuBar *menu_bar = new wxMenuBar;
3399 menu_bar->Append(m_pFileMenu, "&File");
3400 menu_bar->Append(view_menu, "&View");
3401 menu_bar->Append(help_menu, "&Help");
3403 subframe->SetMenuBar(menu_bar);
3404 subframe->Centre(wxBOTH);
3406 wxAcceleratorEntry accelEntries[4];
3407 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('E'), PLOTMENU_VIEW_SCALE_MINMAX);
3408 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('A'), PLOTMENU_VIEW_SCALE_AUTO);
3409 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('U'), PLOTMENU_VIEW_SCALE_FULL);
3410 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), PLOTMENU_FILE_PROPERTIES);
3411 wxAcceleratorTable accelTable (4, accelEntries);
3412 subframe->SetAcceleratorTable (accelTable);
3419 PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
3421 m_bMinSpecified = false;
3422 m_bMaxSpecified = false;
3423 m_dAutoScaleFactor = 1.;
3425 m_pFrame = CreateChildFrame(doc, this);
3427 m_pCanvas = CreateCanvas (m_pFrame);
3428 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
3429 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
3430 m_pFrame->SetTitle ("Plot File");
3432 m_pFrame->Show(true);
3439 PlotFileView::setInitialClientSize ()
3441 if (m_pFrame && m_pCanvas) {
3442 wxSize bestSize = m_pCanvas->GetBestSize();
3444 m_pFrame->SetClientSize (bestSize);
3445 m_pFrame->Show (true);
3446 m_pFrame->SetFocus();
3452 PlotFileView::OnDraw (wxDC* dc)
3454 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3455 const int iNColumns = rPlotFile.getNumColumns();
3456 const int iNRecords = rPlotFile.getNumRecords();
3458 if (iNColumns > 0 && iNRecords > 0) {
3460 m_pCanvas->GetClientSize (&xsize, &ysize);
3461 SGPDriver driver (dc, xsize, ysize);
3464 m_pEZPlot->plot (&sgp);
3470 PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3472 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3473 const int iNColumns = rPlotFile.getNumColumns();
3474 const int iNRecords = rPlotFile.getNumRecords();
3475 const bool bScatterPlot = rPlotFile.getIsScatterPlot();
3477 if (iNColumns > 0 && iNRecords > 0) {
3480 m_pEZPlot = new EZPlot;
3482 for (unsigned int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)
3483 m_pEZPlot->ezset (rPlotFile.getEzsetCommand (iEzset));
3485 if (m_bMinSpecified) {
3486 std::ostringstream os;
3487 os << "ymin " << m_dMinPixel;
3488 m_pEZPlot->ezset (os.str());
3491 if (m_bMaxSpecified) {
3492 std::ostringstream os;
3493 os << "ymax " << m_dMaxPixel;
3494 m_pEZPlot->ezset (os.str());
3497 m_pEZPlot->ezset("box");
3498 m_pEZPlot->ezset("grid");
3500 double* pdX = new double [iNRecords];
3501 double* pdY = new double [iNRecords];
3502 if (! bScatterPlot) {
3503 rPlotFile.getColumn (0, pdX);
3505 for (int iCol = 1; iCol < iNColumns; iCol++) {
3506 rPlotFile.getColumn (iCol, pdY);
3507 m_pEZPlot->addCurve (pdX, pdY, iNRecords);
3510 rPlotFile.getColumn (0, pdX);
3511 rPlotFile.getColumn (1, pdY);
3512 m_pEZPlot->addCurve (pdX, pdY, iNRecords);
3519 m_pCanvas->Refresh();
3523 PlotFileView::OnClose (bool deleteWindow)
3525 if (! GetDocument() || ! GetDocument()->Close())
3530 m_pCanvas->setView (NULL);
3533 wxString s(wxTheApp->GetAppName());
3535 m_pFrame->SetTitle(s);
3541 if (GetDocument() && GetDocument()->getBadFileOpen())
3542 ::wxYield(); // wxWindows bug workaround
3549 ////////////////////////////////////////////////////////////////
3552 IMPLEMENT_DYNAMIC_CLASS(TextFileView, wxView)
3554 TextFileView::~TextFileView()
3556 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
3557 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
3560 bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
3562 m_pFrame = CreateChildFrame(doc, this);
3563 SetFrame (m_pFrame);
3566 m_pFrame->GetClientSize(&width, &height);
3567 m_pFrame->SetTitle("TextFile");
3568 m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(-1,-1), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
3569 m_pFrame->SetTitle("Log");
3571 m_pFrame->Show (true);
3577 // Handled by wxTextWindow
3578 void TextFileView::OnDraw(wxDC *WXUNUSED(dc) )
3582 void TextFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3587 TextFileView::OnClose (bool deleteWindow)
3589 if (! theApp->getMainFrame()->getShuttingDown())
3593 //GetDocumentManager()->ActivateView (this, false, true);
3594 if (! GetDocument() || ! GetDocument()->Close())
3601 if (GetDocument() && GetDocument()->getBadFileOpen())
3602 ::wxYield(); // wxWindows bug workaround
3613 TextFileView::CreateChildFrame (wxDocument *doc, wxView *view)
3616 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE, "Log");
3618 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE, "Log");
3620 theApp->setIconForFrame (subframe);
3622 m_pFileMenu = new wxMenu;
3624 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3625 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3626 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3627 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3628 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3629 // m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3631 m_pFileMenu->AppendSeparator();
3632 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3633 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3634 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3635 m_pFileMenu->AppendSeparator();
3636 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3637 m_pFileMenu->AppendSeparator();
3638 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3639 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3640 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3641 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3643 wxMenu *help_menu = new wxMenu;
3644 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3645 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3646 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3647 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3649 wxMenuBar *menu_bar = new wxMenuBar;
3651 menu_bar->Append(m_pFileMenu, "&File");
3652 menu_bar->Append(help_menu, "&Help");
3654 subframe->SetMenuBar(menu_bar);
3655 subframe->Centre(wxBOTH);
3661 // Define a constructor for my text subwindow
3662 TextFileCanvas::TextFileCanvas (TextFileView* v, wxFrame* frame, const wxPoint& pos, const wxSize& size, long style)
3663 : wxTextCtrl (frame, -1, "", pos, size, style), m_pView(v)
3667 TextFileCanvas::~TextFileCanvas ()
3673 TextFileCanvas::GetBestSize() const
3676 theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
3677 xSize = maxValue<int> (xSize, ySize);
3679 ySize = xSize = (xSize / 4);
3683 return wxSize (xSize, ySize);