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.17 2000/08/27 20:32:55 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);
156 int iRetVal = dialogAutoScale.ShowModal();
157 if (iRetVal == wxID_OK) {
158 m_bMinSpecified = true;
159 m_bMaxSpecified = true;
161 dialogAutoScale.getMinMax (&dMin, &dMax);
164 OnUpdate (this, NULL);
169 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
171 const ImageFile& rIF = GetDocument()->getImageFile();
173 if (! m_bMinSpecified && ! m_bMaxSpecified)
174 rIF.getMinMax (min, max);
181 DialogGetImageMinMax dialogMinMax (m_frame, rIF, min, max);
182 int retVal = dialogMinMax.ShowModal();
183 if (retVal == wxID_OK) {
184 m_bMinSpecified = true;
185 m_bMaxSpecified = true;
186 m_dMinPixel = dialogMinMax.getMinimum();
187 m_dMaxPixel = dialogMinMax.getMaximum();
188 OnUpdate (this, NULL);
194 ImageFileView::CreateCanvas (wxView *view, wxFrame *parent)
196 ImageFileCanvas* pCanvas;
198 parent->GetClientSize(&width, &height);
200 pCanvas = new ImageFileCanvas (dynamic_cast<ImageFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
202 pCanvas->SetScrollbars(20, 20, 50, 50);
203 pCanvas->SetBackgroundColour(*wxWHITE);
210 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
212 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
214 wxMenu *file_menu = new wxMenu;
216 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
217 file_menu->Append(wxID_OPEN, "&Open...");
218 file_menu->Append(wxID_SAVE, "&Save");
219 file_menu->Append(wxID_SAVEAS, "Save &As...");
220 file_menu->Append(wxID_CLOSE, "&Close");
222 file_menu->AppendSeparator();
223 file_menu->Append(IFMENU_FILE_PROPERTIES, "P&roperties");
225 file_menu->AppendSeparator();
226 file_menu->Append(wxID_PRINT, "&Print...");
227 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
228 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
230 wxMenu *view_menu = new wxMenu;
231 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...");
232 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...");
234 wxMenu *help_menu = new wxMenu;
235 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
237 wxMenuBar *menu_bar = new wxMenuBar;
239 menu_bar->Append(file_menu, "&File");
240 menu_bar->Append(view_menu, "&View");
241 menu_bar->Append(help_menu, "&Help");
243 subframe->SetMenuBar(menu_bar);
245 subframe->Centre(wxBOTH);
252 ImageFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
254 m_frame = CreateChildFrame(doc, this);
257 m_bMinSpecified = false;
258 m_bMaxSpecified = false;
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)
385 PhantomView::~PhantomView(void)
390 PhantomView::OnProperties (wxCommandEvent& event)
392 const int idPhantom = GetDocument()->getPhantomID();
393 const string& namePhantom = GetDocument()->getPhantomName();
395 os << "Phantom " << namePhantom << " (" << idPhantom << ")\n";
396 *theApp->getLog() << os.str().c_str();
398 const Phantom& rPhantom = GetDocument()->getPhantom();
405 PhantomView::OnProjections (wxCommandEvent& event)
407 DialogGetProjectionParameters dialogProjection (m_frame, 367, 320, 1, 1., 1., 1., Scanner::GEOMETRY_PARALLEL, Trace::TRACE_NONE);
408 int retVal = dialogProjection.ShowModal();
409 if (retVal == wxID_OK) {
410 int nDet = dialogProjection.getNDet();
411 int nView = dialogProjection.getNView();
412 int nSamples = dialogProjection.getNSamples();
413 int iTrace = dialogProjection.getTrace();
414 double dRotAngle = dialogProjection.getRotAngle();
415 double dFocalLengthRatio = dialogProjection.getFocalLengthRatio();
416 double dFieldOfViewRatio = dialogProjection.getFieldOfViewRatio();
418 wxString sGeometry = dialogProjection.getGeometry();
419 if (nDet > 0 && nView > 0 && sGeometry != "") {
420 const Phantom& rPhantom = GetDocument()->getPhantom();
421 ProjectionFileDocument* pProjectionDoc = dynamic_cast<ProjectionFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.pj", wxDOC_SILENT));
422 Projections& rProj = pProjectionDoc->getProjections();
423 Scanner theScanner (rPhantom, sGeometry.c_str(), nDet, nView, nSamples, dRotAngle, dFocalLengthRatio, dFieldOfViewRatio);
424 if (theScanner.fail()) {
425 *theApp->getLog() << "Failed making scanner: " << theScanner.failMessage().c_str() << "\n";
428 rProj.initFromScanner (theScanner);
430 if (iTrace > Trace::TRACE_CONSOLE) {
431 ProjectionsDialog dialogProjections (theScanner, rProj, rPhantom, iTrace, dynamic_cast<wxWindow*>(m_frame));
432 for (int iView = 0; iView < rProj.nView(); iView++) {
433 if (! dialogProjections.projectView (iView)) {
434 pProjectionDoc->DeleteAllViews();
440 theScanner.collectProjections (rProj, rPhantom);
442 pProjectionDoc->Modify(true);
443 pProjectionDoc->UpdateAllViews(this);
444 if (wxView* pView = pProjectionDoc->GetFirstView())
445 if (wxFrame* pFrame = pView->GetFrame()) {
449 os << "Projections for " << rPhantom.name() << ": nDet=" << nDet << ", nView=" << nView << ", nSamples=" << nSamples << ", RotAngle=" << dRotAngle << ", FocalLengthRatio=" << dFocalLengthRatio << ", FieldOfViewRatio=" << dFieldOfViewRatio << ", Geometry=" << sGeometry.c_str() << "\n";
450 *theApp->getLog() << os.str().c_str();
457 PhantomView::OnRasterize (wxCommandEvent& event)
459 DialogGetRasterParameters dialogRaster (m_frame, 256, 256, 1);
460 int retVal = dialogRaster.ShowModal();
461 if (retVal == wxID_OK) {
462 int xSize = dialogRaster.getXSize();
463 int ySize = dialogRaster.getYSize();
464 int nSamples = dialogRaster.getNSamples();
467 if (xSize > 0 && ySize > 0) {
468 const Phantom& rPhantom = GetDocument()->getPhantom();
469 ImageFileDocument* pRasterDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
470 ImageFile& imageFile = pRasterDoc->getImageFile();
472 imageFile.setArraySize (xSize, ySize);
473 rPhantom.convertToImagefile (imageFile, nSamples, Trace::TRACE_NONE);
474 pRasterDoc->Modify(true);
475 pRasterDoc->UpdateAllViews(this);
478 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << xSize << ", YSize=" << ySize << ", nSamples=" << nSamples << "\n";
479 *theApp->getLog() << os.str().c_str();
486 PhantomView::CreateCanvas (wxView *view, wxFrame *parent)
488 PhantomCanvas* pCanvas;
490 parent->GetClientSize(&width, &height);
492 pCanvas = new PhantomCanvas (dynamic_cast<PhantomView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
494 pCanvas->SetBackgroundColour(*wxWHITE);
501 PhantomView::CreateChildFrame(wxDocument *doc, wxView *view)
503 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
505 wxMenu *file_menu = new wxMenu;
507 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
508 file_menu->Append(wxID_OPEN, "&Open...");
509 file_menu->Append(wxID_CLOSE, "&Close");
511 file_menu->AppendSeparator();
512 file_menu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties");
514 file_menu->AppendSeparator();
515 file_menu->Append(wxID_PRINT, "&Print...");
516 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
517 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
519 wxMenu *process_menu = new wxMenu;
520 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...");
521 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...");
523 wxMenu *help_menu = new wxMenu;
524 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
525 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
527 wxMenuBar *menu_bar = new wxMenuBar;
529 menu_bar->Append(file_menu, "&File");
530 menu_bar->Append(process_menu, "&Process");
531 menu_bar->Append(help_menu, "&Help");
533 subframe->SetMenuBar(menu_bar);
535 subframe->Centre(wxBOTH);
542 PhantomView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
544 m_frame = CreateChildFrame(doc, this);
548 m_frame->GetClientSize(&width, &height);
549 m_frame->SetTitle("PhantomView");
550 m_canvas = CreateCanvas(this, m_frame);
553 int x, y; // X requires a forced resize
554 m_frame->GetSize(&x, &y);
555 m_frame->SetSize(-1, -1, x, y);
566 PhantomView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
573 PhantomView::OnClose (bool deleteWindow)
575 if (!GetDocument()->Close())
579 m_canvas->m_pView = NULL;
581 wxString s(wxTheApp->GetAppName());
583 m_frame->SetTitle(s);
596 PhantomView::OnDraw (wxDC* dc)
599 m_canvas->GetClientSize (&xsize, &ysize);
600 SGPDriver driver (dc, xsize, ysize);
602 const Phantom& rPhantom = GetDocument()->getPhantom();
603 sgp.setColor (C_RED);
609 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
610 : wxScrolledWindow(frame, -1, pos, size, style)
616 ProjectionFileCanvas::OnDraw(wxDC& dc)
619 m_pView->OnDraw(& dc);
622 // ProjectionFileView
624 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
626 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
627 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
628 EVT_MENU(PJMENU_PROCESS_RECONSTRUCT, ProjectionFileView::OnReconstruct)
631 ProjectionFileView::ProjectionFileView(void)
632 : wxView(), m_canvas(NULL), m_frame(NULL)
636 ProjectionFileView::~ProjectionFileView(void)
641 ProjectionFileView::OnProperties (wxCommandEvent& event)
643 const Projections& rProj = GetDocument()->getProjections();
645 os << "ProjectionFile " << rProj.getFilename() << ": Number of Detectors = " << rProj.nDet() << ", Number of Views = " << rProj.nView() << "\n";
646 *theApp->getLog() << os.str().c_str();
651 ProjectionFileView::OnReconstruct (wxCommandEvent& event)
654 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);
656 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);
658 int retVal = dialogReconstruction.ShowModal();
659 if (retVal == wxID_OK) {
660 int xSize = dialogReconstruction.getXSize();
661 int ySize = dialogReconstruction.getYSize();
662 wxString optFilterName = dialogReconstruction.getFilterName();
663 double optFilterParam = dialogReconstruction.getFilterParam();
664 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
665 int optZeropad = dialogReconstruction.getZeropad();
666 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
667 wxString optInterpName = dialogReconstruction.getInterpName();
668 int optInterpParam = dialogReconstruction.getInterpParam();
669 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
670 if (xSize > 0 && ySize > 0) {
671 ImageFileDocument* pReconDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
672 ImageFile& imageFile = pReconDoc->getImageFile();
673 const Projections& rProj = GetDocument()->getProjections();
674 imageFile.setArraySize (xSize, ySize);
675 rProj.reconstruct (imageFile, optFilterName.c_str(), optFilterParam, optFilterMethodName.c_str(), optZeropad, optFilterGenerationName.c_str(), optInterpName.c_str(), optInterpParam, optBackprojectName.c_str(), Trace::TRACE_NONE);
676 pReconDoc->Modify(true);
677 pReconDoc->UpdateAllViews(this);
679 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";
680 *theApp->getLog() << os.str().c_str();
686 ProjectionFileCanvas*
687 ProjectionFileView::CreateCanvas (wxView *view, wxFrame *parent)
689 ProjectionFileCanvas* pCanvas;
691 parent->GetClientSize(&width, &height);
693 pCanvas = new ProjectionFileCanvas (dynamic_cast<ProjectionFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
695 pCanvas->SetScrollbars(20, 20, 50, 50);
696 pCanvas->SetBackgroundColour(*wxWHITE);
703 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
705 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
707 wxMenu *file_menu = new wxMenu;
709 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
710 file_menu->Append(wxID_OPEN, "&Open...");
711 file_menu->Append(wxID_SAVE, "&Save");
712 file_menu->Append(wxID_SAVEAS, "Save &As...");
713 file_menu->Append(wxID_CLOSE, "&Close");
715 file_menu->AppendSeparator();
716 file_menu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
718 file_menu->AppendSeparator();
719 file_menu->Append(wxID_PRINT, "&Print...");
720 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
721 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
723 wxMenu *process_menu = new wxMenu;
724 process_menu->Append(PJMENU_PROCESS_RECONSTRUCT, "R&econstruct...");
726 wxMenu *help_menu = new wxMenu;
727 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
728 help_menu->AppendSeparator();
729 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
731 wxMenuBar *menu_bar = new wxMenuBar;
733 menu_bar->Append(file_menu, "&File");
734 menu_bar->Append(process_menu, "&Process");
735 menu_bar->Append(help_menu, "&Help");
737 subframe->SetMenuBar(menu_bar);
739 subframe->Centre(wxBOTH);
746 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
748 m_frame = CreateChildFrame(doc, this);
752 m_frame->GetClientSize(&width, &height);
753 m_frame->SetTitle("ProjectionFileView");
754 m_canvas = CreateCanvas(this, m_frame);
757 int x, y; // X requires a forced resize
758 m_frame->GetSize(&x, &y);
759 m_frame->SetSize(-1, -1, x, y);
769 ProjectionFileView::OnDraw (wxDC* dc)
772 dc->DrawBitmap (m_bitmap, 0, 0, false);
777 ProjectionFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
779 const Projections& rProj = GetDocument()->getProjections();
780 const int nDet = rProj.nDet();
781 const int nView = rProj.nView();
782 if (nDet != 0 && nView != 0) {
783 const DetectorArray& detarray = rProj.getDetectorArray(0);
784 const DetectorValue* detval = detarray.detValues();
785 double min = detval[0];
786 double max = detval[0];
787 for (int iy = 0; iy < nView; iy++) {
788 const DetectorArray& detarray = rProj.getDetectorArray(iy);
789 const DetectorValue* detval = detarray.detValues();
790 for (int ix = 0; ix < nDet; ix++) {
791 if (min > detval[ix])
793 else if (max < detval[ix])
798 unsigned char* imageData = new unsigned char [nDet * nView * 3];
799 double scale = (max - min) / 255;
800 for (int iy = 0; iy < nView; iy++) {
801 const DetectorArray& detarray = rProj.getDetectorArray(iy);
802 const DetectorValue* detval = detarray.detValues();
803 for (int ix = 0; ix < nDet; ix++) {
804 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
805 intensity = clamp(intensity, 0, 255);
806 int baseAddr = (iy * nDet + ix) * 3;
807 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
810 wxImage image (nDet, nView, imageData, true);
811 m_bitmap = image.ConvertToBitmap();
815 xSize = clamp (xSize, 0, 800);
816 ySize = clamp (ySize, 0, 800);
817 m_frame->SetClientSize (xSize, ySize);
818 m_canvas->SetScrollbars (20, 20, nDet/20, nView/20);
826 ProjectionFileView::OnClose (bool deleteWindow)
828 if (!GetDocument()->Close())
832 m_canvas->m_pView = NULL;
834 wxString s(wxTheApp->GetAppName());
836 m_frame->SetTitle(s);