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-2000 Kevin Rosenberg
12 ** $Id: views.cpp,v 1.49 2001/01/02 15:58:18 kevin Exp $
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
28 // For compilers that support precompilation, includes "wx/wx.h".
29 #include "wx/wxprec.h"
39 #if !wxUSE_DOC_VIEW_ARCHITECTURE
40 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
44 #include "wx/progdlg.h"
51 #include "dlgprojections.h"
52 #include "dlgreconstruct.h"
53 #include "backprojectors.h"
54 #include "reconstruct.h"
57 #if defined(MSVC) || HAVE_SSTREAM
60 #include <sstream_subst>
66 BEGIN_EVENT_TABLE(ImageFileCanvas, wxScrolledWindow)
67 EVT_MOUSE_EVENTS(ImageFileCanvas::OnMouseEvent)
71 ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
72 : wxScrolledWindow(frame, -1, pos, size, style)
80 ImageFileCanvas::OnDraw(wxDC& dc)
83 m_pView->OnDraw(& dc);
87 ImageFileCanvas::DrawRubberBandCursor (wxDC& dc, int x, int y)
89 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
94 dc.SetLogicalFunction (wxINVERT);
95 dc.SetPen (*wxGREEN_PEN);
96 dc.DrawLine (0, yPt, nx, yPt);
97 dc.DrawLine (x, 0, x, ny);
98 dc.SetLogicalFunction (wxCOPY);
102 ImageFileCanvas::GetCurrentCursor (int& x, int& y)
107 if (m_xCursor >= 0 && m_yCursor >= 0)
114 ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
122 wxPoint pt(event.GetLogicalPosition(dc));
124 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
125 ImageFileArrayConst v = rIF.getArray();
128 const int yPt = ny - 1 - pt.y;
129 if (event.RightIsDown()) {
130 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
131 std::ostringstream os;
132 os << "Image value (" << pt.x << "," << yPt << ") = " << v[pt.x][yPt];
133 if (rIF.isComplex()) {
134 double dImag = rIF.getImaginaryArray()[pt.x][yPt];
136 os << " - " << -dImag;
138 os << " + " << dImag;
142 *theApp->getLog() << os.str().c_str();
144 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
146 else if (event.LeftIsDown() || event.LeftUp() || event.RightUp()) {
147 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
148 if (m_xCursor >= 0 && m_yCursor >= 0) {
149 DrawRubberBandCursor (dc, m_xCursor, m_yCursor);
151 DrawRubberBandCursor (dc, pt.x, yPt);
155 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
157 if (event.LeftUp()) {
158 std::ostringstream os;
159 os << "Selected column " << pt.x << " , row " << yPt << "\n";
160 *theApp->getLog() << os.str().c_str();
166 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
168 BEGIN_EVENT_TABLE(ImageFileView, wxView)
169 EVT_MENU(IFMENU_FILE_EXPORT, ImageFileView::OnExport)
170 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
171 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
172 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
173 EVT_MENU(IFMENU_COMPARE_IMAGES, ImageFileView::OnCompare)
174 EVT_MENU(IFMENU_COMPARE_ROW, ImageFileView::OnCompareRow)
175 EVT_MENU(IFMENU_COMPARE_COL, ImageFileView::OnCompareCol)
176 EVT_MENU(IFMENU_FILTER_INVERTVALUES, ImageFileView::OnInvertValues)
177 EVT_MENU(IFMENU_FILTER_SQUARE, ImageFileView::OnSquare)
178 EVT_MENU(IFMENU_FILTER_SQRT, ImageFileView::OnSquareRoot)
179 EVT_MENU(IFMENU_FILTER_LOG, ImageFileView::OnLog)
180 EVT_MENU(IFMENU_FILTER_EXP, ImageFileView::OnExp)
181 EVT_MENU(IFMENU_FILTER_FOURIER, ImageFileView::OnFourier)
182 EVT_MENU(IFMENU_FILTER_INVERSE_FOURIER, ImageFileView::OnInverseFourier)
183 EVT_MENU(IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, ImageFileView::OnShuffleFourierToNaturalOrder)
184 EVT_MENU(IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, ImageFileView::OnShuffleNaturalToFourierOrder)
185 EVT_MENU(IFMENU_IMAGE_ADD, ImageFileView::OnAdd)
186 EVT_MENU(IFMENU_IMAGE_SUBTRACT, ImageFileView::OnSubtract)
187 EVT_MENU(IFMENU_IMAGE_MULTIPLY, ImageFileView::OnMultiply)
188 EVT_MENU(IFMENU_IMAGE_DIVIDE, ImageFileView::OnDivide)
189 EVT_MENU(IFMENU_IMAGE_SCALESIZE, ImageFileView::OnScaleSize)
191 EVT_MENU(IFMENU_FILTER_FFT, ImageFileView::OnFFT)
192 EVT_MENU(IFMENU_FILTER_IFFT, ImageFileView::OnIFFT)
194 EVT_MENU(IFMENU_FILTER_MAGNITUDE, ImageFileView::OnMagnitude)
195 EVT_MENU(IFMENU_FILTER_PHASE, ImageFileView::OnPhase)
196 EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)
197 EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol)
198 EVT_MENU(IFMENU_PLOT_HISTOGRAM, ImageFileView::OnPlotHistogram)
201 ImageFileView::ImageFileView(void)
202 : wxView(), m_canvas(NULL), m_frame(NULL), m_bMinSpecified(false), m_bMaxSpecified(false)
204 m_iDefaultExportFormatID = ImageFile::FORMAT_PNG;
207 ImageFileView::~ImageFileView(void)
212 ImageFileView::OnProperties (wxCommandEvent& event)
214 const ImageFile& rIF = GetDocument()->getImageFile();
215 if (rIF.nx() == 0 || rIF.ny() == 0)
216 *theApp->getLog() << "Properties: empty imagefile\n";
218 const std::string& rFilename = rIF.getFilename();
219 std::ostringstream os;
220 double min, max, mean, mode, median, stddev;
221 rIF.statistics (rIF.getArray(), min, max, mean, mode, median, stddev);
222 os << "Filename: " << rFilename << "\n";
223 os << "Size: (" << rIF.nx() << "," << rIF.ny() << ")\n";
229 os << "\nMinimum: "<<min<<"\nMaximum: "<<max<<"\nMean: "<<mean<<"\nMedian: "<<median<<"\nMode: "<<mode<<"\nStandard Deviation: "<<stddev << "\n";
230 if (rIF.isComplex()) {
231 rIF.statistics (rIF.getImaginaryArray(), min, max, mean, mode, median, stddev);
232 os << "\nImaginary: min: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
234 if (rIF.nLabels() > 0) {
236 rIF.printLabelsBrief (os);
238 *theApp->getLog() << os.str().c_str();
239 wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
240 dialogMsg.ShowModal();
245 ImageFileView::OnScaleAuto (wxCommandEvent& event)
247 const ImageFile& rIF = GetDocument()->getImageFile();
248 double min, max, mean, mode, median, stddev;
249 rIF.statistics(min, max, mean, mode, median, stddev);
250 DialogAutoScaleParameters dialogAutoScale (m_frame, mean, mode, median, stddev, m_dAutoScaleFactor);
251 int iRetVal = dialogAutoScale.ShowModal();
252 if (iRetVal == wxID_OK) {
253 m_bMinSpecified = true;
254 m_bMaxSpecified = true;
256 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
259 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
260 OnUpdate (this, NULL);
266 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
268 const ImageFile& rIF = GetDocument()->getImageFile();
270 if (! m_bMinSpecified && ! m_bMaxSpecified)
271 rIF.getMinMax (min, max);
278 DialogGetMinMax dialogMinMax (m_frame, "Set Image Minimum & Maximum", min, max);
279 int retVal = dialogMinMax.ShowModal();
280 if (retVal == wxID_OK) {
281 m_bMinSpecified = true;
282 m_bMaxSpecified = true;
283 m_dMinPixel = dialogMinMax.getMinimum();
284 m_dMaxPixel = dialogMinMax.getMaximum();
285 OnUpdate (this, NULL);
290 ImageFileView::OnCompare (wxCommandEvent& event)
292 std::vector<ImageFileDocument*> vecIF;
293 theApp->getCompatibleImages (GetDocument(), vecIF);
295 if (vecIF.size() == 0) {
296 wxMessageBox("There are no compatible image files open for comparision", "No comparison images");
298 DialogGetComparisonImage dialogGetCompare(m_frame, "Get Comparison Image", vecIF, true);
300 if (dialogGetCompare.ShowModal() == wxID_OK) {
301 const ImageFile& rIF = GetDocument()->getImageFile();
302 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
303 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
304 std::ostringstream os;
305 double min, max, mean, mode, median, stddev;
306 rIF.statistics (min, max, mean, mode, median, stddev);
307 os << rIF.getFilename() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
308 rCompareIF.statistics (min, max, mean, mode, median, stddev);
309 os << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
312 rIF.comparativeStatistics (rCompareIF, d, r, e);
313 os << "Comparative Statistics: d=" << d << ", r=" << r << ", e=" << e << "\n";
314 *theApp->getLog() << os.str().c_str();
315 if (dialogGetCompare.getMakeDifferenceImage()) {
316 ImageFileDocument* pDifferenceDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
317 if (! pDifferenceDoc) {
318 sys_error (ERR_SEVERE, "Unable to create image file");
321 ImageFile& differenceImage = pDifferenceDoc->getImageFile();
323 differenceImage.setArraySize (rIF.nx(), rIF.ny());
324 if (! rIF.subtractImages (rCompareIF, differenceImage)) {
325 pDifferenceDoc->DeleteAllViews();
329 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
330 differenceImage.labelsCopy (rIF, s.c_str());
331 s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
332 differenceImage.labelsCopy (rCompareIF, s.c_str());
333 std::ostringstream osLabel;
334 osLabel << "Compare image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str()
335 << " and " << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": "
337 differenceImage.labelAdd (os.str().c_str());
338 if (theApp->getSetModifyNewDocs())
339 pDifferenceDoc->Modify(true);
340 pDifferenceDoc->UpdateAllViews(this);
341 pDifferenceDoc->GetFirstView()->OnUpdate (this, NULL);
343 wxMessageBox(os.str().c_str(), "Image Comparison");
349 ImageFileView::OnInvertValues (wxCommandEvent& event)
351 ImageFile& rIF = GetDocument()->getImageFile();
352 rIF.invertPixelValues (rIF);
353 rIF.labelAdd ("Invert Pixel Values");
354 if (theApp->getSetModifyNewDocs())
355 GetDocument()->Modify(TRUE);
356 GetDocument()->UpdateAllViews(this);
360 ImageFileView::OnSquare (wxCommandEvent& event)
362 ImageFile& rIF = GetDocument()->getImageFile();
364 rIF.labelAdd ("Square Pixel Values");
365 if (theApp->getSetModifyNewDocs())
366 GetDocument()->Modify(TRUE);
367 GetDocument()->UpdateAllViews(this);
371 ImageFileView::OnSquareRoot (wxCommandEvent& event)
373 ImageFile& rIF = GetDocument()->getImageFile();
375 rIF.labelAdd ("Square-root Pixel Values");
376 if (theApp->getSetModifyNewDocs())
377 GetDocument()->Modify(TRUE);
378 GetDocument()->UpdateAllViews(this);
382 ImageFileView::OnLog (wxCommandEvent& event)
384 ImageFile& rIF = GetDocument()->getImageFile();
386 rIF.labelAdd ("Logrithm base-e Pixel Values");
387 if (theApp->getSetModifyNewDocs())
388 GetDocument()->Modify(TRUE);
389 GetDocument()->UpdateAllViews(this);
393 ImageFileView::OnExp (wxCommandEvent& event)
395 ImageFile& rIF = GetDocument()->getImageFile();
397 rIF.labelAdd ("Exponent base-e Pixel Values");
398 if (theApp->getSetModifyNewDocs())
399 GetDocument()->Modify(TRUE);
400 GetDocument()->UpdateAllViews(this);
404 ImageFileView::OnAdd (wxCommandEvent& event)
406 std::vector<ImageFileDocument*> vecIF;
407 theApp->getCompatibleImages (GetDocument(), vecIF);
409 if (vecIF.size() == 0) {
410 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
412 DialogGetComparisonImage dialogGetCompare (m_frame, "Get Image to Add", vecIF, false);
414 if (dialogGetCompare.ShowModal() == wxID_OK) {
415 ImageFile& rIF = GetDocument()->getImageFile();
416 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
417 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
418 ImageFileDocument* pNewDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
420 sys_error (ERR_SEVERE, "Unable to create image file");
423 ImageFile& newImage = pNewDoc->getImageFile();
424 newImage.setArraySize (rIF.nx(), rIF.ny());
425 rIF.addImages (rRHSIF, newImage);
426 std::ostringstream os;
427 os << "Add image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
428 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
429 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
430 newImage.labelsCopy (rIF, s.c_str());
431 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
432 newImage.labelsCopy (rRHSIF, s.c_str());
433 newImage.labelAdd (os.str().c_str());
434 *theApp->getLog() << os.str().c_str() << "\n";
435 if (theApp->getSetModifyNewDocs())
436 pNewDoc->Modify(TRUE);
437 pNewDoc->UpdateAllViews(this);
438 pNewDoc->GetFirstView()->OnUpdate (this, NULL);
444 ImageFileView::OnSubtract (wxCommandEvent& event)
446 std::vector<ImageFileDocument*> vecIF;
447 theApp->getCompatibleImages (GetDocument(), vecIF);
449 if (vecIF.size() == 0) {
450 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
452 DialogGetComparisonImage dialogGetCompare (m_frame, "Get Image to Subtract", vecIF, false);
454 if (dialogGetCompare.ShowModal() == wxID_OK) {
455 ImageFile& rIF = GetDocument()->getImageFile();
456 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
457 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
458 ImageFileDocument* pNewDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
460 sys_error (ERR_SEVERE, "Unable to create image file");
463 ImageFile& newImage = pNewDoc->getImageFile();
464 newImage.setArraySize (rIF.nx(), rIF.ny());
465 rIF.subtractImages (rRHSIF, newImage);
466 std::ostringstream os;
467 os << "Subtract image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
468 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
469 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
470 newImage.labelsCopy (rIF, s.c_str());
471 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
472 newImage.labelsCopy (rRHSIF, s.c_str());
473 newImage.labelAdd (os.str().c_str());
474 *theApp->getLog() << os.str().c_str() << "\n";
475 if (theApp->getSetModifyNewDocs())
476 pNewDoc->Modify(TRUE);
477 pNewDoc->UpdateAllViews(this);
478 pNewDoc->GetFirstView()->OnUpdate (this, NULL);
484 ImageFileView::OnMultiply (wxCommandEvent& event)
486 std::vector<ImageFileDocument*> vecIF;
487 theApp->getCompatibleImages (GetDocument(), vecIF);
489 if (vecIF.size() == 0) {
490 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
492 DialogGetComparisonImage dialogGetCompare (m_frame, "Get Image to Multiply", vecIF, false);
494 if (dialogGetCompare.ShowModal() == wxID_OK) {
495 ImageFile& rIF = GetDocument()->getImageFile();
496 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
497 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
498 ImageFileDocument* pNewDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
500 sys_error (ERR_SEVERE, "Unable to create image file");
503 ImageFile& newImage = pNewDoc->getImageFile();
504 newImage.setArraySize (rIF.nx(), rIF.ny());
505 rIF.multiplyImages (rRHSIF, newImage);
506 std::ostringstream os;
507 os << "Multiply image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
508 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
509 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
510 newImage.labelsCopy (rIF, s.c_str());
511 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
512 newImage.labelsCopy (rRHSIF, s.c_str());
513 newImage.labelAdd (os.str().c_str());
514 *theApp->getLog() << os.str().c_str() << "\n";
515 if (theApp->getSetModifyNewDocs())
516 pNewDoc->Modify(TRUE);
517 pNewDoc->UpdateAllViews(this);
518 pNewDoc->GetFirstView()->OnUpdate (this, NULL);
524 ImageFileView::OnDivide (wxCommandEvent& event)
526 std::vector<ImageFileDocument*> vecIF;
527 theApp->getCompatibleImages (GetDocument(), vecIF);
529 if (vecIF.size() == 0) {
530 wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
532 DialogGetComparisonImage dialogGetCompare (m_frame, "Get Image to Divide", vecIF, false);
534 if (dialogGetCompare.ShowModal() == wxID_OK) {
535 ImageFile& rIF = GetDocument()->getImageFile();
536 ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
537 const ImageFile& rRHSIF = pRHSDoc->getImageFile();
538 ImageFileDocument* pNewDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
540 sys_error (ERR_SEVERE, "Unable to create image file");
543 ImageFile& newImage = pNewDoc->getImageFile();
544 newImage.setArraySize (rIF.nx(), rIF.ny());
545 rIF.divideImages (rRHSIF, newImage);
546 std::ostringstream os;
547 os << "Divide image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " by "
548 << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
549 wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
550 newImage.labelsCopy (rIF, s.c_str());
551 s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
552 newImage.labelsCopy (rRHSIF, s.c_str());
553 newImage.labelAdd (os.str().c_str());
554 *theApp->getLog() << os.str().c_str() << "\n";
555 if (theApp->getSetModifyNewDocs())
556 pNewDoc->Modify(TRUE);
557 pNewDoc->UpdateAllViews(this);
558 pNewDoc->GetFirstView()->OnUpdate (this, NULL);
566 ImageFileView::OnFFT (wxCommandEvent& event)
568 ImageFile& rIF = GetDocument()->getImageFile();
569 wxProgressDialog dlgProgress (wxString("FFT"), wxString("FFT Progress"), 1, m_frame, wxPD_APP_MODAL);
571 rIF.labelAdd ("FFT Image");
572 m_bMinSpecified = false;
573 m_bMaxSpecified = false;
574 if (theApp->getSetModifyNewDocs())
575 GetDocument()->Modify(TRUE);
576 GetDocument()->UpdateAllViews(this);
580 ImageFileView::OnIFFT (wxCommandEvent& event)
582 ImageFile& rIF = GetDocument()->getImageFile();
583 wxProgressDialog dlgProgress (wxString("IFFT"), wxString("IFFT Progress"), 1, m_frame, wxPD_APP_MODAL);
585 rIF.labelAdd ("IFFT Image");
586 m_bMinSpecified = false;
587 m_bMaxSpecified = false;
588 if (theApp->getSetModifyNewDocs())
589 GetDocument()->Modify(TRUE);
590 GetDocument()->UpdateAllViews(this);
595 ImageFileView::OnFourier (wxCommandEvent& event)
597 ImageFile& rIF = GetDocument()->getImageFile();
598 wxProgressDialog dlgProgress (wxString("Fourier"), wxString("Fourier Progress"), 1, m_frame, wxPD_APP_MODAL);
600 rIF.labelAdd ("Fourier Image");
601 m_bMinSpecified = false;
602 m_bMaxSpecified = false;
603 if (theApp->getSetModifyNewDocs())
604 GetDocument()->Modify(TRUE);
605 GetDocument()->UpdateAllViews(this);
608 ImageFileView::OnInverseFourier (wxCommandEvent& event)
610 ImageFile& rIF = GetDocument()->getImageFile();
611 wxProgressDialog dlgProgress (wxString("Inverse Fourier"), wxString("Inverse Fourier Progress"), 1, m_frame, wxPD_APP_MODAL);
612 rIF.inverseFourier (rIF);
613 rIF.labelAdd ("Inverse Fourier Image");
614 m_bMinSpecified = false;
615 m_bMaxSpecified = false;
616 if (theApp->getSetModifyNewDocs())
617 GetDocument()->Modify(TRUE);
618 GetDocument()->UpdateAllViews(this);
622 ImageFileView::OnShuffleNaturalToFourierOrder (wxCommandEvent& event)
624 ImageFile& rIF = GetDocument()->getImageFile();
625 Fourier::shuffleNaturalToFourierOrder (rIF);
626 rIF.labelAdd ("Shuffle Natural To Fourier Order");
627 m_bMinSpecified = false;
628 m_bMaxSpecified = false;
629 if (theApp->getSetModifyNewDocs())
630 GetDocument()->Modify(TRUE);
631 GetDocument()->UpdateAllViews(this);
635 ImageFileView::OnShuffleFourierToNaturalOrder (wxCommandEvent& event)
637 ImageFile& rIF = GetDocument()->getImageFile();
638 Fourier::shuffleFourierToNaturalOrder (rIF);
639 rIF.labelAdd ("Shuffle Fourier To Natural Order");
640 m_bMinSpecified = false;
641 m_bMaxSpecified = false;
642 if (theApp->getSetModifyNewDocs())
643 GetDocument()->Modify(TRUE);
644 GetDocument()->UpdateAllViews(this);
648 ImageFileView::OnMagnitude (wxCommandEvent& event)
650 ImageFile& rIF = GetDocument()->getImageFile();
651 if (rIF.isComplex()) {
653 rIF.labelAdd ("Magnitude of complex-image");
654 m_bMinSpecified = false;
655 m_bMaxSpecified = false;
656 if (theApp->getSetModifyNewDocs())
657 GetDocument()->Modify(TRUE);
658 GetDocument()->UpdateAllViews(this);
663 ImageFileView::OnPhase (wxCommandEvent& event)
665 ImageFile& rIF = GetDocument()->getImageFile();
666 if (rIF.isComplex()) {
668 rIF.labelAdd ("Phase of complex-image");
669 m_bMinSpecified = false;
670 m_bMaxSpecified = false;
671 if (theApp->getSetModifyNewDocs())
672 GetDocument()->Modify(TRUE);
673 GetDocument()->UpdateAllViews(this);
679 ImageFileView::CreateCanvas (wxView *view, wxFrame *parent)
681 ImageFileCanvas* pCanvas;
683 parent->GetClientSize(&width, &height);
685 pCanvas = new ImageFileCanvas (dynamic_cast<ImageFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
687 pCanvas->SetScrollbars(20, 20, 50, 50);
688 pCanvas->SetBackgroundColour(*wxWHITE);
695 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
697 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
699 wxMenu *file_menu = new wxMenu;
701 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
702 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...");
703 file_menu->Append(wxID_OPEN, "&Open...");
704 file_menu->Append(wxID_SAVE, "&Save");
705 file_menu->Append(wxID_SAVEAS, "Save &As...");
706 file_menu->Append(wxID_CLOSE, "&Close");
708 file_menu->AppendSeparator();
709 file_menu->Append(IFMENU_FILE_PROPERTIES, "P&roperties");
710 file_menu->Append(IFMENU_FILE_EXPORT, "&Export...");
712 file_menu->AppendSeparator();
713 file_menu->Append(wxID_PRINT, "&Print...");
714 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
715 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
717 wxMenu *view_menu = new wxMenu;
718 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...");
719 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...");
721 wxMenu* filter_menu = new wxMenu;
722 filter_menu->Append (IFMENU_FILTER_INVERTVALUES, "&Invert Values");
723 filter_menu->Append (IFMENU_FILTER_SQUARE, "&Square");
724 filter_menu->Append (IFMENU_FILTER_SQRT, "Square &Root");
725 filter_menu->Append (IFMENU_FILTER_LOG, "&Log");
726 filter_menu->Append (IFMENU_FILTER_EXP, "&Exp");
727 filter_menu->AppendSeparator();
729 filter_menu->Append (IFMENU_FILTER_FFT, "&FFT");
730 filter_menu->Append (IFMENU_FILTER_IFFT, "&IFFT");
731 filter_menu->Append (IFMENU_FILTER_FOURIER, "F&ourier");
732 filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "Inverse Fo&urier");
734 filter_menu->Append (IFMENU_FILTER_FOURIER, "&Fourier");
735 filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "&Inverse Fourier");
737 filter_menu->Append (IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, "S&huffle Fourier to Natural Order");
738 filter_menu->Append (IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, "Shu&ffle Natural to Fourier Order");
739 filter_menu->Append (IFMENU_FILTER_MAGNITUDE, "&Magnitude");
740 filter_menu->Append (IFMENU_FILTER_PHASE, "&Phase");
742 wxMenu* image_menu = new wxMenu;
743 image_menu->Append (IFMENU_IMAGE_ADD, "&Add...");
744 image_menu->Append (IFMENU_IMAGE_SUBTRACT, "&Subtract...");
745 image_menu->Append (IFMENU_IMAGE_MULTIPLY, "&Multiply...");
746 image_menu->Append (IFMENU_IMAGE_DIVIDE, "&Divide...");
747 image_menu->AppendSeparator();
748 image_menu->Append (IFMENU_IMAGE_SCALESIZE, "S&cale Size...");
750 wxMenu *analyze_menu = new wxMenu;
751 analyze_menu->Append (IFMENU_PLOT_ROW, "Plot &Row");
752 analyze_menu->Append (IFMENU_PLOT_COL, "Plot &Column");
753 analyze_menu->Append (IFMENU_PLOT_HISTOGRAM, "Plot &Histogram");
754 analyze_menu->AppendSeparator();
755 analyze_menu->Append (IFMENU_COMPARE_IMAGES, "Compare &Images...");
756 analyze_menu->Append (IFMENU_COMPARE_ROW, "Compare &Row");
757 analyze_menu->Append (IFMENU_COMPARE_COL, "Compare &Column");
759 wxMenu *help_menu = new wxMenu;
760 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
762 wxMenuBar *menu_bar = new wxMenuBar;
764 menu_bar->Append(file_menu, "&File");
765 menu_bar->Append(view_menu, "&View");
766 menu_bar->Append(image_menu, "&Image");
767 menu_bar->Append(filter_menu, "Fi<er");
768 menu_bar->Append(analyze_menu, "&Analyze");
769 menu_bar->Append(help_menu, "&Help");
771 subframe->SetMenuBar(menu_bar);
773 subframe->Centre(wxBOTH);
780 ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
782 m_frame = CreateChildFrame(doc, this);
785 m_bMinSpecified = false;
786 m_bMaxSpecified = false;
787 m_dAutoScaleFactor = 1.;
790 m_frame->GetClientSize (&width, &height);
791 m_frame->SetTitle("ImageFileView");
792 m_canvas = CreateCanvas (this, m_frame);
794 int x, y; // X requires a forced resize
795 m_frame->GetSize(&x, &y);
796 m_frame->SetSize(-1, -1, x, y);
805 ImageFileView::OnDraw (wxDC* dc)
808 dc->DrawBitmap(m_bitmap, 0, 0, false);
810 int xCursor, yCursor;
811 if (m_canvas->GetCurrentCursor (xCursor, yCursor))
812 m_canvas->DrawRubberBandCursor (*dc, xCursor, yCursor);
817 ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
819 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
820 ImageFileArrayConst v = rIF.getArray();
823 if (v != NULL && nx != 0 && ny != 0) {
824 if (! m_bMinSpecified || ! m_bMaxSpecified) {
826 rIF.getMinMax (min, max);
827 if (! m_bMinSpecified)
829 if (! m_bMaxSpecified)
832 double scaleWidth = m_dMaxPixel - m_dMinPixel;
834 unsigned char* imageData = new unsigned char [nx * ny * 3];
835 for (int ix = 0; ix < nx; ix++) {
836 for (int iy = 0; iy < ny; iy++) {
837 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
838 int intensity = static_cast<int>(scaleValue + 0.5);
839 intensity = clamp (intensity, 0, 255);
840 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
841 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
844 wxImage image (nx, ny, imageData, true);
845 m_bitmap = image.ConvertToBitmap();
849 xSize = clamp (xSize, 0, 800);
850 ySize = clamp (ySize, 0, 800);
851 m_frame->SetClientSize (xSize, ySize);
852 m_canvas->SetScrollbars(20, 20, nx/20, ny/20);
853 m_canvas->SetBackgroundColour(*wxWHITE);
861 ImageFileView::OnClose (bool deleteWindow)
863 if (!GetDocument()->Close())
867 m_canvas->m_pView = NULL;
869 wxString s(theApp->GetAppName());
871 m_frame->SetTitle(s);
884 ImageFileView::OnExport (wxCommandEvent& event)
886 ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
887 ImageFileArrayConst v = rIF.getArray();
890 if (v != NULL && nx != 0 && ny != 0) {
891 if (! m_bMinSpecified || ! m_bMaxSpecified) {
893 rIF.getMinMax (min, max);
894 if (! m_bMinSpecified)
896 if (! m_bMaxSpecified)
900 DialogExportParameters dialogExport (m_frame, m_iDefaultExportFormatID);
901 if (dialogExport.ShowModal() == wxID_OK) {
902 wxString strFormatName (dialogExport.getFormatName ());
903 m_iDefaultExportFormatID = ImageFile::convertFormatNameToID (strFormatName.c_str());
906 wxString strWildcard;
907 if (m_iDefaultExportFormatID == ImageFile::FORMAT_PGM || m_iDefaultExportFormatID == ImageFile::FORMAT_PGMASCII) {
909 strWildcard = "PGM Files (*.pgm)|*.pgm";
912 else if (m_iDefaultExportFormatID == ImageFile::FORMAT_PNG || m_iDefaultExportFormatID == ImageFile::FORMAT_PNG16) {
914 strWildcard = "PNG Files (*.png)|*.png";
918 const wxString& strFilename = wxFileSelector (wxString("Export Filename"), wxString(""),
919 wxString(""), strExt, strWildcard, wxOVERWRITE_PROMPT | wxHIDE_READONLY | wxSAVE);
921 rIF.exportImage (strFormatName.c_str(), strFilename.c_str(), 1, 1, m_dMinPixel, m_dMaxPixel);
922 *theApp->getLog() << "Exported file " << strFilename << "\n";
929 ImageFileView::OnScaleSize (wxCommandEvent& event)
931 ImageFile& rIF = GetDocument()->getImageFile();
932 unsigned int iOldNX = rIF.nx();
933 unsigned int iOldNY = rIF.ny();
935 DialogGetXYSize dialogGetXYSize (m_frame, "Set New X & Y Dimensions", iOldNX, iOldNY);
936 if (dialogGetXYSize.ShowModal() == wxID_OK) {
937 unsigned int iNewNX = dialogGetXYSize.getXSize();
938 unsigned int iNewNY = dialogGetXYSize.getYSize();
939 std::ostringstream os;
940 os << "Scale Size from (" << iOldNX << "," << iOldNY << ") to (" << iNewNX << "," << iNewNY << ")";
941 ImageFileDocument* pScaledDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
943 sys_error (ERR_SEVERE, "Unable to create image file");
946 ImageFile& rScaledIF = pScaledDoc->getImageFile();
947 rScaledIF.setArraySize (iNewNX, iNewNY);
948 rScaledIF.labelAdd (os.str().c_str());
949 rIF.scaleImage (rScaledIF);
950 *theApp->getLog() << os.str().c_str() << "\n";
951 if (theApp->getSetModifyNewDocs())
952 pScaledDoc->Modify(TRUE);
953 pScaledDoc->UpdateAllViews (this);
954 pScaledDoc->GetFirstView()->OnUpdate (this, NULL);
959 ImageFileView::OnPlotRow (wxCommandEvent& event)
961 int xCursor, yCursor;
962 if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) {
963 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
967 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
968 ImageFileArrayConst v = rIF.getArray();
972 if (v != NULL && yCursor < ny) {
973 double* pX = new double [nx];
974 double* pY = new double [nx];
975 for (int i = 0; i < nx; i++) {
977 pY[i] = v[i][yCursor];
979 PlotFileDocument* pPlotDoc = dynamic_cast<PlotFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.plt", wxDOC_SILENT));
981 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
983 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
984 std::ostringstream os;
985 os << "Row " << yCursor;
986 std::string title("title ");
988 rPlotFile.addEzsetCommand (title.c_str());
989 rPlotFile.addEzsetCommand ("xlabel Column");
990 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
991 rPlotFile.addEzsetCommand ("lxfrac 0");
992 rPlotFile.addEzsetCommand ("box");
993 rPlotFile.addEzsetCommand ("grid");
994 rPlotFile.setCurveSize (2, nx);
995 rPlotFile.addColumn (0, pX);
996 rPlotFile.addColumn (1, pY);
1000 if (theApp->getSetModifyNewDocs())
1001 pPlotDoc->Modify(true);
1002 pPlotDoc->UpdateAllViews();
1007 ImageFileView::OnPlotCol (wxCommandEvent& event)
1009 int xCursor, yCursor;
1010 if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) {
1011 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1015 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
1016 ImageFileArrayConst v = rIF.getArray();
1020 if (v != NULL && xCursor < nx) {
1021 double* pX = new double [ny];
1022 double* pY = new double [ny];
1023 for (int i = 0; i < ny; i++) {
1025 pY[i] = v[xCursor][i];
1027 PlotFileDocument* pPlotDoc = dynamic_cast<PlotFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.plt", wxDOC_SILENT));
1029 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1031 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1032 std::ostringstream os;
1033 os << "Column " << xCursor;
1034 std::string title("title ");
1036 rPlotFile.addEzsetCommand (title.c_str());
1037 rPlotFile.addEzsetCommand ("xlabel Row");
1038 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1039 rPlotFile.addEzsetCommand ("lxfrac 0");
1040 rPlotFile.addEzsetCommand ("box");
1041 rPlotFile.addEzsetCommand ("grid");
1042 rPlotFile.setCurveSize (2, nx);
1043 rPlotFile.addColumn (0, pX);
1044 rPlotFile.addColumn (1, pY);
1048 if (theApp->getSetModifyNewDocs())
1049 pPlotDoc->Modify(true);
1050 pPlotDoc->UpdateAllViews();
1055 ImageFileView::OnCompareCol (wxCommandEvent& event)
1057 int xCursor, yCursor;
1058 if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) {
1059 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1063 std::vector<ImageFileDocument*> vecIFDoc;
1064 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1065 if (vecIFDoc.size() == 0) {
1066 wxMessageBox ("No compatible images for Column Comparison", "Error");
1069 DialogGetComparisonImage dialogGetCompare (m_frame, "Get Comparison Image", vecIFDoc, false);
1071 if (dialogGetCompare.ShowModal() == wxID_OK) {
1072 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1073 const ImageFile& rIF = GetDocument()->getImageFile();
1074 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1076 ImageFileArrayConst v1 = rIF.getArray();
1077 ImageFileArrayConst v2 = rCompareIF.getArray();
1081 if (v1 != NULL && xCursor < nx) {
1082 double* pX = new double [ny];
1083 double* pY1 = new double [ny];
1084 double* pY2 = new double [ny];
1085 for (int i = 0; i < ny; i++) {
1087 pY1[i] = v1[xCursor][i];
1088 pY2[i] = v2[xCursor][i];
1090 PlotFileDocument* pPlotDoc = dynamic_cast<PlotFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.plt", wxDOC_SILENT));
1092 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1094 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1095 std::ostringstream os;
1096 os << "Column " << xCursor << " Comparison";
1097 std::string title("title ");
1099 rPlotFile.addEzsetCommand (title.c_str());
1100 rPlotFile.addEzsetCommand ("xlabel Row");
1101 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1102 rPlotFile.addEzsetCommand ("lxfrac 0");
1103 rPlotFile.addEzsetCommand ("curve 1");
1104 rPlotFile.addEzsetCommand ("color 2");
1105 rPlotFile.addEzsetCommand ("curve 2");
1106 rPlotFile.addEzsetCommand ("color 4");
1107 rPlotFile.addEzsetCommand ("dash 5");
1108 rPlotFile.addEzsetCommand ("box");
1109 rPlotFile.addEzsetCommand ("grid");
1110 rPlotFile.setCurveSize (3, nx);
1111 rPlotFile.addColumn (0, pX);
1112 rPlotFile.addColumn (1, pY1);
1113 rPlotFile.addColumn (2, pY2);
1118 if (theApp->getSetModifyNewDocs())
1119 pPlotDoc->Modify(true);
1120 pPlotDoc->UpdateAllViews();
1126 ImageFileView::OnCompareRow (wxCommandEvent& event)
1128 int xCursor, yCursor;
1129 if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) {
1130 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1134 std::vector<ImageFileDocument*> vecIFDoc;
1135 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1137 if (vecIFDoc.size() == 0) {
1138 wxMessageBox ("No compatible images for Row Comparison", "Error");
1142 DialogGetComparisonImage dialogGetCompare (m_frame, "Get Comparison Image", vecIFDoc, false);
1144 if (dialogGetCompare.ShowModal() == wxID_OK) {
1145 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1146 const ImageFile& rIF = GetDocument()->getImageFile();
1147 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1149 ImageFileArrayConst v1 = rIF.getArray();
1150 ImageFileArrayConst v2 = rCompareIF.getArray();
1154 if (v1 != NULL && yCursor < ny) {
1155 double* pX = new double [nx];
1156 double* pY1 = new double [nx];
1157 double* pY2 = new double [nx];
1158 for (int i = 0; i < nx; i++) {
1160 pY1[i] = v1[i][yCursor];
1161 pY2[i] = v2[i][yCursor];
1163 PlotFileDocument* pPlotDoc = dynamic_cast<PlotFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.plt", wxDOC_SILENT));
1165 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1167 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1168 std::ostringstream os;
1169 os << "Row " << yCursor << " Comparison";
1170 std::string title("title ");
1172 rPlotFile.addEzsetCommand (title.c_str());
1173 rPlotFile.addEzsetCommand ("xlabel Column");
1174 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1175 rPlotFile.addEzsetCommand ("lxfrac 0");
1176 rPlotFile.addEzsetCommand ("curve 1");
1177 rPlotFile.addEzsetCommand ("color 2");
1178 rPlotFile.addEzsetCommand ("curve 2");
1179 rPlotFile.addEzsetCommand ("color 4");
1180 rPlotFile.addEzsetCommand ("dash 5");
1181 rPlotFile.addEzsetCommand ("box");
1182 rPlotFile.addEzsetCommand ("grid");
1183 rPlotFile.setCurveSize (3, ny);
1184 rPlotFile.addColumn (0, pX);
1185 rPlotFile.addColumn (1, pY1);
1186 rPlotFile.addColumn (2, pY2);
1191 if (theApp->getSetModifyNewDocs())
1192 pPlotDoc->Modify(true);
1193 pPlotDoc->UpdateAllViews();
1198 static int NUMBER_HISTOGRAM_BINS = 256;
1201 ImageFileView::OnPlotHistogram (wxCommandEvent& event)
1203 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
1204 ImageFileArrayConst v = rIF.getArray();
1208 if (v != NULL && nx > 0 && ny > 0) {
1209 PlotFileDocument* pPlotDoc = dynamic_cast<PlotFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.plt", wxDOC_SILENT));
1211 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1215 double* pX = new double [NUMBER_HISTOGRAM_BINS];
1216 double* pY = new double [NUMBER_HISTOGRAM_BINS];
1218 rIF.getMinMax (dMin, dMax);
1219 double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
1221 for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
1222 pX[i] = dMin + (i + 0.5) * dBinWidth;
1225 for (int ix = 0; ix < nx; ix++)
1226 for (int iy = 0; iy < ny; iy++) {
1227 int iBin = nearest<int> ((v[ix][iy] - dMin) / dBinWidth);
1228 if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
1232 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1233 std::ostringstream os;
1235 std::string title("title ");
1237 rPlotFile.addEzsetCommand (title.c_str());
1238 rPlotFile.addEzsetCommand ("xlabel Pixel Value");
1239 rPlotFile.addEzsetCommand ("ylabel Count");
1240 rPlotFile.addEzsetCommand ("box");
1241 rPlotFile.addEzsetCommand ("grid");
1242 rPlotFile.setCurveSize (2, nx);
1243 rPlotFile.addColumn (0, pX);
1244 rPlotFile.addColumn (1, pY);
1247 if (theApp->getSetModifyNewDocs())
1248 pPlotDoc->Modify(true);
1249 pPlotDoc->UpdateAllViews();
1256 PhantomCanvas::PhantomCanvas (PhantomView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1257 : wxScrolledWindow(frame, -1, pos, size, style)
1263 PhantomCanvas::OnDraw (wxDC& dc)
1266 m_pView->OnDraw(& dc);
1272 IMPLEMENT_DYNAMIC_CLASS(PhantomView, wxView)
1274 BEGIN_EVENT_TABLE(PhantomView, wxView)
1275 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomView::OnProperties)
1276 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomView::OnRasterize)
1277 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomView::OnProjections)
1280 PhantomView::PhantomView(void)
1281 : wxView(), m_canvas(NULL), m_frame(NULL)
1283 m_iDefaultNDet = 367;
1284 m_iDefaultNView = 320;
1285 m_iDefaultNSample = 2;
1286 m_dDefaultRotation = 2;
1287 m_dDefaultFocalLength = 2;
1288 m_dDefaultFieldOfView = 1;
1289 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
1290 m_iDefaultTrace = Trace::TRACE_NONE;
1293 PhantomView::~PhantomView(void)
1298 PhantomView::OnProperties (wxCommandEvent& event)
1300 const int idPhantom = GetDocument()->getPhantomID();
1301 const wxString& namePhantom = GetDocument()->getPhantomName();
1302 std::ostringstream os;
1303 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")" << "\n";
1304 const Phantom& rPhantom = GetDocument()->getPhantom();
1305 rPhantom.printDefinitions (os);
1307 rPhantom.print (os);
1309 *theApp->getLog() << os.str().c_str() << "\n";
1310 wxMessageBox (os.str().c_str(), "Phantom Properties");
1315 PhantomView::OnProjections (wxCommandEvent& event)
1317 DialogGetProjectionParameters dialogProjection (m_frame, m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView, m_iDefaultGeometry, m_iDefaultTrace);
1318 int retVal = dialogProjection.ShowModal();
1319 if (retVal == wxID_OK) {
1320 m_iDefaultNDet = dialogProjection.getNDet();
1321 m_iDefaultNView = dialogProjection.getNView();
1322 m_iDefaultNSample = dialogProjection.getNSamples();
1323 m_iDefaultTrace = dialogProjection.getTrace();
1324 m_dDefaultRotation = dialogProjection.getRotAngle();
1325 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
1326 m_dDefaultFieldOfView = dialogProjection.getFieldOfViewRatio();
1327 wxString sGeometry = dialogProjection.getGeometry();
1328 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
1330 if (m_iDefaultNDet > 0 && m_iDefaultNView > 0 && sGeometry != "") {
1331 const Phantom& rPhantom = GetDocument()->getPhantom();
1332 ProjectionFileDocument* pProjectionDoc = dynamic_cast<ProjectionFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.pj", wxDOC_SILENT));
1333 if (! pProjectionDoc) {
1334 sys_error (ERR_SEVERE, "Unable to create projection document");
1337 Projections& rProj = pProjectionDoc->getProjections();
1338 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView);
1339 if (theScanner.fail()) {
1340 *theApp->getLog() << "Failed making scanner: " << theScanner.failMessage().c_str() << "\n";
1343 rProj.initFromScanner (theScanner);
1344 m_dDefaultRotation /= PI; // convert back to PI units
1347 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
1348 ProjectionsDialog dialogProjections (theScanner, rProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(m_frame));
1349 for (int iView = 0; iView < rProj.nView(); iView++) {
1352 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
1353 pProjectionDoc->DeleteAllViews();
1358 while (dialogProjections.isPaused()) {
1364 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), rProj.nView() + 1, m_frame, wxPD_CAN_ABORT);
1365 for (int i = 0; i < rProj.nView(); i++) {
1366 theScanner.collectProjections (rProj, rPhantom, i, 1, true, m_iDefaultTrace);
1367 if (! dlgProgress.Update (i+1)) {
1368 pProjectionDoc->DeleteAllViews();
1374 std::ostringstream os;
1375 os << "Projections for " << rPhantom.name() << ": nDet=" << m_iDefaultNDet << ", nView=" << m_iDefaultNView << ", nSamples=" << m_iDefaultNSample << ", RotAngle=" << m_dDefaultRotation << ", FocalLengthRatio=" << m_dDefaultFocalLength << ", FieldOfViewRatio=" << m_dDefaultFieldOfView << ", Geometry=" << sGeometry.c_str();
1376 rProj.setCalcTime (timer.timerEnd());
1377 rProj.setRemark (os.str());
1378 *theApp->getLog() << os.str().c_str() << "\n";
1382 ProjectionFileView* projView = dynamic_cast<ProjectionFileView*>(pProjectionDoc->GetFirstView());
1384 projView->getFrame()->SetFocus();
1385 projView->OnUpdate (projView, NULL);
1387 if (wxView* pView = pProjectionDoc->GetFirstView()) {
1388 if (wxFrame* pFrame = pView->GetFrame()) {
1392 theApp->getDocManager()->ActivateView (pView, true, false);
1395 if (theApp->getSetModifyNewDocs())
1396 pProjectionDoc->Modify(true);
1397 pProjectionDoc->UpdateAllViews(this);
1404 PhantomView::OnRasterize (wxCommandEvent& event)
1406 DialogGetRasterParameters dialogRaster (m_frame, 256, 256, 1);
1407 int retVal = dialogRaster.ShowModal();
1408 if (retVal == wxID_OK) {
1409 int xSize = dialogRaster.getXSize();
1410 int ySize = dialogRaster.getYSize();
1411 int nSamples = dialogRaster.getNSamples();
1414 if (xSize > 0 && ySize > 0) {
1415 const Phantom& rPhantom = GetDocument()->getPhantom();
1416 ImageFileDocument* pRasterDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
1418 sys_error (ERR_SEVERE, "Unable to create image file");
1421 ImageFile& imageFile = pRasterDoc->getImageFile();
1423 imageFile.setArraySize (xSize, ySize);
1424 wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"), imageFile.nx() + 1, m_frame, wxPD_CAN_ABORT);
1426 for (unsigned int i = 0; i < imageFile.nx(); i++) {
1427 rPhantom.convertToImagefile (imageFile, nSamples, Trace::TRACE_NONE, i, 1, true);
1428 if (! dlgProgress.Update(i+1)) {
1429 pRasterDoc->DeleteAllViews();
1433 if (theApp->getSetModifyNewDocs())
1434 pRasterDoc->Modify(true);
1435 pRasterDoc->UpdateAllViews(this);
1436 std::ostringstream os;
1437 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << xSize << ", YSize=" << ySize << ", nSamples=" << nSamples;
1438 *theApp->getLog() << os.str().c_str() << "\n";
1439 imageFile.labelAdd (os.str().c_str(), timer.timerEnd());
1440 ImageFileView* rasterView = dynamic_cast<ImageFileView*>(pRasterDoc->GetFirstView());
1442 rasterView->getFrame()->SetFocus();
1443 rasterView->OnUpdate (rasterView, NULL);
1452 PhantomView::CreateCanvas (wxView *view, wxFrame *parent)
1454 PhantomCanvas* pCanvas;
1456 parent->GetClientSize(&width, &height);
1458 pCanvas = new PhantomCanvas (dynamic_cast<PhantomView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
1460 pCanvas->SetBackgroundColour(*wxWHITE);
1467 PhantomView::CreateChildFrame(wxDocument *doc, wxView *view)
1469 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
1471 wxMenu *file_menu = new wxMenu;
1473 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
1474 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...");
1475 file_menu->Append(wxID_OPEN, "&Open...");
1476 file_menu->Append(wxID_SAVEAS, "Save &As...");
1477 file_menu->Append(wxID_CLOSE, "&Close");
1479 file_menu->AppendSeparator();
1480 file_menu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties");
1482 file_menu->AppendSeparator();
1483 file_menu->Append(wxID_PRINT, "&Print...");
1484 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
1485 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
1487 wxMenu *process_menu = new wxMenu;
1488 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...");
1489 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...");
1491 wxMenu *help_menu = new wxMenu;
1492 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
1493 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
1495 wxMenuBar *menu_bar = new wxMenuBar;
1497 menu_bar->Append(file_menu, "&File");
1498 menu_bar->Append(process_menu, "&Process");
1499 menu_bar->Append(help_menu, "&Help");
1501 subframe->SetMenuBar(menu_bar);
1503 subframe->Centre(wxBOTH);
1510 PhantomView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
1512 m_frame = CreateChildFrame(doc, this);
1516 m_frame->GetClientSize(&width, &height);
1517 m_frame->SetTitle("PhantomView");
1518 m_canvas = CreateCanvas(this, m_frame);
1521 int x, y; // X requires a forced resize
1522 m_frame->GetSize(&x, &y);
1523 m_frame->SetSize(-1, -1, x, y);
1526 m_frame->Show(true);
1534 PhantomView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
1537 m_canvas->Refresh();
1541 PhantomView::OnClose (bool deleteWindow)
1543 if (!GetDocument()->Close())
1547 m_canvas->m_pView = NULL;
1549 wxString s(wxTheApp->GetAppName());
1551 m_frame->SetTitle(s);
1564 PhantomView::OnDraw (wxDC* dc)
1567 m_canvas->GetClientSize (&xsize, &ysize);
1568 SGPDriver driver (dc, xsize, ysize);
1570 const Phantom& rPhantom = GetDocument()->getPhantom();
1571 sgp.setColor (C_RED);
1572 rPhantom.show (sgp);
1577 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1578 : wxScrolledWindow(frame, -1, pos, size, style)
1584 ProjectionFileCanvas::OnDraw(wxDC& dc)
1587 m_pView->OnDraw(& dc);
1590 // ProjectionFileView
1592 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
1594 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
1595 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
1596 EVT_MENU(PJMENU_PROCESS_RECONSTRUCT, ProjectionFileView::OnReconstruct)
1599 ProjectionFileView::ProjectionFileView(void)
1600 : wxView(), m_canvas(NULL), m_frame(NULL)
1604 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
1605 m_dDefaultFilterParam = 1.;
1607 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
1608 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
1610 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
1611 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
1613 m_iDefaultZeropad = 1;
1614 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF3;
1615 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
1616 m_iDefaultInterpParam = 1;
1617 m_iDefaultTrace = Trace::TRACE_NONE;
1620 ProjectionFileView::~ProjectionFileView(void)
1625 ProjectionFileView::OnProperties (wxCommandEvent& event)
1627 const Projections& rProj = GetDocument()->getProjections();
1628 std::ostringstream os;
1629 rProj.printScanInfo(os);
1630 *theApp->getLog() << os.str().c_str();
1631 wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
1632 dialogMsg.ShowModal();
1637 ProjectionFileView::OnReconstruct (wxCommandEvent& event)
1639 DialogGetReconstructionParameters dialogReconstruction (m_frame, m_iDefaultNX, m_iDefaultNY, m_iDefaultFilter, m_dDefaultFilterParam, m_iDefaultFilterMethod, m_iDefaultFilterGeneration, m_iDefaultZeropad, m_iDefaultInterpolation, m_iDefaultInterpParam, m_iDefaultBackprojector, m_iDefaultTrace);
1641 int retVal = dialogReconstruction.ShowModal();
1642 if (retVal == wxID_OK) {
1643 m_iDefaultNX = dialogReconstruction.getXSize();
1644 m_iDefaultNY = dialogReconstruction.getYSize();
1645 wxString optFilterName = dialogReconstruction.getFilterName();
1646 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
1647 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
1648 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
1649 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
1650 m_iDefaultZeropad = dialogReconstruction.getZeropad();
1651 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
1652 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
1653 wxString optInterpName = dialogReconstruction.getInterpName();
1654 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
1655 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
1656 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
1657 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
1658 m_iDefaultTrace = dialogReconstruction.getTrace();
1659 if (m_iDefaultNX > 0 && m_iDefaultNY > 0) {
1660 ImageFileDocument* pReconDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
1662 sys_error (ERR_SEVERE, "Unable to create image file");
1665 ImageFile& imageFile = pReconDoc->getImageFile();
1666 const Projections& rProj = GetDocument()->getProjections();
1667 imageFile.setArraySize (m_iDefaultNX, m_iDefaultNY);
1669 if (m_iDefaultFilterMethod != ProcessSignal::FILTER_METHOD_CONVOLUTION && m_iDefaultFilterGeneration == ProcessSignal::FILTER_GENERATION_DIRECT && rProj.geometry() != Scanner::GEOMETRY_PARALLEL) {
1670 wxMessageBox ("Sorry!\nCurrently, frequency-based filtering with direct filter generation is not support for geometries other than parallel.\nAborting command.", "Not Supported", wxOK | wxICON_WARNING, m_frame);
1674 Reconstructor* pReconstruct = new Reconstructor (rProj, imageFile, optFilterName.c_str(), m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(), optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace);
1677 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
1678 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstruct, rProj, imageFile, m_iDefaultTrace, m_frame);
1679 for (int iView = 0; iView < rProj.nView(); iView++) {
1682 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView)) {
1683 delete pDlgReconstruct;
1684 delete pReconstruct;
1685 pReconDoc->DeleteAllViews();
1690 while (pDlgReconstruct->isPaused()) {
1695 delete pDlgReconstruct;
1697 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, m_frame, wxPD_CAN_ABORT);
1698 for (int i = 0; i < rProj.nView(); i++) {
1699 pReconstruct->reconstructView (i, 1);
1700 if (! dlgProgress.Update(i + 1)) {
1701 delete pReconstruct;
1702 pReconDoc->DeleteAllViews();
1707 delete pReconstruct;
1708 if (theApp->getSetModifyNewDocs())
1709 pReconDoc->Modify(true);
1710 pReconDoc->UpdateAllViews(this);
1711 ImageFileView* rasterView = dynamic_cast<ImageFileView*>(pReconDoc->GetFirstView());
1713 rasterView->getFrame()->SetFocus();
1714 rasterView->OnUpdate (rasterView, NULL);
1716 std::ostringstream os;
1717 os << "Reconstruct " << rProj.getFilename() << ": xSize=" << m_iDefaultNX << ", ySize=" << m_iDefaultNY << ", Filter=" << optFilterName.c_str() << ", FilterParam=" << m_dDefaultFilterParam << ", FilterMethod=" << optFilterMethodName.c_str() << ", FilterGeneration=" << optFilterGenerationName.c_str() << ", Zeropad=" << m_iDefaultZeropad << ", Interpolation=" << optInterpName.c_str() << ", InterpolationParam=" << m_iDefaultInterpParam << ", Backprojection=" << optBackprojectName.c_str();
1718 *theApp->getLog() << os.str().c_str() << "\n";
1719 imageFile.labelAdd (rProj.getLabel());
1720 imageFile.labelAdd (os.str().c_str(), timerRecon.timerEnd());
1726 ProjectionFileCanvas*
1727 ProjectionFileView::CreateCanvas (wxView *view, wxFrame *parent)
1729 ProjectionFileCanvas* pCanvas;
1731 parent->GetClientSize(&width, &height);
1733 pCanvas = new ProjectionFileCanvas (dynamic_cast<ProjectionFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
1735 pCanvas->SetScrollbars(20, 20, 50, 50);
1736 pCanvas->SetBackgroundColour(*wxWHITE);
1743 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
1745 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
1747 wxMenu *file_menu = new wxMenu;
1749 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
1750 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...");
1751 file_menu->Append(wxID_OPEN, "&Open...");
1752 file_menu->Append(wxID_SAVE, "&Save");
1753 file_menu->Append(wxID_SAVEAS, "Save &As...");
1754 file_menu->Append(wxID_CLOSE, "&Close");
1756 file_menu->AppendSeparator();
1757 file_menu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
1759 file_menu->AppendSeparator();
1760 file_menu->Append(wxID_PRINT, "&Print...");
1761 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
1762 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
1764 wxMenu *process_menu = new wxMenu;
1765 process_menu->Append(PJMENU_PROCESS_RECONSTRUCT, "R&econstruct...");
1767 wxMenu *help_menu = new wxMenu;
1768 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
1769 help_menu->AppendSeparator();
1770 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
1772 wxMenuBar *menu_bar = new wxMenuBar;
1774 menu_bar->Append(file_menu, "&File");
1775 menu_bar->Append(process_menu, "&Process");
1776 menu_bar->Append(help_menu, "&Help");
1778 subframe->SetMenuBar(menu_bar);
1780 subframe->Centre(wxBOTH);
1787 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
1789 m_frame = CreateChildFrame(doc, this);
1793 m_frame->GetClientSize(&width, &height);
1794 m_frame->SetTitle("ProjectionFileView");
1795 m_canvas = CreateCanvas(this, m_frame);
1798 int x, y; // X requires a forced resize
1799 m_frame->GetSize(&x, &y);
1800 m_frame->SetSize(-1, -1, x, y);
1803 m_frame->Show(true);
1810 ProjectionFileView::OnDraw (wxDC* dc)
1813 dc->DrawBitmap (m_bitmap, 0, 0, false);
1818 ProjectionFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
1820 const Projections& rProj = GetDocument()->getProjections();
1821 const int nDet = rProj.nDet();
1822 const int nView = rProj.nView();
1823 if (nDet != 0 && nView != 0) {
1824 const DetectorArray& detarray = rProj.getDetectorArray(0);
1825 const DetectorValue* detval = detarray.detValues();
1826 double min = detval[0];
1827 double max = detval[0];
1828 for (int iy = 0; iy < nView; iy++) {
1829 const DetectorArray& detarray = rProj.getDetectorArray(iy);
1830 const DetectorValue* detval = detarray.detValues();
1831 for (int ix = 0; ix < nDet; ix++) {
1832 if (min > detval[ix])
1834 else if (max < detval[ix])
1839 unsigned char* imageData = new unsigned char [nDet * nView * 3];
1840 double scale = (max - min) / 255;
1841 for (int iy2 = 0; iy2 < nView; iy2++) {
1842 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
1843 const DetectorValue* detval = detarray.detValues();
1844 for (int ix = 0; ix < nDet; ix++) {
1845 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
1846 intensity = clamp(intensity, 0, 255);
1847 int baseAddr = (iy2 * nDet + ix) * 3;
1848 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
1851 wxImage image (nDet, nView, imageData, true);
1852 m_bitmap = image.ConvertToBitmap();
1856 xSize = clamp (xSize, 0, 800);
1857 ySize = clamp (ySize, 0, 800);
1858 m_frame->SetClientSize (xSize, ySize);
1859 m_canvas->SetScrollbars (20, 20, nDet/20, nView/20);
1863 m_canvas->Refresh();
1867 ProjectionFileView::OnClose (bool deleteWindow)
1869 if (!GetDocument()->Close())
1873 m_canvas->m_pView = NULL;
1875 wxString s(wxTheApp->GetAppName());
1877 m_frame->SetTitle(s);
1892 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1893 : wxScrolledWindow(frame, -1, pos, size, style)
1899 PlotFileCanvas::OnDraw(wxDC& dc)
1902 m_pView->OnDraw(& dc);
1908 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
1910 BEGIN_EVENT_TABLE(PlotFileView, wxView)
1911 EVT_MENU(PJMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
1912 EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
1913 EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
1916 PlotFileView::PlotFileView(void)
1917 : wxView(), m_canvas(NULL), m_frame(NULL), m_pEZPlot(NULL)
1919 m_bMinSpecified = false;
1920 m_bMaxSpecified = false;
1923 PlotFileView::~PlotFileView(void)
1930 PlotFileView::OnProperties (wxCommandEvent& event)
1932 const PlotFile& rPlot = GetDocument()->getPlotFile();
1933 std::ostringstream os;
1934 os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
1935 rPlot.printHeaders (os);
1936 *theApp->getLog() << os.str().c_str();
1937 wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
1938 dialogMsg.ShowModal();
1943 PlotFileView::OnScaleAuto (wxCommandEvent& event)
1945 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
1946 double min, max, mean, mode, median, stddev;
1947 rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
1948 DialogAutoScaleParameters dialogAutoScale (m_frame, mean, mode, median, stddev, m_dAutoScaleFactor);
1949 int iRetVal = dialogAutoScale.ShowModal();
1950 if (iRetVal == wxID_OK) {
1951 m_bMinSpecified = true;
1952 m_bMaxSpecified = true;
1954 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
1957 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
1958 OnUpdate (this, NULL);
1964 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
1966 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
1970 if (! m_bMinSpecified || ! m_bMaxSpecified) {
1971 if (! rPlotFile.getMinMax (1, min, max)) {
1972 *theApp->getLog() << "Error: unable to find Min/Max\n";
1977 if (m_bMinSpecified)
1979 if (m_bMaxSpecified)
1982 DialogGetMinMax dialogMinMax (m_frame, "Set Y-axis Minimum & Maximum", min, max);
1983 int retVal = dialogMinMax.ShowModal();
1984 if (retVal == wxID_OK) {
1985 m_bMinSpecified = true;
1986 m_bMaxSpecified = true;
1987 m_dMinPixel = dialogMinMax.getMinimum();
1988 m_dMaxPixel = dialogMinMax.getMaximum();
1989 OnUpdate (this, NULL);
1995 PlotFileView::CreateCanvas (wxView *view, wxFrame *parent)
1997 PlotFileCanvas* pCanvas;
1999 parent->GetClientSize(&width, &height);
2001 pCanvas = new PlotFileCanvas (dynamic_cast<PlotFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
2003 pCanvas->SetBackgroundColour(*wxWHITE);
2010 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2012 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2014 wxMenu *file_menu = new wxMenu;
2016 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
2017 file_menu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...");
2018 file_menu->Append(wxID_OPEN, "&Open...");
2019 file_menu->Append(wxID_SAVE, "&Save");
2020 file_menu->Append(wxID_SAVEAS, "Save &As...");
2021 file_menu->Append(wxID_CLOSE, "&Close");
2023 file_menu->AppendSeparator();
2024 file_menu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
2026 file_menu->AppendSeparator();
2027 file_menu->Append(wxID_PRINT, "&Print...");
2028 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2029 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
2031 wxMenu *view_menu = new wxMenu;
2032 view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...");
2033 view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...");
2035 wxMenu *help_menu = new wxMenu;
2036 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
2037 help_menu->AppendSeparator();
2038 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2040 wxMenuBar *menu_bar = new wxMenuBar;
2042 menu_bar->Append(file_menu, "&File");
2043 menu_bar->Append(view_menu, "&View");
2044 menu_bar->Append(help_menu, "&Help");
2046 subframe->SetMenuBar(menu_bar);
2048 subframe->Centre(wxBOTH);
2055 PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
2057 m_frame = CreateChildFrame(doc, this);
2060 m_bMinSpecified = false;
2061 m_bMaxSpecified = false;
2062 m_dAutoScaleFactor = 1.;
2065 m_frame->GetClientSize(&width, &height);
2066 m_frame->SetTitle ("Plot File");
2067 m_canvas = CreateCanvas (this, m_frame);
2070 int x, y; // X requires a forced resize
2071 m_frame->GetSize(&x, &y);
2072 m_frame->SetSize(-1, -1, x, y);
2075 m_frame->Show(true);
2082 PlotFileView::OnDraw (wxDC* dc)
2084 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2085 const int iNColumns = rPlotFile.getNumColumns();
2086 const int iNRecords = rPlotFile.getNumRecords();
2088 if (iNColumns > 0 && iNRecords > 0) {
2090 m_canvas->GetClientSize (&xsize, &ysize);
2091 SGPDriver driver (dc, xsize, ysize);
2094 m_pEZPlot->plot (&sgp);
2100 PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2102 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2103 const int iNColumns = rPlotFile.getNumColumns();
2104 const int iNRecords = rPlotFile.getNumRecords();
2106 if (iNColumns > 0 && iNRecords > 0) {
2109 m_pEZPlot = new EZPlot;
2111 for (unsigned int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)
2112 m_pEZPlot->ezset (rPlotFile.getEzsetCommand (iEzset));
2114 if (m_bMinSpecified) {
2115 std::ostringstream os;
2116 os << "ymin " << m_dMinPixel;
2117 m_pEZPlot->ezset (os.str());
2120 if (m_bMaxSpecified) {
2121 std::ostringstream os;
2122 os << "ymax " << m_dMaxPixel;
2123 m_pEZPlot->ezset (os.str());
2126 m_pEZPlot->ezset("box");
2127 m_pEZPlot->ezset("grid");
2129 double* pdXaxis = new double [iNRecords];
2130 rPlotFile.getColumn (0, pdXaxis);
2132 double* pdY = new double [iNRecords];
2133 for (int iCol = 1; iCol < iNColumns; iCol++) {
2134 rPlotFile.getColumn (iCol, pdY);
2135 m_pEZPlot->addCurve (pdXaxis, pdY, iNRecords);
2143 m_canvas->Refresh();
2147 PlotFileView::OnClose (bool deleteWindow)
2149 if (!GetDocument()->Close())
2153 m_canvas->m_pView = NULL;
2155 wxString s(wxTheApp->GetAppName());
2157 m_frame->SetTitle(s);