+ unsigned char* imageData = new unsigned char [nDet * nView * 3];
+ double scale = (max - min) / 255;
+ for (int iy2 = 0; iy2 < nView; iy2++) {
+ const DetectorArray& detarray = rProj.getDetectorArray (iy2);
+ const DetectorValue* detval = detarray.detValues();
+ for (int ix = 0; ix < nDet; ix++) {
+ int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
+ intensity = clamp(intensity, 0, 255);
+ int baseAddr = (iy2 * nDet + ix) * 3;
+ imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
+ }
+ }
+ wxImage image (nDet, nView, imageData, true);
+ m_bitmap = image.ConvertToBitmap();
+ delete imageData;
+ int xSize = nDet;
+ int ySize = nView;
+ xSize = clamp (xSize, 0, 800);
+ ySize = clamp (ySize, 0, 800);
+ m_pFrame->SetClientSize (xSize, ySize);
+ m_pCanvas->SetScrollbars (20, 20, nDet/20, nView/20);
+ }
+
+ if (m_pCanvas)
+ m_pCanvas->Refresh();
+}
+
+bool
+ProjectionFileView::OnClose (bool deleteWindow)
+{
+ //GetDocumentManager()->ActivateView (this, false, true);
+ if (! GetDocument() || ! GetDocument()->Close())
+ return false;
+
+ if (m_pCanvas) {
+ m_pCanvas->setView(NULL);
+ m_pCanvas = NULL;
+ }
+ wxString s(wxTheApp->GetAppName());
+ if (m_pFrame)
+ m_pFrame->SetTitle(s);
+
+ SetFrame(NULL);
+ Activate(false);
+
+ if (deleteWindow) {
+ m_pFrame->Destroy();
+ m_pFrame = NULL;
+ if (GetDocument() && GetDocument()->getBadFileOpen())
+ ::wxYield(); // wxWindows bug workaround
+ }
+
+ return true;
+}
+
+
+
+// PlotFileCanvas
+PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
+: wxScrolledWindow(frame, -1, pos, size, style)
+{
+ m_pView = v;
+}
+
+PlotFileCanvas::~PlotFileCanvas ()
+{
+ m_pView = NULL;
+}
+
+void
+PlotFileCanvas::OnDraw(wxDC& dc)
+{
+ if (m_pView)
+ m_pView->OnDraw(& dc);
+}
+
+
+// PlotFileView
+
+IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
+
+BEGIN_EVENT_TABLE(PlotFileView, wxView)
+EVT_MENU(PJMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
+EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
+EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
+EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
+END_EVENT_TABLE()
+
+PlotFileView::PlotFileView()
+: wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pEZPlot(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
+{
+}
+
+PlotFileView::~PlotFileView()
+{
+ if (m_pEZPlot)
+ delete m_pEZPlot;
+
+ GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
+}
+
+void
+PlotFileView::OnProperties (wxCommandEvent& event)
+{
+ const PlotFile& rPlot = GetDocument()->getPlotFile();
+ std::ostringstream os;
+ os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
+ rPlot.printHeadersBrief (os);
+ *theApp->getLog() << os.str().c_str();
+ wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
+ dialogMsg.ShowModal();
+}
+
+
+void
+PlotFileView::OnScaleAuto (wxCommandEvent& event)
+{
+ const PlotFile& rPlotFile = GetDocument()->getPlotFile();
+ double min, max, mean, mode, median, stddev;
+ rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
+ DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
+ int iRetVal = dialogAutoScale.ShowModal();
+ if (iRetVal == wxID_OK) {
+ m_bMinSpecified = true;
+ m_bMaxSpecified = true;
+ double dMin, dMax;
+ if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
+ m_dMinPixel = dMin;
+ m_dMaxPixel = dMax;
+ m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
+ OnUpdate (this, NULL);
+ }
+ }
+}
+
+void
+PlotFileView::OnScaleMinMax (wxCommandEvent& event)
+{
+ const PlotFile& rPlotFile = GetDocument()->getPlotFile();
+ double min;
+ double max;
+
+ if (! m_bMinSpecified || ! m_bMaxSpecified) {
+ if (! rPlotFile.getMinMax (1, min, max)) {
+ *theApp->getLog() << "Error: unable to find Min/Max\n";
+ return;
+ }
+ }
+
+ if (m_bMinSpecified)
+ min = m_dMinPixel;
+ if (m_bMaxSpecified)
+ max = m_dMaxPixel;
+
+ DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Y-axis Minimum & Maximum", min, max);
+ int retVal = dialogMinMax.ShowModal();
+ if (retVal == wxID_OK) {
+ m_bMinSpecified = true;
+ m_bMaxSpecified = true;
+ m_dMinPixel = dialogMinMax.getMinimum();
+ m_dMaxPixel = dialogMinMax.getMaximum();
+ OnUpdate (this, NULL);
+ }
+}
+
+void
+PlotFileView::OnScaleFull (wxCommandEvent& event)
+{
+ if (m_bMinSpecified || m_bMaxSpecified) {
+ m_bMinSpecified = false;
+ m_bMaxSpecified = false;
+ OnUpdate (this, NULL);
+ }
+}
+
+
+PlotFileCanvas*
+PlotFileView::CreateCanvas (wxFrame* parent)
+{
+ PlotFileCanvas* pCanvas;
+ int width, height;
+ parent->GetClientSize(&width, &height);
+
+ pCanvas = new PlotFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
+
+ pCanvas->SetBackgroundColour(*wxWHITE);
+ pCanvas->Clear();
+
+ return pCanvas;
+}
+
+#if CTSIM_MDI
+wxDocMDIChildFrame*
+#else
+wxDocChildFrame*
+#endif
+PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
+{
+#ifdef CTSIM_MDI
+ wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
+#else
+ wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
+#endif
+ theApp->setIconForFrame (subframe);
+
+ wxMenu *m_pFileMenu = new wxMenu;
+
+ m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
+ m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
+ m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
+ m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
+ m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
+ m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
+
+ m_pFileMenu->AppendSeparator();
+ m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
+
+ m_pFileMenu->AppendSeparator();
+ m_pFileMenu->Append(wxID_PRINT, "&Print...");
+ m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
+ m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
+#ifdef CTSIM_MDI
+ m_pFileMenu->AppendSeparator();
+ m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
+#endif
+ GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
+ GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
+
+ wxMenu *view_menu = new wxMenu;
+ view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...\tCtrl-E");
+ view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
+ view_menu->Append(PLOTMENU_VIEW_SCALE_FULL, "Display &Full Scale\tCtrl-U");
+
+ wxMenu *help_menu = new wxMenu;
+ help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
+ help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
+ help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
+
+ wxMenuBar *menu_bar = new wxMenuBar;
+
+ menu_bar->Append(m_pFileMenu, "&File");
+ menu_bar->Append(view_menu, "&View");
+ menu_bar->Append(help_menu, "&Help");
+
+ subframe->SetMenuBar(menu_bar);
+ subframe->Centre(wxBOTH);
+
+ wxAcceleratorEntry accelEntries[10];
+ accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
+ accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
+ accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
+ accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
+ accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
+ accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
+ accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
+ accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('E'), PLOTMENU_VIEW_SCALE_MINMAX);
+ accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('A'), PLOTMENU_VIEW_SCALE_AUTO);
+ accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('U'), PLOTMENU_VIEW_SCALE_FULL);
+ wxAcceleratorTable accelTable (10, accelEntries);
+ subframe->SetAcceleratorTable (accelTable);
+
+ return subframe;
+}
+
+
+bool
+PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
+{
+ m_pFrame = CreateChildFrame(doc, this);
+ SetFrame(m_pFrame);
+
+ m_bMinSpecified = false;
+ m_bMaxSpecified = false;
+ m_dAutoScaleFactor = 1.;
+
+ int width, height;
+ m_pFrame->GetClientSize(&width, &height);
+ m_pFrame->SetTitle ("Plot File");
+ m_pCanvas = CreateCanvas (m_pFrame);
+
+#ifdef __X__
+ int x, y; // X requires a forced resize
+ m_pFrame->GetSize(&x, &y);
+ m_pFrame->SetSize(-1, -1, x, y);
+#endif
+
+ m_pFrame->Show(true);
+ Activate(true);
+
+ return true;
+}
+
+void
+PlotFileView::OnDraw (wxDC* dc)
+{
+ const PlotFile& rPlotFile = GetDocument()->getPlotFile();
+ const int iNColumns = rPlotFile.getNumColumns();
+ const int iNRecords = rPlotFile.getNumRecords();
+
+ if (iNColumns > 0 && iNRecords > 0) {
+ int xsize, ysize;
+ m_pCanvas->GetClientSize (&xsize, &ysize);
+ SGPDriver driver (dc, xsize, ysize);
+ SGP sgp (driver);
+ if (m_pEZPlot)
+ m_pEZPlot->plot (&sgp);
+ }
+}