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.154 2002/05/05 05:31:16 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()
83 ImageFileCanvas::OnDraw(wxDC& dc)
86 m_pView->OnDraw(& dc);
90 ImageFileCanvas::DrawRubberBandCursor (wxDC& dc, int x, int y)
92 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
97 dc.SetLogicalFunction (wxINVERT);
98 dc.SetPen (*wxGREEN_PEN);
99 dc.DrawLine (0, yPt, nx, yPt);
100 dc.DrawLine (x, 0, x, ny);
101 dc.SetLogicalFunction (wxCOPY);
105 ImageFileCanvas::GetCurrentCursor (int& x, int& y)
110 if (m_xCursor >= 0 && m_yCursor >= 0)
117 ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
126 wxPoint pt(event.GetLogicalPosition(dc));
128 const ImageFileDocument* pIFDoc = m_pView->GetDocument();
131 const ImageFile& rIF = pIFDoc->getImageFile();
132 ImageFileArrayConst v = rIF.getArray();
135 const int yPt = ny - 1 - pt.y;
136 if (event.RightIsDown()) {
137 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
138 std::ostringstream os;
139 os << "Image value (" << pt.x << "," << yPt << ") = " << v[pt.x][yPt];
140 if (rIF.isComplex()) {
141 double dImag = rIF.getImaginaryArray()[pt.x][yPt];
143 os << " - " << -dImag;
145 os << " + " << dImag;
149 *theApp->getLog() << os.str().c_str();
151 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
153 else if (event.LeftIsDown() || event.LeftUp() || event.RightUp()) {
154 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
155 if (m_xCursor >= 0 && m_yCursor >= 0) {
156 DrawRubberBandCursor (dc, m_xCursor, m_yCursor);
158 DrawRubberBandCursor (dc, pt.x, yPt);
161 wxMenu* pMenu = m_pView->getMenuAnalyze();
162 if (pMenu && ! pMenu->IsEnabled(IFMENU_PLOT_ROW)) {
163 pMenu->Enable (IFMENU_PLOT_ROW, true);
164 pMenu->Enable (IFMENU_PLOT_COL, true);
165 pMenu->Enable (IFMENU_COMPARE_ROW, true);
166 pMenu->Enable (IFMENU_COMPARE_COL, true);
167 pMenu->Enable (IFMENU_PLOT_FFT_ROW, true);
168 pMenu->Enable (IFMENU_PLOT_FFT_COL, true);
171 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
173 if (event.LeftUp()) {
174 std::ostringstream os;
175 os << "Selected column " << pt.x << " , row " << yPt << "\n";
176 *theApp->getLog() << os.str().c_str();
181 ImageFileCanvas::OnChar (wxKeyEvent& event)
183 if (event.GetKeyCode() == WXK_ESCAPE) {
187 m_pView->OnUpdate (NULL);
189 wxScrolledWindow::OnChar (event);
193 ImageFileCanvas::GetBestSize() const
198 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
199 return wxSize (rIF.nx(), rIF.ny());
205 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
207 BEGIN_EVENT_TABLE(ImageFileView, wxView)
208 EVT_MENU(IFMENU_FILE_EXPORT, ImageFileView::OnExport)
209 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
210 EVT_MENU(IFMENU_EDIT_COPY, ImageFileView::OnEditCopy)
211 EVT_MENU(IFMENU_EDIT_CUT, ImageFileView::OnEditCut)
212 EVT_MENU(IFMENU_EDIT_PASTE, ImageFileView::OnEditPaste)
213 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
214 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
215 EVT_MENU(IFMENU_VIEW_SCALE_FULL, ImageFileView::OnScaleFull)
216 EVT_MENU(IFMENU_COMPARE_IMAGES, ImageFileView::OnCompare)
217 EVT_MENU(IFMENU_COMPARE_ROW, ImageFileView::OnCompareRow)
218 EVT_MENU(IFMENU_COMPARE_COL, ImageFileView::OnCompareCol)
219 EVT_MENU(IFMENU_FILTER_INVERTVALUES, ImageFileView::OnInvertValues)
220 EVT_MENU(IFMENU_FILTER_SQUARE, ImageFileView::OnSquare)
221 EVT_MENU(IFMENU_FILTER_SQRT, ImageFileView::OnSquareRoot)
222 EVT_MENU(IFMENU_FILTER_LOG, ImageFileView::OnLog)
223 EVT_MENU(IFMENU_FILTER_EXP, ImageFileView::OnExp)
224 EVT_MENU(IFMENU_FILTER_FOURIER, ImageFileView::OnFourier)
225 EVT_MENU(IFMENU_FILTER_INVERSE_FOURIER, ImageFileView::OnInverseFourier)
226 EVT_MENU(IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, ImageFileView::OnShuffleFourierToNaturalOrder)
227 EVT_MENU(IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, ImageFileView::OnShuffleNaturalToFourierOrder)
228 EVT_MENU(IFMENU_IMAGE_ADD, ImageFileView::OnAdd)
229 EVT_MENU(IFMENU_IMAGE_SUBTRACT, ImageFileView::OnSubtract)
230 EVT_MENU(IFMENU_IMAGE_MULTIPLY, ImageFileView::OnMultiply)
231 EVT_MENU(IFMENU_IMAGE_DIVIDE, ImageFileView::OnDivide)
232 EVT_MENU(IFMENU_IMAGE_SCALESIZE, ImageFileView::OnScaleSize)
234 EVT_MENU(IFMENU_IMAGE_CONVERT3D, ImageFileView::OnConvert3d)
237 EVT_MENU(IFMENU_FILTER_FFT, ImageFileView::OnFFT)
238 EVT_MENU(IFMENU_FILTER_IFFT, ImageFileView::OnIFFT)
239 EVT_MENU(IFMENU_FILTER_FFT_ROWS, ImageFileView::OnFFTRows)
240 EVT_MENU(IFMENU_FILTER_IFFT_ROWS, ImageFileView::OnIFFTRows)
241 EVT_MENU(IFMENU_FILTER_FFT_COLS, ImageFileView::OnFFTCols)
242 EVT_MENU(IFMENU_FILTER_IFFT_COLS, ImageFileView::OnIFFTCols)
244 EVT_MENU(IFMENU_FILTER_MAGNITUDE, ImageFileView::OnMagnitude)
245 EVT_MENU(IFMENU_FILTER_PHASE, ImageFileView::OnPhase)
246 EVT_MENU(IFMENU_FILTER_REAL, ImageFileView::OnReal)
247 EVT_MENU(IFMENU_FILTER_IMAGINARY, ImageFileView::OnImaginary)
248 EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)
249 EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol)
251 EVT_MENU(IFMENU_PLOT_FFT_ROW, ImageFileView::OnPlotFFTRow)
252 EVT_MENU(IFMENU_PLOT_FFT_COL, ImageFileView::OnPlotFFTCol)
254 EVT_MENU(IFMENU_PLOT_HISTOGRAM, ImageFileView::OnPlotHistogram)
257 ImageFileView::ImageFileView()
258 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0), m_pFilterMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
260 m_iDefaultExportFormatID = ImageFile::EXPORT_FORMAT_PNG;
263 ImageFileView::~ImageFileView()
265 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
266 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
271 ImageFileView::OnProperties (wxCommandEvent& event)
273 const ImageFile& rIF = GetDocument()->getImageFile();
274 if (rIF.nx() == 0 || rIF.ny() == 0)
275 *theApp->getLog() << "Properties: empty imagefile\n";
277 const std::string rFilename = m_pFrame->GetTitle().c_str();
278 std::ostringstream os;
279 double min, max, mean, mode, median, stddev;
280 rIF.statistics (rIF.getArray(), min, max, mean, mode, median, stddev);
281 os << "Filename: " << rFilename << "\n";
282 os << "Size: (" << rIF.nx() << "," << rIF.ny() << ")\n";
288 os << "Minimum: "<<min<<"\nMaximum: "<<max<<"\nMean: "<<mean<<"\nMedian: "<<median<<"\nMode: "<<mode<<"\nStandard Deviation: "<<stddev << "\n";
289 if (rIF.isComplex()) {
290 rIF.statistics (rIF.getImaginaryArray(), min, max, mean, mode, median, stddev);
291 os << "Imaginary: min: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
293 if (rIF.nLabels() > 0) {
294 rIF.printLabelsBrief (os);
296 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
297 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
298 dialogMsg.ShowModal();
300 GetDocument()->Activate();
304 ImageFileView::OnScaleAuto (wxCommandEvent& event)
306 const ImageFile& rIF = GetDocument()->getImageFile();
307 double min, max, mean, mode, median, stddev;
308 rIF.statistics(min, max, mean, mode, median, stddev);
309 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
310 int iRetVal = dialogAutoScale.ShowModal();
311 if (iRetVal == wxID_OK) {
312 m_bMinSpecified = true;
313 m_bMaxSpecified = true;
315 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
318 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
319 GetDocument()->UpdateAllViews (this);
322 GetDocument()->Activate();
326 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
328 const ImageFile& rIF = GetDocument()->getImageFile();
330 if (! m_bMinSpecified && ! m_bMaxSpecified)
331 rIF.getMinMax (min, max);
338 DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Image Minimum & Maximum", min, max);
339 int retVal = dialogMinMax.ShowModal();
340 if (retVal == wxID_OK) {
341 m_bMinSpecified = true;
342 m_bMaxSpecified = true;
343 m_dMinPixel = dialogMinMax.getMinimum();
344 m_dMaxPixel = dialogMinMax.getMaximum();
345 GetDocument()->UpdateAllViews (this);
347 GetDocument()->Activate();
351 ImageFileView::OnScaleFull (wxCommandEvent& event)
353 if (m_bMinSpecified || m_bMaxSpecified) {
354 m_bMinSpecified = false;
355 m_bMaxSpecified = false;
356 GetDocument()->UpdateAllViews (this);
358 GetDocument()->Activate();
362 ImageFileView::OnCompare (wxCommandEvent& event)
364 std::vector<ImageFileDocument*> vecIF;
365 theApp->getCompatibleImages (GetDocument(), vecIF);
367 if (vecIF.size() == 0) {
368 wxMessageBox("There are no compatible image files open for comparision", "No comparison images");
370 DialogGetComparisonImage dialogGetCompare(getFrameForChild(), "Get Comparison Image", vecIF, true);
372 if (dialogGetCompare.ShowModal() == wxID_OK) {
373 const ImageFile& rIF = GetDocument()->getImageFile();
374 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
375 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
376 std::ostringstream os;
377 double min, max, mean, mode, median, stddev;
378 rIF.statistics (min, max, mean, mode, median, stddev);
379 os << GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
380 rCompareIF.statistics (min, max, mean, mode, median, stddev);
381 os << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
383 rIF.comparativeStatistics (rCompareIF, d, r, e);
384 os << "Comparative Statistics: d=" << d << ", r=" << r << ", e=" << e << "\n";
385 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
386 if (dialogGetCompare.getMakeDifferenceImage()) {
387 ImageFile* pDifferenceImage = new ImageFile;
389 pDifferenceImage->setArraySize (rIF.nx(), rIF.ny());
390 if (! rIF.subtractImages (rCompareIF, *pDifferenceImage)) {
391 *theApp->getLog() << "Unable to subtract images\n";
392 delete pDifferenceImage;
395 ImageFileDocument* pDifferenceDoc = theApp->newImageDoc();
396 if (! pDifferenceDoc) {
397 sys_error (ERR_SEVERE, "Unable to create image file");
400 pDifferenceDoc->setImageFile (pDifferenceImage);
402 wxString s = GetFrame()->GetTitle() + ": ";
403 pDifferenceImage->labelsCopy (rIF, s.c_str());
404 s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
405 pDifferenceImage->labelsCopy (rCompareIF, s.c_str());
406 std::ostringstream osLabel;
407 osLabel << "Compare image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str()
408 << " and " << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": "
410 pDifferenceImage->labelAdd (os.str().c_str());
411 if (theApp->getAskDeleteNewDocs())
412 pDifferenceDoc->Modify (true);
413 pDifferenceDoc->UpdateAllViews(this);
414 pDifferenceDoc->getView()->setInitialClientSize();
415 pDifferenceDoc->Activate();
417 wxMessageBox(os.str().c_str(), "Image Comparison");
423 ImageFileView::OnInvertValues (wxCommandEvent& event)
425 ImageFile& rIF = GetDocument()->getImageFile();
426 rIF.invertPixelValues (rIF);
427 rIF.labelAdd ("Invert Pixel Values");
428 if (theApp->getAskDeleteNewDocs())
429 GetDocument()->Modify (true);
430 GetDocument()->UpdateAllViews (this);
431 GetDocument()->Activate();
435 ImageFileView::OnSquare (wxCommandEvent& event)
437 ImageFile& rIF = GetDocument()->getImageFile();
439 rIF.labelAdd ("Square Pixel Values");
440 if (theApp->getAskDeleteNewDocs())
441 GetDocument()->Modify (true);
442 GetDocument()->UpdateAllViews (this);
443 GetDocument()->Activate();
447 ImageFileView::OnSquareRoot (wxCommandEvent& event)
449 ImageFile& rIF = GetDocument()->getImageFile();
451 rIF.labelAdd ("Square-root Pixel Values");
452 if (theApp->getAskDeleteNewDocs())
453 GetDocument()->Modify (true);
454 GetDocument()->UpdateAllViews (this);
455 GetDocument()->Activate();
459 ImageFileView::OnLog (wxCommandEvent& event)
461 ImageFile& rIF = GetDocument()->getImageFile();
463 rIF.labelAdd ("Logrithm base-e Pixel Values");
464 if (theApp->getAskDeleteNewDocs())
465 GetDocument()->Modify (true);
466 GetDocument()->UpdateAllViews (this);
467 GetDocument()->Activate();
471 ImageFileView::OnExp (wxCommandEvent& event)
473 ImageFile& rIF = GetDocument()->getImageFile();
475 rIF.labelAdd ("Exponent base-e Pixel Values");
476 if (theApp->getAskDeleteNewDocs())
477 GetDocument()->Modify (true);
478 GetDocument()->UpdateAllViews (this);
479 GetDocument()->Activate();
483 ImageFileView::OnAdd (wxCommandEvent& event)
485 std::vector<ImageFileDocument*> vecIF;
486 theApp->getCompatibleImages (GetDocument(), vecIF);
488 if (vecIF.size() == 0) {
489 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
491 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Add", vecIF, false);
493 if (dialogGetCompare.ShowModal() == wxID_OK) {
494 ImageFile& rIF = GetDocument()->getImageFile();
495 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
496 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
497 ImageFileDocument* pNewDoc = theApp->newImageDoc();
499 sys_error (ERR_SEVERE, "Unable to create image file");
502 ImageFile& newImage = pNewDoc->getImageFile();
503 newImage.setArraySize (rIF.nx(), rIF.ny());
504 rIF.addImages (rRHSIF, newImage);
505 std::ostringstream os;
506 os << "Add image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
507 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
508 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
509 newImage.labelsCopy (rIF, s.c_str());
510 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
511 newImage.labelsCopy (rRHSIF, s.c_str());
512 newImage.labelAdd (os.str().c_str());
513 *theApp->getLog() << os.str().c_str() << "\n";
514 if (theApp->getAskDeleteNewDocs())
515 pNewDoc->Modify (true);
516 pNewDoc->UpdateAllViews (this);
517 pNewDoc->getView()->setInitialClientSize();
524 ImageFileView::OnSubtract (wxCommandEvent& event)
526 std::vector<ImageFileDocument*> vecIF;
527 theApp->getCompatibleImages (GetDocument(), vecIF);
529 if (vecIF.size() == 0) {
530 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
532 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Subtract", vecIF, false);
534 if (dialogGetCompare.ShowModal() == wxID_OK) {
535 ImageFile& rIF = GetDocument()->getImageFile();
536 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
537 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
538 ImageFileDocument* pNewDoc = theApp->newImageDoc();
540 sys_error (ERR_SEVERE, "Unable to create image file");
543 ImageFile& newImage = pNewDoc->getImageFile();
544 newImage.setArraySize (rIF.nx(), rIF.ny());
545 rIF.subtractImages (rRHSIF, newImage);
546 std::ostringstream os;
547 os << "Subtract image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
548 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
549 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
550 newImage.labelsCopy (rIF, s.c_str());
551 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
552 newImage.labelsCopy (rRHSIF, s.c_str());
553 newImage.labelAdd (os.str().c_str());
554 *theApp->getLog() << os.str().c_str() << "\n";
555 if (theApp->getAskDeleteNewDocs())
556 pNewDoc->Modify (true);
557 pNewDoc->UpdateAllViews (this);
558 pNewDoc->getView()->setInitialClientSize();
565 ImageFileView::OnMultiply (wxCommandEvent& event)
567 std::vector<ImageFileDocument*> vecIF;
568 theApp->getCompatibleImages (GetDocument(), vecIF);
570 if (vecIF.size() == 0) {
571 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
573 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Multiply", vecIF, false);
575 if (dialogGetCompare.ShowModal() == wxID_OK) {
576 ImageFile& rIF = GetDocument()->getImageFile();
577 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
578 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
579 ImageFileDocument* pNewDoc = theApp->newImageDoc();
581 sys_error (ERR_SEVERE, "Unable to create image file");
584 ImageFile& newImage = pNewDoc->getImageFile();
585 newImage.setArraySize (rIF.nx(), rIF.ny());
586 rIF.multiplyImages (rRHSIF, newImage);
587 std::ostringstream os;
588 os << "Multiply image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
589 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
590 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
591 newImage.labelsCopy (rIF, s.c_str());
592 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
593 newImage.labelsCopy (rRHSIF, s.c_str());
594 newImage.labelAdd (os.str().c_str());
595 *theApp->getLog() << os.str().c_str() << "\n";
596 if (theApp->getAskDeleteNewDocs())
597 pNewDoc->Modify (true);
598 pNewDoc->UpdateAllViews (this);
599 pNewDoc->getView()->setInitialClientSize();
606 ImageFileView::OnDivide (wxCommandEvent& event)
608 std::vector<ImageFileDocument*> vecIF;
609 theApp->getCompatibleImages (GetDocument(), vecIF);
611 if (vecIF.size() == 0) {
612 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
614 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Divide", vecIF, false);
616 if (dialogGetCompare.ShowModal() == wxID_OK) {
617 ImageFile& rIF = GetDocument()->getImageFile();
618 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
619 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
620 ImageFileDocument* pNewDoc = theApp->newImageDoc();
622 sys_error (ERR_SEVERE, "Unable to create image file");
625 ImageFile& newImage = pNewDoc->getImageFile();
626 newImage.setArraySize (rIF.nx(), rIF.ny());
627 rIF.divideImages (rRHSIF, newImage);
628 std::ostringstream os;
629 os << "Divide image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " by "
630 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
631 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
632 newImage.labelsCopy (rIF, s.c_str());
633 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
634 newImage.labelsCopy (rRHSIF, s.c_str());
635 newImage.labelAdd (os.str().c_str());
636 *theApp->getLog() << os.str().c_str() << "\n";
637 if (theApp->getAskDeleteNewDocs())
638 pNewDoc->Modify (true);
639 pNewDoc->UpdateAllViews (this);
640 pNewDoc->getView()->setInitialClientSize();
649 ImageFileView::OnFFT (wxCommandEvent& event)
651 ImageFile& rIF = GetDocument()->getImageFile();
653 rIF.labelAdd ("FFT Image");
654 m_bMinSpecified = false;
655 m_bMaxSpecified = false;
656 if (theApp->getAskDeleteNewDocs())
657 GetDocument()->Modify (true);
658 GetDocument()->UpdateAllViews (this);
659 GetDocument()->Activate();
663 ImageFileView::OnIFFT (wxCommandEvent& event)
665 ImageFile& rIF = GetDocument()->getImageFile();
667 rIF.labelAdd ("IFFT Image");
668 m_bMinSpecified = false;
669 m_bMaxSpecified = false;
670 if (theApp->getAskDeleteNewDocs())
671 GetDocument()->Modify (true);
672 GetDocument()->UpdateAllViews (this);
673 GetDocument()->Activate();
677 ImageFileView::OnFFTRows (wxCommandEvent& event)
679 ImageFile& rIF = GetDocument()->getImageFile();
681 rIF.labelAdd ("FFT Rows");
682 m_bMinSpecified = false;
683 m_bMaxSpecified = false;
684 if (theApp->getAskDeleteNewDocs())
685 GetDocument()->Modify (true);
686 GetDocument()->UpdateAllViews (this);
687 GetDocument()->Activate();
691 ImageFileView::OnIFFTRows (wxCommandEvent& event)
693 ImageFile& rIF = GetDocument()->getImageFile();
695 rIF.labelAdd ("IFFT Rows");
696 m_bMinSpecified = false;
697 m_bMaxSpecified = false;
698 if (theApp->getAskDeleteNewDocs())
699 GetDocument()->Modify (true);
700 GetDocument()->UpdateAllViews (this);
701 GetDocument()->Activate();
705 ImageFileView::OnFFTCols (wxCommandEvent& event)
707 ImageFile& rIF = GetDocument()->getImageFile();
709 rIF.labelAdd ("FFT Columns");
710 m_bMinSpecified = false;
711 m_bMaxSpecified = false;
712 if (theApp->getAskDeleteNewDocs())
713 GetDocument()->Modify (true);
714 GetDocument()->UpdateAllViews (this);
715 GetDocument()->Activate();
719 ImageFileView::OnIFFTCols (wxCommandEvent& event)
721 ImageFile& rIF = GetDocument()->getImageFile();
723 rIF.labelAdd ("IFFT Columns");
724 m_bMinSpecified = false;
725 m_bMaxSpecified = false;
726 if (theApp->getAskDeleteNewDocs())
727 GetDocument()->Modify (true);
728 GetDocument()->UpdateAllViews (this);
729 GetDocument()->Activate();
734 ImageFileView::OnFourier (wxCommandEvent& event)
736 ImageFile& rIF = GetDocument()->getImageFile();
737 wxProgressDialog dlgProgress (wxString("Fourier"), wxString("Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
739 rIF.labelAdd ("Fourier Image");
740 m_bMinSpecified = false;
741 m_bMaxSpecified = false;
742 if (theApp->getAskDeleteNewDocs())
743 GetDocument()->Modify (true);
744 GetDocument()->UpdateAllViews (this);
745 GetDocument()->Activate();
749 ImageFileView::OnInverseFourier (wxCommandEvent& event)
751 ImageFile& rIF = GetDocument()->getImageFile();
752 wxProgressDialog dlgProgress (wxString("Inverse Fourier"), wxString("Inverse Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
753 rIF.inverseFourier (rIF);
754 rIF.labelAdd ("Inverse Fourier Image");
755 m_bMinSpecified = false;
756 m_bMaxSpecified = false;
757 if (theApp->getAskDeleteNewDocs())
758 GetDocument()->Modify (true);
759 GetDocument()->UpdateAllViews (this);
760 GetDocument()->Activate();
764 ImageFileView::OnShuffleNaturalToFourierOrder (wxCommandEvent& event)
766 ImageFile& rIF = GetDocument()->getImageFile();
767 Fourier::shuffleNaturalToFourierOrder (rIF);
768 rIF.labelAdd ("Shuffle Natural To Fourier Order");
769 m_bMinSpecified = false;
770 m_bMaxSpecified = false;
771 if (theApp->getAskDeleteNewDocs())
772 GetDocument()->Modify (true);
773 GetDocument()->UpdateAllViews (this);
774 GetDocument()->Activate();
778 ImageFileView::OnShuffleFourierToNaturalOrder (wxCommandEvent& event)
780 ImageFile& rIF = GetDocument()->getImageFile();
781 Fourier::shuffleFourierToNaturalOrder (rIF);
782 rIF.labelAdd ("Shuffle Fourier To Natural Order");
783 m_bMinSpecified = false;
784 m_bMaxSpecified = false;
785 if (theApp->getAskDeleteNewDocs())
786 GetDocument()->Modify (true);
787 GetDocument()->UpdateAllViews (this);
788 GetDocument()->Activate();
792 ImageFileView::OnMagnitude (wxCommandEvent& event)
794 ImageFile& rIF = GetDocument()->getImageFile();
796 rIF.labelAdd ("Magnitude");
797 m_bMinSpecified = false;
798 m_bMaxSpecified = false;
799 if (theApp->getAskDeleteNewDocs())
800 GetDocument()->Modify (true);
801 GetDocument()->UpdateAllViews (this);
802 GetDocument()->Activate();
806 ImageFileView::OnPhase (wxCommandEvent& event)
808 ImageFile& rIF = GetDocument()->getImageFile();
809 if (rIF.isComplex()) {
811 rIF.labelAdd ("Phase of complex-image");
812 m_bMinSpecified = false;
813 m_bMaxSpecified = false;
814 if (theApp->getAskDeleteNewDocs())
815 GetDocument()->Modify (true);
816 GetDocument()->UpdateAllViews (this);
818 GetDocument()->Activate();
822 ImageFileView::OnReal (wxCommandEvent& event)
824 ImageFile& rIF = GetDocument()->getImageFile();
825 if (rIF.isComplex()) {
827 rIF.labelAdd ("Real component of complex-image");
828 m_bMinSpecified = false;
829 m_bMaxSpecified = false;
830 if (theApp->getAskDeleteNewDocs())
831 GetDocument()->Modify (true);
832 GetDocument()->UpdateAllViews (this);
834 GetDocument()->Activate();
838 ImageFileView::OnImaginary (wxCommandEvent& event)
840 ImageFile& rIF = GetDocument()->getImageFile();
841 if (rIF.isComplex()) {
843 rIF.labelAdd ("Imaginary component of complex-image");
844 m_bMinSpecified = false;
845 m_bMaxSpecified = false;
846 if (theApp->getAskDeleteNewDocs())
847 GetDocument()->Modify (true);
848 GetDocument()->UpdateAllViews (this);
850 GetDocument()->Activate();
855 ImageFileView::CreateCanvas (wxFrame* parent)
857 ImageFileCanvas* pCanvas;
859 parent->GetClientSize(&width, &height);
861 pCanvas = new ImageFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
863 pCanvas->SetScrollbars(20, 20, 50, 50);
864 pCanvas->SetBackgroundColour(*wxWHITE);
875 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
878 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
880 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
882 theApp->setIconForFrame (subframe);
884 m_pFileMenu = new wxMenu;
885 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
886 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
887 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
888 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
889 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
890 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
891 m_pFileMenu->Append(wxID_REVERT, "Re&vert");
893 m_pFileMenu->AppendSeparator();
894 m_pFileMenu->Append(IFMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
895 m_pFileMenu->Append(IFMENU_FILE_EXPORT, "Expor&t...");
897 m_pFileMenu->AppendSeparator();
898 m_pFileMenu->Append(wxID_PRINT, "&Print...");
899 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
900 m_pFileMenu->Append(wxID_PREVIEW, "Print Preview");
901 m_pFileMenu->AppendSeparator();
902 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
904 m_pFileMenu->AppendSeparator();
905 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
906 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
908 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
909 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
911 wxMenu* edit_menu = new wxMenu;
912 edit_menu->Append(IFMENU_EDIT_COPY, "Copy\tCtrl-C");
913 edit_menu->Append(IFMENU_EDIT_CUT, "Cut\tCtrl-X");
914 edit_menu->Append(IFMENU_EDIT_PASTE, "Paste\tCtrl-V");
916 wxMenu *view_menu = new wxMenu;
917 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale S&et...\tCtrl-E");
918 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
919 view_menu->Append(IFMENU_VIEW_SCALE_FULL, "Display F&ull Scale\tCtrl-U");
921 m_pFilterMenu = new wxMenu;
922 m_pFilterMenu->Append (IFMENU_FILTER_INVERTVALUES, "In&vert Values");
923 m_pFilterMenu->Append (IFMENU_FILTER_SQUARE, "&Square");
924 m_pFilterMenu->Append (IFMENU_FILTER_SQRT, "Square &Root");
925 m_pFilterMenu->Append (IFMENU_FILTER_LOG, "&Log");
926 m_pFilterMenu->Append (IFMENU_FILTER_EXP, "E&xp");
927 m_pFilterMenu->AppendSeparator();
929 m_pFilterMenu->Append (IFMENU_FILTER_FFT, "2-D &FFT\tCtrl-2");
930 m_pFilterMenu->Append (IFMENU_FILTER_IFFT, "2-D &IFFT\tAlt-2");
931 m_pFilterMenu->Append (IFMENU_FILTER_FFT_ROWS, "FFT Rows");
932 m_pFilterMenu->Append (IFMENU_FILTER_IFFT_ROWS, "IFFT Rows");
933 m_pFilterMenu->Append (IFMENU_FILTER_FFT_COLS, "FFT Columns");
934 m_pFilterMenu->Append (IFMENU_FILTER_IFFT_COLS, "IFFT Columns");
935 m_pFilterMenu->Append (IFMENU_FILTER_FOURIER, "2-D F&ourier");
936 m_pFilterMenu->Append (IFMENU_FILTER_INVERSE_FOURIER, "2-D Inverse Fo&urier");
938 m_pFilterMenu->Append (IFMENU_FILTER_FOURIER, "&Fourier");
939 m_pFilterMenu->Append (IFMENU_FILTER_INVERSE_FOURIER, "&Inverse Fourier");
941 m_pFilterMenu->Append (IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, "Shuffl&e Fourier to Natural Order");
942 m_pFilterMenu->Append (IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, "Shuffle &Natural to Fourier Order");
943 m_pFilterMenu->AppendSeparator();
944 m_pFilterMenu->Append (IFMENU_FILTER_MAGNITUDE, "&Magnitude");
945 m_pFilterMenu->Append (IFMENU_FILTER_PHASE, "&Phase");
946 m_pFilterMenu->Append (IFMENU_FILTER_REAL, "Re&al");
947 m_pFilterMenu->Append (IFMENU_FILTER_IMAGINARY, "Ima&ginary");
949 wxMenu* image_menu = new wxMenu;
950 image_menu->Append (IFMENU_IMAGE_ADD, "&Add...");
951 image_menu->Append (IFMENU_IMAGE_SUBTRACT, "&Subtract...");
952 image_menu->Append (IFMENU_IMAGE_MULTIPLY, "&Multiply...");
953 image_menu->Append (IFMENU_IMAGE_DIVIDE, "&Divide...");
954 image_menu->AppendSeparator();
955 image_menu->Append (IFMENU_IMAGE_SCALESIZE, "S&cale Size...");
957 image_menu->Append (IFMENU_IMAGE_CONVERT3D, "Convert &3-D\tCtrl-3");
960 m_pMenuAnalyze = new wxMenu;
961 m_pMenuAnalyze->Append (IFMENU_PLOT_ROW, "Plot &Row");
962 m_pMenuAnalyze->Append (IFMENU_PLOT_COL, "Plot &Column");
963 m_pMenuAnalyze->Append (IFMENU_PLOT_HISTOGRAM, "Plot &Histogram");
964 m_pMenuAnalyze->AppendSeparator();
965 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_ROW, "P&lot FFT Row");
966 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_COL, "Plo&t FFT Column");
967 m_pMenuAnalyze->AppendSeparator();
968 m_pMenuAnalyze->Append (IFMENU_COMPARE_IMAGES, "Compare &Images...");
969 m_pMenuAnalyze->Append (IFMENU_COMPARE_ROW, "Compare Ro&w");
970 m_pMenuAnalyze->Append (IFMENU_COMPARE_COL, "Compare Colu&mn");
971 m_pMenuAnalyze->Enable (IFMENU_PLOT_ROW, false);
972 m_pMenuAnalyze->Enable (IFMENU_PLOT_COL, false);
973 m_pMenuAnalyze->Enable (IFMENU_COMPARE_ROW, false);
974 m_pMenuAnalyze->Enable (IFMENU_COMPARE_COL, false);
975 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_ROW, false);
976 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_COL, false);
978 wxMenu *help_menu = new wxMenu;
979 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
980 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
981 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
982 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
984 wxMenuBar *menu_bar = new wxMenuBar;
986 menu_bar->Append(m_pFileMenu, "&File");
987 menu_bar->Append(edit_menu, "&Edit");
988 menu_bar->Append(view_menu, "&View");
989 menu_bar->Append(image_menu, "&Image");
990 menu_bar->Append(m_pFilterMenu, "Fi<er");
991 menu_bar->Append(m_pMenuAnalyze, "&Analyze");
992 menu_bar->Append(help_menu, "&Help");
994 subframe->SetMenuBar(menu_bar);
996 subframe->Centre(wxBOTH);
998 wxAcceleratorEntry accelEntries[10];
999 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('A'), IFMENU_VIEW_SCALE_AUTO);
1000 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('U'), IFMENU_VIEW_SCALE_FULL);
1001 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('E'), IFMENU_VIEW_SCALE_MINMAX);
1002 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), IFMENU_FILE_PROPERTIES);
1003 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('C'), IFMENU_EDIT_COPY);
1004 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('X'), IFMENU_EDIT_CUT);
1005 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('V'), IFMENU_EDIT_PASTE);
1008 accelEntries[iEntry++].Set (wxACCEL_CTRL, static_cast<int>('2'), IFMENU_FILTER_FFT);
1009 accelEntries[iEntry++].Set (wxACCEL_ALT, static_cast<int>('2'), IFMENU_FILTER_IFFT);
1012 accelEntries[iEntry++].Set (wxACCEL_CTRL, static_cast<int>('3'), IFMENU_IMAGE_CONVERT3D);
1014 wxAcceleratorTable accelTable (iEntry, accelEntries);
1016 subframe->SetAcceleratorTable (accelTable);
1023 ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
1025 m_pFrame = CreateChildFrame(doc, this);
1027 m_bMinSpecified = false;
1028 m_bMaxSpecified = false;
1029 m_dAutoScaleFactor = 1.;
1031 // int width, height;
1032 // m_pFrame->GetClientSize (&width, &height);
1033 m_pFrame->SetTitle("ImageFileView");
1034 m_pCanvas = CreateCanvas (m_pFrame);
1036 // int x, y; // X requires a forced resize
1037 // m_pFrame->GetSize(&x, &y);
1038 // m_pFrame->SetSize(-1, -1, x, y);
1039 m_pFrame->SetFocus();
1040 m_pFrame->Show(true);
1047 ImageFileView::setInitialClientSize ()
1049 if (m_pFrame && m_pCanvas) {
1050 wxSize bestSize = m_pCanvas->GetBestSize();
1052 if (bestSize.x > 800)
1054 if (bestSize.y > 800)
1057 m_pFrame->SetClientSize (bestSize);
1058 m_pFrame->Show (true);
1059 m_pFrame->SetFocus();
1064 ImageFileView::OnDraw (wxDC* dc)
1067 dc->DrawBitmap(m_bitmap, 0, 0, false);
1069 int xCursor, yCursor;
1070 if (m_pCanvas->GetCurrentCursor (xCursor, yCursor))
1071 m_pCanvas->DrawRubberBandCursor (*dc, xCursor, yCursor);
1076 ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
1078 const ImageFile& rIF = GetDocument()->getImageFile();
1079 if (m_pFilterMenu && rIF.isComplex()) {
1080 m_pFilterMenu->Enable(IFMENU_FILTER_REAL, true);
1081 m_pFilterMenu->Enable(IFMENU_FILTER_IMAGINARY, true);
1082 m_pFilterMenu->Enable(IFMENU_FILTER_PHASE, true);
1084 m_pFilterMenu->Enable(IFMENU_FILTER_REAL, false);
1085 m_pFilterMenu->Enable(IFMENU_FILTER_IMAGINARY, false);
1086 m_pFilterMenu->Enable(IFMENU_FILTER_PHASE, false);
1088 ImageFileArrayConst v = rIF.getArray();
1091 if (v != NULL && nx != 0 && ny != 0) {
1092 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1094 rIF.getMinMax (min, max);
1095 if (! m_bMinSpecified)
1097 if (! m_bMaxSpecified)
1100 double scaleWidth = m_dMaxPixel - m_dMinPixel;
1102 unsigned char* imageData = new unsigned char [nx * ny * 3];
1104 sys_error (ERR_SEVERE, "Unable to allocate memory for Image display");
1107 for (int ix = 0; ix < nx; ix++) {
1108 for (int iy = 0; iy < ny; iy++) {
1109 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
1110 int intensity = static_cast<int>(scaleValue + 0.5);
1111 intensity = clamp (intensity, 0, 255);
1112 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
1113 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
1116 wxImage image (nx, ny, imageData, true);
1117 m_bitmap = image.ConvertToBitmap();
1119 m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20);
1120 m_pCanvas->SetBackgroundColour(*wxWHITE);
1124 m_pCanvas->Refresh();
1128 ImageFileView::OnClose (bool deleteWindow)
1130 //GetDocumentManager()->ActivateView (this, false, true);
1131 if (! GetDocument() || ! GetDocument()->Close())
1136 m_pCanvas->setView(NULL);
1139 wxString s(theApp->GetAppName());
1141 m_pFrame->SetTitle(s);
1148 if (GetDocument() && GetDocument()->getBadFileOpen())
1149 ::wxYield(); // wxWindows bug workaround
1156 ImageFileView::OnEditCopy (wxCommandEvent& event)
1158 wxBitmapDataObject *pBitmapObject = new wxBitmapDataObject;
1160 pBitmapObject->SetBitmap (m_bitmap);
1162 if (wxTheClipboard->Open()) {
1163 wxTheClipboard->SetData (pBitmapObject);
1164 wxTheClipboard->Close();
1169 ImageFileView::OnEditCut (wxCommandEvent& event)
1172 ImageFile& rIF = GetDocument()->getImageFile();
1175 ImageFile* pIF = new ImageFile (nx, ny);
1176 pIF->arrayDataClear();
1177 GetDocument()->setImageFile (pIF); // deletes old IF
1178 OnUpdate(this, NULL);
1179 GetDocument()->UpdateAllViews();
1180 if (theApp->getAskDeleteNewDocs())
1181 GetDocument()->Modify (true);
1185 ImageFileView::OnEditPaste (wxCommandEvent& event)
1187 ImageFile& rIF = GetDocument()->getImageFile();
1189 if (wxTheClipboard->Open()) {
1191 if (wxTheClipboard->IsSupported (wxDF_BITMAP)) {
1192 wxBitmapDataObject bitmapObject;
1193 wxTheClipboard->GetData (bitmapObject);
1194 bitmap = bitmapObject.GetBitmap ();
1196 wxTheClipboard->Close();
1200 bool bMonochrome = false;
1202 if (bitmap.Ok() == true && bitmap.GetWidth() == nx && bitmap.GetHeight() == ny) {
1203 wxImage image (bitmap);
1204 double dScale3 = 3 * 255;
1205 unsigned char* pixels = image.GetData();
1206 ImageFileArray v = rIF.getArray();
1207 for (unsigned int ix = 0; ix < rIF.nx(); ix++) {
1208 for (unsigned int iy = 0; iy < rIF.ny(); iy++) {
1209 unsigned int iBase = 3 * (iy * nx + ix);
1210 if (ix == 0 && iy == 0 && (pixels[iBase] == pixels[iBase+1] && pixels[iBase+1] == pixels[iBase+2]))
1213 v[ix][ny - 1 - iy] = (pixels[iBase]+pixels[iBase+1]+pixels[iBase+2]) / dScale3;
1215 double dR = pixels[iBase] / 255.;
1216 double dG = pixels[iBase+1] / 255.;
1217 double dB = pixels[iBase+2] / 255.;
1218 v[ix][ny - 1 - iy] = ImageFile::colorToGrayscale (dR, dG, dB);
1222 OnUpdate(this, NULL);
1223 GetDocument()->UpdateAllViews();
1224 if (theApp->getAskDeleteNewDocs())
1225 GetDocument()->Modify(true);
1231 ImageFileView::OnExport (wxCommandEvent& event)
1233 ImageFile& rIF = GetDocument()->getImageFile();
1234 ImageFileArrayConst v = rIF.getArray();
1237 if (v != NULL && nx != 0 && ny != 0) {
1238 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1240 rIF.getMinMax (min, max);
1241 if (! m_bMinSpecified)
1243 if (! m_bMaxSpecified)
1247 DialogExportParameters dialogExport (getFrameForChild(), m_iDefaultExportFormatID);
1248 if (dialogExport.ShowModal() == wxID_OK) {
1249 wxString strFormatName (dialogExport.getFormatName ());
1250 m_iDefaultExportFormatID = ImageFile::convertExportFormatNameToID (strFormatName.c_str());
1253 wxString strWildcard;
1254 if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PGM || m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PGMASCII) {
1256 strWildcard = "PGM Files (*.pgm)|*.pgm";
1259 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PNG || m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PNG16) {
1261 strWildcard = "PNG Files (*.png)|*.png";
1264 #ifdef HAVE_CTN_DICOM
1265 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_DICOM) {
1267 strWildcard = "DICOM Files (*.*)|*.*";
1270 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_TEXT) {
1272 strWildcard = "Text (*.txt)|*.txt";
1276 strWildcard = "Miscellaneous (*.*)|*.*";
1279 const wxString& strFilename = wxFileSelector (wxString("Export Filename"), wxString(""),
1280 wxString(""), strExt, strWildcard, wxOVERWRITE_PROMPT | wxHIDE_READONLY | wxSAVE);
1282 rIF.exportImage (strFormatName.c_str(), strFilename.c_str(), 1, 1, m_dMinPixel, m_dMaxPixel);
1283 *theApp->getLog() << "Exported file " << strFilename << "\n";
1290 ImageFileView::OnScaleSize (wxCommandEvent& event)
1292 ImageFile& rIF = GetDocument()->getImageFile();
1293 unsigned int iOldNX = rIF.nx();
1294 unsigned int iOldNY = rIF.ny();
1296 DialogGetXYSize dialogGetXYSize (getFrameForChild(), "Set New X & Y Dimensions", iOldNX, iOldNY);
1297 if (dialogGetXYSize.ShowModal() == wxID_OK) {
1298 unsigned int iNewNX = dialogGetXYSize.getXSize();
1299 unsigned int iNewNY = dialogGetXYSize.getYSize();
1300 std::ostringstream os;
1301 os << "Scale Size from (" << iOldNX << "," << iOldNY << ") to (" << iNewNX << "," << iNewNY << ")";
1302 ImageFileDocument* pScaledDoc = theApp->newImageDoc();
1304 sys_error (ERR_SEVERE, "Unable to create image file");
1307 ImageFile& rScaledIF = pScaledDoc->getImageFile();
1308 rScaledIF.setArraySize (iNewNX, iNewNY);
1309 rScaledIF.labelsCopy (rIF);
1310 rScaledIF.labelAdd (os.str().c_str());
1311 rIF.scaleImage (rScaledIF);
1312 *theApp->getLog() << os.str().c_str() << "\n";
1313 if (theApp->getAskDeleteNewDocs())
1314 pScaledDoc->Modify (true);
1315 pScaledDoc->UpdateAllViews (this);
1316 pScaledDoc->getView()->setInitialClientSize();
1317 pScaledDoc->Activate();
1323 ImageFileView::OnConvert3d (wxCommandEvent& event)
1325 ImageFile& rIF = GetDocument()->getImageFile();
1326 Graph3dFileDocument* pGraph3d = theApp->newGraph3dDoc();
1327 pGraph3d->setBadFileOpen();
1328 pGraph3d->createFromImageFile (rIF);
1329 pGraph3d->getView()->OnUpdate (this, NULL);
1330 pGraph3d->UpdateAllViews();
1331 pGraph3d->getView()->getFrame()->SetClientSize (400, 400);
1332 pGraph3d->getView()->getFrame()->Show (true);
1333 GetDocumentManager()->ActivateView (pGraph3d->getView(), true, false);
1335 pGraph3d->getView()->getCanvas()->SetFocus();
1340 ImageFileView::OnPlotRow (wxCommandEvent& event)
1342 int xCursor, yCursor;
1343 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1344 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1348 const ImageFile& rIF = GetDocument()->getImageFile();
1349 ImageFileArrayConst v = rIF.getArray();
1350 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1354 if (v != NULL && yCursor < ny) {
1355 double* pX = new double [nx];
1356 double* pYReal = new double [nx];
1357 double *pYImag = NULL;
1358 double *pYMag = NULL;
1359 if (rIF.isComplex()) {
1360 pYImag = new double [nx];
1361 pYMag = new double [nx];
1363 for (int i = 0; i < nx; i++) {
1365 pYReal[i] = v[i][yCursor];
1366 if (rIF.isComplex()) {
1367 pYImag[i] = vImag[i][yCursor];
1368 pYMag[i] = ::sqrt (v[i][yCursor] * v[i][yCursor] + vImag[i][yCursor] * vImag[i][yCursor]);
1371 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1373 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1375 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1376 std::ostringstream os;
1377 os << "Row " << yCursor;
1378 std::string title("title ");
1380 rPlotFile.addEzsetCommand (title.c_str());
1381 rPlotFile.addEzsetCommand ("xlabel Column");
1382 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1383 rPlotFile.addEzsetCommand ("lxfrac 0");
1384 rPlotFile.addEzsetCommand ("box");
1385 rPlotFile.addEzsetCommand ("grid");
1386 rPlotFile.addEzsetCommand ("curve 1");
1387 rPlotFile.addEzsetCommand ("color 1");
1388 if (rIF.isComplex()) {
1389 rPlotFile.addEzsetCommand ("dash 1");
1390 rPlotFile.addEzsetCommand ("curve 2");
1391 rPlotFile.addEzsetCommand ("color 4");
1392 rPlotFile.addEzsetCommand ("dash 3");
1393 rPlotFile.addEzsetCommand ("curve 3");
1394 rPlotFile.addEzsetCommand ("color 0");
1395 rPlotFile.addEzsetCommand ("solid");
1396 rPlotFile.setCurveSize (4, nx);
1398 rPlotFile.setCurveSize (2, nx);
1399 rPlotFile.addColumn (0, pX);
1400 rPlotFile.addColumn (1, pYReal);
1401 if (rIF.isComplex()) {
1402 rPlotFile.addColumn (2, pYImag);
1403 rPlotFile.addColumn (3, pYMag);
1405 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1406 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1407 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1408 *theApp->getLog() << os.str().c_str() << "\n";
1409 rPlotFile.addDescription (os.str().c_str());
1413 if (rIF.isComplex()) {
1417 if (theApp->getAskDeleteNewDocs())
1418 pPlotDoc->Modify (true);
1419 pPlotDoc->getView()->getFrame()->Show(true);
1420 pPlotDoc->UpdateAllViews ();
1421 pPlotDoc->Activate();
1426 ImageFileView::OnPlotCol (wxCommandEvent& event)
1428 int xCursor, yCursor;
1429 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1430 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1434 const ImageFile& rIF = GetDocument()->getImageFile();
1435 ImageFileArrayConst v = rIF.getArray();
1436 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1440 if (v != NULL && xCursor < nx) {
1441 double* pX = new double [ny];
1442 double* pYReal = new double [ny];
1443 double* pYImag = NULL;
1444 double* pYMag = NULL;
1445 if (rIF.isComplex()) {
1446 pYImag = new double [ny];
1447 pYMag = new double [ny];
1449 for (int i = 0; i < ny; i++) {
1451 pYReal[i] = v[xCursor][i];
1452 if (rIF.isComplex()) {
1453 pYImag[i] = vImag[xCursor][i];
1454 pYMag[i] = ::sqrt (v[xCursor][i] * v[xCursor][i] + vImag[xCursor][i] * vImag[xCursor][i]);
1457 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1459 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1461 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1462 std::ostringstream os;
1463 os << "Column " << xCursor;
1464 std::string title("title ");
1466 rPlotFile.addEzsetCommand (title.c_str());
1467 rPlotFile.addEzsetCommand ("xlabel Row");
1468 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1469 rPlotFile.addEzsetCommand ("lxfrac 0");
1470 rPlotFile.addEzsetCommand ("box");
1471 rPlotFile.addEzsetCommand ("grid");
1472 rPlotFile.addEzsetCommand ("curve 1");
1473 rPlotFile.addEzsetCommand ("color 1");
1474 if (rIF.isComplex()) {
1475 rPlotFile.addEzsetCommand ("dash 1");
1476 rPlotFile.addEzsetCommand ("curve 2");
1477 rPlotFile.addEzsetCommand ("color 4");
1478 rPlotFile.addEzsetCommand ("dash 3");
1479 rPlotFile.addEzsetCommand ("curve 3");
1480 rPlotFile.addEzsetCommand ("color 0");
1481 rPlotFile.addEzsetCommand ("solid");
1482 rPlotFile.setCurveSize (4, ny);
1484 rPlotFile.setCurveSize (2, ny);
1485 rPlotFile.addColumn (0, pX);
1486 rPlotFile.addColumn (1, pYReal);
1487 if (rIF.isComplex()) {
1488 rPlotFile.addColumn (2, pYImag);
1489 rPlotFile.addColumn (3, pYMag);
1491 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1492 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1493 os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1494 *theApp->getLog() << os.str().c_str() << "\n";
1495 rPlotFile.addDescription (os.str().c_str());
1499 if (rIF.isComplex()) {
1503 if (theApp->getAskDeleteNewDocs())
1504 pPlotDoc->Modify (true);
1505 pPlotDoc->getView()->getFrame()->Show(true);
1506 pPlotDoc->UpdateAllViews ();
1507 pPlotDoc->Activate();
1513 ImageFileView::OnPlotFFTRow (wxCommandEvent& event)
1515 int xCursor, yCursor;
1516 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1517 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1521 const ImageFile& rIF = GetDocument()->getImageFile();
1522 ImageFileArrayConst v = rIF.getArray();
1523 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1527 if (v != NULL && yCursor < ny) {
1528 fftw_complex* pcIn = new fftw_complex [nx];
1531 for (i = 0; i < nx; i++) {
1532 pcIn[i].re = v[i][yCursor];
1533 if (rIF.isComplex())
1534 pcIn[i].im = vImag[i][yCursor];
1539 fftw_plan plan = fftw_create_plan (nx, FFTW_FORWARD, FFTW_IN_PLACE | FFTW_ESTIMATE | FFTW_USE_WISDOM);
1540 fftw_one (plan, pcIn, NULL);
1541 fftw_destroy_plan (plan);
1543 double* pX = new double [nx];
1544 double* pYReal = new double [nx];
1545 double* pYImag = new double [nx];
1546 double* pYMag = new double [nx];
1547 for (i = 0; i < nx; i++) {
1549 pYReal[i] = pcIn[i].re / nx;
1550 pYImag[i] = pcIn[i].im / nx;
1551 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1553 Fourier::shuffleFourierToNaturalOrder (pYReal, nx);
1554 Fourier::shuffleFourierToNaturalOrder (pYImag, nx);
1555 Fourier::shuffleFourierToNaturalOrder (pYMag, nx);
1557 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1559 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1561 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1562 std::ostringstream os;
1563 os << "Row " << yCursor;
1564 std::string title("title ");
1566 rPlotFile.addEzsetCommand (title.c_str());
1567 rPlotFile.addEzsetCommand ("xlabel Column");
1568 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1569 rPlotFile.addEzsetCommand ("lxfrac 0");
1570 rPlotFile.addEzsetCommand ("curve 1");
1571 rPlotFile.addEzsetCommand ("color 1");
1572 rPlotFile.addEzsetCommand ("dash 1");
1573 rPlotFile.addEzsetCommand ("curve 2");
1574 rPlotFile.addEzsetCommand ("color 4");
1575 rPlotFile.addEzsetCommand ("dash 3");
1576 rPlotFile.addEzsetCommand ("curve 3");
1577 rPlotFile.addEzsetCommand ("color 0");
1578 rPlotFile.addEzsetCommand ("solid");
1579 rPlotFile.addEzsetCommand ("box");
1580 rPlotFile.addEzsetCommand ("grid");
1581 rPlotFile.setCurveSize (4, nx);
1582 rPlotFile.addColumn (0, pX);
1583 rPlotFile.addColumn (1, pYReal);
1584 rPlotFile.addColumn (2, pYImag);
1585 rPlotFile.addColumn (3, pYMag);
1586 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1587 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1588 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1589 *theApp->getLog() << os.str().c_str() << "\n";
1590 rPlotFile.addDescription (os.str().c_str());
1598 if (theApp->getAskDeleteNewDocs())
1599 pPlotDoc->Modify (true);
1600 pPlotDoc->getView()->getFrame()->Show(true);
1601 pPlotDoc->UpdateAllViews ();
1602 pPlotDoc->Activate();
1607 ImageFileView::OnPlotFFTCol (wxCommandEvent& event)
1609 int xCursor, yCursor;
1610 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1611 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1615 const ImageFile& rIF = GetDocument()->getImageFile();
1616 ImageFileArrayConst v = rIF.getArray();
1617 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1621 if (v != NULL && xCursor < nx) {
1622 fftw_complex* pcIn = new fftw_complex [ny];
1623 double *pdTemp = new double [ny];
1626 for (i = 0; i < ny; i++)
1627 pdTemp[i] = v[xCursor][i];
1628 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1629 for (i = 0; i < ny; i++)
1630 pcIn[i].re = pdTemp[i];
1632 for (i = 0; i < ny; i++) {
1633 if (rIF.isComplex())
1634 pdTemp[i] = vImag[xCursor][i];
1638 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1639 for (i = 0; i < ny; i++)
1640 pcIn[i].im = pdTemp[i];
1642 fftw_plan plan = fftw_create_plan (ny, FFTW_BACKWARD, FFTW_IN_PLACE | FFTW_ESTIMATE | FFTW_USE_WISDOM);
1643 fftw_one (plan, pcIn, NULL);
1644 fftw_destroy_plan (plan);
1646 double* pX = new double [ny];
1647 double* pYReal = new double [ny];
1648 double* pYImag = new double [ny];
1649 double* pYMag = new double [ny];
1650 for (i = 0; i < ny; i++) {
1652 pYReal[i] = pcIn[i].re / ny;
1653 pYImag[i] = pcIn[i].im / ny;
1654 pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1657 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1659 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1661 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1662 std::ostringstream os;
1663 os << "Column " << xCursor;
1664 std::string title("title ");
1666 rPlotFile.addEzsetCommand (title.c_str());
1667 rPlotFile.addEzsetCommand ("xlabel Column");
1668 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1669 rPlotFile.addEzsetCommand ("lxfrac 0");
1670 rPlotFile.addEzsetCommand ("curve 1");
1671 rPlotFile.addEzsetCommand ("color 1");
1672 rPlotFile.addEzsetCommand ("dash 1");
1673 rPlotFile.addEzsetCommand ("curve 2");
1674 rPlotFile.addEzsetCommand ("color 4");
1675 rPlotFile.addEzsetCommand ("dash 3");
1676 rPlotFile.addEzsetCommand ("curve 3");
1677 rPlotFile.addEzsetCommand ("color 0");
1678 rPlotFile.addEzsetCommand ("solid");
1679 rPlotFile.addEzsetCommand ("box");
1680 rPlotFile.addEzsetCommand ("grid");
1681 rPlotFile.setCurveSize (4, ny);
1682 rPlotFile.addColumn (0, pX);
1683 rPlotFile.addColumn (1, pYReal);
1684 rPlotFile.addColumn (2, pYImag);
1685 rPlotFile.addColumn (3, pYMag);
1686 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1687 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1688 os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1689 *theApp->getLog() << os.str().c_str() << "\n";
1690 rPlotFile.addDescription (os.str().c_str());
1699 if (theApp->getAskDeleteNewDocs())
1700 pPlotDoc->Modify (true);
1701 pPlotDoc->getView()->getFrame()->Show(true);
1702 pPlotDoc->UpdateAllViews ();
1703 pPlotDoc->Activate();
1709 ImageFileView::OnCompareCol (wxCommandEvent& event)
1711 int xCursor, yCursor;
1712 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1713 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1717 std::vector<ImageFileDocument*> vecIFDoc;
1718 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1719 if (vecIFDoc.size() == 0) {
1720 wxMessageBox ("No compatible images for Column Comparison", "Error");
1723 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1725 if (dialogGetCompare.ShowModal() == wxID_OK) {
1726 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1727 const ImageFile& rIF = GetDocument()->getImageFile();
1728 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1730 ImageFileArrayConst v1 = rIF.getArray();
1731 ImageFileArrayConst v2 = rCompareIF.getArray();
1735 if (v1 != NULL && xCursor < nx) {
1736 double* pX = new double [ny];
1737 double* pY1 = new double [ny];
1738 double* pY2 = new double [ny];
1739 for (int i = 0; i < ny; i++) {
1741 pY1[i] = v1[xCursor][i];
1742 pY2[i] = v2[xCursor][i];
1744 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1746 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1748 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1749 std::ostringstream os;
1750 os << "Column " << xCursor << " Comparison";
1751 std::string title("title ");
1753 rPlotFile.addEzsetCommand (title.c_str());
1754 rPlotFile.addEzsetCommand ("xlabel Row");
1755 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1756 rPlotFile.addEzsetCommand ("lxfrac 0");
1757 rPlotFile.addEzsetCommand ("curve 1");
1758 rPlotFile.addEzsetCommand ("color 2");
1759 rPlotFile.addEzsetCommand ("curve 2");
1760 rPlotFile.addEzsetCommand ("color 4");
1761 rPlotFile.addEzsetCommand ("dash 5");
1762 rPlotFile.addEzsetCommand ("box");
1763 rPlotFile.addEzsetCommand ("grid");
1764 rPlotFile.setCurveSize (3, ny);
1765 rPlotFile.addColumn (0, pX);
1766 rPlotFile.addColumn (1, pY1);
1767 rPlotFile.addColumn (2, pY2);
1770 for (iL = 0; iL < rIF.nLabels(); iL++) {
1771 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1773 s += rIF.labelGet(iL).getLabelString();
1774 rPlotFile.addDescription (s.c_str());
1776 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1777 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1779 s += rCompareIF.labelGet(iL).getLabelString();
1780 rPlotFile.addDescription (s.c_str());
1782 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1783 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1784 *theApp->getLog() << os.str().c_str() << "\n";
1785 rPlotFile.addDescription (os.str().c_str());
1790 if (theApp->getAskDeleteNewDocs())
1791 pPlotDoc->Modify (true);
1792 pPlotDoc->getView()->getFrame()->Show(true);
1793 pPlotDoc->UpdateAllViews ();
1794 pPlotDoc->Activate();
1800 ImageFileView::OnCompareRow (wxCommandEvent& event)
1802 int xCursor, yCursor;
1803 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1804 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1808 std::vector<ImageFileDocument*> vecIFDoc;
1809 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1811 if (vecIFDoc.size() == 0) {
1812 wxMessageBox ("No compatible images for Row Comparison", "Error");
1816 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1818 if (dialogGetCompare.ShowModal() == wxID_OK) {
1819 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1820 const ImageFile& rIF = GetDocument()->getImageFile();
1821 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1823 ImageFileArrayConst v1 = rIF.getArray();
1824 ImageFileArrayConst v2 = rCompareIF.getArray();
1828 if (v1 != NULL && yCursor < ny) {
1829 double* pX = new double [nx];
1830 double* pY1 = new double [nx];
1831 double* pY2 = new double [nx];
1832 for (int i = 0; i < nx; i++) {
1834 pY1[i] = v1[i][yCursor];
1835 pY2[i] = v2[i][yCursor];
1837 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1839 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1841 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1842 std::ostringstream os;
1843 os << "Row " << yCursor << " Comparison";
1844 std::string title("title ");
1846 rPlotFile.addEzsetCommand (title.c_str());
1847 rPlotFile.addEzsetCommand ("xlabel Column");
1848 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1849 rPlotFile.addEzsetCommand ("lxfrac 0");
1850 rPlotFile.addEzsetCommand ("curve 1");
1851 rPlotFile.addEzsetCommand ("color 2");
1852 rPlotFile.addEzsetCommand ("curve 2");
1853 rPlotFile.addEzsetCommand ("color 4");
1854 rPlotFile.addEzsetCommand ("dash 5");
1855 rPlotFile.addEzsetCommand ("box");
1856 rPlotFile.addEzsetCommand ("grid");
1857 rPlotFile.setCurveSize (3, nx);
1858 rPlotFile.addColumn (0, pX);
1859 rPlotFile.addColumn (1, pY1);
1860 rPlotFile.addColumn (2, pY2);
1862 for (iL = 0; iL < rIF.nLabels(); iL++) {
1863 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1865 s += rIF.labelGet(iL).getLabelString();
1866 rPlotFile.addDescription (s.c_str());
1868 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1869 std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1871 s += rCompareIF.labelGet(iL).getLabelString();
1872 rPlotFile.addDescription (s.c_str());
1874 os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1875 << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1876 *theApp->getLog() << os.str().c_str() << "\n";
1877 rPlotFile.addDescription (os.str().c_str());
1882 if (theApp->getAskDeleteNewDocs())
1883 pPlotDoc->Modify (true);
1884 pPlotDoc->getView()->getFrame()->Show(true);
1885 pPlotDoc->UpdateAllViews ();
1886 pPlotDoc->Activate();
1891 static int NUMBER_HISTOGRAM_BINS = 256;
1894 ImageFileView::OnPlotHistogram (wxCommandEvent& event)
1896 const ImageFile& rIF = GetDocument()->getImageFile();
1897 ImageFileArrayConst v = rIF.getArray();
1901 if (v != NULL && nx > 0 && ny > 0) {
1902 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1904 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1908 double* pX = new double [NUMBER_HISTOGRAM_BINS];
1909 double* pY = new double [NUMBER_HISTOGRAM_BINS];
1911 rIF.getMinMax (dMin, dMax);
1912 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
1914 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
1915 pX[i] = dMin + (i + 0.5) * dBinWidth;
1918 for (int ix = 0; ix < nx; ix++)
1919 for (int iy = 0; iy < ny; iy++) {
1920 int iBin = nearest<int> ((v[ix][iy] - dMin) / dBinWidth);
1921 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
1925 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1926 std::ostringstream os;
1928 std::string title("title ");
1930 rPlotFile.addEzsetCommand (title.c_str());
1931 rPlotFile.addEzsetCommand ("xlabel Pixel Value");
1932 rPlotFile.addEzsetCommand ("ylabel Count");
1933 rPlotFile.addEzsetCommand ("box");
1934 rPlotFile.addEzsetCommand ("grid");
1935 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
1936 rPlotFile.addColumn (0, pX);
1937 rPlotFile.addColumn (1, pY);
1938 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++) {
1939 std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1941 s += rIF.labelGet(iL).getLabelString();
1942 rPlotFile.addDescription (s.c_str());
1944 os << " plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1945 *theApp->getLog() << os.str().c_str() << "\n";
1946 rPlotFile.addDescription (os.str().c_str());
1949 if (theApp->getAskDeleteNewDocs())
1950 pPlotDoc->Modify (true);
1951 pPlotDoc->getView()->getFrame()->Show(true);
1952 pPlotDoc->UpdateAllViews ();
1953 pPlotDoc->Activate();
1960 PhantomCanvas::PhantomCanvas (PhantomFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1961 : wxScrolledWindow(frame, -1, pos, size, style)
1966 PhantomCanvas::~PhantomCanvas ()
1972 PhantomCanvas::OnDraw (wxDC& dc)
1975 m_pView->OnDraw(& dc);
1979 PhantomCanvas::GetBestSize() const
1985 theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
1986 xSize = maxValue<int> (xSize, ySize);
1988 ySize = xSize = (xSize / 4);
1992 return wxSize (xSize, ySize);
1999 IMPLEMENT_DYNAMIC_CLASS(PhantomFileView, wxView)
2001 BEGIN_EVENT_TABLE(PhantomFileView, wxView)
2002 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomFileView::OnProperties)
2003 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomFileView::OnRasterize)
2004 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomFileView::OnProjections)
2007 PhantomFileView::PhantomFileView()
2008 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0)
2010 #if defined(DEBUG) || defined(_DEBUG)
2011 m_iDefaultNDet = 165;
2012 m_iDefaultNView = 180;
2013 m_iDefaultNSample = 1;
2015 m_iDefaultNDet = 367;
2016 m_iDefaultNView = 320;
2017 m_iDefaultNSample = 2;
2019 m_iDefaultOffsetView = 0;
2020 m_dDefaultRotation = 1;
2021 m_dDefaultFocalLength = 2;
2022 m_dDefaultCenterDetectorLength = 2;
2023 m_dDefaultViewRatio = 1;
2024 m_dDefaultScanRatio = 1;
2025 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
2026 m_iDefaultTrace = Trace::TRACE_NONE;
2029 m_iDefaultRasterNX = 115;
2030 m_iDefaultRasterNY = 115;
2031 m_iDefaultRasterNSamples = 1;
2033 m_iDefaultRasterNX = 256;
2034 m_iDefaultRasterNY = 256;
2035 m_iDefaultRasterNSamples = 2;
2037 m_dDefaultRasterViewRatio = 1;
2040 PhantomFileView::~PhantomFileView()
2042 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2043 GetDocumentManager()->ActivateView(this, FALSE, TRUE);
2047 PhantomFileView::OnProperties (wxCommandEvent& event)
2049 const int idPhantom = GetDocument()->getPhantomID();
2050 const wxString& namePhantom = GetDocument()->getPhantomName();
2051 std::ostringstream os;
2052 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")" << "\n";
2053 const Phantom& rPhantom = GetDocument()->getPhantom();
2054 rPhantom.printDefinitions (os);
2056 rPhantom.print (os);
2058 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2059 wxMessageBox (os.str().c_str(), "Phantom Properties");
2060 GetDocument()->Activate();
2065 PhantomFileView::OnProjections (wxCommandEvent& event)
2067 DialogGetProjectionParameters dialogProjection (getFrameForChild(),
2068 m_iDefaultNDet, m_iDefaultNView, m_iDefaultOffsetView, m_iDefaultNSample, m_dDefaultRotation,
2069 m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio,
2070 m_iDefaultGeometry, m_iDefaultTrace);
2071 int retVal = dialogProjection.ShowModal();
2072 if (retVal != wxID_OK)
2075 m_iDefaultNDet = dialogProjection.getNDet();
2076 m_iDefaultNView = dialogProjection.getNView();
2077 m_iDefaultOffsetView = dialogProjection.getOffsetView();
2078 m_iDefaultNSample = dialogProjection.getNSamples();
2079 m_iDefaultTrace = dialogProjection.getTrace();
2080 m_dDefaultRotation = dialogProjection.getRotAngle();
2081 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
2082 m_dDefaultCenterDetectorLength = dialogProjection.getCenterDetectorLengthRatio();
2083 m_dDefaultViewRatio = dialogProjection.getViewRatio();
2084 m_dDefaultScanRatio = dialogProjection.getScanRatio();
2085 wxString sGeometry = dialogProjection.getGeometry();
2086 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
2087 double dRotationRadians = m_dDefaultRotation;
2088 m_dDefaultRotation /= TWOPI; // convert back to fraction of a circle
2090 if (m_iDefaultNDet <= 0 || m_iDefaultNView <= 0 || sGeometry == "")
2093 const Phantom& rPhantom = GetDocument()->getPhantom();
2094 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultOffsetView, m_iDefaultNSample,
2095 dRotationRadians, m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio);
2096 if (theScanner.fail()) {
2097 wxString msg = "Failed making scanner\n";
2098 msg += theScanner.failMessage().c_str();
2099 *theApp->getLog() << msg << "\n";
2100 wxMessageBox (msg, "Error");
2104 std::ostringstream os;
2105 os << "Projections for " << rPhantom.name()
2106 << ": nDet=" << m_iDefaultNDet
2107 << ", nView=" << m_iDefaultNView
2108 << ", gantry offset=" << m_iDefaultOffsetView
2109 << ", nSamples=" << m_iDefaultNSample
2110 << ", RotAngle=" << m_dDefaultRotation
2111 << ", FocalLengthRatio=" << m_dDefaultFocalLength
2112 << ", CenterDetectorLengthRatio=" << m_dDefaultCenterDetectorLength
2113 << ", ViewRatio=" << m_dDefaultViewRatio
2114 << ", ScanRatio=" << m_dDefaultScanRatio
2115 << ", Geometry=" << sGeometry.c_str()
2116 << ", FanBeamAngle=" << convertRadiansToDegrees (theScanner.fanBeamAngle());
2119 Projections* pProj = NULL;
2120 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2121 pProj = new Projections;
2122 pProj->initFromScanner (theScanner);
2124 ProjectionsDialog dialogProjections (theScanner, *pProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(getFrameForChild()));
2125 for (int iView = 0; iView < pProj->nView(); iView++) {
2127 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
2132 while (dialogProjections.isPaused()) {
2139 if (theApp->getUseBackgroundTasks()) {
2140 ProjectorSupervisorThread* pProjector = new ProjectorSupervisorThread (this, m_iDefaultNDet,
2141 m_iDefaultNView, m_iDefaultOffsetView, sGeometry.c_str(), m_iDefaultNSample, dRotationRadians,
2142 m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio, os.str().c_str());
2143 if (pProjector->Create() != wxTHREAD_NO_ERROR) {
2144 sys_error (ERR_SEVERE, "Error creating projector thread");
2148 pProjector->SetPriority(60);
2152 #endif // HAVE_WXTHREADS
2154 pProj = new Projections;
2155 pProj->initFromScanner (theScanner);
2156 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), pProj->nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2157 for (int i = 0; i < pProj->nView(); i++) {
2158 //theScanner.collectProjections (*pProj, rPhantom, i, 1, true, m_iDefaultTrace);
2159 theScanner.collectProjections (*pProj, rPhantom, i, 1, theScanner.offsetView(), true, m_iDefaultTrace);
2160 if ((i + 1) % ITER_PER_UPDATE == 0)
2161 if (! dlgProgress.Update (i+1)) {
2169 *theApp->getLog() << os.str().c_str() << "\n";
2170 pProj->setRemark (os.str());
2171 pProj->setCalcTime (timer.timerEnd());
2173 ProjectionFileDocument* pProjectionDoc = theApp->newProjectionDoc();
2174 if (! pProjectionDoc) {
2175 sys_error (ERR_SEVERE, "Unable to create projection document");
2178 pProjectionDoc->setProjections (pProj);
2179 if (theApp->getAskDeleteNewDocs())
2180 pProjectionDoc-> Modify(true);
2181 pProjectionDoc->UpdateAllViews (this);
2182 pProjectionDoc->getView()->setInitialClientSize();
2183 pProjectionDoc->Activate();
2188 PhantomFileView::OnRasterize (wxCommandEvent& event)
2190 DialogGetRasterParameters dialogRaster (getFrameForChild(), m_iDefaultRasterNX, m_iDefaultRasterNY,
2191 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio);
2192 int retVal = dialogRaster.ShowModal();
2193 if (retVal != wxID_OK)
2196 m_iDefaultRasterNX = dialogRaster.getXSize();
2197 m_iDefaultRasterNY = dialogRaster.getYSize();
2198 m_iDefaultRasterNSamples = dialogRaster.getNSamples();
2199 m_dDefaultRasterViewRatio = dialogRaster.getViewRatio();
2200 if (m_iDefaultRasterNSamples < 1)
2201 m_iDefaultRasterNSamples = 1;
2202 if (m_dDefaultRasterViewRatio < 0)
2203 m_dDefaultRasterViewRatio = 0;
2204 if (m_iDefaultRasterNX <= 0 || m_iDefaultRasterNY <= 0)
2207 const Phantom& rPhantom = GetDocument()->getPhantom();
2208 std::ostringstream os;
2209 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << m_iDefaultRasterNX << ", YSize="
2210 << m_iDefaultRasterNY << ", ViewRatio=" << m_dDefaultRasterViewRatio << ", nSamples="
2211 << m_iDefaultRasterNSamples;;
2214 if (theApp->getUseBackgroundTasks()) {
2215 RasterizerSupervisorThread* pThread = new RasterizerSupervisorThread (this, m_iDefaultRasterNX, m_iDefaultRasterNY,
2216 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio, os.str().c_str());
2217 if (pThread->Create() != wxTHREAD_NO_ERROR) {
2218 *theApp->getLog() << "Error creating rasterizer thread\n";
2221 pThread->SetPriority (60);
2226 ImageFile* pImageFile = new ImageFile (m_iDefaultRasterNX, m_iDefaultRasterNY);
2228 wxProgressDialog dlgProgress (wxString("Rasterize"),
2229 wxString("Rasterization Progress"),
2230 pImageFile->nx() + 1,
2234 for (unsigned int i = 0; i < pImageFile->nx(); i++) {
2235 rPhantom.convertToImagefile (*pImageFile, m_dDefaultRasterViewRatio,
2236 m_iDefaultRasterNSamples, Trace::TRACE_NONE,
2238 if ((i + 1) % ITER_PER_UPDATE == 0)
2239 if (! dlgProgress.Update (i+1)) {
2245 ImageFileDocument* pRasterDoc = theApp->newImageDoc();
2247 sys_error (ERR_SEVERE, "Unable to create image file");
2250 pRasterDoc->setImageFile (pImageFile);
2251 if (theApp->getAskDeleteNewDocs())
2252 pRasterDoc->Modify (true);
2253 *theApp->getLog() << os.str().c_str() << "\n";
2254 pImageFile->labelAdd (os.str().c_str(), timer.timerEnd());
2256 pRasterDoc->UpdateAllViews(this);
2257 pRasterDoc->getView()->setInitialClientSize();
2258 pRasterDoc->Activate();
2264 PhantomFileView::CreateCanvas (wxFrame *parent)
2266 PhantomCanvas* pCanvas;
2268 pCanvas = new PhantomCanvas (this, parent, wxPoint(0, 0), wxSize(0,0), 0);
2269 pCanvas->SetBackgroundColour(*wxWHITE);
2280 PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2283 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2285 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2287 theApp->setIconForFrame (subframe);
2289 m_pFileMenu = new wxMenu;
2291 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2292 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2293 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2294 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2295 m_pFileMenu->Append(wxID_CLOSE, "&Close");
2297 m_pFileMenu->AppendSeparator();
2298 m_pFileMenu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
2300 m_pFileMenu->AppendSeparator();
2301 m_pFileMenu->Append(wxID_PRINT, "&Print...");
2302 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2303 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2304 m_pFileMenu->AppendSeparator();
2305 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
2307 m_pFileMenu->AppendSeparator();
2308 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
2309 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2311 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2312 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2314 wxMenu *process_menu = new wxMenu;
2315 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...\tCtrl-R");
2316 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...\tCtrl-J");
2318 wxMenu *help_menu = new wxMenu;
2319 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2320 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
2321 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
2322 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2324 wxMenuBar *menu_bar = new wxMenuBar;
2326 menu_bar->Append(m_pFileMenu, "&File");
2327 menu_bar->Append(process_menu, "&Process");
2328 menu_bar->Append(help_menu, "&Help");
2330 subframe->SetMenuBar(menu_bar);
2331 subframe->Centre(wxBOTH);
2333 wxAcceleratorEntry accelEntries[3];
2334 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('J'), PHMMENU_PROCESS_PROJECTIONS);
2335 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('R'), PHMMENU_PROCESS_RASTERIZE);
2336 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('I'), PHMMENU_FILE_PROPERTIES);
2337 wxAcceleratorTable accelTable (3, accelEntries);
2338 subframe->SetAcceleratorTable (accelTable);
2345 PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2347 m_pFrame = CreateChildFrame(doc, this);
2349 m_pCanvas = CreateCanvas (m_pFrame);
2350 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
2351 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
2352 m_pFrame->SetTitle ("PhantomFileView");
2354 m_pFrame->Show(true);
2361 PhantomFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2364 m_pCanvas->Refresh();
2368 PhantomFileView::OnClose (bool deleteWindow)
2370 //GetDocumentManager()->ActivateView (this, false, true);
2371 if (! GetDocument() || ! GetDocument()->Close())
2376 m_pCanvas->setView(NULL);
2379 wxString s(wxTheApp->GetAppName());
2381 m_pFrame->SetTitle(s);
2388 if (GetDocument() && GetDocument()->getBadFileOpen())
2389 ::wxYield(); // wxWindows bug workaround
2396 PhantomFileView::OnDraw (wxDC* dc)
2399 m_pCanvas->GetClientSize (&xsize, &ysize);
2400 SGPDriver driver (dc, xsize, ysize);
2402 const Phantom& rPhantom = GetDocument()->getPhantom();
2403 sgp.setColor (C_RED);
2404 rPhantom.show (sgp);
2409 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2410 : wxScrolledWindow(frame, -1, pos, size, style)
2415 ProjectionFileCanvas::~ProjectionFileCanvas ()
2421 ProjectionFileCanvas::OnDraw(wxDC& dc)
2424 m_pView->OnDraw(& dc);
2428 ProjectionFileCanvas::GetBestSize () const
2435 Projections& rProj = m_pView->GetDocument()->getProjections();
2436 best.Set (rProj.nDet(), rProj.nView());
2443 // ProjectionFileView
2445 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
2447 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
2448 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
2449 EVT_MENU(PJMENU_RECONSTRUCT_FBP, ProjectionFileView::OnReconstructFBP)
2450 EVT_MENU(PJMENU_RECONSTRUCT_FBP_REBIN, ProjectionFileView::OnReconstructFBPRebin)
2451 EVT_MENU(PJMENU_RECONSTRUCT_FOURIER, ProjectionFileView::OnReconstructFourier)
2452 EVT_MENU(PJMENU_CONVERT_RECTANGULAR, ProjectionFileView::OnConvertRectangular)
2453 EVT_MENU(PJMENU_CONVERT_POLAR, ProjectionFileView::OnConvertPolar)
2454 EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
2455 EVT_MENU(PJMENU_CONVERT_PARALLEL, ProjectionFileView::OnConvertParallel)
2456 EVT_MENU(PJMENU_PLOT_TTHETA_SAMPLING, ProjectionFileView::OnPlotTThetaSampling)
2457 EVT_MENU(PJMENU_PLOT_HISTOGRAM, ProjectionFileView::OnPlotHistogram)
2458 // EVT_MENU(PJMENU_ARTIFACT_REDUCTION, ProjectionFileView::OnArtifactReduction)
2462 ProjectionFileView::ProjectionFileView()
2463 : wxView(), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0)
2473 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
2474 m_dDefaultFilterParam = 1.;
2476 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
2477 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
2479 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
2480 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
2482 m_iDefaultZeropad = 1;
2483 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF;
2484 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
2485 m_iDefaultInterpParam = 1;
2486 m_iDefaultTrace = Trace::TRACE_NONE;
2488 m_iDefaultPolarNX = 256;
2489 m_iDefaultPolarNY = 256;
2490 m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR;
2491 m_iDefaultPolarZeropad = 1;
2494 ProjectionFileView::~ProjectionFileView()
2496 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2497 GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2501 ProjectionFileView::OnProperties (wxCommandEvent& event)
2503 const Projections& rProj = GetDocument()->getProjections();
2504 std::ostringstream os;
2505 rProj.printScanInfo(os);
2506 *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2507 wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
2508 dialogMsg.ShowModal();
2509 GetDocument()->Activate();
2514 ProjectionFileView::OnConvertRectangular (wxCommandEvent& event)
2516 Projections& rProj = GetDocument()->getProjections();
2518 int nDet = rProj.nDet();
2519 int nView = rProj.nView();
2520 ImageFile* pIF = new ImageFile (nDet, nView);
2521 ImageFileArray v = pIF->getArray();
2522 for (int iv = 0; iv < nView; iv++) {
2523 DetectorValue* detval = rProj.getDetectorArray(iv).detValues();
2525 for (int id = 0; id < nDet; id++)
2526 v[id][iv] = detval[id];
2529 ImageFileDocument* pRectDoc = theApp->newImageDoc ();
2531 sys_error (ERR_SEVERE, "Unable to create image file");
2534 pRectDoc->setImageFile (pIF);
2535 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2536 std::ostringstream os;
2537 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to rectangular image";
2538 *theApp->getLog() << os.str().c_str() << "\n";
2539 pIF->labelAdd (os.str().c_str());
2540 if (theApp->getAskDeleteNewDocs())
2541 pRectDoc->Modify (true);
2542 pRectDoc->UpdateAllViews();
2543 pRectDoc->getView()->setInitialClientSize();
2544 pRectDoc->Activate();
2548 ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
2550 Projections& rProj = GetDocument()->getProjections();
2551 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2552 m_iDefaultPolarInterpolation, -1, IDH_DLG_POLAR);
2553 if (dialogPolar.ShowModal() == wxID_OK) {
2554 wxProgressDialog dlgProgress (wxString("Convert Polar"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2555 wxString strInterpolation (dialogPolar.getInterpolationName());
2556 m_iDefaultPolarNX = dialogPolar.getXSize();
2557 m_iDefaultPolarNY = dialogPolar.getYSize();
2558 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2559 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2560 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2562 if (! rProj.convertPolar (*pIF, m_iDefaultPolarInterpolation)) {
2564 *theApp->getLog() << "Error converting to Polar\n";
2568 pPolarDoc = theApp->newImageDoc ();
2570 sys_error (ERR_SEVERE, "Unable to create image file");
2573 pPolarDoc->setImageFile (pIF);
2574 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2575 std::ostringstream os;
2576 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to polar image: xSize="
2577 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2578 << strInterpolation.c_str();
2579 *theApp->getLog() << os.str().c_str() << "\n";
2580 pIF->labelAdd (os.str().c_str());
2581 if (theApp->getAskDeleteNewDocs())
2582 pPolarDoc->Modify (true);
2583 pPolarDoc->UpdateAllViews ();
2584 pPolarDoc->getView()->setInitialClientSize();
2585 pPolarDoc->Activate();
2590 ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
2592 Projections& rProj = GetDocument()->getProjections();
2593 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert to FFT Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2594 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad, IDH_DLG_FFT_POLAR);
2595 if (dialogPolar.ShowModal() == wxID_OK) {
2596 wxProgressDialog dlgProgress (wxString("Convert FFT Polar"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2597 wxString strInterpolation (dialogPolar.getInterpolationName());
2598 m_iDefaultPolarNX = dialogPolar.getXSize();
2599 m_iDefaultPolarNY = dialogPolar.getYSize();
2600 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2601 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2603 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2604 if (! rProj.convertFFTPolar (*pIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad)) {
2606 *theApp->getLog() << "Error converting to polar\n";
2609 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2611 sys_error (ERR_SEVERE, "Unable to create image file");
2614 pPolarDoc->setImageFile (pIF);
2615 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2616 std::ostringstream os;
2617 os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to FFT polar image: xSize="
2618 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2619 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2620 *theApp->getLog() << os.str().c_str() << "\n";
2621 pIF->labelAdd (os.str().c_str());
2622 if (theApp->getAskDeleteNewDocs())
2623 pPolarDoc->Modify (true);
2624 pPolarDoc->UpdateAllViews (this);
2625 pPolarDoc->getView()->setInitialClientSize();
2626 pPolarDoc->Activate();
2631 ProjectionFileView::OnPlotTThetaSampling (wxCommandEvent& event)
2633 DialogGetThetaRange dlgTheta (this->getFrame(), ParallelRaysums::THETA_RANGE_UNCONSTRAINED);
2634 if (dlgTheta.ShowModal() != wxID_OK)
2637 int iThetaRange = dlgTheta.getThetaRange();
2639 Projections& rProj = GetDocument()->getProjections();
2640 ParallelRaysums parallel (&rProj, iThetaRange);
2641 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
2642 PlotFile& rPlot = pPlotDoc->getPlotFile();
2643 ParallelRaysums::CoordinateContainer& coordContainer = parallel.getCoordinates();
2644 double* pdT = new double [parallel.getNumCoordinates()];
2645 double* pdTheta = new double [parallel.getNumCoordinates()];
2647 for (int i = 0; i < parallel.getNumCoordinates(); i++) {
2648 pdT[i] = coordContainer[i]->m_dT;
2649 pdTheta[i] = coordContainer[i]->m_dTheta;
2651 rPlot.setCurveSize (2, parallel.getNumCoordinates(), true);
2652 rPlot.addEzsetCommand ("title T-Theta Sampling");
2653 rPlot.addEzsetCommand ("xlabel T");
2654 rPlot.addEzsetCommand ("ylabel Theta");
2655 rPlot.addEzsetCommand ("curve 1");
2656 if (rProj.nDet() < 50 && rProj.nView() < 50)
2657 rPlot.addEzsetCommand ("symbol 1"); // x symbol
2659 rPlot.addEzsetCommand ("symbol 6"); // point symbol
2660 rPlot.addEzsetCommand ("noline");
2661 rPlot.addColumn (0, pdT);
2662 rPlot.addColumn (1, pdTheta);
2665 if (theApp->getAskDeleteNewDocs())
2666 pPlotDoc->Modify (true);
2667 pPlotDoc->getView()->getFrame()->Show(true);
2668 pPlotDoc->UpdateAllViews ();
2669 pPlotDoc->Activate();
2674 ProjectionFileView::OnPlotHistogram (wxCommandEvent& event)
2676 Projections& rProj = GetDocument()->getProjections();
2677 int nDet = rProj.nDet();
2678 int nView = rProj.nView();
2680 if (nDet < 1 || nView < 1)
2683 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
2685 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
2689 DetectorValue* pdDetval = rProj.getDetectorArray(0).detValues();
2690 double dMin = pdDetval[0], dMax = pdDetval[0];
2692 for (int iv = 0; iv < nView; iv++) {
2693 pdDetval = rProj.getDetectorArray(iv).detValues();
2694 for (int id = 0; id < nDet; id++) {
2695 double dV = pdDetval[id];
2703 double* pX = new double [NUMBER_HISTOGRAM_BINS];
2704 double* pY = new double [NUMBER_HISTOGRAM_BINS];
2705 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
2707 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
2708 pX[i] = dMin + (i + 0.5) * dBinWidth;
2711 for (int j = 0; j < nView; j++) {
2712 pdDetval = rProj.getDetectorArray(j).detValues();
2713 for (int id = 0; id < nDet; id++) {
2714 int iBin = nearest<int> ((pdDetval[id] - dMin) / dBinWidth);
2715 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
2719 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
2720 std::ostringstream os;
2722 std::string title("title ");
2724 rPlotFile.addEzsetCommand (title.c_str());
2725 rPlotFile.addEzsetCommand ("xlabel Detector Value");
2726 rPlotFile.addEzsetCommand ("ylabel Count");
2727 rPlotFile.addEzsetCommand ("box");
2728 rPlotFile.addEzsetCommand ("grid");
2729 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
2730 rPlotFile.addColumn (0, pX);
2731 rPlotFile.addColumn (1, pY);
2732 rPlotFile.addDescription (rProj.remark());
2733 os << " plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
2734 *theApp->getLog() << os.str().c_str() << "\n";
2735 rPlotFile.addDescription (os.str().c_str());
2738 if (theApp->getAskDeleteNewDocs())
2739 pPlotDoc->Modify (true);
2740 pPlotDoc->getView()->getFrame()->Show(true);
2741 pPlotDoc->UpdateAllViews ();
2742 pPlotDoc->Activate();
2747 ProjectionFileView::OnConvertParallel (wxCommandEvent& event)
2749 Projections& rProj = GetDocument()->getProjections();
2750 if (rProj.geometry() == Scanner::GEOMETRY_PARALLEL) {
2751 wxMessageBox ("Projections are already parallel", "Error");
2754 wxProgressDialog dlgProgress (wxString("Convert to Parallel"), wxString("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2755 Projections* pProjNew = rProj.interpolateToParallel();
2756 ProjectionFileDocument* pProjDocNew = theApp->newProjectionDoc();
2757 pProjDocNew->setProjections (pProjNew);
2759 if (ProjectionFileView* projView = pProjDocNew->getView()) {
2760 projView->OnUpdate (projView, NULL);
2761 if (projView->getCanvas())
2762 projView->getCanvas()->SetClientSize (pProjNew->nDet(), pProjNew->nView());
2763 if (wxFrame* pFrame = projView->getFrame()) {
2768 GetDocumentManager()->ActivateView (projView, true, false);
2770 if (theApp->getAskDeleteNewDocs())
2771 pProjDocNew-> Modify(true);
2772 pProjDocNew->UpdateAllViews (this);
2773 pProjDocNew->getView()->setInitialClientSize();
2774 pProjDocNew->Activate();
2778 ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
2780 Projections& rProj = GetDocument()->getProjections();
2781 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Fourier Reconstruction", m_iDefaultPolarNX, m_iDefaultPolarNY,
2782 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad, IDH_DLG_RECON_FOURIER);
2783 if (dialogPolar.ShowModal() == wxID_OK) {
2784 wxProgressDialog dlgProgress (wxString("Reconstruction Fourier"), wxString("Reconstruction Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2785 wxString strInterpolation (dialogPolar.getInterpolationName());
2786 m_iDefaultPolarNX = dialogPolar.getXSize();
2787 m_iDefaultPolarNY = dialogPolar.getYSize();
2788 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2789 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2791 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2792 if (! rProj.convertFFTPolar (*pIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad)) {
2794 *theApp->getLog() << "Error converting to polar\n";
2800 pIF->magnitude(*pIF);
2801 Fourier::shuffleFourierToNaturalOrder (*pIF);
2803 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2805 sys_error (ERR_SEVERE, "Unable to create image file");
2808 pPolarDoc->setImageFile (pIF);
2809 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2810 std::ostringstream os;
2811 os << "Reconstruct Fourier " << GetFrame()->GetTitle().c_str() << ": xSize="
2812 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2813 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2814 *theApp->getLog() << os.str().c_str() << "\n";
2815 pIF->labelAdd (os.str().c_str());
2816 if (theApp->getAskDeleteNewDocs())
2817 pPolarDoc->Modify (true);
2818 pPolarDoc->UpdateAllViews ();
2819 pPolarDoc->getView()->setInitialClientSize();
2820 pPolarDoc->Activate();
2825 ProjectionFileView::OnReconstructFBPRebin (wxCommandEvent& event)
2827 Projections& rProj = GetDocument()->getProjections();
2828 doReconstructFBP (rProj, true);
2832 ProjectionFileView::OnReconstructFBP (wxCommandEvent& event)
2834 Projections& rProj = GetDocument()->getProjections();
2835 doReconstructFBP (rProj, false);
2839 ProjectionFileView::doReconstructFBP (const Projections& rProj, bool bRebinToParallel)
2841 ReconstructionROI defaultROI;
2842 defaultROI.m_dXMin = -rProj.phmLen() / 2;
2843 defaultROI.m_dXMax = defaultROI.m_dXMin + rProj.phmLen();
2844 defaultROI.m_dYMin = -rProj.phmLen() / 2;
2845 defaultROI.m_dYMax = defaultROI.m_dYMin + rProj.phmLen();
2847 DialogGetReconstructionParameters dialogReconstruction (getFrameForChild(), m_iDefaultNX, m_iDefaultNY,
2848 m_iDefaultFilter, m_dDefaultFilterParam, m_iDefaultFilterMethod, m_iDefaultFilterGeneration,
2849 m_iDefaultZeropad, m_iDefaultInterpolation, m_iDefaultInterpParam, m_iDefaultBackprojector,
2850 m_iDefaultTrace, &defaultROI);
2852 int retVal = dialogReconstruction.ShowModal();
2853 if (retVal != wxID_OK)
2856 m_iDefaultNX = dialogReconstruction.getXSize();
2857 m_iDefaultNY = dialogReconstruction.getYSize();
2858 wxString optFilterName = dialogReconstruction.getFilterName();
2859 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
2860 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
2861 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
2862 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
2863 m_iDefaultZeropad = dialogReconstruction.getZeropad();
2864 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
2865 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
2866 wxString optInterpName = dialogReconstruction.getInterpName();
2867 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
2868 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
2869 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
2870 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
2871 m_iDefaultTrace = dialogReconstruction.getTrace();
2872 dialogReconstruction.getROI (&defaultROI);
2874 if (m_iDefaultNX <= 0 && m_iDefaultNY <= 0)
2877 std::ostringstream os;
2878 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();
2879 if (bRebinToParallel)
2880 os << "; Interpolate to Parallel";
2883 ImageFile* pImageFile = NULL;
2884 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2885 pImageFile = new ImageFile (m_iDefaultNX, m_iDefaultNY);
2886 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2887 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2888 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace,
2889 &defaultROI, bRebinToParallel);
2891 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstructor, rProj, *pImageFile, m_iDefaultTrace, getFrameForChild());
2892 for (int iView = 0; iView < rProj.nView(); iView++) {
2894 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView, true)) {
2895 delete pDlgReconstruct;
2896 delete pReconstructor;
2901 while (pDlgReconstruct->isPaused()) {
2906 pReconstructor->postProcessing();
2907 delete pDlgReconstruct;
2908 delete pReconstructor;
2911 if (theApp->getUseBackgroundTasks()) {
2912 ReconstructorSupervisorThread* pReconstructor = new ReconstructorSupervisorThread (this, m_iDefaultNX,
2913 m_iDefaultNY, optFilterName.c_str(), m_dDefaultFilterParam, optFilterMethodName.c_str(),
2914 m_iDefaultZeropad, optFilterGenerationName.c_str(), optInterpName.c_str(), m_iDefaultInterpParam,
2915 optBackprojectName.c_str(), os.str().c_str(), &defaultROI, bRebinToParallel);
2916 if (pReconstructor->Create() != wxTHREAD_NO_ERROR) {
2917 sys_error (ERR_SEVERE, "Error creating reconstructor thread");
2918 delete pReconstructor;
2921 pReconstructor->SetPriority (60);
2922 pReconstructor->Run();
2927 pImageFile = new ImageFile (m_iDefaultNX, m_iDefaultNY);
2928 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2929 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(),
2930 m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(),
2931 optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace,
2932 &defaultROI, bRebinToParallel);
2934 for (int iView = 0; iView < rProj.nView(); iView++) {
2935 pReconstructor->reconstructView (iView, 1);
2936 if ((iView + 1) % ITER_PER_UPDATE == 0)
2937 if (! dlgProgress.Update (iView + 1)) {
2938 delete pReconstructor;
2939 return; // don't make new window, thread will do this
2942 pReconstructor->postProcessing();
2943 delete pReconstructor;
2946 ImageFileDocument* pReconDoc = theApp->newImageDoc();
2948 sys_error (ERR_SEVERE, "Unable to create image file");
2951 *theApp->getLog() << os.str().c_str() << "\n";
2952 pImageFile->labelAdd (rProj.getLabel());
2953 pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd());
2955 pReconDoc->setImageFile (pImageFile);
2956 if (theApp->getAskDeleteNewDocs())
2957 pReconDoc->Modify (true);
2958 pReconDoc->UpdateAllViews();
2959 pReconDoc->getView()->setInitialClientSize();
2960 pReconDoc->Activate();
2965 ProjectionFileView::OnArtifactReduction (wxCommandEvent& event)
2970 ProjectionFileCanvas*
2971 ProjectionFileView::CreateCanvas (wxFrame *parent)
2973 ProjectionFileCanvas* pCanvas;
2975 parent->GetClientSize(&width, &height);
2977 pCanvas = new ProjectionFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
2979 pCanvas->SetScrollbars(20, 20, 50, 50);
2980 pCanvas->SetBackgroundColour(*wxWHITE);
2991 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2994 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2996 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2998 theApp->setIconForFrame (subframe);
3000 m_pFileMenu = new wxMenu;
3002 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
3003 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
3004 m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
3005 m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
3006 m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
3007 m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
3009 m_pFileMenu->AppendSeparator();
3010 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties\tCtrl-I");
3012 m_pFileMenu->AppendSeparator();
3013 m_pFileMenu->Append(wxID_PRINT, "&Print...");
3014 m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
3015 m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
3016 m_pFileMenu->AppendSeparator();
3017 m_pFileMenu->Append(MAINMENU_IMPORT, "&Import...\tCtrl-M");
3019 m_pFileMenu->AppendSeparator();
3020 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, "Prefere&nces...");
3021 m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
3023 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3024 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3026 wxMenu *convert_menu = new wxMenu;
3027 convert_menu->Append (PJMENU_CONVERT_RECTANGULAR, "&Rectangular Image");
3028 convert_menu->Append (PJMENU_CONVERT_POLAR, "&Polar Image...\tCtrl-L");
3029 convert_menu->Append (PJMENU_CONVERT_FFT_POLAR, "FF&T->Polar Image...\tCtrl-T");
3030 convert_menu->AppendSeparator();
3031 convert_menu->Append (PJMENU_CONVERT_PARALLEL, "&Interpolate to Parallel");
3033 // wxMenu* filter_menu = new wxMenu;
3034 // filter_menu->Append (PJMENU_ARTIFACT_REDUCTION, "&Artifact Reduction");
3036 wxMenu* analyze_menu = new wxMenu;
3037 analyze_menu->Append (PJMENU_PLOT_HISTOGRAM, "&Plot Histogram");
3038 analyze_menu->Append (PJMENU_PLOT_TTHETA_SAMPLING, "Plot T-T&heta Sampling...\tCtrl-H");
3040 wxMenu *reconstruct_menu = new wxMenu;
3041 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP, "&Filtered Backprojection...\tCtrl-R", "Reconstruct image using filtered backprojection");
3042 reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP_REBIN, "Filtered &Backprojection (Rebin to Parallel)...\tCtrl-B", "Reconstruct image using filtered backprojection");
3044 // reconstruct_menu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Fourier...\tCtrl-E", "Reconstruct image using inverse Fourier");
3046 wxMenu *help_menu = new wxMenu;
3047 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3048 help_menu->Append (MAINMENU_HELP_TIPS, "&Tips");
3049 help_menu->Append (IDH_QUICKSTART, "&Quick Start");
3050 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3052 wxMenuBar *menu_bar = new wxMenuBar;
3054 menu_bar->Append (m_pFileMenu, "&File");
3055 menu_bar->Append (convert_menu, "&Convert");
3056 // menu_bar->Append (filter_menu, "Fi<er");
3057 menu_bar->Append (analyze_menu, "&Analyze");
3058 menu_bar->Append (reconstruct_menu, "&Reconstruct");
3059 menu_bar->Append (help_menu, "&Help");
3061 subframe->SetMenuBar(menu_bar);
3062 subframe->Centre(wxBOTH);
3064 wxAcceleratorEntry accelEntries[7];
3065 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('L'), PJMENU_CONVERT_POLAR);
3066 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('T'), PJMENU_CONVERT_FFT_POLAR);
3067 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('R'), PJMENU_RECONSTRUCT_FBP);
3068 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('B'), PJMENU_RECONSTRUCT_FBP_REBIN);
3069 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('E'), PJMENU_RECONSTRUCT_FOURIER);
3070 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('I'), PJMENU_FILE_PROPERTIES);
3071 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('H'), PJMENU_PLOT_TTHETA_SAMPLING);
3072 wxAcceleratorTable accelTable (7, accelEntries);
3073 subframe->SetAcceleratorTable (accelTable);
3080 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
3082 m_pFrame = CreateChildFrame(doc, this);
3086 m_pFrame->GetClientSize (&width, &height);
3087 m_pFrame->SetTitle ("ProjectionFileView");
3088 m_pCanvas = CreateCanvas (m_pFrame);
3090 m_pFrame->Show(true);
3097 ProjectionFileView::OnDraw (wxDC* dc)
3100 dc->DrawBitmap (m_bitmap, 0, 0, false);
3105 ProjectionFileView::setInitialClientSize ()
3107 wxSize bestSize = m_pCanvas->GetBestSize();
3109 if (bestSize.x > 800)
3111 if (bestSize.y > 800)
3114 m_pFrame->SetClientSize (bestSize);
3115 m_pFrame->Show (true);
3116 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);