X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=src%2Fdialogs.cpp;h=ef5ece20e72863c30e08a454e1f65b14c5d14bc7;hp=27b454f0ff857dabbca266e00399557414ed7814;hb=1e88cf0f7fa4f690ea9f110e8ed3f2b5338d0a10;hpb=27a474e0622ebb7229fd5705552021f63d8f932d diff --git a/src/dialogs.cpp b/src/dialogs.cpp index 27b454f..ef5ece2 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.4 2000/07/20 11:17:31 kevin Exp $ +** $Id: dialogs.cpp,v 1.9 2000/08/25 15:59:13 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 @@ -49,44 +49,44 @@ #include "dialogs.h" #include #include "ctsupport.h" +#include "ctsim.h" #include "scanner.h" #include "phantom.h" #include "filter.h" #include "backprojectors.h" +StringValueAndTitleListBox::StringValueAndTitleListBox (wxDialog* pParent, int nChoices, const char* aszTitle[], const char* aszValue[]) + : wxListBox () +{ + wxString asTitle[nChoices]; + for (int i = 0; i < nChoices; i++) + asTitle[i] = aszTitle[i]; -const wxString DialogGetPhantom::s_asPhantom[] = -{ - wxString(Phantom::PHM_HERMAN_STR), - wxString(Phantom::PHM_BHERMAN_STR), - wxString(Phantom::PHM_ROWLAND_STR), - wxString(Phantom::PHM_BROWLAND_STR), - wxString(Phantom::PHM_UNITPULSE_STR), -}; -const wxString DialogGetPhantom::s_asPhantomTitle[] = -{ - wxString(Phantom::PHM_HERMAN_TITLE_STR), - wxString(Phantom::PHM_BHERMAN_TITLE_STR), - wxString(Phantom::PHM_ROWLAND_TITLE_STR), - wxString(Phantom::PHM_BROWLAND_TITLE_STR), - wxString(Phantom::PHM_UNITPULSE_TITLE_STR), + Create (pParent, -1, wxDefaultPosition, wxDefaultSize, nChoices, asTitle, wxLB_SINGLE | wxLB_NEEDED_SB); + + m_ppszValues = aszValue; }; -const unsigned int DialogGetPhantom::s_iNumPhantom = sizeof(s_asPhantom) / sizeof(wxString); + +const char* +StringValueAndTitleListBox::getSelectionStringValue (void) const +{ + return m_ppszValues[GetSelection()]; +} + -DialogGetPhantom::DialogGetPhantom (wxFrame* pParent, const char* szDefaultPhantom = NULL) +DialogGetPhantom::DialogGetPhantom (wxFrame* pParent, int iDefaultPhantom = Phantom::PHM_HERMAN) : wxDialog (pParent, -1, "Select Phantom", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION) { - m_sDefaultPhantom = szDefaultPhantom; - wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL); pTopSizer->Add (new wxStaticText (this, -1, "Select Phantom"), 0, wxALIGN_CENTER | wxTOP | wxLEFT | wxRIGHT, 5); pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); - m_pListBoxPhantom = new wxListBox (this, -1, wxDefaultPosition, wxDefaultSize, s_iNumPhantom, s_asPhantomTitle, wxLB_SINGLE | wxLB_NEEDED_SB); + m_pListBoxPhantom = new StringValueAndTitleListBox (this, Phantom::getPhantomCount(), Phantom::getPhantomTitleArray(), Phantom::getPhantomNameArray()); + m_pListBoxPhantom->SetSelection (iDefaultPhantom); pTopSizer->Add (m_pListBoxPhantom, 0, wxALL | wxALIGN_CENTER | wxEXPAND); pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); @@ -105,14 +105,10 @@ DialogGetPhantom::DialogGetPhantom (wxFrame* pParent, const char* szDefaultPhant pTopSizer->SetSizeHints (this); } -const wxString& +const char* DialogGetPhantom::getPhantom(void) { - int selection = m_pListBoxPhantom->GetSelection(); - if (selection >= 0) - return (s_asPhantom[selection]); - - return (m_sDefaultPhantom); + return m_pListBoxPhantom->getSelectionStringValue(); } @@ -283,31 +279,25 @@ DialogGetRasterParameters::getNSamples (void) // DialogGetProjectionParameters ///////////////////////////////////////////////////////////////////// -const wxString DialogGetProjectionParameters::s_asGeometry[] = -{ - wxString(Scanner::GEOMETRY_PARALLEL_STR), - wxString(Scanner::GEOMETRY_EQUILINEAR_STR), - wxString(Scanner::GEOMETRY_EQUIANGULAR_STR), -}; -const wxString DialogGetProjectionParameters::s_asGeometryTitle[] = -{ - wxString(Scanner::GEOMETRY_PARALLEL_TITLE_STR), - wxString(Scanner::GEOMETRY_EQUILINEAR_TITLE_STR), - wxString(Scanner::GEOMETRY_EQUIANGULAR_TITLE_STR), -}; -const unsigned int DialogGetProjectionParameters::s_iNumGeometry = sizeof(s_asGeometry) / sizeof(wxString); - -DialogGetProjectionParameters::DialogGetProjectionParameters (wxFrame* pParent, int iDefaultNDet = 0, int iDefaultNView = 0, int iDefaultNSamples = 1, double dDefaultRotAngle = 1., const char* szDefaultGeometry = NULL) - : wxDialog (pParent, -1, "Set Projection Parameters", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION) +DialogGetProjectionParameters::DialogGetProjectionParameters (wxFrame* pParent, int iDefaultNDet = 0, int iDefaultNView = 0, int iDefaultNSamples = 1, double dDefaultRotAngle = 1., double dDefaultFocalLength = 1, double dDefaultFieldOfView = 1., int iDefaultGeometry = Scanner::GEOMETRY_PARALLEL) + : wxDialog (pParent, -1, "Set Projection Parameters", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION) { wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL); + m_dDefaultRotAngle = dDefaultRotAngle; + m_dDefaultFocalLength = dDefaultFocalLength; + m_dDefaultFieldOfView = dDefaultFieldOfView; + m_iDefaultNSamples = iDefaultNSamples; + m_iDefaultNView = iDefaultNView; + m_iDefaultNDet = iDefaultNDet; + pTopSizer->Add (new wxStaticText (this, -1, "Set Projection Parameters"), 0, wxALIGN_CENTER | wxTOP | wxLEFT | wxRIGHT, 5); pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); - m_pListBoxGeometry = new wxListBox (this, -1, wxDefaultPosition, wxDefaultSize, s_iNumGeometry, s_asGeometryTitle, wxLB_SINGLE | wxLB_NEEDED_SB); + m_pListBoxGeometry = new StringValueAndTitleListBox (this, Scanner::getGeometryCount(), Scanner::getGeometryTitleArray(), Scanner::getGeometryNameArray()); + m_pListBoxGeometry->SetSelection (iDefaultGeometry); pTopSizer->Add (m_pListBoxGeometry, 0, wxALL | wxALIGN_CENTER | wxEXPAND); ostringstream os; @@ -322,6 +312,12 @@ DialogGetProjectionParameters::DialogGetProjectionParameters (wxFrame* pParent, ostringstream osRotAngle; osRotAngle << dDefaultRotAngle; m_pTextCtrlRotAngle = new wxTextCtrl (this, -1, osRotAngle.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0); + ostringstream osFocalLength; + osFocalLength << dDefaultFocalLength; + m_pTextCtrlFocalLength = new wxTextCtrl (this, -1, osFocalLength.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0); + ostringstream osFieldOfView; + osFieldOfView << dDefaultFieldOfView; + m_pTextCtrlFieldOfView = new wxTextCtrl (this, -1, osFieldOfView.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0); wxGridSizer *pGridSizer = new wxGridSizer (2, 4, 5); pGridSizer->Add (new wxStaticText (this, -1, "Detectors"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); @@ -332,8 +328,11 @@ DialogGetProjectionParameters::DialogGetProjectionParameters (wxFrame* pParent, pGridSizer->Add (m_pTextCtrlNSamples, 0, wxALIGN_CENTER_VERTICAL); pGridSizer->Add (new wxStaticText (this, -1, "Rotation Angle (PI units)"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); pGridSizer->Add (m_pTextCtrlRotAngle, 0, wxALIGN_CENTER_VERTICAL); + pGridSizer->Add (new wxStaticText (this, -1, "Focal Length Ratio (phantom radius units)"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + pGridSizer->Add (m_pTextCtrlFocalLength, 0, wxALIGN_CENTER_VERTICAL); + pGridSizer->Add (new wxStaticText (this, -1, "Field of View (phantom diameter units)"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + pGridSizer->Add (m_pTextCtrlFieldOfView, 0, wxALIGN_CENTER_VERTICAL); pTopSizer->Add (pGridSizer, 1, wxALL, 10); - m_sDefaultGeometry = szDefaultGeometry; pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); @@ -401,14 +400,32 @@ DialogGetProjectionParameters::getRotAngle (void) return (m_dDefaultRotAngle); } -const wxString& -DialogGetProjectionParameters::getGeometry (void) +double +DialogGetProjectionParameters::getFocalLengthRatio (void) { - int selection = m_pListBoxGeometry->GetSelection(); - if (selection >= 0) - return (s_asGeometry[selection]); + wxString strCtrl = m_pTextCtrlFocalLength->GetValue(); + double dValue; + if (strCtrl.ToDouble (&dValue)) + return (dValue); + else + return (m_dDefaultFocalLength); +} + +double +DialogGetProjectionParameters::getFieldOfViewRatio (void) +{ + wxString strCtrl = m_pTextCtrlFieldOfView->GetValue(); + double dValue; + if (strCtrl.ToDouble (&dValue)) + return (dValue); + else + return (m_dDefaultFieldOfView); +} - return m_sDefaultGeometry; +const char* +DialogGetProjectionParameters::getGeometry (void) +{ + return m_pListBoxGeometry->getSelectionStringValue(); } @@ -419,33 +436,8 @@ DialogGetProjectionParameters::getGeometry (void) // DialogGetReconstructionParameters ///////////////////////////////////////////////////////////////////// -const wxString DialogGetReconstructionParameters::s_asFilter[] = -{ - wxString(SignalFilter::FILTER_ABS_BANDLIMIT_STR), - wxString(SignalFilter::FILTER_SHEPP_STR), -}; -const wxString DialogGetReconstructionParameters::s_asFilterTitle[] = -{ - wxString(SignalFilter::FILTER_ABS_BANDLIMIT_TITLE_STR), - wxString(SignalFilter::FILTER_SHEPP_TITLE_STR), -}; -const unsigned int DialogGetReconstructionParameters::s_iNumFilter = sizeof(s_asFilter) / sizeof(wxString); - -const wxString DialogGetReconstructionParameters::s_asInterp[] = -{ - wxString(Backprojector::INTERP_NEAREST_STR), - wxString(Backprojector::INTERP_LINEAR_STR), -}; -const wxString DialogGetReconstructionParameters::s_asInterpTitle[] = -{ - wxString(Backprojector::INTERP_NEAREST_TITLE_STR), - wxString(Backprojector::INTERP_LINEAR_TITLE_STR), - }; -const unsigned int DialogGetReconstructionParameters::s_iNumInterp = sizeof(s_asInterp) / sizeof(wxString); - - -DialogGetReconstructionParameters::DialogGetReconstructionParameters (wxFrame* pParent, int iDefaultXSize = 0, int iDefaultYSize = 0, const char* szDefaultFilterName = NULL, double dDefaultFilterParam = 1., const char* szDefaultFilterMethodName = NULL, int iDefaultZeropad = 3, const char* szDefaultInterpName = NULL, int iDefaultInterpParam = 1, const char* szDefaultBackprojName = NULL) +DialogGetReconstructionParameters::DialogGetReconstructionParameters (wxFrame* pParent, int iDefaultXSize = 0, int iDefaultYSize = 0, int iDefaultFilterID = SignalFilter::FILTER_ABS_BANDLIMIT, double dDefaultFilterParam = 1., int iDefaultFilterMethodID = ProcessSignal::FILTER_METHOD_CONVOLUTION, int iDefaultFilterGenerationID = ProcessSignal::FILTER_GENERATION_INVALID, int iDefaultZeropad = 3, int iDefaultInterpID = Backprojector::INTERP_LINEAR, int iDefaultInterpParam = 1, int iDefaultBackprojectID = Backprojector::BPROJ_IDIFF3) : wxDialog (pParent, -1, "Set Reconstruction Parameters", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION) { wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL); @@ -454,10 +446,23 @@ DialogGetReconstructionParameters::DialogGetReconstructionParameters (wxFrame* p pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); - m_pListBoxFilter = new wxListBox (this, -1, wxDefaultPosition, wxDefaultSize, s_iNumFilter, s_asFilterTitle, wxLB_SINGLE | wxLB_NEEDED_SB); + m_pListBoxFilter = new StringValueAndTitleListBox (this, SignalFilter::getFilterCount(), SignalFilter::getFilterTitleArray(), SignalFilter::getFilterNameArray()); + m_pListBoxFilter->SetSelection (iDefaultFilterID); pTopSizer->Add (m_pListBoxFilter, 0, wxALL | wxALIGN_CENTER | wxEXPAND); - m_pListBoxInterp = new wxListBox (this, -1, wxDefaultPosition, wxDefaultSize, s_iNumInterp, s_asInterpTitle, wxLB_SINGLE | wxLB_NEEDED_SB); + m_pListBoxFilterMethod = new StringValueAndTitleListBox (this, ProcessSignal::getFilterMethodCount(), ProcessSignal::getFilterMethodTitleArray(), ProcessSignal::getFilterMethodNameArray()); + m_pListBoxFilterMethod->SetSelection (iDefaultFilterMethodID); + pTopSizer->Add (m_pListBoxFilterMethod, 0, wxALL | wxALIGN_CENTER | wxEXPAND); + m_pListBoxFilterGeneration = new StringValueAndTitleListBox (this, ProcessSignal::getFilterGenerationCount(), ProcessSignal::getFilterGenerationTitleArray(), ProcessSignal::getFilterGenerationNameArray()); + m_pListBoxFilterGeneration->SetSelection (iDefaultFilterGenerationID); + pTopSizer->Add (m_pListBoxFilterGeneration, 0, wxALL | wxALIGN_CENTER | wxEXPAND); + + m_pListBoxBackproject = new StringValueAndTitleListBox (this, Backprojector::getBackprojectCount(), Backprojector::getBackprojectTitleArray(), Backprojector::getBackprojectNameArray()); + m_pListBoxBackproject->SetSelection (iDefaultBackprojectID); + pTopSizer->Add (m_pListBoxBackproject, 0, wxALL | wxALIGN_CENTER | wxEXPAND); + + m_pListBoxInterp = new StringValueAndTitleListBox (this, Backprojector::getInterpCount(), Backprojector::getInterpTitleArray(), Backprojector::getInterpNameArray()); + m_pListBoxInterp->SetSelection (iDefaultInterpID); pTopSizer->Add (m_pListBoxInterp, 0, wxALL | wxALIGN_CENTER | wxEXPAND); ostringstream os; @@ -489,11 +494,6 @@ DialogGetReconstructionParameters::DialogGetReconstructionParameters (wxFrame* p pGridSizer->Add (m_pTextCtrlInterpParam, 0, wxALIGN_CENTER_VERTICAL); pTopSizer->Add (pGridSizer, 1, wxALL, 10); - m_sDefaultFilterName = szDefaultFilterName; - m_sDefaultFilterMethodName = szDefaultFilterMethodName; - m_sDefaultInterpName = szDefaultInterpName; - m_sDefaultBackprojName = szDefaultBackprojName; - pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL); @@ -571,34 +571,98 @@ DialogGetReconstructionParameters::getFilterParam (void) return (m_dDefaultFilterParam); } -const wxString& +const char* DialogGetReconstructionParameters::getFilterName (void) { - int selection = m_pListBoxFilter->GetSelection(); - if (selection >= 0) - return (s_asFilter[selection]); - - return m_sDefaultFilterName; + return m_pListBoxFilter->getSelectionStringValue(); } -const wxString& +const char* DialogGetReconstructionParameters::getFilterMethodName (void) { - return m_sDefaultFilterMethodName; + return m_pListBoxFilterMethod->getSelectionStringValue(); } -const wxString& +const char* DialogGetReconstructionParameters::getInterpName (void) { - int selection = m_pListBoxInterp->GetSelection(); - if (selection >= 0) - return (s_asInterp[selection]); + return m_pListBoxInterp->getSelectionStringValue(); +} + +const char* +DialogGetReconstructionParameters::getBackprojectName (void) +{ + return m_pListBoxBackproject->getSelectionStringValue(); +} + +const char* +DialogGetReconstructionParameters::getFilterGenerationName (void) +{ + return m_pListBoxFilterGeneration->getSelectionStringValue(); +} + + +DialogAutoScaleParameters::DialogAutoScaleParameters (wxFrame *pParent, const ImageFile& rIF) + : wxDialog (pParent, -1, "Auto Scale Parameters", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION), m_rImageFile(rIF) +{ + wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL); + + pTopSizer->Add (new wxStaticText (this, -1, "Auto Scale Parameters"), 0, wxALIGN_CENTER | wxTOP | wxLEFT | wxRIGHT, 5); + + pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5); + + wxString asTitle[3]; + asTitle[0] = "Median"; + asTitle[1] = "Mode"; + asTitle[2] = "Mean"; - return m_sDefaultInterpName; + m_pListBoxCenter = new wxListBox (this, -1, wxDefaultPosition, wxDefaultSize, 3, asTitle, wxLB_SINGLE | wxLB_NEEDED_SB); + m_pListBoxCenter->SetSelection (0); + pTopSizer->Add (m_pListBoxCenter, 0, wxALL | wxALIGN_CENTER | wxEXPAND); + + wxGridSizer *pGridSizer = new wxGridSizer (2, 2, 5); + pGridSizer->Add (new wxStaticText (this, -1, "Standard Deviation Factor"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL); + m_pTextCtrlStdDevFactor = new wxTextCtrl (this, -1, "1.0", wxDefaultPosition, wxSize(100, 25), 0); + pGridSizer->Add (m_pTextCtrlStdDevFactor, 0, wxALIGN_CENTER_VERTICAL); + pTopSizer->Add (pGridSizer, 1, wxALL, 10); + + 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); } -const wxString& -DialogGetReconstructionParameters::getBackprojName (void) +void +DialogAutoScaleParameters::getMinMax (double* pMin, double* pMax) { - return m_sDefaultBackprojName; + int iCenter = m_pListBoxCenter->GetSelection(); + double min, max, mean, mode, median, stddev; + m_rImageFile.statistics (min, max, mean, mode, median, stddev); + double dCenter = median; + if (iCenter == 1) + dCenter = mode; + else if (iCenter == 2) + dCenter = mean; + + wxString sStddevFactor = m_pTextCtrlStdDevFactor->GetValue(); + double dValue; + if (! sStddevFactor.ToDouble (&dValue)) { + *theApp->getLog() << "Error: Non-numeric Standard Deviation Factor of " << sStddevFactor << "\n"; + *pMin = min; + *pMax = max; + } + double dHalfWidth = dValue * stddev / 2; + *pMin = dCenter - dHalfWidth; + *pMax = dCenter + dHalfWidth; + *theApp->getLog() << "Setting minimum to " << *pMin << " and maximum to " << *pMax << "\n"; }