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.16 2000/08/25 15:59:13 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!
55 #include "backprojectors.h"
59 BEGIN_EVENT_TABLE(ImageFileCanvas, wxScrolledWindow)
60 EVT_MOUSE_EVENTS(ImageFileCanvas::OnMouseEvent)
64 ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
65 : wxScrolledWindow(frame, -1, pos, size, style)
71 ImageFileCanvas::OnDraw(wxDC& dc)
74 m_pView->OnDraw(& dc);
78 ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
86 wxPoint pt(event.GetLogicalPosition(dc));
88 if (event.LeftIsDown()) {
89 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
90 ImageFileArrayConst v = rIF.getArray();
94 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 & pt.y < ny) {
96 os << "Image value (" << pt.x << "," << pt.y << ") = " << v[pt.x][ny - 1 - pt.y] << "\n";
97 *theApp->getLog() << os.str().c_str();
99 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << pt.y << ")\n";
107 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
109 BEGIN_EVENT_TABLE(ImageFileView, wxView)
110 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
111 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
112 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
115 ImageFileView::ImageFileView(void)
116 : wxView(), m_canvas(NULL), m_frame(NULL), m_bMinSpecified(false), m_bMaxSpecified(false)
120 ImageFileView::~ImageFileView(void)
125 ImageFileView::OnProperties (wxCommandEvent& event)
127 double min, max, mean, mode, median, stddev;
128 const ImageFile& rIF = GetDocument()->getImageFile();
129 if (rIF.nx() == 0 || rIF.ny() == 0)
130 *theApp->getLog() << "Properties: empty imagefile\n";
132 const string& rFilename = rIF.getFilename();
133 rIF.statistics (min, max, mean, mode, median, stddev);
135 os << "file: " << rFilename << "\nmin: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
136 *theApp->getLog() << os.str().c_str();
139 ostringstream osSize;
140 m_frame->GetSize (&xSize, &ySize);
141 osSize << "Frame size: (" << xSize << "," << ySize << ")\n";
142 m_frame->GetClientSize (&xSize, &ySize);
143 osSize << "Frame Client size: (" << xSize << "," << ySize << ")\n";
144 m_canvas->GetSize (&xSize, &ySize);
145 osSize << "Canvas size: (" << xSize << "," << ySize << ")\n";
146 *theApp->getLog() << osSize.str().c_str();
151 ImageFileView::OnScaleAuto (wxCommandEvent& event)
153 const ImageFile& rIF = GetDocument()->getImageFile();
154 DialogAutoScaleParameters dialogAutoScale (m_frame, rIF);
155 int iRetVal = dialogAutoScale.ShowModal();
156 if (iRetVal == wxID_OK) {
157 m_bMinSpecified = true;
158 m_bMaxSpecified = true;
160 dialogAutoScale.getMinMax (&dMin, &dMax);
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_CLOSE, "&Close");
218 file_menu->Append(wxID_SAVE, "&Save");
219 file_menu->Append(wxID_SAVEAS, "Save &As...");
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);
255 m_bMinSpecified = false;
256 m_bMaxSpecified = false;
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)
383 PhantomView::~PhantomView(void)
388 PhantomView::OnProperties (wxCommandEvent& event)
390 const int idPhantom = GetDocument()->getPhantomID();
391 const string& namePhantom = GetDocument()->getPhantomName();
393 os << "Phantom " << namePhantom << " (" << idPhantom << ")\n";
394 *theApp->getLog() << os.str().c_str();
396 const Phantom& rPhantom = GetDocument()->getPhantom();
403 PhantomView::OnProjections (wxCommandEvent& event)
405 DialogGetProjectionParameters dialogProjection (m_frame, 367, 320, 1, 1., 1., 1., Scanner::GEOMETRY_PARALLEL);
406 int retVal = dialogProjection.ShowModal();
407 if (retVal == wxID_OK) {
408 int nDet = dialogProjection.getNDet();
409 int nView = dialogProjection.getNView();
410 int nSamples = dialogProjection.getNSamples();
411 double dRotAngle = dialogProjection.getRotAngle();
412 double dFocalLengthRatio = dialogProjection.getFocalLengthRatio();
413 double dFieldOfViewRatio = dialogProjection.getFieldOfViewRatio();
415 wxString sGeometry = dialogProjection.getGeometry();
416 if (nDet > 0 && nView > 0 && sGeometry != "") {
417 const Phantom& rPhantom = GetDocument()->getPhantom();
418 ProjectionFileDocument* pProjectionDoc = dynamic_cast<ProjectionFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.pj", wxDOC_SILENT));
419 Projections& rProj = pProjectionDoc->getProjections();
420 Scanner theScanner (rPhantom, sGeometry.c_str(), nDet, nView, nSamples, dRotAngle, dFocalLengthRatio, dFieldOfViewRatio);
421 if (theScanner.fail()) {
422 *theApp->getLog() << "Failed making scanner: " << theScanner.failMessage().c_str() << "\n";
425 rProj.initFromScanner (theScanner);
428 wxFrame frame (m_frame, -1, "", wxDefaultPosition, wxSize(500,500));
430 wxClientDC dc (&frame);
432 frame.GetClientSize(&x, &y);
433 SGPDriver driver (dynamic_cast<wxDC*>(&dc), x, y);
435 for (int iView = 0; iView < rProj.nView(); iView++) {
436 theScanner.collectProjections (rProj, rPhantom, iView, 1, true, TRACE_RAYS, &sgp);
439 theScanner.collectProjections (rProj, rPhantom);
442 pProjectionDoc->Modify(true);
443 pProjectionDoc->UpdateAllViews(this);
445 os << "Projections for " << rPhantom.name() << ": nDet=" << nDet << ", nView=" << nView << ", nSamples=" << nSamples << ", RotAngle=" << dRotAngle << ", FocalLengthRatio=" << dFocalLengthRatio << ", FieldOfViewRatio=" << dFieldOfViewRatio << ", Geometry=" << sGeometry.c_str() << "\n";
446 *theApp->getLog() << os.str().c_str();
453 PhantomView::OnRasterize (wxCommandEvent& event)
455 DialogGetRasterParameters dialogRaster (m_frame, 256, 256, 1);
456 int retVal = dialogRaster.ShowModal();
457 if (retVal == wxID_OK) {
458 int xSize = dialogRaster.getXSize();
459 int ySize = dialogRaster.getYSize();
460 int nSamples = dialogRaster.getNSamples();
463 if (xSize > 0 && ySize > 0) {
464 const Phantom& rPhantom = GetDocument()->getPhantom();
465 ImageFileDocument* pRasterDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
466 ImageFile& imageFile = pRasterDoc->getImageFile();
468 imageFile.setArraySize (xSize, ySize);
469 rPhantom.convertToImagefile (imageFile, nSamples, TRACE_NONE);
470 pRasterDoc->Modify(true);
471 pRasterDoc->UpdateAllViews(this);
474 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << xSize << ", YSize=" << ySize << ", nSamples=" << nSamples << "\n";
475 *theApp->getLog() << os.str().c_str();
482 PhantomView::CreateCanvas (wxView *view, wxFrame *parent)
484 PhantomCanvas* pCanvas;
486 parent->GetClientSize(&width, &height);
488 pCanvas = new PhantomCanvas (dynamic_cast<PhantomView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
490 pCanvas->SetBackgroundColour(*wxWHITE);
497 PhantomView::CreateChildFrame(wxDocument *doc, wxView *view)
499 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
501 wxMenu *file_menu = new wxMenu;
503 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
504 file_menu->Append(wxID_OPEN, "&Open...");
505 file_menu->Append(wxID_CLOSE, "&Close");
507 file_menu->AppendSeparator();
508 file_menu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties");
510 file_menu->AppendSeparator();
511 file_menu->Append(wxID_PRINT, "&Print...");
512 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
513 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
515 wxMenu *process_menu = new wxMenu;
516 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...");
517 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...");
519 wxMenu *help_menu = new wxMenu;
520 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
521 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
523 wxMenuBar *menu_bar = new wxMenuBar;
525 menu_bar->Append(file_menu, "&File");
526 menu_bar->Append(process_menu, "&Process");
527 menu_bar->Append(help_menu, "&Help");
529 subframe->SetMenuBar(menu_bar);
531 subframe->Centre(wxBOTH);
538 PhantomView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
540 m_frame = CreateChildFrame(doc, this);
543 m_frame->GetClientSize(&width, &height);
544 m_frame->SetTitle("PhantomView");
545 m_canvas = CreateCanvas(this, m_frame);
548 int x, y; // X requires a forced resize
549 m_frame->GetSize(&x, &y);
550 m_frame->SetSize(-1, -1, x, y);
561 PhantomView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
568 PhantomView::OnClose (bool deleteWindow)
570 if (!GetDocument()->Close())
574 m_canvas->m_pView = NULL;
576 wxString s(wxTheApp->GetAppName());
578 m_frame->SetTitle(s);
591 PhantomView::OnDraw (wxDC* dc)
594 m_canvas->GetClientSize (&xsize, &ysize);
595 SGPDriver driver (dc, xsize, ysize);
597 const Phantom& rPhantom = GetDocument()->getPhantom();
598 sgp.setColor (C_RED);
604 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
605 : wxScrolledWindow(frame, -1, pos, size, style)
611 ProjectionFileCanvas::OnDraw(wxDC& dc)
614 m_pView->OnDraw(& dc);
617 // ProjectionFileView
619 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
621 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
622 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
623 EVT_MENU(PJMENU_PROCESS_RECONSTRUCT, ProjectionFileView::OnReconstruct)
626 ProjectionFileView::ProjectionFileView(void)
627 : wxView(), m_canvas(NULL), m_frame(NULL)
631 ProjectionFileView::~ProjectionFileView(void)
636 ProjectionFileView::OnProperties (wxCommandEvent& event)
638 const Projections& rProj = GetDocument()->getProjections();
640 os << "ProjectionFile " << rProj.getFilename() << ": Number of Detectors = " << rProj.nDet() << ", Number of Views = " << rProj.nView() << "\n";
641 *theApp->getLog() << os.str().c_str();
646 ProjectionFileView::OnReconstruct (wxCommandEvent& event)
649 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);
651 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);
653 int retVal = dialogReconstruction.ShowModal();
654 if (retVal == wxID_OK) {
655 int xSize = dialogReconstruction.getXSize();
656 int ySize = dialogReconstruction.getYSize();
657 wxString optFilterName = dialogReconstruction.getFilterName();
658 double optFilterParam = dialogReconstruction.getFilterParam();
659 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
660 int optZeropad = dialogReconstruction.getZeropad();
661 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
662 wxString optInterpName = dialogReconstruction.getInterpName();
663 int optInterpParam = dialogReconstruction.getInterpParam();
664 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
665 if (xSize > 0 && ySize > 0) {
666 ImageFileDocument* pReconDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
667 ImageFile& imageFile = pReconDoc->getImageFile();
668 const Projections& rProj = GetDocument()->getProjections();
669 imageFile.setArraySize (xSize, ySize);
670 rProj.reconstruct (imageFile, optFilterName.c_str(), optFilterParam, optFilterMethodName.c_str(), optZeropad, optFilterGenerationName.c_str(), optInterpName.c_str(), optInterpParam, optBackprojectName.c_str(), TRACE_NONE);
671 pReconDoc->Modify(true);
672 pReconDoc->UpdateAllViews(this);
674 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";
675 *theApp->getLog() << os.str().c_str();
681 ProjectionFileCanvas*
682 ProjectionFileView::CreateCanvas (wxView *view, wxFrame *parent)
684 ProjectionFileCanvas* pCanvas;
686 parent->GetClientSize(&width, &height);
688 pCanvas = new ProjectionFileCanvas (dynamic_cast<ProjectionFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
690 pCanvas->SetScrollbars(20, 20, 50, 50);
691 pCanvas->SetBackgroundColour(*wxWHITE);
698 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
700 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
702 wxMenu *file_menu = new wxMenu;
704 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
705 file_menu->Append(wxID_OPEN, "&Open...");
706 file_menu->Append(wxID_CLOSE, "&Close");
708 file_menu->AppendSeparator();
709 file_menu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
711 file_menu->AppendSeparator();
712 file_menu->Append(wxID_PRINT, "&Print...");
713 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
714 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
716 wxMenu *process_menu = new wxMenu;
717 process_menu->Append(PJMENU_PROCESS_RECONSTRUCT, "R&econstruct...");
719 wxMenu *help_menu = new wxMenu;
720 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
721 help_menu->AppendSeparator();
722 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
724 wxMenuBar *menu_bar = new wxMenuBar;
726 menu_bar->Append(file_menu, "&File");
727 menu_bar->Append(process_menu, "&Process");
728 menu_bar->Append(help_menu, "&Help");
730 subframe->SetMenuBar(menu_bar);
732 subframe->Centre(wxBOTH);
739 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
741 m_frame = CreateChildFrame(doc, this);
744 m_frame->GetClientSize(&width, &height);
745 m_frame->SetTitle("ProjectionFileView");
746 m_canvas = CreateCanvas(this, m_frame);
749 int x, y; // X requires a forced resize
750 m_frame->GetSize(&x, &y);
751 m_frame->SetSize(-1, -1, x, y);
761 ProjectionFileView::OnDraw (wxDC* dc)
764 dc->DrawBitmap (m_bitmap, 0, 0, false);
769 ProjectionFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
771 const Projections& rProj = GetDocument()->getProjections();
772 const int nDet = rProj.nDet();
773 const int nView = rProj.nView();
774 if (nDet != 0 && nView != 0) {
775 const DetectorArray& detarray = rProj.getDetectorArray(0);
776 const DetectorValue* detval = detarray.detValues();
777 double min = detval[0];
778 double max = detval[0];
779 for (int iy = 0; iy < nView; iy++) {
780 const DetectorArray& detarray = rProj.getDetectorArray(iy);
781 const DetectorValue* detval = detarray.detValues();
782 for (int ix = 0; ix < nDet; ix++) {
783 if (min > detval[ix])
785 else if (max < detval[ix])
790 unsigned char* imageData = new unsigned char [nDet * nView * 3];
791 double scale = (max - min) / 255;
792 for (int iy = 0; iy < nView; iy++) {
793 const DetectorArray& detarray = rProj.getDetectorArray(iy);
794 const DetectorValue* detval = detarray.detValues();
795 for (int ix = 0; ix < nDet; ix++) {
796 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
797 intensity = clamp(intensity, 0, 255);
798 int baseAddr = (iy * nDet + ix) * 3;
799 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
802 wxImage image (nDet, nView, imageData, true);
803 m_bitmap = image.ConvertToBitmap();
807 xSize = clamp (xSize, 0, 800);
808 ySize = clamp (ySize, 0, 800);
809 m_frame->SetClientSize (xSize, ySize);
810 m_canvas->SetScrollbars (20, 20, nDet/20, nView/20);
818 ProjectionFileView::OnClose (bool deleteWindow)
820 if (!GetDocument()->Close())
824 m_canvas->m_pView = NULL;
826 wxString s(wxTheApp->GetAppName());
828 m_frame->SetTitle(s);