X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=src%2Fviews.cpp;h=d3827f0e41a281b0833a42d1bf755ca3d6dd2d8a;hp=81eb051098485141b32c14cdf0d802ae5f259476;hb=739e435359d44546dd812fff8c86b815a214d587;hpb=89997e727ff5d4d8828f6fdaee435d809b623ffe diff --git a/src/views.cpp b/src/views.cpp index 81eb051..d3827f0 100644 --- a/src/views.cpp +++ b/src/views.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: views.cpp,v 1.31 2000/12/19 21:37:51 kevin Exp $ +** $Id: views.cpp,v 1.32 2000/12/20 14:39:09 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -406,36 +406,12 @@ ImageFileView::OnClose (bool deleteWindow) #include "wx/plot.h" -class VectorPlotCurve : wxPlotCurve { -private: - int m_nPoints; - std::vector m_points; - -public: - VectorPlotCurve (const double* const points, int n, double minVal, double maxVal) - : wxPlotCurve (minVal, minVal, maxVal) - { - for (int i = 0; i < n; i++) - m_points.push_back(points[i]); - } - - wxInt32 GetStartX () - { return 0; } - - wxInt32 GetEndX () - { return m_nPoints - 1; } - - double GetY (wxInt32 x) - { return m_points[x]; } -}; - - void ImageFileView::OnPlotRow (wxCommandEvent& event) { int xCursor, yCursor; if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) { - // os << "No row selected. Please use left mouse button on image to select row\n"; + *theApp->getLog() << "No row selected. Please use left mouse button on image to select row\n"; return; } @@ -445,21 +421,26 @@ ImageFileView::OnPlotRow (wxCommandEvent& event) int ny = rIF.ny(); if (v != NULL && yCursor < ny) { - double* pVec = new double [nx]; - double minVal = v[0][yCursor]; - double maxVal = minVal; + double* pX = new double [nx]; + double* pY = new double [nx]; for (int i = 0; i < nx; i++) { - pVec[i] = v[i][yCursor]; - if (pVec[i] < minVal) - minVal = pVec[i]; - else if (pVec[i] > maxVal) - maxVal = pVec[i]; + pX[i] = i; + pY[i] = v[i][yCursor]; + } + PlotFileDocument* pPlotDoc = dynamic_cast(theApp->getDocManager()->CreateDocument("untitled.plt", wxDOC_SILENT)); + if (! pPlotDoc) { + sys_error (ERR_SEVERE, "Internal error: unable to create Plot file"); + } else { + PlotFile& rPlot = pPlotDoc->getPlotFile(); + rPlot.setTitle("Row Plot"); + rPlot.setXLabel("Column"); + rPlot.setYLabel("Pixel Value"); + rPlot.setCurveSize (2, nx); + rPlot.addColumn (0, pX); + rPlot.addColumn (1, pY); + delete pX; + delete pY; } - VectorPlotCurve* plotCurve = new VectorPlotCurve (pVec, nx, minVal, maxVal); - wxPlotWindow* plotWindow = new wxPlotWindow (m_canvas, NULL, wxPoint(0,0), wxSize(500,300)); - plotWindow->Add (reinterpret_cast(plotCurve)); - plotWindow->Enable(TRUE); - plotWindow->Show(); } } @@ -489,10 +470,6 @@ ImageFileView::OnPlotCol (wxCommandEvent& event) maxVal = v[xCursor][i]; pVec[i] = v[xCursor][i]; } - - VectorPlotCurve* plotCurve = new VectorPlotCurve (pVec, ny, minVal, maxVal); - wxPlotWindow plotWindow (m_canvas, NULL, wxPoint(0,0), wxSize(500,300)); - plotWindow.Add (reinterpret_cast(plotCurve)); } } @@ -1126,7 +1103,6 @@ ProjectionFileView::OnClose (bool deleteWindow) // PlotFileCanvas - PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style) : wxScrolledWindow(frame, -1, pos, size, style) { @@ -1160,7 +1136,7 @@ PlotFileView::~PlotFileView(void) void PlotFileView::OnProperties (wxCommandEvent& event) { - const PlotFile& rProj = GetDocument()->getPlot(); + const PlotFile& rProj = GetDocument()->getPlotFile(); std::ostringstream os; os << "Columns: " << rProj.getNumColumns() << ", Records: " << rProj.getNumRecords() << "\n"; *theApp->getLog() << os.str().c_str(); @@ -1249,23 +1225,57 @@ PlotFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) void PlotFileView::OnDraw (wxDC* dc) { - if (m_bitmap.Ok()) - dc->DrawBitmap (m_bitmap, 0, 0, false); + const PlotFile& rPlot = GetDocument()->getPlotFile(); + const int iNColumns = rPlot.getNumColumns(); + const int iNRecords = rPlot.getNumRecords(); + + if (iNColumns > 0 && iNRecords > 0) { + int xsize, ysize; + m_canvas->GetClientSize (&xsize, &ysize); + SGPDriver driver (dc, xsize, ysize); + SGP sgp (driver); + const PlotFile& rPhantom = GetDocument()->getPlotFile(); + EZPlot plot (sgp); + + if (! rPlot.getTitle().empty()) { + std::string s("title "); + s += rPlot.getTitle(); + plot.ezset (s); + } + if (! rPlot.getXLabel().empty()) { + std::string s("xlabel "); + s += rPlot.getXLabel(); + plot.ezset (s); + } + if (! rPlot.getYLabel().empty()) { + std::string s("ylabel "); + s += rPlot.getYLabel(); + plot.ezset (s); + } + + plot.ezset("box"); + plot.ezset("grid"); + + double* pdXaxis = new double [iNRecords]; + rPlot.getColumn (0, pdXaxis); + + double* pdY = new double [iNRecords]; + for (int iCol = 1; iCol < iNColumns; iCol++) { + rPlot.getColumn (iCol, pdY); + plot.addCurve (pdXaxis, pdY, iNRecords); + } + + delete pdXaxis; + delete pdY; + + plot.plot(); + } } void PlotFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) { - const PlotFile& rPlot = GetDocument()->getPlotFile(); - const int iNColumns = rPlot.getNumColumns(); - const int iNRecords = rPlot.getNumRecords(); - if (iNColumns > 0 && iNRecords > 0) { -// int xSize, ySize; -// m_frame->SetClientSize (xSize, ySize); -// m_canvas->SetScrollbars (20, 20, nDet/20, nView/20); - } - if (m_canvas) m_canvas->Refresh(); }