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.28 2000/12/17 23:30:48 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)
78 ImageFileCanvas::OnDraw(wxDC& dc)
81 m_pView->OnDraw(& dc);
85 ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
93 wxPoint pt(event.GetLogicalPosition(dc));
95 if (event.LeftIsDown()) {
96 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
97 ImageFileArrayConst v = rIF.getArray();
101 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
102 std::ostringstream os;
103 os << "Image value (" << pt.x << "," << pt.y << ") = " << v[pt.x][ny - 1 - pt.y] << "\n";
104 *theApp->getLog() << os.str().c_str();
106 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << pt.y << ")\n";
114 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
116 BEGIN_EVENT_TABLE(ImageFileView, wxView)
117 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
118 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
119 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
122 ImageFileView::ImageFileView(void)
123 : wxView(), m_canvas(NULL), m_frame(NULL), m_bMinSpecified(false), m_bMaxSpecified(false)
127 ImageFileView::~ImageFileView(void)
132 ImageFileView::OnProperties (wxCommandEvent& event)
134 double min, max, mean, mode, median, stddev;
135 const ImageFile& rIF = GetDocument()->getImageFile();
136 if (rIF.nx() == 0 || rIF.ny() == 0)
137 *theApp->getLog() << "Properties: empty imagefile\n";
139 const std::string& rFilename = rIF.getFilename();
140 rIF.statistics (min, max, mean, mode, median, stddev);
141 std::ostringstream os;
142 os << "file: " << rFilename << "\nmin: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
143 *theApp->getLog() << os.str().c_str();
144 wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
145 dialogMsg.ShowModal();
150 ImageFileView::OnScaleAuto (wxCommandEvent& event)
152 const ImageFile& rIF = GetDocument()->getImageFile();
153 DialogAutoScaleParameters dialogAutoScale (m_frame, rIF, m_dAutoScaleFactor);
154 int iRetVal = dialogAutoScale.ShowModal();
155 if (iRetVal == wxID_OK) {
156 m_bMinSpecified = true;
157 m_bMaxSpecified = true;
159 dialogAutoScale.getMinMax (&dMin, &dMax);
162 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
163 OnUpdate (this, NULL);
168 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
170 const ImageFile& rIF = GetDocument()->getImageFile();
172 if (! m_bMinSpecified && ! m_bMaxSpecified)
173 rIF.getMinMax (min, max);
180 DialogGetImageMinMax dialogMinMax (m_frame, rIF, min, max);
181 int retVal = dialogMinMax.ShowModal();
182 if (retVal == wxID_OK) {
183 m_bMinSpecified = true;
184 m_bMaxSpecified = true;
185 m_dMinPixel = dialogMinMax.getMinimum();
186 m_dMaxPixel = dialogMinMax.getMaximum();
187 OnUpdate (this, NULL);
193 ImageFileView::CreateCanvas (wxView *view, wxFrame *parent)
195 ImageFileCanvas* pCanvas;
197 parent->GetClientSize(&width, &height);
199 pCanvas = new ImageFileCanvas (dynamic_cast<ImageFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
201 pCanvas->SetScrollbars(20, 20, 50, 50);
202 pCanvas->SetBackgroundColour(*wxWHITE);
209 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
211 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
213 wxMenu *file_menu = new wxMenu;
215 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
216 file_menu->Append(wxID_OPEN, "&Open...");
217 file_menu->Append(wxID_SAVE, "&Save");
218 file_menu->Append(wxID_SAVEAS, "Save &As...");
219 file_menu->Append(wxID_CLOSE, "&Close");
221 file_menu->AppendSeparator();
222 file_menu->Append(IFMENU_FILE_PROPERTIES, "P&roperties");
224 file_menu->AppendSeparator();
225 file_menu->Append(wxID_PRINT, "&Print...");
226 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
227 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
229 wxMenu *view_menu = new wxMenu;
230 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...");
231 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...");
233 wxMenu *help_menu = new wxMenu;
234 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
236 wxMenuBar *menu_bar = new wxMenuBar;
238 menu_bar->Append(file_menu, "&File");
239 menu_bar->Append(view_menu, "&View");
240 menu_bar->Append(help_menu, "&Help");
242 subframe->SetMenuBar(menu_bar);
244 subframe->Centre(wxBOTH);
251 ImageFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
253 m_frame = CreateChildFrame(doc, this);
256 m_bMinSpecified = false;
257 m_bMaxSpecified = false;
258 m_dAutoScaleFactor = 1.;
261 m_frame->GetClientSize(&width, &height);
262 m_frame->SetTitle("ImageFileView");
263 m_canvas = CreateCanvas(this, m_frame);
266 int x, y; // X requires a forced resize
267 m_frame->GetSize(&x, &y);
268 m_frame->SetSize(-1, -1, x, y);
278 ImageFileView::OnDraw (wxDC* dc)
281 dc->DrawBitmap(m_bitmap, 0, 0, false);
286 ImageFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
288 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
289 ImageFileArrayConst v = rIF.getArray();
292 if (v != NULL && nx != 0 && ny != 0) {
293 if (! m_bMinSpecified || ! m_bMaxSpecified) {
295 rIF.getMinMax (min, max);
296 if (! m_bMinSpecified)
298 if (! m_bMaxSpecified)
301 double scaleWidth = m_dMaxPixel - m_dMinPixel;
303 unsigned char* imageData = new unsigned char [nx * ny * 3];
304 for (int ix = 0; ix < nx; ix++) {
305 for (int iy = 0; iy < ny; iy++) {
306 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
307 int intensity = static_cast<int>(scaleValue + 0.5);
308 intensity = clamp (intensity, 0, 255);
309 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
310 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
313 wxImage image (nx, ny, imageData, true);
314 m_bitmap = image.ConvertToBitmap();
318 xSize = clamp (xSize, 0, 800);
319 ySize = clamp (ySize, 0, 800);
320 m_frame->SetClientSize (xSize, ySize);
321 m_canvas->SetScrollbars(20, 20, nx/20, ny/20);
322 m_canvas->SetBackgroundColour(*wxWHITE);
330 ImageFileView::OnClose (bool deleteWindow)
332 if (!GetDocument()->Close())
336 m_canvas->m_pView = NULL;
338 wxString s(theApp->GetAppName());
340 m_frame->SetTitle(s);
356 PhantomCanvas::PhantomCanvas (PhantomView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
357 : wxScrolledWindow(frame, -1, pos, size, style)
363 PhantomCanvas::OnDraw(wxDC& dc)
366 m_pView->OnDraw(& dc);
372 IMPLEMENT_DYNAMIC_CLASS(PhantomView, wxView)
374 BEGIN_EVENT_TABLE(PhantomView, wxView)
375 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomView::OnProperties)
376 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomView::OnRasterize)
377 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomView::OnProjections)
380 PhantomView::PhantomView(void)
381 : wxView(), m_canvas(NULL), m_frame(NULL)
383 m_iDefaultNDet = 367;
384 m_iDefaultNView = 320;
385 m_iDefaultNSample = 2;
386 m_dDefaultRotation = 2;
387 m_dDefaultFocalLength = 2;
388 m_dDefaultFieldOfView = 1;
389 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
390 m_iDefaultTrace = Trace::TRACE_NONE;
393 PhantomView::~PhantomView(void)
398 PhantomView::OnProperties (wxCommandEvent& event)
400 const int idPhantom = GetDocument()->getPhantomID();
401 const wxString& namePhantom = GetDocument()->getPhantomName();
402 std::ostringstream os;
403 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")\n";
404 *theApp->getLog() << os.str().c_str();
406 const Phantom& rPhantom = GetDocument()->getPhantom();
413 PhantomView::OnProjections (wxCommandEvent& event)
415 DialogGetProjectionParameters dialogProjection (m_frame, m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView, m_iDefaultGeometry, m_iDefaultTrace);
416 int retVal = dialogProjection.ShowModal();
417 if (retVal == wxID_OK) {
418 m_iDefaultNDet = dialogProjection.getNDet();
419 m_iDefaultNView = dialogProjection.getNView();
420 m_iDefaultNSample = dialogProjection.getNSamples();
421 m_iDefaultTrace = dialogProjection.getTrace();
422 m_dDefaultRotation = dialogProjection.getRotAngle();
423 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
424 m_dDefaultFieldOfView = dialogProjection.getFieldOfViewRatio();
425 wxString sGeometry = dialogProjection.getGeometry();
426 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
428 if (m_iDefaultNDet > 0 && m_iDefaultNView > 0 && sGeometry != "") {
429 const Phantom& rPhantom = GetDocument()->getPhantom();
430 ProjectionFileDocument* pProjectionDoc = dynamic_cast<ProjectionFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.pj", wxDOC_SILENT));
431 Projections& rProj = pProjectionDoc->getProjections();
432 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView);
433 if (theScanner.fail()) {
434 *theApp->getLog() << "Failed making scanner: " << theScanner.failMessage().c_str() << "\n";
437 rProj.initFromScanner (theScanner);
438 m_dDefaultRotation /= PI; // convert back to PI units
440 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
441 ProjectionsDialog dialogProjections (theScanner, rProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(m_frame));
442 for (int iView = 0; iView < rProj.nView(); iView++) {
445 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
446 pProjectionDoc->DeleteAllViews();
451 while (dialogProjections.isPaused()) {
457 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), rProj.nView() + 1, m_frame, wxPD_CAN_ABORT);
458 for (int i = 0; i < rProj.nView(); i++) {
459 theScanner.collectProjections (rProj, rPhantom, i, 1, true, m_iDefaultTrace);
460 if (! dlgProgress.Update (i+1)) {
461 pProjectionDoc->DeleteAllViews();
467 std::ostringstream os;
468 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();
469 rProj.setRemark (os.str());
470 *theApp->getLog() << os.str().c_str() << "\n";
474 if (wxView* pView = pProjectionDoc->GetFirstView()) {
475 if (wxFrame* pFrame = pView->GetFrame()) {
479 theApp->getDocManager()->ActivateView (pView, true, false);
482 pProjectionDoc->Modify(true);
483 pProjectionDoc->UpdateAllViews(this);
490 PhantomView::OnRasterize (wxCommandEvent& event)
492 DialogGetRasterParameters dialogRaster (m_frame, 256, 256, 1);
493 int retVal = dialogRaster.ShowModal();
494 if (retVal == wxID_OK) {
495 int xSize = dialogRaster.getXSize();
496 int ySize = dialogRaster.getYSize();
497 int nSamples = dialogRaster.getNSamples();
500 if (xSize > 0 && ySize > 0) {
501 const Phantom& rPhantom = GetDocument()->getPhantom();
502 ImageFileDocument* pRasterDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
503 ImageFile& imageFile = pRasterDoc->getImageFile();
505 imageFile.setArraySize (xSize, ySize);
506 wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"), imageFile.nx() + 1, m_frame, wxPD_CAN_ABORT);
507 for (unsigned int i = 0; i < imageFile.nx(); i++) {
508 rPhantom.convertToImagefile (imageFile, nSamples, Trace::TRACE_NONE, i, 1, true);
509 if (! dlgProgress.Update(i+1)) {
510 pRasterDoc->DeleteAllViews();
514 pRasterDoc->Modify(true);
515 pRasterDoc->UpdateAllViews(this);
517 std::ostringstream os;
518 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << xSize << ", YSize=" << ySize << ", nSamples=" << nSamples << "\n";
519 *theApp->getLog() << os.str().c_str();
526 PhantomView::CreateCanvas (wxView *view, wxFrame *parent)
528 PhantomCanvas* pCanvas;
530 parent->GetClientSize(&width, &height);
532 pCanvas = new PhantomCanvas (dynamic_cast<PhantomView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
534 pCanvas->SetBackgroundColour(*wxWHITE);
541 PhantomView::CreateChildFrame(wxDocument *doc, wxView *view)
543 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
545 wxMenu *file_menu = new wxMenu;
547 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
548 file_menu->Append(wxID_OPEN, "&Open...");
549 file_menu->Append(wxID_CLOSE, "&Close");
551 file_menu->AppendSeparator();
552 file_menu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties");
554 file_menu->AppendSeparator();
555 file_menu->Append(wxID_PRINT, "&Print...");
556 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
557 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
559 wxMenu *process_menu = new wxMenu;
560 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...");
561 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...");
563 wxMenu *help_menu = new wxMenu;
564 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
565 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
567 wxMenuBar *menu_bar = new wxMenuBar;
569 menu_bar->Append(file_menu, "&File");
570 menu_bar->Append(process_menu, "&Process");
571 menu_bar->Append(help_menu, "&Help");
573 subframe->SetMenuBar(menu_bar);
575 subframe->Centre(wxBOTH);
582 PhantomView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
584 m_frame = CreateChildFrame(doc, this);
588 m_frame->GetClientSize(&width, &height);
589 m_frame->SetTitle("PhantomView");
590 m_canvas = CreateCanvas(this, m_frame);
593 int x, y; // X requires a forced resize
594 m_frame->GetSize(&x, &y);
595 m_frame->SetSize(-1, -1, x, y);
606 PhantomView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
613 PhantomView::OnClose (bool deleteWindow)
615 if (!GetDocument()->Close())
619 m_canvas->m_pView = NULL;
621 wxString s(wxTheApp->GetAppName());
623 m_frame->SetTitle(s);
636 PhantomView::OnDraw (wxDC* dc)
639 m_canvas->GetClientSize (&xsize, &ysize);
640 SGPDriver driver (dc, xsize, ysize);
642 const Phantom& rPhantom = GetDocument()->getPhantom();
643 sgp.setColor (C_RED);
649 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
650 : wxScrolledWindow(frame, -1, pos, size, style)
656 ProjectionFileCanvas::OnDraw(wxDC& dc)
659 m_pView->OnDraw(& dc);
662 // ProjectionFileView
664 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
666 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
667 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
668 EVT_MENU(PJMENU_PROCESS_RECONSTRUCT, ProjectionFileView::OnReconstruct)
671 ProjectionFileView::ProjectionFileView(void)
672 : wxView(), m_canvas(NULL), m_frame(NULL)
676 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
677 m_dDefaultFilterParam = 1.;
679 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
680 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
682 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
683 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
685 m_iDefaultZeropad = 1;
686 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF3;
687 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
688 m_iDefaultInterpParam = 1;
689 m_iDefaultTrace = Trace::TRACE_NONE;
692 ProjectionFileView::~ProjectionFileView(void)
697 ProjectionFileView::OnProperties (wxCommandEvent& event)
699 const Projections& rProj = GetDocument()->getProjections();
700 std::ostringstream os;
701 rProj.printScanInfo(os);
702 *theApp->getLog() << os.str().c_str();
703 wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
704 dialogMsg.ShowModal();
709 ProjectionFileView::OnReconstruct (wxCommandEvent& event)
711 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);
713 int retVal = dialogReconstruction.ShowModal();
714 if (retVal == wxID_OK) {
715 m_iDefaultNX = dialogReconstruction.getXSize();
716 m_iDefaultNY = dialogReconstruction.getYSize();
717 wxString optFilterName = dialogReconstruction.getFilterName();
718 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
719 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
720 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
721 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
722 m_iDefaultZeropad = dialogReconstruction.getZeropad();
723 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
724 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
725 wxString optInterpName = dialogReconstruction.getInterpName();
726 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
727 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
728 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
729 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
730 m_iDefaultTrace = dialogReconstruction.getTrace();
731 if (m_iDefaultNX > 0 && m_iDefaultNY > 0) {
732 ImageFileDocument* pReconDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
733 ImageFile& imageFile = pReconDoc->getImageFile();
734 const Projections& rProj = GetDocument()->getProjections();
735 imageFile.setArraySize (m_iDefaultNX, m_iDefaultNY);
737 if (m_iDefaultFilterMethod != ProcessSignal::FILTER_METHOD_CONVOLUTION && m_iDefaultFilterGeneration == ProcessSignal::FILTER_GENERATION_DIRECT && rProj.geometry() != Scanner::GEOMETRY_PARALLEL) {
738 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);
742 SGPDriver* pSGPDriver = NULL;
744 wxMemoryDC* pDCPlot = NULL;
746 if (m_iDefaultTrace >= Trace::TRACE_PLOT) {
747 bitmap.Create (500, 500);
748 pDCPlot = new wxMemoryDC;
749 pDCPlot->SelectObject (bitmap);
750 pSGPDriver = new SGPDriver (dynamic_cast<wxDC*>pDCPlot, 500, 500);
751 pSGP = new SGP (*pSGPDriver);
753 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);
756 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);
760 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
761 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstruct, rProj, imageFile, m_iDefaultTrace, m_frame);
762 for (int iView = 0; iView < rProj.nView(); iView++) {
765 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView)) {
766 delete pDlgReconstruct;
768 pReconDoc->DeleteAllViews();
773 while (pDlgReconstruct->isPaused()) {
778 delete pDlgReconstruct;
780 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, m_frame, wxPD_CAN_ABORT);
781 for (int i = 0; i < rProj.nView(); i++) {
782 pReconstruct->reconstructView (i, 1);
783 if (! dlgProgress.Update(i + 1)) {
785 pReconDoc->DeleteAllViews();
791 pReconDoc->Modify(true);
792 pReconDoc->UpdateAllViews(this);
793 std::ostringstream os;
794 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();
795 *theApp->getLog() << os.str().c_str() << "\n";
796 imageFile.labelAdd (rProj.getLabel());
797 imageFile.labelAdd (Array2dFileLabel::L_HISTORY, os.str().c_str(), timerRecon.timerEnd());
\r
798 imageFile.setCalcTime (timerReconstruct.timerEnd());
804 ProjectionFileCanvas*
805 ProjectionFileView::CreateCanvas (wxView *view, wxFrame *parent)
807 ProjectionFileCanvas* pCanvas;
809 parent->GetClientSize(&width, &height);
811 pCanvas = new ProjectionFileCanvas (dynamic_cast<ProjectionFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
813 pCanvas->SetScrollbars(20, 20, 50, 50);
814 pCanvas->SetBackgroundColour(*wxWHITE);
821 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
823 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
825 wxMenu *file_menu = new wxMenu;
827 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
828 file_menu->Append(wxID_OPEN, "&Open...");
829 file_menu->Append(wxID_SAVE, "&Save");
830 file_menu->Append(wxID_SAVEAS, "Save &As...");
831 file_menu->Append(wxID_CLOSE, "&Close");
833 file_menu->AppendSeparator();
834 file_menu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
836 file_menu->AppendSeparator();
837 file_menu->Append(wxID_PRINT, "&Print...");
838 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
839 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
841 wxMenu *process_menu = new wxMenu;
842 process_menu->Append(PJMENU_PROCESS_RECONSTRUCT, "R&econstruct...");
844 wxMenu *help_menu = new wxMenu;
845 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
846 help_menu->AppendSeparator();
847 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
849 wxMenuBar *menu_bar = new wxMenuBar;
851 menu_bar->Append(file_menu, "&File");
852 menu_bar->Append(process_menu, "&Process");
853 menu_bar->Append(help_menu, "&Help");
855 subframe->SetMenuBar(menu_bar);
857 subframe->Centre(wxBOTH);
864 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
866 m_frame = CreateChildFrame(doc, this);
870 m_frame->GetClientSize(&width, &height);
871 m_frame->SetTitle("ProjectionFileView");
872 m_canvas = CreateCanvas(this, m_frame);
875 int x, y; // X requires a forced resize
876 m_frame->GetSize(&x, &y);
877 m_frame->SetSize(-1, -1, x, y);
887 ProjectionFileView::OnDraw (wxDC* dc)
890 dc->DrawBitmap (m_bitmap, 0, 0, false);
895 ProjectionFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
897 const Projections& rProj = GetDocument()->getProjections();
898 const int nDet = rProj.nDet();
899 const int nView = rProj.nView();
900 if (nDet != 0 && nView != 0) {
901 const DetectorArray& detarray = rProj.getDetectorArray(0);
902 const DetectorValue* detval = detarray.detValues();
903 double min = detval[0];
904 double max = detval[0];
905 for (int iy = 0; iy < nView; iy++) {
906 const DetectorArray& detarray = rProj.getDetectorArray(iy);
907 const DetectorValue* detval = detarray.detValues();
908 for (int ix = 0; ix < nDet; ix++) {
909 if (min > detval[ix])
911 else if (max < detval[ix])
916 unsigned char* imageData = new unsigned char [nDet * nView * 3];
917 double scale = (max - min) / 255;
918 for (int iy2 = 0; iy2 < nView; iy2++) {
919 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
920 const DetectorValue* detval = detarray.detValues();
921 for (int ix = 0; ix < nDet; ix++) {
922 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
923 intensity = clamp(intensity, 0, 255);
924 int baseAddr = (iy2 * nDet + ix) * 3;
925 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
928 wxImage image (nDet, nView, imageData, true);
929 m_bitmap = image.ConvertToBitmap();
933 xSize = clamp (xSize, 0, 800);
934 ySize = clamp (ySize, 0, 800);
935 m_frame->SetClientSize (xSize, ySize);
936 m_canvas->SetScrollbars (20, 20, nDet/20, nView/20);
944 ProjectionFileView::OnClose (bool deleteWindow)
946 if (!GetDocument()->Close())
950 m_canvas->m_pView = NULL;
952 wxString s(wxTheApp->GetAppName());
954 m_frame->SetTitle(s);