r268: Improved reconstruction dilog
[ctsim.git] / src / dialogs.cpp
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          dialogs.cpp
5 **   Purpose:       Dialog routines for CTSim program
6 **   Programmer:    Kevin Rosenberg
7 **   Date Started:  July 2000
8 **
9 **  This is part of the CTSim program
10 **  Copyright (C) 1983-2000 Kevin Rosenberg
11 **
12 **  $Id: dialogs.cpp,v 1.16 2000/12/17 19:07:46 kevin Exp $
13 **
14 **  This program is free software; you can redistribute it and/or modify
15 **  it under the terms of the GNU General Public License (version 2) as
16 **  published by the Free Software Foundation.
17 **
18 **  This program is distributed in the hope that it will be useful,
19 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 **  GNU General Public License for more details.
22 **
23 **  You should have received a copy of the GNU General Public License
24 **  along with this program; if not, write to the Free Software
25 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 ******************************************************************************/
27
28 #ifdef __GNUG__
29 // #pragma implementation
30 #endif
31
32 // For compilers that support precompilation, includes "wx/wx.h".
33 #include "wx/wxprec.h"
34
35 #ifdef __BORLANDC__
36 #pragma hdrstop
37 #endif
38
39 #ifndef WX_PRECOMP
40 #include "wx/wx.h"
41 #endif
42
43 #if !wxUSE_DOC_VIEW_ARCHITECTURE
44 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
45 #endif
46
47 #include "wx/statline.h"
48 #include "wx/sizer.h"
49 #include "dialogs.h"
50 #include <sstream>
51 #include "ctsupport.h"
52 #include "ctsim.h"
53 #include "scanner.h"
54 #include "phantom.h"
55 #include "filter.h"
56 #include "backprojectors.h"
57
58
59 StringValueAndTitleListBox::StringValueAndTitleListBox (wxDialog* pParent, int nChoices, const char* aszTitle[], const char* aszValue[])
60   : wxListBox ()
61 {
62     wxString* psTitle = new wxString [nChoices];
63     for (int i = 0; i < nChoices; i++)
64         psTitle[i] = aszTitle[i];
65
66     Create (pParent, -1, wxDefaultPosition, wxSize(200,-1), nChoices, psTitle, wxLB_SINGLE | wxLB_NEEDED_SB);
67
68     m_ppszValues = aszValue;\r
69         delete [] psTitle;
70 };
71
72 const char*
73 StringValueAndTitleListBox::getSelectionStringValue (void) const
74 {
75   return m_ppszValues[GetSelection()];
76 }
77
78
79
80 DialogGetPhantom::DialogGetPhantom (wxFrame* pParent, int iDefaultPhantom)
81     : wxDialog (pParent, -1, "Select Phantom", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION)
82 {
83   wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
84
85   pTopSizer->Add (new wxStaticText (this, -1, "Select Phantom"), 0, wxALIGN_CENTER | wxALL, 5);
86                    
87   pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxALL, 5);
88
89   m_pListBoxPhantom = new StringValueAndTitleListBox (this, Phantom::getPhantomCount(), Phantom::getPhantomTitleArray(), Phantom::getPhantomNameArray());
90   m_pListBoxPhantom->SetSelection (iDefaultPhantom);
91   pTopSizer->Add (m_pListBoxPhantom, 0, wxALL | wxALIGN_CENTER | wxEXPAND);
92
93   pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5);
94
95   wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
96   wxButton* pButtonOk = new wxButton (this, wxID_OK, "Okay");
97   wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel");
98   pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
99   pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10);
100
101   pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
102
103   SetAutoLayout (true);
104   SetSizer (pTopSizer);
105   pTopSizer->Fit (this);
106   pTopSizer->SetSizeHints (this);
107 }
108
109 const char*
110 DialogGetPhantom::getPhantom(void)
111 {
112     return m_pListBoxPhantom->getSelectionStringValue();
113 }
114
115
116 DialogGetImageMinMax::DialogGetImageMinMax (wxFrame* pParent, const ImageFile& rImagefile, double dDefaultMin, double dDefaultMax)
117     : wxDialog (pParent, -1, "Set Image Display Minimum & Maximum", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION)
118 {
119   wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
120
121   pTopSizer->Add (new wxStaticText (this, -1, "Set Image Display Minimum and Maximum"), 0, wxALIGN_CENTER | wxTOP | wxLEFT | wxRIGHT, 5);
122                    
123   pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5);
124
125   std::ostringstream os;
126   os << dDefaultMin;
127   m_pTextCtrlMin = new wxTextCtrl (this, -1, os.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
128   std::ostringstream osMax;
129   osMax << dDefaultMax;
130   m_pTextCtrlMax = new wxTextCtrl (this, -1, osMax.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
131
132   wxFlexGridSizer *pGridSizer = new wxFlexGridSizer (2);
133   pGridSizer->Add (new wxStaticText (this, -1, "Minimum"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
134   pGridSizer->Add (m_pTextCtrlMin, 0, wxALIGN_CENTER_VERTICAL);
135   pGridSizer->Add (new wxStaticText (this, -1, "Maximum"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
136   pGridSizer->Add (m_pTextCtrlMax, 0, wxALIGN_CENTER_VERTICAL);
137   pTopSizer->Add (pGridSizer, 1, wxALL, 10);
138
139   pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5);
140
141   wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
142   wxButton* pButtonOk = new wxButton (this, wxID_OK, "Okay");
143   wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel");
144   pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
145   pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10);
146
147   pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
148
149   SetAutoLayout (true);
150   SetSizer (pTopSizer);
151   pTopSizer->Fit (this);
152   pTopSizer->SetSizeHints (this);
153 }
154
155 DialogGetImageMinMax::~DialogGetImageMinMax (void)
156 {
157 #if 0
158   delete m_pTextCtrlMin;
159   delete m_pTextCtrlMax;
160 #endif
161 }
162
163 double
164 DialogGetImageMinMax::getMinimum (void)
165 {
166     wxString strCtrl = m_pTextCtrlMin->GetValue();
167     double dValue;
168     if (strCtrl.ToDouble (&dValue))
169         return dValue;
170     else
171         return (m_dDefaultMin);
172 }
173
174 double
175 DialogGetImageMinMax::getMaximum (void)
176 {
177     wxString strCtrl = m_pTextCtrlMax->GetValue();
178     double dValue;
179     if (strCtrl.ToDouble (&dValue))
180         return dValue;
181     else
182         return (m_dDefaultMax);
183 }
184
185
186 /////////////////////////////////////////////////////////////////////
187 // CLASS IDENTIFICATION
188 //
189 // DialogGetRasterParameters
190 /////////////////////////////////////////////////////////////////////
191
192 DialogGetRasterParameters::DialogGetRasterParameters (wxFrame* pParent, int iDefaultXSize, int iDefaultYSize, int iDefaultNSamples)
193     : wxDialog (pParent, -1, "Set Rasterization Parameters", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION)
194 {
195   wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
196
197   pTopSizer->Add (new wxStaticText (this, -1, "Set Rasterization Parameters"), 0, wxALIGN_CENTER | wxTOP | wxLEFT | wxRIGHT, 5);
198                    
199   pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5);
200
201   std::ostringstream os;
202   os << iDefaultXSize;
203   m_pTextCtrlXSize = new wxTextCtrl (this, -1, os.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
204   std::ostringstream osYSize;
205   osYSize << iDefaultYSize;
206   m_pTextCtrlYSize = new wxTextCtrl (this, -1, osYSize.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
207   std::ostringstream osNSamples;
208   osNSamples << iDefaultNSamples;
209   m_pTextCtrlNSamples = new wxTextCtrl (this, -1, osNSamples.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
210
211   wxFlexGridSizer *pGridSizer = new wxFlexGridSizer (2);
212   pGridSizer->Add (new wxStaticText (this, -1, "X Size"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
213   pGridSizer->Add (m_pTextCtrlXSize, 0, wxALIGN_CENTER_VERTICAL);
214   pGridSizer->Add (new wxStaticText (this, -1, "Y Size"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
215   pGridSizer->Add (m_pTextCtrlYSize, 0, wxALIGN_CENTER_VERTICAL);
216   pGridSizer->Add (new wxStaticText (this, -1, "Samples per Pixel"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
217   pGridSizer->Add (m_pTextCtrlNSamples, 0, wxALIGN_CENTER_VERTICAL);
218   pTopSizer->Add (pGridSizer, 1, wxALL, 10);
219
220   pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5);
221
222   wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
223   wxButton* pButtonOk = new wxButton (this, wxID_OK, "Okay");
224   wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel");
225   pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
226   pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10);
227
228   pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
229
230   SetAutoLayout (true);
231   SetSizer (pTopSizer);
232   pTopSizer->Fit (this);
233   pTopSizer->SetSizeHints (this);
234 }
235
236 DialogGetRasterParameters::~DialogGetRasterParameters (void)
237 {
238 }
239
240
241 unsigned int
242 DialogGetRasterParameters::getXSize (void)
243 {
244     wxString strCtrl = m_pTextCtrlXSize->GetValue();
245     unsigned long lValue;
246     if (strCtrl.ToULong (&lValue))
247         return lValue;
248     else
249         return (m_iDefaultXSize);
250 }
251
252 unsigned int
253 DialogGetRasterParameters::getYSize (void)
254 {
255     wxString strCtrl = m_pTextCtrlYSize->GetValue();
256     unsigned long lValue;
257     if (strCtrl.ToULong (&lValue))
258         return lValue;
259     else
260         return (m_iDefaultYSize);
261 }
262
263
264 unsigned int
265 DialogGetRasterParameters::getNSamples (void)
266 {
267     wxString strCtrl = m_pTextCtrlNSamples->GetValue();
268     unsigned long lValue;
269     if (strCtrl.ToULong (&lValue))
270         return lValue;
271     else
272         return (m_iDefaultNSamples);
273 }
274
275
276
277 /////////////////////////////////////////////////////////////////////
278 // CLASS IDENTIFICATION
279 //
280 // DialogGetProjectionParameters
281 /////////////////////////////////////////////////////////////////////
282
283
284 DialogGetProjectionParameters::DialogGetProjectionParameters (wxFrame* pParent, int iDefaultNDet, int iDefaultNView, int iDefaultNSamples, double dDefaultRotAngle, double dDefaultFocalLength, double dDefaultFieldOfView, int iDefaultGeometry, int iDefaultTrace)
285   : wxDialog (pParent, -1, "Set Projection Parameters", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION)
286 {
287   wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
288
289   m_dDefaultRotAngle = dDefaultRotAngle;
290   m_dDefaultFocalLength = dDefaultFocalLength;
291   m_dDefaultFieldOfView = dDefaultFieldOfView;
292   m_iDefaultNSamples = iDefaultNSamples;
293   m_iDefaultNView = iDefaultNView;
294   m_iDefaultNDet = iDefaultNDet;
295   m_iDefaultTrace = iDefaultTrace;
296   m_iDefaultGeometry = iDefaultGeometry;
297
298   pTopSizer->Add (new wxStaticText (this, -1, "Set Projection Parameters"), 0, wxALIGN_CENTER | wxTOP | wxLEFT | wxRIGHT, 5);
299                    
300   pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5);
301
302   std::ostringstream os;
303   os << iDefaultNDet;
304   m_pTextCtrlNDet = new wxTextCtrl (this, -1, os.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
305   std::ostringstream osNView;
306   osNView << iDefaultNView;
307   m_pTextCtrlNView = new wxTextCtrl (this, -1, osNView.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
308   std::ostringstream osNSamples;
309   osNSamples << iDefaultNSamples;
310   m_pTextCtrlNSamples = new wxTextCtrl (this, -1, osNSamples.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
311   std::ostringstream osRotAngle;
312   osRotAngle << dDefaultRotAngle;
313   m_pTextCtrlRotAngle = new wxTextCtrl (this, -1, osRotAngle.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
314   std::ostringstream osFocalLength;
315   osFocalLength << dDefaultFocalLength;
316   m_pTextCtrlFocalLength = new wxTextCtrl (this, -1, osFocalLength.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
317   std::ostringstream osFieldOfView;
318   osFieldOfView << dDefaultFieldOfView;
319   m_pTextCtrlFieldOfView = new wxTextCtrl (this, -1, osFieldOfView.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
320
321   wxFlexGridSizer* pGridSizer = new wxFlexGridSizer (2);
322   pGridSizer->Add (new wxStaticText (this, -1, "Scanner Geometry"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
323   m_pListBoxGeometry = new StringValueAndTitleListBox (this, Scanner::getGeometryCount(), Scanner::getGeometryTitleArray(), Scanner::getGeometryNameArray());
324   m_pListBoxGeometry->SetSelection (iDefaultGeometry);
325
326   pGridSizer->Add (m_pListBoxGeometry, 0, wxALL | wxALIGN_CENTER | wxEXPAND);
327
328   pGridSizer->Add (new wxStaticText (this, -1, "Detectors"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
329   pGridSizer->Add (m_pTextCtrlNDet, 0, wxALIGN_CENTER_VERTICAL);
330   pGridSizer->Add (new wxStaticText (this, -1, "Views"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
331   pGridSizer->Add (m_pTextCtrlNView, 0, wxALIGN_CENTER_VERTICAL);
332   pGridSizer->Add (new wxStaticText (this, -1, "Samples per Detector"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
333   pGridSizer->Add (m_pTextCtrlNSamples, 0, wxALIGN_CENTER_VERTICAL);
334   pGridSizer->Add (new wxStaticText (this, -1, "Rotation Angle (PI units)"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
335   pGridSizer->Add (m_pTextCtrlRotAngle, 0, wxALIGN_CENTER_VERTICAL);
336   pGridSizer->Add (new wxStaticText (this, -1, "Focal Length Ratio (phantom radius units)"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
337   pGridSizer->Add (m_pTextCtrlFocalLength, 0, wxALIGN_CENTER_VERTICAL);
338   pGridSizer->Add (new wxStaticText (this, -1, "Field of View (phantom diameter units)"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
339   pGridSizer->Add (m_pTextCtrlFieldOfView, 0, wxALIGN_CENTER_VERTICAL);
340
341   m_pListBoxTrace = new StringValueAndTitleListBox (this, Trace::getTraceCount(), Trace::getTraceTitleArray(), Trace::getTraceNameArray());
342   m_pListBoxTrace->SetSelection (iDefaultTrace);
343
344   pGridSizer->Add (new wxStaticText (this, -1, "Trace Level"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
345   pGridSizer->Add (m_pListBoxTrace, 0, wxALL | wxALIGN_CENTER | wxEXPAND);
346   pTopSizer->Add (pGridSizer, 1, wxALL, 10);
347
348   pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5);
349
350   wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
351   wxButton* pButtonOk = new wxButton (this, wxID_OK, "Okay");
352   wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel");
353   pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
354   pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10);
355
356   pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
357
358   SetAutoLayout (true);
359   SetSizer (pTopSizer);
360   pTopSizer->Fit (this);
361   pTopSizer->SetSizeHints (this);
362 }
363
364 DialogGetProjectionParameters::~DialogGetProjectionParameters (void)
365 {
366 }
367
368
369 unsigned int
370 DialogGetProjectionParameters::getNDet (void)
371 {
372     wxString strCtrl = m_pTextCtrlNDet->GetValue();
373     unsigned long lValue;
374     if (strCtrl.ToULong (&lValue))
375         return lValue;
376     else
377         return (m_iDefaultNDet);
378 }
379
380 unsigned int
381 DialogGetProjectionParameters::getNView (void)
382 {
383     wxString strCtrl = m_pTextCtrlNView->GetValue();
384     unsigned long lValue;
385     if (strCtrl.ToULong (&lValue))
386         return lValue;
387     else
388         return (m_iDefaultNView);
389 }
390
391
392 unsigned int
393 DialogGetProjectionParameters::getNSamples (void)
394 {
395     wxString strCtrl = m_pTextCtrlNSamples->GetValue();
396     unsigned long lValue;
397     if (strCtrl.ToULong (&lValue))
398         return lValue;
399     else
400         return (m_iDefaultNSamples);
401 }
402
403 double
404 DialogGetProjectionParameters::getRotAngle (void)
405 {
406     wxString strCtrl = m_pTextCtrlRotAngle->GetValue();
407     double dValue;
408     if (strCtrl.ToDouble (&dValue))
409         return (dValue * PI);
410     else
411       return (m_dDefaultRotAngle);
412 }
413
414 double
415 DialogGetProjectionParameters::getFocalLengthRatio (void)
416 {
417     wxString strCtrl = m_pTextCtrlFocalLength->GetValue();
418     double dValue;
419     if (strCtrl.ToDouble (&dValue))
420         return (dValue);
421     else
422       return (m_dDefaultFocalLength);
423 }
424
425 double
426 DialogGetProjectionParameters::getFieldOfViewRatio (void)
427 {
428     wxString strCtrl = m_pTextCtrlFieldOfView->GetValue();
429     double dValue;
430     if (strCtrl.ToDouble (&dValue))
431         return (dValue);
432     else
433       return (m_dDefaultFieldOfView);
434 }
435
436 const char*
437 DialogGetProjectionParameters::getGeometry (void)
438 {
439   return m_pListBoxGeometry->getSelectionStringValue();
440 }
441
442 int
443 DialogGetProjectionParameters::getTrace (void)
444 {
445   return Trace::convertTraceNameToID(m_pListBoxTrace->getSelectionStringValue());
446 }
447
448
449
450 /////////////////////////////////////////////////////////////////////
451 // CLASS IDENTIFICATION
452 //
453 // DialogGetReconstructionParameters
454 /////////////////////////////////////////////////////////////////////
455
456
457 DialogGetReconstructionParameters::DialogGetReconstructionParameters (wxFrame* pParent, int iDefaultXSize, int iDefaultYSize, int iDefaultFilterID, double dDefaultFilterParam,  int iDefaultFilterMethodID, int iDefaultFilterGenerationID, int iDefaultZeropad, int iDefaultInterpID, int iDefaultInterpParam, int iDefaultBackprojectID, int iTrace)
458     : wxDialog (pParent, -1, "Set Reconstruction Parameters", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION)
459 {
460   wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
461
462   pTopSizer->Add (new wxStaticText (this, -1, "Set Reconstruction Parameters"), 0, wxALIGN_CENTER | wxTOP | wxLEFT | wxRIGHT, 5);
463                    
464   pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5);
465
466   std::ostringstream os;
467   os << iDefaultXSize;
468   m_pTextCtrlXSize = new wxTextCtrl (this, -1, os.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
469   std::ostringstream osYSize;
470   osYSize << iDefaultYSize;
471   m_pTextCtrlYSize = new wxTextCtrl (this, -1, osYSize.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
472   std::ostringstream osFilterParam;
473   osFilterParam << dDefaultFilterParam;
474   m_pTextCtrlFilterParam = new wxTextCtrl (this, -1, osFilterParam.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
475   std::ostringstream osZeropad;
476   osZeropad << iDefaultZeropad;
477   m_pTextCtrlZeropad = new wxTextCtrl (this, -1, osZeropad.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
478   std::ostringstream osInterpParam;
479   osInterpParam << iDefaultInterpParam;
480   m_pTextCtrlInterpParam = new wxTextCtrl (this, -1, osInterpParam.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
481
482   wxFlexGridSizer* pGridSizer = new wxFlexGridSizer (6);
483   pGridSizer->Add (new wxStaticText (this, -1, "Filter"), 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5);
484   m_pListBoxFilter = new StringValueAndTitleListBox (this, SignalFilter::getFilterCount(), SignalFilter::getFilterTitleArray(), SignalFilter::getFilterNameArray());
485   m_pListBoxFilter->SetSelection (iDefaultFilterID);
486   pGridSizer->Add (m_pListBoxFilter, 0, wxALL | wxALIGN_LEFT | wxEXPAND);
487
488   m_pListBoxFilterMethod = new StringValueAndTitleListBox (this, ProcessSignal::getFilterMethodCount(), ProcessSignal::getFilterMethodTitleArray(), ProcessSignal::getFilterMethodNameArray());
489   m_pListBoxFilterMethod->SetSelection (iDefaultFilterMethodID);
490   pGridSizer->Add (new wxStaticText (this, -1, "Filter Method"), 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5);
491   pGridSizer->Add (m_pListBoxFilterMethod, 0, wxALL | wxALIGN_LEFT | wxEXPAND);
492
493   m_pListBoxFilterGeneration = new StringValueAndTitleListBox (this, ProcessSignal::getFilterGenerationCount(), ProcessSignal::getFilterGenerationTitleArray(), ProcessSignal::getFilterGenerationNameArray());
494   m_pListBoxFilterGeneration->SetSelection (iDefaultFilterGenerationID);
495   pGridSizer->Add (new wxStaticText (this, -1, "Filter Generation"), 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5);
496   pGridSizer->Add (m_pListBoxFilterGeneration, 0, wxALL | wxALIGN_LEFT | wxEXPAND);
497 \r
498   
499   m_pListBoxBackproject = new StringValueAndTitleListBox (this, Backprojector::getBackprojectCount(), Backprojector::getBackprojectTitleArray(), Backprojector::getBackprojectNameArray());
500   m_pListBoxBackproject->SetSelection (iDefaultBackprojectID);
501   pGridSizer->Add (new wxStaticText (this, -1, "Backprojection"), 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5);
502   pGridSizer->Add (m_pListBoxBackproject, 0, wxALL | wxALIGN_RIGHT | wxEXPAND);
503
504   m_pListBoxInterp = new StringValueAndTitleListBox (this, Backprojector::getInterpCount(), Backprojector::getInterpTitleArray(), Backprojector::getInterpNameArray());
505   m_pListBoxInterp->SetSelection (iDefaultInterpID);
506   pGridSizer->Add (new wxStaticText (this, -1, "Interpolation"), 0, wxALIGN_CENTER_VERTICAL | wxALIGN_RIGHT | wxALL, 5);
507   pGridSizer->Add (m_pListBoxInterp, 0, wxALL | wxALIGN_RIGHT | wxEXPAND);
508
509
510   pGridSizer->Add (new wxStaticText (this, -1, "Trace Level"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);\r
511   static const char* aszTraceTitle[] = {"None", "Full"};\r
512   static const char* aszTraceName[] = {"none", "full"};\r
513   m_pListBoxTrace = new StringValueAndTitleListBox (this, 2, aszTraceTitle, aszTraceName);\r
514   iTrace = clamp(iTrace, 0, 1);\r
515   m_pListBoxTrace->SetSelection (iTrace);\r
516   pGridSizer->Add (m_pListBoxTrace);\r
517 \r
518   pGridSizer->Add (new wxStaticText (this, -1, "X Size"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
519   pGridSizer->Add (m_pTextCtrlXSize, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL);
520   pGridSizer->Add (new wxStaticText (this, -1, "Y Size"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
521   pGridSizer->Add (m_pTextCtrlYSize, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL);
522   pGridSizer->Add (new wxStaticText (this, -1, "Filter Parameter"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
523   pGridSizer->Add (m_pTextCtrlFilterParam, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL);
524   pGridSizer->Add (new wxStaticText (this, -1, "Zeropad"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
525   pGridSizer->Add (m_pTextCtrlZeropad, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL);
526   pGridSizer->Add (new wxStaticText (this, -1, "Interpolation Parameter"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
527   pGridSizer->Add (m_pTextCtrlInterpParam, 0, wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL);
528
529   pTopSizer->Add (pGridSizer, 1, wxALL, 3);
530
531   pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5);
532
533   wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
534   wxButton* pButtonOk = new wxButton (this, wxID_OK, "Okay");
535   wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel");
536   pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
537   pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10);
538
539   pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
540
541   SetAutoLayout (true);
542   SetSizer (pTopSizer);
543   pTopSizer->Layout();
544   pTopSizer->Fit (this);
545   pTopSizer->SetSizeHints (this);
546 }
547
548 DialogGetReconstructionParameters::~DialogGetReconstructionParameters (void)
549 {
550 }
551
552
553 unsigned int
554 DialogGetReconstructionParameters::getXSize (void)
555 {
556     wxString strCtrl = m_pTextCtrlXSize->GetValue();
557     unsigned long lValue;
558     if (strCtrl.ToULong (&lValue))
559         return lValue;
560     else
561         return (m_iDefaultXSize);
562 }
563
564 unsigned int
565 DialogGetReconstructionParameters::getYSize (void)
566 {
567     wxString strCtrl = m_pTextCtrlYSize->GetValue();
568     unsigned long lValue;
569     if (strCtrl.ToULong (&lValue))
570         return lValue;
571     else
572         return (m_iDefaultYSize);
573 }
574
575 unsigned int
576 DialogGetReconstructionParameters::getZeropad (void)
577 {
578     wxString strCtrl = m_pTextCtrlZeropad->GetValue();
579     unsigned long lValue;
580     if (strCtrl.ToULong (&lValue))
581         return lValue;
582     else
583         return (m_iDefaultZeropad);
584 }
585
586
587 unsigned int
588 DialogGetReconstructionParameters::getInterpParam (void)
589 {
590     wxString strCtrl = m_pTextCtrlInterpParam->GetValue();
591     unsigned long lValue;
592     if (strCtrl.ToULong (&lValue))
593         return lValue;
594     else
595         return (m_iDefaultInterpParam);
596 }
597
598 double
599 DialogGetReconstructionParameters::getFilterParam (void)
600 {
601     wxString strCtrl = m_pTextCtrlFilterParam->GetValue();
602     double dValue;
603     if (strCtrl.ToDouble (&dValue))
604         return (dValue);
605     else
606       return (m_dDefaultFilterParam);
607 }
608
609 const char*
610 DialogGetReconstructionParameters::getFilterName (void)
611 {
612   return m_pListBoxFilter->getSelectionStringValue();
613 }
614
615 const char*
616 DialogGetReconstructionParameters::getFilterMethodName (void)
617 {
618   return m_pListBoxFilterMethod->getSelectionStringValue();
619 }
620
621 const char*
622 DialogGetReconstructionParameters::getInterpName (void)
623 {
624   return m_pListBoxInterp->getSelectionStringValue();
625 }
626
627 int
628 DialogGetReconstructionParameters::getTrace (void)
629 {
630   int iTrace = 0;
631   if (strcmp("full", m_pListBoxTrace->getSelectionStringValue()) == 0)
632       iTrace = Trace::TRACE_PLOT;
633   return iTrace;
634 }
635
636 const char*
637 DialogGetReconstructionParameters::getBackprojectName (void)
638 {
639   return m_pListBoxBackproject->getSelectionStringValue();
640 }
641
642 const char*
643 DialogGetReconstructionParameters::getFilterGenerationName (void)
644 {
645   return m_pListBoxFilterGeneration->getSelectionStringValue();
646 }
647
648
649 DialogAutoScaleParameters::DialogAutoScaleParameters (wxFrame *pParent, const ImageFile& rIF, double dDefaultScaleFactor)
650   : wxDialog (pParent, -1, "Auto Scale Parameters", wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxCAPTION), m_rImageFile(rIF)
651 {
652   wxBoxSizer* pTopSizer = new wxBoxSizer (wxVERTICAL);
653
654   pTopSizer->Add (new wxStaticText (this, -1, "Auto Scale Parameters"), 0, wxALIGN_CENTER | wxTOP | wxLEFT | wxRIGHT, 5);
655                    
656   pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5);
657
658   wxString asTitle[3];
659   asTitle[0] = "Median";
660   asTitle[1] = "Mode";
661   asTitle[2] = "Mean";
662
663   m_pListBoxCenter = new wxListBox (this, -1, wxDefaultPosition, wxDefaultSize, 3, asTitle, wxLB_SINGLE | wxLB_NEEDED_SB);
664   m_pListBoxCenter->SetSelection (0);
665   pTopSizer->Add (m_pListBoxCenter, 0, wxALL | wxALIGN_CENTER | wxEXPAND);
666
667   wxGridSizer *pGridSizer = new wxGridSizer (2);
668   pGridSizer->Add (new wxStaticText (this, -1, "Standard Deviation Factor"), 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
669   std::ostringstream osDefaultFactor;
670   osDefaultFactor << dDefaultScaleFactor;
671   m_pTextCtrlStdDevFactor = new wxTextCtrl (this, -1, osDefaultFactor.str().c_str(), wxDefaultPosition, wxSize(100, 25), 0);
672   pGridSizer->Add (m_pTextCtrlStdDevFactor, 0, wxALIGN_CENTER_VERTICAL);
673   pTopSizer->Add (pGridSizer, 1, wxALL, 10);
674
675   pTopSizer->Add (new wxStaticLine (this, -1, wxDefaultPosition, wxSize(3,3), wxHORIZONTAL), 0, wxEXPAND | wxALL, 5);
676
677   wxBoxSizer* pButtonSizer = new wxBoxSizer (wxHORIZONTAL);
678   wxButton* pButtonOk = new wxButton (this, wxID_OK, "Okay");
679   wxButton* pButtonCancel = new wxButton (this, wxID_CANCEL, "Cancel");
680   pButtonSizer->Add (pButtonOk, 0, wxEXPAND | wxALL, 10);
681   pButtonSizer->Add (pButtonCancel, 0, wxEXPAND | wxALL, 10);
682
683   pTopSizer->Add (pButtonSizer, 0, wxALIGN_CENTER);
684
685   SetAutoLayout (true);
686   SetSizer (pTopSizer);
687   pTopSizer->Fit (this);
688   pTopSizer->SetSizeHints (this);
689 }
690
691 void 
692 DialogAutoScaleParameters::getMinMax (double* pMin, double* pMax)
693 {
694   int iCenter = m_pListBoxCenter->GetSelection();
695   double min, max, mean, mode, median, stddev;
696   m_rImageFile.statistics (min, max, mean, mode, median, stddev);
697   double dCenter = median;
698   if (iCenter == 1)
699     dCenter = mode;
700   else if (iCenter == 2)
701     dCenter = mean;
702   
703   wxString sStddevFactor = m_pTextCtrlStdDevFactor->GetValue();
704   double dValue;
705   if (! sStddevFactor.ToDouble (&dValue)) {
706     *theApp->getLog() << "Error: Non-numeric Standard Deviation Factor of " << sStddevFactor << "\n";
707     *pMin = min;
708     *pMax = max;
709   }
710   double dHalfWidth = dValue * stddev / 2;
711   *pMin = dCenter - dHalfWidth;
712   *pMax = dCenter + dHalfWidth;
713   *theApp->getLog() << "Setting minimum to " << *pMin << " and maximum to " << *pMax << "\n";
714 }
715
716 double
717 DialogAutoScaleParameters::getAutoScaleFactor ()
718 {
719   wxString sStddevFactor = m_pTextCtrlStdDevFactor->GetValue();
720   double dValue = 1.;
721   if (! sStddevFactor.ToDouble (&dValue)) {
722     *theApp->getLog() << "Error: Non-numeric Standard Deviation Factor of " << sStddevFactor << "\n";
723   }
724
725   return dValue;
726 }