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.30 2000/12/18 09:31:26 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);
265 int x, y; // X requires a forced resize
266 m_frame->GetSize(&x, &y);
267 m_frame->SetSize(-1, -1, x, y);
268 m_frame->SetFocus();
\r
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 wxString& namePhantom = GetDocument()->getPhantomName();
400 std::ostringstream os;
401 os << "Phantom " << namePhantom.c_str() << " (" << 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();
465 std::ostringstream os;
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();
467 rProj.setRemark (os.str());
468 *theApp->getLog() << os.str().c_str() << "\n";
472 ProjectionFileView* projView = dynamic_cast<ProjectionFileView*>(pProjectionDoc->GetFirstView());
\r
474 projView->getFrame()->SetFocus();
\r
475 projView->OnUpdate (projView, NULL);
\r
477 if (wxView* pView = pProjectionDoc->GetFirstView()) {
478 if (wxFrame* pFrame = pView->GetFrame()) {
482 theApp->getDocManager()->ActivateView (pView, true, false);
485 pProjectionDoc->Modify(true);
486 pProjectionDoc->UpdateAllViews(this);
493 PhantomView::OnRasterize (wxCommandEvent& event)
495 DialogGetRasterParameters dialogRaster (m_frame, 256, 256, 1);
496 int retVal = dialogRaster.ShowModal();
497 if (retVal == wxID_OK) {
498 int xSize = dialogRaster.getXSize();
499 int ySize = dialogRaster.getYSize();
500 int nSamples = dialogRaster.getNSamples();
503 if (xSize > 0 && ySize > 0) {
504 const Phantom& rPhantom = GetDocument()->getPhantom();
505 ImageFileDocument* pRasterDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
506 ImageFile& imageFile = pRasterDoc->getImageFile();
508 imageFile.setArraySize (xSize, ySize);
509 wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"), imageFile.nx() + 1, m_frame, wxPD_CAN_ABORT);
510 for (unsigned int i = 0; i < imageFile.nx(); i++) {
511 rPhantom.convertToImagefile (imageFile, nSamples, Trace::TRACE_NONE, i, 1, true);
512 if (! dlgProgress.Update(i+1)) {
513 pRasterDoc->DeleteAllViews();
517 pRasterDoc->Modify(true);
518 pRasterDoc->UpdateAllViews(this);
519 ImageFileView* rasterView = dynamic_cast<ImageFileView*>(pRasterDoc->GetFirstView());
\r
521 rasterView->getFrame()->SetFocus();
\r
522 rasterView->OnUpdate (rasterView, NULL);
\r
525 std::ostringstream os;
526 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << xSize << ", YSize=" << ySize << ", nSamples=" << nSamples << "\n";
527 *theApp->getLog() << os.str().c_str();
534 PhantomView::CreateCanvas (wxView *view, wxFrame *parent)
536 PhantomCanvas* pCanvas;
538 parent->GetClientSize(&width, &height);
540 pCanvas = new PhantomCanvas (dynamic_cast<PhantomView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
542 pCanvas->SetBackgroundColour(*wxWHITE);
549 PhantomView::CreateChildFrame(wxDocument *doc, wxView *view)
551 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
553 wxMenu *file_menu = new wxMenu;
555 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
556 file_menu->Append(wxID_OPEN, "&Open...");
557 file_menu->Append(wxID_CLOSE, "&Close");
559 file_menu->AppendSeparator();
560 file_menu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties");
562 file_menu->AppendSeparator();
563 file_menu->Append(wxID_PRINT, "&Print...");
564 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
565 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
567 wxMenu *process_menu = new wxMenu;
568 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...");
569 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...");
571 wxMenu *help_menu = new wxMenu;
572 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
573 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
575 wxMenuBar *menu_bar = new wxMenuBar;
577 menu_bar->Append(file_menu, "&File");
578 menu_bar->Append(process_menu, "&Process");
579 menu_bar->Append(help_menu, "&Help");
581 subframe->SetMenuBar(menu_bar);
583 subframe->Centre(wxBOTH);
590 PhantomView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
592 m_frame = CreateChildFrame(doc, this);
596 m_frame->GetClientSize(&width, &height);
597 m_frame->SetTitle("PhantomView");
598 m_canvas = CreateCanvas(this, m_frame);
601 int x, y; // X requires a forced resize
602 m_frame->GetSize(&x, &y);
603 m_frame->SetSize(-1, -1, x, y);
614 PhantomView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
621 PhantomView::OnClose (bool deleteWindow)
623 if (!GetDocument()->Close())
627 m_canvas->m_pView = NULL;
629 wxString s(wxTheApp->GetAppName());
631 m_frame->SetTitle(s);
644 PhantomView::OnDraw (wxDC* dc)
647 m_canvas->GetClientSize (&xsize, &ysize);
648 SGPDriver driver (dc, xsize, ysize);
650 const Phantom& rPhantom = GetDocument()->getPhantom();
651 sgp.setColor (C_RED);
657 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
658 : wxScrolledWindow(frame, -1, pos, size, style)
664 ProjectionFileCanvas::OnDraw(wxDC& dc)
667 m_pView->OnDraw(& dc);
670 // ProjectionFileView
672 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
674 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
675 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
676 EVT_MENU(PJMENU_PROCESS_RECONSTRUCT, ProjectionFileView::OnReconstruct)
679 ProjectionFileView::ProjectionFileView(void)
680 : wxView(), m_canvas(NULL), m_frame(NULL)
684 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
685 m_dDefaultFilterParam = 1.;
687 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
688 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
690 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
691 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
693 m_iDefaultZeropad = 1;
694 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF3;
695 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
696 m_iDefaultInterpParam = 1;
697 m_iDefaultTrace = Trace::TRACE_NONE;
700 ProjectionFileView::~ProjectionFileView(void)
705 ProjectionFileView::OnProperties (wxCommandEvent& event)
707 const Projections& rProj = GetDocument()->getProjections();
708 std::ostringstream os;
709 rProj.printScanInfo(os);
710 *theApp->getLog() << os.str().c_str();
711 wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
712 dialogMsg.ShowModal();
717 ProjectionFileView::OnReconstruct (wxCommandEvent& event)
719 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);
721 int retVal = dialogReconstruction.ShowModal();
722 if (retVal == wxID_OK) {
723 m_iDefaultNX = dialogReconstruction.getXSize();
724 m_iDefaultNY = dialogReconstruction.getYSize();
725 wxString optFilterName = dialogReconstruction.getFilterName();
726 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
727 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
728 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
729 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
730 m_iDefaultZeropad = dialogReconstruction.getZeropad();
731 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
732 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
733 wxString optInterpName = dialogReconstruction.getInterpName();
734 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
735 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
736 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
737 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
738 m_iDefaultTrace = dialogReconstruction.getTrace();
739 if (m_iDefaultNX > 0 && m_iDefaultNY > 0) {
740 ImageFileDocument* pReconDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
741 ImageFile& imageFile = pReconDoc->getImageFile();
742 const Projections& rProj = GetDocument()->getProjections();
743 imageFile.setArraySize (m_iDefaultNX, m_iDefaultNY);
745 if (m_iDefaultFilterMethod != ProcessSignal::FILTER_METHOD_CONVOLUTION && m_iDefaultFilterGeneration == ProcessSignal::FILTER_GENERATION_DIRECT && rProj.geometry() != Scanner::GEOMETRY_PARALLEL) {
746 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);
750 SGPDriver* pSGPDriver = NULL;
752 wxMemoryDC* pDCPlot = NULL;
754 if (m_iDefaultTrace >= Trace::TRACE_PLOT) {
755 bitmap.Create (500, 500);
756 pDCPlot = new wxMemoryDC;
757 pDCPlot->SelectObject (bitmap);
758 pSGPDriver = new SGPDriver (dynamic_cast<wxDC*>pDCPlot, 500, 500);
759 pSGP = new SGP (*pSGPDriver);
761 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);
764 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);
768 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
769 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstruct, rProj, imageFile, m_iDefaultTrace, m_frame);
770 for (int iView = 0; iView < rProj.nView(); iView++) {
773 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView)) {
774 delete pDlgReconstruct;
776 pReconDoc->DeleteAllViews();
781 while (pDlgReconstruct->isPaused()) {
786 delete pDlgReconstruct;
788 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, m_frame, wxPD_CAN_ABORT);
789 for (int i = 0; i < rProj.nView(); i++) {
790 pReconstruct->reconstructView (i, 1);
791 if (! dlgProgress.Update(i + 1)) {
793 pReconDoc->DeleteAllViews();
799 pReconDoc->Modify(true);
800 pReconDoc->UpdateAllViews(this);
801 ImageFileView* rasterView = dynamic_cast<ImageFileView*>(pReconDoc->GetFirstView());
\r
803 rasterView->getFrame()->SetFocus();
\r
804 rasterView->OnUpdate (rasterView, NULL);
\r
806 std::ostringstream os;
807 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();
808 *theApp->getLog() << os.str().c_str() << "\n";
809 imageFile.labelAdd (rProj.getLabel());
810 imageFile.labelAdd (Array2dFileLabel::L_HISTORY, os.str().c_str(), timerRecon.timerEnd());
816 ProjectionFileCanvas*
817 ProjectionFileView::CreateCanvas (wxView *view, wxFrame *parent)
819 ProjectionFileCanvas* pCanvas;
821 parent->GetClientSize(&width, &height);
823 pCanvas = new ProjectionFileCanvas (dynamic_cast<ProjectionFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
825 pCanvas->SetScrollbars(20, 20, 50, 50);
826 pCanvas->SetBackgroundColour(*wxWHITE);
833 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
835 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
837 wxMenu *file_menu = new wxMenu;
839 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
840 file_menu->Append(wxID_OPEN, "&Open...");
841 file_menu->Append(wxID_SAVE, "&Save");
842 file_menu->Append(wxID_SAVEAS, "Save &As...");
843 file_menu->Append(wxID_CLOSE, "&Close");
845 file_menu->AppendSeparator();
846 file_menu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
848 file_menu->AppendSeparator();
849 file_menu->Append(wxID_PRINT, "&Print...");
850 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
851 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
853 wxMenu *process_menu = new wxMenu;
854 process_menu->Append(PJMENU_PROCESS_RECONSTRUCT, "R&econstruct...");
856 wxMenu *help_menu = new wxMenu;
857 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
858 help_menu->AppendSeparator();
859 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
861 wxMenuBar *menu_bar = new wxMenuBar;
863 menu_bar->Append(file_menu, "&File");
864 menu_bar->Append(process_menu, "&Process");
865 menu_bar->Append(help_menu, "&Help");
867 subframe->SetMenuBar(menu_bar);
869 subframe->Centre(wxBOTH);
876 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
878 m_frame = CreateChildFrame(doc, this);
882 m_frame->GetClientSize(&width, &height);
883 m_frame->SetTitle("ProjectionFileView");
884 m_canvas = CreateCanvas(this, m_frame);
887 int x, y; // X requires a forced resize
888 m_frame->GetSize(&x, &y);
889 m_frame->SetSize(-1, -1, x, y);
899 ProjectionFileView::OnDraw (wxDC* dc)
902 dc->DrawBitmap (m_bitmap, 0, 0, false);
907 ProjectionFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
909 const Projections& rProj = GetDocument()->getProjections();
910 const int nDet = rProj.nDet();
911 const int nView = rProj.nView();
912 if (nDet != 0 && nView != 0) {
913 const DetectorArray& detarray = rProj.getDetectorArray(0);
914 const DetectorValue* detval = detarray.detValues();
915 double min = detval[0];
916 double max = detval[0];
917 for (int iy = 0; iy < nView; iy++) {
918 const DetectorArray& detarray = rProj.getDetectorArray(iy);
919 const DetectorValue* detval = detarray.detValues();
920 for (int ix = 0; ix < nDet; ix++) {
921 if (min > detval[ix])
923 else if (max < detval[ix])
928 unsigned char* imageData = new unsigned char [nDet * nView * 3];
929 double scale = (max - min) / 255;
930 for (int iy2 = 0; iy2 < nView; iy2++) {
931 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
932 const DetectorValue* detval = detarray.detValues();
933 for (int ix = 0; ix < nDet; ix++) {
934 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
935 intensity = clamp(intensity, 0, 255);
936 int baseAddr = (iy2 * nDet + ix) * 3;
937 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
940 wxImage image (nDet, nView, imageData, true);
941 m_bitmap = image.ConvertToBitmap();
945 xSize = clamp (xSize, 0, 800);
946 ySize = clamp (ySize, 0, 800);
947 m_frame->SetClientSize (xSize, ySize);
948 m_canvas->SetScrollbars (20, 20, nDet/20, nView/20);
956 ProjectionFileView::OnClose (bool deleteWindow)
958 if (!GetDocument()->Close())
962 m_canvas->m_pView = NULL;
964 wxString s(wxTheApp->GetAppName());
966 m_frame->SetTitle(s);