X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=src%2Fviews.cpp;h=307d6c0c054cf24823a1f9884be4807f7dfa6430;hp=8b1abce2803d6167fa5d90ad2addf1d6166342e2;hb=67a6c34b5a6f38d34e8cbe66091853f453fd2d7a;hpb=2a3686d3bd1f690d318b81766c261da785cf9b57 diff --git a/src/views.cpp b/src/views.cpp index 8b1abce..307d6c0 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.37 2000/12/23 18:12:35 kevin Exp $ +** $Id: views.cpp,v 1.41 2000/12/29 19:30:08 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 @@ -91,9 +91,10 @@ ImageFileCanvas::DrawRubberBandCursor (wxDC& dc, int x, int y) int nx = rIF.nx(); int ny = rIF.ny(); + int yPt = ny - y - 1; dc.SetLogicalFunction (wxINVERT); dc.SetPen (*wxGREEN_PEN); - dc.DrawLine (0, y, nx, y); + dc.DrawLine (0, yPt, nx, yPt); dc.DrawLine (x, 0, x, ny); dc.SetLogicalFunction (wxCOPY); } @@ -121,38 +122,33 @@ ImageFileCanvas::OnMouseEvent(wxMouseEvent& event) wxPoint pt(event.GetLogicalPosition(dc)); + const ImageFile& rIF = m_pView->GetDocument()->getImageFile(); + ImageFileArrayConst v = rIF.getArray(); + int nx = rIF.nx(); + int ny = rIF.ny(); + const int yPt = ny - 1 - pt.y; if (event.RightIsDown()) { - const ImageFile& rIF = m_pView->GetDocument()->getImageFile(); - ImageFileArrayConst v = rIF.getArray(); - int nx = rIF.nx(); - int ny = rIF.ny(); - if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) { std::ostringstream os; - os << "Image value (" << pt.x << "," << pt.y << ") = " << v[pt.x][ny - 1 - pt.y] << "\n"; + os << "Image value (" << pt.x << "," << yPt << ") = " << v[pt.x][yPt] << "\n"; *theApp->getLog() << os.str().c_str(); } else - *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << pt.y << ")\n"; + *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n"; } - else if (event.LeftIsDown() || event.LeftUp()) { - const ImageFile& rIF = m_pView->GetDocument()->getImageFile(); - ImageFileArrayConst v = rIF.getArray(); - int nx = rIF.nx(); - int ny = rIF.ny(); - + else if (event.LeftIsDown() || event.LeftUp() || event.RightUp()) { if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) { if (m_xCursor >= 0 && m_yCursor >= 0) { DrawRubberBandCursor (dc, m_xCursor, m_yCursor); } - DrawRubberBandCursor (dc, pt.x, pt.y); + DrawRubberBandCursor (dc, pt.x, yPt); m_xCursor = pt.x; - m_yCursor = pt.y; + m_yCursor = yPt; } else - *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << pt.y << ")\n"; + *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n"; } if (event.LeftUp()) { std::ostringstream os; - os << "Selected column" << pt.x << " and row" << pt.y << "\n"; + os << "Selected column " << pt.x << " , row " << yPt << "\n"; *theApp->getLog() << os.str().c_str(); } } @@ -168,6 +164,15 @@ EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto) EVT_MENU(IFMENU_COMPARE_IMAGES, ImageFileView::OnCompare) EVT_MENU(IFMENU_COMPARE_ROW, ImageFileView::OnCompareRow) EVT_MENU(IFMENU_COMPARE_COL, ImageFileView::OnCompareCol) +EVT_MENU(IFMENU_PROCESS_INVERTVALUES, ImageFileView::OnInvertValues) +EVT_MENU(IFMENU_PROCESS_SQUARE, ImageFileView::OnSquare) +EVT_MENU(IFMENU_PROCESS_SQRT, ImageFileView::OnSquareRoot) +EVT_MENU(IFMENU_PROCESS_LOG, ImageFileView::OnLog) +EVT_MENU(IFMENU_PROCESS_EXP, ImageFileView::OnExp) +EVT_MENU(IFMENU_PROCESS_FOURIER, ImageFileView::OnFourier) +EVT_MENU(IFMENU_PROCESS_INVERSE_FOURIER, ImageFileView::OnInverseFourier) +EVT_MENU(IFMENU_PROCESS_MAGNITUDE, ImageFileView::OnMagnitude) +EVT_MENU(IFMENU_PROCESS_PHASE, ImageFileView::OnPhase) EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow) EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol) END_EVENT_TABLE() @@ -184,15 +189,26 @@ ImageFileView::~ImageFileView(void) void ImageFileView::OnProperties (wxCommandEvent& event) { - double min, max, mean, mode, median, stddev; const ImageFile& rIF = GetDocument()->getImageFile(); if (rIF.nx() == 0 || rIF.ny() == 0) *theApp->getLog() << "Properties: empty imagefile\n"; else { const std::string& rFilename = rIF.getFilename(); - rIF.statistics (min, max, mean, mode, median, stddev); std::ostringstream os; - os << "file: " << rFilename << "\nmin: "<getLog() << os.str().c_str(); wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION); dialogMsg.ShowModal(); @@ -249,15 +265,15 @@ ImageFileView::OnCompare (wxCommandEvent& event) { std::vector vecIF; theApp->getCompatibleImages (GetDocument(), vecIF); - + if (vecIF.size() == 0) { wxMessageBox("There are no compatible image files open for comparision", "No comparison images"); } else { DialogGetComparisonImage dialogGetCompare(m_frame, "Get Comparison Image", vecIF, true); - + if (dialogGetCompare.ShowModal() == wxID_OK) { - ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument(); const ImageFile& rIF = GetDocument()->getImageFile(); + ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument(); const ImageFile& rCompareIF = pCompareDoc->getImageFile(); std::ostringstream os; double min, max, mean, mode, median, stddev; @@ -277,14 +293,15 @@ ImageFileView::OnCompare (wxCommandEvent& event) return; } ImageFile& differenceImage = pDifferenceDoc->getImageFile(); - + differenceImage.setArraySize (rIF.nx(), rIF.ny()); if (! rIF.subtractImages (rCompareIF, differenceImage)) { pDifferenceDoc->DeleteAllViews(); return; } - - pDifferenceDoc->Modify(true); + + if (theApp->getSetModifyNewDocs()) + pDifferenceDoc->Modify(true); pDifferenceDoc->UpdateAllViews(this); pDifferenceDoc->GetFirstView()->OnUpdate (this, NULL); } @@ -293,6 +310,105 @@ ImageFileView::OnCompare (wxCommandEvent& event) } } +void +ImageFileView::OnInvertValues (wxCommandEvent& event) +{ + ImageFile& rIF = GetDocument()->getImageFile(); + rIF.invertPixelValues (rIF); + if (theApp->getSetModifyNewDocs()) + GetDocument()->Modify(TRUE); + GetDocument()->UpdateAllViews(this); +} + +void +ImageFileView::OnSquare (wxCommandEvent& event) +{ + ImageFile& rIF = GetDocument()->getImageFile(); + rIF.square (rIF); + if (theApp->getSetModifyNewDocs()) + GetDocument()->Modify(TRUE); + GetDocument()->UpdateAllViews(this); +} + +void +ImageFileView::OnSquareRoot (wxCommandEvent& event) +{ + ImageFile& rIF = GetDocument()->getImageFile(); + rIF.sqrt (rIF); + if (theApp->getSetModifyNewDocs()) + GetDocument()->Modify(TRUE); + GetDocument()->UpdateAllViews(this); +} + +void +ImageFileView::OnLog (wxCommandEvent& event) +{ + ImageFile& rIF = GetDocument()->getImageFile(); + rIF.log (rIF); + if (theApp->getSetModifyNewDocs()) + GetDocument()->Modify(TRUE); + GetDocument()->UpdateAllViews(this); +} + +void +ImageFileView::OnExp (wxCommandEvent& event) +{ + ImageFile& rIF = GetDocument()->getImageFile(); + rIF.exp (rIF); + if (theApp->getSetModifyNewDocs()) + GetDocument()->Modify(TRUE); + GetDocument()->UpdateAllViews(this); +} + +void +ImageFileView::OnFourier (wxCommandEvent& event) +{ + ImageFile& rIF = GetDocument()->getImageFile(); + rIF.fourier (rIF); + m_bMinSpecified = false; + m_bMaxSpecified = false; + if (theApp->getSetModifyNewDocs()) + GetDocument()->Modify(TRUE); + GetDocument()->UpdateAllViews(this); +} + +void +ImageFileView::OnInverseFourier (wxCommandEvent& event) +{ + ImageFile& rIF = GetDocument()->getImageFile(); + rIF.inverseFourier (rIF); + m_bMinSpecified = false; + m_bMaxSpecified = false; + if (theApp->getSetModifyNewDocs()) + GetDocument()->Modify(TRUE); + GetDocument()->UpdateAllViews(this); +} + +void +ImageFileView::OnMagnitude (wxCommandEvent& event) +{ + ImageFile& rIF = GetDocument()->getImageFile(); + rIF.magnitude (rIF); + m_bMinSpecified = false; + m_bMaxSpecified = false; + if (theApp->getSetModifyNewDocs()) + GetDocument()->Modify(TRUE); + GetDocument()->UpdateAllViews(this); +} + +void +ImageFileView::OnPhase (wxCommandEvent& event) +{ + ImageFile& rIF = GetDocument()->getImageFile(); + rIF.phase (rIF); + m_bMinSpecified = false; + m_bMaxSpecified = false; + if (theApp->getSetModifyNewDocs()) + GetDocument()->Modify(TRUE); + GetDocument()->UpdateAllViews(this); +} + + ImageFileCanvas* ImageFileView::CreateCanvas (wxView *view, wxFrame *parent) { @@ -334,6 +450,18 @@ ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view) view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale &Set..."); view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto..."); + wxMenu* process_menu = new wxMenu; + process_menu->Append (IFMENU_PROCESS_INVERTVALUES, "&Invert Values"); + process_menu->Append (IFMENU_PROCESS_SQUARE, "&Square"); + process_menu->Append (IFMENU_PROCESS_SQRT, "Square &Root"); + process_menu->Append (IFMENU_PROCESS_LOG, "&Log"); + process_menu->Append (IFMENU_PROCESS_EXP, "&Exp"); + process_menu->AppendSeparator(); + process_menu->Append (IFMENU_PROCESS_FOURIER, "&Fourier"); + process_menu->Append (IFMENU_PROCESS_INVERSE_FOURIER, "&Inverse Fourier"); + process_menu->Append (IFMENU_PROCESS_MAGNITUDE, "&Magnitude"); + process_menu->Append (IFMENU_PROCESS_PHASE, "&Phase"); + wxMenu *plot_menu = new wxMenu; plot_menu->Append (IFMENU_PLOT_ROW, "Plot &Row"); plot_menu->Append (IFMENU_PLOT_COL, "Plot &Column"); @@ -342,7 +470,7 @@ ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view) compare_menu->Append (IFMENU_COMPARE_IMAGES, "Compare &Images..."); compare_menu->Append (IFMENU_COMPARE_ROW, "Compare &Row"); compare_menu->Append (IFMENU_COMPARE_COL, "Compare &Column"); - + wxMenu *help_menu = new wxMenu; help_menu->Append(MAINMENU_HELP_ABOUT, "&About"); @@ -350,7 +478,8 @@ ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view) menu_bar->Append(file_menu, "&File"); menu_bar->Append(view_menu, "&View"); - menu_bar->Append(plot_menu, "&Plot"); + menu_bar->Append(process_menu, "&Process"); + menu_bar->Append(plot_menu, "P&lot"); menu_bar->Append(compare_menu, "&Compare"); menu_bar->Append(help_menu, "&Help"); @@ -500,6 +629,7 @@ ImageFileView::OnPlotRow (wxCommandEvent& event) rPlotFile.addEzsetCommand (title.c_str()); rPlotFile.addEzsetCommand ("xlabel Column"); rPlotFile.addEzsetCommand ("ylabel Pixel Value"); + rPlotFile.addEzsetCommand ("lxfrac 0"); rPlotFile.addEzsetCommand ("box"); rPlotFile.addEzsetCommand ("grid"); rPlotFile.setCurveSize (2, nx); @@ -508,9 +638,10 @@ ImageFileView::OnPlotRow (wxCommandEvent& event) } delete pX; delete pY; - pPlotDoc->Modify(true); + if (theApp->getSetModifyNewDocs()) + pPlotDoc->Modify(true); + pPlotDoc->UpdateAllViews(); } - } void @@ -546,6 +677,7 @@ ImageFileView::OnPlotCol (wxCommandEvent& event) rPlotFile.addEzsetCommand (title.c_str()); rPlotFile.addEzsetCommand ("xlabel Row"); rPlotFile.addEzsetCommand ("ylabel Pixel Value"); + rPlotFile.addEzsetCommand ("lxfrac 0"); rPlotFile.addEzsetCommand ("box"); rPlotFile.addEzsetCommand ("grid"); rPlotFile.setCurveSize (2, nx); @@ -554,7 +686,9 @@ ImageFileView::OnPlotCol (wxCommandEvent& event) } delete pX; delete pY; - pPlotDoc->Modify(true); + if (theApp->getSetModifyNewDocs()) + pPlotDoc->Modify(true); + pPlotDoc->UpdateAllViews(); } } @@ -606,6 +740,12 @@ ImageFileView::OnCompareCol (wxCommandEvent& event) rPlotFile.addEzsetCommand (title.c_str()); rPlotFile.addEzsetCommand ("xlabel Row"); rPlotFile.addEzsetCommand ("ylabel Pixel Value"); + rPlotFile.addEzsetCommand ("lxfrac 0"); + rPlotFile.addEzsetCommand ("curve 1"); + rPlotFile.addEzsetCommand ("color 2"); + rPlotFile.addEzsetCommand ("curve 2"); + rPlotFile.addEzsetCommand ("color 4"); + rPlotFile.addEzsetCommand ("dash 5"); rPlotFile.addEzsetCommand ("box"); rPlotFile.addEzsetCommand ("grid"); rPlotFile.setCurveSize (3, nx); @@ -616,7 +756,9 @@ ImageFileView::OnCompareCol (wxCommandEvent& event) delete pX; delete pY1; delete pY2; - pPlotDoc->Modify(true); + if (theApp->getSetModifyNewDocs()) + pPlotDoc->Modify(true); + pPlotDoc->UpdateAllViews(); } } } @@ -637,7 +779,7 @@ ImageFileView::OnCompareRow (wxCommandEvent& event) wxMessageBox ("No compatible images for Row Comparison", "Error"); return; } - + DialogGetComparisonImage dialogGetCompare (m_frame, "Get Comparison Image", vecIFDoc, false); if (dialogGetCompare.ShowModal() == wxID_OK) { @@ -671,6 +813,12 @@ ImageFileView::OnCompareRow (wxCommandEvent& event) rPlotFile.addEzsetCommand (title.c_str()); rPlotFile.addEzsetCommand ("xlabel Column"); rPlotFile.addEzsetCommand ("ylabel Pixel Value"); + rPlotFile.addEzsetCommand ("lxfrac 0"); + rPlotFile.addEzsetCommand ("curve 1"); + rPlotFile.addEzsetCommand ("color 2"); + rPlotFile.addEzsetCommand ("curve 2"); + rPlotFile.addEzsetCommand ("color 4"); + rPlotFile.addEzsetCommand ("dash 5"); rPlotFile.addEzsetCommand ("box"); rPlotFile.addEzsetCommand ("grid"); rPlotFile.setCurveSize (3, ny); @@ -681,7 +829,9 @@ ImageFileView::OnCompareRow (wxCommandEvent& event) delete pX; delete pY1; delete pY2; - pPlotDoc->Modify(true); + if (theApp->getSetModifyNewDocs()) + pPlotDoc->Modify(true); + pPlotDoc->UpdateAllViews(); } } } @@ -824,7 +974,8 @@ PhantomView::OnProjections (wxCommandEvent& event) theApp->getDocManager()->ActivateView (pView, true, false); } ::wxYield(); - pProjectionDoc->Modify(true); + if (theApp->getSetModifyNewDocs()) + pProjectionDoc->Modify(true); pProjectionDoc->UpdateAllViews(this); } } @@ -860,7 +1011,8 @@ PhantomView::OnRasterize (wxCommandEvent& event) return; } } - pRasterDoc->Modify(true); + if (theApp->getSetModifyNewDocs()) + pRasterDoc->Modify(true); pRasterDoc->UpdateAllViews(this); ImageFileView* rasterView = dynamic_cast(pRasterDoc->GetFirstView()); if (rasterView) { @@ -1146,7 +1298,8 @@ ProjectionFileView::OnReconstruct (wxCommandEvent& event) } } delete pReconstruct; - pReconDoc->Modify(true); + if (theApp->getSetModifyNewDocs()) + pReconDoc->Modify(true); pReconDoc->UpdateAllViews(this); ImageFileView* rasterView = dynamic_cast(pReconDoc->GetFirstView()); if (rasterView) { @@ -1353,12 +1506,14 @@ EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto) END_EVENT_TABLE() PlotFileView::PlotFileView(void) -: wxView(), m_canvas(NULL), m_frame(NULL) +: wxView(), m_canvas(NULL), m_frame(NULL), m_pEZPlot(NULL) { } PlotFileView::~PlotFileView(void) -{ +{ + if (m_pEZPlot) + delete m_pEZPlot; } void @@ -1484,7 +1639,7 @@ PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view) bool -PlotFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) +PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) ) { m_frame = CreateChildFrame(doc, this); SetFrame(m_frame); @@ -1506,7 +1661,7 @@ PlotFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) m_frame->Show(true); Activate(true); - + return true; } @@ -1522,49 +1677,58 @@ PlotFileView::OnDraw (wxDC* dc) m_canvas->GetClientSize (&xsize, &ysize); SGPDriver driver (dc, xsize, ysize); SGP sgp (driver); - const PlotFile& rPhantom = GetDocument()->getPlotFile(); - EZPlot plot (sgp); - - for (int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++) - plot.ezset (rPlotFile.getEzsetCommand (iEzset)); - - if (m_bMinSpecified) { - std::ostringstream os; - os << "ymin " << m_dMinPixel; - plot.ezset (os.str()); - } - - if (m_bMaxSpecified) { - std::ostringstream os; - os << "ymax " << m_dMaxPixel; - plot.ezset (os.str()); - } - - plot.ezset("box"); - plot.ezset("grid"); - - double* pdXaxis = new double [iNRecords]; - rPlotFile.getColumn (0, pdXaxis); - - double* pdY = new double [iNRecords]; - for (int iCol = 1; iCol < iNColumns; iCol++) { - rPlotFile.getColumn (iCol, pdY); - plot.addCurve (pdXaxis, pdY, iNRecords); - } - - delete pdXaxis; - delete pdY; - - plot.plot(); + if (m_pEZPlot) + m_pEZPlot->plot (&sgp); } } void -PlotFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) +PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) { - if (m_canvas) - m_canvas->Refresh(); + if (m_canvas) { + const PlotFile& rPlotFile = GetDocument()->getPlotFile(); + const int iNColumns = rPlotFile.getNumColumns(); + const int iNRecords = rPlotFile.getNumRecords(); + + if (iNColumns > 0 && iNRecords > 0) { + if (m_pEZPlot) + delete m_pEZPlot; + m_pEZPlot = new EZPlot; + + for (int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++) + m_pEZPlot->ezset (rPlotFile.getEzsetCommand (iEzset)); + + if (m_bMinSpecified) { + std::ostringstream os; + os << "ymin " << m_dMinPixel; + m_pEZPlot->ezset (os.str()); + } + + if (m_bMaxSpecified) { + std::ostringstream os; + os << "ymax " << m_dMaxPixel; + m_pEZPlot->ezset (os.str()); + } + + m_pEZPlot->ezset("box"); + m_pEZPlot->ezset("grid"); + + double* pdXaxis = new double [iNRecords]; + rPlotFile.getColumn (0, pdXaxis); + + double* pdY = new double [iNRecords]; + for (int iCol = 1; iCol < iNColumns; iCol++) { + rPlotFile.getColumn (iCol, pdY); + m_pEZPlot->addCurve (pdXaxis, pdY, iNRecords); + } + + delete pdXaxis; + delete pdY; + } + + m_canvas->Refresh(); + } } bool