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.165 2003/01/29 04:34:06 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 dc->DrawBitmap(*m_pBitmap, 0, 0, false);
1066 int xCursor, yCursor;
1067 if (m_pCanvas->GetCurrentCursor (xCursor, yCursor))
1068 m_pCanvas->DrawRubberBandCursor (*dc, xCursor, yCursor);
1073 ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
1075 const ImageFile& rIF = GetDocument()->getImageFile();
1076 if (m_pFilterMenu && rIF.isComplex()) {
1077 m_pFilterMenu->Enable(IFMENU_FILTER_REAL, true);
1078 m_pFilterMenu->Enable(IFMENU_FILTER_IMAGINARY, true);
1079 m_pFilterMenu->Enable(IFMENU_FILTER_PHASE, true);
1081 m_pFilterMenu->Enable(IFMENU_FILTER_REAL, false);
1082 m_pFilterMenu->Enable(IFMENU_FILTER_IMAGINARY, false);
1083 m_pFilterMenu->Enable(IFMENU_FILTER_PHASE, false);
1085 ImageFileArrayConst v = rIF.getArray();
1088 if (v != NULL && nx != 0 && ny != 0) {
1089 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1091 rIF.getMinMax (min, max);
1092 if (! m_bMinSpecified)
1094 if (! m_bMaxSpecified)
1097 double scaleWidth = m_dMaxPixel - m_dMinPixel;
1099 unsigned char* imageData = new unsigned char [nx * ny * 3];
1101 sys_error (ERR_SEVERE, "Unable to allocate memory for Image display");
1104 for (int ix = 0; ix < nx; ix++) {
1105 for (int iy = 0; iy < ny; iy++) {
1106 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
1107 int intensity = static_cast<int>(scaleValue + 0.5);
1108 intensity = clamp (intensity, 0, 255);
1109 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
1110 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
1113 wxImage image (nx, ny, imageData, true);
1118 m_pBitmap = new wxBitmap (image);
1120 m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20);
1121 m_pCanvas->SetBackgroundColour(*wxWHITE);
1125 m_pCanvas->Refresh();
1129 ImageFileView::OnClose (bool deleteWindow)
1131 if (! GetDocument() || ! GetDocument()->Close())
1136 m_pCanvas->setView(NULL);
1139 wxString s(theApp->GetAppName());
1141 m_pFrame->SetTitle(s);
1148 if (GetDocument() && GetDocument()->getBadFileOpen())
1149 ::wxYield(); // wxWindows bug workaround
1156 ImageFileView::OnEditCopy (wxCommandEvent& event)
1158 wxBitmapDataObject *pBitmapObject = new wxBitmapDataObject;
1161 pBitmapObject->SetBitmap (*m_pBitmap);
1163 if (wxTheClipboard->Open()) {
1164 wxTheClipboard->SetData (pBitmapObject);
1165 wxTheClipboard->Close();
1170 ImageFileView::OnEditCut (wxCommandEvent& event)
1173 ImageFile& rIF = GetDocument()->getImageFile();
1176 ImageFile* pIF = new ImageFile (nx, ny);
1177 pIF->arrayDataClear();
1178 GetDocument()->setImageFile (pIF); // deletes old IF
1179 OnUpdate(this, NULL);
1180 GetDocument()->UpdateAllViews();
1181 if (theApp->getAskDeleteNewDocs())
1182 GetDocument()->Modify (true);
1186 ImageFileView::OnEditPaste (wxCommandEvent& event)
1188 ImageFile& rIF = GetDocument()->getImageFile();
1190 if (wxTheClipboard->Open()) {
1192 if (wxTheClipboard->IsSupported (wxDF_BITMAP)) {
1193 wxBitmapDataObject bitmapObject;
1194 wxTheClipboard->GetData (bitmapObject);
1195 bitmap = bitmapObject.GetBitmap ();
1197 wxTheClipboard->Close();
1201 bool bMonochrome = false;
1203 if (bitmap.Ok() == true && bitmap.GetWidth() == nx && bitmap.GetHeight() == ny) {
1204 wxImage image (bitmap.ConvertToImage());
1205 double dScale3 = 3 * 255;
1206 unsigned char* pixels = image.GetData();
1207 ImageFileArray v = rIF.getArray();
1208 for (unsigned int ix = 0; ix < rIF.nx(); ix++) {
1209 for (unsigned int iy = 0; iy < rIF.ny(); iy++) {
1210 unsigned int iBase = 3 * (iy * nx + ix);
1211 if (ix == 0 && iy == 0 && (pixels[iBase] == pixels[iBase+1] && pixels[iBase+1] == pixels[iBase+2]))
1214 v[ix][ny - 1 - iy] = (pixels[iBase]+pixels[iBase+1]+pixels[iBase+2]) / dScale3;
1216 double dR = pixels[iBase] / 255.;
1217 double dG = pixels[iBase+1] / 255.;
1218 double dB = pixels[iBase+2] / 255.;
1219 v[ix][ny - 1 - iy] = ImageFile::colorToGrayscale (dR, dG, dB);
1223 OnUpdate(this, NULL);
1224 GetDocument()->UpdateAllViews();
1225 if (theApp->getAskDeleteNewDocs())
1226 GetDocument()->Modify(true);
1232 ImageFileView::OnExport (wxCommandEvent& event)
1234 ImageFile& rIF = GetDocument()->getImageFile();
1235 ImageFileArrayConst v = rIF.getArray();
1238 if (v != NULL && nx != 0 && ny != 0) {
1239 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1241 rIF.getMinMax (min, max);
1242 if (! m_bMinSpecified)
1244 if (! m_bMaxSpecified)
1248 DialogExportParameters dialogExport (getFrameForChild(), m_iDefaultExportFormatID);
1249 if (dialogExport.ShowModal() == wxID_OK) {
1250 wxString strFormatName (dialogExport.getFormatName ());
1251 m_iDefaultExportFormatID = ImageFile::convertExportFormatNameToID (strFormatName.c_str());
1254 wxString strWildcard;
1255 if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PGM || m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PGMASCII) {
1257 strWildcard = "PGM Files (*.pgm)|*.pgm";
1260 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PNG || m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PNG16) {
1262 strWildcard = "PNG Files (*.png)|*.png";
1265 #ifdef HAVE_CTN_DICOM
1266 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_DICOM) {
1268 strWildcard = "DICOM Files (*.*)|*.*";
1271 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_TEXT) {
1273 strWildcard = "Text (*.txt)|*.txt";
1277 strWildcard = "Miscellaneous (*.*)|*.*";
1280 const wxString& strFilename = wxFileSelector (wxString("Export Filename"), wxString(""),
1281 wxString(""), strExt, strWildcard, wxOVERWRITE_PROMPT | wxHIDE_READONLY | wxSAVE);
1283 rIF.exportImage (strFormatName.c_str(), strFilename.c_str(), 1, 1, m_dMinPixel, m_dMaxPixel);
1284 *theApp->getLog() << "Exported file " << strFilename << "\n";
1291 ImageFileView::OnScaleSize (wxCommandEvent& event)
1293 ImageFile& rIF = GetDocument()->getImageFile();
1294 unsigned int iOldNX = rIF.nx();
1295 unsigned int iOldNY = rIF.ny();
1297 DialogGetXYSize dialogGetXYSize (getFrameForChild(), "Set New X & Y Dimensions", iOldNX, iOldNY);
1298 if (dialogGetXYSize.ShowModal() == wxID_OK) {
1299 unsigned int iNewNX = dialogGetXYSize.getXSize();
1300 unsigned int iNewNY = dialogGetXYSize.getYSize();
1301 std::ostringstream os;
1302 os << "Scale Size from (" << iOldNX << "," << iOldNY << ") to (" << iNewNX << "," << iNewNY << ")";
1303 ImageFileDocument* pScaledDoc = theApp->newImageDoc();
1305 sys_error (ERR_SEVERE, "Unable to create image file");
1308 ImageFile& rScaledIF = pScaledDoc->getImageFile();
1309 rScaledIF.setArraySize (iNewNX, iNewNY);
1310 rScaledIF.labelsCopy (rIF);
1311 rScaledIF.labelAdd (os.str().c_str());
1312 rIF.scaleImage (rScaledIF);
1313 *theApp->getLog() << os.str().c_str() << "\n";
1314 if (theApp->getAskDeleteNewDocs())
1315 pScaledDoc->Modify (true);
1316 pScaledDoc->UpdateAllViews (this);
1317 pScaledDoc->getView()->setInitialClientSize();
1318 pScaledDoc->Activate();
1324 ImageFileView::OnConvert3d (wxCommandEvent& event)
1326 ImageFile& rIF = GetDocument()->getImageFile();
1327 Graph3dFileDocument* pGraph3d = theApp->newGraph3dDoc();
1328 pGraph3d->getView()->getFrame()->Show (false);
1329 pGraph3d->setBadFileOpen();
1330 pGraph3d->createFromImageFile (rIF);
1331 pGraph3d->UpdateAllViews();
1332 pGraph3d->getView()->getFrame()->Show (true);
1333 pGraph3d->getView()->Activate(true);
1335 pGraph3d->getView()->getCanvas()->SetFocus();
1340 ImageFileView::OnPlotRow (wxCommandEvent& event)
1342 int xCursor, yCursor;
1343 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1344 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1348 const ImageFile& rIF = GetDocument()->getImageFile();
1349 ImageFileArrayConst v = rIF.getArray();
1350 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1354 if (v != NULL && yCursor < ny) {
1355 double* pX = new double [nx];
1356 double* pYReal = new double [nx];
1357 double *pYImag = NULL;
1358 double *pYMag = NULL;
1359 if (rIF.isComplex()) {
1360 pYImag = new double [nx];
1361 pYMag = new double [nx];
1363 for (int i = 0; i < nx; i++) {
1365 pYReal[i] = v[i][yCursor];
1366 if (rIF.isComplex()) {
1367 pYImag[i] = vImag[i][yCursor];
1368 pYMag[i] = ::sqrt (v[i][yCursor] * v[i][yCursor] + vImag[i][yCursor] * vImag[i][yCursor]);
1371 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1373 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1375 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1376 std::ostringstream os;
1377 os << "Row " << yCursor;
1378 std::string title("title ");
1380 rPlotFile.addEzsetCommand (title.c_str());
1381 rPlotFile.addEzsetCommand ("xlabel Column");
1382 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1383 rPlotFile.addEzsetCommand ("lxfrac 0");
1384 rPlotFile.addEzsetCommand ("box");
1385 rPlotFile.addEzsetCommand ("grid");
1386 rPlotFile.addEzsetCommand ("curve 1");
1387 rPlotFile.addEzsetCommand ("color 1");
1388 if (rIF.isComplex()) {
1389 rPlotFile.addEzsetCommand ("dash 1");
1390 rPlotFile.addEzsetCommand ("curve 2");
1391 rPlotFile.addEzsetCommand ("color 4");
1392 rPlotFile.addEzsetCommand ("dash 3");
1393 rPlotFile.addEzsetCommand ("curve 3");
1394 rPlotFile.addEzsetCommand ("color 0");
1395 rPlotFile.addEzsetCommand ("solid");
1396 rPlotFile.setCurveSize (4, nx);
1398 rPlotFile.setCurveSize (2, nx);
1399 rPlotFile.addColumn (0, pX);
1400 rPlotFile.addColumn (1, pYReal);
1401 if (rIF.isComplex()) {
1402 rPlotFile.addColumn (2, pYImag);
1403 rPlotFile.addColumn (3, pYMag);
1405 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1406 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1407 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1408 *theApp->getLog() << os.str().c_str() << "\n";
1409 rPlotFile.addDescription (os.str().c_str());
1413 if (rIF.isComplex()) {
1417 if (theApp->getAskDeleteNewDocs())
1418 pPlotDoc->Modify (true);
1419 pPlotDoc->getView()->getFrame()->Show(true);
1420 pPlotDoc->UpdateAllViews ();
1421 pPlotDoc->Activate();
1426 ImageFileView::OnPlotCol (wxCommandEvent& event)
1428 int xCursor, yCursor;
1429 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1430 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1434 const ImageFile& rIF = GetDocument()->getImageFile();
1435 ImageFileArrayConst v = rIF.getArray();
1436 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1440 if (v != NULL && xCursor < nx) {
1441 double* pX = new double [ny];
1442 double* pYReal = new double [ny];
1443 double* pYImag = NULL;
1444 double* pYMag = NULL;
1445 if (rIF.isComplex()) {
1446 pYImag = new double [ny];
1447 pYMag = new double [ny];
1449 for (int i = 0; i < ny; i++) {
1451 pYReal[i] = v[xCursor][i];
1452 if (rIF.isComplex()) {
1453 pYImag[i] = vImag[xCursor][i];
1454 pYMag[i] = ::sqrt (v[xCursor][i] * v[xCursor][i] + vImag[xCursor][i] * vImag[xCursor][i]);
1457 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1459 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1461 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1462 std::ostringstream os;
1463 os << "Column " << xCursor;
1464 std::string title("title ");
1466 rPlotFile.addEzsetCommand (title.c_str());
1467 rPlotFile.addEzsetCommand ("xlabel Row");
1468 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1469 rPlotFile.addEzsetCommand ("lxfrac 0");
1470 rPlotFile.addEzsetCommand ("box");
1471 rPlotFile.addEzsetCommand ("grid");
1472 rPlotFile.addEzsetCommand ("curve 1");
1473 rPlotFile.addEzsetCommand ("color 1");
1474 if (rIF.isComplex()) {
1475 rPlotFile.addEzsetCommand ("dash 1");
1476 rPlotFile.addEzsetCommand ("curve 2");
1477 rPlotFile.addEzsetCommand ("color 4");
1478 rPlotFile.addEzsetCommand ("dash 3");
1479 rPlotFile.addEzsetCommand ("curve 3");
1480 rPlotFile.addEzsetCommand ("color 0");
1481 rPlotFile.addEzsetCommand ("solid");
1482 rPlotFile.setCurveSize (4, ny);
1484 rPlotFile.setCurveSize (2, ny);
1485 rPlotFile.addColumn (0, pX);
1486 rPlotFile.addColumn (1, pYReal);
1487 if (rIF.isComplex()) {
1488 rPlotFile.addColumn (2, pYImag);
1489 rPlotFile.addColumn (3, pYMag);
1491 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1492 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1493 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1494 *theApp->getLog() << os.str().c_str() << "\n";
1495 rPlotFile.addDescription (os.str().c_str());
1499 if (rIF.isComplex()) {
1503 if (theApp->getAskDeleteNewDocs())
1504 pPlotDoc->Modify (true);
1505 pPlotDoc->getView()->getFrame()->Show(true);
1506 pPlotDoc->UpdateAllViews ();
1507 pPlotDoc->Activate();
1513 ImageFileView::OnPlotFFTRow (wxCommandEvent& event)
1515 int xCursor, yCursor;
1516 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1517 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1521 const ImageFile& rIF = GetDocument()->getImageFile();
1522 ImageFileArrayConst v = rIF.getArray();
1523 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1527 if (v != NULL && yCursor < ny) {
1528 fftw_complex* pcIn = new fftw_complex [nx];
1531 for (i = 0; i < nx; i++) {
1532 pcIn[i].re = v[i][yCursor];
1533 if (rIF.isComplex())
1534 pcIn[i].im = vImag[i][yCursor];
1539 fftw_plan plan = fftw_create_plan (nx, FFTW_FORWARD, FFTW_IN_PLACE | FFTW_ESTIMATE | FFTW_USE_WISDOM);
1540 fftw_one (plan, pcIn, NULL);
1541 fftw_destroy_plan (plan);
1543 double* pX = new double [nx];
1544 double* pYReal = new double [nx];
1545 double* pYImag = new double [nx];
1546 double* pYMag = new double [nx];
1547 for (i = 0; i < nx; i++) {
1549 pYReal[i] = pcIn[i].re / nx;
1550 pYImag[i] = pcIn[i].im / nx;
1551 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1553 Fourier::shuffleFourierToNaturalOrder (pYReal, nx);
1554 Fourier::shuffleFourierToNaturalOrder (pYImag, nx);
1555 Fourier::shuffleFourierToNaturalOrder (pYMag, nx);
1557 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1559 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1561 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1562 std::ostringstream os;
1563 os << "Row " << yCursor;
1564 std::string title("title ");
1566 rPlotFile.addEzsetCommand (title.c_str());
1567 rPlotFile.addEzsetCommand ("xlabel Column");
1568 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1569 rPlotFile.addEzsetCommand ("lxfrac 0");
1570 rPlotFile.addEzsetCommand ("curve 1");
1571 rPlotFile.addEzsetCommand ("color 1");
1572 rPlotFile.addEzsetCommand ("dash 1");
1573 rPlotFile.addEzsetCommand ("curve 2");
1574 rPlotFile.addEzsetCommand ("color 4");
1575 rPlotFile.addEzsetCommand ("dash 3");
1576 rPlotFile.addEzsetCommand ("curve 3");
1577 rPlotFile.addEzsetCommand ("color 0");
1578 rPlotFile.addEzsetCommand ("solid");
1579 rPlotFile.addEzsetCommand ("box");
1580 rPlotFile.addEzsetCommand ("grid");
1581 rPlotFile.setCurveSize (4, nx);
1582 rPlotFile.addColumn (0, pX);
1583 rPlotFile.addColumn (1, pYReal);
1584 rPlotFile.addColumn (2, pYImag);
1585 rPlotFile.addColumn (3, pYMag);
1586 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1587 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1588 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1589 *theApp->getLog() << os.str().c_str() << "\n";
1590 rPlotFile.addDescription (os.str().c_str());
1598 if (theApp->getAskDeleteNewDocs())
1599 pPlotDoc->Modify (true);
1600 pPlotDoc->getView()->getFrame()->Show(true);
1601 pPlotDoc->UpdateAllViews ();
1602 pPlotDoc->Activate();
1607 ImageFileView::OnPlotFFTCol (wxCommandEvent& event)
1609 int xCursor, yCursor;
1610 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1611 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1615 const ImageFile& rIF = GetDocument()->getImageFile();
1616 ImageFileArrayConst v = rIF.getArray();
1617 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1621 if (v != NULL && xCursor < nx) {
1622 fftw_complex* pcIn = new fftw_complex [ny];
1623 double *pdTemp = new double [ny];
1626 for (i = 0; i < ny; i++)
1627 pdTemp[i] = v[xCursor][i];
1628 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1629 for (i = 0; i < ny; i++)
1630 pcIn[i].re = pdTemp[i];
1632 for (i = 0; i < ny; i++) {
1633 if (rIF.isComplex())
1634 pdTemp[i] = vImag[xCursor][i];
1638 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1639 for (i = 0; i < ny; i++)
1640 pcIn[i].im = pdTemp[i];
1642 fftw_plan plan = fftw_create_plan (ny, FFTW_BACKWARD, FFTW_IN_PLACE | FFTW_ESTIMATE | FFTW_USE_WISDOM);
1643 fftw_one (plan, pcIn, NULL);
1644 fftw_destroy_plan (plan);
1646 double* pX = new double [ny];
1647 double* pYReal = new double [ny];
1648 double* pYImag = new double [ny];
1649 double* pYMag = new double [ny];
1650 for (i = 0; i < ny; i++) {
1652 pYReal[i] = pcIn[i].re / ny;
1653 pYImag[i] = pcIn[i].im / ny;
1654 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1657 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1659 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1661 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1662 std::ostringstream os;
1663 os << "Column " << xCursor;
1664 std::string title("title ");
1666 rPlotFile.addEzsetCommand (title.c_str());
1667 rPlotFile.addEzsetCommand ("xlabel Column");
1668 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1669 rPlotFile.addEzsetCommand ("lxfrac 0");
1670 rPlotFile.addEzsetCommand ("curve 1");
1671 rPlotFile.addEzsetCommand ("color 1");
1672 rPlotFile.addEzsetCommand ("dash 1");
1673 rPlotFile.addEzsetCommand ("curve 2");
1674 rPlotFile.addEzsetCommand ("color 4");
1675 rPlotFile.addEzsetCommand ("dash 3");
1676 rPlotFile.addEzsetCommand ("curve 3");
1677 rPlotFile.addEzsetCommand ("color 0");
1678 rPlotFile.addEzsetCommand ("solid");
1679 rPlotFile.addEzsetCommand ("box");
1680 rPlotFile.addEzsetCommand ("grid");
1681 rPlotFile.setCurveSize (4, ny);
1682 rPlotFile.addColumn (0, pX);
1683 rPlotFile.addColumn (1, pYReal);
1684 rPlotFile.addColumn (2, pYImag);
1685 rPlotFile.addColumn (3, pYMag);
1686 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1687 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1688 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1689 *theApp->getLog() << os.str().c_str() << "\n";
1690 rPlotFile.addDescription (os.str().c_str());
1699 if (theApp->getAskDeleteNewDocs())
1700 pPlotDoc->Modify (true);
1701 pPlotDoc->getView()->getFrame()->Show(true);
1702 pPlotDoc->UpdateAllViews ();
1703 pPlotDoc->Activate();
1709 ImageFileView::OnCompareCol (wxCommandEvent& event)
1711 int xCursor, yCursor;
1712 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1713 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1717 std::vector<ImageFileDocument*> vecIFDoc;
1718 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1719 if (vecIFDoc.size() == 0) {
1720 wxMessageBox ("No compatible images for Column Comparison", "Error");
1723 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1725 if (dialogGetCompare.ShowModal() == wxID_OK) {
1726 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1727 const ImageFile& rIF = GetDocument()->getImageFile();
1728 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1730 ImageFileArrayConst v1 = rIF.getArray();
1731 ImageFileArrayConst v2 = rCompareIF.getArray();
1735 if (v1 != NULL && xCursor < nx) {
1736 double* pX = new double [ny];
1737 double* pY1 = new double [ny];
1738 double* pY2 = new double [ny];
1739 for (int i = 0; i < ny; i++) {
1741 pY1[i] = v1[xCursor][i];
1742 pY2[i] = v2[xCursor][i];
1744 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1746 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1748 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1749 std::ostringstream os;
1750 os << "Column " << xCursor << " Comparison";
1751 std::string title("title ");
1753 rPlotFile.addEzsetCommand (title.c_str());
1754 rPlotFile.addEzsetCommand ("xlabel Row");
1755 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1756 rPlotFile.addEzsetCommand ("lxfrac 0");
1757 rPlotFile.addEzsetCommand ("curve 1");
1758 rPlotFile.addEzsetCommand ("color 2");
1759 rPlotFile.addEzsetCommand ("curve 2");
1760 rPlotFile.addEzsetCommand ("color 4");
1761 rPlotFile.addEzsetCommand ("dash 5");
1762 rPlotFile.addEzsetCommand ("box");
1763 rPlotFile.addEzsetCommand ("grid");
1764 rPlotFile.setCurveSize (3, ny);
1765 rPlotFile.addColumn (0, pX);
1766 rPlotFile.addColumn (1, pY1);
1767 rPlotFile.addColumn (2, pY2);
1770 for (iL = 0; iL < rIF.nLabels(); iL++) {
1771 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1773 s += rIF.labelGet(iL).getLabelString();
1774 rPlotFile.addDescription (s.c_str());
1776 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1777 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1779 s += rCompareIF.labelGet(iL).getLabelString();
1780 rPlotFile.addDescription (s.c_str());
1782 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1783 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1784 *theApp->getLog() << os.str().c_str() << "\n";
1785 rPlotFile.addDescription (os.str().c_str());
1790 if (theApp->getAskDeleteNewDocs())
1791 pPlotDoc->Modify (true);
1792 pPlotDoc->getView()->getFrame()->Show(true);
1793 pPlotDoc->UpdateAllViews ();
1794 pPlotDoc->Activate();
1800 ImageFileView::OnCompareRow (wxCommandEvent& event)
1802 int xCursor, yCursor;
1803 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1804 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1808 std::vector<ImageFileDocument*> vecIFDoc;
1809 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1811 if (vecIFDoc.size() == 0) {
1812 wxMessageBox ("No compatible images for Row Comparison", "Error");
1816 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1818 if (dialogGetCompare.ShowModal() == wxID_OK) {
1819 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1820 const ImageFile& rIF = GetDocument()->getImageFile();
1821 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1823 ImageFileArrayConst v1 = rIF.getArray();
1824 ImageFileArrayConst v2 = rCompareIF.getArray();
1828 if (v1 != NULL && yCursor < ny) {
1829 double* pX = new double [nx];
1830 double* pY1 = new double [nx];
1831 double* pY2 = new double [nx];
1832 for (int i = 0; i < nx; i++) {
1834 pY1[i] = v1[i][yCursor];
1835 pY2[i] = v2[i][yCursor];
1837 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1839 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1841 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1842 std::ostringstream os;
1843 os << "Row " << yCursor << " Comparison";
1844 std::string title("title ");
1846 rPlotFile.addEzsetCommand (title.c_str());
1847 rPlotFile.addEzsetCommand ("xlabel Column");
1848 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1849 rPlotFile.addEzsetCommand ("lxfrac 0");
1850 rPlotFile.addEzsetCommand ("curve 1");
1851 rPlotFile.addEzsetCommand ("color 2");
1852 rPlotFile.addEzsetCommand ("curve 2");
1853 rPlotFile.addEzsetCommand ("color 4");
1854 rPlotFile.addEzsetCommand ("dash 5");
1855 rPlotFile.addEzsetCommand ("box");
1856 rPlotFile.addEzsetCommand ("grid");
1857 rPlotFile.setCurveSize (3, nx);
1858 rPlotFile.addColumn (0, pX);
1859 rPlotFile.addColumn (1, pY1);
1860 rPlotFile.addColumn (2, pY2);
1862 for (iL = 0; iL < rIF.nLabels(); iL++) {
1863 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1865 s += rIF.labelGet(iL).getLabelString();
1866 rPlotFile.addDescription (s.c_str());
1868 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1869 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1871 s += rCompareIF.labelGet(iL).getLabelString();
1872 rPlotFile.addDescription (s.c_str());
1874 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1875 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1876 *theApp->getLog() << os.str().c_str() << "\n";
1877 rPlotFile.addDescription (os.str().c_str());
1882 if (theApp->getAskDeleteNewDocs())
1883 pPlotDoc->Modify (true);
1884 pPlotDoc->getView()->getFrame()->Show(true);
1885 pPlotDoc->UpdateAllViews ();
1886 pPlotDoc->Activate();
1891 static int NUMBER_HISTOGRAM_BINS = 256;
1894 ImageFileView::OnPlotHistogram (wxCommandEvent& event)
1896 const ImageFile& rIF = GetDocument()->getImageFile();
1897 ImageFileArrayConst v = rIF.getArray();
1901 if (v != NULL && nx > 0 && ny > 0) {
1902 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1904 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1908 double* pX = new double [NUMBER_HISTOGRAM_BINS];
1909 double* pY = new double [NUMBER_HISTOGRAM_BINS];
1911 rIF.getMinMax (dMin, dMax);
1912 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
1914 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
1915 pX[i] = dMin + (i + 0.5) * dBinWidth;
1918 for (int ix = 0; ix < nx; ix++)
1919 for (int iy = 0; iy < ny; iy++) {
1920 int iBin = nearest<int> ((v[ix][iy] - dMin) / dBinWidth);
1921 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
1925 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1926 std::ostringstream os;
1928 std::string title("title ");
1930 rPlotFile.addEzsetCommand (title.c_str());
1931 rPlotFile.addEzsetCommand ("xlabel Pixel Value");
1932 rPlotFile.addEzsetCommand ("ylabel Count");
1933 rPlotFile.addEzsetCommand ("box");
1934 rPlotFile.addEzsetCommand ("grid");
1935 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
1936 rPlotFile.addColumn (0, pX);
1937 rPlotFile.addColumn (1, pY);
1938 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++) {
1939 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1941 s += rIF.labelGet(iL).getLabelString();
1942 rPlotFile.addDescription (s.c_str());
1944 os << " plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1945 *theApp->getLog() << os.str().c_str() << "\n";
1946 rPlotFile.addDescription (os.str().c_str());
1949 if (theApp->getAskDeleteNewDocs())
1950 pPlotDoc->Modify (true);
1951 pPlotDoc->getView()->getFrame()->Show(true);
1952 pPlotDoc->UpdateAllViews ();
1953 pPlotDoc->Activate();
1960 PhantomCanvas::PhantomCanvas (PhantomFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1961 : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v)
1965 PhantomCanvas::~PhantomCanvas ()
1971 PhantomCanvas::OnDraw (wxDC& dc)
1974 m_pView->OnDraw(& dc);
1978 PhantomCanvas::GetBestSize() const
1984 theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
1985 xSize = maxValue<int> (xSize, ySize);
1987 ySize = xSize = (xSize / 4);
1989 xSize = ySize = static_cast<int>(ySize * .7);
1992 return wxSize (xSize, ySize);
1999 IMPLEMENT_DYNAMIC_CLASS(PhantomFileView, wxView)
2001 BEGIN_EVENT_TABLE(PhantomFileView, wxView)
2002 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomFileView::OnProperties)
2003 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomFileView::OnRasterize)
2004 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomFileView::OnProjections)
2007 PhantomFileView::PhantomFileView()
2008 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0)
2010 #if defined(DEBUG) || defined(_DEBUG)
2011 m_iDefaultNDet = 165;
2012 m_iDefaultNView = 180;
2013 m_iDefaultNSample = 1;
2015 m_iDefaultNDet = 367;
2016 m_iDefaultNView = 320;
2017 m_iDefaultNSample = 2;
2019 m_iDefaultOffsetView = 0;
2020 m_dDefaultRotation = 1;
2021 m_dDefaultFocalLength = 2;
2022 m_dDefaultCenterDetectorLength = 2;
2023 m_dDefaultViewRatio = 1;
2024 m_dDefaultScanRatio = 1;
2025 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
2026 m_iDefaultTrace = Trace::TRACE_NONE;
2029 m_iDefaultRasterNX = 115;
2030 m_iDefaultRasterNY = 115;
2031 m_iDefaultRasterNSamples = 1;
2033 m_iDefaultRasterNX = 256;
2034 m_iDefaultRasterNY = 256;
2035 m_iDefaultRasterNSamples = 2;
2037 m_dDefaultRasterViewRatio = 1;
2040 PhantomFileView::~PhantomFileView()
2042 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2043 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
2047 PhantomFileView::OnProperties (wxCommandEvent& event)
2049 const int idPhantom = GetDocument()->getPhantomID();
2050 const wxString& namePhantom = GetDocument()->getPhantomName();
2051 std::ostringstream os;
2052 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")" << "\n";
2053 const Phantom& rPhantom = GetDocument()->getPhantom();
2054 rPhantom.printDefinitions (os);
2056 rPhantom.print (os);
2058 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2059 wxMessageBox (os.str().c_str(), "Phantom Properties");
2060 GetDocument()->Activate();
2065 PhantomFileView::OnProjections (wxCommandEvent& event)
2067 DialogGetProjectionParameters dialogProjection (getFrameForChild(),
2068 m_iDefaultNDet, m_iDefaultNView, m_iDefaultOffsetView, m_iDefaultNSample, m_dDefaultRotation,
2069 m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio,
2070 m_iDefaultGeometry, m_iDefaultTrace);
2071 int retVal = dialogProjection.ShowModal();
2072 if (retVal != wxID_OK)
2075 m_iDefaultNDet = dialogProjection.getNDet();
2076 m_iDefaultNView = dialogProjection.getNView();
2077 m_iDefaultOffsetView = dialogProjection.getOffsetView();
2078 m_iDefaultNSample = dialogProjection.getNSamples();
2079 m_iDefaultTrace = dialogProjection.getTrace();
2080 m_dDefaultRotation = dialogProjection.getRotAngle();
2081 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
2082 m_dDefaultCenterDetectorLength = dialogProjection.getCenterDetectorLengthRatio();
2083 m_dDefaultViewRatio = dialogProjection.getViewRatio();
2084 m_dDefaultScanRatio = dialogProjection.getScanRatio();
2085 wxString sGeometry = dialogProjection.getGeometry();
2086 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
2087 double dRotationRadians = m_dDefaultRotation;
2088 m_dDefaultRotation /= TWOPI; // convert back to fraction of a circle
2090 if (m_iDefaultNDet <= 0 || m_iDefaultNView <= 0 || sGeometry == "")
2093 const Phantom& rPhantom = GetDocument()->getPhantom();
2094 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultOffsetView, m_iDefaultNSample,
2095 dRotationRadians, m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio);
2096 if (theScanner.fail()) {
2097 wxString msg = "Failed making scanner\n";
2098 msg += theScanner.failMessage().c_str();
2099 *theApp->getLog() << msg << "\n";
2100 wxMessageBox (msg, "Error");
2104 std::ostringstream os;
2105 os << "Projections for " << rPhantom.name()
2106 << ": nDet=" << m_iDefaultNDet
2107 << ", nView=" << m_iDefaultNView
2108 << ", gantry offset=" << m_iDefaultOffsetView
2109 << ", nSamples=" << m_iDefaultNSample
2110 << ", RotAngle=" << m_dDefaultRotation
2111 << ", FocalLengthRatio=" << m_dDefaultFocalLength
2112 << ", CenterDetectorLengthRatio=" << m_dDefaultCenterDetectorLength
2113 << ", ViewRatio=" << m_dDefaultViewRatio
2114 << ", ScanRatio=" << m_dDefaultScanRatio
2115 << ", Geometry=" << sGeometry.c_str()
2116 << ", FanBeamAngle=" << convertRadiansToDegrees (theScanner.fanBeamAngle());
2119 Projections* pProj = NULL;
2120 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2121 pProj = new Projections;
2122 pProj->initFromScanner (theScanner);
2124 ProjectionsDialog dialogProjections (theScanner, *pProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(getFrameForChild()));
2125 for (int iView = 0; iView < pProj->nView(); iView++) {
2127 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
2132 while (dialogProjections.isPaused()) {
2139 if (theApp->getUseBackgroundTasks()) {
2140 ProjectorSupervisorThread* pProjector = new ProjectorSupervisorThread (this, m_iDefaultNDet,
2141 m_iDefaultNView, m_iDefaultOffsetView, sGeometry.c_str(), m_iDefaultNSample, dRotationRadians,
2142 m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio, os.str().c_str());
2143 if (pProjector->Create() != wxTHREAD_NO_ERROR) {
2144 sys_error (ERR_SEVERE, "Error creating projector thread");
2148 pProjector->SetPriority(60);
2152 #endif // HAVE_WXTHREADS
2154 pProj = new Projections;
2155 pProj->initFromScanner (theScanner);
2156 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), pProj->nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2157 for (int i = 0; i < pProj->nView(); i++) {
2158 //theScanner.collectProjections (*pProj, rPhantom, i, 1, true, m_iDefaultTrace);
2159 theScanner.collectProjections (*pProj, rPhantom, i, 1, theScanner.offsetView(), true, m_iDefaultTrace);
2160 if ((i + 1) % ITER_PER_UPDATE == 0)
2161 if (! dlgProgress.Update (i+1)) {
2169 *theApp->getLog() << os.str().c_str() << "\n";
2170 pProj->setRemark (os.str());
2171 pProj->setCalcTime (timer.timerEnd());
2173 ProjectionFileDocument* pProjectionDoc = theApp->newProjectionDoc();
2174 if (! pProjectionDoc) {
2175 sys_error (ERR_SEVERE, "Unable to create projection document");
2178 pProjectionDoc->setProjections (pProj);
2179 if (theApp->getAskDeleteNewDocs())
2180 pProjectionDoc-> Modify(true);
2181 pProjectionDoc->UpdateAllViews (this);
2182 pProjectionDoc->getView()->setInitialClientSize();
2183 pProjectionDoc->Activate();
2188 PhantomFileView::OnRasterize (wxCommandEvent& event)
2190 DialogGetRasterParameters dialogRaster (getFrameForChild(), m_iDefaultRasterNX, m_iDefaultRasterNY,
2191 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio);
2192 int retVal = dialogRaster.ShowModal();
2193 if (retVal != wxID_OK)
2196 m_iDefaultRasterNX = dialogRaster.getXSize();
2197 m_iDefaultRasterNY = dialogRaster.getYSize();
2198 m_iDefaultRasterNSamples = dialogRaster.getNSamples();
2199 m_dDefaultRasterViewRatio = dialogRaster.getViewRatio();
2200 if (m_iDefaultRasterNSamples < 1)
2201 m_iDefaultRasterNSamples = 1;
2202 if (m_dDefaultRasterViewRatio < 0)
2203 m_dDefaultRasterViewRatio = 0;
2204 if (m_iDefaultRasterNX <= 0 || m_iDefaultRasterNY <= 0)
2207 const Phantom& rPhantom = GetDocument()->getPhantom();
2208 std::ostringstream os;
2209 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << m_iDefaultRasterNX << ", YSize="
2210 << m_iDefaultRasterNY << ", ViewRatio=" << m_dDefaultRasterViewRatio << ", nSamples="
2211 << m_iDefaultRasterNSamples;;
2214 if (theApp->getUseBackgroundTasks()) {
2215 RasterizerSupervisorThread* pThread = new RasterizerSupervisorThread (this, m_iDefaultRasterNX, m_iDefaultRasterNY,
2216 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio, os.str().c_str());
2217 if (pThread->Create() != wxTHREAD_NO_ERROR) {
2218 *theApp->getLog() << "Error creating rasterizer thread\n";
2221 pThread->SetPriority (60);
2226 ImageFile* pImageFile = new ImageFile (m_iDefaultRasterNX, m_iDefaultRasterNY);
2228 wxProgressDialog dlgProgress (wxString("Rasterize"),
2229 wxString("Rasterization Progress"),
2230 pImageFile->nx() + 1,
2234 for (unsigned int i = 0; i < pImageFile->nx(); i++) {
2235 rPhantom.convertToImagefile (*pImageFile, m_dDefaultRasterViewRatio,
2236 m_iDefaultRasterNSamples, Trace::TRACE_NONE,
2238 if ((i + 1) % ITER_PER_UPDATE == 0)
2239 if (! dlgProgress.Update (i+1)) {
2245 ImageFileDocument* pRasterDoc = theApp->newImageDoc();
2247 sys_error (ERR_SEVERE, "Unable to create image file");
2250 pRasterDoc->setImageFile (pImageFile);
2251 if (theApp->getAskDeleteNewDocs())
2252 pRasterDoc->Modify (true);
2253 *theApp->getLog() << os.str().c_str() << "\n";
2254 pImageFile->labelAdd (os.str().c_str(), timer.timerEnd());
2256 pRasterDoc->UpdateAllViews(this);
2257 pRasterDoc->getView()->setInitialClientSize();
2258 pRasterDoc->Activate();
2264 PhantomFileView::CreateCanvas (wxFrame *parent)
2266 PhantomCanvas* pCanvas = new PhantomCanvas (this, parent, wxPoint(-1,-1),
2268 pCanvas->SetBackgroundColour(*wxWHITE);
2279 PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2282 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
2284 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
2286 theApp->setIconForFrame (subframe);
2288 m_pFileMenu = new wxMenu;
2290 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2291 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2292 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2293 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2294 m_pFileMenu->Append(wxID_CLOSE, "&Close");
2296 m_pFileMenu->AppendSeparator();
2297 m_pFileMenu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
2299 m_pFileMenu->AppendSeparator();
2300 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2301 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2302 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2303 m_pFileMenu->AppendSeparator();
2304 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
2305 m_pFileMenu->AppendSeparator();
2306 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
2307 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2308 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2309 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2311 wxMenu *process_menu = new wxMenu;
2312 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...\tCtrl-R");
2313 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...\tCtrl-J");
2315 wxMenu *help_menu = new wxMenu;
2316 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2317 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
2318 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
2319 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2321 wxMenuBar *menu_bar = new wxMenuBar;
2323 menu_bar->Append(m_pFileMenu, "&File");
2324 menu_bar->Append(process_menu, "&Process");
2325 menu_bar->Append(help_menu, "&Help");
2327 subframe->SetMenuBar(menu_bar);
2328 subframe->Centre(wxBOTH);
2330 wxAcceleratorEntry accelEntries[3];
2331 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('J'), PHMMENU_PROCESS_PROJECTIONS);
2332 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('R'), PHMMENU_PROCESS_RASTERIZE);
2333 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('I'), PHMMENU_FILE_PROPERTIES);
2334 wxAcceleratorTable accelTable (3, accelEntries);
2335 subframe->SetAcceleratorTable (accelTable);
2342 PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2344 m_pFrame = CreateChildFrame(doc, this);
2346 m_pCanvas = CreateCanvas (m_pFrame);
2347 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
2348 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
2349 m_pFrame->SetTitle ("PhantomFileView");
2351 m_pFrame->Show(true);
2358 PhantomFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2361 m_pCanvas->Refresh();
2365 PhantomFileView::OnClose (bool deleteWindow)
2367 if (! GetDocument() || ! GetDocument()->Close())
2372 m_pCanvas->setView(NULL);
2375 wxString s(wxTheApp->GetAppName());
2377 m_pFrame->SetTitle(s);
2384 if (GetDocument() && GetDocument()->getBadFileOpen())
2385 ::wxYield(); // wxWindows bug workaround
2392 PhantomFileView::OnDraw (wxDC* dc)
2395 m_pCanvas->GetClientSize (&xsize, &ysize);
2396 SGPDriver driver (dc, xsize, ysize);
2398 const Phantom& rPhantom = GetDocument()->getPhantom();
2399 sgp.setColor (C_RED);
2400 rPhantom.show (sgp);
2405 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2406 : wxScrolledWindow(frame, -1, pos, size, style)
2411 ProjectionFileCanvas::~ProjectionFileCanvas ()
2417 ProjectionFileCanvas::OnDraw(wxDC& dc)
2420 m_pView->OnDraw(& dc);
2424 ProjectionFileCanvas::GetBestSize () const
2426 const int iMinX = 50;
2427 const int iMinY = 20;
2428 wxSize bestSize (iMinX,iMinY);
2431 Projections& rProj = m_pView->GetDocument()->getProjections();
2432 bestSize.Set (rProj.nDet(), rProj.nView());
2435 if (bestSize.x > 800)
2437 if (bestSize.y > 800)
2440 if (bestSize.x < iMinX)
2442 if (bestSize.y < iMinY)
2449 // ProjectionFileView
2451 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
2453 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
2454 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
2455 EVT_MENU(PJMENU_RECONSTRUCT_FBP, ProjectionFileView::OnReconstructFBP)
2456 EVT_MENU(PJMENU_RECONSTRUCT_FBP_REBIN, ProjectionFileView::OnReconstructFBPRebin)
2457 EVT_MENU(PJMENU_RECONSTRUCT_FOURIER, ProjectionFileView::OnReconstructFourier)
2458 EVT_MENU(PJMENU_CONVERT_RECTANGULAR, ProjectionFileView::OnConvertRectangular)
2459 EVT_MENU(PJMENU_CONVERT_POLAR, ProjectionFileView::OnConvertPolar)
2460 EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
2461 EVT_MENU(PJMENU_CONVERT_PARALLEL, ProjectionFileView::OnConvertParallel)
2462 EVT_MENU(PJMENU_PLOT_TTHETA_SAMPLING, ProjectionFileView::OnPlotTThetaSampling)
2463 EVT_MENU(PJMENU_PLOT_HISTOGRAM, ProjectionFileView::OnPlotHistogram)
2464 // EVT_MENU(PJMENU_ARTIFACT_REDUCTION, ProjectionFileView::OnArtifactReduction)
2468 ProjectionFileView::ProjectionFileView()
2469 : wxView(), m_pBitmap(0), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0)
2479 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
2480 m_dDefaultFilterParam = 1.;
2482 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
2483 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
2485 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
2486 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
2488 m_iDefaultZeropad = 1;
2489 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF;
2490 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
2491 m_iDefaultInterpParam = 1;
2492 m_iDefaultTrace = Trace::TRACE_NONE;
2494 m_iDefaultPolarNX = 256;
2495 m_iDefaultPolarNY = 256;
2496 m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR;
2497 m_iDefaultPolarZeropad = 1;
2500 ProjectionFileView::~ProjectionFileView()
2502 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2503 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2507 ProjectionFileView::OnProperties (wxCommandEvent& event)
2509 const Projections& rProj = GetDocument()->getProjections();
2510 std::ostringstream os;
2511 rProj.printScanInfo(os);
2512 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2513 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
2514 dialogMsg.ShowModal();
2515 GetDocument()->Activate();
2520 ProjectionFileView::OnConvertRectangular (wxCommandEvent& event)
2522 Projections& rProj = GetDocument()->getProjections();
2524 int nDet = rProj.nDet();
2525 int nView = rProj.nView();
2526 ImageFile* pIF = new ImageFile (nDet, nView);
2527 ImageFileArray v = pIF->getArray();
2528 for (int iv = 0; iv < nView; iv++) {
2529 DetectorValue* detval = rProj.getDetectorArray(iv).detValues();
2531 for (int id = 0; id < nDet; id++)
2532 v[id][iv] = detval[id];
2535 ImageFileDocument* pRectDoc = theApp->newImageDoc ();
2537 sys_error (ERR_SEVERE, "Unable to create image file");
2540 pRectDoc->setImageFile (pIF);
2541 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2542 std::ostringstream os;
2543 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to rectangular image";
2544 *theApp->getLog() << os.str().c_str() << "\n";
2545 pIF->labelAdd (os.str().c_str());
2546 if (theApp->getAskDeleteNewDocs())
2547 pRectDoc->Modify (true);
2548 pRectDoc->UpdateAllViews();
2549 pRectDoc->getView()->setInitialClientSize();
2550 pRectDoc->Activate();
2554 ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
2556 Projections& rProj = GetDocument()->getProjections();
2557 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2558 m_iDefaultPolarInterpolation, -1, IDH_DLG_POLAR);
2559 if (dialogPolar.ShowModal() == wxID_OK) {
2560 wxProgressDialog dlgProgress (wxString("Convert Polar"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2561 wxString strInterpolation (dialogPolar.getInterpolationName());
2562 m_iDefaultPolarNX = dialogPolar.getXSize();
2563 m_iDefaultPolarNY = dialogPolar.getYSize();
2564 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2565 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2566 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2568 if (! rProj.convertPolar (*pIF, m_iDefaultPolarInterpolation)) {
2570 *theApp->getLog() << "Error converting to Polar\n";
2574 pPolarDoc = theApp->newImageDoc ();
2576 sys_error (ERR_SEVERE, "Unable to create image file");
2579 pPolarDoc->setImageFile (pIF);
2580 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2581 std::ostringstream os;
2582 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to polar image: xSize="
2583 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2584 << strInterpolation.c_str();
2585 *theApp->getLog() << os.str().c_str() << "\n";
2586 pIF->labelAdd (os.str().c_str());
2587 if (theApp->getAskDeleteNewDocs())
2588 pPolarDoc->Modify (true);
2589 pPolarDoc->UpdateAllViews ();
2590 pPolarDoc->getView()->setInitialClientSize();
2591 pPolarDoc->Activate();
2596 ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
2598 Projections& rProj = GetDocument()->getProjections();
2599 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert to FFT Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2600 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad, IDH_DLG_FFT_POLAR);
2601 if (dialogPolar.ShowModal() == wxID_OK) {
2602 wxProgressDialog dlgProgress (wxString("Convert FFT Polar"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2603 wxString strInterpolation (dialogPolar.getInterpolationName());
2604 m_iDefaultPolarNX = dialogPolar.getXSize();
2605 m_iDefaultPolarNY = dialogPolar.getYSize();
2606 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2607 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2609 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2610 if (! rProj.convertFFTPolar (*pIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad)) {
2612 *theApp->getLog() << "Error converting to polar\n";
2615 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2617 sys_error (ERR_SEVERE, "Unable to create image file");
2620 pPolarDoc->setImageFile (pIF);
2621 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2622 std::ostringstream os;
2623 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to FFT polar image: xSize="
2624 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2625 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2626 *theApp->getLog() << os.str().c_str() << "\n";
2627 pIF->labelAdd (os.str().c_str());
2628 if (theApp->getAskDeleteNewDocs())
2629 pPolarDoc->Modify (true);
2630 pPolarDoc->UpdateAllViews (this);
2631 pPolarDoc->getView()->setInitialClientSize();
2632 pPolarDoc->Activate();
2637 ProjectionFileView::OnPlotTThetaSampling (wxCommandEvent& event)
2639 DialogGetThetaRange dlgTheta (this->getFrame(), ParallelRaysums::THETA_RANGE_UNCONSTRAINED);
2640 if (dlgTheta.ShowModal() != wxID_OK)
2643 int iThetaRange = dlgTheta.getThetaRange();
2645 Projections& rProj = GetDocument()->getProjections();
2646 ParallelRaysums parallel (&rProj, iThetaRange);
2647 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
2648 PlotFile& rPlot = pPlotDoc->getPlotFile();
2649 ParallelRaysums::CoordinateContainer& coordContainer = parallel.getCoordinates();
2650 double* pdT = new double [parallel.getNumCoordinates()];
2651 double* pdTheta = new double [parallel.getNumCoordinates()];
2653 for (int i = 0; i < parallel.getNumCoordinates(); i++) {
2654 pdT[i] = coordContainer[i]->m_dT;
2655 pdTheta[i] = coordContainer[i]->m_dTheta;
2657 rPlot.setCurveSize (2, parallel.getNumCoordinates(), true);
2658 rPlot.addEzsetCommand ("title T-Theta Sampling");
2659 rPlot.addEzsetCommand ("xlabel T");
2660 rPlot.addEzsetCommand ("ylabel Theta");
2661 rPlot.addEzsetCommand ("curve 1");
2662 if (rProj.nDet() < 50 && rProj.nView() < 50)
2663 rPlot.addEzsetCommand ("symbol 1"); // x symbol
2665 rPlot.addEzsetCommand ("symbol 6"); // point symbol
2666 rPlot.addEzsetCommand ("noline");
2667 rPlot.addColumn (0, pdT);
2668 rPlot.addColumn (1, pdTheta);
2671 if (theApp->getAskDeleteNewDocs())
2672 pPlotDoc->Modify (true);
2673 pPlotDoc->getView()->getFrame()->Show(true);
2674 pPlotDoc->UpdateAllViews ();
2675 pPlotDoc->Activate();
2680 ProjectionFileView::OnPlotHistogram (wxCommandEvent& event)
2682 Projections& rProj = GetDocument()->getProjections();
2683 int nDet = rProj.nDet();
2684 int nView = rProj.nView();
2686 if (nDet < 1 || nView < 1)
2689 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
2691 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
2695 DetectorValue* pdDetval = rProj.getDetectorArray(0).detValues();
2696 double dMin = pdDetval[0], dMax = pdDetval[0];
2698 for (int iv = 0; iv < nView; iv++) {
2699 pdDetval = rProj.getDetectorArray(iv).detValues();
2700 for (int id = 0; id < nDet; id++) {
2701 double dV = pdDetval[id];
2709 double* pX = new double [NUMBER_HISTOGRAM_BINS];
2710 double* pY = new double [NUMBER_HISTOGRAM_BINS];
2711 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
2713 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
2714 pX[i] = dMin + (i + 0.5) * dBinWidth;
2717 for (int j = 0; j < nView; j++) {
2718 pdDetval = rProj.getDetectorArray(j).detValues();
2719 for (int id = 0; id < nDet; id++) {
2720 int iBin = nearest<int> ((pdDetval[id] - dMin) / dBinWidth);
2721 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
2725 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
2726 std::ostringstream os;
2728 std::string title("title ");
2730 rPlotFile.addEzsetCommand (title.c_str());
2731 rPlotFile.addEzsetCommand ("xlabel Detector Value");
2732 rPlotFile.addEzsetCommand ("ylabel Count");
2733 rPlotFile.addEzsetCommand ("box");
2734 rPlotFile.addEzsetCommand ("grid");
2735 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
2736 rPlotFile.addColumn (0, pX);
2737 rPlotFile.addColumn (1, pY);
2738 rPlotFile.addDescription (rProj.remark());
2739 os << " plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
2740 *theApp->getLog() << os.str().c_str() << "\n";
2741 rPlotFile.addDescription (os.str().c_str());
2744 if (theApp->getAskDeleteNewDocs())
2745 pPlotDoc->Modify (true);
2746 pPlotDoc->getView()->getFrame()->Show(true);
2747 pPlotDoc->UpdateAllViews ();
2748 pPlotDoc->Activate();
2753 ProjectionFileView::OnConvertParallel (wxCommandEvent& event)
2755 Projections& rProj = GetDocument()->getProjections();
2756 if (rProj.geometry() == Scanner::GEOMETRY_PARALLEL) {
2757 wxMessageBox ("Projections are already parallel", "Error");
2760 wxProgressDialog dlgProgress (wxString("Convert to Parallel"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2761 Projections* pProjNew = rProj.interpolateToParallel();
2762 ProjectionFileDocument* pProjDocNew = theApp->newProjectionDoc();
2763 pProjDocNew->setProjections (pProjNew);
2765 if (ProjectionFileView* projView = pProjDocNew->getView()) {
2766 projView->OnUpdate (projView, NULL);
2767 if (projView->getCanvas())
2768 projView->getCanvas()->SetClientSize (pProjNew->nDet(), pProjNew->nView());
2769 if (wxFrame* pFrame = projView->getFrame()) {
2774 GetDocumentManager()->ActivateView (projView, true, false);
2776 if (theApp->getAskDeleteNewDocs())
2777 pProjDocNew-> Modify(true);
2778 pProjDocNew->UpdateAllViews (this);
2779 pProjDocNew->getView()->setInitialClientSize();
2780 pProjDocNew->Activate();
2784 ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
2786 Projections& rProj = GetDocument()->getProjections();
2787 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Fourier Reconstruction", m_iDefaultPolarNX, m_iDefaultPolarNY,
2788 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad, IDH_DLG_RECON_FOURIER);
2789 if (dialogPolar.ShowModal() == wxID_OK) {
2790 wxProgressDialog dlgProgress (wxString("Reconstruction Fourier"), wxString("Reconstruction Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2791 wxString strInterpolation (dialogPolar.getInterpolationName());
2792 m_iDefaultPolarNX = dialogPolar.getXSize();
2793 m_iDefaultPolarNY = dialogPolar.getYSize();
2794 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2795 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2797 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2798 if (! rProj.convertFFTPolar (*pIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad)) {
2800 *theApp->getLog() << "Error converting to polar\n";
2806 pIF->magnitude(*pIF);
2807 Fourier::shuffleFourierToNaturalOrder (*pIF);
2809 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2811 sys_error (ERR_SEVERE, "Unable to create image file");
2814 pPolarDoc->setImageFile (pIF);
2815 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2816 std::ostringstream os;
2817 os << "Reconstruct Fourier " << GetFrame()->GetTitle().c_str() << ": xSize="
2818 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2819 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2820 *theApp->getLog() << os.str().c_str() << "\n";
2821 pIF->labelAdd (os.str().c_str());
2822 if (theApp->getAskDeleteNewDocs())
2823 pPolarDoc->Modify (true);
2824 pPolarDoc->UpdateAllViews ();
2825 pPolarDoc->getView()->setInitialClientSize();
2826 pPolarDoc->Activate();
2831 ProjectionFileView::OnReconstructFBPRebin (wxCommandEvent& event)
2833 Projections& rProj = GetDocument()->getProjections();
2834 doReconstructFBP (rProj, true);
2838 ProjectionFileView::OnReconstructFBP (wxCommandEvent& event)
2840 Projections& rProj = GetDocument()->getProjections();
2841 doReconstructFBP (rProj, false);
2845 ProjectionFileView::doReconstructFBP (const Projections& rProj, bool bRebinToParallel)
2847 ReconstructionROI defaultROI;
2848 defaultROI.m_dXMin = -rProj.phmLen() / 2;
2849 defaultROI.m_dXMax = defaultROI.m_dXMin + rProj.phmLen();
2850 defaultROI.m_dYMin = -rProj.phmLen() / 2;
2851 defaultROI.m_dYMax = defaultROI.m_dYMin + rProj.phmLen();
2853 DialogGetReconstructionParameters dialogReconstruction (getFrameForChild(), m_iDefaultNX, m_iDefaultNY,
2854 m_iDefaultFilter, m_dDefaultFilterParam, m_iDefaultFilterMethod, m_iDefaultFilterGeneration,
2855 m_iDefaultZeropad, m_iDefaultInterpolation, m_iDefaultInterpParam, m_iDefaultBackprojector,
2856 m_iDefaultTrace, &defaultROI);
2858 int retVal = dialogReconstruction.ShowModal();
2859 if (retVal != wxID_OK)
2862 m_iDefaultNX = dialogReconstruction.getXSize();
2863 m_iDefaultNY = dialogReconstruction.getYSize();
2864 wxString optFilterName = dialogReconstruction.getFilterName();
2865 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
2866 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
2867 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
2868 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
2869 m_iDefaultZeropad = dialogReconstruction.getZeropad();
2870 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
2871 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
2872 wxString optInterpName = dialogReconstruction.getInterpName();
2873 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
2874 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
2875 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
2876 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
2877 m_iDefaultTrace = dialogReconstruction.getTrace();
2878 dialogReconstruction.getROI (&defaultROI);
2880 if (m_iDefaultNX <= 0 && m_iDefaultNY <= 0)
2883 std::ostringstream os;
2884 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();
2885 if (bRebinToParallel)
2886 os << "; Interpolate to Parallel";
2889 ImageFile* pImageFile = NULL;
2890 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2891 pImageFile = new ImageFile (m_iDefaultNX, m_iDefaultNY);
2892 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2893 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2894 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace,
2895 &defaultROI, bRebinToParallel);
2897 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstructor, rProj, *pImageFile, m_iDefaultTrace, getFrameForChild());
2898 for (int iView = 0; iView < rProj.nView(); iView++) {
2900 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView, true)) {
2901 delete pDlgReconstruct;
2902 delete pReconstructor;
2907 while (pDlgReconstruct->isPaused()) {
2912 pReconstructor->postProcessing();
2913 delete pDlgReconstruct;
2914 delete pReconstructor;
2917 if (theApp->getUseBackgroundTasks()) {
2918 ReconstructorSupervisorThread* pReconstructor = new ReconstructorSupervisorThread (this, m_iDefaultNX,
2919 m_iDefaultNY, optFilterName.c_str(), m_dDefaultFilterParam, optFilterMethodName.c_str(),
2920 m_iDefaultZeropad, optFilterGenerationName.c_str(), optInterpName.c_str(), m_iDefaultInterpParam,
2921 optBackprojectName.c_str(), os.str().c_str(), &defaultROI, bRebinToParallel);
2922 if (pReconstructor->Create() != wxTHREAD_NO_ERROR) {
2923 sys_error (ERR_SEVERE, "Error creating reconstructor thread");
2924 delete pReconstructor;
2927 pReconstructor->SetPriority (60);
2928 pReconstructor->Run();
2933 pImageFile = new ImageFile (m_iDefaultNX, m_iDefaultNY);
2934 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2935 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2936 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2937 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace,
2938 &defaultROI, bRebinToParallel);
2940 for (int iView = 0; iView < rProj.nView(); iView++) {
2941 pReconstructor->reconstructView (iView, 1);
2942 if ((iView + 1) % ITER_PER_UPDATE == 0)
2943 if (! dlgProgress.Update (iView + 1)) {
2944 delete pReconstructor;
2945 return; // don't make new window, thread will do this
2948 pReconstructor->postProcessing();
2949 delete pReconstructor;
2952 ImageFileDocument* pReconDoc = theApp->newImageDoc();
2954 sys_error (ERR_SEVERE, "Unable to create image file");
2957 *theApp->getLog() << os.str().c_str() << "\n";
2958 pImageFile->labelAdd (rProj.getLabel());
2959 pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd());
2961 pReconDoc->setImageFile (pImageFile);
2962 if (theApp->getAskDeleteNewDocs())
2963 pReconDoc->Modify (true);
2964 pReconDoc->UpdateAllViews();
2965 pReconDoc->getView()->setInitialClientSize();
2966 pReconDoc->Activate();
2971 ProjectionFileView::OnArtifactReduction (wxCommandEvent& event)
2976 ProjectionFileCanvas*
2977 ProjectionFileView::CreateCanvas (wxFrame *parent)
2979 ProjectionFileCanvas* pCanvas;
2981 parent->GetClientSize(&width, &height);
2983 pCanvas = new ProjectionFileCanvas (this, parent, wxPoint(-1,-1), wxSize(width, height), 0);
2985 pCanvas->SetScrollbars(20, 20, 50, 50);
2986 pCanvas->SetBackgroundColour(*wxWHITE);
2997 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
3000 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
3002 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
3004 theApp->setIconForFrame (subframe);
3006 m_pFileMenu = new wxMenu;
3008 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3009 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3010 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3011 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3012 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3013 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3015 m_pFileMenu->AppendSeparator();
3016 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
3018 m_pFileMenu->AppendSeparator();
3019 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3020 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3021 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3022 m_pFileMenu->AppendSeparator();
3023 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3024 m_pFileMenu->AppendSeparator();
3025 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3026 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3027 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3028 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3030 wxMenu *convert_menu = new wxMenu;
3031 convert_menu->Append (PJMENU_CONVERT_RECTANGULAR, "&Rectangular Image");
3032 convert_menu->Append (PJMENU_CONVERT_POLAR, "&Polar Image...\tCtrl-L");
3033 convert_menu->Append (PJMENU_CONVERT_FFT_POLAR, "FF&T->Polar Image...\tCtrl-T");
3034 convert_menu->AppendSeparator();
3035 convert_menu->Append (PJMENU_CONVERT_PARALLEL, "&Interpolate to Parallel");
3037 // wxMenu* filter_menu = new wxMenu;
3038 // filter_menu->Append (PJMENU_ARTIFACT_REDUCTION, "&Artifact Reduction");
3040 wxMenu* analyze_menu = new wxMenu;
3041 analyze_menu->Append (PJMENU_PLOT_HISTOGRAM, "&Plot Histogram");
3042 analyze_menu->Append (PJMENU_PLOT_TTHETA_SAMPLING, "Plot T-T&heta Sampling...\tCtrl-H");
3044 wxMenu *reconstruct_menu = new wxMenu;
3045 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP, "&Filtered Backprojection...\tCtrl-R", "Reconstruct image using filtered backprojection");
3046 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP_REBIN, "Filtered &Backprojection (Rebin to Parallel)...\tCtrl-B", "Reconstruct image using filtered backprojection");
3048 // reconstruct_menu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Fourier...\tCtrl-E", "Reconstruct image using inverse Fourier");
3050 wxMenu *help_menu = new wxMenu;
3051 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3052 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3053 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3054 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3056 wxMenuBar *menu_bar = new wxMenuBar;
3058 menu_bar->Append (m_pFileMenu, "&File");
3059 menu_bar->Append (convert_menu, "&Convert");
3060 // menu_bar->Append (filter_menu, "Fi<er");
3061 menu_bar->Append (analyze_menu, "&Analyze");
3062 menu_bar->Append (reconstruct_menu, "&Reconstruct");
3063 menu_bar->Append (help_menu, "&Help");
3065 subframe->SetMenuBar(menu_bar);
3066 subframe->Centre(wxBOTH);
3068 wxAcceleratorEntry accelEntries[7];
3069 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('L'), PJMENU_CONVERT_POLAR);
3070 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('T'), PJMENU_CONVERT_FFT_POLAR);
3071 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('R'), PJMENU_RECONSTRUCT_FBP);
3072 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('B'), PJMENU_RECONSTRUCT_FBP_REBIN);
3073 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('E'), PJMENU_RECONSTRUCT_FOURIER);
3074 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('I'), PJMENU_FILE_PROPERTIES);
3075 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('H'), PJMENU_PLOT_TTHETA_SAMPLING);
3076 wxAcceleratorTable accelTable (7, accelEntries);
3077 subframe->SetAcceleratorTable (accelTable);
3084 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
3086 m_pFrame = CreateChildFrame(doc, this);
3088 m_pCanvas = CreateCanvas (m_pFrame);
3089 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
3090 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
3091 m_pFrame->SetTitle ("ProjectionFileView");
3093 m_pFrame->Show(true);
3100 ProjectionFileView::OnDraw (wxDC* dc)
3102 if (m_pBitmap && m_pBitmap->Ok())
3103 dc->DrawBitmap (*m_pBitmap, 0, 0, false);
3108 ProjectionFileView::setInitialClientSize ()
3110 if (m_pFrame && m_pCanvas) {
3111 wxSize bestSize = m_pCanvas->GetBestSize();
3113 m_pFrame->SetClientSize (bestSize);
3114 m_pFrame->Show (true);
3115 m_pFrame->SetFocus();
3120 ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3122 const Projections& rProj = GetDocument()->getProjections();
3123 const int nDet = rProj.nDet();
3124 const int nView = rProj.nView();
3125 if (nDet != 0 && nView != 0) {
3126 const DetectorArray& detarray = rProj.getDetectorArray(0);
3127 const DetectorValue* detval = detarray.detValues();
3128 double min = detval[0];
3129 double max = detval[0];
3130 for (int iy = 0; iy < nView; iy++) {
3131 const DetectorArray& detarray = rProj.getDetectorArray(iy);
3132 const DetectorValue* detval = detarray.detValues();
3133 for (int ix = 0; ix < nDet; ix++) {
3134 if (min > detval[ix])
3136 else if (max < detval[ix])
3141 unsigned char* imageData = new unsigned char [nDet * nView * 3];
3143 sys_error (ERR_SEVERE, "Unable to allocate memory for image display");
3146 double scale = (max - min) / 255;
3147 for (int iy2 = 0; iy2 < nView; iy2++) {
3148 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
3149 const DetectorValue* detval = detarray.detValues();
3150 for (int ix = 0; ix < nDet; ix++) {
3151 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
3152 intensity = clamp(intensity, 0, 255);
3153 int baseAddr = (iy2 * nDet + ix) * 3;
3154 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
3157 wxImage image (nDet, nView, imageData, true);
3162 m_pBitmap = new wxBitmap (image);
3166 m_pCanvas->SetScrollbars(20, 20, nDet/20, nView/20);
3167 m_pCanvas->SetBackgroundColour(*wxWHITE);
3170 m_pCanvas->Refresh();
3174 ProjectionFileView::OnClose (bool deleteWindow)
3176 //GetDocumentManager()->ActivateView (this, false, true);
3177 if (! GetDocument() || ! GetDocument()->Close())
3182 m_pCanvas->setView(NULL);
3185 wxString s(wxTheApp->GetAppName());
3187 m_pFrame->SetTitle(s);
3194 if (GetDocument() && GetDocument()->getBadFileOpen())
3195 ::wxYield(); // wxWindows bug workaround
3204 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
3205 : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v)
3209 PlotFileCanvas::~PlotFileCanvas ()
3214 PlotFileCanvas::GetBestSize() const
3216 return wxSize (500, 300);
3221 PlotFileCanvas::OnDraw(wxDC& dc)
3224 m_pView->OnDraw(& dc);
3230 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
3232 BEGIN_EVENT_TABLE(PlotFileView, wxView)
3233 EVT_MENU(PLOTMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
3234 EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
3235 EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
3236 EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
3239 PlotFileView::PlotFileView()
3240 : wxView(), m_pFrame(0), m_pCanvas(0), m_pEZPlot(0), m_pFileMenu(0),
3241 m_bMinSpecified(false), m_bMaxSpecified(false)
3245 PlotFileView::~PlotFileView()
3250 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
3251 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
3255 PlotFileView::OnProperties (wxCommandEvent& event)
3257 const PlotFile& rPlot = GetDocument()->getPlotFile();
3258 std::ostringstream os;
3259 os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
3260 rPlot.printHeadersBrief (os);
3261 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<<\n";
3262 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
3263 dialogMsg.ShowModal();
3264 GetDocument()->Activate();
3269 PlotFileView::OnScaleAuto (wxCommandEvent& event)
3271 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3272 double min, max, mean, mode, median, stddev;
3273 rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
3274 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
3275 int iRetVal = dialogAutoScale.ShowModal();
3276 if (iRetVal == wxID_OK) {
3277 m_bMinSpecified = true;
3278 m_bMaxSpecified = true;
3280 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
3283 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
3284 OnUpdate (this, NULL);
3287 GetDocument()->Activate();
3291 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
3293 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3297 if (! m_bMinSpecified || ! m_bMaxSpecified) {
3298 if (! rPlotFile.getMinMax (1, min, max)) {
3299 *theApp->getLog() << "Error: unable to find Min/Max\n";
3304 if (m_bMinSpecified)
3306 if (m_bMaxSpecified)
3309 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Y-axis Minimum & Maximum", min, max);
3310 int retVal = dialogMinMax.ShowModal();
3311 if (retVal == wxID_OK) {
3312 m_bMinSpecified = true;
3313 m_bMaxSpecified = true;
3314 m_dMinPixel = dialogMinMax.getMinimum();
3315 m_dMaxPixel = dialogMinMax.getMaximum();
3316 OnUpdate (this, NULL);
3318 GetDocument()->Activate();
3322 PlotFileView::OnScaleFull (wxCommandEvent& event)
3324 if (m_bMinSpecified || m_bMaxSpecified) {
3325 m_bMinSpecified = false;
3326 m_bMaxSpecified = false;
3327 OnUpdate (this, NULL);
3329 GetDocument()->Activate();
3334 PlotFileView::CreateCanvas (wxFrame* parent)
3336 PlotFileCanvas* pCanvas;
3338 pCanvas = new PlotFileCanvas (this, parent, wxPoint(-1,-1), wxSize(-1,-1), 0);
3339 pCanvas->SetBackgroundColour(*wxWHITE);
3350 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
3353 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
3355 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
3357 theApp->setIconForFrame (subframe);
3359 m_pFileMenu = new wxMenu;
3361 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3362 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3363 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3364 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3365 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3366 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3368 m_pFileMenu->AppendSeparator();
3369 m_pFileMenu->Append(PLOTMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
3371 m_pFileMenu->AppendSeparator();
3372 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3373 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3374 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3375 m_pFileMenu->AppendSeparator();
3376 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3377 m_pFileMenu->AppendSeparator();
3378 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3379 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3380 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3381 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3383 wxMenu *view_menu = new wxMenu;
3384 view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...\tCtrl-E");
3385 view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
3386 view_menu->Append(PLOTMENU_VIEW_SCALE_FULL, "Display &Full Scale\tCtrl-U");
3388 wxMenu *help_menu = new wxMenu;
3389 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3390 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3391 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3392 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3394 wxMenuBar *menu_bar = new wxMenuBar;
3396 menu_bar->Append(m_pFileMenu, "&File");
3397 menu_bar->Append(view_menu, "&View");
3398 menu_bar->Append(help_menu, "&Help");
3400 subframe->SetMenuBar(menu_bar);
3401 subframe->Centre(wxBOTH);
3403 wxAcceleratorEntry accelEntries[4];
3404 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('E'), PLOTMENU_VIEW_SCALE_MINMAX);
3405 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('A'), PLOTMENU_VIEW_SCALE_AUTO);
3406 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('U'), PLOTMENU_VIEW_SCALE_FULL);
3407 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), PLOTMENU_FILE_PROPERTIES);
3408 wxAcceleratorTable accelTable (4, accelEntries);
3409 subframe->SetAcceleratorTable (accelTable);
3416 PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
3418 m_bMinSpecified = false;
3419 m_bMaxSpecified = false;
3420 m_dAutoScaleFactor = 1.;
3422 m_pFrame = CreateChildFrame(doc, this);
3424 m_pCanvas = CreateCanvas (m_pFrame);
3425 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
3426 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
3427 m_pFrame->SetTitle ("Plot File");
3429 m_pFrame->Show(true);
3436 PlotFileView::setInitialClientSize ()
3438 if (m_pFrame && m_pCanvas) {
3439 wxSize bestSize = m_pCanvas->GetBestSize();
3441 m_pFrame->SetClientSize (bestSize);
3442 m_pFrame->Show (true);
3443 m_pFrame->SetFocus();
3449 PlotFileView::OnDraw (wxDC* dc)
3451 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3452 const int iNColumns = rPlotFile.getNumColumns();
3453 const int iNRecords = rPlotFile.getNumRecords();
3455 if (iNColumns > 0 && iNRecords > 0) {
3457 m_pCanvas->GetClientSize (&xsize, &ysize);
3458 SGPDriver driver (dc, xsize, ysize);
3461 m_pEZPlot->plot (&sgp);
3467 PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3469 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3470 const int iNColumns = rPlotFile.getNumColumns();
3471 const int iNRecords = rPlotFile.getNumRecords();
3472 const bool bScatterPlot = rPlotFile.getIsScatterPlot();
3474 if (iNColumns > 0 && iNRecords > 0) {
3477 m_pEZPlot = new EZPlot;
3479 for (unsigned int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)
3480 m_pEZPlot->ezset (rPlotFile.getEzsetCommand (iEzset));
3482 if (m_bMinSpecified) {
3483 std::ostringstream os;
3484 os << "ymin " << m_dMinPixel;
3485 m_pEZPlot->ezset (os.str());
3488 if (m_bMaxSpecified) {
3489 std::ostringstream os;
3490 os << "ymax " << m_dMaxPixel;
3491 m_pEZPlot->ezset (os.str());
3494 m_pEZPlot->ezset("box");
3495 m_pEZPlot->ezset("grid");
3497 double* pdX = new double [iNRecords];
3498 double* pdY = new double [iNRecords];
3499 if (! bScatterPlot) {
3500 rPlotFile.getColumn (0, pdX);
3502 for (int iCol = 1; iCol < iNColumns; iCol++) {
3503 rPlotFile.getColumn (iCol, pdY);
3504 m_pEZPlot->addCurve (pdX, pdY, iNRecords);
3507 rPlotFile.getColumn (0, pdX);
3508 rPlotFile.getColumn (1, pdY);
3509 m_pEZPlot->addCurve (pdX, pdY, iNRecords);
3516 m_pCanvas->Refresh();
3520 PlotFileView::OnClose (bool deleteWindow)
3522 if (! GetDocument() || ! GetDocument()->Close())
3527 m_pCanvas->setView (NULL);
3530 wxString s(wxTheApp->GetAppName());
3532 m_pFrame->SetTitle(s);
3538 if (GetDocument() && GetDocument()->getBadFileOpen())
3539 ::wxYield(); // wxWindows bug workaround
3546 ////////////////////////////////////////////////////////////////
3549 IMPLEMENT_DYNAMIC_CLASS(TextFileView, wxView)
3551 TextFileView::~TextFileView()
3553 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
3554 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
3557 bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
3559 m_pFrame = CreateChildFrame(doc, this);
3560 SetFrame (m_pFrame);
3563 m_pFrame->GetClientSize(&width, &height);
3564 m_pFrame->SetTitle("TextFile");
3565 m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(-1,-1), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
3566 m_pFrame->SetTitle("Log");
3568 m_pFrame->Show (true);
3574 // Handled by wxTextWindow
3575 void TextFileView::OnDraw(wxDC *WXUNUSED(dc) )
3579 void TextFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3584 TextFileView::OnClose (bool deleteWindow)
3586 if (! theApp->getMainFrame()->getShuttingDown())
3590 //GetDocumentManager()->ActivateView (this, false, true);
3591 if (! GetDocument() || ! GetDocument()->Close())
3598 if (GetDocument() && GetDocument()->getBadFileOpen())
3599 ::wxYield(); // wxWindows bug workaround
3610 TextFileView::CreateChildFrame (wxDocument *doc, wxView *view)
3613 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE, "Log");
3615 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE, "Log");
3617 theApp->setIconForFrame (subframe);
3619 m_pFileMenu = new wxMenu;
3621 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3622 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3623 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3624 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3625 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3626 // m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3628 m_pFileMenu->AppendSeparator();
3629 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3630 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3631 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3632 m_pFileMenu->AppendSeparator();
3633 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3634 m_pFileMenu->AppendSeparator();
3635 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3636 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3637 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3638 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3640 wxMenu *help_menu = new wxMenu;
3641 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3642 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3643 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3644 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3646 wxMenuBar *menu_bar = new wxMenuBar;
3648 menu_bar->Append(m_pFileMenu, "&File");
3649 menu_bar->Append(help_menu, "&Help");
3651 subframe->SetMenuBar(menu_bar);
3652 subframe->Centre(wxBOTH);
3658 // Define a constructor for my text subwindow
3659 TextFileCanvas::TextFileCanvas (TextFileView* v, wxFrame* frame, const wxPoint& pos, const wxSize& size, long style)
3660 : wxTextCtrl (frame, -1, "", pos, size, style), m_pView(v)
3664 TextFileCanvas::~TextFileCanvas ()
3670 TextFileCanvas::GetBestSize() const
3673 theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
3674 xSize = maxValue<int> (xSize, ySize);
3676 ySize = xSize = (xSize / 4);
3680 return wxSize (xSize, ySize);