r307: additions for plotfile
[ctsim.git] / src / views.cpp
index 81eb051098485141b32c14cdf0d802ae5f259476..d3827f0e41a281b0833a42d1bf755ca3d6dd2d8a 100644 (file)
@@ -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)
 \r
 #include "wx/plot.h"\r
 \r
-class VectorPlotCurve : wxPlotCurve {\r
-private:\r
-       int     m_nPoints;\r
-       std::vector<double> m_points;\r
-\r
-public:\r
-       VectorPlotCurve (const double* const points, int n, double minVal, double maxVal)\r
-               : wxPlotCurve (minVal, minVal, maxVal)\r
-       {\r
-               for (int i = 0; i < n; i++)\r
-                       m_points.push_back(points[i]);\r
-       }\r
-\r
-       wxInt32 GetStartX ()\r
-       { return 0; }\r
-\r
-       wxInt32 GetEndX ()\r
-       { return m_nPoints - 1; }\r
-\r
-       double GetY (wxInt32 x)\r
-       { return m_points[x]; }\r
-};\r
-\r
-
 void\r
 ImageFileView::OnPlotRow (wxCommandEvent& event)\r
 {\r
        int xCursor, yCursor;\r
        if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) {\r
-               // os << "No row selected. Please use left mouse button on image to select row\n";\r
+               *theApp->getLog() << "No row selected. Please use left mouse button on image to select row\n";\r
                return;\r
        }\r
 \r
@@ -445,21 +421,26 @@ ImageFileView::OnPlotRow (wxCommandEvent& event)
     int ny = rIF.ny();\r
 \r
     if (v != NULL && yCursor < ny) {\r
-               double* pVec = new double [nx];\r
-               double minVal = v[0][yCursor];\r
-               double maxVal = minVal;\r
+               double* pX = new double [nx];\r
+               double* pY = new double [nx];\r
                for (int i = 0; i < nx; i++) {\r
-                       pVec[i] = v[i][yCursor];\r
-                       if (pVec[i] < minVal)\r
-                               minVal = pVec[i];\r
-                       else if (pVec[i] > maxVal)\r
-                               maxVal = pVec[i];\r
+                       pX[i] = i;\r
+                       pY[i] = v[i][yCursor];\r
+               }\r
+               PlotFileDocument* pPlotDoc = dynamic_cast<PlotFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.plt", wxDOC_SILENT));\r
+               if (! pPlotDoc) {\r
+                       sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");\r
+               } else {\r
+                       PlotFile& rPlot = pPlotDoc->getPlotFile();\r
+                       rPlot.setTitle("Row Plot");\r
+                       rPlot.setXLabel("Column");\r
+                       rPlot.setYLabel("Pixel Value");\r
+                       rPlot.setCurveSize (2, nx);\r
+                       rPlot.addColumn (0, pX);\r
+                       rPlot.addColumn (1, pY);\r
+                       delete pX;\r
+                       delete pY;\r
                }\r
-               VectorPlotCurve* plotCurve = new VectorPlotCurve (pVec, nx, minVal, maxVal);\r
-               wxPlotWindow* plotWindow = new wxPlotWindow (m_canvas, NULL, wxPoint(0,0), wxSize(500,300));\r
-               plotWindow->Add (reinterpret_cast<wxPlotCurve*>(plotCurve));\r
-               plotWindow->Enable(TRUE);\r
-               plotWindow->Show();\r
        }\r
 \r
 }\r
@@ -489,10 +470,6 @@ ImageFileView::OnPlotCol (wxCommandEvent& event)
                                maxVal = v[xCursor][i];\r
                        pVec[i] = v[xCursor][i];\r
                }\r
-\r
-               VectorPlotCurve* plotCurve = new VectorPlotCurve (pVec, ny, minVal, maxVal);\r
-               wxPlotWindow plotWindow (m_canvas, NULL, wxPoint(0,0), wxSize(500,300));\r
-               plotWindow.Add (reinterpret_cast<wxPlotCurve*>(plotCurve));\r
        }\r
 }\r
 \r
@@ -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;\r
        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();\r
+    const int iNColumns = rPlot.getNumColumns();\r
+       const int iNRecords = rPlot.getNumRecords();\r
+\r
+       if (iNColumns > 0 && iNRecords > 0) {\r
+               int xsize, ysize;\r
+               m_canvas->GetClientSize (&xsize, &ysize);\r
+               SGPDriver driver (dc, xsize, ysize);\r
+               SGP sgp (driver);\r
+               const PlotFile& rPhantom = GetDocument()->getPlotFile();\r
+               EZPlot plot (sgp);\r
+\r
+               if (! rPlot.getTitle().empty()) {\r
+                       std::string s("title ");\r
+                       s += rPlot.getTitle();\r
+                       plot.ezset (s);\r
+               }\r
+               if (! rPlot.getXLabel().empty()) {\r
+                       std::string s("xlabel ");\r
+                       s += rPlot.getXLabel();\r
+                       plot.ezset (s);\r
+               }\r
+               if (! rPlot.getYLabel().empty()) {\r
+                       std::string s("ylabel ");\r
+                       s += rPlot.getYLabel();\r
+                       plot.ezset (s);\r
+               }\r
+\r
+       plot.ezset("box");\r
+       plot.ezset("grid");\r
+\r
+               double* pdXaxis = new double [iNRecords];\r
+               rPlot.getColumn (0, pdXaxis);\r
+\r
+               double* pdY = new double [iNRecords];\r
+               for (int iCol = 1; iCol < iNColumns; iCol++) {\r
+                       rPlot.getColumn (iCol, pdY);\r
+                       plot.addCurve (pdXaxis, pdY, iNRecords);\r
+               }\r
+\r
+               delete pdXaxis;\r
+               delete pdY;\r
+\r
+               plot.plot();\r
+       }\r
 }
 
 
 void 
 PlotFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
 {
-    const PlotFile& rPlot = GetDocument()->getPlotFile();
-    const int iNColumns = rPlot.getNumColumns();\r
-       const int iNRecords = rPlot.getNumRecords();
-    if (iNColumns > 0 && iNRecords > 0) {
-//      int xSize, ySize;\r
-//      m_frame->SetClientSize (xSize, ySize);
-//    m_canvas->SetScrollbars (20, 20, nDet/20, nView/20);
-    }
-    
     if (m_canvas)
       m_canvas->Refresh();
 }