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.25 2000/12/16 06:12:47 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"
54 #include "backprojectors.h"
55 #include "reconstruct.h"
60 BEGIN_EVENT_TABLE(ImageFileCanvas, wxScrolledWindow)
61 EVT_MOUSE_EVENTS(ImageFileCanvas::OnMouseEvent)
65 ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
66 : wxScrolledWindow(frame, -1, pos, size, style)
72 ImageFileCanvas::OnDraw(wxDC& dc)
75 m_pView->OnDraw(& dc);
79 ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
87 wxPoint pt(event.GetLogicalPosition(dc));
89 if (event.LeftIsDown()) {
90 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
91 ImageFileArrayConst v = rIF.getArray();
95 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
96 std::ostringstream os;
97 os << "Image value (" << pt.x << "," << pt.y << ") = " << v[pt.x][ny - 1 - pt.y] << "\n";
98 *theApp->getLog() << os.str().c_str();
100 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << pt.y << ")\n";
108 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
110 BEGIN_EVENT_TABLE(ImageFileView, wxView)
111 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
112 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
113 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
116 ImageFileView::ImageFileView(void)
117 : wxView(), m_canvas(NULL), m_frame(NULL), m_bMinSpecified(false), m_bMaxSpecified(false)
121 ImageFileView::~ImageFileView(void)
126 ImageFileView::OnProperties (wxCommandEvent& event)
128 double min, max, mean, mode, median, stddev;
129 const ImageFile& rIF = GetDocument()->getImageFile();
130 if (rIF.nx() == 0 || rIF.ny() == 0)
131 *theApp->getLog() << "Properties: empty imagefile\n";
133 const std::string& rFilename = rIF.getFilename();
134 rIF.statistics (min, max, mean, mode, median, stddev);
135 std::ostringstream os;
136 os << "file: " << rFilename << "\nmin: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
137 *theApp->getLog() << os.str().c_str();
138 wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
139 dialogMsg.ShowModal();
144 ImageFileView::OnScaleAuto (wxCommandEvent& event)
146 const ImageFile& rIF = GetDocument()->getImageFile();
147 DialogAutoScaleParameters dialogAutoScale (m_frame, rIF, m_dAutoScaleFactor);
148 int iRetVal = dialogAutoScale.ShowModal();
149 if (iRetVal == wxID_OK) {
150 m_bMinSpecified = true;
151 m_bMaxSpecified = true;
153 dialogAutoScale.getMinMax (&dMin, &dMax);
156 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
157 OnUpdate (this, NULL);
162 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
164 const ImageFile& rIF = GetDocument()->getImageFile();
166 if (! m_bMinSpecified && ! m_bMaxSpecified)
167 rIF.getMinMax (min, max);
174 DialogGetImageMinMax dialogMinMax (m_frame, rIF, min, max);
175 int retVal = dialogMinMax.ShowModal();
176 if (retVal == wxID_OK) {
177 m_bMinSpecified = true;
178 m_bMaxSpecified = true;
179 m_dMinPixel = dialogMinMax.getMinimum();
180 m_dMaxPixel = dialogMinMax.getMaximum();
181 OnUpdate (this, NULL);
187 ImageFileView::CreateCanvas (wxView *view, wxFrame *parent)
189 ImageFileCanvas* pCanvas;
191 parent->GetClientSize(&width, &height);
193 pCanvas = new ImageFileCanvas (dynamic_cast<ImageFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
195 pCanvas->SetScrollbars(20, 20, 50, 50);
196 pCanvas->SetBackgroundColour(*wxWHITE);
203 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
205 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
207 wxMenu *file_menu = new wxMenu;
209 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
210 file_menu->Append(wxID_OPEN, "&Open...");
211 file_menu->Append(wxID_SAVE, "&Save");
212 file_menu->Append(wxID_SAVEAS, "Save &As...");
213 file_menu->Append(wxID_CLOSE, "&Close");
215 file_menu->AppendSeparator();
216 file_menu->Append(IFMENU_FILE_PROPERTIES, "P&roperties");
218 file_menu->AppendSeparator();
219 file_menu->Append(wxID_PRINT, "&Print...");
220 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
221 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
223 wxMenu *view_menu = new wxMenu;
224 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...");
225 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...");
227 wxMenu *help_menu = new wxMenu;
228 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
230 wxMenuBar *menu_bar = new wxMenuBar;
232 menu_bar->Append(file_menu, "&File");
233 menu_bar->Append(view_menu, "&View");
234 menu_bar->Append(help_menu, "&Help");
236 subframe->SetMenuBar(menu_bar);
238 subframe->Centre(wxBOTH);
245 ImageFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
247 m_frame = CreateChildFrame(doc, this);
250 m_bMinSpecified = false;
251 m_bMaxSpecified = false;
252 m_dAutoScaleFactor = 1.;
255 m_frame->GetClientSize(&width, &height);
256 m_frame->SetTitle("ImageFileView");
257 m_canvas = CreateCanvas(this, m_frame);
260 int x, y; // X requires a forced resize
261 m_frame->GetSize(&x, &y);
262 m_frame->SetSize(-1, -1, x, y);
272 ImageFileView::OnDraw (wxDC* dc)
275 dc->DrawBitmap(m_bitmap, 0, 0, false);
280 ImageFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
282 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
283 ImageFileArrayConst v = rIF.getArray();
286 if (v != NULL && nx != 0 && ny != 0) {
287 if (! m_bMinSpecified || ! m_bMaxSpecified) {
289 rIF.getMinMax (min, max);
290 if (! m_bMinSpecified)
292 if (! m_bMaxSpecified)
295 double scaleWidth = m_dMaxPixel - m_dMinPixel;
297 unsigned char* imageData = new unsigned char [nx * ny * 3];
298 for (int ix = 0; ix < nx; ix++) {
299 for (int iy = 0; iy < ny; iy++) {
300 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
301 int intensity = static_cast<int>(scaleValue + 0.5);
302 intensity = clamp (intensity, 0, 255);
303 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
304 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
307 wxImage image (nx, ny, imageData, true);
308 m_bitmap = image.ConvertToBitmap();
312 xSize = clamp (xSize, 0, 800);
313 ySize = clamp (ySize, 0, 800);
314 m_frame->SetClientSize (xSize, ySize);
315 m_canvas->SetScrollbars(20, 20, nx/20, ny/20);
316 m_canvas->SetBackgroundColour(*wxWHITE);
324 ImageFileView::OnClose (bool deleteWindow)
326 if (!GetDocument()->Close())
330 m_canvas->m_pView = NULL;
332 wxString s(theApp->GetAppName());
334 m_frame->SetTitle(s);
350 PhantomCanvas::PhantomCanvas (PhantomView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
351 : wxScrolledWindow(frame, -1, pos, size, style)
357 PhantomCanvas::OnDraw(wxDC& dc)
360 m_pView->OnDraw(& dc);
366 IMPLEMENT_DYNAMIC_CLASS(PhantomView, wxView)
368 BEGIN_EVENT_TABLE(PhantomView, wxView)
369 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomView::OnProperties)
370 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomView::OnRasterize)
371 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomView::OnProjections)
374 PhantomView::PhantomView(void)
375 : wxView(), m_canvas(NULL), m_frame(NULL)
377 m_iDefaultNDet = 367;
378 m_iDefaultNView = 320;
379 m_iDefaultNSample = 2;
380 m_dDefaultRotation = 2;
381 m_dDefaultFocalLength = 2;
382 m_dDefaultFieldOfView = 1;
383 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
384 m_iDefaultTrace = Trace::TRACE_NONE;
387 PhantomView::~PhantomView(void)
392 PhantomView::OnProperties (wxCommandEvent& event)
394 const int idPhantom = GetDocument()->getPhantomID();
395 const wxString& namePhantom = GetDocument()->getPhantomName();
396 std::ostringstream os;
397 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")\n";
398 *theApp->getLog() << os.str().c_str();
400 const Phantom& rPhantom = GetDocument()->getPhantom();
407 PhantomView::OnProjections (wxCommandEvent& event)
409 DialogGetProjectionParameters dialogProjection (m_frame, m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView, m_iDefaultGeometry, m_iDefaultTrace);
410 int retVal = dialogProjection.ShowModal();
411 if (retVal == wxID_OK) {
412 m_iDefaultNDet = dialogProjection.getNDet();
413 m_iDefaultNView = dialogProjection.getNView();
414 m_iDefaultNSample = dialogProjection.getNSamples();
415 m_iDefaultTrace = dialogProjection.getTrace();
416 m_dDefaultRotation = dialogProjection.getRotAngle();
417 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
418 m_dDefaultFieldOfView = dialogProjection.getFieldOfViewRatio();
419 wxString sGeometry = dialogProjection.getGeometry();
420 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
422 if (m_iDefaultNDet > 0 && m_iDefaultNView > 0 && sGeometry != "") {
423 const Phantom& rPhantom = GetDocument()->getPhantom();
424 ProjectionFileDocument* pProjectionDoc = dynamic_cast<ProjectionFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.pj", wxDOC_SILENT));
425 Projections& rProj = pProjectionDoc->getProjections();
426 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView);
427 if (theScanner.fail()) {
428 *theApp->getLog() << "Failed making scanner: " << theScanner.failMessage().c_str() << "\n";
431 rProj.initFromScanner (theScanner);
432 m_dDefaultRotation /= PI; // convert back to PI units
434 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
435 ProjectionsDialog dialogProjections (theScanner, rProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(m_frame));
436 for (int iView = 0; iView < rProj.nView(); iView++) {
439 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
440 pProjectionDoc->DeleteAllViews();
445 while (dialogProjections.isPaused()) {
451 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), rProj.nView() + 1, m_frame, wxPD_CAN_ABORT);
452 for (int i = 0; i < rProj.nView(); i++) {
453 theScanner.collectProjections (rProj, rPhantom, i, 1, true, m_iDefaultTrace);
454 if (! dlgProgress.Update (i+1)) {
455 pProjectionDoc->DeleteAllViews();
461 std::ostringstream os;
462 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() << "\n";
463 rProj.setRemark (os.str());
464 *theApp->getLog() << os.str().c_str();
468 if (wxView* pView = pProjectionDoc->GetFirstView()) {
469 if (wxFrame* pFrame = pView->GetFrame()) {
473 theApp->getDocManager()->ActivateView (pView, true, false);
476 pProjectionDoc->Modify(true);
477 pProjectionDoc->UpdateAllViews(this);
484 PhantomView::OnRasterize (wxCommandEvent& event)
486 DialogGetRasterParameters dialogRaster (m_frame, 256, 256, 1);
487 int retVal = dialogRaster.ShowModal();
488 if (retVal == wxID_OK) {
489 int xSize = dialogRaster.getXSize();
490 int ySize = dialogRaster.getYSize();
491 int nSamples = dialogRaster.getNSamples();
494 if (xSize > 0 && ySize > 0) {
495 const Phantom& rPhantom = GetDocument()->getPhantom();
496 ImageFileDocument* pRasterDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
497 ImageFile& imageFile = pRasterDoc->getImageFile();
499 imageFile.setArraySize (xSize, ySize);
500 wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"), imageFile.nx() + 1, m_frame, wxPD_CAN_ABORT);
501 for (unsigned int i = 0; i < imageFile.nx(); i++) {
502 rPhantom.convertToImagefile (imageFile, nSamples, Trace::TRACE_NONE, i, 1, true);
503 if (! dlgProgress.Update(i+1)) {
504 pRasterDoc->DeleteAllViews();
508 pRasterDoc->Modify(true);
509 pRasterDoc->UpdateAllViews(this);
511 std::ostringstream os;
512 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << xSize << ", YSize=" << ySize << ", nSamples=" << nSamples << "\n";
513 *theApp->getLog() << os.str().c_str();
520 PhantomView::CreateCanvas (wxView *view, wxFrame *parent)
522 PhantomCanvas* pCanvas;
524 parent->GetClientSize(&width, &height);
526 pCanvas = new PhantomCanvas (dynamic_cast<PhantomView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
528 pCanvas->SetBackgroundColour(*wxWHITE);
535 PhantomView::CreateChildFrame(wxDocument *doc, wxView *view)
537 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
539 wxMenu *file_menu = new wxMenu;
541 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
542 file_menu->Append(wxID_OPEN, "&Open...");
543 file_menu->Append(wxID_CLOSE, "&Close");
545 file_menu->AppendSeparator();
546 file_menu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties");
548 file_menu->AppendSeparator();
549 file_menu->Append(wxID_PRINT, "&Print...");
550 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
551 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
553 wxMenu *process_menu = new wxMenu;
554 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...");
555 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...");
557 wxMenu *help_menu = new wxMenu;
558 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
559 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
561 wxMenuBar *menu_bar = new wxMenuBar;
563 menu_bar->Append(file_menu, "&File");
564 menu_bar->Append(process_menu, "&Process");
565 menu_bar->Append(help_menu, "&Help");
567 subframe->SetMenuBar(menu_bar);
569 subframe->Centre(wxBOTH);
576 PhantomView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
578 m_frame = CreateChildFrame(doc, this);
582 m_frame->GetClientSize(&width, &height);
583 m_frame->SetTitle("PhantomView");
584 m_canvas = CreateCanvas(this, m_frame);
587 int x, y; // X requires a forced resize
588 m_frame->GetSize(&x, &y);
589 m_frame->SetSize(-1, -1, x, y);
600 PhantomView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
607 PhantomView::OnClose (bool deleteWindow)
609 if (!GetDocument()->Close())
613 m_canvas->m_pView = NULL;
615 wxString s(wxTheApp->GetAppName());
617 m_frame->SetTitle(s);
630 PhantomView::OnDraw (wxDC* dc)
633 m_canvas->GetClientSize (&xsize, &ysize);
634 SGPDriver driver (dc, xsize, ysize);
636 const Phantom& rPhantom = GetDocument()->getPhantom();
637 sgp.setColor (C_RED);
643 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
644 : wxScrolledWindow(frame, -1, pos, size, style)
650 ProjectionFileCanvas::OnDraw(wxDC& dc)
653 m_pView->OnDraw(& dc);
656 // ProjectionFileView
658 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
660 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
661 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
662 EVT_MENU(PJMENU_PROCESS_RECONSTRUCT, ProjectionFileView::OnReconstruct)
665 ProjectionFileView::ProjectionFileView(void)
666 : wxView(), m_canvas(NULL), m_frame(NULL)
670 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
671 m_dDefaultFilterParam = 1.;
673 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
674 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
676 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
677 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
679 m_iDefaultZeropad = 1;
680 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF3;
681 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
682 m_iDefaultInterpParam = 1;
683 m_iDefaultTrace = Trace::TRACE_NONE;
686 ProjectionFileView::~ProjectionFileView(void)
691 ProjectionFileView::OnProperties (wxCommandEvent& event)
693 const Projections& rProj = GetDocument()->getProjections();
694 std::ostringstream os;
695 rProj.printScanInfo(os);
696 *theApp->getLog() << os.str().c_str();
697 wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
698 dialogMsg.ShowModal();
703 ProjectionFileView::OnReconstruct (wxCommandEvent& event)
705 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);
707 int retVal = dialogReconstruction.ShowModal();
708 if (retVal == wxID_OK) {
709 m_iDefaultNX = dialogReconstruction.getXSize();
710 m_iDefaultNY = dialogReconstruction.getYSize();
711 wxString optFilterName = dialogReconstruction.getFilterName();
712 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
713 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
714 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
715 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
716 m_iDefaultZeropad = dialogReconstruction.getZeropad();
717 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
718 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
719 wxString optInterpName = dialogReconstruction.getInterpName();
720 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
721 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
722 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
723 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
724 m_iDefaultTrace = dialogReconstruction.getTrace();
725 if (m_iDefaultNX > 0 && m_iDefaultNY > 0) {
726 ImageFileDocument* pReconDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
727 ImageFile& imageFile = pReconDoc->getImageFile();
728 const Projections& rProj = GetDocument()->getProjections();
729 imageFile.setArraySize (m_iDefaultNX, m_iDefaultNY);
732 if (m_iDefaultFilterMethod != ProcessSignal::FILTER_METHOD_CONVOLUTION && m_iDefaultFilterGeneration == ProcessSignal::FILTER_GENERATION_DIRECT && rProj.geometry() != Scanner::GEOMETRY_PARALLEL) {
733 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);
737 SGPDriver* pSGPDriver = NULL;
739 wxMemoryDC* pDCPlot = NULL;
741 if (m_iDefaultTrace >= Trace::TRACE_PLOT) {
742 bitmap.Create (500, 500);
743 pDCPlot = new wxMemoryDC;
744 pDCPlot->SelectObject (bitmap);
745 pSGPDriver = new SGPDriver (dynamic_cast<wxDC*>pDCPlot, 500, 500);
746 pSGP = new SGP (*pSGPDriver);
748 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);
751 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);
754 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
755 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstruct, rProj, imageFile, m_iDefaultTrace, m_frame);
756 for (int iView = 0; iView < rProj.nView(); iView++) {
759 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView)) {
760 delete pDlgReconstruct;
762 pReconDoc->DeleteAllViews();
767 while (pDlgReconstruct->isPaused()) {
772 delete pDlgReconstruct;
774 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, m_frame, wxPD_CAN_ABORT);
775 for (int i = 0; i < rProj.nView(); i++) {
776 pReconstruct->reconstructView (i, 1);
777 if (! dlgProgress.Update(i + 1)) {
779 pReconDoc->DeleteAllViews();
785 pReconDoc->Modify(true);
786 pReconDoc->UpdateAllViews(this);
787 std::ostringstream os;
788 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() << "\n";
789 *theApp->getLog() << os.str().c_str();
790 imageFile.labelAdd (rProj.getLabel());
791 imageFile.labelAdd (Array2dFileLabel::L_HISTORY, os.str().c_str(), timerRecon.timerEnd());
797 ProjectionFileCanvas*
798 ProjectionFileView::CreateCanvas (wxView *view, wxFrame *parent)
800 ProjectionFileCanvas* pCanvas;
802 parent->GetClientSize(&width, &height);
804 pCanvas = new ProjectionFileCanvas (dynamic_cast<ProjectionFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
806 pCanvas->SetScrollbars(20, 20, 50, 50);
807 pCanvas->SetBackgroundColour(*wxWHITE);
814 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
816 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
818 wxMenu *file_menu = new wxMenu;
820 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
821 file_menu->Append(wxID_OPEN, "&Open...");
822 file_menu->Append(wxID_SAVE, "&Save");
823 file_menu->Append(wxID_SAVEAS, "Save &As...");
824 file_menu->Append(wxID_CLOSE, "&Close");
826 file_menu->AppendSeparator();
827 file_menu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
829 file_menu->AppendSeparator();
830 file_menu->Append(wxID_PRINT, "&Print...");
831 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
832 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
834 wxMenu *process_menu = new wxMenu;
835 process_menu->Append(PJMENU_PROCESS_RECONSTRUCT, "R&econstruct...");
837 wxMenu *help_menu = new wxMenu;
838 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
839 help_menu->AppendSeparator();
840 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
842 wxMenuBar *menu_bar = new wxMenuBar;
844 menu_bar->Append(file_menu, "&File");
845 menu_bar->Append(process_menu, "&Process");
846 menu_bar->Append(help_menu, "&Help");
848 subframe->SetMenuBar(menu_bar);
850 subframe->Centre(wxBOTH);
857 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
859 m_frame = CreateChildFrame(doc, this);
863 m_frame->GetClientSize(&width, &height);
864 m_frame->SetTitle("ProjectionFileView");
865 m_canvas = CreateCanvas(this, m_frame);
868 int x, y; // X requires a forced resize
869 m_frame->GetSize(&x, &y);
870 m_frame->SetSize(-1, -1, x, y);
880 ProjectionFileView::OnDraw (wxDC* dc)
883 dc->DrawBitmap (m_bitmap, 0, 0, false);
888 ProjectionFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
890 const Projections& rProj = GetDocument()->getProjections();
891 const int nDet = rProj.nDet();
892 const int nView = rProj.nView();
893 if (nDet != 0 && nView != 0) {
894 const DetectorArray& detarray = rProj.getDetectorArray(0);
895 const DetectorValue* detval = detarray.detValues();
896 double min = detval[0];
897 double max = detval[0];
898 for (int iy = 0; iy < nView; iy++) {
899 const DetectorArray& detarray = rProj.getDetectorArray(iy);
900 const DetectorValue* detval = detarray.detValues();
901 for (int ix = 0; ix < nDet; ix++) {
902 if (min > detval[ix])
904 else if (max < detval[ix])
909 unsigned char* imageData = new unsigned char [nDet * nView * 3];
910 double scale = (max - min) / 255;
911 for (int iy2 = 0; iy2 < nView; iy2++) {
912 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
913 const DetectorValue* detval = detarray.detValues();
914 for (int ix = 0; ix < nDet; ix++) {
915 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
916 intensity = clamp(intensity, 0, 255);
917 int baseAddr = (iy2 * nDet + ix) * 3;
918 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
921 wxImage image (nDet, nView, imageData, true);
922 m_bitmap = image.ConvertToBitmap();
926 xSize = clamp (xSize, 0, 800);
927 ySize = clamp (ySize, 0, 800);
928 m_frame->SetClientSize (xSize, ySize);
929 m_canvas->SetScrollbars (20, 20, nDet/20, nView/20);
937 ProjectionFileView::OnClose (bool deleteWindow)
939 if (!GetDocument()->Close())
943 m_canvas->m_pView = NULL;
945 wxString s(wxTheApp->GetAppName());
947 m_frame->SetTitle(s);