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.158 2002/06/02 19:01:58 kevin Exp $
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
28 #include "wx/wxprec.h"
33 #if !wxUSE_DOC_VIEW_ARCHITECTURE
34 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
38 #include "wx/progdlg.h"
39 #include "wx/clipbrd.h"
46 #include "dlgprojections.h"
47 #include "dlgreconstruct.h"
48 #include "backprojectors.h"
49 #include "reconstruct.h"
51 #include "threadproj.h"
52 #include "threadrecon.h"
53 #include "threadraster.h"
55 #if defined(MSVC) || HAVE_SSTREAM
58 #include <sstream_subst>
61 // Used to reduce calls to progress bar update function
62 const short int ITER_PER_UPDATE = 10;
66 BEGIN_EVENT_TABLE(ImageFileCanvas, wxScrolledWindow)
67 EVT_MOUSE_EVENTS(ImageFileCanvas::OnMouseEvent)
68 EVT_CHAR(ImageFileCanvas::OnChar)
72 ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
73 : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v), m_xCursor(-1), m_yCursor(-1)
77 ImageFileCanvas::~ImageFileCanvas()
81 ImageFileCanvas::OnDraw(wxDC& dc)
84 m_pView->OnDraw(& dc);
88 ImageFileCanvas::DrawRubberBandCursor (wxDC& dc, int x, int y)
90 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
95 dc.SetLogicalFunction (wxINVERT);
96 dc.SetPen (*wxGREEN_PEN);
97 dc.DrawLine (0, yPt, nx, yPt);
98 dc.DrawLine (x, 0, x, ny);
99 dc.SetLogicalFunction (wxCOPY);
103 ImageFileCanvas::GetCurrentCursor (int& x, int& y)
108 if (m_xCursor >= 0 && m_yCursor >= 0)
115 ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
124 wxPoint pt(event.GetLogicalPosition(dc));
126 const ImageFileDocument* pIFDoc = m_pView->GetDocument();
129 const ImageFile& rIF = pIFDoc->getImageFile();
130 ImageFileArrayConst v = rIF.getArray();
133 const int yPt = ny - 1 - pt.y;
134 if (event.RightIsDown()) {
135 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
136 std::ostringstream os;
137 os << "Image value (" << pt.x << "," << yPt << ") = " << v[pt.x][yPt];
138 if (rIF.isComplex()) {
139 double dImag = rIF.getImaginaryArray()[pt.x][yPt];
141 os << " - " << -dImag;
143 os << " + " << dImag;
147 *theApp->getLog() << os.str().c_str();
149 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
151 else if (event.LeftIsDown() || event.LeftUp() || event.RightUp()) {
152 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
153 if (m_xCursor >= 0 && m_yCursor >= 0) {
154 DrawRubberBandCursor (dc, m_xCursor, m_yCursor);
156 DrawRubberBandCursor (dc, pt.x, yPt);
159 wxMenu* pMenu = m_pView->getMenuAnalyze();
160 if (pMenu && ! pMenu->IsEnabled(IFMENU_PLOT_ROW)) {
161 pMenu->Enable (IFMENU_PLOT_ROW, true);
162 pMenu->Enable (IFMENU_PLOT_COL, true);
163 pMenu->Enable (IFMENU_COMPARE_ROW, true);
164 pMenu->Enable (IFMENU_COMPARE_COL, true);
165 pMenu->Enable (IFMENU_PLOT_FFT_ROW, true);
166 pMenu->Enable (IFMENU_PLOT_FFT_COL, true);
169 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
171 if (event.LeftUp()) {
172 std::ostringstream os;
173 os << "Selected column " << pt.x << " , row " << yPt << "\n";
174 *theApp->getLog() << os.str().c_str();
179 ImageFileCanvas::OnChar (wxKeyEvent& event)
181 if (event.GetKeyCode() == WXK_ESCAPE) {
185 m_pView->OnUpdate (NULL);
187 wxScrolledWindow::OnChar (event);
191 ImageFileCanvas::GetBestSize() const
193 const int iMinX = 50;
194 const int iMinY = 20;
195 wxSize bestSize (iMinX,iMinY);
198 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
199 bestSize.Set (rIF.nx(), rIF.ny());
202 if (bestSize.x > 800)
204 if (bestSize.y > 800)
207 if (bestSize.y < iMinY)
209 if (bestSize.x < iMinX)
218 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
220 BEGIN_EVENT_TABLE(ImageFileView, wxView)
221 EVT_MENU(IFMENU_FILE_EXPORT, ImageFileView::OnExport)
222 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
223 EVT_MENU(IFMENU_EDIT_COPY, ImageFileView::OnEditCopy)
224 EVT_MENU(IFMENU_EDIT_CUT, ImageFileView::OnEditCut)
225 EVT_MENU(IFMENU_EDIT_PASTE, ImageFileView::OnEditPaste)
226 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
227 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
228 EVT_MENU(IFMENU_VIEW_SCALE_FULL, ImageFileView::OnScaleFull)
229 EVT_MENU(IFMENU_COMPARE_IMAGES, ImageFileView::OnCompare)
230 EVT_MENU(IFMENU_COMPARE_ROW, ImageFileView::OnCompareRow)
231 EVT_MENU(IFMENU_COMPARE_COL, ImageFileView::OnCompareCol)
232 EVT_MENU(IFMENU_FILTER_INVERTVALUES, ImageFileView::OnInvertValues)
233 EVT_MENU(IFMENU_FILTER_SQUARE, ImageFileView::OnSquare)
234 EVT_MENU(IFMENU_FILTER_SQRT, ImageFileView::OnSquareRoot)
235 EVT_MENU(IFMENU_FILTER_LOG, ImageFileView::OnLog)
236 EVT_MENU(IFMENU_FILTER_EXP, ImageFileView::OnExp)
237 EVT_MENU(IFMENU_FILTER_FOURIER, ImageFileView::OnFourier)
238 EVT_MENU(IFMENU_FILTER_INVERSE_FOURIER, ImageFileView::OnInverseFourier)
239 EVT_MENU(IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, ImageFileView::OnShuffleFourierToNaturalOrder)
240 EVT_MENU(IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, ImageFileView::OnShuffleNaturalToFourierOrder)
241 EVT_MENU(IFMENU_IMAGE_ADD, ImageFileView::OnAdd)
242 EVT_MENU(IFMENU_IMAGE_SUBTRACT, ImageFileView::OnSubtract)
243 EVT_MENU(IFMENU_IMAGE_MULTIPLY, ImageFileView::OnMultiply)
244 EVT_MENU(IFMENU_IMAGE_DIVIDE, ImageFileView::OnDivide)
245 EVT_MENU(IFMENU_IMAGE_SCALESIZE, ImageFileView::OnScaleSize)
247 EVT_MENU(IFMENU_IMAGE_CONVERT3D, ImageFileView::OnConvert3d)
250 EVT_MENU(IFMENU_FILTER_FFT, ImageFileView::OnFFT)
251 EVT_MENU(IFMENU_FILTER_IFFT, ImageFileView::OnIFFT)
252 EVT_MENU(IFMENU_FILTER_FFT_ROWS, ImageFileView::OnFFTRows)
253 EVT_MENU(IFMENU_FILTER_IFFT_ROWS, ImageFileView::OnIFFTRows)
254 EVT_MENU(IFMENU_FILTER_FFT_COLS, ImageFileView::OnFFTCols)
255 EVT_MENU(IFMENU_FILTER_IFFT_COLS, ImageFileView::OnIFFTCols)
257 EVT_MENU(IFMENU_FILTER_MAGNITUDE, ImageFileView::OnMagnitude)
258 EVT_MENU(IFMENU_FILTER_PHASE, ImageFileView::OnPhase)
259 EVT_MENU(IFMENU_FILTER_REAL, ImageFileView::OnReal)
260 EVT_MENU(IFMENU_FILTER_IMAGINARY, ImageFileView::OnImaginary)
261 EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)
262 EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol)
264 EVT_MENU(IFMENU_PLOT_FFT_ROW, ImageFileView::OnPlotFFTRow)
265 EVT_MENU(IFMENU_PLOT_FFT_COL, ImageFileView::OnPlotFFTCol)
267 EVT_MENU(IFMENU_PLOT_HISTOGRAM, ImageFileView::OnPlotHistogram)
270 ImageFileView::ImageFileView()
271 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0), m_pFilterMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
273 m_iDefaultExportFormatID = ImageFile::EXPORT_FORMAT_PNG;
276 ImageFileView::~ImageFileView()
278 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
279 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
284 ImageFileView::OnProperties (wxCommandEvent& event)
286 const ImageFile& rIF = GetDocument()->getImageFile();
287 if (rIF.nx() == 0 || rIF.ny() == 0)
288 *theApp->getLog() << "Properties: empty imagefile\n";
290 const std::string rFilename = m_pFrame->GetTitle().c_str();
291 std::ostringstream os;
292 double min, max, mean, mode, median, stddev;
293 rIF.statistics (rIF.getArray(), min, max, mean, mode, median, stddev);
294 os << "Filename: " << rFilename << "\n";
295 os << "Size: (" << rIF.nx() << "," << rIF.ny() << ")\n";
301 os << "Minimum: "<<min<<"\nMaximum: "<<max<<"\nMean: "<<mean<<"\nMedian: "<<median<<"\nMode: "<<mode<<"\nStandard Deviation: "<<stddev << "\n";
302 if (rIF.isComplex()) {
303 rIF.statistics (rIF.getImaginaryArray(), min, max, mean, mode, median, stddev);
304 os << "Imaginary: min: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
306 if (rIF.nLabels() > 0) {
307 rIF.printLabelsBrief (os);
309 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
310 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
311 dialogMsg.ShowModal();
313 GetDocument()->Activate();
317 ImageFileView::OnScaleAuto (wxCommandEvent& event)
319 const ImageFile& rIF = GetDocument()->getImageFile();
320 double min, max, mean, mode, median, stddev;
321 rIF.statistics(min, max, mean, mode, median, stddev);
322 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
323 int iRetVal = dialogAutoScale.ShowModal();
324 if (iRetVal == wxID_OK) {
325 m_bMinSpecified = true;
326 m_bMaxSpecified = true;
328 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
331 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
332 GetDocument()->UpdateAllViews (this);
335 GetDocument()->Activate();
339 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
341 const ImageFile& rIF = GetDocument()->getImageFile();
343 if (! m_bMinSpecified && ! m_bMaxSpecified)
344 rIF.getMinMax (min, max);
351 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Image Minimum & Maximum", min, max);
352 int retVal = dialogMinMax.ShowModal();
353 if (retVal == wxID_OK) {
354 m_bMinSpecified = true;
355 m_bMaxSpecified = true;
356 m_dMinPixel = dialogMinMax.getMinimum();
357 m_dMaxPixel = dialogMinMax.getMaximum();
358 GetDocument()->UpdateAllViews (this);
360 GetDocument()->Activate();
364 ImageFileView::OnScaleFull (wxCommandEvent& event)
366 if (m_bMinSpecified || m_bMaxSpecified) {
367 m_bMinSpecified = false;
368 m_bMaxSpecified = false;
369 GetDocument()->UpdateAllViews (this);
371 GetDocument()->Activate();
375 ImageFileView::OnCompare (wxCommandEvent& event)
377 std::vector<ImageFileDocument*> vecIF;
378 theApp->getCompatibleImages (GetDocument(), vecIF);
380 if (vecIF.size() == 0) {
381 wxMessageBox("There are no compatible image files open for comparision", "No comparison images");
383 DialogGetComparisonImage dialogGetCompare(getFrameForChild(), "Get Comparison Image", vecIF, true);
385 if (dialogGetCompare.ShowModal() == wxID_OK) {
386 const ImageFile& rIF = GetDocument()->getImageFile();
387 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
388 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
389 std::ostringstream os;
390 double min, max, mean, mode, median, stddev;
391 rIF.statistics (min, max, mean, mode, median, stddev);
392 os << GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
393 rCompareIF.statistics (min, max, mean, mode, median, stddev);
394 os << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
396 rIF.comparativeStatistics (rCompareIF, d, r, e);
397 os << "Comparative Statistics: d=" << d << ", r=" << r << ", e=" << e << "\n";
398 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
399 if (dialogGetCompare.getMakeDifferenceImage()) {
400 ImageFile* pDifferenceImage = new ImageFile;
402 pDifferenceImage->setArraySize (rIF.nx(), rIF.ny());
403 if (! rIF.subtractImages (rCompareIF, *pDifferenceImage)) {
404 *theApp->getLog() << "Unable to subtract images\n";
405 delete pDifferenceImage;
408 ImageFileDocument* pDifferenceDoc = theApp->newImageDoc();
409 if (! pDifferenceDoc) {
410 sys_error (ERR_SEVERE, "Unable to create image file");
413 pDifferenceDoc->setImageFile (pDifferenceImage);
415 wxString s = GetFrame()->GetTitle() + ": ";
416 pDifferenceImage->labelsCopy (rIF, s.c_str());
417 s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
418 pDifferenceImage->labelsCopy (rCompareIF, s.c_str());
419 std::ostringstream osLabel;
420 osLabel << "Compare image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str()
421 << " and " << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": "
423 pDifferenceImage->labelAdd (os.str().c_str());
424 if (theApp->getAskDeleteNewDocs())
425 pDifferenceDoc->Modify (true);
426 pDifferenceDoc->UpdateAllViews(this);
427 pDifferenceDoc->getView()->setInitialClientSize();
428 pDifferenceDoc->Activate();
430 wxMessageBox(os.str().c_str(), "Image Comparison");
436 ImageFileView::OnInvertValues (wxCommandEvent& event)
438 ImageFile& rIF = GetDocument()->getImageFile();
439 rIF.invertPixelValues (rIF);
440 rIF.labelAdd ("Invert Pixel Values");
441 if (theApp->getAskDeleteNewDocs())
442 GetDocument()->Modify (true);
443 GetDocument()->UpdateAllViews (this);
444 GetDocument()->Activate();
448 ImageFileView::OnSquare (wxCommandEvent& event)
450 ImageFile& rIF = GetDocument()->getImageFile();
452 rIF.labelAdd ("Square Pixel Values");
453 if (theApp->getAskDeleteNewDocs())
454 GetDocument()->Modify (true);
455 GetDocument()->UpdateAllViews (this);
456 GetDocument()->Activate();
460 ImageFileView::OnSquareRoot (wxCommandEvent& event)
462 ImageFile& rIF = GetDocument()->getImageFile();
464 rIF.labelAdd ("Square-root Pixel Values");
465 if (theApp->getAskDeleteNewDocs())
466 GetDocument()->Modify (true);
467 GetDocument()->UpdateAllViews (this);
468 GetDocument()->Activate();
472 ImageFileView::OnLog (wxCommandEvent& event)
474 ImageFile& rIF = GetDocument()->getImageFile();
476 rIF.labelAdd ("Logrithm base-e Pixel Values");
477 if (theApp->getAskDeleteNewDocs())
478 GetDocument()->Modify (true);
479 GetDocument()->UpdateAllViews (this);
480 GetDocument()->Activate();
484 ImageFileView::OnExp (wxCommandEvent& event)
486 ImageFile& rIF = GetDocument()->getImageFile();
488 rIF.labelAdd ("Exponent base-e Pixel Values");
489 if (theApp->getAskDeleteNewDocs())
490 GetDocument()->Modify (true);
491 GetDocument()->UpdateAllViews (this);
492 GetDocument()->Activate();
496 ImageFileView::OnAdd (wxCommandEvent& event)
498 std::vector<ImageFileDocument*> vecIF;
499 theApp->getCompatibleImages (GetDocument(), vecIF);
501 if (vecIF.size() == 0) {
502 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
504 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Add", vecIF, false);
506 if (dialogGetCompare.ShowModal() == wxID_OK) {
507 ImageFile& rIF = GetDocument()->getImageFile();
508 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
509 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
510 ImageFileDocument* pNewDoc = theApp->newImageDoc();
512 sys_error (ERR_SEVERE, "Unable to create image file");
515 ImageFile& newImage = pNewDoc->getImageFile();
516 newImage.setArraySize (rIF.nx(), rIF.ny());
517 rIF.addImages (rRHSIF, newImage);
518 std::ostringstream os;
519 os << "Add image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
520 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
521 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
522 newImage.labelsCopy (rIF, s.c_str());
523 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
524 newImage.labelsCopy (rRHSIF, s.c_str());
525 newImage.labelAdd (os.str().c_str());
526 *theApp->getLog() << os.str().c_str() << "\n";
527 if (theApp->getAskDeleteNewDocs())
528 pNewDoc->Modify (true);
529 pNewDoc->UpdateAllViews (this);
530 pNewDoc->getView()->setInitialClientSize();
537 ImageFileView::OnSubtract (wxCommandEvent& event)
539 std::vector<ImageFileDocument*> vecIF;
540 theApp->getCompatibleImages (GetDocument(), vecIF);
542 if (vecIF.size() == 0) {
543 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
545 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Subtract", vecIF, false);
547 if (dialogGetCompare.ShowModal() == wxID_OK) {
548 ImageFile& rIF = GetDocument()->getImageFile();
549 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
550 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
551 ImageFileDocument* pNewDoc = theApp->newImageDoc();
553 sys_error (ERR_SEVERE, "Unable to create image file");
556 ImageFile& newImage = pNewDoc->getImageFile();
557 newImage.setArraySize (rIF.nx(), rIF.ny());
558 rIF.subtractImages (rRHSIF, newImage);
559 std::ostringstream os;
560 os << "Subtract image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
561 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
562 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
563 newImage.labelsCopy (rIF, s.c_str());
564 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
565 newImage.labelsCopy (rRHSIF, s.c_str());
566 newImage.labelAdd (os.str().c_str());
567 *theApp->getLog() << os.str().c_str() << "\n";
568 if (theApp->getAskDeleteNewDocs())
569 pNewDoc->Modify (true);
570 pNewDoc->UpdateAllViews (this);
571 pNewDoc->getView()->setInitialClientSize();
578 ImageFileView::OnMultiply (wxCommandEvent& event)
580 std::vector<ImageFileDocument*> vecIF;
581 theApp->getCompatibleImages (GetDocument(), vecIF);
583 if (vecIF.size() == 0) {
584 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
586 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Multiply", vecIF, false);
588 if (dialogGetCompare.ShowModal() == wxID_OK) {
589 ImageFile& rIF = GetDocument()->getImageFile();
590 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
591 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
592 ImageFileDocument* pNewDoc = theApp->newImageDoc();
594 sys_error (ERR_SEVERE, "Unable to create image file");
597 ImageFile& newImage = pNewDoc->getImageFile();
598 newImage.setArraySize (rIF.nx(), rIF.ny());
599 rIF.multiplyImages (rRHSIF, newImage);
600 std::ostringstream os;
601 os << "Multiply image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
602 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
603 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
604 newImage.labelsCopy (rIF, s.c_str());
605 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
606 newImage.labelsCopy (rRHSIF, s.c_str());
607 newImage.labelAdd (os.str().c_str());
608 *theApp->getLog() << os.str().c_str() << "\n";
609 if (theApp->getAskDeleteNewDocs())
610 pNewDoc->Modify (true);
611 pNewDoc->UpdateAllViews (this);
612 pNewDoc->getView()->setInitialClientSize();
619 ImageFileView::OnDivide (wxCommandEvent& event)
621 std::vector<ImageFileDocument*> vecIF;
622 theApp->getCompatibleImages (GetDocument(), vecIF);
624 if (vecIF.size() == 0) {
625 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
627 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Divide", vecIF, false);
629 if (dialogGetCompare.ShowModal() == wxID_OK) {
630 ImageFile& rIF = GetDocument()->getImageFile();
631 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
632 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
633 ImageFileDocument* pNewDoc = theApp->newImageDoc();
635 sys_error (ERR_SEVERE, "Unable to create image file");
638 ImageFile& newImage = pNewDoc->getImageFile();
639 newImage.setArraySize (rIF.nx(), rIF.ny());
640 rIF.divideImages (rRHSIF, newImage);
641 std::ostringstream os;
642 os << "Divide image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " by "
643 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
644 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
645 newImage.labelsCopy (rIF, s.c_str());
646 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
647 newImage.labelsCopy (rRHSIF, s.c_str());
648 newImage.labelAdd (os.str().c_str());
649 *theApp->getLog() << os.str().c_str() << "\n";
650 if (theApp->getAskDeleteNewDocs())
651 pNewDoc->Modify (true);
652 pNewDoc->UpdateAllViews (this);
653 pNewDoc->getView()->setInitialClientSize();
662 ImageFileView::OnFFT (wxCommandEvent& event)
664 ImageFile& rIF = GetDocument()->getImageFile();
666 rIF.labelAdd ("FFT Image");
667 m_bMinSpecified = false;
668 m_bMaxSpecified = false;
669 if (theApp->getAskDeleteNewDocs())
670 GetDocument()->Modify (true);
671 GetDocument()->UpdateAllViews (this);
672 GetDocument()->Activate();
676 ImageFileView::OnIFFT (wxCommandEvent& event)
678 ImageFile& rIF = GetDocument()->getImageFile();
680 rIF.labelAdd ("IFFT Image");
681 m_bMinSpecified = false;
682 m_bMaxSpecified = false;
683 if (theApp->getAskDeleteNewDocs())
684 GetDocument()->Modify (true);
685 GetDocument()->UpdateAllViews (this);
686 GetDocument()->Activate();
690 ImageFileView::OnFFTRows (wxCommandEvent& event)
692 ImageFile& rIF = GetDocument()->getImageFile();
694 rIF.labelAdd ("FFT Rows");
695 m_bMinSpecified = false;
696 m_bMaxSpecified = false;
697 if (theApp->getAskDeleteNewDocs())
698 GetDocument()->Modify (true);
699 GetDocument()->UpdateAllViews (this);
700 GetDocument()->Activate();
704 ImageFileView::OnIFFTRows (wxCommandEvent& event)
706 ImageFile& rIF = GetDocument()->getImageFile();
708 rIF.labelAdd ("IFFT Rows");
709 m_bMinSpecified = false;
710 m_bMaxSpecified = false;
711 if (theApp->getAskDeleteNewDocs())
712 GetDocument()->Modify (true);
713 GetDocument()->UpdateAllViews (this);
714 GetDocument()->Activate();
718 ImageFileView::OnFFTCols (wxCommandEvent& event)
720 ImageFile& rIF = GetDocument()->getImageFile();
722 rIF.labelAdd ("FFT Columns");
723 m_bMinSpecified = false;
724 m_bMaxSpecified = false;
725 if (theApp->getAskDeleteNewDocs())
726 GetDocument()->Modify (true);
727 GetDocument()->UpdateAllViews (this);
728 GetDocument()->Activate();
732 ImageFileView::OnIFFTCols (wxCommandEvent& event)
734 ImageFile& rIF = GetDocument()->getImageFile();
736 rIF.labelAdd ("IFFT Columns");
737 m_bMinSpecified = false;
738 m_bMaxSpecified = false;
739 if (theApp->getAskDeleteNewDocs())
740 GetDocument()->Modify (true);
741 GetDocument()->UpdateAllViews (this);
742 GetDocument()->Activate();
747 ImageFileView::OnFourier (wxCommandEvent& event)
749 ImageFile& rIF = GetDocument()->getImageFile();
750 wxProgressDialog dlgProgress (wxString("Fourier"), wxString("Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
752 rIF.labelAdd ("Fourier Image");
753 m_bMinSpecified = false;
754 m_bMaxSpecified = false;
755 if (theApp->getAskDeleteNewDocs())
756 GetDocument()->Modify (true);
757 GetDocument()->UpdateAllViews (this);
758 GetDocument()->Activate();
762 ImageFileView::OnInverseFourier (wxCommandEvent& event)
764 ImageFile& rIF = GetDocument()->getImageFile();
765 wxProgressDialog dlgProgress (wxString("Inverse Fourier"), wxString("Inverse Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
766 rIF.inverseFourier (rIF);
767 rIF.labelAdd ("Inverse Fourier Image");
768 m_bMinSpecified = false;
769 m_bMaxSpecified = false;
770 if (theApp->getAskDeleteNewDocs())
771 GetDocument()->Modify (true);
772 GetDocument()->UpdateAllViews (this);
773 GetDocument()->Activate();
777 ImageFileView::OnShuffleNaturalToFourierOrder (wxCommandEvent& event)
779 ImageFile& rIF = GetDocument()->getImageFile();
780 Fourier::shuffleNaturalToFourierOrder (rIF);
781 rIF.labelAdd ("Shuffle Natural To Fourier Order");
782 m_bMinSpecified = false;
783 m_bMaxSpecified = false;
784 if (theApp->getAskDeleteNewDocs())
785 GetDocument()->Modify (true);
786 GetDocument()->UpdateAllViews (this);
787 GetDocument()->Activate();
791 ImageFileView::OnShuffleFourierToNaturalOrder (wxCommandEvent& event)
793 ImageFile& rIF = GetDocument()->getImageFile();
794 Fourier::shuffleFourierToNaturalOrder (rIF);
795 rIF.labelAdd ("Shuffle Fourier To Natural Order");
796 m_bMinSpecified = false;
797 m_bMaxSpecified = false;
798 if (theApp->getAskDeleteNewDocs())
799 GetDocument()->Modify (true);
800 GetDocument()->UpdateAllViews (this);
801 GetDocument()->Activate();
805 ImageFileView::OnMagnitude (wxCommandEvent& event)
807 ImageFile& rIF = GetDocument()->getImageFile();
809 rIF.labelAdd ("Magnitude");
810 m_bMinSpecified = false;
811 m_bMaxSpecified = false;
812 if (theApp->getAskDeleteNewDocs())
813 GetDocument()->Modify (true);
814 GetDocument()->UpdateAllViews (this);
815 GetDocument()->Activate();
819 ImageFileView::OnPhase (wxCommandEvent& event)
821 ImageFile& rIF = GetDocument()->getImageFile();
822 if (rIF.isComplex()) {
824 rIF.labelAdd ("Phase of complex-image");
825 m_bMinSpecified = false;
826 m_bMaxSpecified = false;
827 if (theApp->getAskDeleteNewDocs())
828 GetDocument()->Modify (true);
829 GetDocument()->UpdateAllViews (this);
831 GetDocument()->Activate();
835 ImageFileView::OnReal (wxCommandEvent& event)
837 ImageFile& rIF = GetDocument()->getImageFile();
838 if (rIF.isComplex()) {
840 rIF.labelAdd ("Real component of complex-image");
841 m_bMinSpecified = false;
842 m_bMaxSpecified = false;
843 if (theApp->getAskDeleteNewDocs())
844 GetDocument()->Modify (true);
845 GetDocument()->UpdateAllViews (this);
847 GetDocument()->Activate();
851 ImageFileView::OnImaginary (wxCommandEvent& event)
853 ImageFile& rIF = GetDocument()->getImageFile();
854 if (rIF.isComplex()) {
856 rIF.labelAdd ("Imaginary component of complex-image");
857 m_bMinSpecified = false;
858 m_bMaxSpecified = false;
859 if (theApp->getAskDeleteNewDocs())
860 GetDocument()->Modify (true);
861 GetDocument()->UpdateAllViews (this);
863 GetDocument()->Activate();
868 ImageFileView::CreateCanvas (wxFrame* parent)
870 ImageFileCanvas* pCanvas = new ImageFileCanvas (this, parent, wxPoint(0, 0),
872 pCanvas->SetBackgroundColour(*wxWHITE);
883 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
886 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(10,10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
888 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
890 theApp->setIconForFrame (subframe);
892 m_pFileMenu = new wxMenu;
893 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
894 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
895 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
896 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
897 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
898 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
899 m_pFileMenu->Append(wxID_REVERT, "Re&vert");
901 m_pFileMenu->AppendSeparator();
902 m_pFileMenu->Append(IFMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
903 m_pFileMenu->Append(IFMENU_FILE_EXPORT, "Expor&t...");
905 m_pFileMenu->AppendSeparator();
906 m_pFileMenu->Append(wxID_PRINT, "&Print...");
907 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
908 m_pFileMenu->Append(wxID_PREVIEW, "Print Preview");
909 m_pFileMenu->AppendSeparator();
910 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
912 m_pFileMenu->AppendSeparator();
913 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
914 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
916 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
917 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
919 wxMenu* edit_menu = new wxMenu;
920 edit_menu->Append(IFMENU_EDIT_COPY, "Copy\tCtrl-C");
921 edit_menu->Append(IFMENU_EDIT_CUT, "Cut\tCtrl-X");
922 edit_menu->Append(IFMENU_EDIT_PASTE, "Paste\tCtrl-V");
924 wxMenu *view_menu = new wxMenu;
925 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale S&et...\tCtrl-E");
926 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
927 view_menu->Append(IFMENU_VIEW_SCALE_FULL, "Display F&ull Scale\tCtrl-U");
929 m_pFilterMenu = new wxMenu;
930 m_pFilterMenu->Append (IFMENU_FILTER_INVERTVALUES, "In&vert Values");
931 m_pFilterMenu->Append (IFMENU_FILTER_SQUARE, "&Square");
932 m_pFilterMenu->Append (IFMENU_FILTER_SQRT, "Square &Root");
933 m_pFilterMenu->Append (IFMENU_FILTER_LOG, "&Log");
934 m_pFilterMenu->Append (IFMENU_FILTER_EXP, "E&xp");
935 m_pFilterMenu->AppendSeparator();
937 m_pFilterMenu->Append (IFMENU_FILTER_FFT, "2-D &FFT\tCtrl-2");
938 m_pFilterMenu->Append (IFMENU_FILTER_IFFT, "2-D &IFFT\tAlt-2");
939 m_pFilterMenu->Append (IFMENU_FILTER_FFT_ROWS, "FFT Rows");
940 m_pFilterMenu->Append (IFMENU_FILTER_IFFT_ROWS, "IFFT Rows");
941 m_pFilterMenu->Append (IFMENU_FILTER_FFT_COLS, "FFT Columns");
942 m_pFilterMenu->Append (IFMENU_FILTER_IFFT_COLS, "IFFT Columns");
943 m_pFilterMenu->Append (IFMENU_FILTER_FOURIER, "2-D F&ourier");
944 m_pFilterMenu->Append (IFMENU_FILTER_INVERSE_FOURIER, "2-D Inverse Fo&urier");
946 m_pFilterMenu->Append (IFMENU_FILTER_FOURIER, "&Fourier");
947 m_pFilterMenu->Append (IFMENU_FILTER_INVERSE_FOURIER, "&Inverse Fourier");
949 m_pFilterMenu->Append (IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, "Shuffl&e Fourier to Natural Order");
950 m_pFilterMenu->Append (IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, "Shuffle &Natural to Fourier Order");
951 m_pFilterMenu->AppendSeparator();
952 m_pFilterMenu->Append (IFMENU_FILTER_MAGNITUDE, "&Magnitude");
953 m_pFilterMenu->Append (IFMENU_FILTER_PHASE, "&Phase");
954 m_pFilterMenu->Append (IFMENU_FILTER_REAL, "Re&al");
955 m_pFilterMenu->Append (IFMENU_FILTER_IMAGINARY, "Ima&ginary");
957 wxMenu* image_menu = new wxMenu;
958 image_menu->Append (IFMENU_IMAGE_ADD, "&Add...");
959 image_menu->Append (IFMENU_IMAGE_SUBTRACT, "&Subtract...");
960 image_menu->Append (IFMENU_IMAGE_MULTIPLY, "&Multiply...");
961 image_menu->Append (IFMENU_IMAGE_DIVIDE, "&Divide...");
962 image_menu->AppendSeparator();
963 image_menu->Append (IFMENU_IMAGE_SCALESIZE, "S&cale Size...");
965 image_menu->Append (IFMENU_IMAGE_CONVERT3D, "Convert &3-D\tCtrl-3");
968 m_pMenuAnalyze = new wxMenu;
969 m_pMenuAnalyze->Append (IFMENU_PLOT_ROW, "Plot &Row");
970 m_pMenuAnalyze->Append (IFMENU_PLOT_COL, "Plot &Column");
971 m_pMenuAnalyze->Append (IFMENU_PLOT_HISTOGRAM, "Plot &Histogram");
972 m_pMenuAnalyze->AppendSeparator();
973 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_ROW, "P&lot FFT Row");
974 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_COL, "Plo&t FFT Column");
975 m_pMenuAnalyze->AppendSeparator();
976 m_pMenuAnalyze->Append (IFMENU_COMPARE_IMAGES, "Compare &Images...");
977 m_pMenuAnalyze->Append (IFMENU_COMPARE_ROW, "Compare Ro&w");
978 m_pMenuAnalyze->Append (IFMENU_COMPARE_COL, "Compare Colu&mn");
979 m_pMenuAnalyze->Enable (IFMENU_PLOT_ROW, false);
980 m_pMenuAnalyze->Enable (IFMENU_PLOT_COL, false);
981 m_pMenuAnalyze->Enable (IFMENU_COMPARE_ROW, false);
982 m_pMenuAnalyze->Enable (IFMENU_COMPARE_COL, false);
983 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_ROW, false);
984 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_COL, false);
986 wxMenu *help_menu = new wxMenu;
987 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
988 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
989 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
990 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
992 wxMenuBar *menu_bar = new wxMenuBar;
994 menu_bar->Append(m_pFileMenu, "&File");
995 menu_bar->Append(edit_menu, "&Edit");
996 menu_bar->Append(view_menu, "&View");
997 menu_bar->Append(image_menu, "&Image");
998 menu_bar->Append(m_pFilterMenu, "Fi<er");
999 menu_bar->Append(m_pMenuAnalyze, "&Analyze");
1000 menu_bar->Append(help_menu, "&Help");
1002 subframe->SetMenuBar(menu_bar);
1004 subframe->Centre(wxBOTH);
1006 wxAcceleratorEntry accelEntries[10];
1007 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('A'), IFMENU_VIEW_SCALE_AUTO);
1008 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('U'), IFMENU_VIEW_SCALE_FULL);
1009 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('E'), IFMENU_VIEW_SCALE_MINMAX);
1010 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), IFMENU_FILE_PROPERTIES);
1011 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('C'), IFMENU_EDIT_COPY);
1012 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('X'), IFMENU_EDIT_CUT);
1013 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('V'), IFMENU_EDIT_PASTE);
1016 accelEntries[iEntry++].Set (wxACCEL_CTRL, static_cast<int>('2'), IFMENU_FILTER_FFT);
1017 accelEntries[iEntry++].Set (wxACCEL_ALT, static_cast<int>('2'), IFMENU_FILTER_IFFT);
1020 accelEntries[iEntry++].Set (wxACCEL_CTRL, static_cast<int>('3'), IFMENU_IMAGE_CONVERT3D);
1022 wxAcceleratorTable accelTable (iEntry, accelEntries);
1024 subframe->SetAcceleratorTable (accelTable);
1031 ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
1033 m_bMinSpecified = false;
1034 m_bMaxSpecified = false;
1035 m_dAutoScaleFactor = 1.;
1037 m_pFrame = CreateChildFrame(doc, this);
1038 SetFrame (m_pFrame);
1039 m_pCanvas = CreateCanvas (m_pFrame);
1040 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
1041 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
1042 m_pFrame->SetTitle("ImageFileView");
1044 m_pFrame->Show(true);
1051 ImageFileView::setInitialClientSize ()
1053 if (m_pFrame && m_pCanvas) {
1054 wxSize bestSize = m_pCanvas->GetBestSize();
1056 m_pFrame->SetClientSize (bestSize);
1057 m_pFrame->Show (true);
1058 m_pFrame->SetFocus();
1063 ImageFileView::OnDraw (wxDC* dc)
1066 dc->DrawBitmap(m_bitmap, 0, 0, false);
1068 int xCursor, yCursor;
1069 if (m_pCanvas->GetCurrentCursor (xCursor, yCursor))
1070 m_pCanvas->DrawRubberBandCursor (*dc, xCursor, yCursor);
1075 ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
1077 const ImageFile& rIF = GetDocument()->getImageFile();
1078 if (m_pFilterMenu && rIF.isComplex()) {
1079 m_pFilterMenu->Enable(IFMENU_FILTER_REAL, true);
1080 m_pFilterMenu->Enable(IFMENU_FILTER_IMAGINARY, true);
1081 m_pFilterMenu->Enable(IFMENU_FILTER_PHASE, true);
1083 m_pFilterMenu->Enable(IFMENU_FILTER_REAL, false);
1084 m_pFilterMenu->Enable(IFMENU_FILTER_IMAGINARY, false);
1085 m_pFilterMenu->Enable(IFMENU_FILTER_PHASE, false);
1087 ImageFileArrayConst v = rIF.getArray();
1090 if (v != NULL && nx != 0 && ny != 0) {
1091 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1093 rIF.getMinMax (min, max);
1094 if (! m_bMinSpecified)
1096 if (! m_bMaxSpecified)
1099 double scaleWidth = m_dMaxPixel - m_dMinPixel;
1101 unsigned char* imageData = new unsigned char [nx * ny * 3];
1103 sys_error (ERR_SEVERE, "Unable to allocate memory for Image display");
1106 for (int ix = 0; ix < nx; ix++) {
1107 for (int iy = 0; iy < ny; iy++) {
1108 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
1109 int intensity = static_cast<int>(scaleValue + 0.5);
1110 intensity = clamp (intensity, 0, 255);
1111 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
1112 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
1115 wxImage image (nx, ny, imageData, true);
1116 m_bitmap = image.ConvertToBitmap();
1118 m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20);
1119 m_pCanvas->SetBackgroundColour(*wxWHITE);
1123 m_pCanvas->Refresh();
1127 ImageFileView::OnClose (bool deleteWindow)
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->UpdateAllViews();
1328 pGraph3d->getView()->getFrame()->Show (true);
1329 pGraph3d->getView()->Activate(true);
1331 pGraph3d->getView()->getCanvas()->SetFocus();
1336 ImageFileView::OnPlotRow (wxCommandEvent& event)
1338 int xCursor, yCursor;
1339 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1340 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1344 const ImageFile& rIF = GetDocument()->getImageFile();
1345 ImageFileArrayConst v = rIF.getArray();
1346 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1350 if (v != NULL && yCursor < ny) {
1351 double* pX = new double [nx];
1352 double* pYReal = new double [nx];
1353 double *pYImag = NULL;
1354 double *pYMag = NULL;
1355 if (rIF.isComplex()) {
1356 pYImag = new double [nx];
1357 pYMag = new double [nx];
1359 for (int i = 0; i < nx; i++) {
1361 pYReal[i] = v[i][yCursor];
1362 if (rIF.isComplex()) {
1363 pYImag[i] = vImag[i][yCursor];
1364 pYMag[i] = ::sqrt (v[i][yCursor] * v[i][yCursor] + vImag[i][yCursor] * vImag[i][yCursor]);
1367 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1369 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1371 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1372 std::ostringstream os;
1373 os << "Row " << yCursor;
1374 std::string title("title ");
1376 rPlotFile.addEzsetCommand (title.c_str());
1377 rPlotFile.addEzsetCommand ("xlabel Column");
1378 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1379 rPlotFile.addEzsetCommand ("lxfrac 0");
1380 rPlotFile.addEzsetCommand ("box");
1381 rPlotFile.addEzsetCommand ("grid");
1382 rPlotFile.addEzsetCommand ("curve 1");
1383 rPlotFile.addEzsetCommand ("color 1");
1384 if (rIF.isComplex()) {
1385 rPlotFile.addEzsetCommand ("dash 1");
1386 rPlotFile.addEzsetCommand ("curve 2");
1387 rPlotFile.addEzsetCommand ("color 4");
1388 rPlotFile.addEzsetCommand ("dash 3");
1389 rPlotFile.addEzsetCommand ("curve 3");
1390 rPlotFile.addEzsetCommand ("color 0");
1391 rPlotFile.addEzsetCommand ("solid");
1392 rPlotFile.setCurveSize (4, nx);
1394 rPlotFile.setCurveSize (2, nx);
1395 rPlotFile.addColumn (0, pX);
1396 rPlotFile.addColumn (1, pYReal);
1397 if (rIF.isComplex()) {
1398 rPlotFile.addColumn (2, pYImag);
1399 rPlotFile.addColumn (3, pYMag);
1401 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1402 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1403 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1404 *theApp->getLog() << os.str().c_str() << "\n";
1405 rPlotFile.addDescription (os.str().c_str());
1409 if (rIF.isComplex()) {
1413 if (theApp->getAskDeleteNewDocs())
1414 pPlotDoc->Modify (true);
1415 pPlotDoc->getView()->getFrame()->Show(true);
1416 pPlotDoc->UpdateAllViews ();
1417 pPlotDoc->Activate();
1422 ImageFileView::OnPlotCol (wxCommandEvent& event)
1424 int xCursor, yCursor;
1425 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1426 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1430 const ImageFile& rIF = GetDocument()->getImageFile();
1431 ImageFileArrayConst v = rIF.getArray();
1432 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1436 if (v != NULL && xCursor < nx) {
1437 double* pX = new double [ny];
1438 double* pYReal = new double [ny];
1439 double* pYImag = NULL;
1440 double* pYMag = NULL;
1441 if (rIF.isComplex()) {
1442 pYImag = new double [ny];
1443 pYMag = new double [ny];
1445 for (int i = 0; i < ny; i++) {
1447 pYReal[i] = v[xCursor][i];
1448 if (rIF.isComplex()) {
1449 pYImag[i] = vImag[xCursor][i];
1450 pYMag[i] = ::sqrt (v[xCursor][i] * v[xCursor][i] + vImag[xCursor][i] * vImag[xCursor][i]);
1453 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1455 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1457 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1458 std::ostringstream os;
1459 os << "Column " << xCursor;
1460 std::string title("title ");
1462 rPlotFile.addEzsetCommand (title.c_str());
1463 rPlotFile.addEzsetCommand ("xlabel Row");
1464 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1465 rPlotFile.addEzsetCommand ("lxfrac 0");
1466 rPlotFile.addEzsetCommand ("box");
1467 rPlotFile.addEzsetCommand ("grid");
1468 rPlotFile.addEzsetCommand ("curve 1");
1469 rPlotFile.addEzsetCommand ("color 1");
1470 if (rIF.isComplex()) {
1471 rPlotFile.addEzsetCommand ("dash 1");
1472 rPlotFile.addEzsetCommand ("curve 2");
1473 rPlotFile.addEzsetCommand ("color 4");
1474 rPlotFile.addEzsetCommand ("dash 3");
1475 rPlotFile.addEzsetCommand ("curve 3");
1476 rPlotFile.addEzsetCommand ("color 0");
1477 rPlotFile.addEzsetCommand ("solid");
1478 rPlotFile.setCurveSize (4, ny);
1480 rPlotFile.setCurveSize (2, ny);
1481 rPlotFile.addColumn (0, pX);
1482 rPlotFile.addColumn (1, pYReal);
1483 if (rIF.isComplex()) {
1484 rPlotFile.addColumn (2, pYImag);
1485 rPlotFile.addColumn (3, pYMag);
1487 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1488 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1489 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1490 *theApp->getLog() << os.str().c_str() << "\n";
1491 rPlotFile.addDescription (os.str().c_str());
1495 if (rIF.isComplex()) {
1499 if (theApp->getAskDeleteNewDocs())
1500 pPlotDoc->Modify (true);
1501 pPlotDoc->getView()->getFrame()->Show(true);
1502 pPlotDoc->UpdateAllViews ();
1503 pPlotDoc->Activate();
1509 ImageFileView::OnPlotFFTRow (wxCommandEvent& event)
1511 int xCursor, yCursor;
1512 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1513 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1517 const ImageFile& rIF = GetDocument()->getImageFile();
1518 ImageFileArrayConst v = rIF.getArray();
1519 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1523 if (v != NULL && yCursor < ny) {
1524 fftw_complex* pcIn = new fftw_complex [nx];
1527 for (i = 0; i < nx; i++) {
1528 pcIn[i].re = v[i][yCursor];
1529 if (rIF.isComplex())
1530 pcIn[i].im = vImag[i][yCursor];
1535 fftw_plan plan = fftw_create_plan (nx, FFTW_FORWARD, FFTW_IN_PLACE | FFTW_ESTIMATE | FFTW_USE_WISDOM);
1536 fftw_one (plan, pcIn, NULL);
1537 fftw_destroy_plan (plan);
1539 double* pX = new double [nx];
1540 double* pYReal = new double [nx];
1541 double* pYImag = new double [nx];
1542 double* pYMag = new double [nx];
1543 for (i = 0; i < nx; i++) {
1545 pYReal[i] = pcIn[i].re / nx;
1546 pYImag[i] = pcIn[i].im / nx;
1547 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1549 Fourier::shuffleFourierToNaturalOrder (pYReal, nx);
1550 Fourier::shuffleFourierToNaturalOrder (pYImag, nx);
1551 Fourier::shuffleFourierToNaturalOrder (pYMag, nx);
1553 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1555 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1557 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1558 std::ostringstream os;
1559 os << "Row " << yCursor;
1560 std::string title("title ");
1562 rPlotFile.addEzsetCommand (title.c_str());
1563 rPlotFile.addEzsetCommand ("xlabel Column");
1564 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1565 rPlotFile.addEzsetCommand ("lxfrac 0");
1566 rPlotFile.addEzsetCommand ("curve 1");
1567 rPlotFile.addEzsetCommand ("color 1");
1568 rPlotFile.addEzsetCommand ("dash 1");
1569 rPlotFile.addEzsetCommand ("curve 2");
1570 rPlotFile.addEzsetCommand ("color 4");
1571 rPlotFile.addEzsetCommand ("dash 3");
1572 rPlotFile.addEzsetCommand ("curve 3");
1573 rPlotFile.addEzsetCommand ("color 0");
1574 rPlotFile.addEzsetCommand ("solid");
1575 rPlotFile.addEzsetCommand ("box");
1576 rPlotFile.addEzsetCommand ("grid");
1577 rPlotFile.setCurveSize (4, nx);
1578 rPlotFile.addColumn (0, pX);
1579 rPlotFile.addColumn (1, pYReal);
1580 rPlotFile.addColumn (2, pYImag);
1581 rPlotFile.addColumn (3, pYMag);
1582 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1583 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1584 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1585 *theApp->getLog() << os.str().c_str() << "\n";
1586 rPlotFile.addDescription (os.str().c_str());
1594 if (theApp->getAskDeleteNewDocs())
1595 pPlotDoc->Modify (true);
1596 pPlotDoc->getView()->getFrame()->Show(true);
1597 pPlotDoc->UpdateAllViews ();
1598 pPlotDoc->Activate();
1603 ImageFileView::OnPlotFFTCol (wxCommandEvent& event)
1605 int xCursor, yCursor;
1606 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1607 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1611 const ImageFile& rIF = GetDocument()->getImageFile();
1612 ImageFileArrayConst v = rIF.getArray();
1613 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1617 if (v != NULL && xCursor < nx) {
1618 fftw_complex* pcIn = new fftw_complex [ny];
1619 double *pdTemp = new double [ny];
1622 for (i = 0; i < ny; i++)
1623 pdTemp[i] = v[xCursor][i];
1624 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1625 for (i = 0; i < ny; i++)
1626 pcIn[i].re = pdTemp[i];
1628 for (i = 0; i < ny; i++) {
1629 if (rIF.isComplex())
1630 pdTemp[i] = vImag[xCursor][i];
1634 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1635 for (i = 0; i < ny; i++)
1636 pcIn[i].im = pdTemp[i];
1638 fftw_plan plan = fftw_create_plan (ny, FFTW_BACKWARD, FFTW_IN_PLACE | FFTW_ESTIMATE | FFTW_USE_WISDOM);
1639 fftw_one (plan, pcIn, NULL);
1640 fftw_destroy_plan (plan);
1642 double* pX = new double [ny];
1643 double* pYReal = new double [ny];
1644 double* pYImag = new double [ny];
1645 double* pYMag = new double [ny];
1646 for (i = 0; i < ny; i++) {
1648 pYReal[i] = pcIn[i].re / ny;
1649 pYImag[i] = pcIn[i].im / ny;
1650 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1653 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1655 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1657 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1658 std::ostringstream os;
1659 os << "Column " << xCursor;
1660 std::string title("title ");
1662 rPlotFile.addEzsetCommand (title.c_str());
1663 rPlotFile.addEzsetCommand ("xlabel Column");
1664 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1665 rPlotFile.addEzsetCommand ("lxfrac 0");
1666 rPlotFile.addEzsetCommand ("curve 1");
1667 rPlotFile.addEzsetCommand ("color 1");
1668 rPlotFile.addEzsetCommand ("dash 1");
1669 rPlotFile.addEzsetCommand ("curve 2");
1670 rPlotFile.addEzsetCommand ("color 4");
1671 rPlotFile.addEzsetCommand ("dash 3");
1672 rPlotFile.addEzsetCommand ("curve 3");
1673 rPlotFile.addEzsetCommand ("color 0");
1674 rPlotFile.addEzsetCommand ("solid");
1675 rPlotFile.addEzsetCommand ("box");
1676 rPlotFile.addEzsetCommand ("grid");
1677 rPlotFile.setCurveSize (4, ny);
1678 rPlotFile.addColumn (0, pX);
1679 rPlotFile.addColumn (1, pYReal);
1680 rPlotFile.addColumn (2, pYImag);
1681 rPlotFile.addColumn (3, pYMag);
1682 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1683 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1684 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1685 *theApp->getLog() << os.str().c_str() << "\n";
1686 rPlotFile.addDescription (os.str().c_str());
1695 if (theApp->getAskDeleteNewDocs())
1696 pPlotDoc->Modify (true);
1697 pPlotDoc->getView()->getFrame()->Show(true);
1698 pPlotDoc->UpdateAllViews ();
1699 pPlotDoc->Activate();
1705 ImageFileView::OnCompareCol (wxCommandEvent& event)
1707 int xCursor, yCursor;
1708 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1709 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1713 std::vector<ImageFileDocument*> vecIFDoc;
1714 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1715 if (vecIFDoc.size() == 0) {
1716 wxMessageBox ("No compatible images for Column Comparison", "Error");
1719 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1721 if (dialogGetCompare.ShowModal() == wxID_OK) {
1722 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1723 const ImageFile& rIF = GetDocument()->getImageFile();
1724 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1726 ImageFileArrayConst v1 = rIF.getArray();
1727 ImageFileArrayConst v2 = rCompareIF.getArray();
1731 if (v1 != NULL && xCursor < nx) {
1732 double* pX = new double [ny];
1733 double* pY1 = new double [ny];
1734 double* pY2 = new double [ny];
1735 for (int i = 0; i < ny; i++) {
1737 pY1[i] = v1[xCursor][i];
1738 pY2[i] = v2[xCursor][i];
1740 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1742 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1744 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1745 std::ostringstream os;
1746 os << "Column " << xCursor << " Comparison";
1747 std::string title("title ");
1749 rPlotFile.addEzsetCommand (title.c_str());
1750 rPlotFile.addEzsetCommand ("xlabel Row");
1751 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1752 rPlotFile.addEzsetCommand ("lxfrac 0");
1753 rPlotFile.addEzsetCommand ("curve 1");
1754 rPlotFile.addEzsetCommand ("color 2");
1755 rPlotFile.addEzsetCommand ("curve 2");
1756 rPlotFile.addEzsetCommand ("color 4");
1757 rPlotFile.addEzsetCommand ("dash 5");
1758 rPlotFile.addEzsetCommand ("box");
1759 rPlotFile.addEzsetCommand ("grid");
1760 rPlotFile.setCurveSize (3, ny);
1761 rPlotFile.addColumn (0, pX);
1762 rPlotFile.addColumn (1, pY1);
1763 rPlotFile.addColumn (2, pY2);
1766 for (iL = 0; iL < rIF.nLabels(); iL++) {
1767 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1769 s += rIF.labelGet(iL).getLabelString();
1770 rPlotFile.addDescription (s.c_str());
1772 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1773 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1775 s += rCompareIF.labelGet(iL).getLabelString();
1776 rPlotFile.addDescription (s.c_str());
1778 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1779 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1780 *theApp->getLog() << os.str().c_str() << "\n";
1781 rPlotFile.addDescription (os.str().c_str());
1786 if (theApp->getAskDeleteNewDocs())
1787 pPlotDoc->Modify (true);
1788 pPlotDoc->getView()->getFrame()->Show(true);
1789 pPlotDoc->UpdateAllViews ();
1790 pPlotDoc->Activate();
1796 ImageFileView::OnCompareRow (wxCommandEvent& event)
1798 int xCursor, yCursor;
1799 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1800 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1804 std::vector<ImageFileDocument*> vecIFDoc;
1805 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1807 if (vecIFDoc.size() == 0) {
1808 wxMessageBox ("No compatible images for Row Comparison", "Error");
1812 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1814 if (dialogGetCompare.ShowModal() == wxID_OK) {
1815 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1816 const ImageFile& rIF = GetDocument()->getImageFile();
1817 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1819 ImageFileArrayConst v1 = rIF.getArray();
1820 ImageFileArrayConst v2 = rCompareIF.getArray();
1824 if (v1 != NULL && yCursor < ny) {
1825 double* pX = new double [nx];
1826 double* pY1 = new double [nx];
1827 double* pY2 = new double [nx];
1828 for (int i = 0; i < nx; i++) {
1830 pY1[i] = v1[i][yCursor];
1831 pY2[i] = v2[i][yCursor];
1833 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1835 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1837 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1838 std::ostringstream os;
1839 os << "Row " << yCursor << " Comparison";
1840 std::string title("title ");
1842 rPlotFile.addEzsetCommand (title.c_str());
1843 rPlotFile.addEzsetCommand ("xlabel Column");
1844 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1845 rPlotFile.addEzsetCommand ("lxfrac 0");
1846 rPlotFile.addEzsetCommand ("curve 1");
1847 rPlotFile.addEzsetCommand ("color 2");
1848 rPlotFile.addEzsetCommand ("curve 2");
1849 rPlotFile.addEzsetCommand ("color 4");
1850 rPlotFile.addEzsetCommand ("dash 5");
1851 rPlotFile.addEzsetCommand ("box");
1852 rPlotFile.addEzsetCommand ("grid");
1853 rPlotFile.setCurveSize (3, nx);
1854 rPlotFile.addColumn (0, pX);
1855 rPlotFile.addColumn (1, pY1);
1856 rPlotFile.addColumn (2, pY2);
1858 for (iL = 0; iL < rIF.nLabels(); iL++) {
1859 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1861 s += rIF.labelGet(iL).getLabelString();
1862 rPlotFile.addDescription (s.c_str());
1864 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1865 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1867 s += rCompareIF.labelGet(iL).getLabelString();
1868 rPlotFile.addDescription (s.c_str());
1870 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1871 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1872 *theApp->getLog() << os.str().c_str() << "\n";
1873 rPlotFile.addDescription (os.str().c_str());
1878 if (theApp->getAskDeleteNewDocs())
1879 pPlotDoc->Modify (true);
1880 pPlotDoc->getView()->getFrame()->Show(true);
1881 pPlotDoc->UpdateAllViews ();
1882 pPlotDoc->Activate();
1887 static int NUMBER_HISTOGRAM_BINS = 256;
1890 ImageFileView::OnPlotHistogram (wxCommandEvent& event)
1892 const ImageFile& rIF = GetDocument()->getImageFile();
1893 ImageFileArrayConst v = rIF.getArray();
1897 if (v != NULL && nx > 0 && ny > 0) {
1898 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1900 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1904 double* pX = new double [NUMBER_HISTOGRAM_BINS];
1905 double* pY = new double [NUMBER_HISTOGRAM_BINS];
1907 rIF.getMinMax (dMin, dMax);
1908 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
1910 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
1911 pX[i] = dMin + (i + 0.5) * dBinWidth;
1914 for (int ix = 0; ix < nx; ix++)
1915 for (int iy = 0; iy < ny; iy++) {
1916 int iBin = nearest<int> ((v[ix][iy] - dMin) / dBinWidth);
1917 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
1921 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1922 std::ostringstream os;
1924 std::string title("title ");
1926 rPlotFile.addEzsetCommand (title.c_str());
1927 rPlotFile.addEzsetCommand ("xlabel Pixel Value");
1928 rPlotFile.addEzsetCommand ("ylabel Count");
1929 rPlotFile.addEzsetCommand ("box");
1930 rPlotFile.addEzsetCommand ("grid");
1931 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
1932 rPlotFile.addColumn (0, pX);
1933 rPlotFile.addColumn (1, pY);
1934 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++) {
1935 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1937 s += rIF.labelGet(iL).getLabelString();
1938 rPlotFile.addDescription (s.c_str());
1940 os << " plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1941 *theApp->getLog() << os.str().c_str() << "\n";
1942 rPlotFile.addDescription (os.str().c_str());
1945 if (theApp->getAskDeleteNewDocs())
1946 pPlotDoc->Modify (true);
1947 pPlotDoc->getView()->getFrame()->Show(true);
1948 pPlotDoc->UpdateAllViews ();
1949 pPlotDoc->Activate();
1956 PhantomCanvas::PhantomCanvas (PhantomFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1957 : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v)
1961 PhantomCanvas::~PhantomCanvas ()
1967 PhantomCanvas::OnDraw (wxDC& dc)
1970 m_pView->OnDraw(& dc);
1974 PhantomCanvas::GetBestSize() const
1980 theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
1981 xSize = maxValue<int> (xSize, ySize);
1983 ySize = xSize = (xSize / 4);
1985 xSize = ySize = static_cast<int>(ySize * .7);
1988 return wxSize (xSize, ySize);
1995 IMPLEMENT_DYNAMIC_CLASS(PhantomFileView, wxView)
1997 BEGIN_EVENT_TABLE(PhantomFileView, wxView)
1998 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomFileView::OnProperties)
1999 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomFileView::OnRasterize)
2000 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomFileView::OnProjections)
2003 PhantomFileView::PhantomFileView()
2004 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0)
2006 #if defined(DEBUG) || defined(_DEBUG)
2007 m_iDefaultNDet = 165;
2008 m_iDefaultNView = 180;
2009 m_iDefaultNSample = 1;
2011 m_iDefaultNDet = 367;
2012 m_iDefaultNView = 320;
2013 m_iDefaultNSample = 2;
2015 m_iDefaultOffsetView = 0;
2016 m_dDefaultRotation = 1;
2017 m_dDefaultFocalLength = 2;
2018 m_dDefaultCenterDetectorLength = 2;
2019 m_dDefaultViewRatio = 1;
2020 m_dDefaultScanRatio = 1;
2021 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
2022 m_iDefaultTrace = Trace::TRACE_NONE;
2025 m_iDefaultRasterNX = 115;
2026 m_iDefaultRasterNY = 115;
2027 m_iDefaultRasterNSamples = 1;
2029 m_iDefaultRasterNX = 256;
2030 m_iDefaultRasterNY = 256;
2031 m_iDefaultRasterNSamples = 2;
2033 m_dDefaultRasterViewRatio = 1;
2036 PhantomFileView::~PhantomFileView()
2038 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2039 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
2043 PhantomFileView::OnProperties (wxCommandEvent& event)
2045 const int idPhantom = GetDocument()->getPhantomID();
2046 const wxString& namePhantom = GetDocument()->getPhantomName();
2047 std::ostringstream os;
2048 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")" << "\n";
2049 const Phantom& rPhantom = GetDocument()->getPhantom();
2050 rPhantom.printDefinitions (os);
2052 rPhantom.print (os);
2054 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2055 wxMessageBox (os.str().c_str(), "Phantom Properties");
2056 GetDocument()->Activate();
2061 PhantomFileView::OnProjections (wxCommandEvent& event)
2063 DialogGetProjectionParameters dialogProjection (getFrameForChild(),
2064 m_iDefaultNDet, m_iDefaultNView, m_iDefaultOffsetView, m_iDefaultNSample, m_dDefaultRotation,
2065 m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio,
2066 m_iDefaultGeometry, m_iDefaultTrace);
2067 int retVal = dialogProjection.ShowModal();
2068 if (retVal != wxID_OK)
2071 m_iDefaultNDet = dialogProjection.getNDet();
2072 m_iDefaultNView = dialogProjection.getNView();
2073 m_iDefaultOffsetView = dialogProjection.getOffsetView();
2074 m_iDefaultNSample = dialogProjection.getNSamples();
2075 m_iDefaultTrace = dialogProjection.getTrace();
2076 m_dDefaultRotation = dialogProjection.getRotAngle();
2077 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
2078 m_dDefaultCenterDetectorLength = dialogProjection.getCenterDetectorLengthRatio();
2079 m_dDefaultViewRatio = dialogProjection.getViewRatio();
2080 m_dDefaultScanRatio = dialogProjection.getScanRatio();
2081 wxString sGeometry = dialogProjection.getGeometry();
2082 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
2083 double dRotationRadians = m_dDefaultRotation;
2084 m_dDefaultRotation /= TWOPI; // convert back to fraction of a circle
2086 if (m_iDefaultNDet <= 0 || m_iDefaultNView <= 0 || sGeometry == "")
2089 const Phantom& rPhantom = GetDocument()->getPhantom();
2090 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultOffsetView, m_iDefaultNSample,
2091 dRotationRadians, m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio);
2092 if (theScanner.fail()) {
2093 wxString msg = "Failed making scanner\n";
2094 msg += theScanner.failMessage().c_str();
2095 *theApp->getLog() << msg << "\n";
2096 wxMessageBox (msg, "Error");
2100 std::ostringstream os;
2101 os << "Projections for " << rPhantom.name()
2102 << ": nDet=" << m_iDefaultNDet
2103 << ", nView=" << m_iDefaultNView
2104 << ", gantry offset=" << m_iDefaultOffsetView
2105 << ", nSamples=" << m_iDefaultNSample
2106 << ", RotAngle=" << m_dDefaultRotation
2107 << ", FocalLengthRatio=" << m_dDefaultFocalLength
2108 << ", CenterDetectorLengthRatio=" << m_dDefaultCenterDetectorLength
2109 << ", ViewRatio=" << m_dDefaultViewRatio
2110 << ", ScanRatio=" << m_dDefaultScanRatio
2111 << ", Geometry=" << sGeometry.c_str()
2112 << ", FanBeamAngle=" << convertRadiansToDegrees (theScanner.fanBeamAngle());
2115 Projections* pProj = NULL;
2116 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2117 pProj = new Projections;
2118 pProj->initFromScanner (theScanner);
2120 ProjectionsDialog dialogProjections (theScanner, *pProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(getFrameForChild()));
2121 for (int iView = 0; iView < pProj->nView(); iView++) {
2123 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
2128 while (dialogProjections.isPaused()) {
2135 if (theApp->getUseBackgroundTasks()) {
2136 ProjectorSupervisorThread* pProjector = new ProjectorSupervisorThread (this, m_iDefaultNDet,
2137 m_iDefaultNView, m_iDefaultOffsetView, sGeometry.c_str(), m_iDefaultNSample, dRotationRadians,
2138 m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio, os.str().c_str());
2139 if (pProjector->Create() != wxTHREAD_NO_ERROR) {
2140 sys_error (ERR_SEVERE, "Error creating projector thread");
2144 pProjector->SetPriority(60);
2148 #endif // HAVE_WXTHREADS
2150 pProj = new Projections;
2151 pProj->initFromScanner (theScanner);
2152 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), pProj->nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2153 for (int i = 0; i < pProj->nView(); i++) {
2154 //theScanner.collectProjections (*pProj, rPhantom, i, 1, true, m_iDefaultTrace);
2155 theScanner.collectProjections (*pProj, rPhantom, i, 1, theScanner.offsetView(), true, m_iDefaultTrace);
2156 if ((i + 1) % ITER_PER_UPDATE == 0)
2157 if (! dlgProgress.Update (i+1)) {
2165 *theApp->getLog() << os.str().c_str() << "\n";
2166 pProj->setRemark (os.str());
2167 pProj->setCalcTime (timer.timerEnd());
2169 ProjectionFileDocument* pProjectionDoc = theApp->newProjectionDoc();
2170 if (! pProjectionDoc) {
2171 sys_error (ERR_SEVERE, "Unable to create projection document");
2174 pProjectionDoc->setProjections (pProj);
2175 if (theApp->getAskDeleteNewDocs())
2176 pProjectionDoc-> Modify(true);
2177 pProjectionDoc->UpdateAllViews (this);
2178 pProjectionDoc->getView()->setInitialClientSize();
2179 pProjectionDoc->Activate();
2184 PhantomFileView::OnRasterize (wxCommandEvent& event)
2186 DialogGetRasterParameters dialogRaster (getFrameForChild(), m_iDefaultRasterNX, m_iDefaultRasterNY,
2187 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio);
2188 int retVal = dialogRaster.ShowModal();
2189 if (retVal != wxID_OK)
2192 m_iDefaultRasterNX = dialogRaster.getXSize();
2193 m_iDefaultRasterNY = dialogRaster.getYSize();
2194 m_iDefaultRasterNSamples = dialogRaster.getNSamples();
2195 m_dDefaultRasterViewRatio = dialogRaster.getViewRatio();
2196 if (m_iDefaultRasterNSamples < 1)
2197 m_iDefaultRasterNSamples = 1;
2198 if (m_dDefaultRasterViewRatio < 0)
2199 m_dDefaultRasterViewRatio = 0;
2200 if (m_iDefaultRasterNX <= 0 || m_iDefaultRasterNY <= 0)
2203 const Phantom& rPhantom = GetDocument()->getPhantom();
2204 std::ostringstream os;
2205 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << m_iDefaultRasterNX << ", YSize="
2206 << m_iDefaultRasterNY << ", ViewRatio=" << m_dDefaultRasterViewRatio << ", nSamples="
2207 << m_iDefaultRasterNSamples;;
2210 if (theApp->getUseBackgroundTasks()) {
2211 RasterizerSupervisorThread* pThread = new RasterizerSupervisorThread (this, m_iDefaultRasterNX, m_iDefaultRasterNY,
2212 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio, os.str().c_str());
2213 if (pThread->Create() != wxTHREAD_NO_ERROR) {
2214 *theApp->getLog() << "Error creating rasterizer thread\n";
2217 pThread->SetPriority (60);
2222 ImageFile* pImageFile = new ImageFile (m_iDefaultRasterNX, m_iDefaultRasterNY);
2224 wxProgressDialog dlgProgress (wxString("Rasterize"),
2225 wxString("Rasterization Progress"),
2226 pImageFile->nx() + 1,
2230 for (unsigned int i = 0; i < pImageFile->nx(); i++) {
2231 rPhantom.convertToImagefile (*pImageFile, m_dDefaultRasterViewRatio,
2232 m_iDefaultRasterNSamples, Trace::TRACE_NONE,
2234 if ((i + 1) % ITER_PER_UPDATE == 0)
2235 if (! dlgProgress.Update (i+1)) {
2241 ImageFileDocument* pRasterDoc = theApp->newImageDoc();
2243 sys_error (ERR_SEVERE, "Unable to create image file");
2246 pRasterDoc->setImageFile (pImageFile);
2247 if (theApp->getAskDeleteNewDocs())
2248 pRasterDoc->Modify (true);
2249 *theApp->getLog() << os.str().c_str() << "\n";
2250 pImageFile->labelAdd (os.str().c_str(), timer.timerEnd());
2252 pRasterDoc->UpdateAllViews(this);
2253 pRasterDoc->getView()->setInitialClientSize();
2254 pRasterDoc->Activate();
2260 PhantomFileView::CreateCanvas (wxFrame *parent)
2262 PhantomCanvas* pCanvas = new PhantomCanvas (this, parent, wxPoint(0, 0),
2264 pCanvas->SetBackgroundColour(*wxWHITE);
2275 PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2278 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2280 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2282 theApp->setIconForFrame (subframe);
2284 m_pFileMenu = new wxMenu;
2286 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2287 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2288 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2289 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2290 m_pFileMenu->Append(wxID_CLOSE, "&Close");
2292 m_pFileMenu->AppendSeparator();
2293 m_pFileMenu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
2295 m_pFileMenu->AppendSeparator();
2296 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2297 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2298 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2299 m_pFileMenu->AppendSeparator();
2300 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
2302 m_pFileMenu->AppendSeparator();
2303 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
2304 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2306 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2307 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2309 wxMenu *process_menu = new wxMenu;
2310 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...\tCtrl-R");
2311 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...\tCtrl-J");
2313 wxMenu *help_menu = new wxMenu;
2314 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2315 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
2316 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
2317 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2319 wxMenuBar *menu_bar = new wxMenuBar;
2321 menu_bar->Append(m_pFileMenu, "&File");
2322 menu_bar->Append(process_menu, "&Process");
2323 menu_bar->Append(help_menu, "&Help");
2325 subframe->SetMenuBar(menu_bar);
2326 subframe->Centre(wxBOTH);
2328 wxAcceleratorEntry accelEntries[3];
2329 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('J'), PHMMENU_PROCESS_PROJECTIONS);
2330 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('R'), PHMMENU_PROCESS_RASTERIZE);
2331 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('I'), PHMMENU_FILE_PROPERTIES);
2332 wxAcceleratorTable accelTable (3, accelEntries);
2333 subframe->SetAcceleratorTable (accelTable);
2340 PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2342 m_pFrame = CreateChildFrame(doc, this);
2344 m_pCanvas = CreateCanvas (m_pFrame);
2345 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
2346 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
2347 m_pFrame->SetTitle ("PhantomFileView");
2349 m_pFrame->Show(true);
2356 PhantomFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2359 m_pCanvas->Refresh();
2363 PhantomFileView::OnClose (bool deleteWindow)
2365 if (! GetDocument() || ! GetDocument()->Close())
2370 m_pCanvas->setView(NULL);
2373 wxString s(wxTheApp->GetAppName());
2375 m_pFrame->SetTitle(s);
2382 if (GetDocument() && GetDocument()->getBadFileOpen())
2383 ::wxYield(); // wxWindows bug workaround
2390 PhantomFileView::OnDraw (wxDC* dc)
2393 m_pCanvas->GetClientSize (&xsize, &ysize);
2394 SGPDriver driver (dc, xsize, ysize);
2396 const Phantom& rPhantom = GetDocument()->getPhantom();
2397 sgp.setColor (C_RED);
2398 rPhantom.show (sgp);
2403 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2404 : wxScrolledWindow(frame, -1, pos, size, style)
2409 ProjectionFileCanvas::~ProjectionFileCanvas ()
2415 ProjectionFileCanvas::OnDraw(wxDC& dc)
2418 m_pView->OnDraw(& dc);
2422 ProjectionFileCanvas::GetBestSize () const
2424 const int iMinX = 50;
2425 const int iMinY = 20;
2426 wxSize bestSize (iMinX,iMinY);
2429 Projections& rProj = m_pView->GetDocument()->getProjections();
2430 bestSize.Set (rProj.nDet(), rProj.nView());
2433 if (bestSize.x > 800)
2435 if (bestSize.y > 800)
2438 if (bestSize.x < iMinX)
2440 if (bestSize.y < iMinY)
2447 // ProjectionFileView
2449 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
2451 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
2452 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
2453 EVT_MENU(PJMENU_RECONSTRUCT_FBP, ProjectionFileView::OnReconstructFBP)
2454 EVT_MENU(PJMENU_RECONSTRUCT_FBP_REBIN, ProjectionFileView::OnReconstructFBPRebin)
2455 EVT_MENU(PJMENU_RECONSTRUCT_FOURIER, ProjectionFileView::OnReconstructFourier)
2456 EVT_MENU(PJMENU_CONVERT_RECTANGULAR, ProjectionFileView::OnConvertRectangular)
2457 EVT_MENU(PJMENU_CONVERT_POLAR, ProjectionFileView::OnConvertPolar)
2458 EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
2459 EVT_MENU(PJMENU_CONVERT_PARALLEL, ProjectionFileView::OnConvertParallel)
2460 EVT_MENU(PJMENU_PLOT_TTHETA_SAMPLING, ProjectionFileView::OnPlotTThetaSampling)
2461 EVT_MENU(PJMENU_PLOT_HISTOGRAM, ProjectionFileView::OnPlotHistogram)
2462 // EVT_MENU(PJMENU_ARTIFACT_REDUCTION, ProjectionFileView::OnArtifactReduction)
2466 ProjectionFileView::ProjectionFileView()
2467 : wxView(), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0)
2477 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
2478 m_dDefaultFilterParam = 1.;
2480 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
2481 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
2483 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
2484 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
2486 m_iDefaultZeropad = 1;
2487 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF;
2488 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
2489 m_iDefaultInterpParam = 1;
2490 m_iDefaultTrace = Trace::TRACE_NONE;
2492 m_iDefaultPolarNX = 256;
2493 m_iDefaultPolarNY = 256;
2494 m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR;
2495 m_iDefaultPolarZeropad = 1;
2498 ProjectionFileView::~ProjectionFileView()
2500 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2501 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2505 ProjectionFileView::OnProperties (wxCommandEvent& event)
2507 const Projections& rProj = GetDocument()->getProjections();
2508 std::ostringstream os;
2509 rProj.printScanInfo(os);
2510 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2511 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
2512 dialogMsg.ShowModal();
2513 GetDocument()->Activate();
2518 ProjectionFileView::OnConvertRectangular (wxCommandEvent& event)
2520 Projections& rProj = GetDocument()->getProjections();
2522 int nDet = rProj.nDet();
2523 int nView = rProj.nView();
2524 ImageFile* pIF = new ImageFile (nDet, nView);
2525 ImageFileArray v = pIF->getArray();
2526 for (int iv = 0; iv < nView; iv++) {
2527 DetectorValue* detval = rProj.getDetectorArray(iv).detValues();
2529 for (int id = 0; id < nDet; id++)
2530 v[id][iv] = detval[id];
2533 ImageFileDocument* pRectDoc = theApp->newImageDoc ();
2535 sys_error (ERR_SEVERE, "Unable to create image file");
2538 pRectDoc->setImageFile (pIF);
2539 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2540 std::ostringstream os;
2541 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to rectangular image";
2542 *theApp->getLog() << os.str().c_str() << "\n";
2543 pIF->labelAdd (os.str().c_str());
2544 if (theApp->getAskDeleteNewDocs())
2545 pRectDoc->Modify (true);
2546 pRectDoc->UpdateAllViews();
2547 pRectDoc->getView()->setInitialClientSize();
2548 pRectDoc->Activate();
2552 ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
2554 Projections& rProj = GetDocument()->getProjections();
2555 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2556 m_iDefaultPolarInterpolation, -1, IDH_DLG_POLAR);
2557 if (dialogPolar.ShowModal() == wxID_OK) {
2558 wxProgressDialog dlgProgress (wxString("Convert Polar"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2559 wxString strInterpolation (dialogPolar.getInterpolationName());
2560 m_iDefaultPolarNX = dialogPolar.getXSize();
2561 m_iDefaultPolarNY = dialogPolar.getYSize();
2562 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2563 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2564 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2566 if (! rProj.convertPolar (*pIF, m_iDefaultPolarInterpolation)) {
2568 *theApp->getLog() << "Error converting to Polar\n";
2572 pPolarDoc = theApp->newImageDoc ();
2574 sys_error (ERR_SEVERE, "Unable to create image file");
2577 pPolarDoc->setImageFile (pIF);
2578 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2579 std::ostringstream os;
2580 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to polar image: xSize="
2581 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2582 << strInterpolation.c_str();
2583 *theApp->getLog() << os.str().c_str() << "\n";
2584 pIF->labelAdd (os.str().c_str());
2585 if (theApp->getAskDeleteNewDocs())
2586 pPolarDoc->Modify (true);
2587 pPolarDoc->UpdateAllViews ();
2588 pPolarDoc->getView()->setInitialClientSize();
2589 pPolarDoc->Activate();
2594 ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
2596 Projections& rProj = GetDocument()->getProjections();
2597 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert to FFT Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2598 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad, IDH_DLG_FFT_POLAR);
2599 if (dialogPolar.ShowModal() == wxID_OK) {
2600 wxProgressDialog dlgProgress (wxString("Convert FFT Polar"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2601 wxString strInterpolation (dialogPolar.getInterpolationName());
2602 m_iDefaultPolarNX = dialogPolar.getXSize();
2603 m_iDefaultPolarNY = dialogPolar.getYSize();
2604 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2605 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2607 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2608 if (! rProj.convertFFTPolar (*pIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad)) {
2610 *theApp->getLog() << "Error converting to polar\n";
2613 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2615 sys_error (ERR_SEVERE, "Unable to create image file");
2618 pPolarDoc->setImageFile (pIF);
2619 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2620 std::ostringstream os;
2621 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to FFT polar image: xSize="
2622 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2623 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2624 *theApp->getLog() << os.str().c_str() << "\n";
2625 pIF->labelAdd (os.str().c_str());
2626 if (theApp->getAskDeleteNewDocs())
2627 pPolarDoc->Modify (true);
2628 pPolarDoc->UpdateAllViews (this);
2629 pPolarDoc->getView()->setInitialClientSize();
2630 pPolarDoc->Activate();
2635 ProjectionFileView::OnPlotTThetaSampling (wxCommandEvent& event)
2637 DialogGetThetaRange dlgTheta (this->getFrame(), ParallelRaysums::THETA_RANGE_UNCONSTRAINED);
2638 if (dlgTheta.ShowModal() != wxID_OK)
2641 int iThetaRange = dlgTheta.getThetaRange();
2643 Projections& rProj = GetDocument()->getProjections();
2644 ParallelRaysums parallel (&rProj, iThetaRange);
2645 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
2646 PlotFile& rPlot = pPlotDoc->getPlotFile();
2647 ParallelRaysums::CoordinateContainer& coordContainer = parallel.getCoordinates();
2648 double* pdT = new double [parallel.getNumCoordinates()];
2649 double* pdTheta = new double [parallel.getNumCoordinates()];
2651 for (int i = 0; i < parallel.getNumCoordinates(); i++) {
2652 pdT[i] = coordContainer[i]->m_dT;
2653 pdTheta[i] = coordContainer[i]->m_dTheta;
2655 rPlot.setCurveSize (2, parallel.getNumCoordinates(), true);
2656 rPlot.addEzsetCommand ("title T-Theta Sampling");
2657 rPlot.addEzsetCommand ("xlabel T");
2658 rPlot.addEzsetCommand ("ylabel Theta");
2659 rPlot.addEzsetCommand ("curve 1");
2660 if (rProj.nDet() < 50 && rProj.nView() < 50)
2661 rPlot.addEzsetCommand ("symbol 1"); // x symbol
2663 rPlot.addEzsetCommand ("symbol 6"); // point symbol
2664 rPlot.addEzsetCommand ("noline");
2665 rPlot.addColumn (0, pdT);
2666 rPlot.addColumn (1, pdTheta);
2669 if (theApp->getAskDeleteNewDocs())
2670 pPlotDoc->Modify (true);
2671 pPlotDoc->getView()->getFrame()->Show(true);
2672 pPlotDoc->UpdateAllViews ();
2673 pPlotDoc->Activate();
2678 ProjectionFileView::OnPlotHistogram (wxCommandEvent& event)
2680 Projections& rProj = GetDocument()->getProjections();
2681 int nDet = rProj.nDet();
2682 int nView = rProj.nView();
2684 if (nDet < 1 || nView < 1)
2687 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
2689 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
2693 DetectorValue* pdDetval = rProj.getDetectorArray(0).detValues();
2694 double dMin = pdDetval[0], dMax = pdDetval[0];
2696 for (int iv = 0; iv < nView; iv++) {
2697 pdDetval = rProj.getDetectorArray(iv).detValues();
2698 for (int id = 0; id < nDet; id++) {
2699 double dV = pdDetval[id];
2707 double* pX = new double [NUMBER_HISTOGRAM_BINS];
2708 double* pY = new double [NUMBER_HISTOGRAM_BINS];
2709 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
2711 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
2712 pX[i] = dMin + (i + 0.5) * dBinWidth;
2715 for (int j = 0; j < nView; j++) {
2716 pdDetval = rProj.getDetectorArray(j).detValues();
2717 for (int id = 0; id < nDet; id++) {
2718 int iBin = nearest<int> ((pdDetval[id] - dMin) / dBinWidth);
2719 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
2723 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
2724 std::ostringstream os;
2726 std::string title("title ");
2728 rPlotFile.addEzsetCommand (title.c_str());
2729 rPlotFile.addEzsetCommand ("xlabel Detector Value");
2730 rPlotFile.addEzsetCommand ("ylabel Count");
2731 rPlotFile.addEzsetCommand ("box");
2732 rPlotFile.addEzsetCommand ("grid");
2733 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
2734 rPlotFile.addColumn (0, pX);
2735 rPlotFile.addColumn (1, pY);
2736 rPlotFile.addDescription (rProj.remark());
2737 os << " plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
2738 *theApp->getLog() << os.str().c_str() << "\n";
2739 rPlotFile.addDescription (os.str().c_str());
2742 if (theApp->getAskDeleteNewDocs())
2743 pPlotDoc->Modify (true);
2744 pPlotDoc->getView()->getFrame()->Show(true);
2745 pPlotDoc->UpdateAllViews ();
2746 pPlotDoc->Activate();
2751 ProjectionFileView::OnConvertParallel (wxCommandEvent& event)
2753 Projections& rProj = GetDocument()->getProjections();
2754 if (rProj.geometry() == Scanner::GEOMETRY_PARALLEL) {
2755 wxMessageBox ("Projections are already parallel", "Error");
2758 wxProgressDialog dlgProgress (wxString("Convert to Parallel"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2759 Projections* pProjNew = rProj.interpolateToParallel();
2760 ProjectionFileDocument* pProjDocNew = theApp->newProjectionDoc();
2761 pProjDocNew->setProjections (pProjNew);
2763 if (ProjectionFileView* projView = pProjDocNew->getView()) {
2764 projView->OnUpdate (projView, NULL);
2765 if (projView->getCanvas())
2766 projView->getCanvas()->SetClientSize (pProjNew->nDet(), pProjNew->nView());
2767 if (wxFrame* pFrame = projView->getFrame()) {
2772 GetDocumentManager()->ActivateView (projView, true, false);
2774 if (theApp->getAskDeleteNewDocs())
2775 pProjDocNew-> Modify(true);
2776 pProjDocNew->UpdateAllViews (this);
2777 pProjDocNew->getView()->setInitialClientSize();
2778 pProjDocNew->Activate();
2782 ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
2784 Projections& rProj = GetDocument()->getProjections();
2785 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Fourier Reconstruction", m_iDefaultPolarNX, m_iDefaultPolarNY,
2786 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad, IDH_DLG_RECON_FOURIER);
2787 if (dialogPolar.ShowModal() == wxID_OK) {
2788 wxProgressDialog dlgProgress (wxString("Reconstruction Fourier"), wxString("Reconstruction Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2789 wxString strInterpolation (dialogPolar.getInterpolationName());
2790 m_iDefaultPolarNX = dialogPolar.getXSize();
2791 m_iDefaultPolarNY = dialogPolar.getYSize();
2792 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2793 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2795 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2796 if (! rProj.convertFFTPolar (*pIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad)) {
2798 *theApp->getLog() << "Error converting to polar\n";
2804 pIF->magnitude(*pIF);
2805 Fourier::shuffleFourierToNaturalOrder (*pIF);
2807 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2809 sys_error (ERR_SEVERE, "Unable to create image file");
2812 pPolarDoc->setImageFile (pIF);
2813 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2814 std::ostringstream os;
2815 os << "Reconstruct Fourier " << GetFrame()->GetTitle().c_str() << ": xSize="
2816 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2817 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2818 *theApp->getLog() << os.str().c_str() << "\n";
2819 pIF->labelAdd (os.str().c_str());
2820 if (theApp->getAskDeleteNewDocs())
2821 pPolarDoc->Modify (true);
2822 pPolarDoc->UpdateAllViews ();
2823 pPolarDoc->getView()->setInitialClientSize();
2824 pPolarDoc->Activate();
2829 ProjectionFileView::OnReconstructFBPRebin (wxCommandEvent& event)
2831 Projections& rProj = GetDocument()->getProjections();
2832 doReconstructFBP (rProj, true);
2836 ProjectionFileView::OnReconstructFBP (wxCommandEvent& event)
2838 Projections& rProj = GetDocument()->getProjections();
2839 doReconstructFBP (rProj, false);
2843 ProjectionFileView::doReconstructFBP (const Projections& rProj, bool bRebinToParallel)
2845 ReconstructionROI defaultROI;
2846 defaultROI.m_dXMin = -rProj.phmLen() / 2;
2847 defaultROI.m_dXMax = defaultROI.m_dXMin + rProj.phmLen();
2848 defaultROI.m_dYMin = -rProj.phmLen() / 2;
2849 defaultROI.m_dYMax = defaultROI.m_dYMin + rProj.phmLen();
2851 DialogGetReconstructionParameters dialogReconstruction (getFrameForChild(), m_iDefaultNX, m_iDefaultNY,
2852 m_iDefaultFilter, m_dDefaultFilterParam, m_iDefaultFilterMethod, m_iDefaultFilterGeneration,
2853 m_iDefaultZeropad, m_iDefaultInterpolation, m_iDefaultInterpParam, m_iDefaultBackprojector,
2854 m_iDefaultTrace, &defaultROI);
2856 int retVal = dialogReconstruction.ShowModal();
2857 if (retVal != wxID_OK)
2860 m_iDefaultNX = dialogReconstruction.getXSize();
2861 m_iDefaultNY = dialogReconstruction.getYSize();
2862 wxString optFilterName = dialogReconstruction.getFilterName();
2863 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
2864 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
2865 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
2866 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
2867 m_iDefaultZeropad = dialogReconstruction.getZeropad();
2868 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
2869 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
2870 wxString optInterpName = dialogReconstruction.getInterpName();
2871 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
2872 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
2873 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
2874 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
2875 m_iDefaultTrace = dialogReconstruction.getTrace();
2876 dialogReconstruction.getROI (&defaultROI);
2878 if (m_iDefaultNX <= 0 && m_iDefaultNY <= 0)
2881 std::ostringstream os;
2882 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();
2883 if (bRebinToParallel)
2884 os << "; Interpolate to Parallel";
2887 ImageFile* pImageFile = NULL;
2888 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2889 pImageFile = new ImageFile (m_iDefaultNX, m_iDefaultNY);
2890 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2891 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2892 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace,
2893 &defaultROI, bRebinToParallel);
2895 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstructor, rProj, *pImageFile, m_iDefaultTrace, getFrameForChild());
2896 for (int iView = 0; iView < rProj.nView(); iView++) {
2898 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView, true)) {
2899 delete pDlgReconstruct;
2900 delete pReconstructor;
2905 while (pDlgReconstruct->isPaused()) {
2910 pReconstructor->postProcessing();
2911 delete pDlgReconstruct;
2912 delete pReconstructor;
2915 if (theApp->getUseBackgroundTasks()) {
2916 ReconstructorSupervisorThread* pReconstructor = new ReconstructorSupervisorThread (this, m_iDefaultNX,
2917 m_iDefaultNY, optFilterName.c_str(), m_dDefaultFilterParam, optFilterMethodName.c_str(),
2918 m_iDefaultZeropad, optFilterGenerationName.c_str(), optInterpName.c_str(), m_iDefaultInterpParam,
2919 optBackprojectName.c_str(), os.str().c_str(), &defaultROI, bRebinToParallel);
2920 if (pReconstructor->Create() != wxTHREAD_NO_ERROR) {
2921 sys_error (ERR_SEVERE, "Error creating reconstructor thread");
2922 delete pReconstructor;
2925 pReconstructor->SetPriority (60);
2926 pReconstructor->Run();
2931 pImageFile = new ImageFile (m_iDefaultNX, m_iDefaultNY);
2932 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2933 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2934 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2935 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace,
2936 &defaultROI, bRebinToParallel);
2938 for (int iView = 0; iView < rProj.nView(); iView++) {
2939 pReconstructor->reconstructView (iView, 1);
2940 if ((iView + 1) % ITER_PER_UPDATE == 0)
2941 if (! dlgProgress.Update (iView + 1)) {
2942 delete pReconstructor;
2943 return; // don't make new window, thread will do this
2946 pReconstructor->postProcessing();
2947 delete pReconstructor;
2950 ImageFileDocument* pReconDoc = theApp->newImageDoc();
2952 sys_error (ERR_SEVERE, "Unable to create image file");
2955 *theApp->getLog() << os.str().c_str() << "\n";
2956 pImageFile->labelAdd (rProj.getLabel());
2957 pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd());
2959 pReconDoc->setImageFile (pImageFile);
2960 if (theApp->getAskDeleteNewDocs())
2961 pReconDoc->Modify (true);
2962 pReconDoc->UpdateAllViews();
2963 pReconDoc->getView()->setInitialClientSize();
2964 pReconDoc->Activate();
2969 ProjectionFileView::OnArtifactReduction (wxCommandEvent& event)
2974 ProjectionFileCanvas*
2975 ProjectionFileView::CreateCanvas (wxFrame *parent)
2977 ProjectionFileCanvas* pCanvas;
2979 parent->GetClientSize(&width, &height);
2981 pCanvas = new ProjectionFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
2983 pCanvas->SetScrollbars(20, 20, 50, 50);
2984 pCanvas->SetBackgroundColour(*wxWHITE);
2995 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2998 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
3000 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
3002 theApp->setIconForFrame (subframe);
3004 m_pFileMenu = new wxMenu;
3006 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3007 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3008 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3009 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3010 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3011 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3013 m_pFileMenu->AppendSeparator();
3014 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
3016 m_pFileMenu->AppendSeparator();
3017 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3018 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3019 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3020 m_pFileMenu->AppendSeparator();
3021 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3023 m_pFileMenu->AppendSeparator();
3024 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3025 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3027 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3028 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3030 wxMenu *convert_menu = new wxMenu;
3031 convert_menu->Append (PJMENU_CONVERT_RECTANGULAR, "&Rectangular Image");
3032 convert_menu->Append (PJMENU_CONVERT_POLAR, "&Polar Image...\tCtrl-L");
3033 convert_menu->Append (PJMENU_CONVERT_FFT_POLAR, "FF&T->Polar Image...\tCtrl-T");
3034 convert_menu->AppendSeparator();
3035 convert_menu->Append (PJMENU_CONVERT_PARALLEL, "&Interpolate to Parallel");
3037 // wxMenu* filter_menu = new wxMenu;
3038 // filter_menu->Append (PJMENU_ARTIFACT_REDUCTION, "&Artifact Reduction");
3040 wxMenu* analyze_menu = new wxMenu;
3041 analyze_menu->Append (PJMENU_PLOT_HISTOGRAM, "&Plot Histogram");
3042 analyze_menu->Append (PJMENU_PLOT_TTHETA_SAMPLING, "Plot T-T&heta Sampling...\tCtrl-H");
3044 wxMenu *reconstruct_menu = new wxMenu;
3045 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP, "&Filtered Backprojection...\tCtrl-R", "Reconstruct image using filtered backprojection");
3046 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP_REBIN, "Filtered &Backprojection (Rebin to Parallel)...\tCtrl-B", "Reconstruct image using filtered backprojection");
3048 // reconstruct_menu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Fourier...\tCtrl-E", "Reconstruct image using inverse Fourier");
3050 wxMenu *help_menu = new wxMenu;
3051 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3052 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3053 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3054 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3056 wxMenuBar *menu_bar = new wxMenuBar;
3058 menu_bar->Append (m_pFileMenu, "&File");
3059 menu_bar->Append (convert_menu, "&Convert");
3060 // menu_bar->Append (filter_menu, "Fi<er");
3061 menu_bar->Append (analyze_menu, "&Analyze");
3062 menu_bar->Append (reconstruct_menu, "&Reconstruct");
3063 menu_bar->Append (help_menu, "&Help");
3065 subframe->SetMenuBar(menu_bar);
3066 subframe->Centre(wxBOTH);
3068 wxAcceleratorEntry accelEntries[7];
3069 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('L'), PJMENU_CONVERT_POLAR);
3070 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('T'), PJMENU_CONVERT_FFT_POLAR);
3071 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('R'), PJMENU_RECONSTRUCT_FBP);
3072 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('B'), PJMENU_RECONSTRUCT_FBP_REBIN);
3073 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('E'), PJMENU_RECONSTRUCT_FOURIER);
3074 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('I'), PJMENU_FILE_PROPERTIES);
3075 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('H'), PJMENU_PLOT_TTHETA_SAMPLING);
3076 wxAcceleratorTable accelTable (7, accelEntries);
3077 subframe->SetAcceleratorTable (accelTable);
3084 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
3086 m_pFrame = CreateChildFrame(doc, this);
3088 m_pCanvas = CreateCanvas (m_pFrame);
3089 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
3090 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
3091 m_pFrame->SetTitle ("ProjectionFileView");
3093 m_pFrame->Show(true);
3100 ProjectionFileView::OnDraw (wxDC* dc)
3103 dc->DrawBitmap (m_bitmap, 0, 0, false);
3108 ProjectionFileView::setInitialClientSize ()
3110 if (m_pFrame && m_pCanvas) {
3111 wxSize bestSize = m_pCanvas->GetBestSize();
3113 m_pFrame->SetClientSize (bestSize);
3114 m_pFrame->Show (true);
3115 m_pFrame->SetFocus();
3120 ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3122 const Projections& rProj = GetDocument()->getProjections();
3123 const int nDet = rProj.nDet();
3124 const int nView = rProj.nView();
3125 if (nDet != 0 && nView != 0) {
3126 const DetectorArray& detarray = rProj.getDetectorArray(0);
3127 const DetectorValue* detval = detarray.detValues();
3128 double min = detval[0];
3129 double max = detval[0];
3130 for (int iy = 0; iy < nView; iy++) {
3131 const DetectorArray& detarray = rProj.getDetectorArray(iy);
3132 const DetectorValue* detval = detarray.detValues();
3133 for (int ix = 0; ix < nDet; ix++) {
3134 if (min > detval[ix])
3136 else if (max < detval[ix])
3141 unsigned char* imageData = new unsigned char [nDet * nView * 3];
3143 sys_error (ERR_SEVERE, "Unable to allocate memory for image display");
3146 double scale = (max - min) / 255;
3147 for (int iy2 = 0; iy2 < nView; iy2++) {
3148 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
3149 const DetectorValue* detval = detarray.detValues();
3150 for (int ix = 0; ix < nDet; ix++) {
3151 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
3152 intensity = clamp(intensity, 0, 255);
3153 int baseAddr = (iy2 * nDet + ix) * 3;
3154 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
3157 wxImage image (nDet, nView, imageData, true);
3158 m_bitmap = image.ConvertToBitmap();
3162 m_pCanvas->SetScrollbars(20, 20, nDet/20, nView/20);
3163 m_pCanvas->SetBackgroundColour(*wxWHITE);
3166 m_pCanvas->Refresh();
3170 ProjectionFileView::OnClose (bool deleteWindow)
3172 //GetDocumentManager()->ActivateView (this, false, true);
3173 if (! GetDocument() || ! GetDocument()->Close())
3178 m_pCanvas->setView(NULL);
3181 wxString s(wxTheApp->GetAppName());
3183 m_pFrame->SetTitle(s);
3190 if (GetDocument() && GetDocument()->getBadFileOpen())
3191 ::wxYield(); // wxWindows bug workaround
3200 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
3201 : wxScrolledWindow(frame, -1, pos, size, style)
3207 PlotFileCanvas::GetBestSize() const
3213 theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
3214 xSize = maxValue<int> (xSize, ySize);
3216 ySize = xSize = (xSize / 4);
3220 return wxSize (xSize, ySize);
3223 PlotFileCanvas::~PlotFileCanvas ()
3229 PlotFileCanvas::OnDraw(wxDC& dc)
3232 m_pView->OnDraw(& dc);
3238 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
3240 BEGIN_EVENT_TABLE(PlotFileView, wxView)
3241 EVT_MENU(PLOTMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
3242 EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
3243 EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
3244 EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
3247 PlotFileView::PlotFileView()
3248 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pEZPlot(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
3252 PlotFileView::~PlotFileView()
3257 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
3261 PlotFileView::OnProperties (wxCommandEvent& event)
3263 const PlotFile& rPlot = GetDocument()->getPlotFile();
3264 std::ostringstream os;
3265 os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
3266 rPlot.printHeadersBrief (os);
3267 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<<\n";
3268 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
3269 dialogMsg.ShowModal();
3270 GetDocument()->Activate();
3275 PlotFileView::OnScaleAuto (wxCommandEvent& event)
3277 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3278 double min, max, mean, mode, median, stddev;
3279 rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
3280 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
3281 int iRetVal = dialogAutoScale.ShowModal();
3282 if (iRetVal == wxID_OK) {
3283 m_bMinSpecified = true;
3284 m_bMaxSpecified = true;
3286 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
3289 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
3290 OnUpdate (this, NULL);
3293 GetDocument()->Activate();
3297 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
3299 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3303 if (! m_bMinSpecified || ! m_bMaxSpecified) {
3304 if (! rPlotFile.getMinMax (1, min, max)) {
3305 *theApp->getLog() << "Error: unable to find Min/Max\n";
3310 if (m_bMinSpecified)
3312 if (m_bMaxSpecified)
3315 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Y-axis Minimum & Maximum", min, max);
3316 int retVal = dialogMinMax.ShowModal();
3317 if (retVal == wxID_OK) {
3318 m_bMinSpecified = true;
3319 m_bMaxSpecified = true;
3320 m_dMinPixel = dialogMinMax.getMinimum();
3321 m_dMaxPixel = dialogMinMax.getMaximum();
3322 OnUpdate (this, NULL);
3324 GetDocument()->Activate();
3328 PlotFileView::OnScaleFull (wxCommandEvent& event)
3330 if (m_bMinSpecified || m_bMaxSpecified) {
3331 m_bMinSpecified = false;
3332 m_bMaxSpecified = false;
3333 OnUpdate (this, NULL);
3335 GetDocument()->Activate();
3340 PlotFileView::CreateCanvas (wxFrame* parent)
3342 PlotFileCanvas* pCanvas;
3344 parent->GetClientSize(&width, &height);
3346 pCanvas = new PlotFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
3348 pCanvas->SetBackgroundColour(*wxWHITE);
3359 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
3362 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
3364 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
3366 theApp->setIconForFrame (subframe);
3368 m_pFileMenu = new wxMenu;
3370 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3371 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3372 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3373 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3374 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3375 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3377 m_pFileMenu->AppendSeparator();
3378 m_pFileMenu->Append(PLOTMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
3380 m_pFileMenu->AppendSeparator();
3381 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3382 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3383 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3384 m_pFileMenu->AppendSeparator();
3385 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3387 m_pFileMenu->AppendSeparator();
3388 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3389 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3391 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3392 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3394 wxMenu *view_menu = new wxMenu;
3395 view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...\tCtrl-E");
3396 view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
3397 view_menu->Append(PLOTMENU_VIEW_SCALE_FULL, "Display &Full Scale\tCtrl-U");
3399 wxMenu *help_menu = new wxMenu;
3400 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3401 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3402 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3403 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3405 wxMenuBar *menu_bar = new wxMenuBar;
3407 menu_bar->Append(m_pFileMenu, "&File");
3408 menu_bar->Append(view_menu, "&View");
3409 menu_bar->Append(help_menu, "&Help");
3411 subframe->SetMenuBar(menu_bar);
3412 subframe->Centre(wxBOTH);
3414 wxAcceleratorEntry accelEntries[4];
3415 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('E'), PLOTMENU_VIEW_SCALE_MINMAX);
3416 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('A'), PLOTMENU_VIEW_SCALE_AUTO);
3417 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('U'), PLOTMENU_VIEW_SCALE_FULL);
3418 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), PLOTMENU_FILE_PROPERTIES);
3419 wxAcceleratorTable accelTable (4, accelEntries);
3420 subframe->SetAcceleratorTable (accelTable);
3427 PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
3429 m_pFrame = CreateChildFrame(doc, this);
3432 m_bMinSpecified = false;
3433 m_bMaxSpecified = false;
3434 m_dAutoScaleFactor = 1.;
3437 m_pFrame->GetClientSize(&width, &height);
3438 m_pFrame->SetTitle ("Plot File");
3439 m_pCanvas = CreateCanvas (m_pFrame);
3441 m_pFrame->Show(true);
3448 PlotFileView::OnDraw (wxDC* dc)
3450 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3451 const int iNColumns = rPlotFile.getNumColumns();
3452 const int iNRecords = rPlotFile.getNumRecords();
3454 if (iNColumns > 0 && iNRecords > 0) {
3456 m_pCanvas->GetClientSize (&xsize, &ysize);
3457 SGPDriver driver (dc, xsize, ysize);
3460 m_pEZPlot->plot (&sgp);
3466 PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3468 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3469 const int iNColumns = rPlotFile.getNumColumns();
3470 const int iNRecords = rPlotFile.getNumRecords();
3471 const bool bScatterPlot = rPlotFile.getIsScatterPlot();
3473 if (iNColumns > 0 && iNRecords > 0) {
3476 m_pEZPlot = new EZPlot;
3478 for (unsigned int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)
3479 m_pEZPlot->ezset (rPlotFile.getEzsetCommand (iEzset));
3481 if (m_bMinSpecified) {
3482 std::ostringstream os;
3483 os << "ymin " << m_dMinPixel;
3484 m_pEZPlot->ezset (os.str());
3487 if (m_bMaxSpecified) {
3488 std::ostringstream os;
3489 os << "ymax " << m_dMaxPixel;
3490 m_pEZPlot->ezset (os.str());
3493 m_pEZPlot->ezset("box");
3494 m_pEZPlot->ezset("grid");
3496 double* pdX = new double [iNRecords];
3497 double* pdY = new double [iNRecords];
3498 if (! bScatterPlot) {
3499 rPlotFile.getColumn (0, pdX);
3501 for (int iCol = 1; iCol < iNColumns; iCol++) {
3502 rPlotFile.getColumn (iCol, pdY);
3503 m_pEZPlot->addCurve (pdX, pdY, iNRecords);
3506 rPlotFile.getColumn (0, pdX);
3507 rPlotFile.getColumn (1, pdY);
3508 m_pEZPlot->addCurve (pdX, pdY, iNRecords);
3515 m_pCanvas->Refresh();
3519 PlotFileView::OnClose (bool deleteWindow)
3521 //GetDocumentManager()->ActivateView (this, false, true);
3522 if (! GetDocument() || ! GetDocument()->Close())
3527 m_pCanvas->setView (NULL);
3530 wxString s(wxTheApp->GetAppName());
3532 m_pFrame->SetTitle(s);
3538 if (GetDocument() && GetDocument()->getBadFileOpen())
3539 ::wxYield(); // wxWindows bug workaround
3546 ////////////////////////////////////////////////////////////////
3549 IMPLEMENT_DYNAMIC_CLASS(TextFileView, wxView)
3551 TextFileView::~TextFileView()
3553 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
3554 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
3557 bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
3559 m_pFrame = CreateChildFrame(doc, this);
3560 SetFrame (m_pFrame);
3563 m_pFrame->GetClientSize(&width, &height);
3564 m_pFrame->SetTitle("TextFile");
3565 m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
3566 m_pFrame->SetTitle("Log");
3568 m_pFrame->Show (true);
3574 // Handled by wxTextWindow
3575 void TextFileView::OnDraw(wxDC *WXUNUSED(dc) )
3579 void TextFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3584 TextFileView::OnClose (bool deleteWindow)
3586 if (! theApp->getMainFrame()->getShuttingDown())
3590 //GetDocumentManager()->ActivateView (this, false, true);
3591 if (! GetDocument() || ! GetDocument()->Close())
3598 if (GetDocument() && GetDocument()->getBadFileOpen())
3599 ::wxYield(); // wxWindows bug workaround
3610 TextFileView::CreateChildFrame (wxDocument *doc, wxView *view)
3613 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(0,0), wxDEFAULT_FRAME_STYLE, "Log");
3615 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE, "Log");
3617 theApp->setIconForFrame (subframe);
3619 m_pFileMenu = new wxMenu;
3621 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3622 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3623 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3624 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3625 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3626 // m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3628 m_pFileMenu->AppendSeparator();
3629 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3630 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3631 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3632 m_pFileMenu->AppendSeparator();
3633 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3635 m_pFileMenu->AppendSeparator();
3636 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3637 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3639 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3640 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3642 wxMenu *help_menu = new wxMenu;
3643 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3644 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3645 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3646 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3648 wxMenuBar *menu_bar = new wxMenuBar;
3650 menu_bar->Append(m_pFileMenu, "&File");
3651 menu_bar->Append(help_menu, "&Help");
3653 subframe->SetMenuBar(menu_bar);
3654 subframe->Centre(wxBOTH);
3660 // Define a constructor for my text subwindow
3661 TextFileCanvas::TextFileCanvas (TextFileView* v, wxFrame* frame, const wxPoint& pos, const wxSize& size, long style)
3662 : wxTextCtrl (frame, -1, "", pos, size, style), m_pView(v)
3666 TextFileCanvas::~TextFileCanvas ()
3672 TextFileCanvas::GetBestSize() const
3675 theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
3676 xSize = maxValue<int> (xSize, ySize);
3678 ySize = xSize = (xSize / 4);
3682 return wxSize (xSize, ySize);