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.21 2000/09/04 09:06:46 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 ******************************************************************************/
29 // #pragma implementation
32 // For compilers that support precompilation, includes "wx/wx.h".
33 #include "wx/wxprec.h"
43 #if !wxUSE_DOC_VIEW_ARCHITECTURE
44 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
48 #include "wx/progdlg.h"
55 #include "dlgprojections.h"
56 #include "dlgreconstruct.h"
58 #include "backprojectors.h"
59 #include "reconstruct.h"
64 BEGIN_EVENT_TABLE(ImageFileCanvas, wxScrolledWindow)
65 EVT_MOUSE_EVENTS(ImageFileCanvas::OnMouseEvent)
69 ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
70 : wxScrolledWindow(frame, -1, pos, size, style)
76 ImageFileCanvas::OnDraw(wxDC& dc)
79 m_pView->OnDraw(& dc);
83 ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
91 wxPoint pt(event.GetLogicalPosition(dc));
93 if (event.LeftIsDown()) {
94 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
95 ImageFileArrayConst v = rIF.getArray();
99 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 & pt.y < ny) {
101 os << "Image value (" << pt.x << "," << pt.y << ") = " << v[pt.x][ny - 1 - pt.y] << "\n";
102 *theApp->getLog() << os.str().c_str();
104 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << pt.y << ")\n";
112 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
114 BEGIN_EVENT_TABLE(ImageFileView, wxView)
115 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
116 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
117 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
120 ImageFileView::ImageFileView(void)
121 : wxView(), m_canvas(NULL), m_frame(NULL), m_bMinSpecified(false), m_bMaxSpecified(false)
125 ImageFileView::~ImageFileView(void)
130 ImageFileView::OnProperties (wxCommandEvent& event)
132 double min, max, mean, mode, median, stddev;
133 const ImageFile& rIF = GetDocument()->getImageFile();
134 if (rIF.nx() == 0 || rIF.ny() == 0)
135 *theApp->getLog() << "Properties: empty imagefile\n";
137 const string& rFilename = rIF.getFilename();
138 rIF.statistics (min, max, mean, mode, median, stddev);
140 os << "file: " << rFilename << "\nmin: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
141 *theApp->getLog() << os.str().c_str();
142 wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
143 dialogMsg.ShowModal();
148 ImageFileView::OnScaleAuto (wxCommandEvent& event)
150 const ImageFile& rIF = GetDocument()->getImageFile();
151 DialogAutoScaleParameters dialogAutoScale (m_frame, rIF, m_dAutoScaleFactor);
152 int iRetVal = dialogAutoScale.ShowModal();
153 if (iRetVal == wxID_OK) {
154 m_bMinSpecified = true;
155 m_bMaxSpecified = true;
157 dialogAutoScale.getMinMax (&dMin, &dMax);
160 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
161 OnUpdate (this, NULL);
166 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
168 const ImageFile& rIF = GetDocument()->getImageFile();
170 if (! m_bMinSpecified && ! m_bMaxSpecified)
171 rIF.getMinMax (min, max);
178 DialogGetImageMinMax dialogMinMax (m_frame, rIF, min, max);
179 int retVal = dialogMinMax.ShowModal();
180 if (retVal == wxID_OK) {
181 m_bMinSpecified = true;
182 m_bMaxSpecified = true;
183 m_dMinPixel = dialogMinMax.getMinimum();
184 m_dMaxPixel = dialogMinMax.getMaximum();
185 OnUpdate (this, NULL);
191 ImageFileView::CreateCanvas (wxView *view, wxFrame *parent)
193 ImageFileCanvas* pCanvas;
195 parent->GetClientSize(&width, &height);
197 pCanvas = new ImageFileCanvas (dynamic_cast<ImageFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
199 pCanvas->SetScrollbars(20, 20, 50, 50);
200 pCanvas->SetBackgroundColour(*wxWHITE);
207 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
209 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
211 wxMenu *file_menu = new wxMenu;
213 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
214 file_menu->Append(wxID_OPEN, "&Open...");
215 file_menu->Append(wxID_SAVE, "&Save");
216 file_menu->Append(wxID_SAVEAS, "Save &As...");
217 file_menu->Append(wxID_CLOSE, "&Close");
219 file_menu->AppendSeparator();
220 file_menu->Append(IFMENU_FILE_PROPERTIES, "P&roperties");
222 file_menu->AppendSeparator();
223 file_menu->Append(wxID_PRINT, "&Print...");
224 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
225 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
227 wxMenu *view_menu = new wxMenu;
228 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...");
229 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...");
231 wxMenu *help_menu = new wxMenu;
232 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
234 wxMenuBar *menu_bar = new wxMenuBar;
236 menu_bar->Append(file_menu, "&File");
237 menu_bar->Append(view_menu, "&View");
238 menu_bar->Append(help_menu, "&Help");
240 subframe->SetMenuBar(menu_bar);
242 subframe->Centre(wxBOTH);
249 ImageFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
251 m_frame = CreateChildFrame(doc, this);
254 m_bMinSpecified = false;
255 m_bMaxSpecified = false;
256 m_dAutoScaleFactor = 1.;
259 m_frame->GetClientSize(&width, &height);
260 m_frame->SetTitle("ImageFileView");
261 m_canvas = CreateCanvas(this, m_frame);
264 int x, y; // X requires a forced resize
265 m_frame->GetSize(&x, &y);
266 m_frame->SetSize(-1, -1, x, y);
276 ImageFileView::OnDraw (wxDC* dc)
279 dc->DrawBitmap(m_bitmap, 0, 0, false);
284 ImageFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
286 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
287 ImageFileArrayConst v = rIF.getArray();
290 if (v != NULL && nx != 0 && ny != 0) {
291 if (! m_bMinSpecified || ! m_bMaxSpecified) {
293 rIF.getMinMax (min, max);
294 if (! m_bMinSpecified)
296 if (! m_bMaxSpecified)
299 double scaleWidth = m_dMaxPixel - m_dMinPixel;
301 unsigned char* imageData = new unsigned char [nx * ny * 3];
302 for (int ix = 0; ix < nx; ix++) {
303 for (int iy = 0; iy < ny; iy++) {
304 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
305 int intensity = static_cast<int>(scaleValue + 0.5);
306 intensity = clamp (intensity, 0, 255);
307 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
308 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
311 wxImage image (nx, ny, imageData, true);
312 m_bitmap = image.ConvertToBitmap();
316 xSize = clamp (xSize, 0, 800);
317 ySize = clamp (ySize, 0, 800);
318 m_frame->SetClientSize (xSize, ySize);
319 m_canvas->SetScrollbars(20, 20, nx/20, ny/20);
320 m_canvas->SetBackgroundColour(*wxWHITE);
328 ImageFileView::OnClose (bool deleteWindow)
330 if (!GetDocument()->Close())
334 m_canvas->m_pView = NULL;
336 wxString s(theApp->GetAppName());
338 m_frame->SetTitle(s);
354 PhantomCanvas::PhantomCanvas (PhantomView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
355 : wxScrolledWindow(frame, -1, pos, size, style)
361 PhantomCanvas::OnDraw(wxDC& dc)
364 m_pView->OnDraw(& dc);
370 IMPLEMENT_DYNAMIC_CLASS(PhantomView, wxView)
372 BEGIN_EVENT_TABLE(PhantomView, wxView)
373 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomView::OnProperties)
374 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomView::OnRasterize)
375 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomView::OnProjections)
378 PhantomView::PhantomView(void)
379 : wxView(), m_canvas(NULL), m_frame(NULL)
381 m_iDefaultNDet = 367;
382 m_iDefaultNView = 320;
383 m_iDefaultNSample = 2;
384 m_dDefaultRotation = 2;
385 m_dDefaultFocalLength = 2;
386 m_dDefaultFieldOfView = 1;
387 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
388 m_iDefaultTrace = Trace::TRACE_NONE;
391 PhantomView::~PhantomView(void)
396 PhantomView::OnProperties (wxCommandEvent& event)
398 const int idPhantom = GetDocument()->getPhantomID();
399 const string& namePhantom = GetDocument()->getPhantomName();
401 os << "Phantom " << namePhantom << " (" << idPhantom << ")\n";
402 *theApp->getLog() << os.str().c_str();
404 const Phantom& rPhantom = GetDocument()->getPhantom();
411 PhantomView::OnProjections (wxCommandEvent& event)
413 DialogGetProjectionParameters dialogProjection (m_frame, m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView, m_iDefaultGeometry, m_iDefaultTrace);
414 int retVal = dialogProjection.ShowModal();
415 if (retVal == wxID_OK) {
416 m_iDefaultNDet = dialogProjection.getNDet();
417 m_iDefaultNView = dialogProjection.getNView();
418 m_iDefaultNSample = dialogProjection.getNSamples();
419 m_iDefaultTrace = dialogProjection.getTrace();
420 m_dDefaultRotation = dialogProjection.getRotAngle();
421 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
422 m_dDefaultFieldOfView = dialogProjection.getFieldOfViewRatio();
423 wxString sGeometry = dialogProjection.getGeometry();
424 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
426 if (m_iDefaultNDet > 0 && m_iDefaultNView > 0 && sGeometry != "") {
427 const Phantom& rPhantom = GetDocument()->getPhantom();
428 ProjectionFileDocument* pProjectionDoc = dynamic_cast<ProjectionFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.pj", wxDOC_SILENT));
429 Projections& rProj = pProjectionDoc->getProjections();
430 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView);
431 if (theScanner.fail()) {
432 *theApp->getLog() << "Failed making scanner: " << theScanner.failMessage().c_str() << "\n";
435 rProj.initFromScanner (theScanner);
436 m_dDefaultRotation /= PI; // convert back to PI units
438 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
439 ProjectionsDialog dialogProjections (theScanner, rProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(m_frame));
440 for (int iView = 0; iView < rProj.nView(); iView++) {
443 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
444 pProjectionDoc->DeleteAllViews();
449 while (dialogProjections.isPaused()) {
455 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), rProj.nView() + 1, m_frame, wxPD_CAN_ABORT);
456 for (int i = 0; i < rProj.nView(); i++) {
457 theScanner.collectProjections (rProj, rPhantom, i, 1, true, m_iDefaultTrace);
458 if (! dlgProgress.Update (i+1)) {
459 pProjectionDoc->DeleteAllViews();
466 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";
467 rProj.setRemark (os.str());
468 *theApp->getLog() << os.str().c_str();
471 pProjectionDoc->Modify(true);
472 pProjectionDoc->UpdateAllViews(this);
474 if (wxView* pView = pProjectionDoc->GetFirstView())
475 if (wxFrame* pFrame = pView->GetFrame()) {
486 PhantomView::OnRasterize (wxCommandEvent& event)
488 DialogGetRasterParameters dialogRaster (m_frame, 256, 256, 1);
489 int retVal = dialogRaster.ShowModal();
490 if (retVal == wxID_OK) {
491 int xSize = dialogRaster.getXSize();
492 int ySize = dialogRaster.getYSize();
493 int nSamples = dialogRaster.getNSamples();
496 if (xSize > 0 && ySize > 0) {
497 const Phantom& rPhantom = GetDocument()->getPhantom();
498 ImageFileDocument* pRasterDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
499 ImageFile& imageFile = pRasterDoc->getImageFile();
501 imageFile.setArraySize (xSize, ySize);
502 wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"), imageFile.nx() + 1, m_frame, wxPD_CAN_ABORT);
503 for (unsigned int i = 0; i < imageFile.nx(); i++) {
504 rPhantom.convertToImagefile (imageFile, nSamples, Trace::TRACE_NONE, i, 1, true);
505 if (! dlgProgress.Update(i+1)) {
506 pRasterDoc->DeleteAllViews();
510 pRasterDoc->Modify(true);
511 pRasterDoc->UpdateAllViews(this);
514 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << xSize << ", YSize=" << ySize << ", nSamples=" << nSamples << "\n";
515 *theApp->getLog() << os.str().c_str();
522 PhantomView::CreateCanvas (wxView *view, wxFrame *parent)
524 PhantomCanvas* pCanvas;
526 parent->GetClientSize(&width, &height);
528 pCanvas = new PhantomCanvas (dynamic_cast<PhantomView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
530 pCanvas->SetBackgroundColour(*wxWHITE);
537 PhantomView::CreateChildFrame(wxDocument *doc, wxView *view)
539 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
541 wxMenu *file_menu = new wxMenu;
543 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
544 file_menu->Append(wxID_OPEN, "&Open...");
545 file_menu->Append(wxID_CLOSE, "&Close");
547 file_menu->AppendSeparator();
548 file_menu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties");
550 file_menu->AppendSeparator();
551 file_menu->Append(wxID_PRINT, "&Print...");
552 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
553 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
555 wxMenu *process_menu = new wxMenu;
556 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...");
557 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...");
559 wxMenu *help_menu = new wxMenu;
560 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
561 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
563 wxMenuBar *menu_bar = new wxMenuBar;
565 menu_bar->Append(file_menu, "&File");
566 menu_bar->Append(process_menu, "&Process");
567 menu_bar->Append(help_menu, "&Help");
569 subframe->SetMenuBar(menu_bar);
571 subframe->Centre(wxBOTH);
578 PhantomView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
580 m_frame = CreateChildFrame(doc, this);
584 m_frame->GetClientSize(&width, &height);
585 m_frame->SetTitle("PhantomView");
586 m_canvas = CreateCanvas(this, m_frame);
589 int x, y; // X requires a forced resize
590 m_frame->GetSize(&x, &y);
591 m_frame->SetSize(-1, -1, x, y);
602 PhantomView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
609 PhantomView::OnClose (bool deleteWindow)
611 if (!GetDocument()->Close())
615 m_canvas->m_pView = NULL;
617 wxString s(wxTheApp->GetAppName());
619 m_frame->SetTitle(s);
632 PhantomView::OnDraw (wxDC* dc)
635 m_canvas->GetClientSize (&xsize, &ysize);
636 SGPDriver driver (dc, xsize, ysize);
638 const Phantom& rPhantom = GetDocument()->getPhantom();
639 sgp.setColor (C_RED);
645 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
646 : wxScrolledWindow(frame, -1, pos, size, style)
652 ProjectionFileCanvas::OnDraw(wxDC& dc)
655 m_pView->OnDraw(& dc);
658 // ProjectionFileView
660 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
662 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
663 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
664 EVT_MENU(PJMENU_PROCESS_RECONSTRUCT, ProjectionFileView::OnReconstruct)
667 ProjectionFileView::ProjectionFileView(void)
668 : wxView(), m_canvas(NULL), m_frame(NULL)
672 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
673 m_dDefaultFilterParam = 1.;
675 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
676 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
678 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
679 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
681 m_iDefaultZeropad = 1;
682 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF3;
683 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
684 m_iDefaultInterpParam = 1;
685 m_iDefaultTrace = Trace::TRACE_NONE;
688 ProjectionFileView::~ProjectionFileView(void)
693 ProjectionFileView::OnProperties (wxCommandEvent& event)
695 const Projections& rProj = GetDocument()->getProjections();
697 rProj.printScanInfo(os);
698 *theApp->getLog() << os.str().c_str();
699 wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
700 dialogMsg.ShowModal();
705 ProjectionFileView::OnReconstruct (wxCommandEvent& event)
707 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);
709 int retVal = dialogReconstruction.ShowModal();
710 if (retVal == wxID_OK) {
711 m_iDefaultNX = dialogReconstruction.getXSize();
712 m_iDefaultNY = dialogReconstruction.getYSize();
713 wxString optFilterName = dialogReconstruction.getFilterName();
714 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
715 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
716 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
717 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
718 m_iDefaultZeropad = dialogReconstruction.getZeropad();
719 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
720 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
721 wxString optInterpName = dialogReconstruction.getInterpName();
722 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
723 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
724 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
725 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
726 m_iDefaultTrace = dialogReconstruction.getTrace();
727 if (m_iDefaultNX > 0 && m_iDefaultNY > 0) {
728 ImageFileDocument* pReconDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
729 ImageFile& imageFile = pReconDoc->getImageFile();
730 const Projections& rProj = GetDocument()->getProjections();
731 imageFile.setArraySize (m_iDefaultNX, m_iDefaultNY);
734 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);
735 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
736 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstruct, rProj, imageFile, m_iDefaultTrace, m_frame);
737 for (int iView = 0; iView < rProj.nView(); iView++) {
740 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView)) {
741 delete pDlgReconstruct;
743 pReconDoc->DeleteAllViews();
748 while (pDlgReconstruct->isPaused()) {
753 delete pDlgReconstruct;
755 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, m_frame, wxPD_CAN_ABORT);
756 for (int i = 0; i < rProj.nView(); i++) {
757 pReconstruct->reconstructView (i, 1);
758 if (! dlgProgress.Update(i + 1)) {
760 pReconDoc->DeleteAllViews();
766 pReconDoc->Modify(true);
767 pReconDoc->UpdateAllViews(this);
769 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";
770 *theApp->getLog() << os.str().c_str();
771 imageFile.labelAdd (rProj.getLabel());
772 imageFile.labelAdd (Array2dFileLabel::L_HISTORY, os.str().c_str(), timerRecon.timerEnd());
778 ProjectionFileCanvas*
779 ProjectionFileView::CreateCanvas (wxView *view, wxFrame *parent)
781 ProjectionFileCanvas* pCanvas;
783 parent->GetClientSize(&width, &height);
785 pCanvas = new ProjectionFileCanvas (dynamic_cast<ProjectionFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
787 pCanvas->SetScrollbars(20, 20, 50, 50);
788 pCanvas->SetBackgroundColour(*wxWHITE);
795 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
797 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
799 wxMenu *file_menu = new wxMenu;
801 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
802 file_menu->Append(wxID_OPEN, "&Open...");
803 file_menu->Append(wxID_SAVE, "&Save");
804 file_menu->Append(wxID_SAVEAS, "Save &As...");
805 file_menu->Append(wxID_CLOSE, "&Close");
807 file_menu->AppendSeparator();
808 file_menu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
810 file_menu->AppendSeparator();
811 file_menu->Append(wxID_PRINT, "&Print...");
812 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
813 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
815 wxMenu *process_menu = new wxMenu;
816 process_menu->Append(PJMENU_PROCESS_RECONSTRUCT, "R&econstruct...");
818 wxMenu *help_menu = new wxMenu;
819 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
820 help_menu->AppendSeparator();
821 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
823 wxMenuBar *menu_bar = new wxMenuBar;
825 menu_bar->Append(file_menu, "&File");
826 menu_bar->Append(process_menu, "&Process");
827 menu_bar->Append(help_menu, "&Help");
829 subframe->SetMenuBar(menu_bar);
831 subframe->Centre(wxBOTH);
838 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
840 m_frame = CreateChildFrame(doc, this);
844 m_frame->GetClientSize(&width, &height);
845 m_frame->SetTitle("ProjectionFileView");
846 m_canvas = CreateCanvas(this, m_frame);
849 int x, y; // X requires a forced resize
850 m_frame->GetSize(&x, &y);
851 m_frame->SetSize(-1, -1, x, y);
861 ProjectionFileView::OnDraw (wxDC* dc)
864 dc->DrawBitmap (m_bitmap, 0, 0, false);
869 ProjectionFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
871 const Projections& rProj = GetDocument()->getProjections();
872 const int nDet = rProj.nDet();
873 const int nView = rProj.nView();
874 if (nDet != 0 && nView != 0) {
875 const DetectorArray& detarray = rProj.getDetectorArray(0);
876 const DetectorValue* detval = detarray.detValues();
877 double min = detval[0];
878 double max = detval[0];
879 for (int iy = 0; iy < nView; iy++) {
880 const DetectorArray& detarray = rProj.getDetectorArray(iy);
881 const DetectorValue* detval = detarray.detValues();
882 for (int ix = 0; ix < nDet; ix++) {
883 if (min > detval[ix])
885 else if (max < detval[ix])
890 unsigned char* imageData = new unsigned char [nDet * nView * 3];
891 double scale = (max - min) / 255;
892 for (int iy = 0; iy < nView; iy++) {
893 const DetectorArray& detarray = rProj.getDetectorArray(iy);
894 const DetectorValue* detval = detarray.detValues();
895 for (int ix = 0; ix < nDet; ix++) {
896 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
897 intensity = clamp(intensity, 0, 255);
898 int baseAddr = (iy * nDet + ix) * 3;
899 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
902 wxImage image (nDet, nView, imageData, true);
903 m_bitmap = image.ConvertToBitmap();
907 xSize = clamp (xSize, 0, 800);
908 ySize = clamp (ySize, 0, 800);
909 m_frame->SetClientSize (xSize, ySize);
910 m_canvas->SetScrollbars (20, 20, nDet/20, nView/20);
918 ProjectionFileView::OnClose (bool deleteWindow)
920 if (!GetDocument()->Close())
924 m_canvas->m_pView = NULL;
926 wxString s(wxTheApp->GetAppName());
928 m_frame->SetTitle(s);