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.32 2000/12/20 14:39:09 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
\r
60 #include <sstream_subst>
\r
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)
\r
89 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
\r
90 ImageFileArrayConst v = rIF.getArray();
\r
94 dc.SetLogicalFunction (wxINVERT);
\r
95 dc.SetPen (*wxGREEN_PEN);
\r
96 dc.DrawLine (0, y, nx, y);
\r
97 dc.DrawLine (x, 0, x, ny);
\r
98 dc.SetLogicalFunction (wxCOPY);
\r
102 ImageFileCanvas::GetCurrentCursor (int& x, int& y)
\r
107 if (m_xCursor >= 0 && m_yCursor >= 0)
\r
114 ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
122 wxPoint pt(event.GetLogicalPosition(dc));
124 if (event.RightIsDown()) {
\r
125 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
\r
126 ImageFileArrayConst v = rIF.getArray();
\r
130 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
\r
131 std::ostringstream os;
\r
132 os << "Image value (" << pt.x << "," << pt.y << ") = " << v[pt.x][ny - 1 - pt.y] << "\n";
\r
133 *theApp->getLog() << os.str().c_str();
\r
135 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << pt.y << ")\n";
\r
137 else if (event.LeftIsDown()) {
\r
138 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
\r
139 ImageFileArrayConst v = rIF.getArray();
\r
143 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
\r
144 if (m_xCursor >= 0 && m_yCursor >= 0) {
\r
145 DrawRubberBandCursor (dc, m_xCursor, m_yCursor);
\r
147 DrawRubberBandCursor (dc, pt.x, pt.y);
\r
150 std::ostringstream os;
\r
151 os << "Selected column" << pt.x << " and row" << pt.y << "\n";
\r
152 *theApp->getLog() << os.str().c_str();
\r
154 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << pt.y << ")\n";
\r
160 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
162 BEGIN_EVENT_TABLE(ImageFileView, wxView)
163 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
164 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
165 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
\r
166 EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)
167 EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol)
\r
170 ImageFileView::ImageFileView(void)
171 : wxView(), m_canvas(NULL), m_frame(NULL), m_bMinSpecified(false), m_bMaxSpecified(false)
175 ImageFileView::~ImageFileView(void)
180 ImageFileView::OnProperties (wxCommandEvent& event)
182 double min, max, mean, mode, median, stddev;
183 const ImageFile& rIF = GetDocument()->getImageFile();
184 if (rIF.nx() == 0 || rIF.ny() == 0)
185 *theApp->getLog() << "Properties: empty imagefile\n";
187 const std::string& rFilename = rIF.getFilename();
188 rIF.statistics (min, max, mean, mode, median, stddev);
189 std::ostringstream os;
190 os << "file: " << rFilename << "\nmin: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
191 *theApp->getLog() << os.str().c_str();
192 wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
193 dialogMsg.ShowModal();
198 ImageFileView::OnScaleAuto (wxCommandEvent& event)
200 const ImageFile& rIF = GetDocument()->getImageFile();
201 DialogAutoScaleParameters dialogAutoScale (m_frame, rIF, m_dAutoScaleFactor);
202 int iRetVal = dialogAutoScale.ShowModal();
203 if (iRetVal == wxID_OK) {
204 m_bMinSpecified = true;
205 m_bMaxSpecified = true;
207 dialogAutoScale.getMinMax (&dMin, &dMax);
210 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
211 OnUpdate (this, NULL);
216 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
218 const ImageFile& rIF = GetDocument()->getImageFile();
220 if (! m_bMinSpecified && ! m_bMaxSpecified)
221 rIF.getMinMax (min, max);
228 DialogGetImageMinMax dialogMinMax (m_frame, rIF, min, max);
229 int retVal = dialogMinMax.ShowModal();
230 if (retVal == wxID_OK) {
231 m_bMinSpecified = true;
232 m_bMaxSpecified = true;
233 m_dMinPixel = dialogMinMax.getMinimum();
234 m_dMaxPixel = dialogMinMax.getMaximum();
235 OnUpdate (this, NULL);
241 ImageFileView::CreateCanvas (wxView *view, wxFrame *parent)
243 ImageFileCanvas* pCanvas;
245 parent->GetClientSize(&width, &height);
247 pCanvas = new ImageFileCanvas (dynamic_cast<ImageFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
249 pCanvas->SetScrollbars(20, 20, 50, 50);
250 pCanvas->SetBackgroundColour(*wxWHITE);
257 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
259 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
261 wxMenu *file_menu = new wxMenu;
263 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
264 file_menu->Append(wxID_OPEN, "&Open...");
265 file_menu->Append(wxID_SAVE, "&Save");
266 file_menu->Append(wxID_SAVEAS, "Save &As...");
267 file_menu->Append(wxID_CLOSE, "&Close");
269 file_menu->AppendSeparator();
270 file_menu->Append(IFMENU_FILE_PROPERTIES, "P&roperties");
272 file_menu->AppendSeparator();
273 file_menu->Append(wxID_PRINT, "&Print...");
274 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
275 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
277 wxMenu *view_menu = new wxMenu;
278 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...");
279 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...");
281 wxMenu *plot_menu = new wxMenu;
\r
282 plot_menu->Append (IFMENU_PLOT_ROW, "Plot &Row");
\r
283 plot_menu->Append (IFMENU_PLOT_COL, "Plot &Column");
\r
285 wxMenu *help_menu = new wxMenu;
286 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
288 wxMenuBar *menu_bar = new wxMenuBar;
290 menu_bar->Append(file_menu, "&File");
291 menu_bar->Append(view_menu, "&View");
\r
292 menu_bar->Append(plot_menu, "&Plot");
293 menu_bar->Append(help_menu, "&Help");
295 subframe->SetMenuBar(menu_bar);
297 subframe->Centre(wxBOTH);
304 ImageFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
306 m_frame = CreateChildFrame(doc, this);
309 m_bMinSpecified = false;
310 m_bMaxSpecified = false;
311 m_dAutoScaleFactor = 1.;
314 m_frame->GetClientSize (&width, &height);
315 m_frame->SetTitle("ImageFileView");
316 m_canvas = CreateCanvas (this, m_frame);
318 int x, y; // X requires a forced resize
319 m_frame->GetSize(&x, &y);
320 m_frame->SetSize(-1, -1, x, y);
321 m_frame->SetFocus();
\r
329 ImageFileView::OnDraw (wxDC* dc)
332 dc->DrawBitmap(m_bitmap, 0, 0, false);
334 int xCursor, yCursor;
\r
335 if (m_canvas->GetCurrentCursor (xCursor, yCursor))
\r
336 m_canvas->DrawRubberBandCursor (*dc, xCursor, yCursor);
\r
341 ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
343 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
344 ImageFileArrayConst v = rIF.getArray();
347 if (v != NULL && nx != 0 && ny != 0) {
348 if (! m_bMinSpecified || ! m_bMaxSpecified) {
350 rIF.getMinMax (min, max);
351 if (! m_bMinSpecified)
353 if (! m_bMaxSpecified)
356 double scaleWidth = m_dMaxPixel - m_dMinPixel;
358 unsigned char* imageData = new unsigned char [nx * ny * 3];
359 for (int ix = 0; ix < nx; ix++) {
360 for (int iy = 0; iy < ny; iy++) {
361 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
362 int intensity = static_cast<int>(scaleValue + 0.5);
363 intensity = clamp (intensity, 0, 255);
364 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
365 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
368 wxImage image (nx, ny, imageData, true);
369 m_bitmap = image.ConvertToBitmap();
373 xSize = clamp (xSize, 0, 800);
374 ySize = clamp (ySize, 0, 800);
375 m_frame->SetClientSize (xSize, ySize);
376 m_canvas->SetScrollbars(20, 20, nx/20, ny/20);
377 m_canvas->SetBackgroundColour(*wxWHITE);
\r
385 ImageFileView::OnClose (bool deleteWindow)
387 if (!GetDocument()->Close())
391 m_canvas->m_pView = NULL;
393 wxString s(theApp->GetAppName());
395 m_frame->SetTitle(s);
407 #include "wx/plot.h"
\r
410 ImageFileView::OnPlotRow (wxCommandEvent& event)
\r
412 int xCursor, yCursor;
\r
413 if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) {
\r
414 *theApp->getLog() << "No row selected. Please use left mouse button on image to select row\n";
\r
418 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
\r
419 ImageFileArrayConst v = rIF.getArray();
\r
423 if (v != NULL && yCursor < ny) {
\r
424 double* pX = new double [nx];
\r
425 double* pY = new double [nx];
\r
426 for (int i = 0; i < nx; i++) {
\r
428 pY[i] = v[i][yCursor];
\r
430 PlotFileDocument* pPlotDoc = dynamic_cast<PlotFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.plt", wxDOC_SILENT));
\r
432 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
\r
434 PlotFile& rPlot = pPlotDoc->getPlotFile();
\r
435 rPlot.setTitle("Row Plot");
\r
436 rPlot.setXLabel("Column");
\r
437 rPlot.setYLabel("Pixel Value");
\r
438 rPlot.setCurveSize (2, nx);
\r
439 rPlot.addColumn (0, pX);
\r
440 rPlot.addColumn (1, pY);
\r
449 ImageFileView::OnPlotCol (wxCommandEvent& event)
\r
451 int xCursor, yCursor;
\r
452 if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) {
\r
453 // os << "No column selected. Please use left mouse button on image to select column\n";
\r
457 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
\r
458 ImageFileArrayConst v = rIF.getArray();
\r
462 if (v != NULL && xCursor < nx) {
\r
463 double* pVec = new double [ny];
\r
464 double minVal = v[xCursor][0];
\r
465 double maxVal = minVal;
\r
466 for (int i = 0; i < ny; i++) {
\r
467 if (minVal < v[xCursor][i])
\r
468 minVal = v[xCursor][i];
\r
469 else if (maxVal > v[xCursor][i])
\r
470 maxVal = v[xCursor][i];
\r
471 pVec[i] = v[xCursor][i];
\r
479 PhantomCanvas::PhantomCanvas (PhantomView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
480 : wxScrolledWindow(frame, -1, pos, size, style)
486 PhantomCanvas::OnDraw(wxDC& dc)
489 m_pView->OnDraw(& dc);
495 IMPLEMENT_DYNAMIC_CLASS(PhantomView, wxView)
497 BEGIN_EVENT_TABLE(PhantomView, wxView)
498 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomView::OnProperties)
499 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomView::OnRasterize)
500 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomView::OnProjections)
503 PhantomView::PhantomView(void)
504 : wxView(), m_canvas(NULL), m_frame(NULL)
506 m_iDefaultNDet = 367;
507 m_iDefaultNView = 320;
508 m_iDefaultNSample = 2;
509 m_dDefaultRotation = 2;
510 m_dDefaultFocalLength = 2;
511 m_dDefaultFieldOfView = 1;
512 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
513 m_iDefaultTrace = Trace::TRACE_NONE;
516 PhantomView::~PhantomView(void)
521 PhantomView::OnProperties (wxCommandEvent& event)
523 const int idPhantom = GetDocument()->getPhantomID();
524 const wxString& namePhantom = GetDocument()->getPhantomName();
525 std::ostringstream os;
526 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")\n";
527 *theApp->getLog() << os.str().c_str();
529 const Phantom& rPhantom = GetDocument()->getPhantom();
536 PhantomView::OnProjections (wxCommandEvent& event)
538 DialogGetProjectionParameters dialogProjection (m_frame, m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView, m_iDefaultGeometry, m_iDefaultTrace);
539 int retVal = dialogProjection.ShowModal();
540 if (retVal == wxID_OK) {
541 m_iDefaultNDet = dialogProjection.getNDet();
542 m_iDefaultNView = dialogProjection.getNView();
543 m_iDefaultNSample = dialogProjection.getNSamples();
544 m_iDefaultTrace = dialogProjection.getTrace();
545 m_dDefaultRotation = dialogProjection.getRotAngle();
546 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
547 m_dDefaultFieldOfView = dialogProjection.getFieldOfViewRatio();
548 wxString sGeometry = dialogProjection.getGeometry();
549 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
551 if (m_iDefaultNDet > 0 && m_iDefaultNView > 0 && sGeometry != "") {
552 const Phantom& rPhantom = GetDocument()->getPhantom();
553 ProjectionFileDocument* pProjectionDoc = dynamic_cast<ProjectionFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.pj", wxDOC_SILENT));
554 Projections& rProj = pProjectionDoc->getProjections();
555 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView);
556 if (theScanner.fail()) {
557 *theApp->getLog() << "Failed making scanner: " << theScanner.failMessage().c_str() << "\n";
560 rProj.initFromScanner (theScanner);
561 m_dDefaultRotation /= PI; // convert back to PI units
563 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
564 ProjectionsDialog dialogProjections (theScanner, rProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(m_frame));
565 for (int iView = 0; iView < rProj.nView(); iView++) {
568 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
569 pProjectionDoc->DeleteAllViews();
574 while (dialogProjections.isPaused()) {
580 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), rProj.nView() + 1, m_frame, wxPD_CAN_ABORT);
581 for (int i = 0; i < rProj.nView(); i++) {
582 theScanner.collectProjections (rProj, rPhantom, i, 1, true, m_iDefaultTrace);
583 if (! dlgProgress.Update (i+1)) {
584 pProjectionDoc->DeleteAllViews();
590 std::ostringstream os;
591 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();
592 rProj.setRemark (os.str());
593 *theApp->getLog() << os.str().c_str() << "\n";
597 ProjectionFileView* projView = dynamic_cast<ProjectionFileView*>(pProjectionDoc->GetFirstView());
\r
599 projView->getFrame()->SetFocus();
\r
600 projView->OnUpdate (projView, NULL);
\r
602 if (wxView* pView = pProjectionDoc->GetFirstView()) {
603 if (wxFrame* pFrame = pView->GetFrame()) {
607 theApp->getDocManager()->ActivateView (pView, true, false);
610 pProjectionDoc->Modify(true);
611 pProjectionDoc->UpdateAllViews(this);
618 PhantomView::OnRasterize (wxCommandEvent& event)
620 DialogGetRasterParameters dialogRaster (m_frame, 256, 256, 1);
621 int retVal = dialogRaster.ShowModal();
622 if (retVal == wxID_OK) {
623 int xSize = dialogRaster.getXSize();
624 int ySize = dialogRaster.getYSize();
625 int nSamples = dialogRaster.getNSamples();
628 if (xSize > 0 && ySize > 0) {
629 const Phantom& rPhantom = GetDocument()->getPhantom();
630 ImageFileDocument* pRasterDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
631 ImageFile& imageFile = pRasterDoc->getImageFile();
633 imageFile.setArraySize (xSize, ySize);
634 wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"), imageFile.nx() + 1, m_frame, wxPD_CAN_ABORT);
635 for (unsigned int i = 0; i < imageFile.nx(); i++) {
636 rPhantom.convertToImagefile (imageFile, nSamples, Trace::TRACE_NONE, i, 1, true);
637 if (! dlgProgress.Update(i+1)) {
638 pRasterDoc->DeleteAllViews();
642 pRasterDoc->Modify(true);
643 pRasterDoc->UpdateAllViews(this);
644 ImageFileView* rasterView = dynamic_cast<ImageFileView*>(pRasterDoc->GetFirstView());
\r
646 rasterView->getFrame()->SetFocus();
\r
647 rasterView->OnUpdate (rasterView, NULL);
\r
650 std::ostringstream os;
651 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << xSize << ", YSize=" << ySize << ", nSamples=" << nSamples << "\n";
652 *theApp->getLog() << os.str().c_str();
659 PhantomView::CreateCanvas (wxView *view, wxFrame *parent)
661 PhantomCanvas* pCanvas;
663 parent->GetClientSize(&width, &height);
665 pCanvas = new PhantomCanvas (dynamic_cast<PhantomView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
667 pCanvas->SetBackgroundColour(*wxWHITE);
674 PhantomView::CreateChildFrame(wxDocument *doc, wxView *view)
676 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
678 wxMenu *file_menu = new wxMenu;
680 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
681 file_menu->Append(wxID_OPEN, "&Open...");
682 file_menu->Append(wxID_CLOSE, "&Close");
684 file_menu->AppendSeparator();
685 file_menu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties");
687 file_menu->AppendSeparator();
688 file_menu->Append(wxID_PRINT, "&Print...");
689 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
690 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
692 wxMenu *process_menu = new wxMenu;
693 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...");
694 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...");
696 wxMenu *help_menu = new wxMenu;
697 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
698 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
700 wxMenuBar *menu_bar = new wxMenuBar;
702 menu_bar->Append(file_menu, "&File");
703 menu_bar->Append(process_menu, "&Process");
704 menu_bar->Append(help_menu, "&Help");
706 subframe->SetMenuBar(menu_bar);
708 subframe->Centre(wxBOTH);
715 PhantomView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
717 m_frame = CreateChildFrame(doc, this);
721 m_frame->GetClientSize(&width, &height);
722 m_frame->SetTitle("PhantomView");
723 m_canvas = CreateCanvas(this, m_frame);
726 int x, y; // X requires a forced resize
727 m_frame->GetSize(&x, &y);
728 m_frame->SetSize(-1, -1, x, y);
739 PhantomView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
746 PhantomView::OnClose (bool deleteWindow)
748 if (!GetDocument()->Close())
752 m_canvas->m_pView = NULL;
754 wxString s(wxTheApp->GetAppName());
756 m_frame->SetTitle(s);
769 PhantomView::OnDraw (wxDC* dc)
772 m_canvas->GetClientSize (&xsize, &ysize);
773 SGPDriver driver (dc, xsize, ysize);
775 const Phantom& rPhantom = GetDocument()->getPhantom();
776 sgp.setColor (C_RED);
782 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
783 : wxScrolledWindow(frame, -1, pos, size, style)
789 ProjectionFileCanvas::OnDraw(wxDC& dc)
792 m_pView->OnDraw(& dc);
795 // ProjectionFileView
797 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
799 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
800 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
801 EVT_MENU(PJMENU_PROCESS_RECONSTRUCT, ProjectionFileView::OnReconstruct)
804 ProjectionFileView::ProjectionFileView(void)
805 : wxView(), m_canvas(NULL), m_frame(NULL)
809 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
810 m_dDefaultFilterParam = 1.;
812 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
813 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
815 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
816 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
818 m_iDefaultZeropad = 1;
819 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF3;
820 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
821 m_iDefaultInterpParam = 1;
822 m_iDefaultTrace = Trace::TRACE_NONE;
825 ProjectionFileView::~ProjectionFileView(void)
830 ProjectionFileView::OnProperties (wxCommandEvent& event)
832 const Projections& rProj = GetDocument()->getProjections();
833 std::ostringstream os;
834 rProj.printScanInfo(os);
835 *theApp->getLog() << os.str().c_str();
836 wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
837 dialogMsg.ShowModal();
842 ProjectionFileView::OnReconstruct (wxCommandEvent& event)
844 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);
846 int retVal = dialogReconstruction.ShowModal();
847 if (retVal == wxID_OK) {
848 m_iDefaultNX = dialogReconstruction.getXSize();
849 m_iDefaultNY = dialogReconstruction.getYSize();
850 wxString optFilterName = dialogReconstruction.getFilterName();
851 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
852 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
853 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
854 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
855 m_iDefaultZeropad = dialogReconstruction.getZeropad();
856 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
857 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
858 wxString optInterpName = dialogReconstruction.getInterpName();
859 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
860 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
861 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
862 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
863 m_iDefaultTrace = dialogReconstruction.getTrace();
864 if (m_iDefaultNX > 0 && m_iDefaultNY > 0) {
865 ImageFileDocument* pReconDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
866 ImageFile& imageFile = pReconDoc->getImageFile();
867 const Projections& rProj = GetDocument()->getProjections();
868 imageFile.setArraySize (m_iDefaultNX, m_iDefaultNY);
870 if (m_iDefaultFilterMethod != ProcessSignal::FILTER_METHOD_CONVOLUTION && m_iDefaultFilterGeneration == ProcessSignal::FILTER_GENERATION_DIRECT && rProj.geometry() != Scanner::GEOMETRY_PARALLEL) {
871 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);
875 SGPDriver* pSGPDriver = NULL;
877 wxMemoryDC* pDCPlot = NULL;
879 if (m_iDefaultTrace >= Trace::TRACE_PLOT) {
880 bitmap.Create (500, 500);
881 pDCPlot = new wxMemoryDC;
882 pDCPlot->SelectObject (bitmap);
883 pSGPDriver = new SGPDriver (dynamic_cast<wxDC*>pDCPlot, 500, 500);
884 pSGP = new SGP (*pSGPDriver);
886 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, pSGP);
889 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);
893 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
894 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstruct, rProj, imageFile, m_iDefaultTrace, m_frame);
895 for (int iView = 0; iView < rProj.nView(); iView++) {
898 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView)) {
899 delete pDlgReconstruct;
901 pReconDoc->DeleteAllViews();
906 while (pDlgReconstruct->isPaused()) {
911 delete pDlgReconstruct;
913 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, m_frame, wxPD_CAN_ABORT);
914 for (int i = 0; i < rProj.nView(); i++) {
915 pReconstruct->reconstructView (i, 1);
916 if (! dlgProgress.Update(i + 1)) {
918 pReconDoc->DeleteAllViews();
924 pReconDoc->Modify(true);
925 pReconDoc->UpdateAllViews(this);
926 ImageFileView* rasterView = dynamic_cast<ImageFileView*>(pReconDoc->GetFirstView());
\r
928 rasterView->getFrame()->SetFocus();
\r
929 rasterView->OnUpdate (rasterView, NULL);
\r
931 std::ostringstream os;
932 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();
933 *theApp->getLog() << os.str().c_str() << "\n";
934 imageFile.labelAdd (rProj.getLabel());
935 imageFile.labelAdd (Array2dFileLabel::L_HISTORY, os.str().c_str(), timerRecon.timerEnd());
941 ProjectionFileCanvas*
942 ProjectionFileView::CreateCanvas (wxView *view, wxFrame *parent)
944 ProjectionFileCanvas* pCanvas;
946 parent->GetClientSize(&width, &height);
948 pCanvas = new ProjectionFileCanvas (dynamic_cast<ProjectionFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
950 pCanvas->SetScrollbars(20, 20, 50, 50);
951 pCanvas->SetBackgroundColour(*wxWHITE);
958 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
960 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
962 wxMenu *file_menu = new wxMenu;
964 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
965 file_menu->Append(wxID_OPEN, "&Open...");
966 file_menu->Append(wxID_SAVE, "&Save");
967 file_menu->Append(wxID_SAVEAS, "Save &As...");
968 file_menu->Append(wxID_CLOSE, "&Close");
970 file_menu->AppendSeparator();
971 file_menu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
973 file_menu->AppendSeparator();
974 file_menu->Append(wxID_PRINT, "&Print...");
975 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
976 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
978 wxMenu *process_menu = new wxMenu;
979 process_menu->Append(PJMENU_PROCESS_RECONSTRUCT, "R&econstruct...");
981 wxMenu *help_menu = new wxMenu;
982 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
983 help_menu->AppendSeparator();
984 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
986 wxMenuBar *menu_bar = new wxMenuBar;
988 menu_bar->Append(file_menu, "&File");
989 menu_bar->Append(process_menu, "&Process");
990 menu_bar->Append(help_menu, "&Help");
992 subframe->SetMenuBar(menu_bar);
994 subframe->Centre(wxBOTH);
1001 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
1003 m_frame = CreateChildFrame(doc, this);
1007 m_frame->GetClientSize(&width, &height);
1008 m_frame->SetTitle("ProjectionFileView");
1009 m_canvas = CreateCanvas(this, m_frame);
1012 int x, y; // X requires a forced resize
1013 m_frame->GetSize(&x, &y);
1014 m_frame->SetSize(-1, -1, x, y);
1017 m_frame->Show(true);
1024 ProjectionFileView::OnDraw (wxDC* dc)
1027 dc->DrawBitmap (m_bitmap, 0, 0, false);
1032 ProjectionFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
1034 const Projections& rProj = GetDocument()->getProjections();
1035 const int nDet = rProj.nDet();
1036 const int nView = rProj.nView();
1037 if (nDet != 0 && nView != 0) {
1038 const DetectorArray& detarray = rProj.getDetectorArray(0);
1039 const DetectorValue* detval = detarray.detValues();
1040 double min = detval[0];
1041 double max = detval[0];
1042 for (int iy = 0; iy < nView; iy++) {
1043 const DetectorArray& detarray = rProj.getDetectorArray(iy);
1044 const DetectorValue* detval = detarray.detValues();
1045 for (int ix = 0; ix < nDet; ix++) {
1046 if (min > detval[ix])
1048 else if (max < detval[ix])
1053 unsigned char* imageData = new unsigned char [nDet * nView * 3];
1054 double scale = (max - min) / 255;
1055 for (int iy2 = 0; iy2 < nView; iy2++) {
1056 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
1057 const DetectorValue* detval = detarray.detValues();
1058 for (int ix = 0; ix < nDet; ix++) {
1059 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
1060 intensity = clamp(intensity, 0, 255);
1061 int baseAddr = (iy2 * nDet + ix) * 3;
1062 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
1065 wxImage image (nDet, nView, imageData, true);
1066 m_bitmap = image.ConvertToBitmap();
1070 xSize = clamp (xSize, 0, 800);
1071 ySize = clamp (ySize, 0, 800);
1072 m_frame->SetClientSize (xSize, ySize);
1073 m_canvas->SetScrollbars (20, 20, nDet/20, nView/20);
1077 m_canvas->Refresh();
1081 ProjectionFileView::OnClose (bool deleteWindow)
1083 if (!GetDocument()->Close())
1087 m_canvas->m_pView = NULL;
1089 wxString s(wxTheApp->GetAppName());
1091 m_frame->SetTitle(s);
1106 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1107 : wxScrolledWindow(frame, -1, pos, size, style)
1113 PlotFileCanvas::OnDraw(wxDC& dc)
1116 m_pView->OnDraw(& dc);
1121 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
1123 BEGIN_EVENT_TABLE(PlotFileView, wxView)
1124 EVT_MENU(PJMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
1127 PlotFileView::PlotFileView(void)
1128 : wxView(), m_canvas(NULL), m_frame(NULL)
1132 PlotFileView::~PlotFileView(void)
1137 PlotFileView::OnProperties (wxCommandEvent& event)
1139 const PlotFile& rProj = GetDocument()->getPlotFile();
1140 std::ostringstream os;
\r
1141 os << "Columns: " << rProj.getNumColumns() << ", Records: " << rProj.getNumRecords() << "\n";
1142 *theApp->getLog() << os.str().c_str();
1143 wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
1144 dialogMsg.ShowModal();
1149 PlotFileView::CreateCanvas (wxView *view, wxFrame *parent)
1151 PlotFileCanvas* pCanvas;
1153 parent->GetClientSize(&width, &height);
1155 pCanvas = new PlotFileCanvas (dynamic_cast<PlotFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
1157 pCanvas->SetBackgroundColour(*wxWHITE);
1164 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
1166 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
1168 wxMenu *file_menu = new wxMenu;
1170 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
1171 file_menu->Append(wxID_OPEN, "&Open...");
1172 file_menu->Append(wxID_SAVE, "&Save");
1173 file_menu->Append(wxID_SAVEAS, "Save &As...");
1174 file_menu->Append(wxID_CLOSE, "&Close");
1176 file_menu->AppendSeparator();
1177 file_menu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
1179 file_menu->AppendSeparator();
1180 file_menu->Append(wxID_PRINT, "&Print...");
1181 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
1182 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
1184 wxMenu *help_menu = new wxMenu;
1185 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
1186 help_menu->AppendSeparator();
1187 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
1189 wxMenuBar *menu_bar = new wxMenuBar;
1191 menu_bar->Append(file_menu, "&File");
1192 menu_bar->Append(help_menu, "&Help");
1194 subframe->SetMenuBar(menu_bar);
1196 subframe->Centre(wxBOTH);
1203 PlotFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
1205 m_frame = CreateChildFrame(doc, this);
1209 m_frame->GetClientSize(&width, &height);
1210 m_frame->SetTitle ("Plot File");
1211 m_canvas = CreateCanvas (this, m_frame);
1214 int x, y; // X requires a forced resize
1215 m_frame->GetSize(&x, &y);
1216 m_frame->SetSize(-1, -1, x, y);
1219 m_frame->Show(true);
1226 PlotFileView::OnDraw (wxDC* dc)
1228 const PlotFile& rPlot = GetDocument()->getPlotFile();
\r
1229 const int iNColumns = rPlot.getNumColumns();
\r
1230 const int iNRecords = rPlot.getNumRecords();
\r
1232 if (iNColumns > 0 && iNRecords > 0) {
\r
1234 m_canvas->GetClientSize (&xsize, &ysize);
\r
1235 SGPDriver driver (dc, xsize, ysize);
\r
1237 const PlotFile& rPhantom = GetDocument()->getPlotFile();
\r
1238 EZPlot plot (sgp);
\r
1240 if (! rPlot.getTitle().empty()) {
\r
1241 std::string s("title ");
\r
1242 s += rPlot.getTitle();
\r
1245 if (! rPlot.getXLabel().empty()) {
\r
1246 std::string s("xlabel ");
\r
1247 s += rPlot.getXLabel();
\r
1250 if (! rPlot.getYLabel().empty()) {
\r
1251 std::string s("ylabel ");
\r
1252 s += rPlot.getYLabel();
\r
1256 plot.ezset("box");
\r
1257 plot.ezset("grid");
\r
1259 double* pdXaxis = new double [iNRecords];
\r
1260 rPlot.getColumn (0, pdXaxis);
\r
1262 double* pdY = new double [iNRecords];
\r
1263 for (int iCol = 1; iCol < iNColumns; iCol++) {
\r
1264 rPlot.getColumn (iCol, pdY);
\r
1265 plot.addCurve (pdXaxis, pdY, iNRecords);
\r
1277 PlotFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
1280 m_canvas->Refresh();
1284 PlotFileView::OnClose (bool deleteWindow)
1286 if (!GetDocument()->Close())
1290 m_canvas->m_pView = NULL;
1292 wxString s(wxTheApp->GetAppName());
1294 m_frame->SetTitle(s);