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.18 2000/08/31 08:38:58 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!
54 #include "dlgprojections.h"
56 #include "backprojectors.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) {
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 string& rFilename = rIF.getFilename();
134 rIF.statistics (min, max, mean, mode, median, stddev);
136 os << "file: " << rFilename << "\nmin: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
137 *theApp->getLog() << os.str().c_str();
140 ostringstream osSize;
141 m_frame->GetSize (&xSize, &ySize);
142 osSize << "Frame size: (" << xSize << "," << ySize << ")\n";
143 m_frame->GetClientSize (&xSize, &ySize);
144 osSize << "Frame Client size: (" << xSize << "," << ySize << ")\n";
145 m_canvas->GetSize (&xSize, &ySize);
146 osSize << "Canvas size: (" << xSize << "," << ySize << ")\n";
147 *theApp->getLog() << osSize.str().c_str();
152 ImageFileView::OnScaleAuto (wxCommandEvent& event)
154 const ImageFile& rIF = GetDocument()->getImageFile();
155 DialogAutoScaleParameters dialogAutoScale (m_frame, rIF, m_dAutoScaleFactor);
156 int iRetVal = dialogAutoScale.ShowModal();
157 if (iRetVal == wxID_OK) {
158 m_bMinSpecified = true;
159 m_bMaxSpecified = true;
161 dialogAutoScale.getMinMax (&dMin, &dMax);
164 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
165 OnUpdate (this, NULL);
170 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
172 const ImageFile& rIF = GetDocument()->getImageFile();
174 if (! m_bMinSpecified && ! m_bMaxSpecified)
175 rIF.getMinMax (min, max);
182 DialogGetImageMinMax dialogMinMax (m_frame, rIF, min, max);
183 int retVal = dialogMinMax.ShowModal();
184 if (retVal == wxID_OK) {
185 m_bMinSpecified = true;
186 m_bMaxSpecified = true;
187 m_dMinPixel = dialogMinMax.getMinimum();
188 m_dMaxPixel = dialogMinMax.getMaximum();
189 OnUpdate (this, NULL);
195 ImageFileView::CreateCanvas (wxView *view, wxFrame *parent)
197 ImageFileCanvas* pCanvas;
199 parent->GetClientSize(&width, &height);
201 pCanvas = new ImageFileCanvas (dynamic_cast<ImageFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
203 pCanvas->SetScrollbars(20, 20, 50, 50);
204 pCanvas->SetBackgroundColour(*wxWHITE);
211 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
213 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
215 wxMenu *file_menu = new wxMenu;
217 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
218 file_menu->Append(wxID_OPEN, "&Open...");
219 file_menu->Append(wxID_SAVE, "&Save");
220 file_menu->Append(wxID_SAVEAS, "Save &As...");
221 file_menu->Append(wxID_CLOSE, "&Close");
223 file_menu->AppendSeparator();
224 file_menu->Append(IFMENU_FILE_PROPERTIES, "P&roperties");
226 file_menu->AppendSeparator();
227 file_menu->Append(wxID_PRINT, "&Print...");
228 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
229 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
231 wxMenu *view_menu = new wxMenu;
232 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...");
233 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...");
235 wxMenu *help_menu = new wxMenu;
236 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
238 wxMenuBar *menu_bar = new wxMenuBar;
240 menu_bar->Append(file_menu, "&File");
241 menu_bar->Append(view_menu, "&View");
242 menu_bar->Append(help_menu, "&Help");
244 subframe->SetMenuBar(menu_bar);
246 subframe->Centre(wxBOTH);
253 ImageFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
255 m_frame = CreateChildFrame(doc, this);
258 m_bMinSpecified = false;
259 m_bMaxSpecified = false;
260 m_dAutoScaleFactor = 1.;
263 m_frame->GetClientSize(&width, &height);
264 m_frame->SetTitle("ImageFileView");
265 m_canvas = CreateCanvas(this, m_frame);
268 int x, y; // X requires a forced resize
269 m_frame->GetSize(&x, &y);
270 m_frame->SetSize(-1, -1, x, y);
280 ImageFileView::OnDraw (wxDC* dc)
283 dc->DrawBitmap(m_bitmap, 0, 0, false);
288 ImageFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
290 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
291 ImageFileArrayConst v = rIF.getArray();
294 if (v != NULL && nx != 0 && ny != 0) {
295 if (! m_bMinSpecified || ! m_bMaxSpecified) {
297 rIF.getMinMax (min, max);
298 if (! m_bMinSpecified)
300 if (! m_bMaxSpecified)
303 double scaleWidth = m_dMaxPixel - m_dMinPixel;
305 unsigned char* imageData = new unsigned char [nx * ny * 3];
306 for (int ix = 0; ix < nx; ix++) {
307 for (int iy = 0; iy < ny; iy++) {
308 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
309 int intensity = static_cast<int>(scaleValue + 0.5);
310 intensity = clamp (intensity, 0, 255);
311 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
312 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
315 wxImage image (nx, ny, imageData, true);
316 m_bitmap = image.ConvertToBitmap();
320 xSize = clamp (xSize, 0, 800);
321 ySize = clamp (ySize, 0, 800);
322 m_frame->SetClientSize (xSize, ySize);
323 m_canvas->SetScrollbars(20, 20, nx/20, ny/20);
324 m_canvas->SetBackgroundColour(*wxWHITE);
332 ImageFileView::OnClose (bool deleteWindow)
334 if (!GetDocument()->Close())
338 m_canvas->m_pView = NULL;
340 wxString s(theApp->GetAppName());
342 m_frame->SetTitle(s);
358 PhantomCanvas::PhantomCanvas (PhantomView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
359 : wxScrolledWindow(frame, -1, pos, size, style)
365 PhantomCanvas::OnDraw(wxDC& dc)
368 m_pView->OnDraw(& dc);
374 IMPLEMENT_DYNAMIC_CLASS(PhantomView, wxView)
376 BEGIN_EVENT_TABLE(PhantomView, wxView)
377 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomView::OnProperties)
378 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomView::OnRasterize)
379 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomView::OnProjections)
382 PhantomView::PhantomView(void)
383 : wxView(), m_canvas(NULL), m_frame(NULL)
387 PhantomView::~PhantomView(void)
392 PhantomView::OnProperties (wxCommandEvent& event)
394 const int idPhantom = GetDocument()->getPhantomID();
395 const string& namePhantom = GetDocument()->getPhantomName();
397 os << "Phantom " << namePhantom << " (" << 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, 367, 320, 1, 1., 1., 1., Scanner::GEOMETRY_PARALLEL, Trace::TRACE_NONE);
410 int retVal = dialogProjection.ShowModal();
411 if (retVal == wxID_OK) {
412 int nDet = dialogProjection.getNDet();
413 int nView = dialogProjection.getNView();
414 int nSamples = dialogProjection.getNSamples();
415 int iTrace = dialogProjection.getTrace();
416 double dRotAngle = dialogProjection.getRotAngle();
417 double dFocalLengthRatio = dialogProjection.getFocalLengthRatio();
418 double dFieldOfViewRatio = dialogProjection.getFieldOfViewRatio();
420 wxString sGeometry = dialogProjection.getGeometry();
421 if (nDet > 0 && nView > 0 && sGeometry != "") {
422 const Phantom& rPhantom = GetDocument()->getPhantom();
423 ProjectionFileDocument* pProjectionDoc = dynamic_cast<ProjectionFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.pj", wxDOC_SILENT));
424 Projections& rProj = pProjectionDoc->getProjections();
425 Scanner theScanner (rPhantom, sGeometry.c_str(), nDet, nView, nSamples, dRotAngle, dFocalLengthRatio, dFieldOfViewRatio);
426 if (theScanner.fail()) {
427 *theApp->getLog() << "Failed making scanner: " << theScanner.failMessage().c_str() << "\n";
430 rProj.initFromScanner (theScanner);
432 if (iTrace > Trace::TRACE_CONSOLE) {
433 ProjectionsDialog dialogProjections (theScanner, rProj, rPhantom, iTrace, dynamic_cast<wxWindow*>(m_frame));
434 for (int iView = 0; iView < rProj.nView(); iView++) {
437 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
438 pProjectionDoc->DeleteAllViews();
443 while (dialogProjections.isPaused()) {
449 theScanner.collectProjections (rProj, rPhantom, iTrace);
451 pProjectionDoc->Modify(true);
452 pProjectionDoc->UpdateAllViews(this);
453 if (wxView* pView = pProjectionDoc->GetFirstView())
454 if (wxFrame* pFrame = pView->GetFrame()) {
458 os << "Projections for " << rPhantom.name() << ": nDet=" << nDet << ", nView=" << nView << ", nSamples=" << nSamples << ", RotAngle=" << dRotAngle << ", FocalLengthRatio=" << dFocalLengthRatio << ", FieldOfViewRatio=" << dFieldOfViewRatio << ", Geometry=" << sGeometry.c_str() << "\n";
459 rProj.setRemark (os.str());
460 *theApp->getLog() << os.str().c_str();
467 PhantomView::OnRasterize (wxCommandEvent& event)
469 DialogGetRasterParameters dialogRaster (m_frame, 256, 256, 1);
470 int retVal = dialogRaster.ShowModal();
471 if (retVal == wxID_OK) {
472 int xSize = dialogRaster.getXSize();
473 int ySize = dialogRaster.getYSize();
474 int nSamples = dialogRaster.getNSamples();
477 if (xSize > 0 && ySize > 0) {
478 const Phantom& rPhantom = GetDocument()->getPhantom();
479 ImageFileDocument* pRasterDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
480 ImageFile& imageFile = pRasterDoc->getImageFile();
482 imageFile.setArraySize (xSize, ySize);
483 rPhantom.convertToImagefile (imageFile, nSamples, Trace::TRACE_NONE);
484 pRasterDoc->Modify(true);
485 pRasterDoc->UpdateAllViews(this);
488 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << xSize << ", YSize=" << ySize << ", nSamples=" << nSamples << "\n";
489 *theApp->getLog() << os.str().c_str();
496 PhantomView::CreateCanvas (wxView *view, wxFrame *parent)
498 PhantomCanvas* pCanvas;
500 parent->GetClientSize(&width, &height);
502 pCanvas = new PhantomCanvas (dynamic_cast<PhantomView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
504 pCanvas->SetBackgroundColour(*wxWHITE);
511 PhantomView::CreateChildFrame(wxDocument *doc, wxView *view)
513 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
515 wxMenu *file_menu = new wxMenu;
517 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
518 file_menu->Append(wxID_OPEN, "&Open...");
519 file_menu->Append(wxID_CLOSE, "&Close");
521 file_menu->AppendSeparator();
522 file_menu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties");
524 file_menu->AppendSeparator();
525 file_menu->Append(wxID_PRINT, "&Print...");
526 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
527 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
529 wxMenu *process_menu = new wxMenu;
530 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...");
531 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...");
533 wxMenu *help_menu = new wxMenu;
534 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
535 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
537 wxMenuBar *menu_bar = new wxMenuBar;
539 menu_bar->Append(file_menu, "&File");
540 menu_bar->Append(process_menu, "&Process");
541 menu_bar->Append(help_menu, "&Help");
543 subframe->SetMenuBar(menu_bar);
545 subframe->Centre(wxBOTH);
552 PhantomView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
554 m_frame = CreateChildFrame(doc, this);
558 m_frame->GetClientSize(&width, &height);
559 m_frame->SetTitle("PhantomView");
560 m_canvas = CreateCanvas(this, m_frame);
563 int x, y; // X requires a forced resize
564 m_frame->GetSize(&x, &y);
565 m_frame->SetSize(-1, -1, x, y);
576 PhantomView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
583 PhantomView::OnClose (bool deleteWindow)
585 if (!GetDocument()->Close())
589 m_canvas->m_pView = NULL;
591 wxString s(wxTheApp->GetAppName());
593 m_frame->SetTitle(s);
606 PhantomView::OnDraw (wxDC* dc)
609 m_canvas->GetClientSize (&xsize, &ysize);
610 SGPDriver driver (dc, xsize, ysize);
612 const Phantom& rPhantom = GetDocument()->getPhantom();
613 sgp.setColor (C_RED);
619 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
620 : wxScrolledWindow(frame, -1, pos, size, style)
626 ProjectionFileCanvas::OnDraw(wxDC& dc)
629 m_pView->OnDraw(& dc);
632 // ProjectionFileView
634 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
636 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
637 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
638 EVT_MENU(PJMENU_PROCESS_RECONSTRUCT, ProjectionFileView::OnReconstruct)
641 ProjectionFileView::ProjectionFileView(void)
642 : wxView(), m_canvas(NULL), m_frame(NULL)
646 ProjectionFileView::~ProjectionFileView(void)
651 ProjectionFileView::OnProperties (wxCommandEvent& event)
653 const Projections& rProj = GetDocument()->getProjections();
655 rProj.printScanInfo(os);
656 *theApp->getLog() << os.str().c_str();
661 ProjectionFileView::OnReconstruct (wxCommandEvent& event)
664 DialogGetReconstructionParameters dialogReconstruction (m_frame, 256, 256, SignalFilter::FILTER_ABS_BANDLIMIT, 1., ProcessSignal::FILTER_METHOD_RFFTW, ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER, 1, Backprojector::INTERP_LINEAR, 1, Backprojector::BPROJ_IDIFF3);
666 DialogGetReconstructionParameters dialogReconstruction (m_frame, 256, 256, SignalFilter::FILTER_ABS_BANDLIMIT, 1., ProcessSignal::FILTER_METHOD_CONVOLUTION, ProcessSignal::FILTER_GENERATION_DIRECT, 1, Backprojector::INTERP_LINEAR, 1, Backprojector::BPROJ_IDIFF3);
668 int retVal = dialogReconstruction.ShowModal();
669 if (retVal == wxID_OK) {
670 int xSize = dialogReconstruction.getXSize();
671 int ySize = dialogReconstruction.getYSize();
672 wxString optFilterName = dialogReconstruction.getFilterName();
673 double optFilterParam = dialogReconstruction.getFilterParam();
674 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
675 int optZeropad = dialogReconstruction.getZeropad();
676 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
677 wxString optInterpName = dialogReconstruction.getInterpName();
678 int optInterpParam = dialogReconstruction.getInterpParam();
679 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
680 if (xSize > 0 && ySize > 0) {
681 ImageFileDocument* pReconDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
682 ImageFile& imageFile = pReconDoc->getImageFile();
683 const Projections& rProj = GetDocument()->getProjections();
684 imageFile.setArraySize (xSize, ySize);
685 rProj.reconstruct (imageFile, optFilterName.c_str(), optFilterParam, optFilterMethodName.c_str(), optZeropad, optFilterGenerationName.c_str(), optInterpName.c_str(), optInterpParam, optBackprojectName.c_str(), Trace::TRACE_NONE);
686 pReconDoc->Modify(true);
687 pReconDoc->UpdateAllViews(this);
689 os << "Reconstruct " << rProj.getFilename() << ": xSize=" << xSize << ", ySize=" << ySize << ", Filter=" << optFilterName.c_str() << ", FilterParam=" << optFilterParam << ", FilterMethod=" << optFilterMethodName.c_str() << ", FilterGeneration=" << optFilterGenerationName.c_str() << ", Zeropad=" << optZeropad << ", Interpolation=" << optInterpName.c_str() << ", InterpolationParam=" << optInterpParam << ", Backprojection=" << optBackprojectName.c_str() << "\n";
690 *theApp->getLog() << os.str().c_str();
696 ProjectionFileCanvas*
697 ProjectionFileView::CreateCanvas (wxView *view, wxFrame *parent)
699 ProjectionFileCanvas* pCanvas;
701 parent->GetClientSize(&width, &height);
703 pCanvas = new ProjectionFileCanvas (dynamic_cast<ProjectionFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
705 pCanvas->SetScrollbars(20, 20, 50, 50);
706 pCanvas->SetBackgroundColour(*wxWHITE);
713 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
715 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
717 wxMenu *file_menu = new wxMenu;
719 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
720 file_menu->Append(wxID_OPEN, "&Open...");
721 file_menu->Append(wxID_SAVE, "&Save");
722 file_menu->Append(wxID_SAVEAS, "Save &As...");
723 file_menu->Append(wxID_CLOSE, "&Close");
725 file_menu->AppendSeparator();
726 file_menu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
728 file_menu->AppendSeparator();
729 file_menu->Append(wxID_PRINT, "&Print...");
730 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
731 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
733 wxMenu *process_menu = new wxMenu;
734 process_menu->Append(PJMENU_PROCESS_RECONSTRUCT, "R&econstruct...");
736 wxMenu *help_menu = new wxMenu;
737 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
738 help_menu->AppendSeparator();
739 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
741 wxMenuBar *menu_bar = new wxMenuBar;
743 menu_bar->Append(file_menu, "&File");
744 menu_bar->Append(process_menu, "&Process");
745 menu_bar->Append(help_menu, "&Help");
747 subframe->SetMenuBar(menu_bar);
749 subframe->Centre(wxBOTH);
756 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
758 m_frame = CreateChildFrame(doc, this);
762 m_frame->GetClientSize(&width, &height);
763 m_frame->SetTitle("ProjectionFileView");
764 m_canvas = CreateCanvas(this, m_frame);
767 int x, y; // X requires a forced resize
768 m_frame->GetSize(&x, &y);
769 m_frame->SetSize(-1, -1, x, y);
779 ProjectionFileView::OnDraw (wxDC* dc)
782 dc->DrawBitmap (m_bitmap, 0, 0, false);
787 ProjectionFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
789 const Projections& rProj = GetDocument()->getProjections();
790 const int nDet = rProj.nDet();
791 const int nView = rProj.nView();
792 if (nDet != 0 && nView != 0) {
793 const DetectorArray& detarray = rProj.getDetectorArray(0);
794 const DetectorValue* detval = detarray.detValues();
795 double min = detval[0];
796 double max = detval[0];
797 for (int iy = 0; iy < nView; iy++) {
798 const DetectorArray& detarray = rProj.getDetectorArray(iy);
799 const DetectorValue* detval = detarray.detValues();
800 for (int ix = 0; ix < nDet; ix++) {
801 if (min > detval[ix])
803 else if (max < detval[ix])
808 unsigned char* imageData = new unsigned char [nDet * nView * 3];
809 double scale = (max - min) / 255;
810 for (int iy = 0; iy < nView; iy++) {
811 const DetectorArray& detarray = rProj.getDetectorArray(iy);
812 const DetectorValue* detval = detarray.detValues();
813 for (int ix = 0; ix < nDet; ix++) {
814 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
815 intensity = clamp(intensity, 0, 255);
816 int baseAddr = (iy * nDet + ix) * 3;
817 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
820 wxImage image (nDet, nView, imageData, true);
821 m_bitmap = image.ConvertToBitmap();
825 xSize = clamp (xSize, 0, 800);
826 ySize = clamp (ySize, 0, 800);
827 m_frame->SetClientSize (xSize, ySize);
828 m_canvas->SetScrollbars (20, 20, nDet/20, nView/20);
836 ProjectionFileView::OnClose (bool deleteWindow)
838 if (!GetDocument()->Close())
842 m_canvas->m_pView = NULL;
844 wxString s(wxTheApp->GetAppName());
846 m_frame->SetTitle(s);