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.37 2000/12/23 18:12:35 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)
80 ImageFileCanvas::OnDraw(wxDC& dc)
83 m_pView->OnDraw(& dc);
87 ImageFileCanvas::DrawRubberBandCursor (wxDC& dc, int x, int y)
\r
89 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
\r
90 ImageFileArrayConst v = rIF.getArray();
\r
94 dc.SetLogicalFunction (wxINVERT);
\r
95 dc.SetPen (*wxGREEN_PEN);
\r
96 dc.DrawLine (0, y, nx, y);
\r
97 dc.DrawLine (x, 0, x, ny);
\r
98 dc.SetLogicalFunction (wxCOPY);
\r
102 ImageFileCanvas::GetCurrentCursor (int& x, int& y)
\r
107 if (m_xCursor >= 0 && m_yCursor >= 0)
\r
114 ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
122 wxPoint pt(event.GetLogicalPosition(dc));
124 if (event.RightIsDown()) {
\r
125 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
\r
126 ImageFileArrayConst v = rIF.getArray();
\r
130 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
\r
131 std::ostringstream os;
\r
132 os << "Image value (" << pt.x << "," << pt.y << ") = " << v[pt.x][ny - 1 - pt.y] << "\n";
\r
133 *theApp->getLog() << os.str().c_str();
\r
135 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << pt.y << ")\n";
\r
137 else if (event.LeftIsDown() || event.LeftUp()) {
\r
138 const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
\r
139 ImageFileArrayConst v = rIF.getArray();
\r
143 if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
\r
144 if (m_xCursor >= 0 && m_yCursor >= 0) {
\r
145 DrawRubberBandCursor (dc, m_xCursor, m_yCursor);
\r
147 DrawRubberBandCursor (dc, pt.x, pt.y);
\r
151 *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << pt.y << ")\n";
\r
153 if (event.LeftUp()) {
\r
154 std::ostringstream os;
\r
155 os << "Selected column" << pt.x << " and row" << pt.y << "\n";
\r
156 *theApp->getLog() << os.str().c_str();
\r
162 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
164 BEGIN_EVENT_TABLE(ImageFileView, wxView)
165 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
166 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
167 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
\r
168 EVT_MENU(IFMENU_COMPARE_IMAGES, ImageFileView::OnCompare)
\r
169 EVT_MENU(IFMENU_COMPARE_ROW, ImageFileView::OnCompareRow)
\r
170 EVT_MENU(IFMENU_COMPARE_COL, ImageFileView::OnCompareCol)
\r
171 EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)
\r
172 EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol)
\r
175 ImageFileView::ImageFileView(void)
176 : wxView(), m_canvas(NULL), m_frame(NULL), m_bMinSpecified(false), m_bMaxSpecified(false)
180 ImageFileView::~ImageFileView(void)
185 ImageFileView::OnProperties (wxCommandEvent& event)
187 double min, max, mean, mode, median, stddev;
188 const ImageFile& rIF = GetDocument()->getImageFile();
189 if (rIF.nx() == 0 || rIF.ny() == 0)
190 *theApp->getLog() << "Properties: empty imagefile\n";
192 const std::string& rFilename = rIF.getFilename();
193 rIF.statistics (min, max, mean, mode, median, stddev);
194 std::ostringstream os;
195 os << "file: " << rFilename << "\nmin: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
196 *theApp->getLog() << os.str().c_str();
197 wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
198 dialogMsg.ShowModal();
203 ImageFileView::OnScaleAuto (wxCommandEvent& event)
205 const ImageFile& rIF = GetDocument()->getImageFile();
206 double min, max, mean, mode, median, stddev;
\r
207 rIF.statistics(min, max, mean, mode, median, stddev);
\r
208 DialogAutoScaleParameters dialogAutoScale (m_frame, mean, mode, median, stddev, m_dAutoScaleFactor);
209 int iRetVal = dialogAutoScale.ShowModal();
210 if (iRetVal == wxID_OK) {
211 m_bMinSpecified = true;
212 m_bMaxSpecified = true;
214 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
217 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
218 OnUpdate (this, NULL);
\r
224 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
226 const ImageFile& rIF = GetDocument()->getImageFile();
228 if (! m_bMinSpecified && ! m_bMaxSpecified)
229 rIF.getMinMax (min, max);
236 DialogGetMinMax dialogMinMax (m_frame, "Set Image Minimum & Maximum", min, max);
237 int retVal = dialogMinMax.ShowModal();
238 if (retVal == wxID_OK) {
239 m_bMinSpecified = true;
240 m_bMaxSpecified = true;
241 m_dMinPixel = dialogMinMax.getMinimum();
242 m_dMaxPixel = dialogMinMax.getMaximum();
243 OnUpdate (this, NULL);
248 ImageFileView::OnCompare (wxCommandEvent& event)
\r
250 std::vector<ImageFileDocument*> vecIF;
\r
251 theApp->getCompatibleImages (GetDocument(), vecIF);
\r
253 if (vecIF.size() == 0) {
\r
254 wxMessageBox("There are no compatible image files open for comparision", "No comparison images");
\r
256 DialogGetComparisonImage dialogGetCompare(m_frame, "Get Comparison Image", vecIF, true);
\r
258 if (dialogGetCompare.ShowModal() == wxID_OK) {
\r
259 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
\r
260 const ImageFile& rIF = GetDocument()->getImageFile();
\r
261 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
\r
262 std::ostringstream os;
\r
263 double min, max, mean, mode, median, stddev;
\r
264 rIF.statistics (min, max, mean, mode, median, stddev);
\r
265 os << rIF.getFilename() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
\r
266 rCompareIF.statistics (min, max, mean, mode, median, stddev);
\r
267 os << rCompareIF.getFilename() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
\r
270 rIF.comparativeStatistics (rCompareIF, d, r, e);
\r
271 os << "Comparative Statistics: d=" << d << ", r=" << r << ", e=" << e << "\n";
\r
272 *theApp->getLog() << os.str().c_str();
\r
273 if (dialogGetCompare.getMakeDifferenceImage()) {
\r
274 ImageFileDocument* pDifferenceDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
\r
275 if (! pDifferenceDoc) {
\r
276 sys_error (ERR_SEVERE, "Unable to create image file");
\r
279 ImageFile& differenceImage = pDifferenceDoc->getImageFile();
\r
281 differenceImage.setArraySize (rIF.nx(), rIF.ny());
\r
282 if (! rIF.subtractImages (rCompareIF, differenceImage)) {
\r
283 pDifferenceDoc->DeleteAllViews();
\r
287 pDifferenceDoc->Modify(true);
\r
288 pDifferenceDoc->UpdateAllViews(this);
\r
289 pDifferenceDoc->GetFirstView()->OnUpdate (this, NULL);
\r
291 wxMessageBox(os.str().c_str(), "Image Comparison");
\r
297 ImageFileView::CreateCanvas (wxView *view, wxFrame *parent)
299 ImageFileCanvas* pCanvas;
301 parent->GetClientSize(&width, &height);
303 pCanvas = new ImageFileCanvas (dynamic_cast<ImageFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
305 pCanvas->SetScrollbars(20, 20, 50, 50);
306 pCanvas->SetBackgroundColour(*wxWHITE);
313 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
315 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
317 wxMenu *file_menu = new wxMenu;
319 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
320 file_menu->Append(wxID_OPEN, "&Open...");
321 file_menu->Append(wxID_SAVE, "&Save");
322 file_menu->Append(wxID_SAVEAS, "Save &As...");
323 file_menu->Append(wxID_CLOSE, "&Close");
325 file_menu->AppendSeparator();
326 file_menu->Append(IFMENU_FILE_PROPERTIES, "P&roperties");
328 file_menu->AppendSeparator();
329 file_menu->Append(wxID_PRINT, "&Print...");
330 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
331 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
333 wxMenu *view_menu = new wxMenu;
334 view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...");
335 view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...");
337 wxMenu *plot_menu = new wxMenu;
\r
338 plot_menu->Append (IFMENU_PLOT_ROW, "Plot &Row");
\r
339 plot_menu->Append (IFMENU_PLOT_COL, "Plot &Column");
\r
341 wxMenu *compare_menu = new wxMenu;
\r
342 compare_menu->Append (IFMENU_COMPARE_IMAGES, "Compare &Images...");
\r
343 compare_menu->Append (IFMENU_COMPARE_ROW, "Compare &Row");
\r
344 compare_menu->Append (IFMENU_COMPARE_COL, "Compare &Column");
\r
346 wxMenu *help_menu = new wxMenu;
347 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
349 wxMenuBar *menu_bar = new wxMenuBar;
351 menu_bar->Append(file_menu, "&File");
352 menu_bar->Append(view_menu, "&View");
\r
353 menu_bar->Append(plot_menu, "&Plot");
\r
354 menu_bar->Append(compare_menu, "&Compare");
355 menu_bar->Append(help_menu, "&Help");
357 subframe->SetMenuBar(menu_bar);
359 subframe->Centre(wxBOTH);
366 ImageFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
368 m_frame = CreateChildFrame(doc, this);
371 m_bMinSpecified = false;
372 m_bMaxSpecified = false;
373 m_dAutoScaleFactor = 1.;
376 m_frame->GetClientSize (&width, &height);
377 m_frame->SetTitle("ImageFileView");
378 m_canvas = CreateCanvas (this, m_frame);
380 int x, y; // X requires a forced resize
381 m_frame->GetSize(&x, &y);
382 m_frame->SetSize(-1, -1, x, y);
383 m_frame->SetFocus();
\r
391 ImageFileView::OnDraw (wxDC* dc)
394 dc->DrawBitmap(m_bitmap, 0, 0, false);
396 int xCursor, yCursor;
\r
397 if (m_canvas->GetCurrentCursor (xCursor, yCursor))
\r
398 m_canvas->DrawRubberBandCursor (*dc, xCursor, yCursor);
\r
403 ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
405 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
406 ImageFileArrayConst v = rIF.getArray();
409 if (v != NULL && nx != 0 && ny != 0) {
410 if (! m_bMinSpecified || ! m_bMaxSpecified) {
412 rIF.getMinMax (min, max);
413 if (! m_bMinSpecified)
415 if (! m_bMaxSpecified)
418 double scaleWidth = m_dMaxPixel - m_dMinPixel;
420 unsigned char* imageData = new unsigned char [nx * ny * 3];
421 for (int ix = 0; ix < nx; ix++) {
422 for (int iy = 0; iy < ny; iy++) {
423 double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
424 int intensity = static_cast<int>(scaleValue + 0.5);
425 intensity = clamp (intensity, 0, 255);
426 int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
427 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
430 wxImage image (nx, ny, imageData, true);
431 m_bitmap = image.ConvertToBitmap();
435 xSize = clamp (xSize, 0, 800);
436 ySize = clamp (ySize, 0, 800);
437 m_frame->SetClientSize (xSize, ySize);
438 m_canvas->SetScrollbars(20, 20, nx/20, ny/20);
439 m_canvas->SetBackgroundColour(*wxWHITE);
\r
447 ImageFileView::OnClose (bool deleteWindow)
449 if (!GetDocument()->Close())
453 m_canvas->m_pView = NULL;
455 wxString s(theApp->GetAppName());
457 m_frame->SetTitle(s);
471 ImageFileView::OnPlotRow (wxCommandEvent& event)
\r
473 int xCursor, yCursor;
\r
474 if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) {
\r
475 wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
\r
479 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
\r
480 ImageFileArrayConst v = rIF.getArray();
\r
484 if (v != NULL && yCursor < ny) {
\r
485 double* pX = new double [nx];
\r
486 double* pY = new double [nx];
\r
487 for (int i = 0; i < nx; i++) {
\r
489 pY[i] = v[i][yCursor];
\r
491 PlotFileDocument* pPlotDoc = dynamic_cast<PlotFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.plt", wxDOC_SILENT));
\r
493 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
\r
495 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
\r
496 std::ostringstream os;
\r
497 os << "Row " << yCursor;
\r
498 std::string title("title ");
\r
500 rPlotFile.addEzsetCommand (title.c_str());
\r
501 rPlotFile.addEzsetCommand ("xlabel Column");
\r
502 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
\r
503 rPlotFile.addEzsetCommand ("box");
\r
504 rPlotFile.addEzsetCommand ("grid");
\r
505 rPlotFile.setCurveSize (2, nx);
\r
506 rPlotFile.addColumn (0, pX);
\r
507 rPlotFile.addColumn (1, pY);
\r
511 pPlotDoc->Modify(true);
\r
517 ImageFileView::OnPlotCol (wxCommandEvent& event)
\r
519 int xCursor, yCursor;
\r
520 if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) {
\r
521 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
\r
525 const ImageFile& rIF = dynamic_cast<ImageFileDocument*>(GetDocument())->getImageFile();
\r
526 ImageFileArrayConst v = rIF.getArray();
\r
530 if (v != NULL && xCursor < nx) {
\r
531 double* pX = new double [ny];
\r
532 double* pY = new double [ny];
\r
533 for (int i = 0; i < ny; i++) {
\r
535 pY[i] = v[xCursor][i];
\r
537 PlotFileDocument* pPlotDoc = dynamic_cast<PlotFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.plt", wxDOC_SILENT));
\r
539 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
\r
541 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
\r
542 std::ostringstream os;
\r
543 os << "Column " << xCursor;
\r
544 std::string title("title ");
\r
546 rPlotFile.addEzsetCommand (title.c_str());
\r
547 rPlotFile.addEzsetCommand ("xlabel Row");
\r
548 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
\r
549 rPlotFile.addEzsetCommand ("box");
\r
550 rPlotFile.addEzsetCommand ("grid");
\r
551 rPlotFile.setCurveSize (2, nx);
\r
552 rPlotFile.addColumn (0, pX);
\r
553 rPlotFile.addColumn (1, pY);
\r
557 pPlotDoc->Modify(true);
\r
562 ImageFileView::OnCompareCol (wxCommandEvent& event)
\r
564 int xCursor, yCursor;
\r
565 if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) {
\r
566 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
\r
570 std::vector<ImageFileDocument*> vecIFDoc;
\r
571 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
\r
572 if (vecIFDoc.size() == 0) {
\r
573 wxMessageBox ("No compatible images for Column Comparison", "Error");
\r
576 DialogGetComparisonImage dialogGetCompare (m_frame, "Get Comparison Image", vecIFDoc, false);
\r
578 if (dialogGetCompare.ShowModal() == wxID_OK) {
\r
579 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
\r
580 const ImageFile& rIF = GetDocument()->getImageFile();
\r
581 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
\r
583 ImageFileArrayConst v1 = rIF.getArray();
\r
584 ImageFileArrayConst v2 = rCompareIF.getArray();
\r
588 if (v1 != NULL && xCursor < nx) {
\r
589 double* pX = new double [ny];
\r
590 double* pY1 = new double [ny];
\r
591 double* pY2 = new double [ny];
\r
592 for (int i = 0; i < ny; i++) {
\r
594 pY1[i] = v1[xCursor][i];
\r
595 pY2[i] = v2[xCursor][i];
\r
597 PlotFileDocument* pPlotDoc = dynamic_cast<PlotFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.plt", wxDOC_SILENT));
\r
599 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
\r
601 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
\r
602 std::ostringstream os;
\r
603 os << "Column " << xCursor << " Comparison";
\r
604 std::string title("title ");
\r
606 rPlotFile.addEzsetCommand (title.c_str());
\r
607 rPlotFile.addEzsetCommand ("xlabel Row");
\r
608 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
\r
609 rPlotFile.addEzsetCommand ("box");
\r
610 rPlotFile.addEzsetCommand ("grid");
\r
611 rPlotFile.setCurveSize (3, nx);
\r
612 rPlotFile.addColumn (0, pX);
\r
613 rPlotFile.addColumn (1, pY1);
\r
614 rPlotFile.addColumn (2, pY2);
\r
619 pPlotDoc->Modify(true);
\r
625 ImageFileView::OnCompareRow (wxCommandEvent& event)
\r
627 int xCursor, yCursor;
\r
628 if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) {
\r
629 wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
\r
633 std::vector<ImageFileDocument*> vecIFDoc;
\r
634 theApp->getCompatibleImages (GetDocument(), vecIFDoc);
\r
636 if (vecIFDoc.size() == 0) {
\r
637 wxMessageBox ("No compatible images for Row Comparison", "Error");
\r
641 DialogGetComparisonImage dialogGetCompare (m_frame, "Get Comparison Image", vecIFDoc, false);
\r
643 if (dialogGetCompare.ShowModal() == wxID_OK) {
\r
644 ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
\r
645 const ImageFile& rIF = GetDocument()->getImageFile();
\r
646 const ImageFile& rCompareIF = pCompareDoc->getImageFile();
\r
648 ImageFileArrayConst v1 = rIF.getArray();
\r
649 ImageFileArrayConst v2 = rCompareIF.getArray();
\r
653 if (v1 != NULL && yCursor < ny) {
\r
654 double* pX = new double [nx];
\r
655 double* pY1 = new double [nx];
\r
656 double* pY2 = new double [nx];
\r
657 for (int i = 0; i < nx; i++) {
\r
659 pY1[i] = v1[i][yCursor];
\r
660 pY2[i] = v2[i][yCursor];
\r
662 PlotFileDocument* pPlotDoc = dynamic_cast<PlotFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.plt", wxDOC_SILENT));
\r
664 sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
\r
666 PlotFile& rPlotFile = pPlotDoc->getPlotFile();
\r
667 std::ostringstream os;
\r
668 os << "Row " << yCursor << " Comparison";
\r
669 std::string title("title ");
\r
671 rPlotFile.addEzsetCommand (title.c_str());
\r
672 rPlotFile.addEzsetCommand ("xlabel Column");
\r
673 rPlotFile.addEzsetCommand ("ylabel Pixel Value");
\r
674 rPlotFile.addEzsetCommand ("box");
\r
675 rPlotFile.addEzsetCommand ("grid");
\r
676 rPlotFile.setCurveSize (3, ny);
\r
677 rPlotFile.addColumn (0, pX);
\r
678 rPlotFile.addColumn (1, pY1);
\r
679 rPlotFile.addColumn (2, pY2);
\r
684 pPlotDoc->Modify(true);
\r
692 PhantomCanvas::PhantomCanvas (PhantomView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
693 : wxScrolledWindow(frame, -1, pos, size, style)
699 PhantomCanvas::OnDraw(wxDC& dc)
702 m_pView->OnDraw(& dc);
708 IMPLEMENT_DYNAMIC_CLASS(PhantomView, wxView)
710 BEGIN_EVENT_TABLE(PhantomView, wxView)
711 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomView::OnProperties)
712 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomView::OnRasterize)
713 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomView::OnProjections)
716 PhantomView::PhantomView(void)
717 : wxView(), m_canvas(NULL), m_frame(NULL)
719 m_iDefaultNDet = 367;
720 m_iDefaultNView = 320;
721 m_iDefaultNSample = 2;
722 m_dDefaultRotation = 2;
723 m_dDefaultFocalLength = 2;
724 m_dDefaultFieldOfView = 1;
725 m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
726 m_iDefaultTrace = Trace::TRACE_NONE;
729 PhantomView::~PhantomView(void)
734 PhantomView::OnProperties (wxCommandEvent& event)
736 const int idPhantom = GetDocument()->getPhantomID();
737 const wxString& namePhantom = GetDocument()->getPhantomName();
738 std::ostringstream os;
739 os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")\n";
740 *theApp->getLog() << os.str().c_str();
742 const Phantom& rPhantom = GetDocument()->getPhantom();
749 PhantomView::OnProjections (wxCommandEvent& event)
751 DialogGetProjectionParameters dialogProjection (m_frame, m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView, m_iDefaultGeometry, m_iDefaultTrace);
752 int retVal = dialogProjection.ShowModal();
753 if (retVal == wxID_OK) {
754 m_iDefaultNDet = dialogProjection.getNDet();
755 m_iDefaultNView = dialogProjection.getNView();
756 m_iDefaultNSample = dialogProjection.getNSamples();
757 m_iDefaultTrace = dialogProjection.getTrace();
758 m_dDefaultRotation = dialogProjection.getRotAngle();
759 m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
760 m_dDefaultFieldOfView = dialogProjection.getFieldOfViewRatio();
761 wxString sGeometry = dialogProjection.getGeometry();
762 m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
764 if (m_iDefaultNDet > 0 && m_iDefaultNView > 0 && sGeometry != "") {
765 const Phantom& rPhantom = GetDocument()->getPhantom();
766 ProjectionFileDocument* pProjectionDoc = dynamic_cast<ProjectionFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.pj", wxDOC_SILENT));
\r
767 if (! pProjectionDoc) {
\r
768 sys_error (ERR_SEVERE, "Unable to create projection document");
\r
771 Projections& rProj = pProjectionDoc->getProjections();
772 Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView);
773 if (theScanner.fail()) {
774 *theApp->getLog() << "Failed making scanner: " << theScanner.failMessage().c_str() << "\n";
777 rProj.initFromScanner (theScanner);
778 m_dDefaultRotation /= PI; // convert back to PI units
780 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
781 ProjectionsDialog dialogProjections (theScanner, rProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(m_frame));
782 for (int iView = 0; iView < rProj.nView(); iView++) {
785 if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
786 pProjectionDoc->DeleteAllViews();
791 while (dialogProjections.isPaused()) {
797 wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), rProj.nView() + 1, m_frame, wxPD_CAN_ABORT);
798 for (int i = 0; i < rProj.nView(); i++) {
799 theScanner.collectProjections (rProj, rPhantom, i, 1, true, m_iDefaultTrace);
800 if (! dlgProgress.Update (i+1)) {
801 pProjectionDoc->DeleteAllViews();
807 std::ostringstream os;
808 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();
809 rProj.setRemark (os.str());
810 *theApp->getLog() << os.str().c_str() << "\n";
814 ProjectionFileView* projView = dynamic_cast<ProjectionFileView*>(pProjectionDoc->GetFirstView());
\r
816 projView->getFrame()->SetFocus();
\r
817 projView->OnUpdate (projView, NULL);
\r
819 if (wxView* pView = pProjectionDoc->GetFirstView()) {
820 if (wxFrame* pFrame = pView->GetFrame()) {
824 theApp->getDocManager()->ActivateView (pView, true, false);
827 pProjectionDoc->Modify(true);
828 pProjectionDoc->UpdateAllViews(this);
835 PhantomView::OnRasterize (wxCommandEvent& event)
837 DialogGetRasterParameters dialogRaster (m_frame, 256, 256, 1);
838 int retVal = dialogRaster.ShowModal();
839 if (retVal == wxID_OK) {
840 int xSize = dialogRaster.getXSize();
841 int ySize = dialogRaster.getYSize();
842 int nSamples = dialogRaster.getNSamples();
845 if (xSize > 0 && ySize > 0) {
846 const Phantom& rPhantom = GetDocument()->getPhantom();
847 ImageFileDocument* pRasterDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
\r
848 if (! pRasterDoc) {
\r
849 sys_error (ERR_SEVERE, "Unable to create image file");
\r
852 ImageFile& imageFile = pRasterDoc->getImageFile();
854 imageFile.setArraySize (xSize, ySize);
855 wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"), imageFile.nx() + 1, m_frame, wxPD_CAN_ABORT);
856 for (unsigned int i = 0; i < imageFile.nx(); i++) {
857 rPhantom.convertToImagefile (imageFile, nSamples, Trace::TRACE_NONE, i, 1, true);
858 if (! dlgProgress.Update(i+1)) {
859 pRasterDoc->DeleteAllViews();
863 pRasterDoc->Modify(true);
864 pRasterDoc->UpdateAllViews(this);
865 ImageFileView* rasterView = dynamic_cast<ImageFileView*>(pRasterDoc->GetFirstView());
\r
867 rasterView->getFrame()->SetFocus();
\r
868 rasterView->OnUpdate (rasterView, NULL);
\r
871 std::ostringstream os;
872 os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << xSize << ", YSize=" << ySize << ", nSamples=" << nSamples << "\n";
873 *theApp->getLog() << os.str().c_str();
880 PhantomView::CreateCanvas (wxView *view, wxFrame *parent)
882 PhantomCanvas* pCanvas;
884 parent->GetClientSize(&width, &height);
886 pCanvas = new PhantomCanvas (dynamic_cast<PhantomView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
888 pCanvas->SetBackgroundColour(*wxWHITE);
895 PhantomView::CreateChildFrame(wxDocument *doc, wxView *view)
897 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
899 wxMenu *file_menu = new wxMenu;
901 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
902 file_menu->Append(wxID_OPEN, "&Open...");
903 file_menu->Append(wxID_CLOSE, "&Close");
905 file_menu->AppendSeparator();
906 file_menu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties");
908 file_menu->AppendSeparator();
909 file_menu->Append(wxID_PRINT, "&Print...");
910 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
911 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
913 wxMenu *process_menu = new wxMenu;
914 process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...");
915 process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...");
917 wxMenu *help_menu = new wxMenu;
918 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
919 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
921 wxMenuBar *menu_bar = new wxMenuBar;
923 menu_bar->Append(file_menu, "&File");
924 menu_bar->Append(process_menu, "&Process");
925 menu_bar->Append(help_menu, "&Help");
927 subframe->SetMenuBar(menu_bar);
929 subframe->Centre(wxBOTH);
936 PhantomView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
938 m_frame = CreateChildFrame(doc, this);
942 m_frame->GetClientSize(&width, &height);
943 m_frame->SetTitle("PhantomView");
944 m_canvas = CreateCanvas(this, m_frame);
947 int x, y; // X requires a forced resize
948 m_frame->GetSize(&x, &y);
949 m_frame->SetSize(-1, -1, x, y);
960 PhantomView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
967 PhantomView::OnClose (bool deleteWindow)
969 if (!GetDocument()->Close())
973 m_canvas->m_pView = NULL;
975 wxString s(wxTheApp->GetAppName());
977 m_frame->SetTitle(s);
990 PhantomView::OnDraw (wxDC* dc)
993 m_canvas->GetClientSize (&xsize, &ysize);
994 SGPDriver driver (dc, xsize, ysize);
996 const Phantom& rPhantom = GetDocument()->getPhantom();
997 sgp.setColor (C_RED);
1003 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1004 : wxScrolledWindow(frame, -1, pos, size, style)
1010 ProjectionFileCanvas::OnDraw(wxDC& dc)
1013 m_pView->OnDraw(& dc);
1016 // ProjectionFileView
1018 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
1020 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
1021 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
1022 EVT_MENU(PJMENU_PROCESS_RECONSTRUCT, ProjectionFileView::OnReconstruct)
1025 ProjectionFileView::ProjectionFileView(void)
1026 : wxView(), m_canvas(NULL), m_frame(NULL)
1030 m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
1031 m_dDefaultFilterParam = 1.;
1033 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
1034 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
1036 m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
1037 m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
1039 m_iDefaultZeropad = 1;
1040 m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF3;
1041 m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
1042 m_iDefaultInterpParam = 1;
1043 m_iDefaultTrace = Trace::TRACE_NONE;
1046 ProjectionFileView::~ProjectionFileView(void)
1051 ProjectionFileView::OnProperties (wxCommandEvent& event)
1053 const Projections& rProj = GetDocument()->getProjections();
1054 std::ostringstream os;
1055 rProj.printScanInfo(os);
1056 *theApp->getLog() << os.str().c_str();
1057 wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
1058 dialogMsg.ShowModal();
1063 ProjectionFileView::OnReconstruct (wxCommandEvent& event)
1065 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);
1067 int retVal = dialogReconstruction.ShowModal();
1068 if (retVal == wxID_OK) {
1069 m_iDefaultNX = dialogReconstruction.getXSize();
1070 m_iDefaultNY = dialogReconstruction.getYSize();
1071 wxString optFilterName = dialogReconstruction.getFilterName();
1072 m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
1073 m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
1074 wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
1075 m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
1076 m_iDefaultZeropad = dialogReconstruction.getZeropad();
1077 wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
1078 m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
1079 wxString optInterpName = dialogReconstruction.getInterpName();
1080 m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
1081 m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
1082 wxString optBackprojectName = dialogReconstruction.getBackprojectName();
1083 m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
1084 m_iDefaultTrace = dialogReconstruction.getTrace();
1085 if (m_iDefaultNX > 0 && m_iDefaultNY > 0) {
1086 ImageFileDocument* pReconDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
\r
1087 if (! pReconDoc) {
\r
1088 sys_error (ERR_SEVERE, "Unable to create image file");
\r
1091 ImageFile& imageFile = pReconDoc->getImageFile();
1092 const Projections& rProj = GetDocument()->getProjections();
1093 imageFile.setArraySize (m_iDefaultNX, m_iDefaultNY);
1095 if (m_iDefaultFilterMethod != ProcessSignal::FILTER_METHOD_CONVOLUTION && m_iDefaultFilterGeneration == ProcessSignal::FILTER_GENERATION_DIRECT && rProj.geometry() != Scanner::GEOMETRY_PARALLEL) {
1096 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);
1100 SGPDriver* pSGPDriver = NULL;
1102 wxMemoryDC* pDCPlot = NULL;
1104 if (m_iDefaultTrace >= Trace::TRACE_PLOT) {
1105 bitmap.Create (500, 500);
1106 pDCPlot = new wxMemoryDC;
1107 pDCPlot->SelectObject (bitmap);
1108 pSGPDriver = new SGPDriver (dynamic_cast<wxDC*>pDCPlot, 500, 500);
1109 pSGP = new SGP (*pSGPDriver);
1111 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);
1114 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);
1118 if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
1119 ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstruct, rProj, imageFile, m_iDefaultTrace, m_frame);
1120 for (int iView = 0; iView < rProj.nView(); iView++) {
1123 if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView)) {
1124 delete pDlgReconstruct;
1125 delete pReconstruct;
1126 pReconDoc->DeleteAllViews();
1131 while (pDlgReconstruct->isPaused()) {
1136 delete pDlgReconstruct;
1138 wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, m_frame, wxPD_CAN_ABORT);
1139 for (int i = 0; i < rProj.nView(); i++) {
1140 pReconstruct->reconstructView (i, 1);
1141 if (! dlgProgress.Update(i + 1)) {
1142 delete pReconstruct;
1143 pReconDoc->DeleteAllViews();
1148 delete pReconstruct;
1149 pReconDoc->Modify(true);
1150 pReconDoc->UpdateAllViews(this);
1151 ImageFileView* rasterView = dynamic_cast<ImageFileView*>(pReconDoc->GetFirstView());
\r
1153 rasterView->getFrame()->SetFocus();
\r
1154 rasterView->OnUpdate (rasterView, NULL);
\r
1156 std::ostringstream os;
1157 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();
1158 *theApp->getLog() << os.str().c_str() << "\n";
1159 imageFile.labelAdd (rProj.getLabel());
1160 imageFile.labelAdd (Array2dFileLabel::L_HISTORY, os.str().c_str(), timerRecon.timerEnd());
1166 ProjectionFileCanvas*
1167 ProjectionFileView::CreateCanvas (wxView *view, wxFrame *parent)
1169 ProjectionFileCanvas* pCanvas;
1171 parent->GetClientSize(&width, &height);
1173 pCanvas = new ProjectionFileCanvas (dynamic_cast<ProjectionFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
1175 pCanvas->SetScrollbars(20, 20, 50, 50);
1176 pCanvas->SetBackgroundColour(*wxWHITE);
1183 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
1185 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
1187 wxMenu *file_menu = new wxMenu;
1189 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
1190 file_menu->Append(wxID_OPEN, "&Open...");
1191 file_menu->Append(wxID_SAVE, "&Save");
1192 file_menu->Append(wxID_SAVEAS, "Save &As...");
1193 file_menu->Append(wxID_CLOSE, "&Close");
1195 file_menu->AppendSeparator();
1196 file_menu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
1198 file_menu->AppendSeparator();
1199 file_menu->Append(wxID_PRINT, "&Print...");
1200 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
1201 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
1203 wxMenu *process_menu = new wxMenu;
1204 process_menu->Append(PJMENU_PROCESS_RECONSTRUCT, "R&econstruct...");
1206 wxMenu *help_menu = new wxMenu;
1207 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
1208 help_menu->AppendSeparator();
1209 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
1211 wxMenuBar *menu_bar = new wxMenuBar;
1213 menu_bar->Append(file_menu, "&File");
1214 menu_bar->Append(process_menu, "&Process");
1215 menu_bar->Append(help_menu, "&Help");
1217 subframe->SetMenuBar(menu_bar);
1219 subframe->Centre(wxBOTH);
1226 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
1228 m_frame = CreateChildFrame(doc, this);
1232 m_frame->GetClientSize(&width, &height);
1233 m_frame->SetTitle("ProjectionFileView");
1234 m_canvas = CreateCanvas(this, m_frame);
1237 int x, y; // X requires a forced resize
1238 m_frame->GetSize(&x, &y);
1239 m_frame->SetSize(-1, -1, x, y);
1242 m_frame->Show(true);
1249 ProjectionFileView::OnDraw (wxDC* dc)
1252 dc->DrawBitmap (m_bitmap, 0, 0, false);
1257 ProjectionFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
1259 const Projections& rProj = GetDocument()->getProjections();
1260 const int nDet = rProj.nDet();
1261 const int nView = rProj.nView();
1262 if (nDet != 0 && nView != 0) {
1263 const DetectorArray& detarray = rProj.getDetectorArray(0);
1264 const DetectorValue* detval = detarray.detValues();
1265 double min = detval[0];
1266 double max = detval[0];
1267 for (int iy = 0; iy < nView; iy++) {
1268 const DetectorArray& detarray = rProj.getDetectorArray(iy);
1269 const DetectorValue* detval = detarray.detValues();
1270 for (int ix = 0; ix < nDet; ix++) {
1271 if (min > detval[ix])
1273 else if (max < detval[ix])
1278 unsigned char* imageData = new unsigned char [nDet * nView * 3];
1279 double scale = (max - min) / 255;
1280 for (int iy2 = 0; iy2 < nView; iy2++) {
1281 const DetectorArray& detarray = rProj.getDetectorArray (iy2);
1282 const DetectorValue* detval = detarray.detValues();
1283 for (int ix = 0; ix < nDet; ix++) {
1284 int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
1285 intensity = clamp(intensity, 0, 255);
1286 int baseAddr = (iy2 * nDet + ix) * 3;
1287 imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
1290 wxImage image (nDet, nView, imageData, true);
1291 m_bitmap = image.ConvertToBitmap();
1295 xSize = clamp (xSize, 0, 800);
1296 ySize = clamp (ySize, 0, 800);
1297 m_frame->SetClientSize (xSize, ySize);
1298 m_canvas->SetScrollbars (20, 20, nDet/20, nView/20);
1302 m_canvas->Refresh();
1306 ProjectionFileView::OnClose (bool deleteWindow)
1308 if (!GetDocument()->Close())
1312 m_canvas->m_pView = NULL;
1314 wxString s(wxTheApp->GetAppName());
1316 m_frame->SetTitle(s);
1331 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1332 : wxScrolledWindow(frame, -1, pos, size, style)
1338 PlotFileCanvas::OnDraw(wxDC& dc)
1341 m_pView->OnDraw(& dc);
1347 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
1349 BEGIN_EVENT_TABLE(PlotFileView, wxView)
1350 EVT_MENU(PJMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
1351 EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
\r
1352 EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
\r
1355 PlotFileView::PlotFileView(void)
1356 : wxView(), m_canvas(NULL), m_frame(NULL)
1360 PlotFileView::~PlotFileView(void)
1365 PlotFileView::OnProperties (wxCommandEvent& event)
1367 const PlotFile& rProj = GetDocument()->getPlotFile();
1368 std::ostringstream os;
\r
1369 os << "Columns: " << rProj.getNumColumns() << ", Records: " << rProj.getNumRecords() << "\n";
1370 *theApp->getLog() << os.str().c_str();
1371 wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
1372 dialogMsg.ShowModal();
1377 PlotFileView::OnScaleAuto (wxCommandEvent& event)
\r
1379 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
\r
1380 double min, max, mean, mode, median, stddev;
\r
1381 rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
\r
1382 DialogAutoScaleParameters dialogAutoScale (m_frame, mean, mode, median, stddev, m_dAutoScaleFactor);
\r
1383 int iRetVal = dialogAutoScale.ShowModal();
\r
1384 if (iRetVal == wxID_OK) {
\r
1385 m_bMinSpecified = true;
\r
1386 m_bMaxSpecified = true;
\r
1387 double dMin, dMax;
\r
1388 if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
\r
1389 m_dMinPixel = dMin;
\r
1390 m_dMaxPixel = dMax;
\r
1391 m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
\r
1392 OnUpdate (this, NULL);
\r
1398 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
\r
1400 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
\r
1403 if (! m_bMinSpecified && ! m_bMaxSpecified) {
\r
1404 if (! rPlotFile.getMinMax (1, min, max)) {
\r
1405 *theApp->getLog() << "Error: unable to find Min/Max\n";
\r
1410 if (m_bMinSpecified)
\r
1411 min = m_dMinPixel;
\r
1412 if (m_bMaxSpecified)
\r
1413 max = m_dMaxPixel;
\r
1415 DialogGetMinMax dialogMinMax (m_frame, "Set Y-axis Minimum & Maximum", min, max);
\r
1416 int retVal = dialogMinMax.ShowModal();
\r
1417 if (retVal == wxID_OK) {
\r
1418 m_bMinSpecified = true;
\r
1419 m_bMaxSpecified = true;
\r
1420 m_dMinPixel = dialogMinMax.getMinimum();
\r
1421 m_dMaxPixel = dialogMinMax.getMaximum();
\r
1422 OnUpdate (this, NULL);
\r
1428 PlotFileView::CreateCanvas (wxView *view, wxFrame *parent)
1430 PlotFileCanvas* pCanvas;
1432 parent->GetClientSize(&width, &height);
1434 pCanvas = new PlotFileCanvas (dynamic_cast<PlotFileView*>(view), parent, wxPoint(0, 0), wxSize(width, height), 0);
1436 pCanvas->SetBackgroundColour(*wxWHITE);
1443 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
1445 wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
1447 wxMenu *file_menu = new wxMenu;
1449 file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...");
1450 file_menu->Append(wxID_OPEN, "&Open...");
1451 file_menu->Append(wxID_SAVE, "&Save");
1452 file_menu->Append(wxID_SAVEAS, "Save &As...");
1453 file_menu->Append(wxID_CLOSE, "&Close");
1455 file_menu->AppendSeparator();
1456 file_menu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
1458 file_menu->AppendSeparator();
1459 file_menu->Append(wxID_PRINT, "&Print...");
1460 file_menu->Append(wxID_PRINT_SETUP, "Print &Setup...");
1461 file_menu->Append(wxID_PREVIEW, "Print Pre&view");
1463 wxMenu *view_menu = new wxMenu;
\r
1464 view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...");
\r
1465 view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...");
\r
1467 wxMenu *help_menu = new wxMenu;
1468 help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents");
1469 help_menu->AppendSeparator();
1470 help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
1472 wxMenuBar *menu_bar = new wxMenuBar;
1474 menu_bar->Append(file_menu, "&File");
\r
1475 menu_bar->Append(view_menu, "&View");
1476 menu_bar->Append(help_menu, "&Help");
1478 subframe->SetMenuBar(menu_bar);
1480 subframe->Centre(wxBOTH);
1487 PlotFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
1489 m_frame = CreateChildFrame(doc, this);
1492 m_bMinSpecified = false;
\r
1493 m_bMaxSpecified = false;
\r
1494 m_dAutoScaleFactor = 1.;
\r
1497 m_frame->GetClientSize(&width, &height);
1498 m_frame->SetTitle ("Plot File");
1499 m_canvas = CreateCanvas (this, m_frame);
1502 int x, y; // X requires a forced resize
1503 m_frame->GetSize(&x, &y);
1504 m_frame->SetSize(-1, -1, x, y);
1507 m_frame->Show(true);
1514 PlotFileView::OnDraw (wxDC* dc)
1516 const PlotFile& rPlotFile = GetDocument()->getPlotFile();
\r
1517 const int iNColumns = rPlotFile.getNumColumns();
\r
1518 const int iNRecords = rPlotFile.getNumRecords();
\r
1520 if (iNColumns > 0 && iNRecords > 0) {
\r
1522 m_canvas->GetClientSize (&xsize, &ysize);
\r
1523 SGPDriver driver (dc, xsize, ysize);
\r
1525 const PlotFile& rPhantom = GetDocument()->getPlotFile();
\r
1526 EZPlot plot (sgp);
\r
1528 for (int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)
\r
1529 plot.ezset (rPlotFile.getEzsetCommand (iEzset));
\r
1531 if (m_bMinSpecified) {
\r
1532 std::ostringstream os;
\r
1533 os << "ymin " << m_dMinPixel;
\r
1534 plot.ezset (os.str());
\r
1537 if (m_bMaxSpecified) {
\r
1538 std::ostringstream os;
\r
1539 os << "ymax " << m_dMaxPixel;
\r
1540 plot.ezset (os.str());
\r
1543 plot.ezset("box");
\r
1544 plot.ezset("grid");
\r
1546 double* pdXaxis = new double [iNRecords];
\r
1547 rPlotFile.getColumn (0, pdXaxis);
\r
1549 double* pdY = new double [iNRecords];
\r
1550 for (int iCol = 1; iCol < iNColumns; iCol++) {
\r
1551 rPlotFile.getColumn (iCol, pdY);
\r
1552 plot.addCurve (pdXaxis, pdY, iNRecords);
\r
1564 PlotFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
1567 m_canvas->Refresh();
1571 PlotFileView::OnClose (bool deleteWindow)
1573 if (!GetDocument()->Close())
1577 m_canvas->m_pView = NULL;
1579 wxString s(wxTheApp->GetAppName());
1581 m_frame->SetTitle(s);