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-2009 Kevin Rosenberg
12 ** This program is free software; you can redistribute it and/or modify
13 ** it under the terms of the GNU General Public License (version 2) as
14 ** published by the Free Software Foundation.
16 ** This program is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ** GNU General Public License for more details.
21 ** You should have received a copy of the GNU General Public License
22 ** along with this program; if not, write to the Free Software
23 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 ******************************************************************************/
26 #include "wx/wxprec.h"
31 #if !wxUSE_DOC_VIEW_ARCHITECTURE
32 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
36 #include "wx/progdlg.h"
37 #include "wx/clipbrd.h"
44 #include "dlgprojections.h"
45 #include "dlgreconstruct.h"
46 #include "backprojectors.h"
47 #include "reconstruct.h"
49 #include "threadproj.h"
50 #include "threadrecon.h"
51 #include "threadraster.h"
53 #if defined(MSVC) || HAVE_SSTREAM
56 #include <sstream_subst>
59 // Used to reduce calls to progress bar update function
60 const short int ITER_PER_UPDATE = 10;
64 BEGIN_EVENT_TABLE(ImageFileCanvas, wxScrolledWindow)
65 EVT_MOUSE_EVENTS(ImageFileCanvas::OnMouseEvent)
66 EVT_CHAR(ImageFileCanvas::OnChar)
70 ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
71 : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v), m_xCursor(-1), m_yCursor(-1)
75 ImageFileCanvas::~ImageFileCanvas()
79 ImageFileCanvas::OnDraw(wxDC& dc)
82 m_pView->OnDraw(& dc);
86 ImageFileCanvas::DrawRubberBandCursor (wxDC& dc, int x, int y)
88 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
93 dc.SetLogicalFunction (wxINVERT);
94 dc.SetPen (*wxGREEN_PEN);
95 dc.DrawLine (0, yPt, nx, yPt);
96 dc.DrawLine (x, 0, x, ny);
97 dc.SetLogicalFunction (wxCOPY);
101 ImageFileCanvas::GetCurrentCursor (int& x, int& y)
106 if (m_xCursor >= 0 && m_yCursor >= 0)
113 ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
122 wxPoint pt(event.GetLogicalPosition(dc));
124 const ImageFileDocument* pIFDoc = m_pView->GetDocument();
127 const ImageFile& rIF = pIFDoc->getImageFile();
128 ImageFileArrayConst v = rIF.getArray();
131 const int yPt = ny - 1 - pt.y;
132 if (event.RightIsDown()) {
133 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
135 os << _T("Image value (") << pt.x << _T(",") << yPt << _T(") = ")
137 if (rIF.isComplex()) {
138 double dImag = rIF.getImaginaryArray()[pt.x][yPt];
140 os << _T(" - ") << -dImag;
142 os << _T(" + ") << dImag;
146 *theApp->getLog() << os;
148 *theApp->getLog() << _T("Mouse out of image range (") << pt.x << _T(",") << yPt << _T(")\n");
150 else if (event.LeftIsDown() || event.LeftUp() || event.RightUp()) {
151 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
152 if (m_xCursor >= 0 && m_yCursor >= 0) {
153 DrawRubberBandCursor (dc, m_xCursor, m_yCursor);
155 DrawRubberBandCursor (dc, pt.x, yPt);
158 wxMenu* pMenu = m_pView->getMenuAnalyze();
159 if (pMenu && ! pMenu->IsEnabled(IFMENU_PLOT_ROW)) {
160 pMenu->Enable (IFMENU_PLOT_ROW, true);
161 pMenu->Enable (IFMENU_PLOT_COL, true);
162 pMenu->Enable (IFMENU_COMPARE_ROW, true);
163 pMenu->Enable (IFMENU_COMPARE_COL, true);
164 pMenu->Enable (IFMENU_PLOT_FFT_ROW, true);
165 pMenu->Enable (IFMENU_PLOT_FFT_COL, true);
168 *theApp->getLog() << _T("Mouse out of image range (") << pt.x << _T(",") << yPt << _T(")\n");
170 if (event.LeftUp()) {
172 os << _T("Selected column ") << pt.x << _T(" , row ") << yPt << _T("\n");
173 *theApp->getLog() << os;
178 ImageFileCanvas::OnChar (wxKeyEvent& event)
180 if (event.GetKeyCode() == WXK_ESCAPE) {
184 m_pView->OnUpdate (NULL);
190 ImageFileCanvas::GetBestSize() const
192 const int iMinX = 50;
193 const int iMinY = 20;
194 wxSize bestSize (iMinX,iMinY);
197 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
198 bestSize.Set (rIF.nx(), rIF.ny());
201 if (bestSize.x > 800)
203 if (bestSize.y > 800)
206 if (bestSize.y < iMinY)
208 if (bestSize.x < iMinX)
217 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
219 BEGIN_EVENT_TABLE(ImageFileView, wxView)
220 EVT_MENU(IFMENU_FILE_EXPORT, ImageFileView::OnExport)
221 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
222 EVT_MENU(IFMENU_EDIT_COPY, ImageFileView::OnEditCopy)
223 EVT_MENU(IFMENU_EDIT_CUT, ImageFileView::OnEditCut)
224 EVT_MENU(IFMENU_EDIT_PASTE, ImageFileView::OnEditPaste)
225 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
226 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
227 EVT_MENU(IFMENU_VIEW_SCALE_FULL, ImageFileView::OnScaleFull)
228 EVT_MENU(IFMENU_COMPARE_IMAGES, ImageFileView::OnCompare)
229 EVT_MENU(IFMENU_COMPARE_ROW, ImageFileView::OnCompareRow)
230 EVT_MENU(IFMENU_COMPARE_COL, ImageFileView::OnCompareCol)
231 EVT_MENU(IFMENU_FILTER_INVERTVALUES, ImageFileView::OnInvertValues)
232 EVT_MENU(IFMENU_FILTER_SQUARE, ImageFileView::OnSquare)
233 EVT_MENU(IFMENU_FILTER_SQRT, ImageFileView::OnSquareRoot)
234 EVT_MENU(IFMENU_FILTER_LOG, ImageFileView::OnLog)
235 EVT_MENU(IFMENU_FILTER_EXP, ImageFileView::OnExp)
236 EVT_MENU(IFMENU_FILTER_FOURIER, ImageFileView::OnFourier)
237 EVT_MENU(IFMENU_FILTER_INVERSE_FOURIER, ImageFileView::OnInverseFourier)
238 EVT_MENU(IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, ImageFileView::OnShuffleFourierToNaturalOrder)
239 EVT_MENU(IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, ImageFileView::OnShuffleNaturalToFourierOrder)
240 EVT_MENU(IFMENU_IMAGE_ADD, ImageFileView::OnAdd)
241 EVT_MENU(IFMENU_IMAGE_SUBTRACT, ImageFileView::OnSubtract)
242 EVT_MENU(IFMENU_IMAGE_MULTIPLY, ImageFileView::OnMultiply)
243 EVT_MENU(IFMENU_IMAGE_DIVIDE, ImageFileView::OnDivide)
244 EVT_MENU(IFMENU_IMAGE_SCALESIZE, ImageFileView::OnScaleSize)
246 EVT_MENU(IFMENU_IMAGE_CONVERT3D, ImageFileView::OnConvert3d)
249 EVT_MENU(IFMENU_FILTER_FFT, ImageFileView::OnFFT)
250 EVT_MENU(IFMENU_FILTER_IFFT, ImageFileView::OnIFFT)
251 EVT_MENU(IFMENU_FILTER_FFT_ROWS, ImageFileView::OnFFTRows)
252 EVT_MENU(IFMENU_FILTER_IFFT_ROWS, ImageFileView::OnIFFTRows)
253 EVT_MENU(IFMENU_FILTER_FFT_COLS, ImageFileView::OnFFTCols)
254 EVT_MENU(IFMENU_FILTER_IFFT_COLS, ImageFileView::OnIFFTCols)
256 EVT_MENU(IFMENU_FILTER_MAGNITUDE, ImageFileView::OnMagnitude)
257 EVT_MENU(IFMENU_FILTER_PHASE, ImageFileView::OnPhase)
258 EVT_MENU(IFMENU_FILTER_REAL, ImageFileView::OnReal)
259 EVT_MENU(IFMENU_FILTER_IMAGINARY, ImageFileView::OnImaginary)
260 EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)
261 EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol)
263 EVT_MENU(IFMENU_PLOT_FFT_ROW, ImageFileView::OnPlotFFTRow)
264 EVT_MENU(IFMENU_PLOT_FFT_COL, ImageFileView::OnPlotFFTCol)
266 EVT_MENU(IFMENU_PLOT_HISTOGRAM, ImageFileView::OnPlotHistogram)
269 ImageFileView::ImageFileView()
270 : wxView(), m_pBitmap(0), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0),
271 m_pFilterMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false),
272 m_iDefaultExportFormatID(ImageFile::EXPORT_FORMAT_PNG)
275 ImageFileView::~ImageFileView()
277 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
278 GetDocumentManager()->ActivateView(this, FALSE);
283 ImageFileView::OnProperties (wxCommandEvent& event)
285 const ImageFile& rIF = GetDocument()->getImageFile();
286 if (rIF.nx() == 0 || rIF.ny() == 0)
287 *theApp->getLog() << _T("Properties: empty imagefile\n");
289 const std::string rFilename (m_pFrame->GetTitle().mb_str(wxConvUTF8));
290 std::ostringstream os;
291 double min, max, mean, mode, median, stddev;
292 rIF.statistics (rIF.getArray(), min, max, mean, mode, median, stddev);
293 os << "Filename: " << rFilename << "\n";
294 os << "Size: (" << rIF.nx() << "," << rIF.ny() << ")\n";
300 os << "Minimum: "<<min<<"\nMaximum: "<<max<<"\nMean: "<<mean<<"\nMedian: "<<median<<"\nMode: "<<mode<<"\nStandard Deviation: "<<stddev << "\n";
301 if (rIF.isComplex()) {
302 rIF.statistics (rIF.getImaginaryArray(), min, max, mean, mode, median, stddev);
303 os << "Imaginary: min: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
305 if (rIF.nLabels() > 0) {
306 rIF.printLabelsBrief (os);
308 *theApp->getLog() << _T(">>>>\n") << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("<<<<\n");
309 wxMessageDialog dialogMsg (getFrameForChild(), wxConvUTF8.cMB2WX(os.str().c_str()), _T("Imagefile Properties"), wxOK | wxICON_INFORMATION);
310 dialogMsg.ShowModal();
312 GetDocument()->Activate();
316 ImageFileView::OnScaleAuto (wxCommandEvent& event)
318 const ImageFile& rIF = GetDocument()->getImageFile();
319 double min, max, mean, mode, median, stddev;
320 rIF.statistics(min, max, mean, mode, median, stddev);
321 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
322 int iRetVal = dialogAutoScale.ShowModal();
323 if (iRetVal == wxID_OK) {
324 m_bMinSpecified = true;
325 m_bMaxSpecified = true;
327 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
330 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
331 OnUpdate(this, NULL);
332 GetDocument()->UpdateAllViews (this);
335 GetDocument()->Activate();
339 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
341 const ImageFile& rIF = GetDocument()->getImageFile();
343 if (! m_bMinSpecified && ! m_bMaxSpecified)
344 rIF.getMinMax (min, max);
351 DialogGetMinMax dialogMinMax (getFrameForChild(), _T("Set Image Minimum & Maximum"), min, max);
352 int retVal = dialogMinMax.ShowModal();
353 if (retVal == wxID_OK) {
354 m_bMinSpecified = true;
355 m_bMaxSpecified = true;
356 m_dMinPixel = dialogMinMax.getMinimum();
357 m_dMaxPixel = dialogMinMax.getMaximum();
358 OnUpdate(this, NULL);
359 GetDocument()->UpdateAllViews (this);
361 GetDocument()->Activate();
365 ImageFileView::OnScaleFull (wxCommandEvent& event)
367 if (m_bMinSpecified || m_bMaxSpecified) {
368 m_bMinSpecified = false;
369 m_bMaxSpecified = false;
370 OnUpdate(this, NULL);
371 GetDocument()->UpdateAllViews (this);
373 GetDocument()->Activate();
377 ImageFileView::OnCompare (wxCommandEvent& event)
379 std::vector<ImageFileDocument*> vecIF;
380 theApp->getCompatibleImages (GetDocument(), vecIF);
382 if (vecIF.size() == 0) {
383 wxMessageBox(_T("There are no compatible image files open for comparision"), _T("No comparison images"));
385 DialogGetComparisonImage dialogGetCompare(getFrameForChild(), _T("Get Comparison Image"), vecIF, true);
387 if (dialogGetCompare.ShowModal() == wxID_OK) {
388 const ImageFile& rIF = GetDocument()->getImageFile();
389 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
390 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
391 std::ostringstream os;
392 double min, max, mean, mode, median, stddev;
393 rIF.statistics (min, max, mean, mode, median, stddev);
394 os << m_pFrame->GetTitle().mb_str(wxConvUTF8) << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
395 rCompareIF.statistics (min, max, mean, mode, median, stddev);
396 os << dynamic_cast<wxFrame*>(pCompareDoc->GetFirstView()->GetFrame())->GetTitle().mb_str(wxConvUTF8) << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
398 rIF.comparativeStatistics (rCompareIF, d, r, e);
399 os << "Comparative Statistics: d=" << d << ", r=" << r << ", e=" << e << "\n";
400 *theApp->getLog() << _T(">>>>\n") << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("<<<<\n");
401 if (dialogGetCompare.getMakeDifferenceImage()) {
402 ImageFile* pDifferenceImage = new ImageFile;
404 pDifferenceImage->setArraySize (rIF.nx(), rIF.ny());
405 if (! rIF.subtractImages (rCompareIF, *pDifferenceImage)) {
406 *theApp->getLog() << _T("Unable to subtract images\n");
407 delete pDifferenceImage;
410 ImageFileDocument* pDifferenceDoc = theApp->newImageDoc();
411 if (! pDifferenceDoc) {
412 sys_error (ERR_SEVERE, "Unable to create image file");
415 pDifferenceDoc->setImageFile (pDifferenceImage);
417 wxString s = m_pFrame->GetTitle() + _T(": ");
418 pDifferenceImage->labelsCopy (rIF, s.mb_str(wxConvUTF8));
419 s = dynamic_cast<wxFrame*>(pCompareDoc->GetFirstView()->GetFrame())->GetTitle() + _T(": ");
420 pDifferenceImage->labelsCopy (rCompareIF, s.mb_str(wxConvUTF8));
421 std::ostringstream osLabel;
422 osLabel << "Compare image " << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str()
423 << " and " << dynamic_cast<wxFrame*>(pCompareDoc->GetFirstView()->GetFrame())->GetTitle().c_str() << ": "
425 pDifferenceImage->labelAdd (os.str().c_str());
426 if (theApp->getAskDeleteNewDocs())
427 pDifferenceDoc->Modify (true);
428 OnUpdate(this, NULL);
429 pDifferenceDoc->UpdateAllViews(this);
430 pDifferenceDoc->getView()->setInitialClientSize();
431 pDifferenceDoc->Activate();
433 wxMessageBox(wxConvUTF8.cMB2WX(os.str().c_str()), _T("Image Comparison"));
439 ImageFileView::OnInvertValues (wxCommandEvent& event)
441 ImageFile& rIF = GetDocument()->getImageFile();
442 rIF.invertPixelValues (rIF);
443 rIF.labelAdd ("Invert Pixel Values");
444 if (theApp->getAskDeleteNewDocs())
445 GetDocument()->Modify (true);
446 OnUpdate(this, NULL);
447 GetDocument()->UpdateAllViews (this);
448 GetDocument()->Activate();
452 ImageFileView::OnSquare (wxCommandEvent& event)
454 ImageFile& rIF = GetDocument()->getImageFile();
456 rIF.labelAdd ("Square Pixel Values");
457 if (theApp->getAskDeleteNewDocs())
458 GetDocument()->Modify (true);
459 OnUpdate(this, NULL);
460 GetDocument()->UpdateAllViews (this);
461 GetDocument()->Activate();
465 ImageFileView::OnSquareRoot (wxCommandEvent& event)
467 ImageFile& rIF = GetDocument()->getImageFile();
469 rIF.labelAdd ("Square-root Pixel Values");
470 if (theApp->getAskDeleteNewDocs())
471 GetDocument()->Modify (true);
472 OnUpdate(this, NULL);
473 GetDocument()->UpdateAllViews (this);
474 GetDocument()->Activate();
478 ImageFileView::OnLog (wxCommandEvent& event)
480 ImageFile& rIF = GetDocument()->getImageFile();
482 rIF.labelAdd ("Logrithm base-e Pixel Values");
483 if (theApp->getAskDeleteNewDocs())
484 GetDocument()->Modify (true);
485 OnUpdate(this, NULL);
486 GetDocument()->UpdateAllViews (this);
487 GetDocument()->Activate();
491 ImageFileView::OnExp (wxCommandEvent& event)
493 ImageFile& rIF = GetDocument()->getImageFile();
495 rIF.labelAdd ("Exponent base-e Pixel Values");
496 if (theApp->getAskDeleteNewDocs())
497 GetDocument()->Modify (true);
498 OnUpdate(this, NULL);
499 GetDocument()->UpdateAllViews (this);
500 GetDocument()->Activate();
504 ImageFileView::OnAdd (wxCommandEvent& event)
506 std::vector<ImageFileDocument*> vecIF;
507 theApp->getCompatibleImages (GetDocument(), vecIF);
509 if (vecIF.size() == 0) {
510 wxMessageBox (_T("There are no compatible image files open for comparision"), _T("No comparison images"));
512 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), _T("Get Image to Add"), vecIF, false);
514 if (dialogGetCompare.ShowModal() == wxID_OK) {
515 ImageFile& rIF = GetDocument()->getImageFile();
516 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
517 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
518 ImageFileDocument* pNewDoc = theApp->newImageDoc();
520 sys_error (ERR_SEVERE, "Unable to create image file");
523 ImageFile& newImage = pNewDoc->getImageFile();
524 newImage.setArraySize (rIF.nx(), rIF.ny());
525 rIF.addImages (rRHSIF, newImage);
526 std::ostringstream os;
527 os << "Add image " << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str() << " and "
528 << dynamic_cast<wxFrame*>(pRHSDoc->GetFirstView()->GetFrame())->GetTitle().c_str();
529 wxString s = dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle() + _T(": ");
530 newImage.labelsCopy (rIF, s.mb_str(wxConvUTF8));
531 s = dynamic_cast<wxFrame*>(pRHSDoc->GetFirstView()->GetFrame())->GetTitle() + _T(": ");
532 newImage.labelsCopy (rRHSIF, s.mb_str(wxConvUTF8));
533 newImage.labelAdd (os.str().c_str());
534 *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
535 if (theApp->getAskDeleteNewDocs())
536 pNewDoc->Modify (true);
537 OnUpdate(this, NULL);
538 pNewDoc->UpdateAllViews (this);
539 pNewDoc->getView()->setInitialClientSize();
546 ImageFileView::OnSubtract (wxCommandEvent& event)
548 std::vector<ImageFileDocument*> vecIF;
549 theApp->getCompatibleImages (GetDocument(), vecIF);
551 if (vecIF.size() == 0) {
552 wxMessageBox (_T("There are no compatible image files open for comparision"), _T("No comparison images"));
554 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), _T("Get Image to Subtract"), vecIF, false);
556 if (dialogGetCompare.ShowModal() == wxID_OK) {
557 ImageFile& rIF = GetDocument()->getImageFile();
558 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
559 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
560 ImageFileDocument* pNewDoc = theApp->newImageDoc();
562 sys_error (ERR_SEVERE, "Unable to create image file");
565 ImageFile& newImage = pNewDoc->getImageFile();
566 newImage.setArraySize (rIF.nx(), rIF.ny());
567 rIF.subtractImages (rRHSIF, newImage);
568 std::ostringstream os;
569 os << "Subtract image " << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str() << " and "
570 << dynamic_cast<wxFrame*>(pRHSDoc->GetFirstView()->GetFrame())->GetTitle().c_str();
571 wxString s = dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle() + _T(": ");
572 newImage.labelsCopy (rIF, s.mb_str(wxConvUTF8));
573 s = dynamic_cast<wxFrame*>(pRHSDoc->GetFirstView()->GetFrame())->GetTitle() + _T(": ");
574 newImage.labelsCopy (rRHSIF, s.mb_str(wxConvUTF8));
575 newImage.labelAdd (os.str().c_str());
576 *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
577 if (theApp->getAskDeleteNewDocs())
578 pNewDoc->Modify (true);
579 OnUpdate(this, NULL);
580 pNewDoc->UpdateAllViews (this);
581 pNewDoc->getView()->setInitialClientSize();
588 ImageFileView::OnMultiply (wxCommandEvent& event)
590 std::vector<ImageFileDocument*> vecIF;
591 theApp->getCompatibleImages (GetDocument(), vecIF);
593 if (vecIF.size() == 0) {
594 wxMessageBox (_T("There are no compatible image files open for comparision"), _T("No comparison images"));
596 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), _T("Get Image to Multiply"), vecIF, false);
598 if (dialogGetCompare.ShowModal() == wxID_OK) {
599 ImageFile& rIF = GetDocument()->getImageFile();
600 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
601 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
602 ImageFileDocument* pNewDoc = theApp->newImageDoc();
604 sys_error (ERR_SEVERE, "Unable to create image file");
607 ImageFile& newImage = pNewDoc->getImageFile();
608 newImage.setArraySize (rIF.nx(), rIF.ny());
609 rIF.multiplyImages (rRHSIF, newImage);
610 std::ostringstream os;
611 os << "Multiply image " << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str() << " and "
612 << dynamic_cast<wxFrame*>(pRHSDoc->GetFirstView()->GetFrame())->GetTitle().c_str();
613 wxString s = dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle() + _T(": ");
614 newImage.labelsCopy (rIF, s.mb_str(wxConvUTF8));
615 s = dynamic_cast<wxFrame*>(pRHSDoc->GetFirstView()->GetFrame())->GetTitle() + _T(": ");
616 newImage.labelsCopy (rRHSIF, s.mb_str(wxConvUTF8));
617 newImage.labelAdd (os.str().c_str());
618 *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
619 if (theApp->getAskDeleteNewDocs())
620 pNewDoc->Modify (true);
621 OnUpdate(this, NULL);
622 pNewDoc->UpdateAllViews (this);
623 pNewDoc->getView()->setInitialClientSize();
630 ImageFileView::OnDivide (wxCommandEvent& event)
632 std::vector<ImageFileDocument*> vecIF;
633 theApp->getCompatibleImages (GetDocument(), vecIF);
635 if (vecIF.size() == 0) {
636 wxMessageBox (_T("There are no compatible image files open for comparision"), _T("No comparison images"));
638 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), _T("Get Image to Divide"), vecIF, false);
640 if (dialogGetCompare.ShowModal() == wxID_OK) {
641 ImageFile& rIF = GetDocument()->getImageFile();
642 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
643 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
644 ImageFileDocument* pNewDoc = theApp->newImageDoc();
646 sys_error (ERR_SEVERE, "Unable to create image file");
649 ImageFile& newImage = pNewDoc->getImageFile();
650 newImage.setArraySize (rIF.nx(), rIF.ny());
651 rIF.divideImages (rRHSIF, newImage);
652 std::ostringstream os;
653 os << "Divide image " << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str() << " by "
654 << dynamic_cast<wxFrame*>(pRHSDoc->GetFirstView()->GetFrame())->GetTitle().c_str();
655 wxString s = dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle() + _T(": ");
656 newImage.labelsCopy (rIF, s.mb_str(wxConvUTF8));
657 s = dynamic_cast<wxFrame*>(pRHSDoc->GetFirstView()->GetFrame())->GetTitle() + _T(": ");
658 newImage.labelsCopy (rRHSIF, s.mb_str(wxConvUTF8));
659 newImage.labelAdd (os.str().c_str());
660 *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
661 if (theApp->getAskDeleteNewDocs())
662 pNewDoc->Modify (true);
663 OnUpdate(this, NULL);
664 pNewDoc->UpdateAllViews (this);
665 pNewDoc->getView()->setInitialClientSize();
674 ImageFileView::OnFFT (wxCommandEvent& event)
676 ImageFile& rIF = GetDocument()->getImageFile();
678 rIF.labelAdd ("FFT Image");
679 m_bMinSpecified = false;
680 m_bMaxSpecified = false;
681 if (theApp->getAskDeleteNewDocs())
682 GetDocument()->Modify (true);
683 OnUpdate(this, NULL);
684 GetDocument()->UpdateAllViews (this);
685 GetDocument()->Activate();
689 ImageFileView::OnIFFT (wxCommandEvent& event)
691 ImageFile& rIF = GetDocument()->getImageFile();
693 rIF.labelAdd ("IFFT Image");
694 m_bMinSpecified = false;
695 m_bMaxSpecified = false;
696 if (theApp->getAskDeleteNewDocs())
697 GetDocument()->Modify (true);
698 OnUpdate(this, NULL);
699 GetDocument()->UpdateAllViews (this);
700 GetDocument()->Activate();
704 ImageFileView::OnFFTRows (wxCommandEvent& event)
706 ImageFile& rIF = GetDocument()->getImageFile();
708 rIF.labelAdd ("FFT Rows");
709 m_bMinSpecified = false;
710 m_bMaxSpecified = false;
711 if (theApp->getAskDeleteNewDocs())
712 GetDocument()->Modify (true);
713 OnUpdate(this, NULL);
714 GetDocument()->UpdateAllViews (this);
715 GetDocument()->Activate();
719 ImageFileView::OnIFFTRows (wxCommandEvent& event)
721 ImageFile& rIF = GetDocument()->getImageFile();
723 rIF.labelAdd ("IFFT Rows");
724 m_bMinSpecified = false;
725 m_bMaxSpecified = false;
726 if (theApp->getAskDeleteNewDocs())
727 GetDocument()->Modify (true);
728 OnUpdate(this, NULL);
729 GetDocument()->UpdateAllViews (this);
730 GetDocument()->Activate();
734 ImageFileView::OnFFTCols (wxCommandEvent& event)
736 ImageFile& rIF = GetDocument()->getImageFile();
738 rIF.labelAdd ("FFT Columns");
739 m_bMinSpecified = false;
740 m_bMaxSpecified = false;
741 if (theApp->getAskDeleteNewDocs())
742 GetDocument()->Modify (true);
743 OnUpdate(this, NULL);
744 GetDocument()->UpdateAllViews (this);
745 GetDocument()->Activate();
749 ImageFileView::OnIFFTCols (wxCommandEvent& event)
751 ImageFile& rIF = GetDocument()->getImageFile();
753 rIF.labelAdd ("IFFT Columns");
754 m_bMinSpecified = false;
755 m_bMaxSpecified = false;
756 if (theApp->getAskDeleteNewDocs())
757 GetDocument()->Modify (true);
758 OnUpdate(this, NULL);
759 GetDocument()->UpdateAllViews (this);
760 GetDocument()->Activate();
765 ImageFileView::OnFourier (wxCommandEvent& event)
767 ImageFile& rIF = GetDocument()->getImageFile();
768 wxProgressDialog dlgProgress (_T("Fourier"), _T("Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
770 rIF.labelAdd ("Fourier Image");
771 m_bMinSpecified = false;
772 m_bMaxSpecified = false;
773 if (theApp->getAskDeleteNewDocs())
774 GetDocument()->Modify (true);
775 OnUpdate(this, NULL);
776 GetDocument()->UpdateAllViews (this);
777 GetDocument()->Activate();
781 ImageFileView::OnInverseFourier (wxCommandEvent& event)
783 ImageFile& rIF = GetDocument()->getImageFile();
784 wxProgressDialog dlgProgress (_T("Inverse Fourier"), _T("Inverse Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
785 rIF.inverseFourier (rIF);
786 rIF.labelAdd ("Inverse Fourier Image");
787 m_bMinSpecified = false;
788 m_bMaxSpecified = false;
789 if (theApp->getAskDeleteNewDocs())
790 GetDocument()->Modify (true);
791 OnUpdate(this, NULL);
792 GetDocument()->UpdateAllViews (this);
793 GetDocument()->Activate();
797 ImageFileView::OnShuffleNaturalToFourierOrder (wxCommandEvent& event)
799 ImageFile& rIF = GetDocument()->getImageFile();
800 Fourier::shuffleNaturalToFourierOrder (rIF);
801 rIF.labelAdd ("Shuffle Natural To Fourier Order");
802 m_bMinSpecified = false;
803 m_bMaxSpecified = false;
804 if (theApp->getAskDeleteNewDocs())
805 GetDocument()->Modify (true);
806 OnUpdate(this, NULL);
807 GetDocument()->UpdateAllViews (this);
808 GetDocument()->Activate();
812 ImageFileView::OnShuffleFourierToNaturalOrder (wxCommandEvent& event)
814 ImageFile& rIF = GetDocument()->getImageFile();
815 Fourier::shuffleFourierToNaturalOrder (rIF);
816 rIF.labelAdd ("Shuffle Fourier To Natural Order");
817 m_bMinSpecified = false;
818 m_bMaxSpecified = false;
819 if (theApp->getAskDeleteNewDocs())
820 GetDocument()->Modify (true);
821 OnUpdate(this, NULL);
822 GetDocument()->UpdateAllViews (this);
823 GetDocument()->Activate();
827 ImageFileView::OnMagnitude (wxCommandEvent& event)
829 ImageFile& rIF = GetDocument()->getImageFile();
831 rIF.labelAdd ("Magnitude");
832 m_bMinSpecified = false;
833 m_bMaxSpecified = false;
834 if (theApp->getAskDeleteNewDocs())
835 GetDocument()->Modify (true);
836 OnUpdate(this, NULL);
837 GetDocument()->UpdateAllViews (this);
838 GetDocument()->Activate();
842 ImageFileView::OnPhase (wxCommandEvent& event)
844 ImageFile& rIF = GetDocument()->getImageFile();
845 if (rIF.isComplex()) {
847 rIF.labelAdd ("Phase of complex-image");
848 m_bMinSpecified = false;
849 m_bMaxSpecified = false;
850 if (theApp->getAskDeleteNewDocs())
851 GetDocument()->Modify (true);
852 OnUpdate(this, NULL);
853 GetDocument()->UpdateAllViews (this);
855 GetDocument()->Activate();
859 ImageFileView::OnReal (wxCommandEvent& event)
861 ImageFile& rIF = GetDocument()->getImageFile();
862 if (rIF.isComplex()) {
864 rIF.labelAdd ("Real component of complex-image");
865 m_bMinSpecified = false;
866 m_bMaxSpecified = false;
867 if (theApp->getAskDeleteNewDocs())
868 GetDocument()->Modify (true);
869 OnUpdate(this, NULL);
870 GetDocument()->UpdateAllViews (this);
872 GetDocument()->Activate();
876 ImageFileView::OnImaginary (wxCommandEvent& event)
878 ImageFile& rIF = GetDocument()->getImageFile();
879 if (rIF.isComplex()) {
881 rIF.labelAdd ("Imaginary component of complex-image");
882 m_bMinSpecified = false;
883 m_bMaxSpecified = false;
884 if (theApp->getAskDeleteNewDocs())
885 GetDocument()->Modify (true);
886 OnUpdate(this, NULL);
887 GetDocument()->UpdateAllViews (this);
889 GetDocument()->Activate();
894 ImageFileView::CreateCanvas (wxFrame* parent)
896 ImageFileCanvas* pCanvas = new ImageFileCanvas (this, parent, wxPoint(-1,-1),
898 pCanvas->SetBackgroundColour(*wxWHITE);
899 pCanvas->ClearBackground();
909 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
912 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, _T("ImageFile Frame"), wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
914 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, _T("ImageFile Frame"), wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
916 theApp->setIconForFrame (subframe);
918 m_pFileMenu = new wxMenu;
919 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, _T("Cr&eate Phantom...\tCtrl-P"));
920 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, _T("Create &Filter...\tCtrl-F"));
921 m_pFileMenu->Append(wxID_OPEN, _T("&Open...\tCtrl-O"));
922 m_pFileMenu->Append(wxID_SAVE, _T("&Save\tCtrl-S"));
923 m_pFileMenu->Append(wxID_SAVEAS, _T("Save &As..."));
924 m_pFileMenu->Append(wxID_CLOSE, _T("&Close\tCtrl-W"));
925 m_pFileMenu->Append(wxID_REVERT, _T("Re&vert"));
927 m_pFileMenu->AppendSeparator();
928 m_pFileMenu->Append(IFMENU_FILE_PROPERTIES, _T("P&roperties\tCtrl-I"));
929 m_pFileMenu->Append(IFMENU_FILE_EXPORT, _T("Expor&t..."));
931 m_pFileMenu->AppendSeparator();
932 m_pFileMenu->Append(wxID_PRINT, _T("&Print..."));
933 m_pFileMenu->Append(wxID_PRINT_SETUP, _T("Print &Setup..."));
934 m_pFileMenu->Append(wxID_PREVIEW, _T("Print Preview"));
935 m_pFileMenu->AppendSeparator();
936 m_pFileMenu->Append(MAINMENU_IMPORT, _T("&Import...\tCtrl-M"));
937 m_pFileMenu->AppendSeparator();
938 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, _T("Prefere&nces..."));
939 m_pFileMenu->Append(MAINMENU_FILE_EXIT, _T("E&xit"));
940 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
941 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
943 wxMenu* edit_menu = new wxMenu;
944 edit_menu->Append(IFMENU_EDIT_COPY, _T("Copy\tCtrl-C"));
945 edit_menu->Append(IFMENU_EDIT_CUT, _T("Cut\tCtrl-X"));
946 edit_menu->Append(IFMENU_EDIT_PASTE, _T("Paste\tCtrl-V"));
948 wxMenu *view_menu = new wxMenu;
949 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, _T("Display Scale S&et...\tCtrl-E"));
950 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, _T("Display Scale &Auto...\tCtrl-A"));
951 view_menu->Append(IFMENU_VIEW_SCALE_FULL, _T("Display F&ull Scale\tCtrl-U"));
953 m_pFilterMenu = new wxMenu;
954 m_pFilterMenu->Append (IFMENU_FILTER_INVERTVALUES, _T("In&vert Values"));
955 m_pFilterMenu->Append (IFMENU_FILTER_SQUARE, _T("&Square"));
956 m_pFilterMenu->Append (IFMENU_FILTER_SQRT, _T("Square &Root"));
957 m_pFilterMenu->Append (IFMENU_FILTER_LOG, _T("&Log"));
958 m_pFilterMenu->Append (IFMENU_FILTER_EXP, _T("E&xp"));
959 m_pFilterMenu->AppendSeparator();
961 m_pFilterMenu->Append (IFMENU_FILTER_FFT, _T("2-D &FFT\tCtrl-2"));
962 m_pFilterMenu->Append (IFMENU_FILTER_IFFT, _T("2-D &IFFT\tAlt-2"));
963 m_pFilterMenu->Append (IFMENU_FILTER_FFT_ROWS, _T("FFT Rows"));
964 m_pFilterMenu->Append (IFMENU_FILTER_IFFT_ROWS, _T("IFFT Rows"));
965 m_pFilterMenu->Append (IFMENU_FILTER_FFT_COLS, _T("FFT Columns"));
966 m_pFilterMenu->Append (IFMENU_FILTER_IFFT_COLS, _T("IFFT Columns"));
967 m_pFilterMenu->Append (IFMENU_FILTER_FOURIER, _T("2-D F&ourier"));
968 m_pFilterMenu->Append (IFMENU_FILTER_INVERSE_FOURIER, _T("2-D Inverse Fo&urier"));
970 m_pFilterMenu->Append (IFMENU_FILTER_FOURIER, _T("&Fourier"));
971 m_pFilterMenu->Append (IFMENU_FILTER_INVERSE_FOURIER, _T("&Inverse Fourier"));
973 m_pFilterMenu->Append (IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, _T("Shuffl&e Fourier to Natural Order"));
974 m_pFilterMenu->Append (IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, _T("Shuffle &Natural to Fourier Order"));
975 m_pFilterMenu->AppendSeparator();
976 m_pFilterMenu->Append (IFMENU_FILTER_MAGNITUDE, _T("&Magnitude"));
977 m_pFilterMenu->Append (IFMENU_FILTER_PHASE, _T("&Phase"));
978 m_pFilterMenu->Append (IFMENU_FILTER_REAL, _T("Re&al"));
979 m_pFilterMenu->Append (IFMENU_FILTER_IMAGINARY, _T("Ima&ginary"));
981 wxMenu* image_menu = new wxMenu;
982 image_menu->Append (IFMENU_IMAGE_ADD, _T("&Add..."));
983 image_menu->Append (IFMENU_IMAGE_SUBTRACT, _T("&Subtract..."));
984 image_menu->Append (IFMENU_IMAGE_MULTIPLY, _T("&Multiply..."));
985 image_menu->Append (IFMENU_IMAGE_DIVIDE, _T("&Divide..."));
986 image_menu->AppendSeparator();
987 image_menu->Append (IFMENU_IMAGE_SCALESIZE, _T("S&cale Size..."));
989 image_menu->Append (IFMENU_IMAGE_CONVERT3D, _T("Convert &3-D\tCtrl-3"));
992 m_pMenuAnalyze = new wxMenu;
993 m_pMenuAnalyze->Append (IFMENU_PLOT_ROW, _T("Plot &Row"));
994 m_pMenuAnalyze->Append (IFMENU_PLOT_COL, _T("Plot &Column"));
995 m_pMenuAnalyze->Append (IFMENU_PLOT_HISTOGRAM, _T("Plot &Histogram"));
996 m_pMenuAnalyze->AppendSeparator();
997 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_ROW, _T("P&lot FFT Row"));
998 m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_COL, _T("Plo&t FFT Column"));
999 m_pMenuAnalyze->AppendSeparator();
1000 m_pMenuAnalyze->Append (IFMENU_COMPARE_IMAGES, _T("Compare &Images..."));
1001 m_pMenuAnalyze->Append (IFMENU_COMPARE_ROW, _T("Compare Ro&w"));
1002 m_pMenuAnalyze->Append (IFMENU_COMPARE_COL, _T("Compare Colu&mn"));
1003 m_pMenuAnalyze->Enable (IFMENU_PLOT_ROW, false);
1004 m_pMenuAnalyze->Enable (IFMENU_PLOT_COL, false);
1005 m_pMenuAnalyze->Enable (IFMENU_COMPARE_ROW, false);
1006 m_pMenuAnalyze->Enable (IFMENU_COMPARE_COL, false);
1007 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_ROW, false);
1008 m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_COL, false);
1010 wxMenu *help_menu = new wxMenu;
1011 help_menu->Append(MAINMENU_HELP_CONTENTS, _T("&Contents\tF1"));
1012 help_menu->Append (MAINMENU_HELP_TIPS, _T("&Tips"));
1013 help_menu->Append (IDH_QUICKSTART, _T("&Quick Start"));
1014 help_menu->Append(MAINMENU_HELP_ABOUT, _T("&About"));
1016 wxMenuBar *menu_bar = new wxMenuBar;
1018 menu_bar->Append(m_pFileMenu, _T("&File"));
1019 menu_bar->Append(edit_menu, _T("&Edit"));
1020 menu_bar->Append(view_menu, _T("&View"));
1021 menu_bar->Append(image_menu, _T("&Image"));
1022 menu_bar->Append(m_pFilterMenu, _T("Fi<er"));
1023 menu_bar->Append(m_pMenuAnalyze, _T("&Analyze"));
1024 menu_bar->Append(help_menu, _T("&Help"));
1026 subframe->SetMenuBar(menu_bar);
1028 subframe->Centre(wxBOTH);
1030 wxAcceleratorEntry accelEntries[10];
1031 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('A'), IFMENU_VIEW_SCALE_AUTO);
1032 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('U'), IFMENU_VIEW_SCALE_FULL);
1033 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('E'), IFMENU_VIEW_SCALE_MINMAX);
1034 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), IFMENU_FILE_PROPERTIES);
1035 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('C'), IFMENU_EDIT_COPY);
1036 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('X'), IFMENU_EDIT_CUT);
1037 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('V'), IFMENU_EDIT_PASTE);
1040 accelEntries[iEntry++].Set (wxACCEL_CTRL, static_cast<int>('2'), IFMENU_FILTER_FFT);
1041 accelEntries[iEntry++].Set (wxACCEL_ALT, static_cast<int>('2'), IFMENU_FILTER_IFFT);
1044 accelEntries[iEntry++].Set (wxACCEL_CTRL, static_cast<int>('3'), IFMENU_IMAGE_CONVERT3D);
1047 wxAcceleratorTable accelTable (iEntry, accelEntries);
1048 subframe->SetAcceleratorTable (accelTable);
1055 ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
1057 m_bMinSpecified = false;
1058 m_bMaxSpecified = false;
1059 m_dAutoScaleFactor = 1.;
1061 m_pFrame = CreateChildFrame(doc, this);
1062 SetFrame (m_pFrame);
1063 m_pCanvas = CreateCanvas (m_pFrame);
1064 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
1065 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
1066 m_pFrame->SetTitle(doc->GetFilename());
1068 m_pFrame->Show(true);
1075 ImageFileView::setInitialClientSize ()
1077 if (m_pFrame && m_pCanvas) {
1078 wxSize bestSize = m_pCanvas->GetBestSize();
1080 m_pFrame->SetClientSize (bestSize);
1081 m_pFrame->Show (true);
1082 m_pFrame->SetFocus();
1087 ImageFileView::OnDraw (wxDC* dc)
1089 if (m_pBitmap && m_pBitmap->Ok()) {
1091 *theApp->getLog() << _T("Drawing bitmap\n");
1093 dc->DrawBitmap(*m_pBitmap, 0, 0, false);
1096 int xCursor, yCursor;
1097 if (m_pCanvas->GetCurrentCursor (xCursor, yCursor))
1098 m_pCanvas->DrawRubberBandCursor (*dc, xCursor, yCursor);
1103 ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
1105 const ImageFile& rIF = GetDocument()->getImageFile();
1106 if (m_pFilterMenu && rIF.isComplex()) {
1107 m_pFilterMenu->Enable(IFMENU_FILTER_REAL, true);
1108 m_pFilterMenu->Enable(IFMENU_FILTER_IMAGINARY, true);
1109 m_pFilterMenu->Enable(IFMENU_FILTER_PHASE, true);
1111 m_pFilterMenu->Enable(IFMENU_FILTER_REAL, false);
1112 m_pFilterMenu->Enable(IFMENU_FILTER_IMAGINARY, false);
1113 m_pFilterMenu->Enable(IFMENU_FILTER_PHASE, false);
1115 ImageFileArrayConst v = rIF.getArray();
1118 if (v != NULL && nx != 0 && ny != 0) {
1119 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1121 rIF.getMinMax (min, max);
1122 if (! m_bMinSpecified)
1124 if (! m_bMaxSpecified)
1127 double scaleWidth = m_dMaxPixel - m_dMinPixel;
1129 unsigned char* imageData = new unsigned char [nx * ny * 3];
1131 sys_error (ERR_SEVERE, "Unable to allocate memory for Image display");
1134 for (int ix = 0; ix < nx; ix++) {
1135 for (int iy = 0; iy < ny; iy++) {
1136 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
1137 int intensity = static_cast<int>(scaleValue + 0.5);
1138 intensity = clamp (intensity, 0, 255);
1139 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
1140 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
1143 wxImage image (nx, ny, imageData, true);
1149 *theApp->getLog() << _T("Making new bitmap\n");
1151 m_pBitmap = new wxBitmap (image);
1153 m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20);
1154 m_pCanvas->SetBackgroundColour(*wxWHITE);
1158 m_pCanvas->Refresh();
1162 ImageFileView::OnClose (bool deleteWindow)
1164 if (! GetDocument() || ! GetDocument()->Close())
1169 m_pCanvas->setView(NULL);
1172 wxString s(theApp->GetAppName());
1174 m_pFrame->SetTitle(s);
1181 if (GetDocument() && GetDocument()->getBadFileOpen())
1182 ::wxYield(); // wxWindows bug workaround
1189 ImageFileView::OnEditCopy (wxCommandEvent& event)
1191 wxBitmapDataObject *pBitmapObject = new wxBitmapDataObject;
1194 pBitmapObject->SetBitmap (*m_pBitmap);
1196 if (wxTheClipboard->Open()) {
1197 wxTheClipboard->SetData (pBitmapObject);
1198 wxTheClipboard->Close();
1203 ImageFileView::OnEditCut (wxCommandEvent& event)
1206 ImageFile& rIF = GetDocument()->getImageFile();
1209 ImageFile* pIF = new ImageFile (nx, ny);
1210 pIF->arrayDataClear();
1211 GetDocument()->setImageFile (pIF); // deletes old IF
1212 OnUpdate(this, NULL);
1213 GetDocument()->UpdateAllViews();
1214 if (theApp->getAskDeleteNewDocs())
1215 GetDocument()->Modify (true);
1219 ImageFileView::OnEditPaste (wxCommandEvent& event)
1221 ImageFile& rIF = GetDocument()->getImageFile();
1223 if (wxTheClipboard->Open()) {
1225 if (wxTheClipboard->IsSupported (wxDF_BITMAP)) {
1226 wxBitmapDataObject bitmapObject;
1227 wxTheClipboard->GetData (bitmapObject);
1228 bitmap = bitmapObject.GetBitmap ();
1230 wxTheClipboard->Close();
1234 bool bMonochrome = false;
1236 if (bitmap.Ok() == true && bitmap.GetWidth() == nx && bitmap.GetHeight() == ny) {
1237 wxImage image (bitmap.ConvertToImage());
1238 double dScale3 = 3 * 255;
1239 unsigned char* pixels = image.GetData();
1240 ImageFileArray v = rIF.getArray();
1241 for (unsigned int ix = 0; ix < rIF.nx(); ix++) {
1242 for (unsigned int iy = 0; iy < rIF.ny(); iy++) {
1243 unsigned int iBase = 3 * (iy * nx + ix);
1244 if (ix == 0 && iy == 0 && (pixels[iBase] == pixels[iBase+1] && pixels[iBase+1] == pixels[iBase+2]))
1247 v[ix][ny - 1 - iy] = (pixels[iBase]+pixels[iBase+1]+pixels[iBase+2]) / dScale3;
1249 double dR = pixels[iBase] / 255.;
1250 double dG = pixels[iBase+1] / 255.;
1251 double dB = pixels[iBase+2] / 255.;
1252 v[ix][ny - 1 - iy] = ImageFile::colorToGrayscale (dR, dG, dB);
1256 OnUpdate(this, NULL);
1257 GetDocument()->UpdateAllViews();
1258 if (theApp->getAskDeleteNewDocs())
1259 GetDocument()->Modify(true);
1265 ImageFileView::OnExport (wxCommandEvent& event)
1267 ImageFile& rIF = GetDocument()->getImageFile();
1268 ImageFileArrayConst v = rIF.getArray();
1271 if (v != NULL && nx != 0 && ny != 0) {
1272 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1274 rIF.getMinMax (min, max);
1275 if (! m_bMinSpecified)
1277 if (! m_bMaxSpecified)
1281 DialogExportParameters dialogExport (getFrameForChild(), m_iDefaultExportFormatID);
1282 if (dialogExport.ShowModal() == wxID_OK) {
1283 wxString strFormatName (dialogExport.getFormatName (), wxConvUTF8);
1284 m_iDefaultExportFormatID = ImageFile::convertExportFormatNameToID (strFormatName.mb_str(wxConvUTF8));
1287 wxString strWildcard;
1288 if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PGM || m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PGMASCII) {
1289 strExt = _T(".pgm");
1290 strWildcard = _T("PGM Files (*.pgm)|*.pgm");
1293 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PNG || m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_PNG16) {
1294 strExt = _T(".png");
1295 strWildcard = _T("PNG Files (*.png)|*.png");
1298 #ifdef HAVE_CTN_DICOM
1299 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_DICOM) {
1301 strWildcard = _T("DICOM Files (*.*)|*.*");
1304 else if (m_iDefaultExportFormatID == ImageFile::EXPORT_FORMAT_TEXT) {
1305 strExt = _T(".txt");
1306 strWildcard = _T("Text (*.txt)|*.txt");
1310 strWildcard = _T("Miscellaneous (*.*)|*.*");
1313 #if WXWIN_COMPATIBILITY_2_4
1314 const wxString& strFilename = wxFileSelector (_T("Export Filename"), _T(""),
1315 _T(""), strExt, strWildcard, wxOVERWRITE_PROMPT | wxHIDE_READONLY | wxSAVE);
1317 const wxString& strFilename = wxFileSelector (_T("Export Filename"), _T(""),
1318 _T(""), strExt, strWildcard, wxOVERWRITE_PROMPT | wxSAVE);
1321 rIF.exportImage (strFormatName.mb_str(wxConvUTF8), strFilename.mb_str(wxConvUTF8), 1, 1, m_dMinPixel, m_dMaxPixel);
1322 *theApp->getLog() << _T("Exported file ") << strFilename << _T("\n");
1329 ImageFileView::OnScaleSize (wxCommandEvent& event)
1331 ImageFile& rIF = GetDocument()->getImageFile();
1332 unsigned int iOldNX = rIF.nx();
1333 unsigned int iOldNY = rIF.ny();
1335 DialogGetXYSize dialogGetXYSize (getFrameForChild(), _T("Set New X & Y Dimensions"), iOldNX, iOldNY);
1336 if (dialogGetXYSize.ShowModal() == wxID_OK) {
1337 unsigned int iNewNX = dialogGetXYSize.getXSize();
1338 unsigned int iNewNY = dialogGetXYSize.getYSize();
1339 std::ostringstream os;
1340 os << "Scale Size from (" << iOldNX << "," << iOldNY << ") to (" << iNewNX << "," << iNewNY << ")";
1341 ImageFileDocument* pScaledDoc = theApp->newImageDoc();
1343 sys_error (ERR_SEVERE, "Unable to create image file");
1346 ImageFile& rScaledIF = pScaledDoc->getImageFile();
1347 rScaledIF.setArraySize (iNewNX, iNewNY);
1348 rScaledIF.labelsCopy (rIF);
1349 rScaledIF.labelAdd (os.str().c_str());
1350 rIF.scaleImage (rScaledIF);
1351 *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
1352 if (theApp->getAskDeleteNewDocs())
1353 pScaledDoc->Modify (true);
1354 OnUpdate(this, NULL);
1355 pScaledDoc->UpdateAllViews (this);
1356 pScaledDoc->getView()->setInitialClientSize();
1357 pScaledDoc->Activate();
1363 ImageFileView::OnConvert3d (wxCommandEvent& event)
1365 ImageFile& rIF = GetDocument()->getImageFile();
1366 Graph3dFileDocument* pGraph3d = theApp->newGraph3dDoc();
1367 pGraph3d->getView()->getFrame()->Show (false);
1368 pGraph3d->setBadFileOpen();
1369 pGraph3d->createFromImageFile (rIF);
1370 pGraph3d->UpdateAllViews();
1371 pGraph3d->getView()->getFrame()->Show (true);
1372 pGraph3d->getView()->Activate(true);
1374 pGraph3d->getView()->getCanvas()->SetFocus();
1379 ImageFileView::OnPlotRow (wxCommandEvent& event)
1381 int xCursor, yCursor;
1382 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1383 wxMessageBox (_T("No row selected. Please use left mouse button on image to select column"),_T("Error"));
1387 const ImageFile& rIF = GetDocument()->getImageFile();
1388 ImageFileArrayConst v = rIF.getArray();
1389 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1393 if (v != NULL && yCursor < ny) {
1394 double* pX = new double [nx];
1395 double* pYReal = new double [nx];
1396 double *pYImag = NULL;
1397 double *pYMag = NULL;
1398 if (rIF.isComplex()) {
1399 pYImag = new double [nx];
1400 pYMag = new double [nx];
1402 for (int i = 0; i < nx; i++) {
1404 pYReal[i] = v[i][yCursor];
1405 if (rIF.isComplex()) {
1406 pYImag[i] = vImag[i][yCursor];
1407 pYMag[i] = ::sqrt (v[i][yCursor] * v[i][yCursor] + vImag[i][yCursor] * vImag[i][yCursor]);
1410 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1412 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1414 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1415 std::ostringstream os;
1416 os << "Row " << yCursor;
1417 std::string title("title ");
1419 rPlotFile.addEzsetCommand (title.c_str());
1420 rPlotFile.addEzsetCommand ("xlabel Column");
1421 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1422 rPlotFile.addEzsetCommand ("lxfrac 0");
1423 rPlotFile.addEzsetCommand ("box");
1424 rPlotFile.addEzsetCommand ("grid");
1425 rPlotFile.addEzsetCommand ("curve 1");
1426 rPlotFile.addEzsetCommand ("color 1");
1427 if (rIF.isComplex()) {
1428 rPlotFile.addEzsetCommand ("dash 1");
1429 rPlotFile.addEzsetCommand ("curve 2");
1430 rPlotFile.addEzsetCommand ("color 4");
1431 rPlotFile.addEzsetCommand ("dash 3");
1432 rPlotFile.addEzsetCommand ("curve 3");
1433 rPlotFile.addEzsetCommand ("color 0");
1434 rPlotFile.addEzsetCommand ("solid");
1435 rPlotFile.setCurveSize (4, nx);
1437 rPlotFile.setCurveSize (2, nx);
1438 rPlotFile.addColumn (0, pX);
1439 rPlotFile.addColumn (1, pYReal);
1440 if (rIF.isComplex()) {
1441 rPlotFile.addColumn (2, pYImag);
1442 rPlotFile.addColumn (3, pYMag);
1444 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1445 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1446 os << ": plot of " << wxConvUTF8.cWX2MB(dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str());
1447 *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
1448 rPlotFile.addDescription (os.str().c_str());
1452 if (rIF.isComplex()) {
1456 if (theApp->getAskDeleteNewDocs())
1457 pPlotDoc->Modify (true);
1458 pPlotDoc->getView()->getFrame()->Show(true);
1459 pPlotDoc->UpdateAllViews ();
1460 pPlotDoc->Activate();
1465 ImageFileView::OnPlotCol (wxCommandEvent& event)
1467 int xCursor, yCursor;
1468 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1469 wxMessageBox (_T("No column selected. Please use left mouse button on image to select column"),_T("Error"));
1473 const ImageFile& rIF = GetDocument()->getImageFile();
1474 ImageFileArrayConst v = rIF.getArray();
1475 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1479 if (v != NULL && xCursor < nx) {
1480 double* const pX = new double [ny];
1481 double* const pYReal = new double [ny];
1482 double* pYImag = NULL;
1483 double* pYMag = NULL;
1484 if (rIF.isComplex()) {
1485 pYImag = new double [ny];
1486 pYMag = new double [ny];
1488 for (int i = 0; i < ny; i++) {
1490 pYReal[i] = v[xCursor][i];
1491 if (rIF.isComplex()) {
1492 pYImag[i] = vImag[xCursor][i];
1493 pYMag[i] = ::sqrt (v[xCursor][i] * v[xCursor][i] + vImag[xCursor][i] * vImag[xCursor][i]);
1496 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1498 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1500 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1501 std::ostringstream os;
1502 os << "Column " << xCursor;
1503 std::string title("title ");
1505 rPlotFile.addEzsetCommand (title.c_str());
1506 rPlotFile.addEzsetCommand ("xlabel Row");
1507 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1508 rPlotFile.addEzsetCommand ("lxfrac 0");
1509 rPlotFile.addEzsetCommand ("box");
1510 rPlotFile.addEzsetCommand ("grid");
1511 rPlotFile.addEzsetCommand ("curve 1");
1512 rPlotFile.addEzsetCommand ("color 1");
1513 if (rIF.isComplex()) {
1514 rPlotFile.addEzsetCommand ("dash 1");
1515 rPlotFile.addEzsetCommand ("curve 2");
1516 rPlotFile.addEzsetCommand ("color 4");
1517 rPlotFile.addEzsetCommand ("dash 3");
1518 rPlotFile.addEzsetCommand ("curve 3");
1519 rPlotFile.addEzsetCommand ("color 0");
1520 rPlotFile.addEzsetCommand ("solid");
1521 rPlotFile.setCurveSize (4, ny);
1523 rPlotFile.setCurveSize (2, ny);
1524 rPlotFile.addColumn (0, pX);
1525 rPlotFile.addColumn (1, pYReal);
1526 if (rIF.isComplex()) {
1527 rPlotFile.addColumn (2, pYImag);
1528 rPlotFile.addColumn (3, pYMag);
1530 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1531 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1532 os << " : plot of " << wxConvUTF8.cWX2MB(dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str());
1533 *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
1534 rPlotFile.addDescription (os.str().c_str());
1538 if (rIF.isComplex()) {
1542 if (theApp->getAskDeleteNewDocs())
1543 pPlotDoc->Modify (true);
1544 pPlotDoc->getView()->getFrame()->Show(true);
1545 pPlotDoc->UpdateAllViews ();
1546 pPlotDoc->Activate();
1552 ImageFileView::OnPlotFFTRow (wxCommandEvent& event)
1554 int xCursor, yCursor;
1555 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1556 wxMessageBox (_T("No row selected. Please use left mouse button on image to select column"),_T("Error"));
1560 const ImageFile& rIF = GetDocument()->getImageFile();
1561 ImageFileArrayConst v = rIF.getArray();
1562 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1566 if (v != NULL && yCursor < ny) {
1567 fftw_complex* pcIn = static_cast<fftw_complex*>(fftw_malloc (sizeof(fftw_complex) * nx));
1570 for (i = 0; i < nx; i++) {
1571 pcIn[i][0] = v[i][yCursor];
1572 if (rIF.isComplex())
1573 pcIn[i][1] = vImag[i][yCursor];
1578 fftw_plan plan = fftw_plan_dft_1d (nx, pcIn, pcIn, FFTW_FORWARD, FFTW_ESTIMATE);
1579 fftw_execute (plan);
1580 fftw_destroy_plan (plan);
1582 double* pX = new double [nx];
1583 double* pYReal = new double [nx];
1584 double* pYImag = new double [nx];
1585 double* pYMag = new double [nx];
1586 for (i = 0; i < nx; i++) {
1588 pYReal[i] = pcIn[i][0] / nx;
1589 pYImag[i] = pcIn[i][1] / nx;
1590 pYMag[i] = ::sqrt (pcIn[i][0] * pcIn[i][0] + pcIn[i][1] * pcIn[i][1]);
1592 Fourier::shuffleFourierToNaturalOrder (pYReal, nx);
1593 Fourier::shuffleFourierToNaturalOrder (pYImag, nx);
1594 Fourier::shuffleFourierToNaturalOrder (pYMag, nx);
1596 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1598 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1600 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1601 std::ostringstream os;
1602 os << "Row " << yCursor;
1603 std::string title("title ");
1605 rPlotFile.addEzsetCommand (title.c_str());
1606 rPlotFile.addEzsetCommand ("xlabel Column");
1607 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1608 rPlotFile.addEzsetCommand ("lxfrac 0");
1609 rPlotFile.addEzsetCommand ("curve 1");
1610 rPlotFile.addEzsetCommand ("color 1");
1611 rPlotFile.addEzsetCommand ("dash 1");
1612 rPlotFile.addEzsetCommand ("curve 2");
1613 rPlotFile.addEzsetCommand ("color 4");
1614 rPlotFile.addEzsetCommand ("dash 3");
1615 rPlotFile.addEzsetCommand ("curve 3");
1616 rPlotFile.addEzsetCommand ("color 0");
1617 rPlotFile.addEzsetCommand ("solid");
1618 rPlotFile.addEzsetCommand ("box");
1619 rPlotFile.addEzsetCommand ("grid");
1620 rPlotFile.setCurveSize (4, nx);
1621 rPlotFile.addColumn (0, pX);
1622 rPlotFile.addColumn (1, pYReal);
1623 rPlotFile.addColumn (2, pYImag);
1624 rPlotFile.addColumn (3, pYMag);
1625 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1626 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1627 os << ": FFT plot of " << wxConvUTF8.cWX2MB(dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str());
1628 *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
1629 rPlotFile.addDescription (os.str().c_str());
1637 if (theApp->getAskDeleteNewDocs())
1638 pPlotDoc->Modify (true);
1639 pPlotDoc->getView()->getFrame()->Show(true);
1640 pPlotDoc->UpdateAllViews ();
1641 pPlotDoc->Activate();
1646 ImageFileView::OnPlotFFTCol (wxCommandEvent& event)
1648 int xCursor, yCursor;
1649 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1650 wxMessageBox (_T("No column selected. Please use left mouse button on image to select column"),_T("Error"));
1654 const ImageFile& rIF = GetDocument()->getImageFile();
1655 ImageFileArrayConst v = rIF.getArray();
1656 ImageFileArrayConst vImag = rIF.getImaginaryArray();
1660 if (v != NULL && xCursor < nx) {
1661 fftw_complex* pcIn = new fftw_complex [ny];
1662 double *pdTemp = new double [ny];
1665 for (i = 0; i < ny; i++)
1666 pdTemp[i] = v[xCursor][i];
1667 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1668 for (i = 0; i < ny; i++)
1669 pcIn[i][0] = pdTemp[i];
1671 for (i = 0; i < ny; i++) {
1672 if (rIF.isComplex())
1673 pdTemp[i] = vImag[xCursor][i];
1677 Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1678 for (i = 0; i < ny; i++)
1679 pcIn[i][1] = pdTemp[i];
1681 fftw_plan plan = fftw_plan_dft_1d (ny, pcIn, pcIn, FFTW_BACKWARD, FFTW_ESTIMATE);
1682 fftw_execute (plan);
1683 fftw_destroy_plan (plan);
1685 double* pX = new double [ny];
1686 double* pYReal = new double [ny];
1687 double* pYImag = new double [ny];
1688 double* pYMag = new double [ny];
1689 for (i = 0; i < ny; i++) {
1691 pYReal[i] = pcIn[i][0] / ny;
1692 pYImag[i] = pcIn[i][1] / ny;
1693 pYMag[i] = ::sqrt (pcIn[i][0] * pcIn[i][0] + pcIn[i][1] * pcIn[i][1]);
1696 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1698 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1700 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1701 std::ostringstream os;
1702 os << "Column " << xCursor;
1703 std::string title("title ");
1705 rPlotFile.addEzsetCommand (title.c_str());
1706 rPlotFile.addEzsetCommand ("xlabel Column");
1707 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1708 rPlotFile.addEzsetCommand ("lxfrac 0");
1709 rPlotFile.addEzsetCommand ("curve 1");
1710 rPlotFile.addEzsetCommand ("color 1");
1711 rPlotFile.addEzsetCommand ("dash 1");
1712 rPlotFile.addEzsetCommand ("curve 2");
1713 rPlotFile.addEzsetCommand ("color 4");
1714 rPlotFile.addEzsetCommand ("dash 3");
1715 rPlotFile.addEzsetCommand ("curve 3");
1716 rPlotFile.addEzsetCommand ("color 0");
1717 rPlotFile.addEzsetCommand ("solid");
1718 rPlotFile.addEzsetCommand ("box");
1719 rPlotFile.addEzsetCommand ("grid");
1720 rPlotFile.setCurveSize (4, ny);
1721 rPlotFile.addColumn (0, pX);
1722 rPlotFile.addColumn (1, pYReal);
1723 rPlotFile.addColumn (2, pYImag);
1724 rPlotFile.addColumn (3, pYMag);
1725 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1726 rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1727 os << ": FFT plot of " << wxConvUTF8.cWX2MB(dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str());
1728 *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
1729 rPlotFile.addDescription (os.str().c_str());
1738 if (theApp->getAskDeleteNewDocs())
1739 pPlotDoc->Modify (true);
1740 pPlotDoc->getView()->getFrame()->Show(true);
1741 pPlotDoc->UpdateAllViews ();
1742 pPlotDoc->Activate();
1748 ImageFileView::OnCompareCol (wxCommandEvent& event)
1750 int xCursor, yCursor;
1751 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1752 wxMessageBox (_T("No column selected. Please use left mouse button on image to select column"),_T("Error"));
1756 std::vector<ImageFileDocument*> vecIFDoc;
1757 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1758 if (vecIFDoc.size() == 0) {
1759 wxMessageBox (_T("No compatible images for Column Comparison"), _T("Error"));
1762 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), _T("Get Comparison Image"), vecIFDoc, false);
1764 if (dialogGetCompare.ShowModal() == wxID_OK) {
1765 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1766 const ImageFile& rIF = GetDocument()->getImageFile();
1767 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1769 ImageFileArrayConst v1 = rIF.getArray();
1770 ImageFileArrayConst v2 = rCompareIF.getArray();
1774 if (v1 != NULL && xCursor < nx) {
1775 double* pX = new double [ny];
1776 double* pY1 = new double [ny];
1777 double* pY2 = new double [ny];
1778 for (int i = 0; i < ny; i++) {
1780 pY1[i] = v1[xCursor][i];
1781 pY2[i] = v2[xCursor][i];
1783 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1785 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1787 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1788 std::ostringstream os;
1789 os << "Column " << xCursor << ": Comparison";
1790 std::string title("title ");
1792 rPlotFile.addEzsetCommand (title.c_str());
1793 rPlotFile.addEzsetCommand ("xlabel Row");
1794 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1795 rPlotFile.addEzsetCommand ("lxfrac 0");
1796 rPlotFile.addEzsetCommand ("curve 1");
1797 rPlotFile.addEzsetCommand ("color 2");
1798 rPlotFile.addEzsetCommand ("curve 2");
1799 rPlotFile.addEzsetCommand ("color 4");
1800 rPlotFile.addEzsetCommand ("dash 5");
1801 rPlotFile.addEzsetCommand ("box");
1802 rPlotFile.addEzsetCommand ("grid");
1803 rPlotFile.setCurveSize (3, ny);
1804 rPlotFile.addColumn (0, pX);
1805 rPlotFile.addColumn (1, pY1);
1806 rPlotFile.addColumn (2, pY2);
1809 for (iL = 0; iL < rIF.nLabels(); iL++) {
1810 std::ostringstream os;
1811 os << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str();
1812 os << ": " << rIF.labelGet(iL).getLabelString();
1813 rPlotFile.addDescription (os.str().c_str());
1815 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1816 std::ostringstream os;
1817 os << dynamic_cast<wxFrame*>(pCompareDoc->GetFirstView()->GetFrame())->GetTitle().mb_str(wxConvUTF8);
1819 os << rCompareIF.labelGet(iL).getLabelString();
1820 rPlotFile.addDescription (os.str().c_str());
1822 os << " between " << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().mb_str(wxConvUTF8) << " and "
1823 << dynamic_cast<wxFrame*>(pCompareDoc->GetFirstView()->GetFrame())->GetTitle().mb_str(wxConvUTF8);
1824 *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
1825 rPlotFile.addDescription (os.str().c_str());
1830 if (theApp->getAskDeleteNewDocs())
1831 pPlotDoc->Modify (true);
1832 pPlotDoc->getView()->getFrame()->Show(true);
1833 pPlotDoc->UpdateAllViews ();
1834 pPlotDoc->Activate();
1840 ImageFileView::OnCompareRow (wxCommandEvent& event)
1842 int xCursor, yCursor;
1843 if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1844 wxMessageBox (_T("No column selected. Please use left mouse button on image to select column"),_T("Error"));
1848 std::vector<ImageFileDocument*> vecIFDoc;
1849 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1851 if (vecIFDoc.size() == 0) {
1852 wxMessageBox (_T("No compatible images for Row Comparison"), _T("Error"));
1856 DialogGetComparisonImage dialogGetCompare (getFrameForChild(), _T("Get Comparison Image"), vecIFDoc, false);
1858 if (dialogGetCompare.ShowModal() == wxID_OK) {
1859 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1860 const ImageFile& rIF = GetDocument()->getImageFile();
1861 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1863 ImageFileArrayConst v1 = rIF.getArray();
1864 ImageFileArrayConst v2 = rCompareIF.getArray();
1868 if (v1 != NULL && yCursor < ny) {
1869 double* pX = new double [nx];
1870 double* pY1 = new double [nx];
1871 double* pY2 = new double [nx];
1872 for (int i = 0; i < nx; i++) {
1874 pY1[i] = v1[i][yCursor];
1875 pY2[i] = v2[i][yCursor];
1877 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1879 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1881 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1882 std::ostringstream os;
1883 os << "Row " << yCursor << ": Comparison";
1884 std::string title("title ");
1886 rPlotFile.addEzsetCommand (title.c_str());
1887 rPlotFile.addEzsetCommand ("xlabel Column");
1888 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1889 rPlotFile.addEzsetCommand ("lxfrac 0");
1890 rPlotFile.addEzsetCommand ("curve 1");
1891 rPlotFile.addEzsetCommand ("color 2");
1892 rPlotFile.addEzsetCommand ("curve 2");
1893 rPlotFile.addEzsetCommand ("color 4");
1894 rPlotFile.addEzsetCommand ("dash 5");
1895 rPlotFile.addEzsetCommand ("box");
1896 rPlotFile.addEzsetCommand ("grid");
1897 rPlotFile.setCurveSize (3, nx);
1898 rPlotFile.addColumn (0, pX);
1899 rPlotFile.addColumn (1, pY1);
1900 rPlotFile.addColumn (2, pY2);
1902 for (iL = 0; iL < rIF.nLabels(); iL++) {
1903 std::ostringstream os;
1904 os << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().mb_str(wxConvUTF8);
1906 os << rIF.labelGet(iL).getLabelString();
1907 rPlotFile.addDescription (os.str().c_str());
1909 for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1910 std::ostringstream os;
1911 os << dynamic_cast<wxFrame*>(pCompareDoc->GetFirstView()->GetFrame())->GetTitle().mb_str(wxConvUTF8) << ": "
1912 << rCompareIF.labelGet(iL).getLabelString();
1913 rPlotFile.addDescription (os.str().c_str());
1915 os << " between " << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().mb_str(wxConvUTF8) << " and "
1916 << dynamic_cast<wxFrame*>(pCompareDoc->GetFirstView()->GetFrame())->GetTitle().mb_str(wxConvUTF8);
1917 *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
1918 rPlotFile.addDescription (os.str().c_str());
1923 if (theApp->getAskDeleteNewDocs())
1924 pPlotDoc->Modify (true);
1925 pPlotDoc->getView()->getFrame()->Show(true);
1926 pPlotDoc->UpdateAllViews ();
1927 pPlotDoc->Activate();
1932 static int NUMBER_HISTOGRAM_BINS = 256;
1935 ImageFileView::OnPlotHistogram (wxCommandEvent& event)
1937 const ImageFile& rIF = GetDocument()->getImageFile();
1938 ImageFileArrayConst v = rIF.getArray();
1942 if (v != NULL && nx > 0 && ny > 0) {
1943 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1945 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1949 double* pX = new double [NUMBER_HISTOGRAM_BINS];
1950 double* pY = new double [NUMBER_HISTOGRAM_BINS];
1952 rIF.getMinMax (dMin, dMax);
1953 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
1955 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
1956 pX[i] = dMin + (i + 0.5) * dBinWidth;
1959 for (int ix = 0; ix < nx; ix++)
1960 for (int iy = 0; iy < ny; iy++) {
1961 int iBin = nearest<int> ((v[ix][iy] - dMin) / dBinWidth);
1962 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
1966 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1967 std::ostringstream os;
1969 std::string title("title ");
1971 rPlotFile.addEzsetCommand (title.c_str());
1972 rPlotFile.addEzsetCommand ("xlabel Pixel Value");
1973 rPlotFile.addEzsetCommand ("ylabel Count");
1974 rPlotFile.addEzsetCommand ("box");
1975 rPlotFile.addEzsetCommand ("grid");
1976 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
1977 rPlotFile.addColumn (0, pX);
1978 rPlotFile.addColumn (1, pY);
1979 for (unsigned int iL = 0; iL < rIF.nLabels(); iL++) {
1980 std::ostringstream os;
1981 os << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().mb_str(wxConvUTF8);
1982 os << ": " << rIF.labelGet(iL).getLabelString();
1983 rPlotFile.addDescription (os.str().c_str());
1985 os << " plot of " << wxConvUTF8.cWX2MB(dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str());
1986 *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
1987 rPlotFile.addDescription (os.str().c_str());
1990 if (theApp->getAskDeleteNewDocs())
1991 pPlotDoc->Modify (true);
1992 pPlotDoc->getView()->getFrame()->Show(true);
1993 pPlotDoc->UpdateAllViews ();
1994 pPlotDoc->Activate();
2001 PhantomCanvas::PhantomCanvas (PhantomFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2002 : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v)
2006 PhantomCanvas::~PhantomCanvas ()
2012 PhantomCanvas::OnDraw (wxDC& dc)
2015 m_pView->OnDraw(& dc);
2019 PhantomCanvas::GetBestSize() const
2025 theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
2026 xSize = maxValue<int> (xSize, ySize);
2028 ySize = xSize = (xSize / 4);
2030 xSize = ySize = static_cast<int>(ySize * .7);
2033 return wxSize (xSize, ySize);
2040 IMPLEMENT_DYNAMIC_CLASS(PhantomFileView, wxView)
2042 BEGIN_EVENT_TABLE(PhantomFileView, wxView)
2043 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomFileView::OnProperties)
2044 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomFileView::OnRasterize)
2045 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomFileView::OnProjections)
2048 PhantomFileView::PhantomFileView()
2049 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0)
2051 #if defined(DEBUG) || defined(_DEBUG)
2052 m_iDefaultNDet = 165;
2053 m_iDefaultNView = 180;
2054 m_iDefaultNSample = 1;
2056 m_iDefaultNDet = 367;
2057 m_iDefaultNView = 320;
2058 m_iDefaultNSample = 2;
2060 m_iDefaultOffsetView = 0;
2061 m_dDefaultRotation = 1;
2062 m_dDefaultFocalLength = 2;
2063 m_dDefaultCenterDetectorLength = 2;
2064 m_dDefaultViewRatio = 1;
2065 m_dDefaultScanRatio = 1;
2066 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
2067 m_iDefaultTrace = Trace::TRACE_NONE;
2070 m_iDefaultRasterNX = 115;
2071 m_iDefaultRasterNY = 115;
2072 m_iDefaultRasterNSamples = 1;
2074 m_iDefaultRasterNX = 256;
2075 m_iDefaultRasterNY = 256;
2076 m_iDefaultRasterNSamples = 2;
2078 m_dDefaultRasterViewRatio = 1;
2081 PhantomFileView::~PhantomFileView()
2083 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2084 GetDocumentManager()->ActivateView(this, FALSE);
2088 PhantomFileView::OnProperties (wxCommandEvent& event)
2090 const int idPhantom = GetDocument()->getPhantomID();
2091 const wxString& namePhantom = GetDocument()->getPhantomName();
2092 std::ostringstream os;
2093 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")" << "\n";
2094 const Phantom& rPhantom = GetDocument()->getPhantom();
2095 rPhantom.printDefinitions (os);
2097 rPhantom.print (os);
2099 *theApp->getLog() << _T(">>>>\n") << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("<<<<\n");
2100 wxMessageBox (wxConvUTF8.cMB2WX(os.str().c_str()), _T("Phantom Properties"));
2101 GetDocument()->Activate();
2106 PhantomFileView::OnProjections (wxCommandEvent& event)
2108 DialogGetProjectionParameters dialogProjection (getFrameForChild(),
2109 m_iDefaultNDet, m_iDefaultNView, m_iDefaultOffsetView, m_iDefaultNSample, m_dDefaultRotation,
2110 m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio,
2111 m_iDefaultGeometry, m_iDefaultTrace);
2112 int retVal = dialogProjection.ShowModal();
2113 if (retVal != wxID_OK)
2116 m_iDefaultNDet = dialogProjection.getNDet();
2117 m_iDefaultNView = dialogProjection.getNView();
2118 m_iDefaultOffsetView = dialogProjection.getOffsetView();
2119 m_iDefaultNSample = dialogProjection.getNSamples();
2120 m_iDefaultTrace = dialogProjection.getTrace();
2121 m_dDefaultRotation = dialogProjection.getRotAngle();
2122 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
2123 m_dDefaultCenterDetectorLength = dialogProjection.getCenterDetectorLengthRatio();
2124 m_dDefaultViewRatio = dialogProjection.getViewRatio();
2125 m_dDefaultScanRatio = dialogProjection.getScanRatio();
2126 wxString sGeometry (dialogProjection.getGeometry(), wxConvUTF8);
2127 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.mb_str(wxConvUTF8));
2128 double dRotationRadians = m_dDefaultRotation;
2129 m_dDefaultRotation /= TWOPI; // convert back to fraction of a circle
2131 if (m_iDefaultNDet <= 0 || m_iDefaultNView <= 0 || sGeometry == _T(""))
2134 const Phantom& rPhantom = GetDocument()->getPhantom();
2135 Scanner theScanner (rPhantom, sGeometry.mb_str(wxConvUTF8), m_iDefaultNDet, m_iDefaultNView, m_iDefaultOffsetView, m_iDefaultNSample,
2136 dRotationRadians, m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio, m_dDefaultScanRatio);
2137 if (theScanner.fail()) {
2138 wxString msg = _T("Failed making scanner\n");
2139 msg += wxConvUTF8.cMB2WX(theScanner.failMessage().c_str());
2140 *theApp->getLog() << msg << _T("\n");
2141 wxMessageBox (msg, _T("Error"));
2145 std::ostringstream os;
2146 os << "Projections for " << rPhantom.name().c_str()
2147 << ": nDet=" << m_iDefaultNDet
2148 << ", nView=" << m_iDefaultNView
2149 << ", gantry offset=" << m_iDefaultOffsetView
2150 << ", nSamples=" << m_iDefaultNSample
2151 << ", RotAngle=" << m_dDefaultRotation
2152 << ", FocalLengthRatio=" << m_dDefaultFocalLength
2153 << ", CenterDetectorLengthRatio=" << m_dDefaultCenterDetectorLength
2154 << ", ViewRatio=" << m_dDefaultViewRatio
2155 << ", ScanRatio=" << m_dDefaultScanRatio
2156 << ", Geometry=" << sGeometry.mb_str(wxConvUTF8)
2157 << ", FanBeamAngle=" << convertRadiansToDegrees (theScanner.fanBeamAngle());
2160 Projections* pProj = NULL;
2161 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2162 pProj = new Projections;
2163 pProj->initFromScanner (theScanner);
2165 ProjectionsDialog dialogProjections (theScanner, *pProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(getFrameForChild()));
2166 for (int iView = 0; iView < pProj->nView(); iView++) {
2168 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
2173 while (dialogProjections.isPaused()) {
2180 if (theApp->getUseBackgroundTasks()) {
2181 ProjectorSupervisorThread* pProjector = new ProjectorSupervisorThread
2182 (this, m_iDefaultNDet, m_iDefaultNView, m_iDefaultOffsetView,
2183 sGeometry.mb_str(wxConvUTF8), m_iDefaultNSample, dRotationRadians,
2184 m_dDefaultFocalLength, m_dDefaultCenterDetectorLength, m_dDefaultViewRatio,
2185 m_dDefaultScanRatio, wxConvUTF8.cMB2WX(os.str().c_str()));
2186 if (pProjector->Create() != wxTHREAD_NO_ERROR) {
2187 sys_error (ERR_SEVERE, "Error creating projector thread");
2191 pProjector->SetPriority(60);
2195 #endif // HAVE_WXTHREADS
2197 pProj = new Projections;
2198 pProj->initFromScanner (theScanner);
2199 wxProgressDialog dlgProgress (_T("Projection"), _T("Projection Progress"), pProj->nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2200 for (int i = 0; i < pProj->nView(); i++) {
2201 //theScanner.collectProjections (*pProj, rPhantom, i, 1, true, m_iDefaultTrace);
2202 theScanner.collectProjections (*pProj, rPhantom, i, 1, theScanner.offsetView(), true, m_iDefaultTrace);
2203 if ((i + 1) % ITER_PER_UPDATE == 0)
2204 if (! dlgProgress.Update (i+1)) {
2212 *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
2213 pProj->setRemark (os.str());
2214 pProj->setCalcTime (timer.timerEnd());
2216 ProjectionFileDocument* pProjectionDoc = theApp->newProjectionDoc();
2217 if (! pProjectionDoc) {
2218 sys_error (ERR_SEVERE, "Unable to create projection document");
2221 pProjectionDoc->setProjections (pProj);
2222 if (theApp->getAskDeleteNewDocs())
2223 pProjectionDoc-> Modify(true);
2224 OnUpdate(this, NULL);
2225 pProjectionDoc->UpdateAllViews (this);
2226 pProjectionDoc->getView()->setInitialClientSize();
2227 pProjectionDoc->Activate();
2230 PhantomFileView::OnRasterize (wxCommandEvent& event)
2232 DialogGetRasterParameters dialogRaster (getFrameForChild(), m_iDefaultRasterNX, m_iDefaultRasterNY,
2233 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio);
2234 int retVal = dialogRaster.ShowModal();
2235 if (retVal != wxID_OK)
2238 m_iDefaultRasterNX = dialogRaster.getXSize();
2239 m_iDefaultRasterNY = dialogRaster.getYSize();
2240 m_iDefaultRasterNSamples = dialogRaster.getNSamples();
2241 m_dDefaultRasterViewRatio = dialogRaster.getViewRatio();
2242 if (m_iDefaultRasterNSamples < 1)
2243 m_iDefaultRasterNSamples = 1;
2244 if (m_dDefaultRasterViewRatio < 0)
2245 m_dDefaultRasterViewRatio = 0;
2246 if (m_iDefaultRasterNX <= 0 || m_iDefaultRasterNY <= 0)
2249 const Phantom& rPhantom = GetDocument()->getPhantom();
2250 std::ostringstream os;
2251 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << m_iDefaultRasterNX << ", YSize="
2252 << m_iDefaultRasterNY << ", ViewRatio=" << m_dDefaultRasterViewRatio << ", nSamples="
2253 << m_iDefaultRasterNSamples;;
2256 if (theApp->getUseBackgroundTasks()) {
2257 RasterizerSupervisorThread* pThread = new RasterizerSupervisorThread
2258 (this, m_iDefaultRasterNX, m_iDefaultRasterNY,
2259 m_iDefaultRasterNSamples, m_dDefaultRasterViewRatio,
2260 wxConvUTF8.cMB2WX(os.str().c_str()));
2261 if (pThread->Create() != wxTHREAD_NO_ERROR) {
2262 *theApp->getLog() << _T("Error creating rasterizer thread\n");
2265 pThread->SetPriority (60);
2270 ImageFile* pImageFile = new ImageFile (m_iDefaultRasterNX, m_iDefaultRasterNY);
2272 wxProgressDialog dlgProgress (_T("Rasterize"),
2273 _T("Rasterization Progress"),
2274 pImageFile->nx() + 1,
2278 for (unsigned int i = 0; i < pImageFile->nx(); i++) {
2279 rPhantom.convertToImagefile (*pImageFile, m_dDefaultRasterViewRatio,
2280 m_iDefaultRasterNSamples, Trace::TRACE_NONE,
2282 if ((i + 1) % ITER_PER_UPDATE == 0)
2283 if (! dlgProgress.Update (i+1)) {
2289 ImageFileDocument* pRasterDoc = theApp->newImageDoc();
2291 sys_error (ERR_SEVERE, "Unable to create image file");
2294 pRasterDoc->setImageFile (pImageFile);
2295 if (theApp->getAskDeleteNewDocs())
2296 pRasterDoc->Modify (true);
2297 *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
2298 pImageFile->labelAdd (os.str().c_str(), timer.timerEnd());
2300 pRasterDoc->UpdateAllViews(this);
2301 pRasterDoc->getView()->setInitialClientSize();
2302 pRasterDoc->Activate();
2308 PhantomFileView::CreateCanvas (wxFrame *parent)
2310 PhantomCanvas* pCanvas =
2311 new PhantomCanvas (this, parent, wxPoint(-1,-1),
2312 wxSize(-1,-1), wxFULL_REPAINT_ON_RESIZE);
2313 pCanvas->SetBackgroundColour(*wxWHITE);
2314 pCanvas->ClearBackground();
2323 PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2326 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, _T("Phantom Frame"), wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
2328 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, _T("Phantom Frame"), wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
2330 theApp->setIconForFrame (subframe);
2332 m_pFileMenu = new wxMenu;
2334 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, _T("Cr&eate Phantom...\tCtrl-P"));
2335 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, _T("Create &Filter...\tCtrl-F"));
2336 m_pFileMenu->Append(wxID_OPEN, _T("&Open...\tCtrl-O"));
2337 m_pFileMenu->Append(wxID_SAVEAS, _T("Save &As..."));
2338 m_pFileMenu->Append(wxID_CLOSE, _T("&Close"));
2340 m_pFileMenu->AppendSeparator();
2341 m_pFileMenu->Append(PHMMENU_FILE_PROPERTIES, _T("P&roperties\tCtrl-I"));
2343 m_pFileMenu->AppendSeparator();
2344 m_pFileMenu->Append(wxID_PRINT, _T("&Print..."));
2345 m_pFileMenu->Append(wxID_PRINT_SETUP, _T("Print &Setup..."));
2346 m_pFileMenu->Append(wxID_PREVIEW, _T("Print Pre&view"));
2347 m_pFileMenu->AppendSeparator();
2348 m_pFileMenu->Append(MAINMENU_IMPORT, _T("&Import...\tCtrl-M"));
2349 m_pFileMenu->AppendSeparator();
2350 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, _T("Prefere&nces..."));
2351 m_pFileMenu->Append(MAINMENU_FILE_EXIT, _T("E&xit"));
2352 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2353 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2355 wxMenu *process_menu = new wxMenu;
2356 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, _T("&Rasterize...\tCtrl-R"));
2357 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, _T("&Projections...\tCtrl-J"));
2359 wxMenu *help_menu = new wxMenu;
2360 help_menu->Append(MAINMENU_HELP_CONTENTS, _T("&Contents\tF1"));
2361 help_menu->Append (MAINMENU_HELP_TIPS, _T("&Tips"));
2362 help_menu->Append (IDH_QUICKSTART, _T("&Quick Start"));
2363 help_menu->Append(MAINMENU_HELP_ABOUT, _T("&About"));
2365 wxMenuBar *menu_bar = new wxMenuBar;
2367 menu_bar->Append(m_pFileMenu, _T("&File"));
2368 menu_bar->Append(process_menu, _T("&Process"));
2369 menu_bar->Append(help_menu, _T("&Help"));
2371 subframe->SetMenuBar(menu_bar);
2372 subframe->Centre(wxBOTH);
2374 wxAcceleratorEntry accelEntries[3];
2375 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('J'), PHMMENU_PROCESS_PROJECTIONS);
2376 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('R'), PHMMENU_PROCESS_RASTERIZE);
2377 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('I'), PHMMENU_FILE_PROPERTIES);
2378 wxAcceleratorTable accelTable (3, accelEntries);
2379 subframe->SetAcceleratorTable (accelTable);
2386 PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2388 m_pFrame = CreateChildFrame(doc, this);
2390 m_pCanvas = CreateCanvas (m_pFrame);
2391 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
2392 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
2393 m_pFrame->SetTitle (doc->GetFilename());
2395 m_pFrame->Show(true);
2402 PhantomFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2405 m_pCanvas->Refresh();
2409 PhantomFileView::OnClose (bool deleteWindow)
2411 if (! GetDocument() || ! GetDocument()->Close())
2416 m_pCanvas->setView(NULL);
2419 wxString s(wxTheApp->GetAppName());
2421 m_pFrame->SetTitle(s);
2428 if (GetDocument() && GetDocument()->getBadFileOpen())
2429 ::wxYield(); // wxWindows bug workaround
2436 PhantomFileView::OnDraw (wxDC* dc)
2439 m_pCanvas->GetClientSize (&xsize, &ysize);
2440 SGPDriver driver (dc, xsize, ysize);
2442 const Phantom& rPhantom = GetDocument()->getPhantom();
2443 sgp.setColor (C_RED);
2444 rPhantom.show (sgp);
2449 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2450 : wxScrolledWindow(frame, -1, pos, size, style)
2455 ProjectionFileCanvas::~ProjectionFileCanvas ()
2461 ProjectionFileCanvas::OnDraw(wxDC& dc)
2464 m_pView->OnDraw(& dc);
2468 ProjectionFileCanvas::GetBestSize () const
2470 const int iMinX = 50;
2471 const int iMinY = 20;
2472 wxSize bestSize (iMinX,iMinY);
2475 Projections& rProj = m_pView->GetDocument()->getProjections();
2476 bestSize.Set (rProj.nDet(), rProj.nView());
2479 if (bestSize.x > 800)
2481 if (bestSize.y > 800)
2484 if (bestSize.x < iMinX)
2486 if (bestSize.y < iMinY)
2493 // ProjectionFileView
2495 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
2497 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
2498 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
2499 EVT_MENU(PJMENU_RECONSTRUCT_FBP, ProjectionFileView::OnReconstructFBP)
2500 EVT_MENU(PJMENU_RECONSTRUCT_FBP_REBIN, ProjectionFileView::OnReconstructFBPRebin)
2501 EVT_MENU(PJMENU_RECONSTRUCT_FOURIER, ProjectionFileView::OnReconstructFourier)
2502 EVT_MENU(PJMENU_CONVERT_RECTANGULAR, ProjectionFileView::OnConvertRectangular)
2503 EVT_MENU(PJMENU_CONVERT_POLAR, ProjectionFileView::OnConvertPolar)
2504 EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
2505 EVT_MENU(PJMENU_CONVERT_PARALLEL, ProjectionFileView::OnConvertParallel)
2506 EVT_MENU(PJMENU_PLOT_TTHETA_SAMPLING, ProjectionFileView::OnPlotTThetaSampling)
2507 EVT_MENU(PJMENU_PLOT_HISTOGRAM, ProjectionFileView::OnPlotHistogram)
2508 // EVT_MENU(PJMENU_ARTIFACT_REDUCTION, ProjectionFileView::OnArtifactReduction)
2512 ProjectionFileView::ProjectionFileView()
2513 : wxView(), m_pBitmap(0), m_pFrame(0), m_pCanvas(0), m_pFileMenu(0)
2523 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
2524 m_dDefaultFilterParam = 1.;
2526 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
2527 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
2529 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
2530 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
2532 m_iDefaultZeropad = 2;
2533 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF;
2534 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
2535 m_iDefaultInterpParam = 1;
2536 m_iDefaultTrace = Trace::TRACE_NONE;
2538 m_iDefaultPolarNX = 256;
2539 m_iDefaultPolarNY = 256;
2540 m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR;
2541 m_iDefaultPolarZeropad = 2;
2544 ProjectionFileView::~ProjectionFileView()
2546 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2547 GetDocumentManager()->ActivateView(this, FALSE);;
2551 ProjectionFileView::OnProperties (wxCommandEvent& event)
2553 const Projections& rProj = GetDocument()->getProjections();
2554 std::ostringstream os;
2555 rProj.printScanInfo(os);
2556 *theApp->getLog() << _T(">>>>\n") << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("<<<<\n");
2557 wxMessageDialog dialogMsg (getFrameForChild(), wxConvUTF8.cMB2WX(os.str().c_str()), _T("Projection File Properties"), wxOK | wxICON_INFORMATION);
2558 dialogMsg.ShowModal();
2559 GetDocument()->Activate();
2564 ProjectionFileView::OnConvertRectangular (wxCommandEvent& event)
2566 Projections& rProj = GetDocument()->getProjections();
2568 int nDet = rProj.nDet();
2569 int nView = rProj.nView();
2570 ImageFile* pIF = new ImageFile (nDet, nView);
2571 ImageFileArray v = pIF->getArray();
2572 for (int iv = 0; iv < nView; iv++) {
2573 DetectorValue* detval = rProj.getDetectorArray(iv).detValues();
2575 for (int id = 0; id < nDet; id++)
2576 v[id][iv] = detval[id];
2579 ImageFileDocument* pRectDoc = theApp->newImageDoc ();
2581 sys_error (ERR_SEVERE, "Unable to create image file");
2584 pRectDoc->setImageFile (pIF);
2585 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2586 std::ostringstream os;
2587 os << "Convert projection file " << getFrame()->GetTitle().c_str() << " to rectangular image";
2588 *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
2589 pIF->labelAdd (os.str().c_str());
2590 if (theApp->getAskDeleteNewDocs())
2591 pRectDoc->Modify (true);
2592 pRectDoc->UpdateAllViews();
2593 pRectDoc->getView()->setInitialClientSize();
2594 pRectDoc->Activate();
2598 ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
2600 Projections& rProj = GetDocument()->getProjections();
2601 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), _T("Convert Polar"), m_iDefaultPolarNX, m_iDefaultPolarNY,
2602 m_iDefaultPolarInterpolation, -1, IDH_DLG_POLAR);
2603 if (dialogPolar.ShowModal() == wxID_OK) {
2604 wxProgressDialog dlgProgress (_T("Convert Polar"), _T("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2605 wxString strInterpolation (dialogPolar.getInterpolationName(), wxConvUTF8);
2606 m_iDefaultPolarNX = dialogPolar.getXSize();
2607 m_iDefaultPolarNY = dialogPolar.getYSize();
2608 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2609 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.mb_str(wxConvUTF8));
2611 if (! rProj.convertPolar (*pIF, m_iDefaultPolarInterpolation)) {
2613 *theApp->getLog() << _T("Error converting to Polar\n");
2617 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2619 sys_error (ERR_SEVERE, "Unable to create image file");
2622 pPolarDoc->setImageFile (pIF);
2623 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2624 std::ostringstream os;
2625 os << "Convert projection file " << getFrame()->GetTitle().c_str() << " to polar image: xSize="
2626 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2627 << strInterpolation.c_str();
2628 *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
2629 pIF->labelAdd (os.str().c_str());
2630 if (theApp->getAskDeleteNewDocs())
2631 pPolarDoc->Modify (true);
2632 pPolarDoc->UpdateAllViews ();
2633 pPolarDoc->getView()->setInitialClientSize();
2634 pPolarDoc->Activate();
2639 ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
2641 Projections& rProj = GetDocument()->getProjections();
2642 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), _T("Convert to FFT Polar"), m_iDefaultPolarNX, m_iDefaultPolarNY,
2643 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad, IDH_DLG_FFT_POLAR);
2644 if (dialogPolar.ShowModal() == wxID_OK) {
2645 wxProgressDialog dlgProgress (_T("Convert FFT Polar"), _T("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2646 wxString strInterpolation (dialogPolar.getInterpolationName(), wxConvUTF8);
2647 m_iDefaultPolarNX = dialogPolar.getXSize();
2648 m_iDefaultPolarNY = dialogPolar.getYSize();
2649 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2650 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2652 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.mb_str(wxConvUTF8));
2653 if (! rProj.convertFFTPolar (*pIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad)) {
2655 *theApp->getLog() << _T("Error converting to polar\n");
2658 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2660 sys_error (ERR_SEVERE, "Unable to create image file");
2663 pPolarDoc->setImageFile (pIF);
2664 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2665 std::ostringstream os;
2666 os << "Convert projection file " << getFrame()->GetTitle().c_str() << " to FFT polar image: xSize="
2667 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2668 << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2669 *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
2670 pIF->labelAdd (os.str().c_str());
2671 if (theApp->getAskDeleteNewDocs())
2672 pPolarDoc->Modify (true);
2673 pPolarDoc->UpdateAllViews (this);
2674 pPolarDoc->getView()->setInitialClientSize();
2675 pPolarDoc->Activate();
2680 ProjectionFileView::OnPlotTThetaSampling (wxCommandEvent& event)
2682 DialogGetThetaRange dlgTheta (this->getFrame(), ParallelRaysums::THETA_RANGE_UNCONSTRAINED);
2683 if (dlgTheta.ShowModal() != wxID_OK)
2686 int iThetaRange = dlgTheta.getThetaRange();
2688 Projections& rProj = GetDocument()->getProjections();
2689 ParallelRaysums parallel (&rProj, iThetaRange);
2690 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
2691 PlotFile& rPlot = pPlotDoc->getPlotFile();
2692 ParallelRaysums::CoordinateContainer& coordContainer = parallel.getCoordinates();
2693 double* pdT = new double [parallel.getNumCoordinates()];
2694 double* pdTheta = new double [parallel.getNumCoordinates()];
2696 for (int i = 0; i < parallel.getNumCoordinates(); i++) {
2697 pdT[i] = coordContainer[i]->m_dT;
2698 pdTheta[i] = coordContainer[i]->m_dTheta;
2700 rPlot.setCurveSize (2, parallel.getNumCoordinates(), true);
2701 rPlot.addEzsetCommand ("title T-Theta Sampling");
2702 rPlot.addEzsetCommand ("xlabel T");
2703 rPlot.addEzsetCommand ("ylabel Theta");
2704 rPlot.addEzsetCommand ("curve 1");
2705 if (rProj.nDet() < 50 && rProj.nView() < 50)
2706 rPlot.addEzsetCommand ("symbol 1"); // x symbol
2708 rPlot.addEzsetCommand ("symbol 6"); // point symbol
2709 rPlot.addEzsetCommand ("noline");
2710 rPlot.addColumn (0, pdT);
2711 rPlot.addColumn (1, pdTheta);
2714 if (theApp->getAskDeleteNewDocs())
2715 pPlotDoc->Modify (true);
2716 pPlotDoc->getView()->getFrame()->Show(true);
2717 pPlotDoc->UpdateAllViews ();
2718 pPlotDoc->Activate();
2723 ProjectionFileView::OnPlotHistogram (wxCommandEvent& event)
2725 Projections& rProj = GetDocument()->getProjections();
2726 int nDet = rProj.nDet();
2727 int nView = rProj.nView();
2729 if (nDet < 1 || nView < 1)
2732 PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
2734 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
2738 DetectorValue* pdDetval = rProj.getDetectorArray(0).detValues();
2739 double dMin = pdDetval[0], dMax = pdDetval[0];
2741 for (int iv = 0; iv < nView; iv++) {
2742 pdDetval = rProj.getDetectorArray(iv).detValues();
2743 for (int id = 0; id < nDet; id++) {
2744 double dV = pdDetval[id];
2752 double* pX = new double [NUMBER_HISTOGRAM_BINS];
2753 double* pY = new double [NUMBER_HISTOGRAM_BINS];
2754 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
2756 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
2757 pX[i] = dMin + (i + 0.5) * dBinWidth;
2760 for (int j = 0; j < nView; j++) {
2761 pdDetval = rProj.getDetectorArray(j).detValues();
2762 for (int id = 0; id < nDet; id++) {
2763 int iBin = nearest<int> ((pdDetval[id] - dMin) / dBinWidth);
2764 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
2768 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
2769 std::ostringstream os;
2771 std::string title("title ");
2773 rPlotFile.addEzsetCommand (title.c_str());
2774 rPlotFile.addEzsetCommand ("xlabel Detector Value");
2775 rPlotFile.addEzsetCommand ("ylabel Count");
2776 rPlotFile.addEzsetCommand ("box");
2777 rPlotFile.addEzsetCommand ("grid");
2778 rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
2779 rPlotFile.addColumn (0, pX);
2780 rPlotFile.addColumn (1, pY);
2781 rPlotFile.addDescription (rProj.remark());
2782 os << " plot of " << dynamic_cast<wxFrame*>(GetDocument()->GetFirstView()->GetFrame())->GetTitle().c_str();
2783 *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
2784 rPlotFile.addDescription (os.str().c_str());
2787 if (theApp->getAskDeleteNewDocs())
2788 pPlotDoc->Modify (true);
2789 pPlotDoc->getView()->getFrame()->Show(true);
2790 pPlotDoc->UpdateAllViews ();
2791 pPlotDoc->Activate();
2796 ProjectionFileView::OnConvertParallel (wxCommandEvent& event)
2798 Projections& rProj = GetDocument()->getProjections();
2799 if (rProj.geometry() == Scanner::GEOMETRY_PARALLEL) {
2800 wxMessageBox (_T("Projections are already parallel"), _T("Error"));
2803 wxProgressDialog dlgProgress (_T("Convert to Parallel"), _T("Conversion Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2804 Projections* pProjNew = rProj.interpolateToParallel();
2805 ProjectionFileDocument* pProjDocNew = theApp->newProjectionDoc();
2806 pProjDocNew->setProjections (pProjNew);
2808 if (ProjectionFileView* projView = pProjDocNew->getView()) {
2809 projView->OnUpdate (projView, NULL);
2810 if (projView->getCanvas())
2811 projView->getCanvas()->SetClientSize (pProjNew->nDet(), pProjNew->nView());
2812 if (wxFrame* pFrame = projView->getFrame()) {
2817 GetDocumentManager()->ActivateView (projView, true);
2819 if (theApp->getAskDeleteNewDocs())
2820 pProjDocNew-> Modify(true);
2821 pProjDocNew->UpdateAllViews (this);
2822 pProjDocNew->getView()->setInitialClientSize();
2823 pProjDocNew->Activate();
2827 ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
2829 Projections& rProj = GetDocument()->getProjections();
2830 DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), _T("Fourier Reconstruction"), m_iDefaultPolarNX, m_iDefaultPolarNY,
2831 m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad, IDH_DLG_RECON_FOURIER);
2832 if (dialogPolar.ShowModal() == wxID_OK) {
2833 wxProgressDialog dlgProgress (_T("Reconstruction Fourier"), _T("Reconstruction Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
2834 wxString strInterpolation (dialogPolar.getInterpolationName(), wxConvUTF8);
2835 m_iDefaultPolarNX = dialogPolar.getXSize();
2836 m_iDefaultPolarNY = dialogPolar.getYSize();
2837 m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2838 ImageFile* pIF = new ImageFile (m_iDefaultPolarNX, m_iDefaultPolarNY);
2840 m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.mb_str(wxConvUTF8));
2841 if (! rProj.convertFFTPolar (*pIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad)) {
2843 *theApp->getLog() << _T("Error converting to polar\n");
2849 pIF->magnitude(*pIF);
2850 Fourier::shuffleFourierToNaturalOrder (*pIF);
2852 ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2854 sys_error (ERR_SEVERE, "Unable to create image file");
2857 pPolarDoc->setImageFile (pIF);
2858 pIF->labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2859 std::ostringstream os;
2860 os << "Reconstruct Fourier " << getFrame()->GetTitle().mb_str(wxConvUTF8) << ": xSize="
2861 << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation="
2862 << strInterpolation.mb_str(wxConvUTF8) << ", zeropad=" << m_iDefaultPolarZeropad;
2863 *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
2864 pIF->labelAdd (os.str().c_str());
2865 if (theApp->getAskDeleteNewDocs())
2866 pPolarDoc->Modify (true);
2867 pPolarDoc->UpdateAllViews ();
2868 pPolarDoc->getView()->setInitialClientSize();
2869 pPolarDoc->Activate();
2874 ProjectionFileView::OnReconstructFBPRebin (wxCommandEvent& event)
2876 Projections& rProj = GetDocument()->getProjections();
2877 doReconstructFBP (rProj, true);
2881 ProjectionFileView::OnReconstructFBP (wxCommandEvent& event)
2883 Projections& rProj = GetDocument()->getProjections();
2884 doReconstructFBP (rProj, false);
2888 ProjectionFileView::doReconstructFBP (const Projections& rProj, bool bRebinToParallel)
2890 ReconstructionROI defaultROI;
2891 defaultROI.m_dXMin = -rProj.phmLen() / 2;
2892 defaultROI.m_dXMax = defaultROI.m_dXMin + rProj.phmLen();
2893 defaultROI.m_dYMin = -rProj.phmLen() / 2;
2894 defaultROI.m_dYMax = defaultROI.m_dYMin + rProj.phmLen();
2896 DialogGetReconstructionParameters dialogReconstruction (getFrameForChild(), m_iDefaultNX, m_iDefaultNY,
2897 m_iDefaultFilter, m_dDefaultFilterParam, m_iDefaultFilterMethod, m_iDefaultFilterGeneration,
2898 m_iDefaultZeropad, m_iDefaultInterpolation, m_iDefaultInterpParam, m_iDefaultBackprojector,
2899 m_iDefaultTrace, &defaultROI);
2901 int retVal = dialogReconstruction.ShowModal();
2902 if (retVal != wxID_OK)
2905 m_iDefaultNX = dialogReconstruction.getXSize();
2906 m_iDefaultNY = dialogReconstruction.getYSize();
2907 wxString optFilterName (dialogReconstruction.getFilterName(), wxConvUTF8);
2908 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.mb_str(wxConvUTF8));
2909 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
2910 wxString optFilterMethodName (dialogReconstruction.getFilterMethodName(), wxConvUTF8);
2911 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.mb_str(wxConvUTF8));
2912 m_iDefaultZeropad = dialogReconstruction.getZeropad();
2913 wxString optFilterGenerationName (dialogReconstruction.getFilterGenerationName(), wxConvUTF8);
2914 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.mb_str(wxConvUTF8));
2915 wxString optInterpName (dialogReconstruction.getInterpName(), wxConvUTF8);
2916 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.mb_str(wxConvUTF8));
2917 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
2918 wxString optBackprojectName (dialogReconstruction.getBackprojectName(), wxConvUTF8);
2919 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.mb_str(wxConvUTF8));
2920 m_iDefaultTrace = dialogReconstruction.getTrace();
2921 dialogReconstruction.getROI (&defaultROI);
2923 if (m_iDefaultNX <= 0 && m_iDefaultNY <= 0)
2926 std::ostringstream os;
2927 os << "Reconstruct " << rProj.getFilename() << ": xSize=" << m_iDefaultNX << ", ySize=" << m_iDefaultNY << ", Filter=" << optFilterName.mb_str(wxConvUTF8) << ", FilterParam=" << m_dDefaultFilterParam << ", FilterMethod=" << optFilterMethodName.mb_str(wxConvUTF8) << ", FilterGeneration=" << optFilterGenerationName.mb_str(wxConvUTF8) << ", Zeropad=" << m_iDefaultZeropad << ", Interpolation=" << optInterpName.mb_str(wxConvUTF8) << ", InterpolationParam=" << m_iDefaultInterpParam << ", Backprojection=" << optBackprojectName.mb_str(wxConvUTF8);
2928 if (bRebinToParallel)
2929 os << "; Interpolate to Parallel";
2932 ImageFile* pImageFile = NULL;
2933 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2934 pImageFile = new ImageFile (m_iDefaultNX, m_iDefaultNY);
2935 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.mb_str(wxConvUTF8),
2936 m_dDefaultFilterParam, optFilterMethodName.mb_str(wxConvUTF8), m_iDefaultZeropad, optFilterGenerationName.mb_str(wxConvUTF8),
2937 optInterpName.mb_str(wxConvUTF8), m_iDefaultInterpParam, optBackprojectName.mb_str(wxConvUTF8), m_iDefaultTrace,
2938 &defaultROI, bRebinToParallel);
2940 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstructor, rProj, *pImageFile, m_iDefaultTrace, getFrameForChild());
2941 for (int iView = 0; iView < rProj.nView(); iView++) {
2943 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView, true)) {
2944 delete pDlgReconstruct;
2945 delete pReconstructor;
2950 while (pDlgReconstruct->isPaused()) {
2955 pReconstructor->postProcessing();
2956 delete pDlgReconstruct;
2957 delete pReconstructor;
2960 if (theApp->getUseBackgroundTasks()) {
2961 ReconstructorSupervisorThread* pReconstructor = new ReconstructorSupervisorThread
2962 (this, m_iDefaultNX, m_iDefaultNY, optFilterName.mb_str(wxConvUTF8),
2963 m_dDefaultFilterParam, optFilterMethodName.mb_str(wxConvUTF8),
2964 m_iDefaultZeropad, optFilterGenerationName.mb_str(wxConvUTF8),
2965 optInterpName.mb_str(wxConvUTF8), m_iDefaultInterpParam,
2966 optBackprojectName.mb_str(wxConvUTF8),
2967 wxConvUTF8.cMB2WX(os.str().c_str()), &defaultROI, bRebinToParallel);
2968 if (pReconstructor->Create() != wxTHREAD_NO_ERROR) {
2969 sys_error (ERR_SEVERE, "Error creating reconstructor thread");
2970 delete pReconstructor;
2973 pReconstructor->SetPriority (60);
2974 pReconstructor->Run();
2979 pImageFile = new ImageFile (m_iDefaultNX, m_iDefaultNY);
2980 wxProgressDialog dlgProgress (_T("Reconstruction"), _T("Reconstruction Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT );
2981 Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.mb_str(wxConvUTF8),
2982 m_dDefaultFilterParam, optFilterMethodName.mb_str(wxConvUTF8), m_iDefaultZeropad, optFilterGenerationName.mb_str(wxConvUTF8),
2983 optInterpName.mb_str(wxConvUTF8), m_iDefaultInterpParam, optBackprojectName.mb_str(wxConvUTF8), m_iDefaultTrace,
2984 &defaultROI, bRebinToParallel);
2986 for (int iView = 0; iView < rProj.nView(); iView++) {
2987 pReconstructor->reconstructView (iView, 1);
2988 if ((iView + 1) % ITER_PER_UPDATE == 0)
2989 if (! dlgProgress.Update (iView + 1)) {
2990 delete pReconstructor;
2991 return; // don't make new window, thread will do this
2994 pReconstructor->postProcessing();
2995 delete pReconstructor;
2998 ImageFileDocument* pReconDoc = theApp->newImageDoc();
3000 sys_error (ERR_SEVERE, "Unable to create image file");
3003 *theApp->getLog() << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("\n");
3004 pImageFile->labelAdd (rProj.getLabel());
3005 pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd());
3007 pReconDoc->setImageFile (pImageFile);
3008 if (theApp->getAskDeleteNewDocs())
3009 pReconDoc->Modify (true);
3010 pReconDoc->UpdateAllViews();
3011 pReconDoc->getView()->setInitialClientSize();
3012 pReconDoc->Activate();
3017 ProjectionFileView::OnArtifactReduction (wxCommandEvent& event)
3022 ProjectionFileCanvas*
3023 ProjectionFileView::CreateCanvas (wxFrame *parent)
3025 ProjectionFileCanvas* pCanvas;
3027 parent->GetClientSize(&width, &height);
3029 pCanvas = new ProjectionFileCanvas (this, parent, wxPoint(-1,-1), wxSize(width, height), 0);
3031 pCanvas->SetScrollbars(20, 20, 50, 50);
3032 pCanvas->SetBackgroundColour(*wxWHITE);
3033 pCanvas->ClearBackground();
3043 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
3046 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, _T("Projection Frame"), wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
3048 wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, _T("Projection Frame"), wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
3050 theApp->setIconForFrame (subframe);
3052 m_pFileMenu = new wxMenu;
3054 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, _T("Cr&eate Phantom...\tCtrl-P"));
3055 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, _T("Create &Filter...\tCtrl-F"));
3056 m_pFileMenu->Append(wxID_OPEN, _T("&Open...\tCtrl-O"));
3057 m_pFileMenu->Append(wxID_SAVE, _T("&Save\tCtrl-S"));
3058 m_pFileMenu->Append(wxID_SAVEAS, _T("Save &As..."));
3059 m_pFileMenu->Append(wxID_CLOSE, _T("&Close\tCtrl-W"));
3061 m_pFileMenu->AppendSeparator();
3062 m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, _T("P&roperties\tCtrl-I"));
3064 m_pFileMenu->AppendSeparator();
3065 m_pFileMenu->Append(wxID_PRINT, _T("&Print..."));
3066 m_pFileMenu->Append(wxID_PRINT_SETUP, _T("Print &Setup..."));
3067 m_pFileMenu->Append(wxID_PREVIEW, _T("Print Pre&view"));
3068 m_pFileMenu->AppendSeparator();
3069 m_pFileMenu->Append(MAINMENU_IMPORT, _T("&Import...\tCtrl-M"));
3070 m_pFileMenu->AppendSeparator();
3071 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, _T("Prefere&nces..."));
3072 m_pFileMenu->Append(MAINMENU_FILE_EXIT, _T("E&xit"));
3073 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3074 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3076 m_pConvertMenu = new wxMenu;
3077 m_pConvertMenu->Append (PJMENU_CONVERT_RECTANGULAR, _T("&Rectangular Image"));
3078 m_pConvertMenu->Append (PJMENU_CONVERT_POLAR, _T("&Polar Image...\tCtrl-L"));
3079 m_pConvertMenu->Append (PJMENU_CONVERT_FFT_POLAR, _T("FF&T->Polar Image...\tCtrl-T"));
3080 m_pConvertMenu->AppendSeparator();
3081 m_pConvertMenu->Append (PJMENU_CONVERT_PARALLEL, _T("&Interpolate to Parallel"));
3083 // wxMenu* filter_menu = new wxMenu;
3084 // filter_menu->Append (PJMENU_ARTIFACT_REDUCTION, _T("&Artifact Reduction"));
3086 wxMenu* analyze_menu = new wxMenu;
3087 analyze_menu->Append (PJMENU_PLOT_HISTOGRAM, _T("&Plot Histogram"));
3088 analyze_menu->Append (PJMENU_PLOT_TTHETA_SAMPLING, _T("Plot T-T&heta Sampling...\tCtrl-H"));
3090 m_pReconstructMenu = new wxMenu;
3091 m_pReconstructMenu->Append (PJMENU_RECONSTRUCT_FBP, _T("&Filtered Backprojection...\tCtrl-R"), _T("Reconstruct image using filtered backprojection"));
3092 m_pReconstructMenu->Append (PJMENU_RECONSTRUCT_FBP_REBIN, _T("Filtered &Backprojection (Rebin to Parallel)...\tCtrl-B"), _T("Reconstruct image using filtered backprojection"));
3093 m_pReconstructMenu->Append (PJMENU_RECONSTRUCT_FOURIER, _T("&Inverse Fourier...\tCtrl-E"), _T("Direct inverse Fourier"));
3095 wxMenu *help_menu = new wxMenu;
3096 help_menu->Append(MAINMENU_HELP_CONTENTS, _T("&Contents\tF1"));
3097 help_menu->Append (MAINMENU_HELP_TIPS, _T("&Tips"));
3098 help_menu->Append (IDH_QUICKSTART, _T("&Quick Start"));
3099 help_menu->Append(MAINMENU_HELP_ABOUT, _T("&About"));
3101 wxMenuBar *menu_bar = new wxMenuBar;
3103 menu_bar->Append (m_pFileMenu, _T("&File"));
3104 menu_bar->Append (m_pConvertMenu, _T("&Convert"));
3105 // menu_bar->Append (filter_menu, _T("Fi<er"));
3106 menu_bar->Append (analyze_menu, _T("&Analyze"));
3107 menu_bar->Append (m_pReconstructMenu, _T("&Reconstruct"));
3108 menu_bar->Append (help_menu, _T("&Help"));
3110 subframe->SetMenuBar(menu_bar);
3111 subframe->Centre(wxBOTH);
3113 wxAcceleratorEntry accelEntries[7];
3114 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('L'), PJMENU_CONVERT_POLAR);
3115 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('T'), PJMENU_CONVERT_FFT_POLAR);
3116 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('R'), PJMENU_RECONSTRUCT_FBP);
3117 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('B'), PJMENU_RECONSTRUCT_FBP_REBIN);
3118 accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('E'), PJMENU_RECONSTRUCT_FOURIER);
3119 accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('I'), PJMENU_FILE_PROPERTIES);
3120 accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('H'), PJMENU_PLOT_TTHETA_SAMPLING);
3121 wxAcceleratorTable accelTable (7, accelEntries);
3122 subframe->SetAcceleratorTable (accelTable);
3129 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
3131 m_pFrame = CreateChildFrame(doc, this);
3133 m_pCanvas = CreateCanvas (m_pFrame);
3134 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
3135 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
3136 m_pFrame->SetTitle (doc->GetFilename());
3138 m_pFrame->Show(true);
3145 ProjectionFileView::OnDraw (wxDC* dc)
3147 if (m_pBitmap && m_pBitmap->Ok())
3148 dc->DrawBitmap (*m_pBitmap, 0, 0, false);
3153 ProjectionFileView::setInitialClientSize ()
3155 if (m_pFrame && m_pCanvas) {
3156 wxSize bestSize = m_pCanvas->GetBestSize();
3158 m_pFrame->SetClientSize (bestSize);
3159 m_pFrame->Show (true);
3160 m_pFrame->SetFocus();
3165 ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3167 const Projections& rProj = GetDocument()->getProjections();
3168 const int nDet = rProj.nDet();
3169 const int nView = rProj.nView();
3170 if (rProj.geometry() == Scanner::GEOMETRY_PARALLEL) {
3171 m_pReconstructMenu->Enable (PJMENU_RECONSTRUCT_FBP_REBIN, false);
3172 m_pConvertMenu->Enable (PJMENU_CONVERT_PARALLEL, false);
3174 m_pReconstructMenu->Enable (PJMENU_RECONSTRUCT_FBP_REBIN, true);
3175 m_pConvertMenu->Enable (PJMENU_CONVERT_PARALLEL, true);
3178 if (nDet != 0 && nView != 0) {
3179 const DetectorArray& detarray = rProj.getDetectorArray(0);
3180 const DetectorValue* detval = detarray.detValues();
3181 double min = detval[0];
3182 double max = detval[0];
3183 for (int iy = 0; iy < nView; iy++) {
3184 const DetectorArray& detarray = rProj.getDetectorArray(iy);
3185 const DetectorValue* detval = detarray.detValues();
3186 for (int ix = 0; ix < nDet; ix++) {
3187 if (min > detval[ix])
3189 else if (max < detval[ix])
3194 unsigned char* imageData = new unsigned char [nDet * nView * 3];
3196 sys_error (ERR_SEVERE, "Unable to allocate memory for image display");
3199 double scale = (max - min) / 255;
3200 for (int iy2 = 0; iy2 < nView; iy2++) {
3201 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
3202 const DetectorValue* detval = detarray.detValues();
3203 for (int ix = 0; ix < nDet; ix++) {
3204 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
3205 intensity = clamp(intensity, 0, 255);
3206 int baseAddr = (iy2 * nDet + ix) * 3;
3207 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
3210 wxImage image (nDet, nView, imageData, true);
3215 m_pBitmap = new wxBitmap (image);
3219 m_pCanvas->SetScrollbars(20, 20, nDet/20, nView/20);
3220 m_pCanvas->SetBackgroundColour(*wxWHITE);
3223 m_pCanvas->Refresh();
3227 ProjectionFileView::OnClose (bool deleteWindow)
3229 //GetDocumentManager()->ActivateView (this, false);
3230 if (! GetDocument() || ! GetDocument()->Close())
3235 m_pCanvas->setView(NULL);
3238 wxString s(wxTheApp->GetAppName());
3240 m_pFrame->SetTitle(s);
3247 if (GetDocument() && GetDocument()->getBadFileOpen())
3248 ::wxYield(); // wxWindows bug workaround
3257 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame,
3258 const wxPoint& pos, const wxSize& size,
3260 : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v)
3264 PlotFileCanvas::~PlotFileCanvas ()
3269 PlotFileCanvas::GetBestSize() const
3271 return wxSize (500, 300);
3276 PlotFileCanvas::OnDraw(wxDC& dc)
3279 m_pView->OnDraw(& dc);
3285 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
3287 BEGIN_EVENT_TABLE(PlotFileView, wxView)
3288 EVT_MENU(PLOTMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
3289 EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
3290 EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
3291 EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
3294 PlotFileView::PlotFileView()
3295 : wxView(), m_pFrame(0), m_pCanvas(0), m_pEZPlot(0), m_pFileMenu(0),
3296 m_bMinSpecified(false), m_bMaxSpecified(false)
3300 PlotFileView::~PlotFileView()
3305 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
3306 GetDocumentManager()->ActivateView(this, FALSE);
3310 PlotFileView::OnProperties (wxCommandEvent& event)
3312 const PlotFile& rPlot = GetDocument()->getPlotFile();
3313 std::ostringstream os;
3314 os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
3315 rPlot.printHeadersBrief (os);
3316 *theApp->getLog() << _T(">>>>\n") << wxConvUTF8.cMB2WX(os.str().c_str()) << _T("<<<<<\n");
3317 wxMessageDialog dialogMsg (getFrameForChild(), wxConvUTF8.cMB2WX(os.str().c_str()), _T("Plot File Properties"),
3318 wxOK | wxICON_INFORMATION);
3319 dialogMsg.ShowModal();
3320 GetDocument()->Activate();
3325 PlotFileView::OnScaleAuto (wxCommandEvent& event)
3327 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3328 double min, max, mean, mode, median, stddev;
3329 rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
3330 DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
3331 int iRetVal = dialogAutoScale.ShowModal();
3332 if (iRetVal == wxID_OK) {
3333 m_bMinSpecified = true;
3334 m_bMaxSpecified = true;
3336 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
3339 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
3340 OnUpdate (this, NULL);
3343 GetDocument()->Activate();
3347 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
3349 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3352 if (! m_bMinSpecified || ! m_bMaxSpecified) {
3353 if (! rPlotFile.getMinMax (1, min, max)) {
3354 *theApp->getLog() << _T("Error: unable to find Min/Max\n");
3359 if (m_bMinSpecified)
3361 if (m_bMaxSpecified)
3364 DialogGetMinMax dialogMinMax (getFrameForChild(), _T("Set Y-axis Minimum & Maximum"), min, max);
3365 int retVal = dialogMinMax.ShowModal();
3366 if (retVal == wxID_OK) {
3367 m_bMinSpecified = true;
3368 m_bMaxSpecified = true;
3369 m_dMinPixel = dialogMinMax.getMinimum();
3370 m_dMaxPixel = dialogMinMax.getMaximum();
3371 OnUpdate (this, NULL);
3373 GetDocument()->Activate();
3377 PlotFileView::OnScaleFull (wxCommandEvent& event)
3379 m_bMinSpecified = false;
3380 m_bMaxSpecified = false;
3381 OnUpdate (this, NULL);
3382 GetDocument()->Activate();
3387 PlotFileView::CreateCanvas (wxFrame* parent)
3389 PlotFileCanvas* pCanvas;
3391 pCanvas = new PlotFileCanvas (this, parent, wxPoint(-1,-1), wxSize(-1,-1),
3392 wxFULL_REPAINT_ON_RESIZE);
3393 pCanvas->SetBackgroundColour(*wxWHITE);
3394 pCanvas->ClearBackground();
3404 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
3407 wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, _T("Plot Frame"), wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
3409 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, _T("Plot Frame"), wxPoint(-1,-1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE);
3411 theApp->setIconForFrame (subframe);
3413 m_pFileMenu = new wxMenu;
3415 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, _T("Cr&eate Phantom...\tCtrl-P"));
3416 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, _T("Create &Filter...\tCtrl-F"));
3417 m_pFileMenu->Append(wxID_OPEN, _T("&Open...\tCtrl-O"));
3418 m_pFileMenu->Append(wxID_SAVE, _T("&Save\tCtrl-S"));
3419 m_pFileMenu->Append(wxID_SAVEAS, _T("Save &As..."));
3420 m_pFileMenu->Append(wxID_CLOSE, _T("&Close\tCtrl-W"));
3422 m_pFileMenu->AppendSeparator();
3423 m_pFileMenu->Append(PLOTMENU_FILE_PROPERTIES, _T("P&roperties\tCtrl-I"));
3425 m_pFileMenu->AppendSeparator();
3426 m_pFileMenu->Append(wxID_PRINT, _T("&Print..."));
3427 m_pFileMenu->Append(wxID_PRINT_SETUP, _T("Print &Setup..."));
3428 m_pFileMenu->Append(wxID_PREVIEW, _T("Print Pre&view"));
3429 m_pFileMenu->AppendSeparator();
3430 m_pFileMenu->Append(MAINMENU_IMPORT, _T("&Import...\tCtrl-M"));
3431 m_pFileMenu->AppendSeparator();
3432 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, _T("Prefere&nces..."));
3433 m_pFileMenu->Append(MAINMENU_FILE_EXIT, _T("E&xit"));
3434 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3435 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3437 wxMenu *view_menu = new wxMenu;
3438 view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, _T("Display Scale &Set...\tCtrl-E"));
3439 view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, _T("Display Scale &Auto...\tCtrl-A"));
3440 view_menu->Append(PLOTMENU_VIEW_SCALE_FULL, _T("Display &Full Scale\tCtrl-U"));
3442 wxMenu *help_menu = new wxMenu;
3443 help_menu->Append(MAINMENU_HELP_CONTENTS, _T("&Contents\tF1"));
3444 help_menu->Append (MAINMENU_HELP_TIPS, _T("&Tips"));
3445 help_menu->Append (IDH_QUICKSTART, _T("&Quick Start"));
3446 help_menu->Append(MAINMENU_HELP_ABOUT, _T("&About"));
3448 wxMenuBar *menu_bar = new wxMenuBar;
3450 menu_bar->Append(m_pFileMenu, _T("&File"));
3451 menu_bar->Append(view_menu, _T("&View"));
3452 menu_bar->Append(help_menu, _T("&Help"));
3454 subframe->SetMenuBar(menu_bar);
3455 subframe->Centre(wxBOTH);
3457 wxAcceleratorEntry accelEntries[4];
3458 accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('E'), PLOTMENU_VIEW_SCALE_MINMAX);
3459 accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('A'), PLOTMENU_VIEW_SCALE_AUTO);
3460 accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('U'), PLOTMENU_VIEW_SCALE_FULL);
3461 accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('I'), PLOTMENU_FILE_PROPERTIES);
3462 wxAcceleratorTable accelTable (4, accelEntries);
3463 subframe->SetAcceleratorTable (accelTable);
3470 PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
3472 m_bMinSpecified = false;
3473 m_bMaxSpecified = false;
3474 m_dAutoScaleFactor = 1.;
3476 m_pFrame = CreateChildFrame(doc, this);
3478 m_pCanvas = CreateCanvas (m_pFrame);
3479 m_pFrame->SetClientSize (m_pCanvas->GetBestSize());
3480 m_pCanvas->SetClientSize (m_pCanvas->GetBestSize());
3481 m_pFrame->SetTitle (_T("test"));
3482 *theApp->getLog() << _T("Plot doc name: ") << doc->GetDocumentName() << _T("\n");
3483 *theApp->getLog() << _T("Plot file name: ") << doc->GetFilename() << _T("\n");
3484 m_pFrame->SetTitle (doc->GetFilename());
3486 m_pFrame->Show(true);
3493 PlotFileView::setInitialClientSize ()
3495 if (m_pFrame && m_pCanvas) {
3496 wxSize bestSize = m_pCanvas->GetBestSize();
3498 m_pFrame->SetClientSize (bestSize);
3499 m_pFrame->Show (true);
3500 m_pFrame->SetFocus();
3506 PlotFileView::OnDraw (wxDC* dc)
3508 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3509 const int iNColumns = rPlotFile.getNumColumns();
3510 const int iNRecords = rPlotFile.getNumRecords();
3512 if (iNColumns > 0 && iNRecords > 0) {
3514 m_pCanvas->GetClientSize (&xsize, &ysize);
3515 SGPDriver driver (dc, xsize, ysize);
3518 m_pEZPlot->plot (&sgp);
3524 PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3526 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
3527 const int iNColumns = rPlotFile.getNumColumns();
3528 const int iNRecords = rPlotFile.getNumRecords();
3529 const bool bScatterPlot = rPlotFile.getIsScatterPlot();
3531 if (iNColumns > 0 && iNRecords > 0) {
3534 m_pEZPlot = new EZPlot;
3536 for (unsigned int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)
3537 m_pEZPlot->ezset (rPlotFile.getEzsetCommand (iEzset));
3539 if (m_bMinSpecified) {
3540 std::ostringstream os;
3541 os << "ymin " << m_dMinPixel;
3542 m_pEZPlot->ezset (os.str());
3545 if (m_bMaxSpecified) {
3546 std::ostringstream os;
3547 os << "ymax " << m_dMaxPixel;
3548 m_pEZPlot->ezset (os.str());
3551 m_pEZPlot->ezset("box");
3552 m_pEZPlot->ezset("grid");
3554 double* pdX = new double [iNRecords];
3555 double* pdY = new double [iNRecords];
3556 if (! bScatterPlot) {
3557 rPlotFile.getColumn (0, pdX);
3559 for (int iCol = 1; iCol < iNColumns; iCol++) {
3560 rPlotFile.getColumn (iCol, pdY);
3561 m_pEZPlot->addCurve (pdX, pdY, iNRecords);
3564 rPlotFile.getColumn (0, pdX);
3565 rPlotFile.getColumn (1, pdY);
3566 m_pEZPlot->addCurve (pdX, pdY, iNRecords);
3573 m_pCanvas->Refresh();
3578 PlotFileView::OnClose (bool deleteWindow)
3580 if (! GetDocument() || ! GetDocument()->Close())
3585 m_pCanvas->setView (NULL);
3588 wxString s(wxTheApp->GetAppName());
3590 m_pFrame->SetTitle(s);
3596 if (GetDocument() && GetDocument()->getBadFileOpen())
3597 ::wxYield(); // wxWindows bug workaround
3604 ////////////////////////////////////////////////////////////////
3607 IMPLEMENT_DYNAMIC_CLASS(TextFileView, wxView)
3609 TextFileView::~TextFileView()
3611 GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
3612 GetDocumentManager()->ActivateView(this, FALSE);;
3615 bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
3617 m_pFrame = CreateChildFrame(doc, this);
3618 SetFrame (m_pFrame);
3621 m_pFrame->GetClientSize(&width, &height);
3622 m_pFrame->SetTitle(doc->GetFilename());
3623 m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(-1,-1), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
3625 m_pFrame->Show (true);
3631 // Handled by wxTextWindow
3632 void TextFileView::OnDraw(wxDC *WXUNUSED(dc) )
3636 void TextFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
3641 TextFileView::OnClose (bool deleteWindow)
3643 if (! theApp->getMainFrame()->getShuttingDown())
3647 //GetDocumentManager()->ActivateView (this, false);
3648 if (! GetDocument() || ! GetDocument()->Close())
3655 if (GetDocument() && GetDocument()->getBadFileOpen())
3656 ::wxYield(); // wxWindows bug workaround
3667 TextFileView::CreateChildFrame (wxDocument *doc, wxView *view)
3670 wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, _T("TextFile Frame"), wxPoint(-1, -1), wxSize(-1,-1), wxDEFAULT_FRAME_STYLE, _T("Log"));
3672 wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, _T("TextFile Frame"), wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE, _T("Log"));
3674 theApp->setIconForFrame (subframe);
3676 m_pFileMenu = new wxMenu;
3678 m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, _T("Cr&eate Phantom...\tCtrl-P"));
3679 m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, _T("Create &Filter...\tCtrl-F"));
3680 m_pFileMenu->Append(wxID_OPEN, _T("&Open...\tCtrl-O"));
3681 m_pFileMenu->Append(wxID_SAVE, _T("&Save\tCtrl-S"));
3682 m_pFileMenu->Append(wxID_SAVEAS, _T("Save &As..."));
3683 // m_pFileMenu->Append(wxID_CLOSE, _T("&Close\tCtrl-W"));
3685 m_pFileMenu->AppendSeparator();
3686 m_pFileMenu->Append(wxID_PRINT, _T("&Print..."));
3687 m_pFileMenu->Append(wxID_PRINT_SETUP, _T("Print &Setup..."));
3688 m_pFileMenu->Append(wxID_PREVIEW, _T("Print Pre&view"));
3689 m_pFileMenu->AppendSeparator();
3690 m_pFileMenu->Append(MAINMENU_IMPORT, _T("&Import...\tCtrl-M"));
3691 m_pFileMenu->AppendSeparator();
3692 m_pFileMenu->Append (MAINMENU_FILE_PREFERENCES, _T("Prefere&nces..."));
3693 m_pFileMenu->Append(MAINMENU_FILE_EXIT, _T("E&xit"));
3694 GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3695 GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3697 wxMenu *help_menu = new wxMenu;
3698 help_menu->Append(MAINMENU_HELP_CONTENTS, _T("&Contents\tF1"));
3699 help_menu->Append (MAINMENU_HELP_TIPS, _T("&Tips"));
3700 help_menu->Append (IDH_QUICKSTART, _T("&Quick Start"));
3701 help_menu->Append(MAINMENU_HELP_ABOUT, _T("&About"));
3703 wxMenuBar *menu_bar = new wxMenuBar;
3705 menu_bar->Append(m_pFileMenu, _T("&File"));
3706 menu_bar->Append(help_menu, _T("&Help"));
3708 subframe->SetMenuBar(menu_bar);
3709 subframe->Centre(wxBOTH);
3715 // Define a constructor for my text subwindow
3716 TextFileCanvas::TextFileCanvas (TextFileView* v, wxFrame* frame, const wxPoint& pos, const wxSize& size, long style)
3717 : wxTextCtrl (frame, -1, _T(""), pos, size, style), m_pView(v)
3721 TextFileCanvas::~TextFileCanvas ()
3727 TextFileCanvas::GetBestSize() const
3730 theApp->getMainFrame()->GetClientSize (&xSize, &ySize);
3731 xSize = maxValue<int> (xSize, ySize);
3733 ySize = xSize = (xSize / 4);
3737 return wxSize (xSize, ySize);