From: Kevin M. Rosenberg Date: Fri, 22 Dec 2000 04:18:30 +0000 (+0000) Subject: r311: image comparison functions X-Git-Tag: debian-4.5.3-3~706 X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=commitdiff_plain;h=c551b53b39a7571cf52831f5e117be1cca95c420 r311: image comparison functions --- diff --git a/ChangeLog b/ChangeLog index 63c618d..3788ecd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,11 +1,22 @@ -2.5.1 - Released 12/30/00 +3.0alpha1 - Released 12/30/00 - * Added PlotFile class - * Added plotting of rows & columns to ctsim - * Updated if2 to output plot files - * Added y-axis scaling to plotting in ctsim - * Reworked statistics to share between imagefile and plotfile class - * Fixed scaling bug in rasterizing Phantom with nsample > 2 + * Added PlotFile class to system, used by if2 and ctsim + + * ctsim: Added image comparison statistics and image subtraction + + * ctsim: Added plotting of rows & columns with y-axis scaling + + * ctsim: Added row and column plot comparisons between two image + files. + + * Reworked statistics algorithm to share between imagefile and + plotfile classes. + + * imagefile.cpp: Fixed scaling bug when rasterizing Phantom with + nsamples > 2. Added image math functions. + + * if2: Updated to output plot files and use new ImageFile class + math functions 2.5.0 - 12/18/00 First Microsoft Windows GUI version diff --git a/configure.in b/configure.in index 403e5ef..26a7779 100644 --- a/configure.in +++ b/configure.in @@ -4,7 +4,7 @@ dnl Must reset CDPATH so that bash's cd does not print to stdout dnl CDPATH= AC_INIT(src/ctsim.cpp) -AM_INIT_AUTOMAKE(ctsim,2.5.0) +AM_INIT_AUTOMAKE(ctsim,3.0.0-alpha1) AM_CONFIG_HEADER(config.h) dnl Checks for programs. diff --git a/include/imagefile.h b/include/imagefile.h index 443bf33..a7e69d7 100644 --- a/include/imagefile.h +++ b/include/imagefile.h @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: imagefile.h,v 1.22 2000/12/16 06:12:47 kevin Exp $ +** $Id: imagefile.h,v 1.23 2000/12/22 04:18:00 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 @@ -52,8 +52,8 @@ public: kfloat32** getArray (void) { return (kfloat32**) (m_arrayData); } - const kfloat32* const * getArray (void) const - { return (const kfloat32**) (m_arrayData); } + kfloat32** const getArray (void) const + { return (kfloat32** const) (m_arrayData); } #ifdef HAVE_MPI MPI::Datatype getMPIDataType (void) const @@ -76,8 +76,8 @@ class F64Image : public Array2dFile kfloat64** getArray (void) { return (kfloat64**) (m_arrayData); } - const kfloat64* const * getArray (void) const - { return (const kfloat64**) (m_arrayData); } + kfloat64** const getArray (void) const + { return (kfloat64** const) (m_arrayData); } #ifdef HAVE_MPI MPI::Datatype getMPIDataType (void) const @@ -94,13 +94,15 @@ typedef F64Image ImageFileBase; typedef kfloat64 ImageFileValue; typedef kfloat64* ImageFileColumn; typedef kfloat64** ImageFileArray; -typedef const kfloat64* const * ImageFileArrayConst; +typedef kfloat64** const ImageFileArrayConst; +typedef const kfloat64* ImageFileColumnConst; #else typedef F32Image ImageFileBase; typedef kfloat32 ImageFileValue; typedef kfloat32* ImageFileColumn; typedef kfloat32** ImageFileArray; -typedef const kfloat32* const * ImageFileArrayConst; +typedef kfloat32** const ImageFileArrayConst; +typedef const kfloat32* ImageFileColumnConst; #endif @@ -126,7 +128,15 @@ class ImageFile : public ImageFileBase bool comparativeStatistics (const ImageFile& imComp, double& d, double& r, double& e) const; bool printComparativeStatistics (const ImageFile& imComp, std::ostream& os) const; - + + bool subtractImages (const ImageFile& rRHS, ImageFile& result) const; + + bool addImages (const ImageFile& rRHS, ImageFile& result) const; + + bool multiplyImages (const ImageFile& rRHS, ImageFile& result) const; + + bool divideImages (const ImageFile& rRHS, ImageFile& result) const; + int display (void) const; int displayScaling (const int scaleFactor, ImageFileValue pmin, ImageFileValue pmax) const; diff --git a/libctsim/imagefile.cpp b/libctsim/imagefile.cpp index b86ff79..a5e9bec 100644 --- a/libctsim/imagefile.cpp +++ b/libctsim/imagefile.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: imagefile.cpp,v 1.23 2000/12/21 03:40:58 kevin Exp $ +** $Id: imagefile.cpp,v 1.24 2000/12/22 04:18:00 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 @@ -266,7 +266,104 @@ ImageFile::getMinMax (double& min, double& max) const } } } + +bool +ImageFile::subtractImages (const ImageFile& rRHS, ImageFile& result) const +{ + if (m_nx != rRHS.nx() || m_ny != rRHS.ny() || m_nx != result.nx() || m_ny != result.ny()) { + sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::subtractImage]"); + return false; + } + + ImageFileArrayConst vLHS = getArray(); + ImageFileArrayConst vRHS = rRHS.getArray(); + ImageFileArray vResult = result.getArray(); + + for (int ix = 0; ix < m_nx; ix++) { + ImageFileColumnConst in1 = vLHS[ix]; + ImageFileColumnConst in2 = vRHS[ix]; + ImageFileColumn out = vResult[ix]; + for (int iy = 0; iy < m_ny; iy++) + *out++ = *in1++ - *in2++; + } + + return true; +} +bool +ImageFile::addImages (const ImageFile& rRHS, ImageFile& result) const +{ + if (m_nx != rRHS.nx() || m_ny != rRHS.ny() || m_nx != result.nx() || m_ny != result.ny()) { + sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::subtractImage]"); + return false; + } + + ImageFileArrayConst vLHS = getArray(); + ImageFileArrayConst vRHS = rRHS.getArray(); + ImageFileArray vResult = result.getArray(); + + for (int ix = 0; ix < m_nx; ix++) { + ImageFileColumnConst in1 = vLHS[ix]; + ImageFileColumnConst in2 = vRHS[ix]; + ImageFileColumn out = vResult[ix]; + for (int iy = 0; iy < m_ny; iy++) + *out++ = *in1++ + *in2++; + } + + return true; +} + +bool +ImageFile::multiplyImages (const ImageFile& rRHS, ImageFile& result) const +{ + if (m_nx != rRHS.nx() || m_ny != rRHS.ny() || m_nx != result.nx() || m_ny != result.ny()) { + sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::subtractImage]"); + return false; + } + + ImageFileArrayConst vLHS = getArray(); + ImageFileArrayConst vRHS = rRHS.getArray(); + ImageFileArray vResult = result.getArray(); + + for (int ix = 0; ix < m_nx; ix++) { + ImageFileColumnConst in1 = vLHS[ix]; + ImageFileColumnConst in2 = vRHS[ix]; + ImageFileColumn out = vResult[ix]; + for (int iy = 0; iy < m_ny; iy++) + *out++ = *in1++ * *in2++; + } + + return true; +} + +bool +ImageFile::divideImages (const ImageFile& rRHS, ImageFile& result) const +{ + if (m_nx != rRHS.nx() || m_ny != rRHS.ny() || m_nx != result.nx() || m_ny != result.ny()) { + sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::subtractImage]"); + return false; + } + + ImageFileArrayConst vLHS = getArray(); + ImageFileArrayConst vRHS = rRHS.getArray(); + ImageFileArray vResult = result.getArray(); + + for (int ix = 0; ix < m_nx; ix++) { + ImageFileColumnConst in1 = vLHS[ix]; + ImageFileColumnConst in2 = vRHS[ix]; + ImageFileColumn out = vResult[ix]; + for (int iy = 0; iy < m_ny; iy++) { + if (*in2 != 0.) + *out++ = *in1++ / *in2++; + else + *out++ = 0; + } + } + + return true; +} + + void ImageFile::writeImagePGM (const char *outfile, int nxcell, int nycell, double densmin, double densmax) { diff --git a/msvc/ctsim/ctsim.plg b/msvc/ctsim/ctsim.plg index 9ec4c1f..ec7bd1a 100644 --- a/msvc/ctsim/ctsim.plg +++ b/msvc/ctsim/ctsim.plg @@ -6,13 +6,13 @@ --------------------Configuration: ctsim - Win32 Debug--------------------

Command Lines

-Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP1EF.tmp" with contents +Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP432.tmp" with contents [ /nologo /G6 /MTd /W3 /Gm /GR /GX /ZI /Od /I "\wx2\include" /I "." /I "..\..\include" /I "..\..\getopt" /I "..\..\..\lpng108" /I "..\..\..\zlib" /I "..\..\..\fftw-2.1.3\fftw" /I "..\..\..\fftw-2.1.3\rfftw" /D VERSION=\"2.5.0\" /D "_DEBUG" /D "__WXMSW__" /D "HAVE_SGP" /D "HAVE_PNG" /D "HAVE_WXWINDOWS" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "HAVE_STRING_H" /D "HAVE_FFTW" /D "HAVE_RFFTW" /D "HAVE_GETOPT_H" /D "MSVC" /D "__WIN95__" /D "__WIN32__" /D WINVER=0x0400 /D "STRICT" /D CTSIMVERSION=\"2.5.0\" /FR"Debug/" /Fp"Debug/ctsim.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c -"C:\ctsim-2.0.6\src\views.cpp" +"C:\ctsim-2.0.6\src\ctsim.cpp" ] -Creating command line "cl.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP1EF.tmp" -Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP1F0.tmp" with contents +Creating command line "cl.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP432.tmp" +Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP433.tmp" with contents [ comctl32.lib winmm.lib rpcrt4.lib ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ../libctsim/Debug/libctsim.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ..\..\..\lpng108\msvc\win32\libpng\lib_dbg\libpng.lib ..\..\..\lpng108\msvc\win32\zlib\lib_dbg\zlib.lib libcmtd.lib ..\..\..\fftw-2.1.3\Win32\FFTW2st\Debug\FFTW2st.lib ..\..\..\fftw-2.1.3\Win32\RFFTW2st\Debug\RFFTW2st.lib ../../../wx2/lib/wxd.lib /nologo /subsystem:windows /incremental:yes /pdb:"Debug/ctsim.pdb" /debug /machine:I386 /nodefaultlib:"libcd.lib" /nodefaultlib:"libcid.lib" /nodefaultlib:"msvcrtd.lib" /out:"Debug/ctsim.exe" /pdbtype:sept /libpath:"..\..\..\lpng108\msvc\win32\libpng\lib" /libpath:"..\..\..\lpng108\msvc\win32\zlib\lib" ".\Debug\ctsim.obj" @@ -27,14 +27,14 @@ comctl32.lib winmm.lib rpcrt4.lib ws2_32.lib kernel32.lib user32.lib gdi32.lib w "\fftw-2.1.3\Win32\RFFTW2st\Debug\RFFTW2st.lib" "\wx2\lib\wxd.lib" ] -Creating command line "link.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP1F0.tmp" +Creating command line "link.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP433.tmp"

Output Window

Compiling... -views.cpp +ctsim.cpp Linking... Creating command line "bscmake.exe /nologo /o"Debug/ctsim.bsc" ".\Debug\ctsim.sbr" ".\Debug\dialogs.sbr" ".\Debug\dlgprojections.sbr" ".\Debug\dlgreconstruct.sbr" ".\Debug\docs.sbr" ".\Debug\views.sbr"" Creating browse info file... -BSCMAKE: warning BK4503 : minor error in .SBR file '.\Debug\views.sbr' ignored +BSCMAKE: warning BK4503 : minor error in .SBR file '.\Debug\ctsim.sbr' ignored

Output Window

diff --git a/src/ctsim.cpp b/src/ctsim.cpp index bdd8a59..b128641 100644 --- a/src/ctsim.cpp +++ b/src/ctsim.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ctsim.cpp,v 1.19 2000/12/20 14:39:09 kevin Exp $ +** $Id: ctsim.cpp,v 1.20 2000/12/22 04:18:00 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 @@ -61,7 +61,7 @@ #endif #endif -static const char* rcsindent = "$Id: ctsim.cpp,v 1.19 2000/12/20 14:39:09 kevin Exp $"; +static const char* rcsindent = "$Id: ctsim.cpp,v 1.20 2000/12/22 04:18:00 kevin Exp $"; class CTSimApp* theApp = NULL; @@ -285,6 +285,27 @@ MainFrame::OnCreatePhantom(wxCommandEvent& WXUNUSED(event)) } +void +CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector& vecIF) +{ + const ImageFile& rIF = pIFDoc->getImageFile(); + int nx = rIF.nx(); + int ny = rIF.ny(); + wxList& rListDocs = m_docManager->GetDocuments(); + std::vector vecFilename; + for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) { + wxDocument* pDoc = reinterpret_cast(pNode->GetData()); + ImageFileDocument* pIFCompareDoc = dynamic_cast(pDoc); + if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) { + const ImageFile& rCompareIF = pIFCompareDoc->getImageFile(); + if (rCompareIF.nx() == nx && rCompareIF.ny() == ny) { + std::string strFilename = pDoc->GetFilename(); + vecIF.push_back (pIFCompareDoc); + } + } + } +} + void MainFrame::OnHelpContents(wxCommandEvent& WXUNUSED(event) ) { diff --git a/src/ctsim.h b/src/ctsim.h index 486224b..dddf210 100644 --- a/src/ctsim.h +++ b/src/ctsim.h @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ctsim.h,v 1.11 2000/12/21 03:40:58 kevin Exp $ +** $Id: ctsim.h,v 1.12 2000/12/22 04:18:00 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 @@ -36,7 +36,10 @@ #endif class wxMenu; -class wxDocument; +class wxDocument; +class ImageFileDocument; +#include + #include "wx/docview.h" // Define a new frame for main window @@ -106,6 +109,8 @@ public: { return m_docManager; } wxString getUntitledFilename(); + + void getCompatibleImages (const ImageFileDocument* pIFDoc, std::vector& vecIF); private: wxDocManager* m_docManager; @@ -136,7 +141,9 @@ enum { IFMENU_PLOT_COL, IFMENU_VIEW_SCALE_AUTO, IFMENU_VIEW_SCALE_MINMAX, - IFMENU_COMPARE_IMAGES, + IFMENU_COMPARE_IMAGES, + IFMENU_COMPARE_ROW, + IFMENU_COMPARE_COL, PHMMENU_PROCESS_RASTERIZE, PHMMENU_PROCESS_PROJECTIONS, PLOTMENU_VIEW_SCALE_MINMAX, diff --git a/src/dialogs.cpp b/src/dialogs.cpp index 66191bb..7d8c0ec 100644 --- a/src/dialogs.cpp +++ b/src/dialogs.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: dialogs.cpp,v 1.19 2000/12/21 03:40:58 kevin Exp $ +** $Id: dialogs.cpp,v 1.20 2000/12/22 04:18:00 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 @@ -53,6 +53,9 @@ #include "phantom.h" #include "filter.h" #include "backprojectors.h" +#include "docs.h" +#include "views.h" +#include "imagefile.h" #if defined(MSVC) || HAVE_SSTREAM #include @@ -127,6 +130,73 @@ DialogGetPhantom::getPhantom(void) } +/////////////////////////////////////////////////////////////////////// +// CLASS IMPLEMENTATION +// DialogGetComparisonImage +/////////////////////////////////////////////////////////////////////// + +DialogGetComparisonImage::DialogGetComparisonImage (wxFrame* pParent, const char* const pszTitle, const std::vector& rVecIF, bool bShowMakeDifference) +: wxDialog (pParent, -1, pszTitle, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION), m_rVecIF(rVecIF) +{ + wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL); + + pTopSizer->Add (new wxStaticText (this, -1, pszTitle), 0, wxALIGN_CENTER | wxALL, 5); + + pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxALL, 5); + + int iNImages = m_rVecIF.size(); + wxString* pstrImages = new wxString [iNImages]; + for (int i = 0; i < iNImages; i++) { + ImageFileView* pView = dynamic_cast(m_rVecIF[i]->GetFirstView()); + if (pView) + pstrImages[i] = pView->getFrame()->GetTitle(); + } + + m_pListBoxImageChoices = new wxListBox (this, -1, wxDefaultPosition, wxDefaultSize, iNImages, pstrImages, wxLB_SINGLE); + delete [] pstrImages; + + m_pListBoxImageChoices->SetSelection (0); + pTopSizer->Add (m_pListBoxImageChoices, 0, wxALL | wxALIGN_CENTER | wxEXPAND); + + if (bShowMakeDifference) { + m_pMakeDifferenceImage = new wxCheckBox (this, -1, "Make Difference Image"); + m_pMakeDifferenceImage->SetValue (FALSE); + pTopSizer->Add (m_pMakeDifferenceImage, 0, wxALL | wxALIGN_CENTER | wxEXPAND); + } else + m_pMakeDifferenceImage = NULL; + + pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); + + wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL); + wxButton* pButtonOk = new wxButton (this, wxID_OK, "Okay"); + wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel"); + pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10); + pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10); + + pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER); + + SetAutoLayout (true); + SetSizer (pTopSizer); + pTopSizer->Fit (this); + pTopSizer->SetSizeHints (this); +} + +ImageFileDocument* +DialogGetComparisonImage::getImageFileDocument(void) +{ + return m_rVecIF[ m_pListBoxImageChoices->GetSelection() ]; +} + +bool +DialogGetComparisonImage::getMakeDifferenceImage() +{ + if (m_pMakeDifferenceImage) + return m_pMakeDifferenceImage->GetValue(); + else + return false; +} + + ///////////////////////////////////////////////////////////////////// // CLASS DiaglogGetMinMax Implementation ///////////////////////////////////////////////////////////////////// diff --git a/src/dialogs.h b/src/dialogs.h index c4c6647..4441ca0 100644 --- a/src/dialogs.h +++ b/src/dialogs.h @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: dialogs.h,v 1.15 2000/12/21 03:40:58 kevin Exp $ +** $Id: dialogs.h,v 1.16 2000/12/22 04:18:00 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 @@ -67,6 +67,25 @@ class DialogGetPhantom : public wxDialog StringValueAndTitleListBox* m_pListBoxPhantom; }; + +#include +class ImageFileDocument; +class DialogGetComparisonImage : public wxDialog +{ + public: + DialogGetComparisonImage (wxFrame* pParent, const char* const pszTitle, const std::vector& rVecIF, bool bShowMakeDifference); + virtual ~DialogGetComparisonImage () {} + + ImageFileDocument* getImageFileDocument (); + + bool getMakeDifferenceImage(); + + private: + wxListBox* m_pListBoxImageChoices; + wxCheckBox* m_pMakeDifferenceImage; + const std::vector& m_rVecIF; +}; + class ImageFile; diff --git a/src/docs.h b/src/docs.h index 7b337bb..116347c 100644 --- a/src/docs.h +++ b/src/docs.h @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: docs.h,v 1.7 2000/12/20 14:39:09 kevin Exp $ +** $Id: docs.h,v 1.8 2000/12/22 04:18:00 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 @@ -37,7 +37,7 @@ #include "imagefile.h" #include "phantom.h" #include "projections.h" - +#include "plotfile.h" class ImageFileDocument: public wxDocument { @@ -121,7 +121,8 @@ public: virtual bool IsModified () const; virtual void Modify (bool mod); }; - + + class PlotFileDocument: public wxDocument { DECLARE_DYNAMIC_CLASS(PlotFileDocument) diff --git a/src/views.cpp b/src/views.cpp index 68b0375..740c81c 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.35 2000/12/21 03:40:58 kevin Exp $ +** $Id: views.cpp,v 1.36 2000/12/22 04:18:00 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 @@ -71,90 +71,90 @@ END_EVENT_TABLE() ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style) : wxScrolledWindow(frame, -1, pos, size, style) { - m_pView = v; - m_xCursor = -1; - m_yCursor = -1; + m_pView = v; + m_xCursor = -1; + m_yCursor = -1; } void ImageFileCanvas::OnDraw(wxDC& dc) { - if (m_pView) - m_pView->OnDraw(& dc); + if (m_pView) + m_pView->OnDraw(& dc); } void ImageFileCanvas::DrawRubberBandCursor (wxDC& dc, int x, int y) { - const ImageFile& rIF = m_pView->GetDocument()->getImageFile(); - ImageFileArrayConst v = rIF.getArray(); - int nx = rIF.nx(); - int ny = rIF.ny(); - - dc.SetLogicalFunction (wxINVERT); - dc.SetPen (*wxGREEN_PEN); - dc.DrawLine (0, y, nx, y); - dc.DrawLine (x, 0, x, ny); - dc.SetLogicalFunction (wxCOPY); + const ImageFile& rIF = m_pView->GetDocument()->getImageFile(); + ImageFileArrayConst v = rIF.getArray(); + int nx = rIF.nx(); + int ny = rIF.ny(); + + dc.SetLogicalFunction (wxINVERT); + dc.SetPen (*wxGREEN_PEN); + dc.DrawLine (0, y, nx, y); + dc.DrawLine (x, 0, x, ny); + dc.SetLogicalFunction (wxCOPY); } bool ImageFileCanvas::GetCurrentCursor (int& x, int& y) { - x = m_xCursor; - y = m_yCursor; - - if (m_xCursor >= 0 && m_yCursor >= 0) - return true; - else - return false; + x = m_xCursor; + y = m_yCursor; + + if (m_xCursor >= 0 && m_yCursor >= 0) + return true; + else + return false; } void ImageFileCanvas::OnMouseEvent(wxMouseEvent& event) { - if (! m_pView) - return; - - wxClientDC dc(this); - PrepareDC(dc); - - wxPoint pt(event.GetLogicalPosition(dc)); - - 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"; - *theApp->getLog() << os.str().c_str(); - } else - *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << pt.y << ")\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(); - - 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); - m_xCursor = pt.x; - m_yCursor = pt.y; - } else - *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << pt.y << ")\n"; - } - if (event.LeftUp()) { - std::ostringstream os; - os << "Selected column" << pt.x << " and row" << pt.y << "\n"; - *theApp->getLog() << os.str().c_str(); - } + if (! m_pView) + return; + + wxClientDC dc(this); + PrepareDC(dc); + + wxPoint pt(event.GetLogicalPosition(dc)); + + 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"; + *theApp->getLog() << os.str().c_str(); + } else + *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << pt.y << ")\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(); + + 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); + m_xCursor = pt.x; + m_yCursor = pt.y; + } else + *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << pt.y << ")\n"; + } + if (event.LeftUp()) { + std::ostringstream os; + os << "Selected column" << pt.x << " and row" << pt.y << "\n"; + *theApp->getLog() << os.str().c_str(); + } } // ImageFileView @@ -166,6 +166,8 @@ EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties) EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax) 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_PLOT_ROW, ImageFileView::OnPlotRow) EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol) END_EVENT_TABLE() @@ -182,368 +184,498 @@ 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(); - } + 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(); + } } void ImageFileView::OnScaleAuto (wxCommandEvent& event) { - const ImageFile& rIF = GetDocument()->getImageFile(); - double min, max, mean, mode, median, stddev; - rIF.statistics(min, max, mean, mode, median, stddev); - DialogAutoScaleParameters dialogAutoScale (m_frame, 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); - } + const ImageFile& rIF = GetDocument()->getImageFile(); + double min, max, mean, mode, median, stddev; + rIF.statistics(min, max, mean, mode, median, stddev); + DialogAutoScaleParameters dialogAutoScale (m_frame, 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 ImageFileView::OnScaleMinMax (wxCommandEvent& event) { - const ImageFile& rIF = GetDocument()->getImageFile(); - double min, max; - if (! m_bMinSpecified && ! m_bMaxSpecified) - rIF.getMinMax (min, max); - - if (m_bMinSpecified) - min = m_dMinPixel; - if (m_bMaxSpecified) - max = m_dMaxPixel; - - DialogGetMinMax dialogMinMax (m_frame, "Set Image 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); - } + const ImageFile& rIF = GetDocument()->getImageFile(); + double min, max; + if (! m_bMinSpecified && ! m_bMaxSpecified) + rIF.getMinMax (min, max); + + if (m_bMinSpecified) + min = m_dMinPixel; + if (m_bMaxSpecified) + max = m_dMaxPixel; + + DialogGetMinMax dialogMinMax (m_frame, "Set Image 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 ImageFileView::OnCompare (wxCommandEvent& event) { - wxList& rListDocs = theApp->getDocManager()->GetDocuments(); std::vector vecIF; - std::vector vecFilename; - int nCompares = 0; - for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) { - wxDocument* pDoc = reinterpret_cast(pNode->GetData()); - ImageFileDocument* pIFDoc = dynamic_cast(pDoc); - if (pIFDoc) { - if (pIFDoc->GetFirstView() != this) { - std::string strFilename = pDoc->GetFilename(); - vecIF.push_back (pIFDoc); - vecFilename.push_back (strFilename); - nCompares++; - } - } - } - for (int i = 0; i < nCompares; i++) { - const std::string& s = vecFilename[i]; - *theApp->getLog() << s.c_str() << "\n"; + 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(); + const ImageFile& rCompareIF = pCompareDoc->getImageFile(); + std::ostringstream os; + double min, max, mean, mode, median, stddev; + rIF.statistics (min, max, mean, mode, median, stddev); + os << rIF.getFilename() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n"; + rCompareIF.statistics (min, max, mean, mode, median, stddev); + os << rCompareIF.getFilename() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n"; + os << "\n"; + double d, r, e; + rIF.comparativeStatistics (rCompareIF, d, r, e); + os << "Comparative Statistics: d=" << d << ", r=" << r << ", e=" << e << "\n"; + *theApp->getLog() << os.str().c_str(); + if (dialogGetCompare.getMakeDifferenceImage()) { + ImageFileDocument* pDifferenceDoc = dynamic_cast(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT)); + if (! pDifferenceDoc) { + sys_error (ERR_SEVERE, "Unable to create image file"); + return; + } + ImageFile& differenceImage = pDifferenceDoc->getImageFile(); + + differenceImage.setArraySize (rIF.nx(), rIF.ny()); + if (! rIF.subtractImages (rCompareIF, differenceImage)) { + pDifferenceDoc->DeleteAllViews(); + return; + } + + pDifferenceDoc->Modify(true); + pDifferenceDoc->UpdateAllViews(this); + pDifferenceDoc->GetFirstView()->OnUpdate (this, NULL); + } + wxMessageBox(os.str().c_str(), "Image Comparison"); + } } } ImageFileCanvas* ImageFileView::CreateCanvas (wxView *view, wxFrame *parent) { - ImageFileCanvas* pCanvas; - int width, height; - parent->GetClientSize(&width, &height); - - pCanvas = new ImageFileCanvas (dynamic_cast(view), parent, wxPoint(0, 0), wxSize(width, height), 0); - - pCanvas->SetScrollbars(20, 20, 50, 50); - pCanvas->SetBackgroundColour(*wxWHITE); - pCanvas->Clear(); - - return pCanvas; + ImageFileCanvas* pCanvas; + int width, height; + parent->GetClientSize(&width, &height); + + pCanvas = new ImageFileCanvas (dynamic_cast(view), parent, wxPoint(0, 0), wxSize(width, height), 0); + + pCanvas->SetScrollbars(20, 20, 50, 50); + pCanvas->SetBackgroundColour(*wxWHITE); + pCanvas->Clear(); + + return pCanvas; } wxFrame* ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view) { - wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE); - - wxMenu *file_menu = new wxMenu; - - file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom..."); - file_menu->Append(wxID_OPEN, "&Open..."); - file_menu->Append(wxID_SAVE, "&Save"); - file_menu->Append(wxID_SAVEAS, "Save &As..."); - file_menu->Append(wxID_CLOSE, "&Close"); - - file_menu->AppendSeparator(); - file_menu->Append(IFMENU_FILE_PROPERTIES, "P&roperties"); - - file_menu->AppendSeparator(); - file_menu->Append(wxID_PRINT, "&Print..."); - file_menu->Append(wxID_PRINT_SETUP, "Print &Setup..."); - file_menu->Append(wxID_PREVIEW, "Print Pre&view"); - - wxMenu *view_menu = new wxMenu; - view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale &Set..."); - view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto..."); - - wxMenu *plot_menu = new wxMenu; - plot_menu->Append (IFMENU_PLOT_ROW, "Plot &Row"); - plot_menu->Append (IFMENU_PLOT_COL, "Plot &Column"); - - wxMenu *compare_menu = new wxMenu; - compare_menu->Append (IFMENU_COMPARE_IMAGES, "&Compare Images"); + wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE); + + wxMenu *file_menu = new wxMenu; + + file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom..."); + file_menu->Append(wxID_OPEN, "&Open..."); + file_menu->Append(wxID_SAVE, "&Save"); + file_menu->Append(wxID_SAVEAS, "Save &As..."); + file_menu->Append(wxID_CLOSE, "&Close"); + + file_menu->AppendSeparator(); + file_menu->Append(IFMENU_FILE_PROPERTIES, "P&roperties"); + + file_menu->AppendSeparator(); + file_menu->Append(wxID_PRINT, "&Print..."); + file_menu->Append(wxID_PRINT_SETUP, "Print &Setup..."); + file_menu->Append(wxID_PREVIEW, "Print Pre&view"); + + wxMenu *view_menu = new wxMenu; + view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale &Set..."); + view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto..."); + + wxMenu *plot_menu = new wxMenu; + plot_menu->Append (IFMENU_PLOT_ROW, "Plot &Row"); + plot_menu->Append (IFMENU_PLOT_COL, "Plot &Column"); + + wxMenu *compare_menu = new wxMenu; + 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"); - - wxMenuBar *menu_bar = new wxMenuBar; - - menu_bar->Append(file_menu, "&File"); - menu_bar->Append(view_menu, "&View"); - menu_bar->Append(plot_menu, "&Plot"); - menu_bar->Append(compare_menu, "&Compare"); - menu_bar->Append(help_menu, "&Help"); - - subframe->SetMenuBar(menu_bar); - - subframe->Centre(wxBOTH); - - return subframe; + wxMenu *help_menu = new wxMenu; + help_menu->Append(MAINMENU_HELP_ABOUT, "&About"); + + wxMenuBar *menu_bar = new wxMenuBar; + + menu_bar->Append(file_menu, "&File"); + menu_bar->Append(view_menu, "&View"); + menu_bar->Append(plot_menu, "&Plot"); + menu_bar->Append(compare_menu, "&Compare"); + menu_bar->Append(help_menu, "&Help"); + + subframe->SetMenuBar(menu_bar); + + subframe->Centre(wxBOTH); + + return subframe; } bool ImageFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) { - m_frame = CreateChildFrame(doc, this); - SetFrame (m_frame); - - m_bMinSpecified = false; - m_bMaxSpecified = false; - m_dAutoScaleFactor = 1.; - - int width, height; - m_frame->GetClientSize (&width, &height); - m_frame->SetTitle("ImageFileView"); - m_canvas = CreateCanvas (this, m_frame); - - int x, y; // X requires a forced resize - m_frame->GetSize(&x, &y); - m_frame->SetSize(-1, -1, x, y); - m_frame->SetFocus(); - m_frame->Show(true); - Activate(true); - - return true; + m_frame = CreateChildFrame(doc, this); + SetFrame (m_frame); + + m_bMinSpecified = false; + m_bMaxSpecified = false; + m_dAutoScaleFactor = 1.; + + int width, height; + m_frame->GetClientSize (&width, &height); + m_frame->SetTitle("ImageFileView"); + m_canvas = CreateCanvas (this, m_frame); + + int x, y; // X requires a forced resize + m_frame->GetSize(&x, &y); + m_frame->SetSize(-1, -1, x, y); + m_frame->SetFocus(); + m_frame->Show(true); + Activate(true); + + return true; } void ImageFileView::OnDraw (wxDC* dc) { - if (m_bitmap.Ok()) - dc->DrawBitmap(m_bitmap, 0, 0, false); - - int xCursor, yCursor; - if (m_canvas->GetCurrentCursor (xCursor, yCursor)) - m_canvas->DrawRubberBandCursor (*dc, xCursor, yCursor); + if (m_bitmap.Ok()) + dc->DrawBitmap(m_bitmap, 0, 0, false); + + int xCursor, yCursor; + if (m_canvas->GetCurrentCursor (xCursor, yCursor)) + m_canvas->DrawRubberBandCursor (*dc, xCursor, yCursor); } void ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) { - const ImageFile& rIF = dynamic_cast(GetDocument())->getImageFile(); - ImageFileArrayConst v = rIF.getArray(); - int nx = rIF.nx(); - int ny = rIF.ny(); - if (v != NULL && nx != 0 && ny != 0) { - if (! m_bMinSpecified || ! m_bMaxSpecified) { - double min, max; - rIF.getMinMax (min, max); - if (! m_bMinSpecified) - m_dMinPixel = min; - if (! m_bMaxSpecified) - m_dMaxPixel = max; - } - double scaleWidth = m_dMaxPixel - m_dMinPixel; - - unsigned char* imageData = new unsigned char [nx * ny * 3]; - for (int ix = 0; ix < nx; ix++) { - for (int iy = 0; iy < ny; iy++) { - double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255; - int intensity = static_cast(scaleValue + 0.5); - intensity = clamp (intensity, 0, 255); - int baseAddr = ((ny - 1 - iy) * nx + ix) * 3; - imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity; - } - } - wxImage image (nx, ny, imageData, true); - m_bitmap = image.ConvertToBitmap(); - delete imageData; - int xSize = nx; - int ySize = ny; - xSize = clamp (xSize, 0, 800); - ySize = clamp (ySize, 0, 800); - m_frame->SetClientSize (xSize, ySize); - m_canvas->SetScrollbars(20, 20, nx/20, ny/20); - m_canvas->SetBackgroundColour(*wxWHITE); - } - - if (m_canvas) - m_canvas->Refresh(); + const ImageFile& rIF = dynamic_cast(GetDocument())->getImageFile(); + ImageFileArrayConst v = rIF.getArray(); + int nx = rIF.nx(); + int ny = rIF.ny(); + if (v != NULL && nx != 0 && ny != 0) { + if (! m_bMinSpecified || ! m_bMaxSpecified) { + double min, max; + rIF.getMinMax (min, max); + if (! m_bMinSpecified) + m_dMinPixel = min; + if (! m_bMaxSpecified) + m_dMaxPixel = max; + } + double scaleWidth = m_dMaxPixel - m_dMinPixel; + + unsigned char* imageData = new unsigned char [nx * ny * 3]; + for (int ix = 0; ix < nx; ix++) { + for (int iy = 0; iy < ny; iy++) { + double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255; + int intensity = static_cast(scaleValue + 0.5); + intensity = clamp (intensity, 0, 255); + int baseAddr = ((ny - 1 - iy) * nx + ix) * 3; + imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity; + } + } + wxImage image (nx, ny, imageData, true); + m_bitmap = image.ConvertToBitmap(); + delete imageData; + int xSize = nx; + int ySize = ny; + xSize = clamp (xSize, 0, 800); + ySize = clamp (ySize, 0, 800); + m_frame->SetClientSize (xSize, ySize); + m_canvas->SetScrollbars(20, 20, nx/20, ny/20); + m_canvas->SetBackgroundColour(*wxWHITE); + } + + if (m_canvas) + m_canvas->Refresh(); } bool ImageFileView::OnClose (bool deleteWindow) { - if (!GetDocument()->Close()) - return false; - - m_canvas->Clear(); - m_canvas->m_pView = NULL; - m_canvas = NULL; - wxString s(theApp->GetAppName()); - if (m_frame) - m_frame->SetTitle(s); - SetFrame(NULL); - - Activate(false); - - if (deleteWindow) { - delete m_frame; - return true; - } + if (!GetDocument()->Close()) + return false; + + m_canvas->Clear(); + m_canvas->m_pView = NULL; + m_canvas = NULL; + wxString s(theApp->GetAppName()); + if (m_frame) + m_frame->SetTitle(s); + SetFrame(NULL); + + Activate(false); + + if (deleteWindow) { + delete m_frame; return true; + } + return true; } -#include "wx/plot.h" void ImageFileView::OnPlotRow (wxCommandEvent& event) { - int xCursor, yCursor; - if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) { - *theApp->getLog() << "No row selected. Please use left mouse button on image to select row\n"; - return; - } - - const ImageFile& rIF = dynamic_cast(GetDocument())->getImageFile(); - ImageFileArrayConst v = rIF.getArray(); + int xCursor, yCursor; + if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) { + wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error"); + return; + } + + const ImageFile& rIF = dynamic_cast(GetDocument())->getImageFile(); + ImageFileArrayConst v = rIF.getArray(); + int nx = rIF.nx(); + int ny = rIF.ny(); + + if (v != NULL && yCursor < ny) { + double* pX = new double [nx]; + double* pY = new double [nx]; + for (int i = 0; i < nx; 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& rPlotFile = pPlotDoc->getPlotFile(); + std::ostringstream title; + title << "Row " << yCursor; + rPlotFile.setTitle(title.str()); + rPlotFile.setXLabel("Column"); + rPlotFile.setYLabel("Pixel Value"); + rPlotFile.setCurveSize (2, nx); + rPlotFile.addColumn (0, pX); + rPlotFile.addColumn (1, pY); + } + delete pX; + delete pY; + pPlotDoc->Modify(true); + } + +} + +void +ImageFileView::OnPlotCol (wxCommandEvent& event) +{ + int xCursor, yCursor; + if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) { + wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error"); + return; + } + + const ImageFile& rIF = dynamic_cast(GetDocument())->getImageFile(); + ImageFileArrayConst v = rIF.getArray(); + int nx = rIF.nx(); + int ny = rIF.ny(); + + if (v != NULL && xCursor < nx) { + double* pX = new double [ny]; + double* pY = new double [ny]; + for (int i = 0; i < ny; i++) { + pX[i] = i; + pY[i] = v[xCursor][i]; + } + 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& rPlotFile = pPlotDoc->getPlotFile(); + std::ostringstream title; + title << "Column " << xCursor; + rPlotFile.setTitle(title.str()); + rPlotFile.setXLabel("Row"); + rPlotFile.setYLabel("Pixel Value"); + rPlotFile.setCurveSize (2, nx); + rPlotFile.addColumn (0, pX); + rPlotFile.addColumn (1, pY); + } + delete pX; + delete pY; + pPlotDoc->Modify(true); + } +} + +void +ImageFileView::OnCompareCol (wxCommandEvent& event) +{ + int xCursor, yCursor; + if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) { + wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error"); + return; + } + + std::vector vecIFDoc; + theApp->getCompatibleImages (GetDocument(), vecIFDoc); + + DialogGetComparisonImage dialogGetCompare (m_frame, "Get Comparison Image", vecIFDoc, false); + + if (dialogGetCompare.ShowModal() == wxID_OK) { + ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument(); + const ImageFile& rIF = GetDocument()->getImageFile(); + const ImageFile& rCompareIF = pCompareDoc->getImageFile(); + + ImageFileArrayConst v1 = rIF.getArray(); + ImageFileArrayConst v2 = rCompareIF.getArray(); int nx = rIF.nx(); int ny = rIF.ny(); - - if (v != NULL && yCursor < ny) { - double* pX = new double [nx]; - double* pY = new double [nx]; - for (int i = 0; i < nx; 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& rPlotFile = pPlotDoc->getPlotFile(); - std::ostringstream title; - title << "Row " << yCursor; - rPlotFile.setTitle(title.str()); - rPlotFile.setXLabel("Column"); - rPlotFile.setYLabel("Pixel Value"); - rPlotFile.setCurveSize (2, nx); - rPlotFile.addColumn (0, pX); - rPlotFile.addColumn (1, pY); - } - delete pX; - delete pY; - pPlotDoc->Modify(true); - } - + + if (v1 != NULL && xCursor < nx) { + double* pX = new double [ny]; + double* pY1 = new double [ny]; + double* pY2 = new double [ny]; + for (int i = 0; i < ny; i++) { + pX[i] = i; + pY1[i] = v1[xCursor][i]; + pY2[i] = v2[xCursor][i]; + } + 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& rPlotFile = pPlotDoc->getPlotFile(); + std::ostringstream title; + title << "Comparison of Column " << xCursor; + rPlotFile.setTitle(title.str()); + rPlotFile.setXLabel("Row"); + rPlotFile.setYLabel("Pixel Value"); + rPlotFile.setCurveSize (3, nx); + rPlotFile.addColumn (0, pX); + rPlotFile.addColumn (1, pY1); + rPlotFile.addColumn (2, pY2); + } + delete pX; + delete pY1; + delete pY2; + pPlotDoc->Modify(true); + } + } } void -ImageFileView::OnPlotCol (wxCommandEvent& event) +ImageFileView::OnCompareRow (wxCommandEvent& event) { - int xCursor, yCursor; - if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) { - // os << "No column selected. Please use left mouse button on image to select column\n"; - return; - } - - const ImageFile& rIF = dynamic_cast(GetDocument())->getImageFile(); - ImageFileArrayConst v = rIF.getArray(); + int xCursor, yCursor; + if (! m_canvas->GetCurrentCursor (xCursor, yCursor)) { + wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error"); + return; + } + + std::vector vecIFDoc; + theApp->getCompatibleImages (GetDocument(), vecIFDoc); + + DialogGetComparisonImage dialogGetCompare (m_frame, "Get Comparison Image", vecIFDoc, false); + + if (dialogGetCompare.ShowModal() == wxID_OK) { + ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument(); + const ImageFile& rIF = GetDocument()->getImageFile(); + const ImageFile& rCompareIF = pCompareDoc->getImageFile(); + + ImageFileArrayConst v1 = rIF.getArray(); + ImageFileArrayConst v2 = rCompareIF.getArray(); int nx = rIF.nx(); int ny = rIF.ny(); - - if (v != NULL && xCursor < nx) { - double* pX = new double [ny]; - double* pY = new double [ny]; - double minVal = v[xCursor][0]; - double maxVal = minVal; - for (int i = 0; i < ny; i++) { - double y = v[xCursor][i]; - if (minVal < y) - minVal = y; - else if (maxVal > y) - maxVal = y; - pX[i] = i; - pY[i] = y; - } - 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& rPlotFile = pPlotDoc->getPlotFile(); - std::ostringstream title; - title << "Column " << xCursor; - rPlotFile.setTitle(title.str()); - rPlotFile.setXLabel("Row"); - rPlotFile.setYLabel("Pixel Value"); - rPlotFile.setCurveSize (2, nx); - rPlotFile.addColumn (0, pX); - rPlotFile.addColumn (1, pY); - } - delete pX; - delete pY; - pPlotDoc->Modify(true); - } + + if (v1 != NULL && yCursor < ny) { + double* pX = new double [nx]; + double* pY1 = new double [nx]; + double* pY2 = new double [nx]; + for (int i = 0; i < nx; i++) { + pX[i] = i; + pY1[i] = v1[i][yCursor]; + pY2[i] = v2[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& rPlotFile = pPlotDoc->getPlotFile(); + std::ostringstream title; + title << "Comparison of Row " << yCursor; + rPlotFile.setTitle(title.str()); + rPlotFile.setXLabel("Column"); + rPlotFile.setYLabel("Pixel Value"); + rPlotFile.setCurveSize (3, ny); + rPlotFile.addColumn (0, pX); + rPlotFile.addColumn (1, pY1); + rPlotFile.addColumn (2, pY2); + } + delete pX; + delete pY1; + delete pY2; + pPlotDoc->Modify(true); + } + } } - + // PhantomCanvas PhantomCanvas::PhantomCanvas (PhantomView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style) : wxScrolledWindow(frame, -1, pos, size, style) { - m_pView = v; + m_pView = v; } void PhantomCanvas::OnDraw(wxDC& dc) { - if (m_pView) - m_pView->OnDraw(& dc); + if (m_pView) + m_pView->OnDraw(& dc); } @@ -560,14 +692,14 @@ END_EVENT_TABLE() PhantomView::PhantomView(void) : wxView(), m_canvas(NULL), m_frame(NULL) { - m_iDefaultNDet = 367; - m_iDefaultNView = 320; - m_iDefaultNSample = 2; - m_dDefaultRotation = 2; - m_dDefaultFocalLength = 2; - m_dDefaultFieldOfView = 1; - m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL; - m_iDefaultTrace = Trace::TRACE_NONE; + m_iDefaultNDet = 367; + m_iDefaultNView = 320; + m_iDefaultNSample = 2; + m_dDefaultRotation = 2; + m_dDefaultFocalLength = 2; + m_dDefaultFieldOfView = 1; + m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL; + m_iDefaultTrace = Trace::TRACE_NONE; } PhantomView::~PhantomView(void) @@ -577,14 +709,14 @@ PhantomView::~PhantomView(void) void PhantomView::OnProperties (wxCommandEvent& event) { - const int idPhantom = GetDocument()->getPhantomID(); - const wxString& namePhantom = GetDocument()->getPhantomName(); - std::ostringstream os; - os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")\n"; - *theApp->getLog() << os.str().c_str(); + const int idPhantom = GetDocument()->getPhantomID(); + const wxString& namePhantom = GetDocument()->getPhantomName(); + std::ostringstream os; + os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")\n"; + *theApp->getLog() << os.str().c_str(); #if DEBUG - const Phantom& rPhantom = GetDocument()->getPhantom(); - rPhantom.print(); + const Phantom& rPhantom = GetDocument()->getPhantom(); + rPhantom.print(); #endif } @@ -592,254 +724,254 @@ PhantomView::OnProperties (wxCommandEvent& event) void PhantomView::OnProjections (wxCommandEvent& event) { - DialogGetProjectionParameters dialogProjection (m_frame, m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView, m_iDefaultGeometry, m_iDefaultTrace); - int retVal = dialogProjection.ShowModal(); - if (retVal == wxID_OK) { - m_iDefaultNDet = dialogProjection.getNDet(); - m_iDefaultNView = dialogProjection.getNView(); - m_iDefaultNSample = dialogProjection.getNSamples(); - m_iDefaultTrace = dialogProjection.getTrace(); - m_dDefaultRotation = dialogProjection.getRotAngle(); - m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio(); - m_dDefaultFieldOfView = dialogProjection.getFieldOfViewRatio(); - wxString sGeometry = dialogProjection.getGeometry(); - m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str()); - - if (m_iDefaultNDet > 0 && m_iDefaultNView > 0 && sGeometry != "") { - const Phantom& rPhantom = GetDocument()->getPhantom(); - ProjectionFileDocument* pProjectionDoc = dynamic_cast(theApp->getDocManager()->CreateDocument("untitled.pj", wxDOC_SILENT)); - if (! pProjectionDoc) { - sys_error (ERR_SEVERE, "Unable to create projection document"); - return; - } - Projections& rProj = pProjectionDoc->getProjections(); - Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView); - if (theScanner.fail()) { - *theApp->getLog() << "Failed making scanner: " << theScanner.failMessage().c_str() << "\n"; - return; - } - rProj.initFromScanner (theScanner); - m_dDefaultRotation /= PI; // convert back to PI units - - if (m_iDefaultTrace > Trace::TRACE_CONSOLE) { - ProjectionsDialog dialogProjections (theScanner, rProj, rPhantom, m_iDefaultTrace, dynamic_cast(m_frame)); - for (int iView = 0; iView < rProj.nView(); iView++) { - ::wxYield(); - ::wxYield(); - if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) { - pProjectionDoc->DeleteAllViews(); - return; - } - ::wxYield(); - ::wxYield(); - while (dialogProjections.isPaused()) { - ::wxYield(); - ::wxUsleep(50); - } - } - } else { - wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), rProj.nView() + 1, m_frame, wxPD_CAN_ABORT); - for (int i = 0; i < rProj.nView(); i++) { - theScanner.collectProjections (rProj, rPhantom, i, 1, true, m_iDefaultTrace); - if (! dlgProgress.Update (i+1)) { - pProjectionDoc->DeleteAllViews(); - return; - } - } - } - - std::ostringstream os; - os << "Projections for " << rPhantom.name() << ": nDet=" << m_iDefaultNDet << ", nView=" << m_iDefaultNView << ", nSamples=" << m_iDefaultNSample << ", RotAngle=" << m_dDefaultRotation << ", FocalLengthRatio=" << m_dDefaultFocalLength << ", FieldOfViewRatio=" << m_dDefaultFieldOfView << ", Geometry=" << sGeometry.c_str(); - rProj.setRemark (os.str()); - *theApp->getLog() << os.str().c_str() << "\n"; - - m_frame->Lower(); - ::wxYield(); - ProjectionFileView* projView = dynamic_cast(pProjectionDoc->GetFirstView()); - if (projView) { - projView->getFrame()->SetFocus(); - projView->OnUpdate (projView, NULL); - } - if (wxView* pView = pProjectionDoc->GetFirstView()) { - if (wxFrame* pFrame = pView->GetFrame()) { - pFrame->SetFocus(); - pFrame->Raise(); - } - theApp->getDocManager()->ActivateView (pView, true, false); - } - ::wxYield(); - pProjectionDoc->Modify(true); - pProjectionDoc->UpdateAllViews(this); - } - } + DialogGetProjectionParameters dialogProjection (m_frame, m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView, m_iDefaultGeometry, m_iDefaultTrace); + int retVal = dialogProjection.ShowModal(); + if (retVal == wxID_OK) { + m_iDefaultNDet = dialogProjection.getNDet(); + m_iDefaultNView = dialogProjection.getNView(); + m_iDefaultNSample = dialogProjection.getNSamples(); + m_iDefaultTrace = dialogProjection.getTrace(); + m_dDefaultRotation = dialogProjection.getRotAngle(); + m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio(); + m_dDefaultFieldOfView = dialogProjection.getFieldOfViewRatio(); + wxString sGeometry = dialogProjection.getGeometry(); + m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str()); + + if (m_iDefaultNDet > 0 && m_iDefaultNView > 0 && sGeometry != "") { + const Phantom& rPhantom = GetDocument()->getPhantom(); + ProjectionFileDocument* pProjectionDoc = dynamic_cast(theApp->getDocManager()->CreateDocument("untitled.pj", wxDOC_SILENT)); + if (! pProjectionDoc) { + sys_error (ERR_SEVERE, "Unable to create projection document"); + return; + } + Projections& rProj = pProjectionDoc->getProjections(); + Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView); + if (theScanner.fail()) { + *theApp->getLog() << "Failed making scanner: " << theScanner.failMessage().c_str() << "\n"; + return; + } + rProj.initFromScanner (theScanner); + m_dDefaultRotation /= PI; // convert back to PI units + + if (m_iDefaultTrace > Trace::TRACE_CONSOLE) { + ProjectionsDialog dialogProjections (theScanner, rProj, rPhantom, m_iDefaultTrace, dynamic_cast(m_frame)); + for (int iView = 0; iView < rProj.nView(); iView++) { + ::wxYield(); + ::wxYield(); + if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) { + pProjectionDoc->DeleteAllViews(); + return; + } + ::wxYield(); + ::wxYield(); + while (dialogProjections.isPaused()) { + ::wxYield(); + ::wxUsleep(50); + } + } + } else { + wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), rProj.nView() + 1, m_frame, wxPD_CAN_ABORT); + for (int i = 0; i < rProj.nView(); i++) { + theScanner.collectProjections (rProj, rPhantom, i, 1, true, m_iDefaultTrace); + if (! dlgProgress.Update (i+1)) { + pProjectionDoc->DeleteAllViews(); + return; + } + } + } + + std::ostringstream os; + os << "Projections for " << rPhantom.name() << ": nDet=" << m_iDefaultNDet << ", nView=" << m_iDefaultNView << ", nSamples=" << m_iDefaultNSample << ", RotAngle=" << m_dDefaultRotation << ", FocalLengthRatio=" << m_dDefaultFocalLength << ", FieldOfViewRatio=" << m_dDefaultFieldOfView << ", Geometry=" << sGeometry.c_str(); + rProj.setRemark (os.str()); + *theApp->getLog() << os.str().c_str() << "\n"; + + m_frame->Lower(); + ::wxYield(); + ProjectionFileView* projView = dynamic_cast(pProjectionDoc->GetFirstView()); + if (projView) { + projView->getFrame()->SetFocus(); + projView->OnUpdate (projView, NULL); + } + if (wxView* pView = pProjectionDoc->GetFirstView()) { + if (wxFrame* pFrame = pView->GetFrame()) { + pFrame->SetFocus(); + pFrame->Raise(); + } + theApp->getDocManager()->ActivateView (pView, true, false); + } + ::wxYield(); + pProjectionDoc->Modify(true); + pProjectionDoc->UpdateAllViews(this); + } + } } void PhantomView::OnRasterize (wxCommandEvent& event) { - DialogGetRasterParameters dialogRaster (m_frame, 256, 256, 1); - int retVal = dialogRaster.ShowModal(); - if (retVal == wxID_OK) { - int xSize = dialogRaster.getXSize(); - int ySize = dialogRaster.getYSize(); - int nSamples = dialogRaster.getNSamples(); - if (nSamples < 1) - nSamples = 1; - if (xSize > 0 && ySize > 0) { - const Phantom& rPhantom = GetDocument()->getPhantom(); - ImageFileDocument* pRasterDoc = dynamic_cast(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT)); - if (! pRasterDoc) { - sys_error (ERR_SEVERE, "Unable to create image file"); - return; - } - ImageFile& imageFile = pRasterDoc->getImageFile(); - - imageFile.setArraySize (xSize, ySize); - wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"), imageFile.nx() + 1, m_frame, wxPD_CAN_ABORT); - for (unsigned int i = 0; i < imageFile.nx(); i++) { - rPhantom.convertToImagefile (imageFile, nSamples, Trace::TRACE_NONE, i, 1, true); - if (! dlgProgress.Update(i+1)) { - pRasterDoc->DeleteAllViews(); - return; - } - } - pRasterDoc->Modify(true); - pRasterDoc->UpdateAllViews(this); - ImageFileView* rasterView = dynamic_cast(pRasterDoc->GetFirstView()); - if (rasterView) { - rasterView->getFrame()->SetFocus(); - rasterView->OnUpdate (rasterView, NULL); - } - - std::ostringstream os; - os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << xSize << ", YSize=" << ySize << ", nSamples=" << nSamples << "\n"; - *theApp->getLog() << os.str().c_str(); - } - } + DialogGetRasterParameters dialogRaster (m_frame, 256, 256, 1); + int retVal = dialogRaster.ShowModal(); + if (retVal == wxID_OK) { + int xSize = dialogRaster.getXSize(); + int ySize = dialogRaster.getYSize(); + int nSamples = dialogRaster.getNSamples(); + if (nSamples < 1) + nSamples = 1; + if (xSize > 0 && ySize > 0) { + const Phantom& rPhantom = GetDocument()->getPhantom(); + ImageFileDocument* pRasterDoc = dynamic_cast(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT)); + if (! pRasterDoc) { + sys_error (ERR_SEVERE, "Unable to create image file"); + return; + } + ImageFile& imageFile = pRasterDoc->getImageFile(); + + imageFile.setArraySize (xSize, ySize); + wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"), imageFile.nx() + 1, m_frame, wxPD_CAN_ABORT); + for (unsigned int i = 0; i < imageFile.nx(); i++) { + rPhantom.convertToImagefile (imageFile, nSamples, Trace::TRACE_NONE, i, 1, true); + if (! dlgProgress.Update(i+1)) { + pRasterDoc->DeleteAllViews(); + return; + } + } + pRasterDoc->Modify(true); + pRasterDoc->UpdateAllViews(this); + ImageFileView* rasterView = dynamic_cast(pRasterDoc->GetFirstView()); + if (rasterView) { + rasterView->getFrame()->SetFocus(); + rasterView->OnUpdate (rasterView, NULL); + } + + std::ostringstream os; + os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << xSize << ", YSize=" << ySize << ", nSamples=" << nSamples << "\n"; + *theApp->getLog() << os.str().c_str(); + } + } } PhantomCanvas* PhantomView::CreateCanvas (wxView *view, wxFrame *parent) { - PhantomCanvas* pCanvas; - int width, height; - parent->GetClientSize(&width, &height); - - pCanvas = new PhantomCanvas (dynamic_cast(view), parent, wxPoint(0, 0), wxSize(width, height), 0); - - pCanvas->SetBackgroundColour(*wxWHITE); - pCanvas->Clear(); - - return pCanvas; + PhantomCanvas* pCanvas; + int width, height; + parent->GetClientSize(&width, &height); + + pCanvas = new PhantomCanvas (dynamic_cast(view), parent, wxPoint(0, 0), wxSize(width, height), 0); + + pCanvas->SetBackgroundColour(*wxWHITE); + pCanvas->Clear(); + + return pCanvas; } wxFrame* PhantomView::CreateChildFrame(wxDocument *doc, wxView *view) { - wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE); - - wxMenu *file_menu = new wxMenu; - - file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom..."); - file_menu->Append(wxID_OPEN, "&Open..."); - file_menu->Append(wxID_CLOSE, "&Close"); - - file_menu->AppendSeparator(); - file_menu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties"); - - file_menu->AppendSeparator(); - file_menu->Append(wxID_PRINT, "&Print..."); - file_menu->Append(wxID_PRINT_SETUP, "Print &Setup..."); - file_menu->Append(wxID_PREVIEW, "Print Pre&view"); - - wxMenu *process_menu = new wxMenu; - process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize..."); - process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections..."); - - wxMenu *help_menu = new wxMenu; - help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents"); - help_menu->Append(MAINMENU_HELP_ABOUT, "&About"); - - wxMenuBar *menu_bar = new wxMenuBar; - - menu_bar->Append(file_menu, "&File"); - menu_bar->Append(process_menu, "&Process"); - menu_bar->Append(help_menu, "&Help"); - - subframe->SetMenuBar(menu_bar); - - subframe->Centre(wxBOTH); - - return subframe; + wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE); + + wxMenu *file_menu = new wxMenu; + + file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom..."); + file_menu->Append(wxID_OPEN, "&Open..."); + file_menu->Append(wxID_CLOSE, "&Close"); + + file_menu->AppendSeparator(); + file_menu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties"); + + file_menu->AppendSeparator(); + file_menu->Append(wxID_PRINT, "&Print..."); + file_menu->Append(wxID_PRINT_SETUP, "Print &Setup..."); + file_menu->Append(wxID_PREVIEW, "Print Pre&view"); + + wxMenu *process_menu = new wxMenu; + process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize..."); + process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections..."); + + wxMenu *help_menu = new wxMenu; + help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents"); + help_menu->Append(MAINMENU_HELP_ABOUT, "&About"); + + wxMenuBar *menu_bar = new wxMenuBar; + + menu_bar->Append(file_menu, "&File"); + menu_bar->Append(process_menu, "&Process"); + menu_bar->Append(help_menu, "&Help"); + + subframe->SetMenuBar(menu_bar); + + subframe->Centre(wxBOTH); + + return subframe; } bool PhantomView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) { - m_frame = CreateChildFrame(doc, this); - SetFrame(m_frame); - - int width, height; - m_frame->GetClientSize(&width, &height); - m_frame->SetTitle("PhantomView"); - m_canvas = CreateCanvas(this, m_frame); - + m_frame = CreateChildFrame(doc, this); + SetFrame(m_frame); + + int width, height; + m_frame->GetClientSize(&width, &height); + m_frame->SetTitle("PhantomView"); + m_canvas = CreateCanvas(this, m_frame); + #ifdef __X__ - int x, y; // X requires a forced resize - m_frame->GetSize(&x, &y); - m_frame->SetSize(-1, -1, x, y); + int x, y; // X requires a forced resize + m_frame->GetSize(&x, &y); + m_frame->SetSize(-1, -1, x, y); #endif - - m_frame->Show(true); - Activate(true); - - return true; + + m_frame->Show(true); + Activate(true); + + return true; } void PhantomView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) { - if (m_canvas) - m_canvas->Refresh(); + if (m_canvas) + m_canvas->Refresh(); } bool PhantomView::OnClose (bool deleteWindow) { - if (!GetDocument()->Close()) - return false; - - m_canvas->Clear(); - m_canvas->m_pView = NULL; - m_canvas = NULL; - wxString s(wxTheApp->GetAppName()); - if (m_frame) - m_frame->SetTitle(s); - SetFrame(NULL); - - Activate(false); - - if (deleteWindow) { - delete m_frame; - return true; - } + if (!GetDocument()->Close()) + return false; + + m_canvas->Clear(); + m_canvas->m_pView = NULL; + m_canvas = NULL; + wxString s(wxTheApp->GetAppName()); + if (m_frame) + m_frame->SetTitle(s); + SetFrame(NULL); + + Activate(false); + + if (deleteWindow) { + delete m_frame; return true; + } + return true; } void PhantomView::OnDraw (wxDC* dc) { - int xsize, ysize; - m_canvas->GetClientSize (&xsize, &ysize); - SGPDriver driver (dc, xsize, ysize); - SGP sgp (driver); - const Phantom& rPhantom = GetDocument()->getPhantom(); - sgp.setColor (C_RED); - rPhantom.show (sgp); + int xsize, ysize; + m_canvas->GetClientSize (&xsize, &ysize); + SGPDriver driver (dc, xsize, ysize); + SGP sgp (driver); + const Phantom& rPhantom = GetDocument()->getPhantom(); + sgp.setColor (C_RED); + rPhantom.show (sgp); } // ProjectionCanvas @@ -847,14 +979,14 @@ PhantomView::OnDraw (wxDC* dc) ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style) : wxScrolledWindow(frame, -1, pos, size, style) { - m_pView = v; + m_pView = v; } void ProjectionFileCanvas::OnDraw(wxDC& dc) { - if (m_pView) - m_pView->OnDraw(& dc); + if (m_pView) + m_pView->OnDraw(& dc); } // ProjectionFileView @@ -869,22 +1001,22 @@ END_EVENT_TABLE() ProjectionFileView::ProjectionFileView(void) : wxView(), m_canvas(NULL), m_frame(NULL) { - m_iDefaultNX = 256; - m_iDefaultNY = 256; - m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT; - m_dDefaultFilterParam = 1.; + m_iDefaultNX = 256; + m_iDefaultNY = 256; + m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT; + m_dDefaultFilterParam = 1.; #if HAVE_FFTW - m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW; - m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER; + m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW; + m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER; #else - m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION; - m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT; + m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION; + m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT; #endif - m_iDefaultZeropad = 1; - m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF3; - m_iDefaultInterpolation = Backprojector::INTERP_LINEAR; - m_iDefaultInterpParam = 1; - m_iDefaultTrace = Trace::TRACE_NONE; + m_iDefaultZeropad = 1; + m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF3; + m_iDefaultInterpolation = Backprojector::INTERP_LINEAR; + m_iDefaultInterpParam = 1; + m_iDefaultTrace = Trace::TRACE_NONE; } ProjectionFileView::~ProjectionFileView(void) @@ -894,279 +1026,279 @@ ProjectionFileView::~ProjectionFileView(void) void ProjectionFileView::OnProperties (wxCommandEvent& event) { - const Projections& rProj = GetDocument()->getProjections(); - std::ostringstream os; - rProj.printScanInfo(os); - *theApp->getLog() << os.str().c_str(); - wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION); - dialogMsg.ShowModal(); + const Projections& rProj = GetDocument()->getProjections(); + std::ostringstream os; + rProj.printScanInfo(os); + *theApp->getLog() << os.str().c_str(); + wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION); + dialogMsg.ShowModal(); } void ProjectionFileView::OnReconstruct (wxCommandEvent& event) { - DialogGetReconstructionParameters dialogReconstruction (m_frame, m_iDefaultNX, m_iDefaultNY, m_iDefaultFilter, m_dDefaultFilterParam, m_iDefaultFilterMethod, m_iDefaultFilterGeneration, m_iDefaultZeropad, m_iDefaultInterpolation, m_iDefaultInterpParam, m_iDefaultBackprojector, m_iDefaultTrace); - - int retVal = dialogReconstruction.ShowModal(); - if (retVal == wxID_OK) { - m_iDefaultNX = dialogReconstruction.getXSize(); - m_iDefaultNY = dialogReconstruction.getYSize(); - wxString optFilterName = dialogReconstruction.getFilterName(); - m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str()); - m_dDefaultFilterParam = dialogReconstruction.getFilterParam(); - wxString optFilterMethodName = dialogReconstruction.getFilterMethodName(); - m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str()); - m_iDefaultZeropad = dialogReconstruction.getZeropad(); - wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName(); - m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str()); - wxString optInterpName = dialogReconstruction.getInterpName(); - m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str()); - m_iDefaultInterpParam = dialogReconstruction.getInterpParam(); - wxString optBackprojectName = dialogReconstruction.getBackprojectName(); - m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str()); - m_iDefaultTrace = dialogReconstruction.getTrace(); - if (m_iDefaultNX > 0 && m_iDefaultNY > 0) { - ImageFileDocument* pReconDoc = dynamic_cast(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT)); - if (pReconDoc) { - sys_error (ERR_SEVERE, "Unable to create image file"); - return; - } - ImageFile& imageFile = pReconDoc->getImageFile(); - const Projections& rProj = GetDocument()->getProjections(); - imageFile.setArraySize (m_iDefaultNX, m_iDefaultNY); - - if (m_iDefaultFilterMethod != ProcessSignal::FILTER_METHOD_CONVOLUTION && m_iDefaultFilterGeneration == ProcessSignal::FILTER_GENERATION_DIRECT && rProj.geometry() != Scanner::GEOMETRY_PARALLEL) { - wxMessageBox ("Sorry!\nCurrently, frequency-based filtering with direct filter generation is not support for geometries other than parallel.\nAborting command.", "Not Supported", wxOK | wxICON_WARNING, m_frame); - return; - } + DialogGetReconstructionParameters dialogReconstruction (m_frame, m_iDefaultNX, m_iDefaultNY, m_iDefaultFilter, m_dDefaultFilterParam, m_iDefaultFilterMethod, m_iDefaultFilterGeneration, m_iDefaultZeropad, m_iDefaultInterpolation, m_iDefaultInterpParam, m_iDefaultBackprojector, m_iDefaultTrace); + + int retVal = dialogReconstruction.ShowModal(); + if (retVal == wxID_OK) { + m_iDefaultNX = dialogReconstruction.getXSize(); + m_iDefaultNY = dialogReconstruction.getYSize(); + wxString optFilterName = dialogReconstruction.getFilterName(); + m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str()); + m_dDefaultFilterParam = dialogReconstruction.getFilterParam(); + wxString optFilterMethodName = dialogReconstruction.getFilterMethodName(); + m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str()); + m_iDefaultZeropad = dialogReconstruction.getZeropad(); + wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName(); + m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str()); + wxString optInterpName = dialogReconstruction.getInterpName(); + m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str()); + m_iDefaultInterpParam = dialogReconstruction.getInterpParam(); + wxString optBackprojectName = dialogReconstruction.getBackprojectName(); + m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str()); + m_iDefaultTrace = dialogReconstruction.getTrace(); + if (m_iDefaultNX > 0 && m_iDefaultNY > 0) { + ImageFileDocument* pReconDoc = dynamic_cast(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT)); + if (pReconDoc) { + sys_error (ERR_SEVERE, "Unable to create image file"); + return; + } + ImageFile& imageFile = pReconDoc->getImageFile(); + const Projections& rProj = GetDocument()->getProjections(); + imageFile.setArraySize (m_iDefaultNX, m_iDefaultNY); + + if (m_iDefaultFilterMethod != ProcessSignal::FILTER_METHOD_CONVOLUTION && m_iDefaultFilterGeneration == ProcessSignal::FILTER_GENERATION_DIRECT && rProj.geometry() != Scanner::GEOMETRY_PARALLEL) { + wxMessageBox ("Sorry!\nCurrently, frequency-based filtering with direct filter generation is not support for geometries other than parallel.\nAborting command.", "Not Supported", wxOK | wxICON_WARNING, m_frame); + return; + } #if 0 - SGPDriver* pSGPDriver = NULL; - SGP* pSGP = NULL; - wxMemoryDC* pDCPlot = NULL; - wxBitmap bitmap; - if (m_iDefaultTrace >= Trace::TRACE_PLOT) { - bitmap.Create (500, 500); - pDCPlot = new wxMemoryDC; - pDCPlot->SelectObject (bitmap); - pSGPDriver = new SGPDriver (dynamic_castpDCPlot, 500, 500); - pSGP = new SGP (*pSGPDriver); - } - Reconstructor* pReconstruct = new Reconstructor (rProj, imageFile, optFilterName.c_str(), m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(), optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace, pSGP); - delete pSGP; + SGPDriver* pSGPDriver = NULL; + SGP* pSGP = NULL; + wxMemoryDC* pDCPlot = NULL; + wxBitmap bitmap; + if (m_iDefaultTrace >= Trace::TRACE_PLOT) { + bitmap.Create (500, 500); + pDCPlot = new wxMemoryDC; + pDCPlot->SelectObject (bitmap); + pSGPDriver = new SGPDriver (dynamic_castpDCPlot, 500, 500); + pSGP = new SGP (*pSGPDriver); + } + Reconstructor* pReconstruct = new Reconstructor (rProj, imageFile, optFilterName.c_str(), m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(), optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace, pSGP); + delete pSGP; #else - Reconstructor* pReconstruct = new Reconstructor (rProj, imageFile, optFilterName.c_str(), m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(), optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace); + Reconstructor* pReconstruct = new Reconstructor (rProj, imageFile, optFilterName.c_str(), m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(), optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace); #endif - - Timer timerRecon; - if (m_iDefaultTrace > Trace::TRACE_CONSOLE) { - ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstruct, rProj, imageFile, m_iDefaultTrace, m_frame); - for (int iView = 0; iView < rProj.nView(); iView++) { - ::wxYield(); - ::wxYield(); - if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView)) { - delete pDlgReconstruct; - delete pReconstruct; - pReconDoc->DeleteAllViews(); - return; - } - ::wxYield(); - ::wxYield(); - while (pDlgReconstruct->isPaused()) { - ::wxYield(); - ::wxUsleep(50); - } - } - delete pDlgReconstruct; - } else { - wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, m_frame, wxPD_CAN_ABORT); - for (int i = 0; i < rProj.nView(); i++) { - pReconstruct->reconstructView (i, 1); - if (! dlgProgress.Update(i + 1)) { - delete pReconstruct; - pReconDoc->DeleteAllViews(); - return; - } - } - } - delete pReconstruct; - pReconDoc->Modify(true); - pReconDoc->UpdateAllViews(this); - ImageFileView* rasterView = dynamic_cast(pReconDoc->GetFirstView()); - if (rasterView) { - rasterView->getFrame()->SetFocus(); - rasterView->OnUpdate (rasterView, NULL); - } - std::ostringstream os; - os << "Reconstruct " << rProj.getFilename() << ": xSize=" << m_iDefaultNX << ", ySize=" << m_iDefaultNY << ", Filter=" << optFilterName.c_str() << ", FilterParam=" << m_dDefaultFilterParam << ", FilterMethod=" << optFilterMethodName.c_str() << ", FilterGeneration=" << optFilterGenerationName.c_str() << ", Zeropad=" << m_iDefaultZeropad << ", Interpolation=" << optInterpName.c_str() << ", InterpolationParam=" << m_iDefaultInterpParam << ", Backprojection=" << optBackprojectName.c_str(); - *theApp->getLog() << os.str().c_str() << "\n"; - imageFile.labelAdd (rProj.getLabel()); - imageFile.labelAdd (Array2dFileLabel::L_HISTORY, os.str().c_str(), timerRecon.timerEnd()); - } - } + + Timer timerRecon; + if (m_iDefaultTrace > Trace::TRACE_CONSOLE) { + ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstruct, rProj, imageFile, m_iDefaultTrace, m_frame); + for (int iView = 0; iView < rProj.nView(); iView++) { + ::wxYield(); + ::wxYield(); + if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView)) { + delete pDlgReconstruct; + delete pReconstruct; + pReconDoc->DeleteAllViews(); + return; + } + ::wxYield(); + ::wxYield(); + while (pDlgReconstruct->isPaused()) { + ::wxYield(); + ::wxUsleep(50); + } + } + delete pDlgReconstruct; + } else { + wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, m_frame, wxPD_CAN_ABORT); + for (int i = 0; i < rProj.nView(); i++) { + pReconstruct->reconstructView (i, 1); + if (! dlgProgress.Update(i + 1)) { + delete pReconstruct; + pReconDoc->DeleteAllViews(); + return; + } + } + } + delete pReconstruct; + pReconDoc->Modify(true); + pReconDoc->UpdateAllViews(this); + ImageFileView* rasterView = dynamic_cast(pReconDoc->GetFirstView()); + if (rasterView) { + rasterView->getFrame()->SetFocus(); + rasterView->OnUpdate (rasterView, NULL); + } + std::ostringstream os; + os << "Reconstruct " << rProj.getFilename() << ": xSize=" << m_iDefaultNX << ", ySize=" << m_iDefaultNY << ", Filter=" << optFilterName.c_str() << ", FilterParam=" << m_dDefaultFilterParam << ", FilterMethod=" << optFilterMethodName.c_str() << ", FilterGeneration=" << optFilterGenerationName.c_str() << ", Zeropad=" << m_iDefaultZeropad << ", Interpolation=" << optInterpName.c_str() << ", InterpolationParam=" << m_iDefaultInterpParam << ", Backprojection=" << optBackprojectName.c_str(); + *theApp->getLog() << os.str().c_str() << "\n"; + imageFile.labelAdd (rProj.getLabel()); + imageFile.labelAdd (Array2dFileLabel::L_HISTORY, os.str().c_str(), timerRecon.timerEnd()); + } + } } ProjectionFileCanvas* ProjectionFileView::CreateCanvas (wxView *view, wxFrame *parent) { - ProjectionFileCanvas* pCanvas; - int width, height; - parent->GetClientSize(&width, &height); - - pCanvas = new ProjectionFileCanvas (dynamic_cast(view), parent, wxPoint(0, 0), wxSize(width, height), 0); - - pCanvas->SetScrollbars(20, 20, 50, 50); - pCanvas->SetBackgroundColour(*wxWHITE); - pCanvas->Clear(); - - return pCanvas; + ProjectionFileCanvas* pCanvas; + int width, height; + parent->GetClientSize(&width, &height); + + pCanvas = new ProjectionFileCanvas (dynamic_cast(view), parent, wxPoint(0, 0), wxSize(width, height), 0); + + pCanvas->SetScrollbars(20, 20, 50, 50); + pCanvas->SetBackgroundColour(*wxWHITE); + pCanvas->Clear(); + + return pCanvas; } wxFrame* ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view) { - wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE); - - wxMenu *file_menu = new wxMenu; - - file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom..."); - file_menu->Append(wxID_OPEN, "&Open..."); - file_menu->Append(wxID_SAVE, "&Save"); - file_menu->Append(wxID_SAVEAS, "Save &As..."); - file_menu->Append(wxID_CLOSE, "&Close"); - - file_menu->AppendSeparator(); - file_menu->Append(PJMENU_FILE_PROPERTIES, "P&roperties"); - - file_menu->AppendSeparator(); - file_menu->Append(wxID_PRINT, "&Print..."); - file_menu->Append(wxID_PRINT_SETUP, "Print &Setup..."); - file_menu->Append(wxID_PREVIEW, "Print Pre&view"); - - wxMenu *process_menu = new wxMenu; - process_menu->Append(PJMENU_PROCESS_RECONSTRUCT, "R&econstruct..."); - - wxMenu *help_menu = new wxMenu; - help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents"); - help_menu->AppendSeparator(); - help_menu->Append(MAINMENU_HELP_ABOUT, "&About"); - - wxMenuBar *menu_bar = new wxMenuBar; - - menu_bar->Append(file_menu, "&File"); - menu_bar->Append(process_menu, "&Process"); - menu_bar->Append(help_menu, "&Help"); - - subframe->SetMenuBar(menu_bar); - - subframe->Centre(wxBOTH); - - return subframe; + wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE); + + wxMenu *file_menu = new wxMenu; + + file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom..."); + file_menu->Append(wxID_OPEN, "&Open..."); + file_menu->Append(wxID_SAVE, "&Save"); + file_menu->Append(wxID_SAVEAS, "Save &As..."); + file_menu->Append(wxID_CLOSE, "&Close"); + + file_menu->AppendSeparator(); + file_menu->Append(PJMENU_FILE_PROPERTIES, "P&roperties"); + + file_menu->AppendSeparator(); + file_menu->Append(wxID_PRINT, "&Print..."); + file_menu->Append(wxID_PRINT_SETUP, "Print &Setup..."); + file_menu->Append(wxID_PREVIEW, "Print Pre&view"); + + wxMenu *process_menu = new wxMenu; + process_menu->Append(PJMENU_PROCESS_RECONSTRUCT, "R&econstruct..."); + + wxMenu *help_menu = new wxMenu; + help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents"); + help_menu->AppendSeparator(); + help_menu->Append(MAINMENU_HELP_ABOUT, "&About"); + + wxMenuBar *menu_bar = new wxMenuBar; + + menu_bar->Append(file_menu, "&File"); + menu_bar->Append(process_menu, "&Process"); + menu_bar->Append(help_menu, "&Help"); + + subframe->SetMenuBar(menu_bar); + + subframe->Centre(wxBOTH); + + return subframe; } bool ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) { - m_frame = CreateChildFrame(doc, this); - SetFrame(m_frame); - - int width, height; - m_frame->GetClientSize(&width, &height); - m_frame->SetTitle("ProjectionFileView"); - m_canvas = CreateCanvas(this, m_frame); - + m_frame = CreateChildFrame(doc, this); + SetFrame(m_frame); + + int width, height; + m_frame->GetClientSize(&width, &height); + m_frame->SetTitle("ProjectionFileView"); + m_canvas = CreateCanvas(this, m_frame); + #ifdef __X__ - int x, y; // X requires a forced resize - m_frame->GetSize(&x, &y); - m_frame->SetSize(-1, -1, x, y); + int x, y; // X requires a forced resize + m_frame->GetSize(&x, &y); + m_frame->SetSize(-1, -1, x, y); #endif - - m_frame->Show(true); - Activate(true); - - return true; + + m_frame->Show(true); + Activate(true); + + return true; } void ProjectionFileView::OnDraw (wxDC* dc) { - if (m_bitmap.Ok()) - dc->DrawBitmap (m_bitmap, 0, 0, false); + if (m_bitmap.Ok()) + dc->DrawBitmap (m_bitmap, 0, 0, false); } void ProjectionFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) { - const Projections& rProj = GetDocument()->getProjections(); - const int nDet = rProj.nDet(); - const int nView = rProj.nView(); - if (nDet != 0 && nView != 0) { - const DetectorArray& detarray = rProj.getDetectorArray(0); - const DetectorValue* detval = detarray.detValues(); - double min = detval[0]; - double max = detval[0]; - for (int iy = 0; iy < nView; iy++) { - const DetectorArray& detarray = rProj.getDetectorArray(iy); - const DetectorValue* detval = detarray.detValues(); - for (int ix = 0; ix < nDet; ix++) { - if (min > detval[ix]) - min = detval[ix]; - else if (max < detval[ix]) - max = detval[ix]; - } - } - - 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(((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_frame->SetClientSize (xSize, ySize); - m_canvas->SetScrollbars (20, 20, nDet/20, nView/20); + const Projections& rProj = GetDocument()->getProjections(); + const int nDet = rProj.nDet(); + const int nView = rProj.nView(); + if (nDet != 0 && nView != 0) { + const DetectorArray& detarray = rProj.getDetectorArray(0); + const DetectorValue* detval = detarray.detValues(); + double min = detval[0]; + double max = detval[0]; + for (int iy = 0; iy < nView; iy++) { + const DetectorArray& detarray = rProj.getDetectorArray(iy); + const DetectorValue* detval = detarray.detValues(); + for (int ix = 0; ix < nDet; ix++) { + if (min > detval[ix]) + min = detval[ix]; + else if (max < detval[ix]) + max = detval[ix]; + } + } + + 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(((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; + } } - - if (m_canvas) - m_canvas->Refresh(); + 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_frame->SetClientSize (xSize, ySize); + m_canvas->SetScrollbars (20, 20, nDet/20, nView/20); + } + + if (m_canvas) + m_canvas->Refresh(); } bool ProjectionFileView::OnClose (bool deleteWindow) { - if (!GetDocument()->Close()) - return false; - - m_canvas->Clear(); - m_canvas->m_pView = NULL; - m_canvas = NULL; - wxString s(wxTheApp->GetAppName()); - if (m_frame) - m_frame->SetTitle(s); - SetFrame(NULL); - - Activate(false); - - if (deleteWindow) { - delete m_frame; - return true; - } + if (!GetDocument()->Close()) + return false; + + m_canvas->Clear(); + m_canvas->m_pView = NULL; + m_canvas = NULL; + wxString s(wxTheApp->GetAppName()); + if (m_frame) + m_frame->SetTitle(s); + SetFrame(NULL); + + Activate(false); + + if (deleteWindow) { + delete m_frame; return true; + } + return true; } @@ -1175,14 +1307,14 @@ ProjectionFileView::OnClose (bool deleteWindow) PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style) : wxScrolledWindow(frame, -1, pos, size, style) { - m_pView = v; + m_pView = v; } void PlotFileCanvas::OnDraw(wxDC& dc) { - if (m_pView) - m_pView->OnDraw(& dc); + if (m_pView) + m_pView->OnDraw(& dc); } @@ -1208,242 +1340,242 @@ PlotFileView::~PlotFileView(void) void PlotFileView::OnProperties (wxCommandEvent& event) { - const PlotFile& rProj = GetDocument()->getPlotFile(); - std::ostringstream os; - os << "Columns: " << rProj.getNumColumns() << ", Records: " << rProj.getNumRecords() << "\n"; - *theApp->getLog() << os.str().c_str(); - wxMessageDialog dialogMsg (m_frame, os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION); - dialogMsg.ShowModal(); + const PlotFile& rProj = GetDocument()->getPlotFile(); + std::ostringstream os; + os << "Columns: " << rProj.getNumColumns() << ", Records: " << rProj.getNumRecords() << "\n"; + *theApp->getLog() << os.str().c_str(); + wxMessageDialog dialogMsg (m_frame, 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 (m_frame, 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); - } + const PlotFile& rPlotFile = GetDocument()->getPlotFile(); + double min, max, mean, mode, median, stddev; + rPlotFile.statistics (1, min, max, mean, mode, median, stddev); + DialogAutoScaleParameters dialogAutoScale (m_frame, 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, 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 (m_frame, "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); + const PlotFile& rPlotFile = GetDocument()->getPlotFile(); + double min, 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 (m_frame, "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); + } } PlotFileCanvas* PlotFileView::CreateCanvas (wxView *view, wxFrame *parent) { - PlotFileCanvas* pCanvas; - int width, height; - parent->GetClientSize(&width, &height); - - pCanvas = new PlotFileCanvas (dynamic_cast(view), parent, wxPoint(0, 0), wxSize(width, height), 0); - - pCanvas->SetBackgroundColour(*wxWHITE); - pCanvas->Clear(); - - return pCanvas; + PlotFileCanvas* pCanvas; + int width, height; + parent->GetClientSize(&width, &height); + + pCanvas = new PlotFileCanvas (dynamic_cast(view), parent, wxPoint(0, 0), wxSize(width, height), 0); + + pCanvas->SetBackgroundColour(*wxWHITE); + pCanvas->Clear(); + + return pCanvas; } wxFrame* PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view) { - wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE); - - wxMenu *file_menu = new wxMenu; - - file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom..."); - file_menu->Append(wxID_OPEN, "&Open..."); - file_menu->Append(wxID_SAVE, "&Save"); - file_menu->Append(wxID_SAVEAS, "Save &As..."); - file_menu->Append(wxID_CLOSE, "&Close"); - - file_menu->AppendSeparator(); - file_menu->Append(PJMENU_FILE_PROPERTIES, "P&roperties"); - - file_menu->AppendSeparator(); - file_menu->Append(wxID_PRINT, "&Print..."); - file_menu->Append(wxID_PRINT_SETUP, "Print &Setup..."); - file_menu->Append(wxID_PREVIEW, "Print Pre&view"); - - wxMenu *view_menu = new wxMenu; - view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set..."); - view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto..."); - - wxMenu *help_menu = new wxMenu; - help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents"); - help_menu->AppendSeparator(); - help_menu->Append(MAINMENU_HELP_ABOUT, "&About"); - - wxMenuBar *menu_bar = new wxMenuBar; - - menu_bar->Append(file_menu, "&File"); - menu_bar->Append(view_menu, "&View"); - menu_bar->Append(help_menu, "&Help"); - - subframe->SetMenuBar(menu_bar); - - subframe->Centre(wxBOTH); - - return subframe; + wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE); + + wxMenu *file_menu = new wxMenu; + + file_menu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom..."); + file_menu->Append(wxID_OPEN, "&Open..."); + file_menu->Append(wxID_SAVE, "&Save"); + file_menu->Append(wxID_SAVEAS, "Save &As..."); + file_menu->Append(wxID_CLOSE, "&Close"); + + file_menu->AppendSeparator(); + file_menu->Append(PJMENU_FILE_PROPERTIES, "P&roperties"); + + file_menu->AppendSeparator(); + file_menu->Append(wxID_PRINT, "&Print..."); + file_menu->Append(wxID_PRINT_SETUP, "Print &Setup..."); + file_menu->Append(wxID_PREVIEW, "Print Pre&view"); + + wxMenu *view_menu = new wxMenu; + view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set..."); + view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto..."); + + wxMenu *help_menu = new wxMenu; + help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents"); + help_menu->AppendSeparator(); + help_menu->Append(MAINMENU_HELP_ABOUT, "&About"); + + wxMenuBar *menu_bar = new wxMenuBar; + + menu_bar->Append(file_menu, "&File"); + menu_bar->Append(view_menu, "&View"); + menu_bar->Append(help_menu, "&Help"); + + subframe->SetMenuBar(menu_bar); + + subframe->Centre(wxBOTH); + + return subframe; } bool PlotFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) ) { - m_frame = CreateChildFrame(doc, this); - SetFrame(m_frame); - - m_bMinSpecified = false; - m_bMaxSpecified = false; - m_dAutoScaleFactor = 1.; - - int width, height; - m_frame->GetClientSize(&width, &height); - m_frame->SetTitle ("Plot File"); - m_canvas = CreateCanvas (this, m_frame); - + m_frame = CreateChildFrame(doc, this); + SetFrame(m_frame); + + m_bMinSpecified = false; + m_bMaxSpecified = false; + m_dAutoScaleFactor = 1.; + + int width, height; + m_frame->GetClientSize(&width, &height); + m_frame->SetTitle ("Plot File"); + m_canvas = CreateCanvas (this, m_frame); + #ifdef __X__ - int x, y; // X requires a forced resize - m_frame->GetSize(&x, &y); - m_frame->SetSize(-1, -1, x, y); + int x, y; // X requires a forced resize + m_frame->GetSize(&x, &y); + m_frame->SetSize(-1, -1, x, y); #endif - - m_frame->Show(true); - Activate(true); - - return true; + + m_frame->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_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(); - } + const PlotFile& rPlotFile = GetDocument()->getPlotFile(); + const int iNColumns = rPlotFile.getNumColumns(); + const int iNRecords = rPlotFile.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 (! 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(); + } } void PlotFileView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) ) { - if (m_canvas) - m_canvas->Refresh(); + if (m_canvas) + m_canvas->Refresh(); } bool PlotFileView::OnClose (bool deleteWindow) { - if (!GetDocument()->Close()) - return false; - - m_canvas->Clear(); - m_canvas->m_pView = NULL; - m_canvas = NULL; - wxString s(wxTheApp->GetAppName()); - if (m_frame) - m_frame->SetTitle(s); - SetFrame(NULL); - - Activate(false); - - if (deleteWindow) { - delete m_frame; - return true; - } + if (!GetDocument()->Close()) + return false; + + m_canvas->Clear(); + m_canvas->m_pView = NULL; + m_canvas = NULL; + wxString s(wxTheApp->GetAppName()); + if (m_frame) + m_frame->SetTitle(s); + SetFrame(NULL); + + Activate(false); + + if (deleteWindow) { + delete m_frame; return true; + } + return true; } diff --git a/src/views.h b/src/views.h index d06ffa3..1457e84 100644 --- a/src/views.h +++ b/src/views.h @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: views.h,v 1.15 2000/12/21 03:40:58 kevin Exp $ +** $Id: views.h,v 1.16 2000/12/22 04:18:00 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 @@ -68,8 +68,10 @@ public: void OnCompare (wxCommandEvent& event); void OnScaleAuto (wxCommandEvent& event); void OnScaleMinMax (wxCommandEvent& event); - void OnPlotRow (wxCommandEvent& event); - void OnPlotCol (wxCommandEvent& event); + void OnPlotRow (wxCommandEvent& event); + void OnPlotCol (wxCommandEvent& event); + void OnCompareRow (wxCommandEvent& event); + void OnCompareCol (wxCommandEvent& event); wxFrame* getFrame() { return m_frame; } diff --git a/tools/if2.cpp b/tools/if2.cpp index db92c22..c49b5a4 100644 --- a/tools/if2.cpp +++ b/tools/if2.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: if2.cpp,v 1.3 2000/12/19 21:37:51 kevin Exp $ +** $Id: if2.cpp,v 1.4 2000/12/22 04:18:00 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 @@ -29,13 +29,14 @@ #include "ct.h" #include "timer.h" -enum {O_ADD, O_SUB, O_MUL, O_COMP, O_ROW_PLOT, O_COLUMN_PLOT, O_VERBOSE, O_HELP, O_VERSION}; +enum {O_ADD, O_SUB, O_MUL, O_DIVIDE, O_COMP, O_ROW_PLOT, O_COLUMN_PLOT, O_VERBOSE, O_HELP, O_VERSION}; static struct option my_options[] = { {"add", 0, 0, O_ADD}, {"sub", 0, 0, O_SUB}, - {"mul", 0, 0, O_MUL}, + {"multiply", 0, 0, O_MUL}, + {"divide", 0, 0, O_DIVIDE}, {"comp", 0, 0, O_COMP}, {"column-plot", 1, 0, O_COLUMN_PLOT}, {"row-plot", 1, 0, O_ROW_PLOT}, @@ -45,7 +46,7 @@ static struct option my_options[] = {0, 0, 0, 0} }; -static const char* g_szIdStr = "$Id: if2.cpp,v 1.3 2000/12/19 21:37:51 kevin Exp $"; +static const char* g_szIdStr = "$Id: if2.cpp,v 1.4 2000/12/22 04:18:00 kevin Exp $"; void if2_usage (const char *program) @@ -79,21 +80,22 @@ if2_main (int argc, char *const argv[]) int opt_verbose = 0; int opt_add = 0; int opt_sub = 0; - int opt_mul = 0; + int opt_mul = 0; + bool opt_divide = false; int opt_comp = 0; bool opt_bImageOutputFile = false; bool opt_bPlotOutputFile = false; int opt_rowPlot = -1; int opt_columnPlot = -1; Timer timerProgram; - + while (1) { char* endptr; int c = getopt_long (argc, argv, "", my_options, NULL); - + if (c == -1) break; - + switch (c) { case O_ADD: opt_add = 1; @@ -103,21 +105,25 @@ if2_main (int argc, char *const argv[]) opt_sub = 1; opt_bImageOutputFile = true; break; - case O_MUL: - opt_mul = 1; - opt_bImageOutputFile = true; - break; + case O_MUL: + opt_mul = 1; + opt_bImageOutputFile = true; + break; + case O_DIVIDE: + opt_divide = true; + opt_bImageOutputFile = true; + break; case O_ROW_PLOT: opt_rowPlot = strtol(optarg, &endptr, 10); if (endptr != optarg + strlen(optarg)) { - if2_usage(argv[0]); + if2_usage(argv[0]); } opt_bPlotOutputFile = true; break; case O_COLUMN_PLOT: opt_columnPlot = strtol(optarg, &endptr, 10); if (endptr != optarg + strlen(optarg)) { - if2_usage(argv[0]); + if2_usage(argv[0]); } opt_bPlotOutputFile = true; break; @@ -143,7 +149,7 @@ if2_main (int argc, char *const argv[]) return (1); } } - + if ((opt_bImageOutputFile || opt_bPlotOutputFile) && (optind + 3 != argc)) { if2_usage(argv[0]); return (1); @@ -157,31 +163,31 @@ if2_main (int argc, char *const argv[]) in_file2 = argv[optind + 1]; if (opt_bImageOutputFile || opt_bPlotOutputFile) strOutFile = argv[optind + 2]; - + pim_in1 = new ImageFile (); pim_in2 = new ImageFile (); ImageFile& im_in1 = *pim_in1; ImageFile& im_in2 = *pim_in2; - + if (! im_in1.fileRead(in_file1) || ! im_in2.fileRead(in_file2)) { - sys_error (ERR_WARNING, "Error reading an image"); - return (1); + sys_error (ERR_WARNING, "Error reading an image"); + return (1); } - + if (im_in1.nx() != im_in2.nx() || im_in1.ny() != im_in2.ny()) { sys_error (ERR_SEVERE, "Error: Size of image 1 (%d,%d) and image 2 (%d,%d) do not match", - im_in1.nx(), im_in1.ny(), im_in2.nx(), im_in2.ny()); + im_in1.nx(), im_in1.ny(), im_in2.nx(), im_in2.ny()); return(1); } if (im_in1.nx() < 0 || im_in1.ny() < 0) { - sys_error (ERR_SEVERE, "Error: Size of image < 0"); - return(1); + sys_error (ERR_SEVERE, "Error: Size of image < 0"); + return(1); } - + ImageFileArray v1 = im_in1.getArray(); ImageFileArray v2 = im_in2.getArray(); ImageFileArray vout = NULL; - + if (opt_bImageOutputFile && opt_bPlotOutputFile) { sys_error (ERR_SEVERE, "Both Image and Plot output files can not be selected simultaneously"); return (1); @@ -190,47 +196,32 @@ if2_main (int argc, char *const argv[]) pim_out = new ImageFile (im_in1.nx(), im_in1.ny()); vout = pim_out->getArray(); } - + std::string strOperation; int nx = im_in1.nx(); int ny = im_in1.ny(); int nx2 = im_in2.nx(); int ny2 = im_in2.ny(); - + if (opt_add) { strOperation = "Add Images"; - for (int ix = 0; ix < nx; ix++) { - ImageFileColumn in1 = v1[ix]; - ImageFileColumn in2 = v2[ix]; - ImageFileColumn out = vout[ix]; - for (int iy = 0; iy < ny; iy++) - *out++ = *in1++ + *in2++; - } + im_in1.addImages (im_in2, *pim_out); } else if (opt_sub) { - strOperation = "Subtract Images"; - for (int ix = 0; ix < nx; ix++) { - ImageFileColumn in1 = v1[ix]; - ImageFileColumn in2 = v2[ix]; - ImageFileColumn out = vout[ix]; - for (int iy = 0; iy < ny; iy++) - *out++ = *in1++ - *in2++; - } - } else if (opt_mul) { - strOperation = "Multiply Images"; - for (int ix = 0; ix < nx; ix++) { - ImageFileColumn in1 = v1[ix]; - ImageFileColumn in2 = v2[ix]; - ImageFileColumn out = vout[ix]; - for (int iy = 0; iy < ny; iy++) - *out++ = *in1++ * *in2++; - } - } + strOperation = "Subtract Images"; + im_in1.subtractImages (im_in2, *pim_out); + } else if (opt_mul) { + strOperation = "Multiply Images"; + im_in1.multiplyImages (im_in2, *pim_out); + } else if (opt_divide) { + strOperation = "Divide Images"; + im_in1.divideImages (im_in2, *pim_out); + } if (opt_comp) { double d, r, e; im_in1.comparativeStatistics (im_in2, d, r, e); std::cout << "d=" << d << ", r=" << r << ", e=" << e << std::endl; } - + int i; if (opt_columnPlot > 0) { if (opt_columnPlot >= nx || opt_columnPlot >= nx2) { @@ -240,18 +231,18 @@ if2_main (int argc, char *const argv[]) double* plot_xaxis = new double [nx]; for (i = 0; i < nx; i++) plot_xaxis[i] = i; - + PlotFile plotFile (3, nx); - + plotFile.addColumn (0, plot_xaxis); plotFile.addColumn (1, v1[opt_columnPlot]); plotFile.addColumn (2, v2[opt_columnPlot]); plotFile.setTitle ("Column Plot"); plotFile.setXLabel ("Column"); plotFile.setYLabel ("Pixel Value"); - + plotFile.fileWrite (strOutFile.c_str()); - + #if HAVE_SGP SGPDriver driver ("Column Plot"); SGP sgp (driver); @@ -271,7 +262,7 @@ if2_main (int argc, char *const argv[]) #endif delete plot_xaxis; } - + if (opt_rowPlot > 0) { if (opt_rowPlot >= ny || opt_rowPlot >= ny2) { sys_error (ERR_SEVERE, "row_plot > ny"); @@ -279,26 +270,26 @@ if2_main (int argc, char *const argv[]) } double* plot_xaxis = new double [ny]; double* v1Row = new double [ny]; - double* v2Row = new double [ny2]; - + double* v2Row = new double [ny2]; + for (i = 0; i < ny; i++) plot_xaxis[i] = i; for (i = 0; i < ny; i++) v1Row[i] = v1[i][opt_rowPlot]; for (i = 0; i < ny2; i++) v2Row[i] = v2[i][opt_rowPlot]; - + PlotFile plotFile (3, ny); - + plotFile.addColumn (0, plot_xaxis); plotFile.addColumn (1, v1Row); plotFile.addColumn (2, v2Row); plotFile.setTitle ("Row Plot"); plotFile.setXLabel ("Row"); plotFile.setYLabel ("Pixel Value"); - + plotFile.fileWrite (strOutFile.c_str()); - + #if HAVE_SGP SGPDriver driver ("Row Plot"); SGP sgp (driver); @@ -316,18 +307,18 @@ if2_main (int argc, char *const argv[]) std::cout << "Press enter to continue" << flush; cio_kb_getc(); #endif - delete plot_xaxis; - delete v1Row; - delete v2Row; + delete plot_xaxis; + delete v1Row; + delete v2Row; } - + if (opt_bImageOutputFile) { pim_out->labelsCopy (im_in1, "if2 file 1: "); pim_out->labelsCopy (im_in2, "if2 file 2: "); pim_out->labelAdd (Array2dFileLabel::L_HISTORY, strOperation.c_str(), timerProgram.timerEnd()); pim_out->fileWrite (strOutFile); } - + return (0); } @@ -336,7 +327,7 @@ int main (int argc, char *const argv[]) { int retval = 1; - + try { retval = if2_main(argc, argv); } catch (exception e) { @@ -344,7 +335,7 @@ main (int argc, char *const argv[]) } catch (...) { std::cerr << "Unknown exception\n"; } - + return (retval); } #endif