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.151 2002/05/03 00:40:30 kevin Exp $
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
28 #include "wx/wxprec.h"
33 #if !wxUSE_DOC_VIEW_ARCHITECTURE
34 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
38 #include "wx/progdlg.h"
39 #include "wx/clipbrd.h"
46 #include "dlgprojections.h"
47 #include "dlgreconstruct.h"
48 #include "backprojectors.h"
49 #include "reconstruct.h"
51 #include "threadproj.h"
52 #include "threadrecon.h"
53 #include "threadraster.h"
55 #if defined(MSVC) || HAVE_SSTREAM
58 #include <sstream_subst>
64 BEGIN_EVENT_TABLE(ImageFileCanvas, wxScrolledWindow)
65 EVT_MOUSE_EVENTS(ImageFileCanvas::OnMouseEvent)
66 EVT_CHAR(ImageFileCanvas::OnChar)
70 ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
71 : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v), m_xCursor(-1), m_yCursor(-1)
75 ImageFileCanvas::~ImageFileCanvas()
81 ImageFileCanvas::OnDraw(wxDC& dc)
84 m_pView->OnDraw(& dc);
88 ImageFileCanvas::DrawRubberBandCursor (wxDC& dc, int x, int y)
90 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
95 dc.SetLogicalFunction (wxINVERT);
96 dc.SetPen (*wxGREEN_PEN);
97 dc.DrawLine (0, yPt, nx, yPt);
98 dc.DrawLine (x, 0, x, ny);
99 dc.SetLogicalFunction (wxCOPY);
103 ImageFileCanvas::GetCurrentCursor (int& x, int& y)
108 if (m_xCursor >= 0 && m_yCursor >= 0)
115 ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
124 wxPoint pt(event.GetLogicalPosition(dc));
126 const ImageFileDocument* pIFDoc = m_pView->GetDocument();
129 const ImageFile& rIF = pIFDoc->getImageFile();
130 ImageFileArrayConst v = rIF.getArray();
133 const int yPt = ny - 1 - pt.y;
134 if (event.RightIsDown()) {
135 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
136 std::ostringstream os;
137 os << "Image value (" << pt.x << "," << yPt << ") = " << v[pt.x][yPt];
138 if (rIF.isComplex()) {
139 double dImag = rIF.getImaginaryArray()[pt.x][yPt];
141 os << " - " << -dImag;
143 os << " + " << dImag;
147 *theApp->getLog() << os.str().c_str();
149 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
151 else if (event.LeftIsDown() || event.LeftUp() || event.RightUp()) {
152 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
153 if (m_xCursor >= 0 && m_yCursor >= 0) {
154 DrawRubberBandCursor (dc, m_xCursor, m_yCursor);
156 DrawRubberBandCursor (dc, pt.x, yPt);
159 wxMenu* pMenu = m_pView->getMenuAnalyze();
160 if (pMenu && ! pMenu->IsEnabled(IFMENU_PLOT_ROW)) {
161 pMenu->Enable (IFMENU_PLOT_ROW, true);
162 pMenu->Enable (IFMENU_PLOT_COL, true);
163 pMenu->Enable (IFMENU_COMPARE_ROW, true);
164 pMenu->Enable (IFMENU_COMPARE_COL, true);
165 pMenu->Enable (IFMENU_PLOT_FFT_ROW, true);
166 pMenu->Enable (IFMENU_PLOT_FFT_COL, true);
169 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
171 if (event.LeftUp()) {
172 std::ostringstream os;
173 os << "Selected column " << pt.x << " , row " << yPt << "\n";
174 *theApp->getLog() << os.str().c_str();
179 ImageFileCanvas::OnChar (wxKeyEvent& event)
181 if (event.GetKeyCode() == WXK_ESCAPE) {
185 m_pView->OnUpdate (NULL);
187 wxScrolledWindow::OnChar (event);
191 ImageFileCanvas::GetBestSize() const
196 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
197 return wxSize (rIF.nx(), rIF.ny());
203 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
205 BEGIN_EVENT_TABLE(ImageFileView, wxView)
206 EVT_MENU(IFMENU_FILE_EXPORT, ImageFileView::OnExport)
207 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
208 EVT_MENU(IFMENU_EDIT_COPY, ImageFileView::OnEditCopy)
209 EVT_MENU(IFMENU_EDIT_CUT, ImageFileView::OnEditCut)
210 EVT_MENU(IFMENU_EDIT_PASTE, ImageFileView::OnEditPaste)
211 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
212 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
213 EVT_MENU(IFMENU_VIEW_SCALE_FULL, ImageFileView::OnScaleFull)
214 EVT_MENU(IFMENU_COMPARE_IMAGES, ImageFileView::OnCompare)
215 EVT_MENU(IFMENU_COMPARE_ROW, ImageFileView::OnCompareRow)
216 EVT_MENU(IFMENU_COMPARE_COL, ImageFileView::OnCompareCol)
217 EVT_MENU(IFMENU_FILTER_INVERTVALUES, ImageFileView::OnInvertValues)
218 EVT_MENU(IFMENU_FILTER_SQUARE, ImageFileView::OnSquare)
219 EVT_MENU(IFMENU_FILTER_SQRT, ImageFileView::OnSquareRoot)
220 EVT_MENU(IFMENU_FILTER_LOG, ImageFileView::OnLog)
221 EVT_MENU(IFMENU_FILTER_EXP, ImageFileView::OnExp)
222 EVT_MENU(IFMENU_FILTER_FOURIER, ImageFileView::OnFourier)
223 EVT_MENU(IFMENU_FILTER_INVERSE_FOURIER, ImageFileView::OnInverseFourier)
224 EVT_MENU(IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, ImageFileView::OnShuffleFourierToNaturalOrder)
225 EVT_MENU(IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, ImageFileView::OnShuffleNaturalToFourierOrder)
226 EVT_MENU(IFMENU_IMAGE_ADD, ImageFileView::OnAdd)
227 EVT_MENU(IFMENU_IMAGE_SUBTRACT, ImageFileView::OnSubtract)
228 EVT_MENU(IFMENU_IMAGE_MULTIPLY, ImageFileView::OnMultiply)
229 EVT_MENU(IFMENU_IMAGE_DIVIDE, ImageFileView::OnDivide)
230 EVT_MENU(IFMENU_IMAGE_SCALESIZE, ImageFileView::OnScaleSize)
232 EVT_MENU(IFMENU_IMAGE_CONVERT3D, ImageFileView::OnConvert3d)
235 EVT_MENU(IFMENU_FILTER_FFT, ImageFileView::OnFFT)
236 EVT_MENU(IFMENU_FILTER_IFFT, ImageFileView::OnIFFT)
237 EVT_MENU(IFMENU_FILTER_FFT_ROWS, ImageFileView::OnFFTRows)
238 EVT_MENU(IFMENU_FILTER_IFFT_ROWS, ImageFileView::OnIFFTRows)
239 EVT_MENU(IFMENU_FILTER_FFT_COLS, ImageFileView::OnFFTCols)
240 EVT_MENU(IFMENU_FILTER_IFFT_COLS, ImageFileView::OnIFFTCols)
242 EVT_MENU(IFMENU_FILTER_MAGNITUDE, ImageFileView::OnMagnitude)
243 EVT_MENU(IFMENU_FILTER_PHASE, ImageFileView::OnPhase)
244 EVT_MENU(IFMENU_FILTER_REAL, ImageFileView::OnReal)
245 EVT_MENU(IFMENU_FILTER_IMAGINARY, ImageFileView::OnImaginary)
246 EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)
247 EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol)
249 EVT_MENU(IFMENU_PLOT_FFT_ROW, ImageFileView::OnPlotFFTRow)
250 EVT_MENU(IFMENU_PLOT_FFT_COL, ImageFileView::OnPlotFFTCol)
252 EVT_MENU(IFMENU_PLOT_HISTOGRAM, ImageFileView::OnPlotHistogram)
255 ImageFileView::ImageFileView()
256 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0), m_pFilterMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
258 m_iDefaultExportFormatID = ImageFile::EXPORT_FORMAT_PNG;
261 ImageFileView::~ImageFileView()
263 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
264 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
269 ImageFileView::OnProperties (wxCommandEvent& event)
271 const ImageFile& rIF = GetDocument()->getImageFile();
272 if (rIF.nx() == 0 || rIF.ny() == 0)
273 *theApp->getLog() << "Properties: empty imagefile\n";
275 const std::string rFilename = m_pFrame->GetTitle().c_str();
276 std::ostringstream os;
277 double min, max, mean, mode, median, stddev;
278 rIF.statistics (rIF.getArray(), min, max, mean, mode, median, stddev);
279 os << "Filename: " << rFilename << "\n";
280 os << "Size: (" << rIF.nx() << "," << rIF.ny() << ")\n";
286 os << "Minimum: "<<min<<"\nMaximum: "<<max<<"\nMean: "<<mean<<"\nMedian: "<<median<<"\nMode: "<<mode<<"\nStandard Deviation: "<<stddev << "\n";
287 if (rIF.isComplex()) {
288 rIF.statistics (rIF.getImaginaryArray(), min, max, mean, mode, median, stddev);
289 os << "Imaginary: min: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
291 if (rIF.nLabels() > 0) {
292 rIF.printLabelsBrief (os);
294 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
295 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
296 dialogMsg.ShowModal();
298 GetDocument()->Activate();
302 ImageFileView::OnScaleAuto (wxCommandEvent& event)
304 const ImageFile& rIF = GetDocument()->getImageFile();
305 double min, max, mean, mode, median, stddev;
306 rIF.statistics(min, max, mean, mode, median, stddev);
307 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
308 int iRetVal = dialogAutoScale.ShowModal();
309 if (iRetVal == wxID_OK) {
310 m_bMinSpecified = true;
311 m_bMaxSpecified = true;
313 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
316 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
317 GetDocument()->UpdateAllViews (this);
320 GetDocument()->Activate();
324 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
326 const ImageFile& rIF = GetDocument()->getImageFile();
328 if (! m_bMinSpecified && ! m_bMaxSpecified)
329 rIF.getMinMax (min, max);
336 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Image Minimum & Maximum", min, max);
337 int retVal = dialogMinMax.ShowModal();
338 if (retVal == wxID_OK) {
339 m_bMinSpecified = true;
340 m_bMaxSpecified = true;
341 m_dMinPixel = dialogMinMax.getMinimum();
342 m_dMaxPixel = dialogMinMax.getMaximum();
343 GetDocument()->UpdateAllViews (this);
345 GetDocument()->Activate();
349 ImageFileView::OnScaleFull (wxCommandEvent& event)
351 if (m_bMinSpecified || m_bMaxSpecified) {
352 m_bMinSpecified = false;
353 m_bMaxSpecified = false;
354 GetDocument()->UpdateAllViews (this);
356 GetDocument()->Activate();
360 ImageFileView::OnCompare (wxCommandEvent& event)
362 std::vector<ImageFileDocument*> vecIF;
363 theApp->getCompatibleImages (GetDocument(), vecIF);
365 if (vecIF.size() == 0) {
366 wxMessageBox("There are no compatible image files open for comparision", "No comparison images");
368 DialogGetComparisonImage dialogGetCompare(getFrameForChild(), "Get Comparison Image", vecIF, true);
370 if (dialogGetCompare.ShowModal() == wxID_OK) {
371 const ImageFile& rIF = GetDocument()->getImageFile();
372 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
373 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
374 std::ostringstream os;
375 double min, max, mean, mode, median, stddev;
376 rIF.statistics (min, max, mean, mode, median, stddev);
377 os << GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
378 rCompareIF.statistics (min, max, mean, mode, median, stddev);
379 os << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
381 rIF.comparativeStatistics (rCompareIF, d, r, e);
382 os << "Comparative Statistics: d=" << d << ", r=" << r << ", e=" << e << "\n";
383 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
384 if (dialogGetCompare.getMakeDifferenceImage()) {
385 ImageFile* pDifferenceImage = new ImageFile;
387 pDifferenceImage->setArraySize (rIF.nx(), rIF.ny());
388 if (! rIF.subtractImages (rCompareIF, *pDifferenceImage)) {
389 *theApp->getLog() << "Unable to subtract images\n";
390 delete pDifferenceImage;
393 ImageFileDocument* pDifferenceDoc = theApp->newImageDoc();
394 if (! pDifferenceDoc) {
395 sys_error (ERR_SEVERE, "Unable to create image file");
398 pDifferenceDoc->setImageFile (pDifferenceImage);
400 wxString s = GetFrame()->GetTitle() + ": ";
401 pDifferenceImage->labelsCopy (rIF, s.c_str());
402 s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
403 pDifferenceImage->labelsCopy (rCompareIF, s.c_str());
404 std::ostringstream osLabel;
405 osLabel << "Compare image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str()
406 << " and " << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": "
408 pDifferenceImage->labelAdd (os.str().c_str());
409 if (theApp->getAskDeleteNewDocs())
410 pDifferenceDoc->Modify (true);
411 pDifferenceDoc->UpdateAllViews(this);
412 pDifferenceDoc->getView()->setInitialClientSize();
413 pDifferenceDoc->Activate();
415 wxMessageBox(os.str().c_str(), "Image Comparison");
421 ImageFileView::OnInvertValues (wxCommandEvent& event)
423 ImageFile& rIF = GetDocument()->getImageFile();
424 rIF.invertPixelValues (rIF);
425 rIF.labelAdd ("Invert Pixel Values");
426 if (theApp->getAskDeleteNewDocs())
427 GetDocument()->Modify (true);
428 GetDocument()->UpdateAllViews (this);
429 GetDocument()->Activate();
433 ImageFileView::OnSquare (wxCommandEvent& event)
435 ImageFile& rIF = GetDocument()->getImageFile();
437 rIF.labelAdd ("Square Pixel Values");
438 if (theApp->getAskDeleteNewDocs())
439 GetDocument()->Modify (true);
440 GetDocument()->UpdateAllViews (this);
441 GetDocument()->Activate();
445 ImageFileView::OnSquareRoot (wxCommandEvent& event)
447 ImageFile& rIF = GetDocument()->getImageFile();
449 rIF.labelAdd ("Square-root Pixel Values");
450 if (theApp->getAskDeleteNewDocs())
451 GetDocument()->Modify (true);
452 GetDocument()->UpdateAllViews (this);
453 GetDocument()->Activate();
457 ImageFileView::OnLog (wxCommandEvent& event)
459 ImageFile& rIF = GetDocument()->getImageFile();
461 rIF.labelAdd ("Logrithm base-e Pixel Values");
462 if (theApp->getAskDeleteNewDocs())
463 GetDocument()->Modify (true);
464 GetDocument()->UpdateAllViews (this);
465 GetDocument()->Activate();
469 ImageFileView::OnExp (wxCommandEvent& event)
471 ImageFile& rIF = GetDocument()->getImageFile();
473 rIF.labelAdd ("Exponent base-e Pixel Values");
474 if (theApp->getAskDeleteNewDocs())
475 GetDocument()->Modify (true);
476 GetDocument()->UpdateAllViews (this);
477 GetDocument()->Activate();
481 ImageFileView::OnAdd (wxCommandEvent& event)
483 std::vector<ImageFileDocument*> vecIF;
484 theApp->getCompatibleImages (GetDocument(), vecIF);
486 if (vecIF.size() == 0) {
487 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
489 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Add", vecIF, false);
491 if (dialogGetCompare.ShowModal() == wxID_OK) {
492 ImageFile& rIF = GetDocument()->getImageFile();
493 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
494 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
495 ImageFileDocument* pNewDoc = theApp->newImageDoc();
497 sys_error (ERR_SEVERE, "Unable to create image file");
500 ImageFile& newImage = pNewDoc->getImageFile();
501 newImage.setArraySize (rIF.nx(), rIF.ny());
502 rIF.addImages (rRHSIF, newImage);
503 std::ostringstream os;
504 os << "Add image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
505 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
506 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
507 newImage.labelsCopy (rIF, s.c_str());
508 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
509 newImage.labelsCopy (rRHSIF, s.c_str());
510 newImage.labelAdd (os.str().c_str());
511 *theApp->getLog() << os.str().c_str() << "\n";
512 if (theApp->getAskDeleteNewDocs())
513 pNewDoc->Modify (true);
514 pNewDoc->UpdateAllViews (this);
515 pNewDoc->getView()->setInitialClientSize();
522 ImageFileView::OnSubtract (wxCommandEvent& event)
524 std::vector<ImageFileDocument*> vecIF;
525 theApp->getCompatibleImages (GetDocument(), vecIF);
527 if (vecIF.size() == 0) {
528 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
530 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Subtract", vecIF, false);
532 if (dialogGetCompare.ShowModal() == wxID_OK) {
533 ImageFile& rIF = GetDocument()->getImageFile();
534 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
535 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
536 ImageFileDocument* pNewDoc = theApp->newImageDoc();
538 sys_error (ERR_SEVERE, "Unable to create image file");
541 ImageFile& newImage = pNewDoc->getImageFile();
542 newImage.setArraySize (rIF.nx(), rIF.ny());
543 rIF.subtractImages (rRHSIF, newImage);
544 std::ostringstream os;
545 os << "Subtract image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
546 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
547 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
548 newImage.labelsCopy (rIF, s.c_str());
549 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
550 newImage.labelsCopy (rRHSIF, s.c_str());
551 newImage.labelAdd (os.str().c_str());
552 *theApp->getLog() << os.str().c_str() << "\n";
553 if (theApp->getAskDeleteNewDocs())
554 pNewDoc->Modify (true);
555 pNewDoc->UpdateAllViews (this);
556 pNewDoc->getView()->setInitialClientSize();
563 ImageFileView::OnMultiply (wxCommandEvent& event)
565 std::vector<ImageFileDocument*> vecIF;
566 theApp->getCompatibleImages (GetDocument(), vecIF);
568 if (vecIF.size() == 0) {
569 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
571 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Multiply", vecIF, false);
573 if (dialogGetCompare.ShowModal() == wxID_OK) {
574 ImageFile& rIF = GetDocument()->getImageFile();
575 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
576 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
577 ImageFileDocument* pNewDoc = theApp->newImageDoc();
579 sys_error (ERR_SEVERE, "Unable to create image file");
582 ImageFile& newImage = pNewDoc->getImageFile();
583 newImage.setArraySize (rIF.nx(), rIF.ny());
584 rIF.multiplyImages (rRHSIF, newImage);
585 std::ostringstream os;
586 os << "Multiply image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
587 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
588 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
589 newImage.labelsCopy (rIF, s.c_str());
590 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
591 newImage.labelsCopy (rRHSIF, s.c_str());
592 newImage.labelAdd (os.str().c_str());
593 *theApp->getLog() << os.str().c_str() << "\n";
594 if (theApp->getAskDeleteNewDocs())
595 pNewDoc->Modify (true);
596 pNewDoc->UpdateAllViews (this);
597 pNewDoc->getView()->setInitialClientSize();
604 ImageFileView::OnDivide (wxCommandEvent& event)
606 std::vector<ImageFileDocument*> vecIF;
607 theApp->getCompatibleImages (GetDocument(), vecIF);
609 if (vecIF.size() == 0) {
610 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
612 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Divide", vecIF, false);
614 if (dialogGetCompare.ShowModal() == wxID_OK) {
615 ImageFile& rIF = GetDocument()->getImageFile();
616 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
617 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
618 ImageFileDocument* pNewDoc = theApp->newImageDoc();
620 sys_error (ERR_SEVERE, "Unable to create image file");
623 ImageFile& newImage = pNewDoc->getImageFile();
624 newImage.setArraySize (rIF.nx(), rIF.ny());
625 rIF.divideImages (rRHSIF, newImage);
626 std::ostringstream os;
627 os << "Divide image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " by "
628 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
629 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
630 newImage.labelsCopy (rIF, s.c_str());
631 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
632 newImage.labelsCopy (rRHSIF, s.c_str());
633 newImage.labelAdd (os.str().c_str());
634 *theApp->getLog() << os.str().c_str() << "\n";
635 if (theApp->getAskDeleteNewDocs())
636 pNewDoc->Modify (true);
637 pNewDoc->UpdateAllViews (this);
638 pNewDoc->getView()->setInitialClientSize();
647 ImageFileView::OnFFT (wxCommandEvent& event)
649 ImageFile& rIF = GetDocument()->getImageFile();
651 rIF.labelAdd ("FFT Image");
652 m_bMinSpecified = false;
653 m_bMaxSpecified = false;
654 if (theApp->getAskDeleteNewDocs())
655 GetDocument()->Modify (true);
656 GetDocument()->UpdateAllViews (this);
657 GetDocument()->Activate();
661 ImageFileView::OnIFFT (wxCommandEvent& event)
663 ImageFile& rIF = GetDocument()->getImageFile();
665 rIF.labelAdd ("IFFT Image");
666 m_bMinSpecified = false;
667 m_bMaxSpecified = false;
668 if (theApp->getAskDeleteNewDocs())
669 GetDocument()->Modify (true);
670 GetDocument()->UpdateAllViews (this);
671 GetDocument()->Activate();
675 ImageFileView::OnFFTRows (wxCommandEvent& event)
677 ImageFile& rIF = GetDocument()->getImageFile();
679 rIF.labelAdd ("FFT Rows");
680 m_bMinSpecified = false;
681 m_bMaxSpecified = false;
682 if (theApp->getAskDeleteNewDocs())
683 GetDocument()->Modify (true);
684 GetDocument()->UpdateAllViews (this);
685 GetDocument()->Activate();
689 ImageFileView::OnIFFTRows (wxCommandEvent& event)
691 ImageFile& rIF = GetDocument()->getImageFile();
693 rIF.labelAdd ("IFFT Rows");
694 m_bMinSpecified = false;
695 m_bMaxSpecified = false;
696 if (theApp->getAskDeleteNewDocs())
697 GetDocument()->Modify (true);
698 GetDocument()->UpdateAllViews (this);
699 GetDocument()->Activate();
703 ImageFileView::OnFFTCols (wxCommandEvent& event)
705 ImageFile& rIF = GetDocument()->getImageFile();
707 rIF.labelAdd ("FFT Columns");
708 m_bMinSpecified = false;
709 m_bMaxSpecified = false;
710 if (theApp->getAskDeleteNewDocs())
711 GetDocument()->Modify (true);
712 GetDocument()->UpdateAllViews (this);
713 GetDocument()->Activate();
717 ImageFileView::OnIFFTCols (wxCommandEvent& event)
719 ImageFile& rIF = GetDocument()->getImageFile();
721 rIF.labelAdd ("IFFT Columns");
722 m_bMinSpecified = false;
723 m_bMaxSpecified = false;
724 if (theApp->getAskDeleteNewDocs())
725 GetDocument()->Modify (true);
726 GetDocument()->UpdateAllViews (this);
727 GetDocument()->Activate();
732 ImageFileView::OnFourier (wxCommandEvent& event)
734 ImageFile& rIF = GetDocument()->getImageFile();
735 wxProgressDialog dlgProgress (wxString("Fourier"), wxString("Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
737 rIF.labelAdd ("Fourier Image");
738 m_bMinSpecified = false;
739 m_bMaxSpecified = false;
740 if (theApp->getAskDeleteNewDocs())
741 GetDocument()->Modify (true);
742 GetDocument()->UpdateAllViews (this);
743 GetDocument()->Activate();
747 ImageFileView::OnInverseFourier (wxCommandEvent& event)
749 ImageFile& rIF = GetDocument()->getImageFile();
750 wxProgressDialog dlgProgress (wxString("Inverse Fourier"), wxString("Inverse Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
751 rIF.inverseFourier (rIF);
752 rIF.labelAdd ("Inverse 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::OnShuffleNaturalToFourierOrder (wxCommandEvent& event)
764 ImageFile& rIF = GetDocument()->getImageFile();
765 Fourier::shuffleNaturalToFourierOrder (rIF);
766 rIF.labelAdd ("Shuffle Natural To Fourier Order");
767 m_bMinSpecified = false;
768 m_bMaxSpecified = false;
769 if (theApp->getAskDeleteNewDocs())
770 GetDocument()->Modify (true);
771 GetDocument()->UpdateAllViews (this);
772 GetDocument()->Activate();
776 ImageFileView::OnShuffleFourierToNaturalOrder (wxCommandEvent& event)
778 ImageFile& rIF = GetDocument()->getImageFile();
779 Fourier::shuffleFourierToNaturalOrder (rIF);
780 rIF.labelAdd ("Shuffle Fourier To Natural Order");
781 m_bMinSpecified = false;
782 m_bMaxSpecified = false;
783 if (theApp->getAskDeleteNewDocs())
784 GetDocument()->Modify (true);
785 GetDocument()->UpdateAllViews (this);
786 GetDocument()->Activate();
790 ImageFileView::OnMagnitude (wxCommandEvent& event)
792 ImageFile& rIF = GetDocument()->getImageFile();
794 rIF.labelAdd ("Magnitude");
795 m_bMinSpecified = false;
796 m_bMaxSpecified = false;
797 if (theApp->getAskDeleteNewDocs())
798 GetDocument()->Modify (true);
799 GetDocument()->UpdateAllViews (this);
800 GetDocument()->Activate();
804 ImageFileView::OnPhase (wxCommandEvent& event)
806 ImageFile& rIF = GetDocument()->getImageFile();
807 if (rIF.isComplex()) {
809 rIF.labelAdd ("Phase of complex-image");
810 m_bMinSpecified = false;
811 m_bMaxSpecified = false;
812 if (theApp->getAskDeleteNewDocs())
813 GetDocument()->Modify (true);
814 GetDocument()->UpdateAllViews (this);
816 GetDocument()->Activate();
820 ImageFileView::OnReal (wxCommandEvent& event)
822 ImageFile& rIF = GetDocument()->getImageFile();
823 if (rIF.isComplex()) {
825 rIF.labelAdd ("Real component of complex-image");
826 m_bMinSpecified = false;
827 m_bMaxSpecified = false;
828 if (theApp->getAskDeleteNewDocs())
829 GetDocument()->Modify (true);
830 GetDocument()->UpdateAllViews (this);
832 GetDocument()->Activate();
836 ImageFileView::OnImaginary (wxCommandEvent& event)
838 ImageFile& rIF = GetDocument()->getImageFile();
839 if (rIF.isComplex()) {
841 rIF.labelAdd ("Imaginary component of complex-image");
842 m_bMinSpecified = false;
843 m_bMaxSpecified = false;
844 if (theApp->getAskDeleteNewDocs())
845 GetDocument()->Modify (true);
846 GetDocument()->UpdateAllViews (this);
848 GetDocument()->Activate();
853 ImageFileView::CreateCanvas (wxFrame* parent)
855 ImageFileCanvas* pCanvas;
857 parent->GetClientSize(&width, &height);
859 pCanvas = new ImageFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
861 pCanvas->SetScrollbars(20, 20, 50, 50);
862 pCanvas->SetBackgroundColour(*wxWHITE);
873 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
876 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
878 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
880 theApp->setIconForFrame (subframe);
882 m_pFileMenu = new wxMenu;
883 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
884 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
885 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
886 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
887 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
888 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
889 m_pFileMenu->Append(wxID_REVERT, "Re&vert");
891 m_pFileMenu->AppendSeparator();
892 m_pFileMenu->Append(IFMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
893 m_pFileMenu->Append(IFMENU_FILE_EXPORT, "Expor&t...");
895 m_pFileMenu->AppendSeparator();
896 m_pFileMenu->Append(wxID_PRINT, "&Print...");
897 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
898 m_pFileMenu->Append(wxID_PREVIEW, "Print Preview");
899 m_pFileMenu->AppendSeparator();
900 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
902 m_pFileMenu->AppendSeparator();
903 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
904 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
906 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
907 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
909 wxMenu* edit_menu = new wxMenu;
910 edit_menu->Append(IFMENU_EDIT_COPY, "Copy\tCtrl-C");
911 edit_menu->Append(IFMENU_EDIT_CUT, "Cut\tCtrl-X");
912 edit_menu->Append(IFMENU_EDIT_PASTE, "Paste\tCtrl-V");
914 wxMenu *view_menu = new wxMenu;
915 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale S&et...\tCtrl-E");
916 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
917 view_menu->Append(IFMENU_VIEW_SCALE_FULL, "Display F&ull Scale\tCtrl-U");
919 m_pFilterMenu = new wxMenu;
920 m_pFilterMenu->Append (IFMENU_FILTER_INVERTVALUES, "In&vert Values");
921 m_pFilterMenu->Append (IFMENU_FILTER_SQUARE, "&Square");
922 m_pFilterMenu->Append (IFMENU_FILTER_SQRT, "Square &Root");
923 m_pFilterMenu->Append (IFMENU_FILTER_LOG, "&Log");
924 m_pFilterMenu->Append (IFMENU_FILTER_EXP, "E&xp");
925 m_pFilterMenu->AppendSeparator();
927 m_pFilterMenu->Append (IFMENU_FILTER_FFT, "2-D &FFT\tCtrl-2");
928 m_pFilterMenu->Append (IFMENU_FILTER_IFFT, "2-D &IFFT\tAlt-2");
929 m_pFilterMenu->Append (IFMENU_FILTER_FFT_ROWS, "FFT Rows");
930 m_pFilterMenu->Append (IFMENU_FILTER_IFFT_ROWS, "IFFT Rows");
931 m_pFilterMenu->Append (IFMENU_FILTER_FFT_COLS, "FFT Columns");
932 m_pFilterMenu->Append (IFMENU_FILTER_IFFT_COLS, "IFFT Columns");
933 m_pFilterMenu->Append (IFMENU_FILTER_FOURIER, "2-D F&ourier");
934 m_pFilterMenu->Append (IFMENU_FILTER_INVERSE_FOURIER, "2-D Inverse Fo&urier");
936 m_pFilterMenu->Append (IFMENU_FILTER_FOURIER, "&Fourier");
937 m_pFilterMenu->Append (IFMENU_FILTER_INVERSE_FOURIER, "&Inverse Fourier");
939 m_pFilterMenu->Append (IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, "Shuffl&e Fourier to Natural Order");
940 m_pFilterMenu->Append (IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, "Shuffle &Natural to Fourier Order");
941 m_pFilterMenu->AppendSeparator();
942 m_pFilterMenu->Append (IFMENU_FILTER_MAGNITUDE, "&Magnitude");
943 m_pFilterMenu->Append (IFMENU_FILTER_PHASE, "&Phase");
944 m_pFilterMenu->Append (IFMENU_FILTER_REAL, "Re&al");
945 m_pFilterMenu->Append (IFMENU_FILTER_IMAGINARY, "Ima&ginary");
947 wxMenu* image_menu = new wxMenu;
948 image_menu->Append (IFMENU_IMAGE_ADD, "&Add...");
949 image_menu->Append (IFMENU_IMAGE_SUBTRACT, "&Subtract...");
950 image_menu->Append (IFMENU_IMAGE_MULTIPLY, "&Multiply...");
951 image_menu->Append (IFMENU_IMAGE_DIVIDE, "&Divide...");
952 image_menu->AppendSeparator();
953 image_menu->Append (IFMENU_IMAGE_SCALESIZE, "S&cale Size...");
955 image_menu->Append (IFMENU_IMAGE_CONVERT3D, "Convert &3-D\tCtrl-3");
958 m_pMenuAnalyze = new wxMenu;
959 m_pMenuAnalyze->Append (IFMENU_PLOT_ROW, "Plot &Row");
960 m_pMenuAnalyze->Append (IFMENU_PLOT_COL, "Plot &Column");
961 m_pMenuAnalyze->Append (IFMENU_PLOT_HISTOGRAM, "Plot &Histogram");
962 m_pMenuAnalyze->AppendSeparator();
963 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_ROW, "P&lot FFT Row");
964 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_COL, "Plo&t FFT Column");
965 m_pMenuAnalyze->AppendSeparator();
966 m_pMenuAnalyze->Append (IFMENU_COMPARE_IMAGES, "Compare &Images...");
967 m_pMenuAnalyze->Append (IFMENU_COMPARE_ROW, "Compare Ro&w");
968 m_pMenuAnalyze->Append (IFMENU_COMPARE_COL, "Compare Colu&mn");
969 m_pMenuAnalyze->Enable (IFMENU_PLOT_ROW, false);
970 m_pMenuAnalyze->Enable (IFMENU_PLOT_COL, false);
971 m_pMenuAnalyze->Enable (IFMENU_COMPARE_ROW, false);
972 m_pMenuAnalyze->Enable (IFMENU_COMPARE_COL, false);
973 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_ROW, false);
974 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_COL, false);
976 wxMenu *help_menu = new wxMenu;
977 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
978 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
979 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
980 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
982 wxMenuBar *menu_bar = new wxMenuBar;
984 menu_bar->Append(m_pFileMenu, "&File");
985 menu_bar->Append(edit_menu, "&Edit");
986 menu_bar->Append(view_menu, "&View");
987 menu_bar->Append(image_menu, "&Image");
988 menu_bar->Append(m_pFilterMenu, "Fi<er");
989 menu_bar->Append(m_pMenuAnalyze, "&Analyze");
990 menu_bar->Append(help_menu, "&Help");
992 subframe->SetMenuBar(menu_bar);
994 subframe->Centre(wxBOTH);
996 wxAcceleratorEntry accelEntries[10];
997 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('A'), IFMENU_VIEW_SCALE_AUTO);
998 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('U'), IFMENU_VIEW_SCALE_FULL);
999 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('E'), IFMENU_VIEW_SCALE_MINMAX);
1000 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), IFMENU_FILE_PROPERTIES);
1001 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('C'), IFMENU_EDIT_COPY);
1002 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('X'), IFMENU_EDIT_CUT);
1003 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('V'), IFMENU_EDIT_PASTE);
1006 accelEntries[iEntry++].Set (wxACCEL_CTRL, static_cast<int>('2'), IFMENU_FILTER_FFT);
1007 accelEntries[iEntry++].Set (wxACCEL_ALT, static_cast<int>('2'), IFMENU_FILTER_IFFT);
1010 accelEntries[iEntry++].Set (wxACCEL_CTRL, static_cast<int>('3'), IFMENU_IMAGE_CONVERT3D);
1012 wxAcceleratorTable accelTable (iEntry, accelEntries);
1014 subframe->SetAcceleratorTable (accelTable);
1021 ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
1023 m_pFrame = CreateChildFrame(doc, this);
1025 m_bMinSpecified = false;
1026 m_bMaxSpecified = false;
1027 m_dAutoScaleFactor = 1.;
1029 // int width, height;
1030 // m_pFrame->GetClientSize (&width, &height);
1031 m_pFrame->SetTitle("ImageFileView");
1032 m_pCanvas = CreateCanvas (m_pFrame);
1034 // int x, y; // X requires a forced resize
1035 // m_pFrame->GetSize(&x, &y);
1036 // m_pFrame->SetSize(-1, -1, x, y);
1037 m_pFrame->SetFocus();
1038 m_pFrame->Show(true);
1045 ImageFileView::setInitialClientSize ()
1047 if (m_pFrame && m_pCanvas) {
1048 wxSize bestSize = m_pCanvas->GetBestSize();
1050 if (bestSize.x > 800)
1052 if (bestSize.y > 800)
1055 m_pFrame->SetClientSize (bestSize);
1056 m_pFrame->Show (true);
1057 m_pFrame->SetFocus();
1062 ImageFileView::OnDraw (wxDC* dc)
1065 dc->DrawBitmap(m_bitmap, 0, 0, false);
1067 int xCursor, yCursor;
1068 if (m_pCanvas->GetCurrentCursor (xCursor, yCursor))
1069 m_pCanvas->DrawRubberBandCursor (*dc, xCursor, yCursor);
1074 ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
1076 const ImageFile& rIF = GetDocument()->getImageFile();
1077 if (m_pFilterMenu && rIF.isComplex()) {
1078 m_pFilterMenu->Enable(IFMENU_FILTER_REAL, true);
1079 m_pFilterMenu->Enable(IFMENU_FILTER_IMAGINARY, true);
1080 m_pFilterMenu->Enable(IFMENU_FILTER_PHASE, true);
1082 m_pFilterMenu->Enable(IFMENU_FILTER_REAL, false);
1083 m_pFilterMenu->Enable(IFMENU_FILTER_IMAGINARY, false);
1084 m_pFilterMenu->Enable(IFMENU_FILTER_PHASE, false);
1086 ImageFileArrayConst v = rIF.getArray();
1089 if (v != NULL && nx != 0 && ny != 0) {
1090 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1092 rIF.getMinMax (min, max);
1093 if (! m_bMinSpecified)
1095 if (! m_bMaxSpecified)
1098 double scaleWidth = m_dMaxPixel - m_dMinPixel;
1100 unsigned char* imageData = new unsigned char [nx * ny * 3];
1102 sys_error (ERR_SEVERE, "Unable to allocate memory for Image display");
1105 for (int ix = 0; ix < nx; ix++) {
1106 for (int iy = 0; iy < ny; iy++) {
1107 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
1108 int intensity = static_cast<int>(scaleValue + 0.5);
1109 intensity = clamp (intensity, 0, 255);
1110 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
1111 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
1114 wxImage image (nx, ny, imageData, true);
1115 m_bitmap = image.ConvertToBitmap();
1117 m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20);
1118 m_pCanvas->SetBackgroundColour(*wxWHITE);
1122 m_pCanvas->Refresh();
1126 ImageFileView::OnClose (bool deleteWindow)
1128 //GetDocumentManager()->ActivateView (this, false, true);
1129 if (! GetDocument() || ! GetDocument()->Close())
1134 m_pCanvas->setView(NULL);
1137 wxString s(theApp->GetAppName());
1139 m_pFrame->SetTitle(s);
1146 if (GetDocument() && GetDocument()->getBadFileOpen())
1147 ::wxYield(); // wxWindows bug workaround
1154 ImageFileView::OnEditCopy (wxCommandEvent& event)
1156 wxBitmapDataObject *pBitmapObject = new wxBitmapDataObject;
1158 pBitmapObject->SetBitmap (m_bitmap);
1160 if (wxTheClipboard->Open()) {
1161 wxTheClipboard->SetData (pBitmapObject);
1162 wxTheClipboard->Close();
1167 ImageFileView::OnEditCut (wxCommandEvent& event)
1170 ImageFile& rIF = GetDocument()->getImageFile();
1173 ImageFile* pIF = new ImageFile (nx, ny);
1174 pIF->arrayDataClear();
1175 GetDocument()->setImageFile (pIF); // deletes old IF
1176 OnUpdate(this, NULL);
1177 GetDocument()->UpdateAllViews();
1178 if (theApp->getAskDeleteNewDocs())
1179 GetDocument()->Modify (true);
1183 ImageFileView::OnEditPaste (wxCommandEvent& event)
1185 ImageFile& rIF = GetDocument()->getImageFile();
1187 if (wxTheClipboard->Open()) {
1189 if (wxTheClipboard->IsSupported (wxDF_BITMAP)) {
1190 wxBitmapDataObject bitmapObject;
1191 wxTheClipboard->GetData (bitmapObject);
1192 bitmap = bitmapObject.GetBitmap ();
1194 wxTheClipboard->Close();
1198 bool bMonochrome = false;
1200 if (bitmap.Ok() == true && bitmap.GetWidth() == nx && bitmap.GetHeight() == ny) {
1201 wxImage image (bitmap);
1202 double dScale3 = 3 * 255;
1203 unsigned char* pixels = image.GetData();
1204 ImageFileArray v = rIF.getArray();
1205 for (unsigned int ix = 0; ix < rIF.nx(); ix++) {
1206 for (unsigned int iy = 0; iy < rIF.ny(); iy++) {
1207 unsigned int iBase = 3 * (iy * nx + ix);
1208 if (ix == 0 && iy == 0 && (pixels[iBase] == pixels[iBase+1] && pixels[iBase+1] == pixels[iBase+2]))
1211 v[ix][ny - 1 - iy] = (pixels[iBase]+pixels[iBase+1]+pixels[iBase+2]) / dScale3;
1213 double dR = pixels[iBase] / 255.;
1214 double dG = pixels[iBase+1] / 255.;
1215 double dB = pixels[iBase+2] / 255.;
1216 v[ix][ny - 1 - iy] = ImageFile::colorToGrayscale (dR, dG, dB);
1220 OnUpdate(this, NULL);
1221 GetDocument()->UpdateAllViews();
1222 if (theApp->getAskDeleteNewDocs())
1223 GetDocument()->Modify(true);
1229 ImageFileView::OnExport (wxCommandEvent& event)
1231 ImageFile& rIF = GetDocument()->getImageFile();
1232 ImageFileArrayConst v = rIF.getArray();
1235 if (v != NULL && nx != 0 && ny != 0) {
1236 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1238 rIF.getMinMax (min, max);
1239 if (! m_bMinSpecified)
1241 if (! m_bMaxSpecified)
1245 DialogExportParameters dialogExport (getFrameForChild(), m_iDefaultExportFormatID);
1246 if (dialogExport.ShowModal() == wxID_OK) {
1247 wxString strFormatName (dialogExport.getFormatName ());
1248 m_iDefaultExportFormatID = ImageFile::convertExportFormatNameToID (strFormatName.c_str());
1251 wxString strWildcard;
1252 if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PGM || m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PGMASCII) {
1254 strWildcard = "PGM Files (*.pgm)|*.pgm";
1257 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PNG || m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PNG16) {
1259 strWildcard = "PNG Files (*.png)|*.png";
1262 #ifdef HAVE_CTN_DICOM
1263 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_DICOM) {
1265 strWildcard = "DICOM Files (*.*)|*.*";
1268 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_TEXT) {
1270 strWildcard = "Text (*.txt)|*.txt";
1274 strWildcard = "Miscellaneous (*.*)|*.*";
1277 const wxString& strFilename = wxFileSelector (wxString("Export Filename"), wxString(""),
1278 wxString(""), strExt, strWildcard, wxOVERWRITE_PROMPT | wxHIDE_READONLY | wxSAVE);
1280 rIF.exportImage (strFormatName.c_str(), strFilename.c_str(), 1, 1, m_dMinPixel, m_dMaxPixel);
1281 *theApp->getLog() << "Exported file " << strFilename << "\n";
1288 ImageFileView::OnScaleSize (wxCommandEvent& event)
1290 ImageFile& rIF = GetDocument()->getImageFile();
1291 unsigned int iOldNX = rIF.nx();
1292 unsigned int iOldNY = rIF.ny();
1294 DialogGetXYSize dialogGetXYSize (getFrameForChild(), "Set New X & Y Dimensions", iOldNX, iOldNY);
1295 if (dialogGetXYSize.ShowModal() == wxID_OK) {
1296 unsigned int iNewNX = dialogGetXYSize.getXSize();
1297 unsigned int iNewNY = dialogGetXYSize.getYSize();
1298 std::ostringstream os;
1299 os << "Scale Size from (" << iOldNX << "," << iOldNY << ") to (" << iNewNX << "," << iNewNY << ")";
1300 ImageFileDocument* pScaledDoc = theApp->newImageDoc();
1302 sys_error (ERR_SEVERE, "Unable to create image file");
1305 ImageFile& rScaledIF = pScaledDoc->getImageFile();
1306 rScaledIF.setArraySize (iNewNX, iNewNY);
1307 rScaledIF.labelsCopy (rIF);
1308 rScaledIF.labelAdd (os.str().c_str());
1309 rIF.scaleImage (rScaledIF);
1310 *theApp->getLog() << os.str().c_str() << "\n";
1311 if (theApp->getAskDeleteNewDocs())
1312 pScaledDoc->Modify (true);
1313 pScaledDoc->UpdateAllViews (this);
1314 pScaledDoc->getView()->setInitialClientSize();
1315 pScaledDoc->Activate();
1321 ImageFileView::OnConvert3d (wxCommandEvent& event)
1323 ImageFile& rIF = GetDocument()->getImageFile();
1324 Graph3dFileDocument* pGraph3d = theApp->newGraph3dDoc();
1325 pGraph3d->setBadFileOpen();
1326 pGraph3d->createFromImageFile (rIF);
1327 pGraph3d->getView()->OnUpdate (this, NULL);
1328 pGraph3d->UpdateAllViews();
1329 pGraph3d->getView()->getFrame()->SetClientSize (400, 400);
1330 pGraph3d->getView()->getFrame()->Show (true);
1331 GetDocumentManager()->ActivateView (pGraph3d->getView(), true, false);
1333 pGraph3d->getView()->getCanvas()->SetFocus();
1338 ImageFileView::OnPlotRow (wxCommandEvent& event)
1340 int xCursor, yCursor;
1341 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1342 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1346 const ImageFile& rIF = GetDocument()->getImageFile();
1347 ImageFileArrayConst v = rIF.getArray();
1348 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1352 if (v != NULL && yCursor < ny) {
1353 double* pX = new double [nx];
1354 double* pYReal = new double [nx];
1355 double *pYImag = NULL;
1356 double *pYMag = NULL;
1357 if (rIF.isComplex()) {
1358 pYImag = new double [nx];
1359 pYMag = new double [nx];
1361 for (int i = 0; i < nx; i++) {
1363 pYReal[i] = v[i][yCursor];
1364 if (rIF.isComplex()) {
1365 pYImag[i] = vImag[i][yCursor];
1366 pYMag[i] = ::sqrt (v[i][yCursor] * v[i][yCursor] + vImag[i][yCursor] * vImag[i][yCursor]);
1369 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1371 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1373 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1374 std::ostringstream os;
1375 os << "Row " << yCursor;
1376 std::string title("title ");
1378 rPlotFile.addEzsetCommand (title.c_str());
1379 rPlotFile.addEzsetCommand ("xlabel Column");
1380 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1381 rPlotFile.addEzsetCommand ("lxfrac 0");
1382 rPlotFile.addEzsetCommand ("box");
1383 rPlotFile.addEzsetCommand ("grid");
1384 rPlotFile.addEzsetCommand ("curve 1");
1385 rPlotFile.addEzsetCommand ("color 1");
1386 if (rIF.isComplex()) {
1387 rPlotFile.addEzsetCommand ("dash 1");
1388 rPlotFile.addEzsetCommand ("curve 2");
1389 rPlotFile.addEzsetCommand ("color 4");
1390 rPlotFile.addEzsetCommand ("dash 3");
1391 rPlotFile.addEzsetCommand ("curve 3");
1392 rPlotFile.addEzsetCommand ("color 0");
1393 rPlotFile.addEzsetCommand ("solid");
1394 rPlotFile.setCurveSize (4, nx);
1396 rPlotFile.setCurveSize (2, nx);
1397 rPlotFile.addColumn (0, pX);
1398 rPlotFile.addColumn (1, pYReal);
1399 if (rIF.isComplex()) {
1400 rPlotFile.addColumn (2, pYImag);
1401 rPlotFile.addColumn (3, pYMag);
1403 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1404 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1405 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1406 *theApp->getLog() << os.str().c_str() << "\n";
1407 rPlotFile.addDescription (os.str().c_str());
1411 if (rIF.isComplex()) {
1415 if (theApp->getAskDeleteNewDocs())
1416 pPlotDoc->Modify (true);
1417 pPlotDoc->getView()->getFrame()->Show(true);
1418 pPlotDoc->UpdateAllViews ();
1419 pPlotDoc->Activate();
1424 ImageFileView::OnPlotCol (wxCommandEvent& event)
1426 int xCursor, yCursor;
1427 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1428 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1432 const ImageFile& rIF = GetDocument()->getImageFile();
1433 ImageFileArrayConst v = rIF.getArray();
1434 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1438 if (v != NULL && xCursor < nx) {
1439 double* pX = new double [ny];
1440 double* pYReal = new double [ny];
1441 double* pYImag = NULL;
1442 double* pYMag = NULL;
1443 if (rIF.isComplex()) {
1444 pYImag = new double [ny];
1445 pYMag = new double [ny];
1447 for (int i = 0; i < ny; i++) {
1449 pYReal[i] = v[xCursor][i];
1450 if (rIF.isComplex()) {
1451 pYImag[i] = vImag[xCursor][i];
1452 pYMag[i] = ::sqrt (v[xCursor][i] * v[xCursor][i] + vImag[xCursor][i] * vImag[xCursor][i]);
1455 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1457 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1459 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1460 std::ostringstream os;
1461 os << "Column " << xCursor;
1462 std::string title("title ");
1464 rPlotFile.addEzsetCommand (title.c_str());
1465 rPlotFile.addEzsetCommand ("xlabel Row");
1466 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1467 rPlotFile.addEzsetCommand ("lxfrac 0");
1468 rPlotFile.addEzsetCommand ("box");
1469 rPlotFile.addEzsetCommand ("grid");
1470 rPlotFile.addEzsetCommand ("curve 1");
1471 rPlotFile.addEzsetCommand ("color 1");
1472 if (rIF.isComplex()) {
1473 rPlotFile.addEzsetCommand ("dash 1");
1474 rPlotFile.addEzsetCommand ("curve 2");
1475 rPlotFile.addEzsetCommand ("color 4");
1476 rPlotFile.addEzsetCommand ("dash 3");
1477 rPlotFile.addEzsetCommand ("curve 3");
1478 rPlotFile.addEzsetCommand ("color 0");
1479 rPlotFile.addEzsetCommand ("solid");
1480 rPlotFile.setCurveSize (4, ny);
1482 rPlotFile.setCurveSize (2, ny);
1483 rPlotFile.addColumn (0, pX);
1484 rPlotFile.addColumn (1, pYReal);
1485 if (rIF.isComplex()) {
1486 rPlotFile.addColumn (2, pYImag);
1487 rPlotFile.addColumn (3, pYMag);
1489 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1490 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1491 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1492 *theApp->getLog() << os.str().c_str() << "\n";
1493 rPlotFile.addDescription (os.str().c_str());
1497 if (rIF.isComplex()) {
1501 if (theApp->getAskDeleteNewDocs())
1502 pPlotDoc->Modify (true);
1503 pPlotDoc->getView()->getFrame()->Show(true);
1504 pPlotDoc->UpdateAllViews ();
1505 pPlotDoc->Activate();
1511 ImageFileView::OnPlotFFTRow (wxCommandEvent& event)
1513 int xCursor, yCursor;
1514 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1515 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1519 const ImageFile& rIF = GetDocument()->getImageFile();
1520 ImageFileArrayConst v = rIF.getArray();
1521 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1525 if (v != NULL && yCursor < ny) {
1526 fftw_complex* pcIn = new fftw_complex [nx];
1529 for (i = 0; i < nx; i++) {
1530 pcIn[i].re = v[i][yCursor];
1531 if (rIF.isComplex())
1532 pcIn[i].im = vImag[i][yCursor];
1537 fftw_plan plan = fftw_create_plan (nx, FFTW_FORWARD, FFTW_IN_PLACE | FFTW_ESTIMATE | FFTW_USE_WISDOM);
1538 fftw_one (plan, pcIn, NULL);
1539 fftw_destroy_plan (plan);
1541 double* pX = new double [nx];
1542 double* pYReal = new double [nx];
1543 double* pYImag = new double [nx];
1544 double* pYMag = new double [nx];
1545 for (i = 0; i < nx; i++) {
1547 pYReal[i] = pcIn[i].re / nx;
1548 pYImag[i] = pcIn[i].im / nx;
1549 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1551 Fourier::shuffleFourierToNaturalOrder (pYReal, nx);
1552 Fourier::shuffleFourierToNaturalOrder (pYImag, nx);
1553 Fourier::shuffleFourierToNaturalOrder (pYMag, nx);
1555 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1557 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1559 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1560 std::ostringstream os;
1561 os << "Row " << yCursor;
1562 std::string title("title ");
1564 rPlotFile.addEzsetCommand (title.c_str());
1565 rPlotFile.addEzsetCommand ("xlabel Column");
1566 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1567 rPlotFile.addEzsetCommand ("lxfrac 0");
1568 rPlotFile.addEzsetCommand ("curve 1");
1569 rPlotFile.addEzsetCommand ("color 1");
1570 rPlotFile.addEzsetCommand ("dash 1");
1571 rPlotFile.addEzsetCommand ("curve 2");
1572 rPlotFile.addEzsetCommand ("color 4");
1573 rPlotFile.addEzsetCommand ("dash 3");
1574 rPlotFile.addEzsetCommand ("curve 3");
1575 rPlotFile.addEzsetCommand ("color 0");
1576 rPlotFile.addEzsetCommand ("solid");
1577 rPlotFile.addEzsetCommand ("box");
1578 rPlotFile.addEzsetCommand ("grid");
1579 rPlotFile.setCurveSize (4, nx);
1580 rPlotFile.addColumn (0, pX);
1581 rPlotFile.addColumn (1, pYReal);
1582 rPlotFile.addColumn (2, pYImag);
1583 rPlotFile.addColumn (3, pYMag);
1584 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1585 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1586 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1587 *theApp->getLog() << os.str().c_str() << "\n";
1588 rPlotFile.addDescription (os.str().c_str());
1596 if (theApp->getAskDeleteNewDocs())
1597 pPlotDoc->Modify (true);
1598 pPlotDoc->getView()->getFrame()->Show(true);
1599 pPlotDoc->UpdateAllViews ();
1600 pPlotDoc->Activate();
1605 ImageFileView::OnPlotFFTCol (wxCommandEvent& event)
1607 int xCursor, yCursor;
1608 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1609 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1613 const ImageFile& rIF = GetDocument()->getImageFile();
1614 ImageFileArrayConst v = rIF.getArray();
1615 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1619 if (v != NULL && xCursor < nx) {
1620 fftw_complex* pcIn = new fftw_complex [ny];
1621 double *pdTemp = new double [ny];
1624 for (i = 0; i < ny; i++)
1625 pdTemp[i] = v[xCursor][i];
1626 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1627 for (i = 0; i < ny; i++)
1628 pcIn[i].re = pdTemp[i];
1630 for (i = 0; i < ny; i++) {
1631 if (rIF.isComplex())
1632 pdTemp[i] = vImag[xCursor][i];
1636 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1637 for (i = 0; i < ny; i++)
1638 pcIn[i].im = pdTemp[i];
1640 fftw_plan plan = fftw_create_plan (ny, FFTW_BACKWARD, FFTW_IN_PLACE | FFTW_ESTIMATE | FFTW_USE_WISDOM);
1641 fftw_one (plan, pcIn, NULL);
1642 fftw_destroy_plan (plan);
1644 double* pX = new double [ny];
1645 double* pYReal = new double [ny];
1646 double* pYImag = new double [ny];
1647 double* pYMag = new double [ny];
1648 for (i = 0; i < ny; i++) {
1650 pYReal[i] = pcIn[i].re / ny;
1651 pYImag[i] = pcIn[i].im / ny;
1652 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1655 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1657 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1659 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1660 std::ostringstream os;
1661 os << "Column " << xCursor;
1662 std::string title("title ");
1664 rPlotFile.addEzsetCommand (title.c_str());
1665 rPlotFile.addEzsetCommand ("xlabel Column");
1666 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1667 rPlotFile.addEzsetCommand ("lxfrac 0");
1668 rPlotFile.addEzsetCommand ("curve 1");
1669 rPlotFile.addEzsetCommand ("color 1");
1670 rPlotFile.addEzsetCommand ("dash 1");
1671 rPlotFile.addEzsetCommand ("curve 2");
1672 rPlotFile.addEzsetCommand ("color 4");
1673 rPlotFile.addEzsetCommand ("dash 3");
1674 rPlotFile.addEzsetCommand ("curve 3");
1675 rPlotFile.addEzsetCommand ("color 0");
1676 rPlotFile.addEzsetCommand ("solid");
1677 rPlotFile.addEzsetCommand ("box");
1678 rPlotFile.addEzsetCommand ("grid");
1679 rPlotFile.setCurveSize (4, ny);
1680 rPlotFile.addColumn (0, pX);
1681 rPlotFile.addColumn (1, pYReal);
1682 rPlotFile.addColumn (2, pYImag);
1683 rPlotFile.addColumn (3, pYMag);
1684 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1685 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1686 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1687 *theApp->getLog() << os.str().c_str() << "\n";
1688 rPlotFile.addDescription (os.str().c_str());
1697 if (theApp->getAskDeleteNewDocs())
1698 pPlotDoc->Modify (true);
1699 pPlotDoc->getView()->getFrame()->Show(true);
1700 pPlotDoc->UpdateAllViews ();
1701 pPlotDoc->Activate();
1707 ImageFileView::OnCompareCol (wxCommandEvent& event)
1709 int xCursor, yCursor;
1710 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1711 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1715 std::vector<ImageFileDocument*> vecIFDoc;
1716 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1717 if (vecIFDoc.size() == 0) {
1718 wxMessageBox ("No compatible images for Column Comparison", "Error");
1721 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1723 if (dialogGetCompare.ShowModal() == wxID_OK) {
1724 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1725 const ImageFile& rIF = GetDocument()->getImageFile();
1726 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1728 ImageFileArrayConst v1 = rIF.getArray();
1729 ImageFileArrayConst v2 = rCompareIF.getArray();
1733 if (v1 != NULL && xCursor < nx) {
1734 double* pX = new double [ny];
1735 double* pY1 = new double [ny];
1736 double* pY2 = new double [ny];
1737 for (int i = 0; i < ny; i++) {
1739 pY1[i] = v1[xCursor][i];
1740 pY2[i] = v2[xCursor][i];
1742 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1744 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1746 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1747 std::ostringstream os;
1748 os << "Column " << xCursor << " Comparison";
1749 std::string title("title ");
1751 rPlotFile.addEzsetCommand (title.c_str());
1752 rPlotFile.addEzsetCommand ("xlabel Row");
1753 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1754 rPlotFile.addEzsetCommand ("lxfrac 0");
1755 rPlotFile.addEzsetCommand ("curve 1");
1756 rPlotFile.addEzsetCommand ("color 2");
1757 rPlotFile.addEzsetCommand ("curve 2");
1758 rPlotFile.addEzsetCommand ("color 4");
1759 rPlotFile.addEzsetCommand ("dash 5");
1760 rPlotFile.addEzsetCommand ("box");
1761 rPlotFile.addEzsetCommand ("grid");
1762 rPlotFile.setCurveSize (3, ny);
1763 rPlotFile.addColumn (0, pX);
1764 rPlotFile.addColumn (1, pY1);
1765 rPlotFile.addColumn (2, pY2);
1768 for (iL = 0; iL < rIF.nLabels(); iL++) {
1769 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1771 s += rIF.labelGet(iL).getLabelString();
1772 rPlotFile.addDescription (s.c_str());
1774 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1775 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1777 s += rCompareIF.labelGet(iL).getLabelString();
1778 rPlotFile.addDescription (s.c_str());
1780 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1781 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1782 *theApp->getLog() << os.str().c_str() << "\n";
1783 rPlotFile.addDescription (os.str().c_str());
1788 if (theApp->getAskDeleteNewDocs())
1789 pPlotDoc->Modify (true);
1790 pPlotDoc->getView()->getFrame()->Show(true);
1791 pPlotDoc->UpdateAllViews ();
1792 pPlotDoc->Activate();
1798 ImageFileView::OnCompareRow (wxCommandEvent& event)
1800 int xCursor, yCursor;
1801 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1802 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1806 std::vector<ImageFileDocument*> vecIFDoc;
1807 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1809 if (vecIFDoc.size() == 0) {
1810 wxMessageBox ("No compatible images for Row Comparison", "Error");
1814 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1816 if (dialogGetCompare.ShowModal() == wxID_OK) {
1817 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1818 const ImageFile& rIF = GetDocument()->getImageFile();
1819 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1821 ImageFileArrayConst v1 = rIF.getArray();
1822 ImageFileArrayConst v2 = rCompareIF.getArray();
1826 if (v1 != NULL && yCursor < ny) {
1827 double* pX = new double [nx];
1828 double* pY1 = new double [nx];
1829 double* pY2 = new double [nx];
1830 for (int i = 0; i < nx; i++) {
1832 pY1[i] = v1[i][yCursor];
1833 pY2[i] = v2[i][yCursor];
1835 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1837 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1839 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1840 std::ostringstream os;
1841 os << "Row " << yCursor << " Comparison";
1842 std::string title("title ");
1844 rPlotFile.addEzsetCommand (title.c_str());
1845 rPlotFile.addEzsetCommand ("xlabel Column");
1846 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1847 rPlotFile.addEzsetCommand ("lxfrac 0");
1848 rPlotFile.addEzsetCommand ("curve 1");
1849 rPlotFile.addEzsetCommand ("color 2");
1850 rPlotFile.addEzsetCommand ("curve 2");
1851 rPlotFile.addEzsetCommand ("color 4");
1852 rPlotFile.addEzsetCommand ("dash 5");
1853 rPlotFile.addEzsetCommand ("box");
1854 rPlotFile.addEzsetCommand ("grid");
1855 rPlotFile.setCurveSize (3, nx);
1856 rPlotFile.addColumn (0, pX);
1857 rPlotFile.addColumn (1, pY1);
1858 rPlotFile.addColumn (2, pY2);
1860 for (iL = 0; iL < rIF.nLabels(); iL++) {
1861 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1863 s += rIF.labelGet(iL).getLabelString();
1864 rPlotFile.addDescription (s.c_str());
1866 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1867 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1869 s += rCompareIF.labelGet(iL).getLabelString();
1870 rPlotFile.addDescription (s.c_str());
1872 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1873 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1874 *theApp->getLog() << os.str().c_str() << "\n";
1875 rPlotFile.addDescription (os.str().c_str());
1880 if (theApp->getAskDeleteNewDocs())
1881 pPlotDoc->Modify (true);
1882 pPlotDoc->getView()->getFrame()->Show(true);
1883 pPlotDoc->UpdateAllViews ();
1884 pPlotDoc->Activate();
1889 static int NUMBER_HISTOGRAM_BINS = 256;
1892 ImageFileView::OnPlotHistogram (wxCommandEvent& event)
1894 const ImageFile& rIF = GetDocument()->getImageFile();
1895 ImageFileArrayConst v = rIF.getArray();
1899 if (v != NULL && nx > 0 && ny > 0) {
1900 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1902 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1906 double* pX = new double [NUMBER_HISTOGRAM_BINS];
1907 double* pY = new double [NUMBER_HISTOGRAM_BINS];
1909 rIF.getMinMax (dMin, dMax);
1910 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
1912 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
1913 pX[i] = dMin + (i + 0.5) * dBinWidth;
1916 for (int ix = 0; ix < nx; ix++)
1917 for (int iy = 0; iy < ny; iy++) {
1918 int iBin = nearest<int> ((v[ix][iy] - dMin) / dBinWidth);
1919 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
1923 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1924 std::ostringstream os;
1926 std::string title("title ");
1928 rPlotFile.addEzsetCommand (title.c_str());
1929 rPlotFile.addEzsetCommand ("xlabel Pixel Value");
1930 rPlotFile.addEzsetCommand ("ylabel Count");
1931 rPlotFile.addEzsetCommand ("box");
1932 rPlotFile.addEzsetCommand ("grid");
1933 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
1934 rPlotFile.addColumn (0, pX);
1935 rPlotFile.addColumn (1, pY);
1936 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++) {
1937 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1939 s += rIF.labelGet(iL).getLabelString();
1940 rPlotFile.addDescription (s.c_str());
1942 os << " plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1943 *theApp->getLog() << os.str().c_str() << "\n";
1944 rPlotFile.addDescription (os.str().c_str());
1947 if (theApp->getAskDeleteNewDocs())
1948 pPlotDoc->Modify (true);
1949 pPlotDoc->getView()->getFrame()->Show(true);
1950 pPlotDoc->UpdateAllViews ();
1951 pPlotDoc->Activate();
1958 PhantomCanvas::PhantomCanvas (PhantomFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1959 : wxScrolledWindow(frame, -1, pos, size, style)
1964 PhantomCanvas::~PhantomCanvas ()
1970 PhantomCanvas::OnDraw (wxDC& dc)
1973 m_pView->OnDraw(& dc);
1977 PhantomCanvas::GetBestSize() const
1983 theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
1984 xSize = maxValue<int> (xSize, ySize);
1986 ySize = xSize = (xSize / 4);
1990 return wxSize (xSize, ySize);
1997 IMPLEMENT_DYNAMIC_CLASS(PhantomFileView, wxView)
1999 BEGIN_EVENT_TABLE(PhantomFileView, wxView)
2000 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomFileView::OnProperties)
2001 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomFileView::OnRasterize)
2002 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomFileView::OnProjections)
2005 PhantomFileView::PhantomFileView()
2006 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0)
2008 #if defined(DEBUG) || defined(_DEBUG)
2009 m_iDefaultNDet = 165;
2010 m_iDefaultNView = 180;
2011 m_iDefaultNSample = 1;
2013 m_iDefaultNDet = 367;
2014 m_iDefaultNView = 320;
2015 m_iDefaultNSample = 2;
2017 m_iDefaultOffsetView = 0;
2018 m_dDefaultRotation = 1;
2019 m_dDefaultFocalLength = 2;
2020 m_dDefaultCenterDetectorLength = 2;
2021 m_dDefaultViewRatio = 1;
2022 m_dDefaultScanRatio = 1;
2023 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
2024 m_iDefaultTrace = Trace::TRACE_NONE;
2027 m_iDefaultRasterNX = 115;
2028 m_iDefaultRasterNY = 115;
2029 m_iDefaultRasterNSamples = 1;
2031 m_iDefaultRasterNX = 256;
2032 m_iDefaultRasterNY = 256;
2033 m_iDefaultRasterNSamples = 2;
2035 m_dDefaultRasterViewRatio = 1;
2038 PhantomFileView::~PhantomFileView()
2040 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2041 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
2045 PhantomFileView::OnProperties (wxCommandEvent& event)
2047 const int idPhantom = GetDocument()->getPhantomID();
2048 const wxString& namePhantom = GetDocument()->getPhantomName();
2049 std::ostringstream os;
2050 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")" << "\n";
2051 const Phantom& rPhantom = GetDocument()->getPhantom();
2052 rPhantom.printDefinitions (os);
2054 rPhantom.print (os);
2056 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2057 wxMessageBox (os.str().c_str(), "Phantom Properties");
2058 GetDocument()->Activate();
2063 PhantomFileView::OnProjections (wxCommandEvent& event)
2065 DialogGetProjectionParameters dialogProjection (getFrameForChild(),
2066 m_iDefaultNDet, m_iDefaultNView, m_iDefaultOffsetView, m_iDefaultNSample, m_dDefaultRotation,
2067 m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio,
2068 m_iDefaultGeometry, m_iDefaultTrace);
2069 int retVal = dialogProjection.ShowModal();
2070 if (retVal != wxID_OK)
2073 m_iDefaultNDet = dialogProjection.getNDet();
2074 m_iDefaultNView = dialogProjection.getNView();
2075 m_iDefaultOffsetView = dialogProjection.getOffsetView();
2076 m_iDefaultNSample = dialogProjection.getNSamples();
2077 m_iDefaultTrace = dialogProjection.getTrace();
2078 m_dDefaultRotation = dialogProjection.getRotAngle();
2079 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
2080 m_dDefaultCenterDetectorLength = dialogProjection.getCenterDetectorLengthRatio();
2081 m_dDefaultViewRatio = dialogProjection.getViewRatio();
2082 m_dDefaultScanRatio = dialogProjection.getScanRatio();
2083 wxString sGeometry = dialogProjection.getGeometry();
2084 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
2085 double dRotationRadians = m_dDefaultRotation;
2086 m_dDefaultRotation /= TWOPI; // convert back to fraction of a circle
2088 if (m_iDefaultNDet <= 0 || m_iDefaultNView <= 0 || sGeometry == "")
2091 const Phantom& rPhantom = GetDocument()->getPhantom();
2092 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultOffsetView, m_iDefaultNSample,
2093 dRotationRadians, m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio);
2094 if (theScanner.fail()) {
2095 wxString msg = "Failed making scanner\n";
2096 msg += theScanner.failMessage().c_str();
2097 *theApp->getLog() << msg << "\n";
2098 wxMessageBox (msg, "Error");
2102 std::ostringstream os;
2103 os << "Projections for " << rPhantom.name()
2104 << ": nDet=" << m_iDefaultNDet
2105 << ", nView=" << m_iDefaultNView
2106 << ", gantry offset=" << m_iDefaultOffsetView
2107 << ", nSamples=" << m_iDefaultNSample
2108 << ", RotAngle=" << m_dDefaultRotation
2109 << ", FocalLengthRatio=" << m_dDefaultFocalLength
2110 << ", CenterDetectorLengthRatio=" << m_dDefaultCenterDetectorLength
2111 << ", ViewRatio=" << m_dDefaultViewRatio
2112 << ", ScanRatio=" << m_dDefaultScanRatio
2113 << ", Geometry=" << sGeometry.c_str()
2114 << ", FanBeamAngle=" << convertRadiansToDegrees (theScanner.fanBeamAngle());
2117 Projections* pProj = NULL;
2118 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2119 pProj = new Projections;
2120 pProj->initFromScanner (theScanner);
2122 ProjectionsDialog dialogProjections (theScanner, *pProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(getFrameForChild()));
2123 for (int iView = 0; iView < pProj->nView(); iView++) {
2125 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
2130 while (dialogProjections.isPaused()) {
2137 if (theApp->getUseBackgroundTasks()) {
2138 ProjectorSupervisorThread* pProjector = new ProjectorSupervisorThread (this, m_iDefaultNDet,
2139 m_iDefaultNView, m_iDefaultOffsetView, sGeometry.c_str(), m_iDefaultNSample, dRotationRadians,
2140 m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio, os.str().c_str());
2141 if (pProjector->Create() != wxTHREAD_NO_ERROR) {
2142 sys_error (ERR_SEVERE, "Error creating projector thread");
2146 pProjector->SetPriority(60);
2150 #endif // HAVE_WXTHREADS
2152 pProj = new Projections;
2153 pProj->initFromScanner (theScanner);
2154 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), pProj->nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2155 for (int i = 0; i < pProj->nView(); i++) {
2156 //theScanner.collectProjections (*pProj, rPhantom, i, 1, true, m_iDefaultTrace);
2157 theScanner.collectProjections (*pProj, rPhantom, i, 1, theScanner.offsetView(), true, m_iDefaultTrace);
2158 if (! dlgProgress.Update (i+1)) {
2166 *theApp->getLog() << os.str().c_str() << "\n";
2167 pProj->setRemark (os.str());
2168 pProj->setCalcTime (timer.timerEnd());
2170 ProjectionFileDocument* pProjectionDoc = theApp->newProjectionDoc();
2171 if (! pProjectionDoc) {
2172 sys_error (ERR_SEVERE, "Unable to create projection document");
2175 pProjectionDoc->setProjections (pProj);
2176 ProjectionFileView* projView = pProjectionDoc->getView();
2178 projView->OnUpdate (projView, NULL);
2179 if (projView->getCanvas())
2180 projView->getCanvas()->SetClientSize (m_iDefaultNDet, m_iDefaultNView);
2181 if (wxFrame* pFrame = projView->getFrame()) {
2186 GetDocumentManager()->ActivateView (projView, true, false);
2188 if (theApp->getAskDeleteNewDocs())
2189 pProjectionDoc-> Modify(true);
2190 pProjectionDoc->UpdateAllViews (this);
2191 pProjectionDoc->getView()->setInitialClientSize();
2192 pProjectionDoc->Activate();
2197 PhantomFileView::OnRasterize (wxCommandEvent& event)
2199 DialogGetRasterParameters dialogRaster (getFrameForChild(), m_iDefaultRasterNX, m_iDefaultRasterNY,
2200 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio);
2201 int retVal = dialogRaster.ShowModal();
2202 if (retVal != wxID_OK)
2205 m_iDefaultRasterNX = dialogRaster.getXSize();
2206 m_iDefaultRasterNY = dialogRaster.getYSize();
2207 m_iDefaultRasterNSamples = dialogRaster.getNSamples();
2208 m_dDefaultRasterViewRatio = dialogRaster.getViewRatio();
2209 if (m_iDefaultRasterNSamples < 1)
2210 m_iDefaultRasterNSamples = 1;
2211 if (m_dDefaultRasterViewRatio < 0)
2212 m_dDefaultRasterViewRatio = 0;
2213 if (m_iDefaultRasterNX <= 0 || m_iDefaultRasterNY <= 0)
2216 const Phantom& rPhantom = GetDocument()->getPhantom();
2217 std::ostringstream os;
2218 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << m_iDefaultRasterNX << ", YSize="
2219 << m_iDefaultRasterNY << ", ViewRatio=" << m_dDefaultRasterViewRatio << ", nSamples="
2220 << m_iDefaultRasterNSamples;;
2223 if (theApp->getUseBackgroundTasks()) {
2224 RasterizerSupervisorThread* pThread = new RasterizerSupervisorThread (this, m_iDefaultRasterNX, m_iDefaultRasterNY,
2225 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio, os.str().c_str());
2226 if (pThread->Create() != wxTHREAD_NO_ERROR) {
2227 *theApp->getLog() << "Error creating rasterizer thread\n";
2230 pThread->SetPriority (60);
2235 ImageFile* pImageFile = new ImageFile (m_iDefaultRasterNX, m_iDefaultRasterNY);
2237 wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"),
2238 pImageFile->nx() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2240 for (unsigned int i = 0; i < pImageFile->nx(); i++) {
2241 rPhantom.convertToImagefile (*pImageFile, m_dDefaultRasterViewRatio, m_iDefaultRasterNSamples, Trace::TRACE_NONE, i, 1, true);
2242 if (! dlgProgress.Update (i+1)) {
2248 ImageFileDocument* pRasterDoc = theApp->newImageDoc();
2250 sys_error (ERR_SEVERE, "Unable to create image file");
2253 pRasterDoc->setImageFile (pImageFile);
2254 if (theApp->getAskDeleteNewDocs())
2255 pRasterDoc->Modify (true);
2256 *theApp->getLog() << os.str().c_str() << "\n";
2257 pImageFile->labelAdd (os.str().c_str(), timer.timerEnd());
2259 pRasterDoc->UpdateAllViews();
2260 pRasterDoc->getView()->setInitialClientSize();
2261 pRasterDoc->Activate();
2267 PhantomFileView::CreateCanvas (wxFrame *parent)
2269 PhantomCanvas* pCanvas;
2271 pCanvas = new PhantomCanvas (this, parent, wxPoint(0, 0), wxSize(0,0), 0);
2272 pCanvas->SetBackgroundColour(*wxWHITE);
2283 PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2286 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2288 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2290 theApp->setIconForFrame (subframe);
2292 m_pFileMenu = new wxMenu;
2294 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2295 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2296 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2297 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2298 m_pFileMenu->Append(wxID_CLOSE, "&Close");
2300 m_pFileMenu->AppendSeparator();
2301 m_pFileMenu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
2303 m_pFileMenu->AppendSeparator();
2304 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2305 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2306 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2307 m_pFileMenu->AppendSeparator();
2308 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
2310 m_pFileMenu->AppendSeparator();
2311 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
2312 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2314 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2315 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2317 wxMenu *process_menu = new wxMenu;
2318 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...\tCtrl-R");
2319 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...\tCtrl-J");
2321 wxMenu *help_menu = new wxMenu;
2322 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2323 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
2324 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
2325 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2327 wxMenuBar *menu_bar = new wxMenuBar;
2329 menu_bar->Append(m_pFileMenu, "&File");
2330 menu_bar->Append(process_menu, "&Process");
2331 menu_bar->Append(help_menu, "&Help");
2333 subframe->SetMenuBar(menu_bar);
2334 subframe->Centre(wxBOTH);
2336 wxAcceleratorEntry accelEntries[3];
2337 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('J'), PHMMENU_PROCESS_PROJECTIONS);
2338 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('R'), PHMMENU_PROCESS_RASTERIZE);
2339 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('I'), PHMMENU_FILE_PROPERTIES);
2340 wxAcceleratorTable accelTable (3, accelEntries);
2341 subframe->SetAcceleratorTable (accelTable);
2348 PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2350 m_pFrame = CreateChildFrame(doc, this);
2352 m_pCanvas = CreateCanvas (m_pFrame);
2353 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
2354 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
2355 m_pFrame->SetTitle ("PhantomFileView");
2357 m_pFrame->Show(true);
2364 PhantomFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2367 m_pCanvas->Refresh();
2371 PhantomFileView::OnClose (bool deleteWindow)
2373 //GetDocumentManager()->ActivateView (this, false, true);
2374 if (! GetDocument() || ! GetDocument()->Close())
2379 m_pCanvas->setView(NULL);
2382 wxString s(wxTheApp->GetAppName());
2384 m_pFrame->SetTitle(s);
2391 if (GetDocument() && GetDocument()->getBadFileOpen())
2392 ::wxYield(); // wxWindows bug workaround
2399 PhantomFileView::OnDraw (wxDC* dc)
2402 m_pCanvas->GetClientSize (&xsize, &ysize);
2403 SGPDriver driver (dc, xsize, ysize);
2405 const Phantom& rPhantom = GetDocument()->getPhantom();
2406 sgp.setColor (C_RED);
2407 rPhantom.show (sgp);
2412 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2413 : wxScrolledWindow(frame, -1, pos, size, style)
2418 ProjectionFileCanvas::~ProjectionFileCanvas ()
2424 ProjectionFileCanvas::OnDraw(wxDC& dc)
2427 m_pView->OnDraw(& dc);
2431 ProjectionFileCanvas::GetBestSize () const
2438 Projections& rProj = m_pView->GetDocument()->getProjections();
2439 best.Set (rProj.nDet(), rProj.nView());
2446 // ProjectionFileView
2448 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
2450 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
2451 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
2452 EVT_MENU(PJMENU_RECONSTRUCT_FBP, ProjectionFileView::OnReconstructFBP)
2453 EVT_MENU(PJMENU_RECONSTRUCT_FBP_REBIN, ProjectionFileView::OnReconstructFBPRebin)
2454 EVT_MENU(PJMENU_RECONSTRUCT_FOURIER, ProjectionFileView::OnReconstructFourier)
2455 EVT_MENU(PJMENU_CONVERT_RECTANGULAR, ProjectionFileView::OnConvertRectangular)
2456 EVT_MENU(PJMENU_CONVERT_POLAR, ProjectionFileView::OnConvertPolar)
2457 EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
2458 EVT_MENU(PJMENU_CONVERT_PARALLEL, ProjectionFileView::OnConvertParallel)
2459 EVT_MENU(PJMENU_PLOT_TTHETA_SAMPLING, ProjectionFileView::OnPlotTThetaSampling)
2460 EVT_MENU(PJMENU_PLOT_HISTOGRAM, ProjectionFileView::OnPlotHistogram)
2461 // EVT_MENU(PJMENU_ARTIFACT_REDUCTION, ProjectionFileView::OnArtifactReduction)
2465 ProjectionFileView::ProjectionFileView()
2466 : wxView(), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0)
2476 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
2477 m_dDefaultFilterParam = 1.;
2479 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
2480 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
2482 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
2483 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
2485 m_iDefaultZeropad = 1;
2486 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF;
2487 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
2488 m_iDefaultInterpParam = 1;
2489 m_iDefaultTrace = Trace::TRACE_NONE;
2491 m_iDefaultPolarNX = 256;
2492 m_iDefaultPolarNY = 256;
2493 m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR;
2494 m_iDefaultPolarZeropad = 1;
2497 ProjectionFileView::~ProjectionFileView()
2499 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2500 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2504 ProjectionFileView::OnProperties (wxCommandEvent& event)
2506 const Projections& rProj = GetDocument()->getProjections();
2507 std::ostringstream os;
2508 rProj.printScanInfo(os);
2509 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2510 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
2511 dialogMsg.ShowModal();
2512 GetDocument()->Activate();
2517 ProjectionFileView::OnConvertRectangular (wxCommandEvent& event)
2519 Projections& rProj = GetDocument()->getProjections();
2521 int nDet = rProj.nDet();
2522 int nView = rProj.nView();
2523 ImageFile* pIF = new ImageFile (nDet, nView);
2524 ImageFileArray v = pIF->getArray();
2525 for (int iv = 0; iv < nView; iv++) {
2526 DetectorValue* detval = rProj.getDetectorArray(iv).detValues();
2528 for (int id = 0; id < nDet; id++)
2529 v[id][iv] = detval[id];
2532 ImageFileDocument* pRectDoc = theApp->newImageDoc ();
2534 sys_error (ERR_SEVERE, "Unable to create image file");
2537 pRectDoc->setImageFile (pIF);
2538 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2539 std::ostringstream os;
2540 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to rectangular image";
2541 *theApp->getLog() << os.str().c_str() << "\n";
2542 pIF->labelAdd (os.str().c_str());
2543 if (theApp->getAskDeleteNewDocs())
2544 pRectDoc->Modify (true);
2545 pRectDoc->getView()->setInitialClientSize();
2546 pRectDoc->Activate();
2550 ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
2552 Projections& rProj = GetDocument()->getProjections();
2553 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2554 m_iDefaultPolarInterpolation, -1, IDH_DLG_POLAR);
2555 if (dialogPolar.ShowModal() == wxID_OK) {
2556 wxProgressDialog dlgProgress (wxString("Convert Polar"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2557 wxString strInterpolation (dialogPolar.getInterpolationName());
2558 m_iDefaultPolarNX = dialogPolar.getXSize();
2559 m_iDefaultPolarNY = dialogPolar.getYSize();
2560 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2561 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2562 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2564 if (! rProj.convertPolar (*pIF, m_iDefaultPolarInterpolation)) {
2566 *theApp->getLog() << "Error converting to Polar\n";
2570 pPolarDoc = theApp->newImageDoc ();
2572 sys_error (ERR_SEVERE, "Unable to create image file");
2575 pPolarDoc->setImageFile (pIF);
2576 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2577 std::ostringstream os;
2578 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to polar image: xSize="
2579 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2580 << strInterpolation.c_str();
2581 *theApp->getLog() << os.str().c_str() << "\n";
2582 pIF->labelAdd (os.str().c_str());
2583 if (theApp->getAskDeleteNewDocs())
2584 pPolarDoc->Modify (true);
2585 pPolarDoc->UpdateAllViews ();
2586 pPolarDoc->getView()->setInitialClientSize();
2587 pPolarDoc->Activate();
2592 ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
2594 Projections& rProj = GetDocument()->getProjections();
2595 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert to FFT Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2596 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad, IDH_DLG_FFT_POLAR);
2597 if (dialogPolar.ShowModal() == wxID_OK) {
2598 wxProgressDialog dlgProgress (wxString("Convert FFT Polar"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2599 wxString strInterpolation (dialogPolar.getInterpolationName());
2600 m_iDefaultPolarNX = dialogPolar.getXSize();
2601 m_iDefaultPolarNY = dialogPolar.getYSize();
2602 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2603 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2605 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2606 if (! rProj.convertFFTPolar (*pIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad)) {
2608 *theApp->getLog() << "Error converting to polar\n";
2611 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2613 sys_error (ERR_SEVERE, "Unable to create image file");
2616 pPolarDoc->setImageFile (pIF);
2617 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2618 std::ostringstream os;
2619 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to FFT polar image: xSize="
2620 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2621 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2622 *theApp->getLog() << os.str().c_str() << "\n";
2623 pIF->labelAdd (os.str().c_str());
2624 if (theApp->getAskDeleteNewDocs())
2625 pPolarDoc->Modify (true);
2626 pPolarDoc->UpdateAllViews ();
2627 pPolarDoc->getView()->setInitialClientSize();
2628 pPolarDoc->Activate();
2633 ProjectionFileView::OnPlotTThetaSampling (wxCommandEvent& event)
2635 DialogGetThetaRange dlgTheta (this->getFrame(), ParallelRaysums::THETA_RANGE_UNCONSTRAINED);
2636 if (dlgTheta.ShowModal() != wxID_OK)
2639 int iThetaRange = dlgTheta.getThetaRange();
2641 Projections& rProj = GetDocument()->getProjections();
2642 ParallelRaysums parallel (&rProj, iThetaRange);
2643 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
2644 PlotFile& rPlot = pPlotDoc->getPlotFile();
2645 ParallelRaysums::CoordinateContainer& coordContainer = parallel.getCoordinates();
2646 double* pdT = new double [parallel.getNumCoordinates()];
2647 double* pdTheta = new double [parallel.getNumCoordinates()];
2649 for (int i = 0; i < parallel.getNumCoordinates(); i++) {
2650 pdT[i] = coordContainer[i]->m_dT;
2651 pdTheta[i] = coordContainer[i]->m_dTheta;
2653 rPlot.setCurveSize (2, parallel.getNumCoordinates(), true);
2654 rPlot.addEzsetCommand ("title T-Theta Sampling");
2655 rPlot.addEzsetCommand ("xlabel T");
2656 rPlot.addEzsetCommand ("ylabel Theta");
2657 rPlot.addEzsetCommand ("curve 1");
2658 if (rProj.nDet() < 50 && rProj.nView() < 50)
2659 rPlot.addEzsetCommand ("symbol 1"); // x symbol
2661 rPlot.addEzsetCommand ("symbol 6"); // point symbol
2662 rPlot.addEzsetCommand ("noline");
2663 rPlot.addColumn (0, pdT);
2664 rPlot.addColumn (1, pdTheta);
2667 if (theApp->getAskDeleteNewDocs())
2668 pPlotDoc->Modify (true);
2669 pPlotDoc->getView()->getFrame()->Show(true);
2670 pPlotDoc->UpdateAllViews ();
2671 pPlotDoc->Activate();
2676 ProjectionFileView::OnPlotHistogram (wxCommandEvent& event)
2678 Projections& rProj = GetDocument()->getProjections();
2679 int nDet = rProj.nDet();
2680 int nView = rProj.nView();
2682 if (nDet < 1 || nView < 1)
2685 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
2687 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
2691 DetectorValue* pdDetval = rProj.getDetectorArray(0).detValues();
2692 double dMin = pdDetval[0], dMax = pdDetval[0];
2694 for (int iv = 0; iv < nView; iv++) {
2695 pdDetval = rProj.getDetectorArray(iv).detValues();
2696 for (int id = 0; id < nDet; id++) {
2697 double dV = pdDetval[id];
2705 double* pX = new double [NUMBER_HISTOGRAM_BINS];
2706 double* pY = new double [NUMBER_HISTOGRAM_BINS];
2707 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
2709 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
2710 pX[i] = dMin + (i + 0.5) * dBinWidth;
2713 for (int j = 0; j < nView; j++) {
2714 pdDetval = rProj.getDetectorArray(j).detValues();
2715 for (int id = 0; id < nDet; id++) {
2716 int iBin = nearest<int> ((pdDetval[id] - dMin) / dBinWidth);
2717 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
2721 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
2722 std::ostringstream os;
2724 std::string title("title ");
2726 rPlotFile.addEzsetCommand (title.c_str());
2727 rPlotFile.addEzsetCommand ("xlabel Detector Value");
2728 rPlotFile.addEzsetCommand ("ylabel Count");
2729 rPlotFile.addEzsetCommand ("box");
2730 rPlotFile.addEzsetCommand ("grid");
2731 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
2732 rPlotFile.addColumn (0, pX);
2733 rPlotFile.addColumn (1, pY);
2734 rPlotFile.addDescription (rProj.remark());
2735 os << " plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
2736 *theApp->getLog() << os.str().c_str() << "\n";
2737 rPlotFile.addDescription (os.str().c_str());
2740 if (theApp->getAskDeleteNewDocs())
2741 pPlotDoc->Modify (true);
2742 pPlotDoc->getView()->getFrame()->Show(true);
2743 pPlotDoc->UpdateAllViews ();
2744 pPlotDoc->Activate();
2749 ProjectionFileView::OnConvertParallel (wxCommandEvent& event)
2751 Projections& rProj = GetDocument()->getProjections();
2752 if (rProj.geometry() == Scanner::GEOMETRY_PARALLEL) {
2753 wxMessageBox ("Projections are already parallel", "Error");
2756 wxProgressDialog dlgProgress (wxString("Convert to Parallel"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2757 Projections* pProjNew = rProj.interpolateToParallel();
2758 ProjectionFileDocument* pProjDocNew = theApp->newProjectionDoc();
2759 pProjDocNew->setProjections (pProjNew);
2761 if (ProjectionFileView* projView = pProjDocNew->getView()) {
2762 projView->OnUpdate (projView, NULL);
2763 if (projView->getCanvas())
2764 projView->getCanvas()->SetClientSize (pProjNew->nDet(), pProjNew->nView());
2765 if (wxFrame* pFrame = projView->getFrame()) {
2770 GetDocumentManager()->ActivateView (projView, true, false);
2772 if (theApp->getAskDeleteNewDocs())
2773 pProjDocNew-> Modify(true);
2774 pProjDocNew->UpdateAllViews (this);
2775 pProjDocNew->getView()->setInitialClientSize();
2776 pProjDocNew->Activate();
2780 ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
2782 Projections& rProj = GetDocument()->getProjections();
2783 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Fourier Reconstruction", m_iDefaultPolarNX, m_iDefaultPolarNY,
2784 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad, IDH_DLG_RECON_FOURIER);
2785 if (dialogPolar.ShowModal() == wxID_OK) {
2786 wxProgressDialog dlgProgress (wxString("Reconstruction Fourier"), wxString("Reconstruction Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2787 wxString strInterpolation (dialogPolar.getInterpolationName());
2788 m_iDefaultPolarNX = dialogPolar.getXSize();
2789 m_iDefaultPolarNY = dialogPolar.getYSize();
2790 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2791 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2793 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2794 if (! rProj.convertFFTPolar (*pIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad)) {
2796 *theApp->getLog() << "Error converting to polar\n";
2802 pIF->magnitude(*pIF);
2803 Fourier::shuffleFourierToNaturalOrder (*pIF);
2805 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2807 sys_error (ERR_SEVERE, "Unable to create image file");
2810 pPolarDoc->setImageFile (pIF);
2811 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2812 std::ostringstream os;
2813 os << "Reconstruct Fourier " << GetFrame()->GetTitle().c_str() << ": xSize="
2814 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2815 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2816 *theApp->getLog() << os.str().c_str() << "\n";
2817 pIF->labelAdd (os.str().c_str());
2818 if (theApp->getAskDeleteNewDocs())
2819 pPolarDoc->Modify (true);
2820 pPolarDoc->UpdateAllViews ();
2821 pPolarDoc->getView()->setInitialClientSize();
2822 pPolarDoc->Activate();
2827 ProjectionFileView::OnReconstructFBPRebin (wxCommandEvent& event)
2829 Projections& rProj = GetDocument()->getProjections();
2830 doReconstructFBP (rProj, true);
2834 ProjectionFileView::OnReconstructFBP (wxCommandEvent& event)
2836 Projections& rProj = GetDocument()->getProjections();
2837 doReconstructFBP (rProj, false);
2841 ProjectionFileView::doReconstructFBP (const Projections& rProj, bool bRebinToParallel)
2843 ReconstructionROI defaultROI;
2844 defaultROI.m_dXMin = -rProj.phmLen() / 2;
2845 defaultROI.m_dXMax = defaultROI.m_dXMin + rProj.phmLen();
2846 defaultROI.m_dYMin = -rProj.phmLen() / 2;
2847 defaultROI.m_dYMax = defaultROI.m_dYMin + rProj.phmLen();
2849 DialogGetReconstructionParameters dialogReconstruction (getFrameForChild(), m_iDefaultNX, m_iDefaultNY,
2850 m_iDefaultFilter, m_dDefaultFilterParam, m_iDefaultFilterMethod, m_iDefaultFilterGeneration,
2851 m_iDefaultZeropad, m_iDefaultInterpolation, m_iDefaultInterpParam, m_iDefaultBackprojector,
2852 m_iDefaultTrace, &defaultROI);
2854 int retVal = dialogReconstruction.ShowModal();
2855 if (retVal != wxID_OK)
2858 m_iDefaultNX = dialogReconstruction.getXSize();
2859 m_iDefaultNY = dialogReconstruction.getYSize();
2860 wxString optFilterName = dialogReconstruction.getFilterName();
2861 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
2862 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
2863 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
2864 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
2865 m_iDefaultZeropad = dialogReconstruction.getZeropad();
2866 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
2867 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
2868 wxString optInterpName = dialogReconstruction.getInterpName();
2869 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
2870 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
2871 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
2872 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
2873 m_iDefaultTrace = dialogReconstruction.getTrace();
2874 dialogReconstruction.getROI (&defaultROI);
2876 if (m_iDefaultNX <= 0 && m_iDefaultNY <= 0)
2879 std::ostringstream os;
2880 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();
2881 if (bRebinToParallel)
2882 os << "; Interpolate to Parallel";
2885 ImageFile* pImageFile = NULL;
2886 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2887 pImageFile = new ImageFile (m_iDefaultNX, m_iDefaultNY);
2888 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2889 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2890 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace,
2891 &defaultROI, bRebinToParallel);
2893 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstructor, rProj, *pImageFile, m_iDefaultTrace, getFrameForChild());
2894 for (int iView = 0; iView < rProj.nView(); iView++) {
2896 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView, true)) {
2897 delete pDlgReconstruct;
2898 delete pReconstructor;
2903 while (pDlgReconstruct->isPaused()) {
2908 pReconstructor->postProcessing();
2909 delete pDlgReconstruct;
2910 delete pReconstructor;
2913 if (theApp->getUseBackgroundTasks()) {
2914 ReconstructorSupervisorThread* pReconstructor = new ReconstructorSupervisorThread (this, m_iDefaultNX,
2915 m_iDefaultNY, optFilterName.c_str(), m_dDefaultFilterParam, optFilterMethodName.c_str(),
2916 m_iDefaultZeropad, optFilterGenerationName.c_str(), optInterpName.c_str(), m_iDefaultInterpParam,
2917 optBackprojectName.c_str(), os.str().c_str(), &defaultROI, bRebinToParallel);
2918 if (pReconstructor->Create() != wxTHREAD_NO_ERROR) {
2919 sys_error (ERR_SEVERE, "Error creating reconstructor thread");
2920 delete pReconstructor;
2923 pReconstructor->SetPriority (60);
2924 pReconstructor->Run();
2929 pImageFile = new ImageFile (m_iDefaultNX, m_iDefaultNY);
2930 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2931 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2932 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2933 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace,
2934 &defaultROI, bRebinToParallel);
2936 for (int iView = 0; iView < rProj.nView(); iView++) {
2937 pReconstructor->reconstructView (iView, 1);
2938 if (! dlgProgress.Update (iView + 1)) {
2939 delete pReconstructor;
2940 return; // don't make new window, thread will do this
2943 pReconstructor->postProcessing();
2944 delete pReconstructor;
2947 ImageFileDocument* pReconDoc = theApp->newImageDoc();
2949 sys_error (ERR_SEVERE, "Unable to create image file");
2952 *theApp->getLog() << os.str().c_str() << "\n";
2953 pImageFile->labelAdd (rProj.getLabel());
2954 pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd());
2956 pReconDoc->setImageFile (pImageFile);
2957 if (theApp->getAskDeleteNewDocs())
2958 pReconDoc->Modify (true);
2959 pReconDoc->UpdateAllViews();
2960 pReconDoc->getView()->setInitialClientSize();
2961 pReconDoc->Activate();
2966 ProjectionFileView::OnArtifactReduction (wxCommandEvent& event)
2971 ProjectionFileCanvas*
2972 ProjectionFileView::CreateCanvas (wxFrame *parent)
2974 ProjectionFileCanvas* pCanvas;
2976 parent->GetClientSize(&width, &height);
2978 pCanvas = new ProjectionFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
2980 pCanvas->SetScrollbars(20, 20, 50, 50);
2981 pCanvas->SetBackgroundColour(*wxWHITE);
2992 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2995 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2997 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2999 theApp->setIconForFrame (subframe);
3001 m_pFileMenu = new wxMenu;
3003 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3004 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3005 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3006 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3007 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3008 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3010 m_pFileMenu->AppendSeparator();
3011 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
3013 m_pFileMenu->AppendSeparator();
3014 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3015 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3016 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3017 m_pFileMenu->AppendSeparator();
3018 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3020 m_pFileMenu->AppendSeparator();
3021 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3022 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3024 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3025 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3027 wxMenu *convert_menu = new wxMenu;
3028 convert_menu->Append (PJMENU_CONVERT_RECTANGULAR, "&Rectangular Image");
3029 convert_menu->Append (PJMENU_CONVERT_POLAR, "&Polar Image...\tCtrl-L");
3030 convert_menu->Append (PJMENU_CONVERT_FFT_POLAR, "FF&T->Polar Image...\tCtrl-T");
3031 convert_menu->AppendSeparator();
3032 convert_menu->Append (PJMENU_CONVERT_PARALLEL, "&Interpolate to Parallel");
3034 // wxMenu* filter_menu = new wxMenu;
3035 // filter_menu->Append (PJMENU_ARTIFACT_REDUCTION, "&Artifact Reduction");
3037 wxMenu* analyze_menu = new wxMenu;
3038 analyze_menu->Append (PJMENU_PLOT_HISTOGRAM, "&Plot Histogram");
3039 analyze_menu->Append (PJMENU_PLOT_TTHETA_SAMPLING, "Plot T-T&heta Sampling...\tCtrl-H");
3041 wxMenu *reconstruct_menu = new wxMenu;
3042 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP, "&Filtered Backprojection...\tCtrl-R", "Reconstruct image using filtered backprojection");
3043 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP_REBIN, "Filtered &Backprojection (Rebin to Parallel)...\tCtrl-B", "Reconstruct image using filtered backprojection");
3045 // reconstruct_menu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Fourier...\tCtrl-E", "Reconstruct image using inverse Fourier");
3047 wxMenu *help_menu = new wxMenu;
3048 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3049 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3050 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3051 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3053 wxMenuBar *menu_bar = new wxMenuBar;
3055 menu_bar->Append (m_pFileMenu, "&File");
3056 menu_bar->Append (convert_menu, "&Convert");
3057 // menu_bar->Append (filter_menu, "Fi<er");
3058 menu_bar->Append (analyze_menu, "&Analyze");
3059 menu_bar->Append (reconstruct_menu, "&Reconstruct");
3060 menu_bar->Append (help_menu, "&Help");
3062 subframe->SetMenuBar(menu_bar);
3063 subframe->Centre(wxBOTH);
3065 wxAcceleratorEntry accelEntries[7];
3066 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('L'), PJMENU_CONVERT_POLAR);
3067 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('T'), PJMENU_CONVERT_FFT_POLAR);
3068 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('R'), PJMENU_RECONSTRUCT_FBP);
3069 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('B'), PJMENU_RECONSTRUCT_FBP_REBIN);
3070 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('E'), PJMENU_RECONSTRUCT_FOURIER);
3071 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('I'), PJMENU_FILE_PROPERTIES);
3072 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('H'), PJMENU_PLOT_TTHETA_SAMPLING);
3073 wxAcceleratorTable accelTable (7, accelEntries);
3074 subframe->SetAcceleratorTable (accelTable);
3081 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
3083 m_pFrame = CreateChildFrame(doc, this);
3087 m_pFrame->GetClientSize (&width, &height);
3088 m_pFrame->SetTitle ("ProjectionFileView");
3089 m_pCanvas = CreateCanvas (m_pFrame);
3091 m_pFrame->Show(true);
3098 ProjectionFileView::OnDraw (wxDC* dc)
3101 dc->DrawBitmap (m_bitmap, 0, 0, false);
3106 ProjectionFileView::setInitialClientSize ()
3108 wxSize bestSize = m_pCanvas->GetBestSize();
3110 if (bestSize.x > 800)
3112 if (bestSize.y > 800)
3115 m_pFrame->SetClientSize (bestSize);
3116 m_pFrame->Show (true);
3117 m_pFrame->SetFocus();
3121 ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3123 const Projections& rProj = GetDocument()->getProjections();
3124 const int nDet = rProj.nDet();
3125 const int nView = rProj.nView();
3126 if (nDet != 0 && nView != 0) {
3127 const DetectorArray& detarray = rProj.getDetectorArray(0);
3128 const DetectorValue* detval = detarray.detValues();
3129 double min = detval[0];
3130 double max = detval[0];
3131 for (int iy = 0; iy < nView; iy++) {
3132 const DetectorArray& detarray = rProj.getDetectorArray(iy);
3133 const DetectorValue* detval = detarray.detValues();
3134 for (int ix = 0; ix < nDet; ix++) {
3135 if (min > detval[ix])
3137 else if (max < detval[ix])
3142 unsigned char* imageData = new unsigned char [nDet * nView * 3];
3144 sys_error (ERR_SEVERE, "Unable to allocate memory for image display");
3147 double scale = (max - min) / 255;
3148 for (int iy2 = 0; iy2 < nView; iy2++) {
3149 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
3150 const DetectorValue* detval = detarray.detValues();
3151 for (int ix = 0; ix < nDet; ix++) {
3152 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
3153 intensity = clamp(intensity, 0, 255);
3154 int baseAddr = (iy2 * nDet + ix) * 3;
3155 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
3158 wxImage image (nDet, nView, imageData, true);
3159 m_bitmap = image.ConvertToBitmap();
3162 //int ySize = nView;
3163 //xSize = clamp (xSize, 0, 800);
3164 //ySize = clamp (ySize, 0, 800);
3165 //m_pFrame->SetClientSize (xSize, ySize);
3166 m_pCanvas->SetScrollbars (20, 20, nDet/20, nView/20);
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)
3211 PlotFileCanvas::GetBestSize() const
3217 theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
3218 xSize = maxValue<int> (xSize, ySize);
3220 ySize = xSize = (xSize / 4);
3224 return wxSize (xSize, ySize);
3227 PlotFileCanvas::~PlotFileCanvas ()
3233 PlotFileCanvas::OnDraw(wxDC& dc)
3236 m_pView->OnDraw(& dc);
3242 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
3244 BEGIN_EVENT_TABLE(PlotFileView, wxView)
3245 EVT_MENU(PLOTMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
3246 EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
3247 EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
3248 EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
3251 PlotFileView::PlotFileView()
3252 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pEZPlot(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
3256 PlotFileView::~PlotFileView()
3261 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
3265 PlotFileView::OnProperties (wxCommandEvent& event)
3267 const PlotFile& rPlot = GetDocument()->getPlotFile();
3268 std::ostringstream os;
3269 os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
3270 rPlot.printHeadersBrief (os);
3271 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<<\n";
3272 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
3273 dialogMsg.ShowModal();
3274 GetDocument()->Activate();
3279 PlotFileView::OnScaleAuto (wxCommandEvent& event)
3281 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3282 double min, max, mean, mode, median, stddev;
3283 rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
3284 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
3285 int iRetVal = dialogAutoScale.ShowModal();
3286 if (iRetVal == wxID_OK) {
3287 m_bMinSpecified = true;
3288 m_bMaxSpecified = true;
3290 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
3293 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
3294 OnUpdate (this, NULL);
3297 GetDocument()->Activate();
3301 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
3303 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3307 if (! m_bMinSpecified || ! m_bMaxSpecified) {
3308 if (! rPlotFile.getMinMax (1, min, max)) {
3309 *theApp->getLog() << "Error: unable to find Min/Max\n";
3314 if (m_bMinSpecified)
3316 if (m_bMaxSpecified)
3319 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Y-axis Minimum & Maximum", min, max);
3320 int retVal = dialogMinMax.ShowModal();
3321 if (retVal == wxID_OK) {
3322 m_bMinSpecified = true;
3323 m_bMaxSpecified = true;
3324 m_dMinPixel = dialogMinMax.getMinimum();
3325 m_dMaxPixel = dialogMinMax.getMaximum();
3326 OnUpdate (this, NULL);
3328 GetDocument()->Activate();
3332 PlotFileView::OnScaleFull (wxCommandEvent& event)
3334 if (m_bMinSpecified || m_bMaxSpecified) {
3335 m_bMinSpecified = false;
3336 m_bMaxSpecified = false;
3337 OnUpdate (this, NULL);
3339 GetDocument()->Activate();
3344 PlotFileView::CreateCanvas (wxFrame* parent)
3346 PlotFileCanvas* pCanvas;
3348 parent->GetClientSize(&width, &height);
3350 pCanvas = new PlotFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
3352 pCanvas->SetBackgroundColour(*wxWHITE);
3363 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
3366 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
3368 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
3370 theApp->setIconForFrame (subframe);
3372 m_pFileMenu = new wxMenu;
3374 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3375 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3376 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3377 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3378 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3379 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3381 m_pFileMenu->AppendSeparator();
3382 m_pFileMenu->Append(PLOTMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
3384 m_pFileMenu->AppendSeparator();
3385 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3386 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3387 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3388 m_pFileMenu->AppendSeparator();
3389 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3391 m_pFileMenu->AppendSeparator();
3392 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3393 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3395 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3396 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3398 wxMenu *view_menu = new wxMenu;
3399 view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...\tCtrl-E");
3400 view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
3401 view_menu->Append(PLOTMENU_VIEW_SCALE_FULL, "Display &Full Scale\tCtrl-U");
3403 wxMenu *help_menu = new wxMenu;
3404 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3405 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3406 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3407 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3409 wxMenuBar *menu_bar = new wxMenuBar;
3411 menu_bar->Append(m_pFileMenu, "&File");
3412 menu_bar->Append(view_menu, "&View");
3413 menu_bar->Append(help_menu, "&Help");
3415 subframe->SetMenuBar(menu_bar);
3416 subframe->Centre(wxBOTH);
3418 wxAcceleratorEntry accelEntries[4];
3419 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('E'), PLOTMENU_VIEW_SCALE_MINMAX);
3420 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('A'), PLOTMENU_VIEW_SCALE_AUTO);
3421 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('U'), PLOTMENU_VIEW_SCALE_FULL);
3422 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), PLOTMENU_FILE_PROPERTIES);
3423 wxAcceleratorTable accelTable (4, accelEntries);
3424 subframe->SetAcceleratorTable (accelTable);
3431 PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
3433 m_pFrame = CreateChildFrame(doc, this);
3436 m_bMinSpecified = false;
3437 m_bMaxSpecified = false;
3438 m_dAutoScaleFactor = 1.;
3441 m_pFrame->GetClientSize(&width, &height);
3442 m_pFrame->SetTitle ("Plot File");
3443 m_pCanvas = CreateCanvas (m_pFrame);
3445 m_pFrame->Show(true);
3452 PlotFileView::OnDraw (wxDC* dc)
3454 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3455 const int iNColumns = rPlotFile.getNumColumns();
3456 const int iNRecords = rPlotFile.getNumRecords();
3458 if (iNColumns > 0 && iNRecords > 0) {
3460 m_pCanvas->GetClientSize (&xsize, &ysize);
3461 SGPDriver driver (dc, xsize, ysize);
3464 m_pEZPlot->plot (&sgp);
3470 PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3472 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3473 const int iNColumns = rPlotFile.getNumColumns();
3474 const int iNRecords = rPlotFile.getNumRecords();
3475 const bool bScatterPlot = rPlotFile.getIsScatterPlot();
3477 if (iNColumns > 0 && iNRecords > 0) {
3480 m_pEZPlot = new EZPlot;
3482 for (unsigned int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)
3483 m_pEZPlot->ezset (rPlotFile.getEzsetCommand (iEzset));
3485 if (m_bMinSpecified) {
3486 std::ostringstream os;
3487 os << "ymin " << m_dMinPixel;
3488 m_pEZPlot->ezset (os.str());
3491 if (m_bMaxSpecified) {
3492 std::ostringstream os;
3493 os << "ymax " << m_dMaxPixel;
3494 m_pEZPlot->ezset (os.str());
3497 m_pEZPlot->ezset("box");
3498 m_pEZPlot->ezset("grid");
3500 double* pdX = new double [iNRecords];
3501 double* pdY = new double [iNRecords];
3502 if (! bScatterPlot) {
3503 rPlotFile.getColumn (0, pdX);
3505 for (int iCol = 1; iCol < iNColumns; iCol++) {
3506 rPlotFile.getColumn (iCol, pdY);
3507 m_pEZPlot->addCurve (pdX, pdY, iNRecords);
3510 rPlotFile.getColumn (0, pdX);
3511 rPlotFile.getColumn (1, pdY);
3512 m_pEZPlot->addCurve (pdX, pdY, iNRecords);
3519 m_pCanvas->Refresh();
3523 PlotFileView::OnClose (bool deleteWindow)
3525 //GetDocumentManager()->ActivateView (this, false, true);
3526 if (! GetDocument() || ! GetDocument()->Close())
3531 m_pCanvas->setView (NULL);
3534 wxString s(wxTheApp->GetAppName());
3536 m_pFrame->SetTitle(s);
3542 if (GetDocument() && GetDocument()->getBadFileOpen())
3543 ::wxYield(); // wxWindows bug workaround
3550 ////////////////////////////////////////////////////////////////
3553 IMPLEMENT_DYNAMIC_CLASS(TextFileView, wxView)
3555 TextFileView::~TextFileView()
3557 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
3558 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
3561 bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
3563 m_pFrame = CreateChildFrame(doc, this);
3564 SetFrame (m_pFrame);
3567 m_pFrame->GetClientSize(&width, &height);
3568 m_pFrame->SetTitle("TextFile");
3569 m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
3570 m_pFrame->SetTitle("Log");
3572 m_pFrame->Show (true);
3578 // Handled by wxTextWindow
3579 void TextFileView::OnDraw(wxDC *WXUNUSED(dc) )
3583 void TextFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3588 TextFileView::OnClose (bool deleteWindow)
3590 if (! theApp->getMainFrame()->getShuttingDown())
3594 //GetDocumentManager()->ActivateView (this, false, true);
3595 if (! GetDocument() || ! GetDocument()->Close())
3602 if (GetDocument() && GetDocument()->getBadFileOpen())
3603 ::wxYield(); // wxWindows bug workaround
3614 TextFileView::CreateChildFrame (wxDocument *doc, wxView *view)
3617 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(0,0), wxDEFAULT_FRAME_STYLE, "Log");
3619 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE, "Log");
3621 theApp->setIconForFrame (subframe);
3623 m_pFileMenu = new wxMenu;
3625 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3626 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3627 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3628 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3629 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3630 // m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3632 m_pFileMenu->AppendSeparator();
3633 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3634 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3635 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3636 m_pFileMenu->AppendSeparator();
3637 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3639 m_pFileMenu->AppendSeparator();
3640 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3641 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3643 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3644 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3646 wxMenu *help_menu = new wxMenu;
3647 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3648 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3649 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3650 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3652 wxMenuBar *menu_bar = new wxMenuBar;
3654 menu_bar->Append(m_pFileMenu, "&File");
3655 menu_bar->Append(help_menu, "&Help");
3657 subframe->SetMenuBar(menu_bar);
3658 subframe->Centre(wxBOTH);
3664 // Define a constructor for my text subwindow
3665 TextFileCanvas::TextFileCanvas (TextFileView* v, wxFrame* frame, const wxPoint& pos, const wxSize& size, long style)
3666 : wxTextCtrl (frame, -1, "", pos, size, style), m_pView(v)
3670 TextFileCanvas::~TextFileCanvas ()
3676 PlotFileCanvas::GetBestSize() const
3679 theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
3680 xSize = maxValue<int> (xSize, ySize);
3682 ySize = xSize = (xSize / 4);
3686 return wxSize (xSize, ySize);