X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=src%2Fviews.cpp;h=8c53e4ced61bf734570a557db7ee14d1fd75f7ff;hp=740c81c03615fca0236f43947be4c453041d817c;hb=5c6b29ab4885308cc3381af6e0a68f4804956d2e;hpb=c551b53b39a7571cf52831f5e117be1cca95c420 diff --git a/src/views.cpp b/src/views.cpp index 740c81c..8c53e4c 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.36 2000/12/22 04:18:00 kevin Exp $ +** $Id: views.cpp,v 1.40 2000/12/29 15:45:06 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,13 @@ 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_FFT_MAGNITUDE, ImageFileView::OnFFTMagnitude) +EVT_MENU(IFMENU_PROCESS_FFT_PHASE, ImageFileView::OnFFTPhase) EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow) EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol) END_EVENT_TABLE() @@ -249,15 +252,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 +280,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 +297,77 @@ 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::OnFFTMagnitude (wxCommandEvent& event) +{ + ImageFile& rIF = GetDocument()->getImageFile(); + rIF.FFTMagnitude (rIF); + if (theApp->getSetModifyNewDocs()) + GetDocument()->Modify(TRUE); + GetDocument()->UpdateAllViews(this); +} + +void +ImageFileView::OnFFTPhase (wxCommandEvent& event) +{ + ImageFile& rIF = GetDocument()->getImageFile(); + rIF.FFTPhase (rIF); + if (theApp->getSetModifyNewDocs()) + GetDocument()->Modify(TRUE); + GetDocument()->UpdateAllViews(this); +} + + ImageFileCanvas* ImageFileView::CreateCanvas (wxView *view, wxFrame *parent) { @@ -334,6 +409,15 @@ 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->Append (IFMENU_PROCESS_FFT_MAGNITUDE, "&FFT Magnitude"); + process_menu->Append (IFMENU_PROCESS_FFT_PHASE, "FFT &Phase"); + wxMenu *plot_menu = new wxMenu; plot_menu->Append (IFMENU_PLOT_ROW, "Plot &Row"); plot_menu->Append (IFMENU_PLOT_COL, "Plot &Column"); @@ -342,7 +426,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 +434,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"); @@ -493,20 +578,26 @@ ImageFileView::OnPlotRow (wxCommandEvent& event) sys_error (ERR_SEVERE, "Internal error: unable to create Plot file"); } else { PlotFile& rPlotFile = pPlotDoc->getPlotFile(); - std::ostringstream title; - title << "Row " << yCursor; - rPlotFile.setTitle(title.str()); - rPlotFile.setXLabel("Column"); - rPlotFile.setYLabel("Pixel Value"); + std::ostringstream os; + os << "Row " << yCursor; + std::string title("title "); + title += os.str(); + 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); rPlotFile.addColumn (0, pX); rPlotFile.addColumn (1, pY); } delete pX; delete pY; - pPlotDoc->Modify(true); + if (theApp->getSetModifyNewDocs()) + pPlotDoc->Modify(true); + pPlotDoc->UpdateAllViews(); } - } void @@ -535,18 +626,25 @@ ImageFileView::OnPlotCol (wxCommandEvent& event) sys_error (ERR_SEVERE, "Internal error: unable to create Plot file"); } else { PlotFile& rPlotFile = pPlotDoc->getPlotFile(); - std::ostringstream title; - title << "Column " << xCursor; - rPlotFile.setTitle(title.str()); - rPlotFile.setXLabel("Row"); - rPlotFile.setYLabel("Pixel Value"); + std::ostringstream os; + os << "Column " << xCursor; + std::string title("title "); + title += os.str(); + 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); rPlotFile.addColumn (0, pX); rPlotFile.addColumn (1, pY); } delete pX; delete pY; - pPlotDoc->Modify(true); + if (theApp->getSetModifyNewDocs()) + pPlotDoc->Modify(true); + pPlotDoc->UpdateAllViews(); } } @@ -561,7 +659,10 @@ ImageFileView::OnCompareCol (wxCommandEvent& event) std::vector vecIFDoc; theApp->getCompatibleImages (GetDocument(), vecIFDoc); - + if (vecIFDoc.size() == 0) { + wxMessageBox ("No compatible images for Column Comparison", "Error"); + return; + } DialogGetComparisonImage dialogGetCompare (m_frame, "Get Comparison Image", vecIFDoc, false); if (dialogGetCompare.ShowModal() == wxID_OK) { @@ -588,11 +689,21 @@ ImageFileView::OnCompareCol (wxCommandEvent& event) sys_error (ERR_SEVERE, "Internal error: unable to create Plot file"); } else { PlotFile& rPlotFile = pPlotDoc->getPlotFile(); - std::ostringstream title; - title << "Comparison of Column " << xCursor; - rPlotFile.setTitle(title.str()); - rPlotFile.setXLabel("Row"); - rPlotFile.setYLabel("Pixel Value"); + std::ostringstream os; + os << "Column " << xCursor << " Comparison"; + std::string title("title "); + title += os.str(); + 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); rPlotFile.addColumn (0, pX); rPlotFile.addColumn (1, pY1); @@ -601,7 +712,9 @@ ImageFileView::OnCompareCol (wxCommandEvent& event) delete pX; delete pY1; delete pY2; - pPlotDoc->Modify(true); + if (theApp->getSetModifyNewDocs()) + pPlotDoc->Modify(true); + pPlotDoc->UpdateAllViews(); } } } @@ -618,6 +731,11 @@ ImageFileView::OnCompareRow (wxCommandEvent& event) std::vector vecIFDoc; theApp->getCompatibleImages (GetDocument(), vecIFDoc); + if (vecIFDoc.size() == 0) { + wxMessageBox ("No compatible images for Row Comparison", "Error"); + return; + } + DialogGetComparisonImage dialogGetCompare (m_frame, "Get Comparison Image", vecIFDoc, false); if (dialogGetCompare.ShowModal() == wxID_OK) { @@ -644,11 +762,21 @@ ImageFileView::OnCompareRow (wxCommandEvent& event) sys_error (ERR_SEVERE, "Internal error: unable to create Plot file"); } else { PlotFile& rPlotFile = pPlotDoc->getPlotFile(); - std::ostringstream title; - title << "Comparison of Row " << yCursor; - rPlotFile.setTitle(title.str()); - rPlotFile.setXLabel("Column"); - rPlotFile.setYLabel("Pixel Value"); + std::ostringstream os; + os << "Row " << yCursor << " Comparison"; + std::string title("title "); + title += os.str(); + 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); rPlotFile.addColumn (0, pX); rPlotFile.addColumn (1, pY1); @@ -657,7 +785,9 @@ ImageFileView::OnCompareRow (wxCommandEvent& event) delete pX; delete pY1; delete pY2; - pPlotDoc->Modify(true); + if (theApp->getSetModifyNewDocs()) + pPlotDoc->Modify(true); + pPlotDoc->UpdateAllViews(); } } } @@ -800,7 +930,8 @@ PhantomView::OnProjections (wxCommandEvent& event) theApp->getDocManager()->ActivateView (pView, true, false); } ::wxYield(); - pProjectionDoc->Modify(true); + if (theApp->getSetModifyNewDocs()) + pProjectionDoc->Modify(true); pProjectionDoc->UpdateAllViews(this); } } @@ -836,7 +967,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) { @@ -1060,7 +1192,7 @@ ProjectionFileView::OnReconstruct (wxCommandEvent& event) m_iDefaultTrace = dialogReconstruction.getTrace(); if (m_iDefaultNX > 0 && m_iDefaultNY > 0) { ImageFileDocument* pReconDoc = dynamic_cast(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT)); - if (pReconDoc) { + if (! pReconDoc) { sys_error (ERR_SEVERE, "Unable to create image file"); return; } @@ -1122,7 +1254,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) { @@ -1329,12 +1462,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 @@ -1460,7 +1595,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); @@ -1482,7 +1617,7 @@ PlotFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) m_frame->Show(true); Activate(true); - + return true; } @@ -1498,62 +1633,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); - - if (! rPlotFile.getTitle().empty()) { - std::string s("title "); - s += rPlotFile.getTitle(); - plot.ezset (s); - } - if (! rPlotFile.getXLabel().empty()) { - std::string s("xlabel "); - s += rPlotFile.getXLabel(); - plot.ezset (s); - } - if (! rPlotFile.getYLabel().empty()) { - std::string s("ylabel "); - s += rPlotFile.getYLabel(); - plot.ezset (s); - } - - 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