r473: no message
[ctsim.git] / src / views.cpp
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          view.cpp
5 **   Purpose:       View & Canvas 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-2001 Kevin Rosenberg
11 **
12 **  $Id: views.cpp,v 1.93 2001/01/30 10:58:13 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 // For compilers that support precompilation, includes "wx/wx.h".
29 #include "wx/wxprec.h"
30
31 #ifdef __BORLANDC__
32 #pragma hdrstop
33 #endif
34
35 #ifndef WX_PRECOMP
36 #include "wx/wx.h"
37 #endif
38
39 #if !wxUSE_DOC_VIEW_ARCHITECTURE
40 #error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in setup.h!
41 #endif
42
43 #include "wx/image.h"
44 #include "wx/progdlg.h"
45
46 #include "ct.h"
47 #include "ctsim.h"
48 #include "docs.h"
49 #include "views.h"
50 #include "dialogs.h"
51 #include "dlgprojections.h"
52 #include "dlgreconstruct.h"
53 #include "backprojectors.h"
54 #include "reconstruct.h"
55 #include "timer.h"
56
57 #if defined(MSVC) || HAVE_SSTREAM
58 #include <sstream>
59 #else
60 #include <sstream_subst>
61 #endif
62
63
64 // ImageFileCanvas
65
66 BEGIN_EVENT_TABLE(ImageFileCanvas, wxScrolledWindow)
67 EVT_MOUSE_EVENTS(ImageFileCanvas::OnMouseEvent)
68 EVT_CHAR(ImageFileCanvas::OnChar)
69 END_EVENT_TABLE()
70
71
72 ImageFileCanvas::ImageFileCanvas (ImageFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
73 : wxScrolledWindow(frame, -1, pos, size, style), m_pView(v), m_xCursor(-1), m_yCursor(-1)
74 {
75 }
76
77 ImageFileCanvas::~ImageFileCanvas()
78 {
79   m_pView = NULL;
80 }
81
82 void 
83 ImageFileCanvas::OnDraw(wxDC& dc)
84 {
85   if (m_pView)
86     m_pView->OnDraw(& dc);
87 }
88
89 void 
90 ImageFileCanvas::DrawRubberBandCursor (wxDC& dc, int x, int y)
91 {
92   const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
93   int nx = rIF.nx();
94   int ny = rIF.ny();
95   
96   int yPt = ny - y - 1;
97   dc.SetLogicalFunction (wxINVERT);
98   dc.SetPen (*wxGREEN_PEN);
99   dc.DrawLine (0, yPt, nx, yPt);
100   dc.DrawLine (x, 0, x, ny);
101   dc.SetLogicalFunction (wxCOPY);
102 }
103
104 bool
105 ImageFileCanvas::GetCurrentCursor (int& x, int& y)
106 {
107   x = m_xCursor;
108   y = m_yCursor;
109   
110   if (m_xCursor >= 0 && m_yCursor >= 0)
111     return true;
112   else
113     return false;
114 }
115
116 void 
117 ImageFileCanvas::OnMouseEvent(wxMouseEvent& event)
118 {
119   if (! m_pView)
120     return;
121   
122   wxClientDC dc(this);
123   PrepareDC(dc);
124   
125   wxPoint pt(event.GetLogicalPosition(dc));
126   
127   const ImageFileDocument* pIFDoc = m_pView->GetDocument();
128   if (! pIFDoc)
129     return;
130   const ImageFile& rIF = pIFDoc->getImageFile();
131   ImageFileArrayConst v = rIF.getArray();
132   int nx = rIF.nx();
133   int ny = rIF.ny();
134   const int yPt = ny - 1 - pt.y;
135   if (event.RightIsDown()) {
136     if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
137       std::ostringstream os;
138       os << "Image value (" << pt.x << "," << yPt << ") = " << v[pt.x][yPt];
139       if (rIF.isComplex()) {
140         double dImag = rIF.getImaginaryArray()[pt.x][yPt];
141         if (dImag < 0)
142           os << " - " << -dImag;
143         else
144           os << " + " << dImag;
145         os << "i\n";
146       } else
147         os << "\n";
148       *theApp->getLog() << os.str().c_str();
149     } else
150       *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
151   }
152   else if (event.LeftIsDown() || event.LeftUp() || event.RightUp()) {
153     if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) {
154       if (m_xCursor >= 0 && m_yCursor >= 0) {
155         DrawRubberBandCursor (dc, m_xCursor, m_yCursor);
156       }
157       DrawRubberBandCursor (dc, pt.x, yPt);
158       m_xCursor = pt.x;
159       m_yCursor = yPt;
160       wxMenu* pMenu = m_pView->getMenuAnalyze();
161       if (pMenu && ! pMenu->IsEnabled(IFMENU_PLOT_ROW)) {
162         pMenu->Enable (IFMENU_PLOT_ROW, true);
163         pMenu->Enable (IFMENU_PLOT_COL, true);
164         pMenu->Enable (IFMENU_COMPARE_ROW, true);
165         pMenu->Enable (IFMENU_COMPARE_COL, true);
166         pMenu->Enable (IFMENU_PLOT_FFT_ROW, true);
167         pMenu->Enable (IFMENU_PLOT_FFT_COL, true);
168       }
169     } else
170       *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n";
171   }
172   if (event.LeftUp()) {
173     std::ostringstream os;
174     os << "Selected column " << pt.x << " , row " << yPt << "\n";
175     *theApp->getLog() << os.str().c_str();
176   }
177 }
178
179 void
180 ImageFileCanvas::OnChar (wxKeyEvent& event)
181 {
182   if (event.GetKeyCode() == WXK_ESCAPE) {
183     m_xCursor = -1;
184     m_yCursor = -1;
185     if (m_pView)
186       m_pView->OnUpdate (NULL);
187   } else
188     wxScrolledWindow::OnChar (event);
189 }
190
191 wxSize
192 ImageFileCanvas::GetBestSize() const
193 {
194   if (! m_pView)
195     return wxSize(0,0);
196   
197   const ImageFile& rIF = m_pView->GetDocument()->getImageFile();
198   return wxSize (rIF.nx(), rIF.ny());
199 }
200
201
202 // ImageFileView
203
204 IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
205
206 BEGIN_EVENT_TABLE(ImageFileView, wxView)
207 EVT_MENU(IFMENU_FILE_EXPORT, ImageFileView::OnExport)
208 EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
209 EVT_MENU(IFMENU_VIEW_SCALE_MINMAX, ImageFileView::OnScaleMinMax)
210 EVT_MENU(IFMENU_VIEW_SCALE_AUTO, ImageFileView::OnScaleAuto)
211 EVT_MENU(IFMENU_VIEW_SCALE_FULL, ImageFileView::OnScaleFull)
212 EVT_MENU(IFMENU_COMPARE_IMAGES, ImageFileView::OnCompare)
213 EVT_MENU(IFMENU_COMPARE_ROW, ImageFileView::OnCompareRow)
214 EVT_MENU(IFMENU_COMPARE_COL, ImageFileView::OnCompareCol)
215 EVT_MENU(IFMENU_FILTER_INVERTVALUES, ImageFileView::OnInvertValues)
216 EVT_MENU(IFMENU_FILTER_SQUARE, ImageFileView::OnSquare)
217 EVT_MENU(IFMENU_FILTER_SQRT, ImageFileView::OnSquareRoot)
218 EVT_MENU(IFMENU_FILTER_LOG, ImageFileView::OnLog)
219 EVT_MENU(IFMENU_FILTER_EXP, ImageFileView::OnExp)
220 EVT_MENU(IFMENU_FILTER_FOURIER, ImageFileView::OnFourier)
221 EVT_MENU(IFMENU_FILTER_INVERSE_FOURIER, ImageFileView::OnInverseFourier)
222 EVT_MENU(IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, ImageFileView::OnShuffleFourierToNaturalOrder)
223 EVT_MENU(IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, ImageFileView::OnShuffleNaturalToFourierOrder)
224 EVT_MENU(IFMENU_IMAGE_ADD, ImageFileView::OnAdd)
225 EVT_MENU(IFMENU_IMAGE_SUBTRACT, ImageFileView::OnSubtract)
226 EVT_MENU(IFMENU_IMAGE_MULTIPLY, ImageFileView::OnMultiply)
227 EVT_MENU(IFMENU_IMAGE_DIVIDE, ImageFileView::OnDivide)
228 EVT_MENU(IFMENU_IMAGE_SCALESIZE, ImageFileView::OnScaleSize)
229 EVT_MENU(IFMENU_IMAGE_CONVERT3D, ImageFileView::OnConvert3d)
230 #ifdef HAVE_FFT
231 EVT_MENU(IFMENU_FILTER_FFT, ImageFileView::OnFFT)
232 EVT_MENU(IFMENU_FILTER_IFFT, ImageFileView::OnIFFT)
233 EVT_MENU(IFMENU_FILTER_FFT_ROWS, ImageFileView::OnFFTRows)
234 EVT_MENU(IFMENU_FILTER_IFFT_ROWS, ImageFileView::OnIFFTRows)
235 EVT_MENU(IFMENU_FILTER_FFT_COLS, ImageFileView::OnFFTCols)
236 EVT_MENU(IFMENU_FILTER_IFFT_COLS, ImageFileView::OnIFFTCols)
237 #endif
238 EVT_MENU(IFMENU_FILTER_MAGNITUDE, ImageFileView::OnMagnitude)
239 EVT_MENU(IFMENU_FILTER_PHASE, ImageFileView::OnPhase)
240 EVT_MENU(IFMENU_PLOT_ROW, ImageFileView::OnPlotRow)
241 EVT_MENU(IFMENU_PLOT_COL, ImageFileView::OnPlotCol)
242 #ifdef HAVE_FFT
243 EVT_MENU(IFMENU_PLOT_FFT_ROW, ImageFileView::OnPlotFFTRow)
244 EVT_MENU(IFMENU_PLOT_FFT_COL, ImageFileView::OnPlotFFTCol)
245 #endif
246 EVT_MENU(IFMENU_PLOT_HISTOGRAM, ImageFileView::OnPlotHistogram)
247 END_EVENT_TABLE()
248
249 ImageFileView::ImageFileView() 
250 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
251 {
252   m_iDefaultExportFormatID = ImageFile::FORMAT_PNG;
253 }
254
255 ImageFileView::~ImageFileView()
256 {
257   GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
258   GetDocumentManager()->ActivateView(this, FALSE, TRUE);
259 }
260
261
262 void
263 ImageFileView::OnProperties (wxCommandEvent& event)
264 {
265   const ImageFile& rIF = GetDocument()->getImageFile();
266   if (rIF.nx() == 0 || rIF.ny() == 0)
267     *theApp->getLog() << "Properties: empty imagefile\n";
268   else {
269     const std::string& rFilename = rIF.getFilename();
270     std::ostringstream os;
271     double min, max, mean, mode, median, stddev;
272     rIF.statistics (rIF.getArray(), min, max, mean, mode, median, stddev);
273     os << "Filename: " << rFilename << "\n";
274     os << "Size: (" << rIF.nx() << "," << rIF.ny() << ")\n";
275     os << "Data type: ";
276     if (rIF.isComplex())
277       os << "Complex\n";
278     else
279       os << "Real\n";
280     os << "Minimum: "<<min<<"\nMaximum: "<<max<<"\nMean: "<<mean<<"\nMedian: "<<median<<"\nMode: "<<mode<<"\nStandard Deviation: "<<stddev << "\n";
281     if (rIF.isComplex()) {
282       rIF.statistics (rIF.getImaginaryArray(), min, max, mean, mode, median, stddev);
283       os << "Imaginary: min: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmedian: "<<median<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
284     }
285     if (rIF.nLabels() > 0) {
286       rIF.printLabelsBrief (os);
287     }
288     *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
289     wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Imagefile Properties", wxOK | wxICON_INFORMATION);
290     dialogMsg.ShowModal();
291   }
292 }
293
294 void 
295 ImageFileView::OnScaleAuto (wxCommandEvent& event)
296 {
297   const ImageFile& rIF = GetDocument()->getImageFile();
298   double min, max, mean, mode, median, stddev;
299   rIF.statistics(min, max, mean, mode, median, stddev);
300   DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
301   int iRetVal = dialogAutoScale.ShowModal();
302   if (iRetVal == wxID_OK) {
303     m_bMinSpecified = true;
304     m_bMaxSpecified = true;
305     double dMin, dMax;
306     if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
307       m_dMinPixel = dMin;
308       m_dMaxPixel = dMax;
309       m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
310       OnUpdate (this, NULL);
311     }
312   }
313 }
314
315 void 
316 ImageFileView::OnScaleMinMax (wxCommandEvent& event)
317 {
318   const ImageFile& rIF = GetDocument()->getImageFile();
319   double min, max;
320   if (! m_bMinSpecified && ! m_bMaxSpecified)
321     rIF.getMinMax (min, max);
322   
323   if (m_bMinSpecified)
324     min = m_dMinPixel;
325   if (m_bMaxSpecified)
326     max = m_dMaxPixel;
327   
328   DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Image Minimum & Maximum", min, max);
329   int retVal = dialogMinMax.ShowModal();
330   if (retVal == wxID_OK) {
331     m_bMinSpecified = true;
332     m_bMaxSpecified = true;
333     m_dMinPixel = dialogMinMax.getMinimum();
334     m_dMaxPixel = dialogMinMax.getMaximum();
335     OnUpdate (this, NULL);
336   }
337 }
338
339 void 
340 ImageFileView::OnScaleFull (wxCommandEvent& event)
341 {
342   if (m_bMinSpecified || m_bMaxSpecified) {
343     m_bMinSpecified = false;
344     m_bMaxSpecified = false;
345     OnUpdate (this, NULL);
346   }
347 }
348
349 void
350 ImageFileView::OnCompare (wxCommandEvent& event)
351 {
352   std::vector<ImageFileDocument*> vecIF;
353   theApp->getCompatibleImages (GetDocument(), vecIF);
354   
355   if (vecIF.size() == 0) {
356     wxMessageBox("There are no compatible image files open for comparision", "No comparison images");
357   } else {
358     DialogGetComparisonImage dialogGetCompare(getFrameForChild(), "Get Comparison Image", vecIF, true);
359     
360     if (dialogGetCompare.ShowModal() == wxID_OK) {
361       const ImageFile& rIF = GetDocument()->getImageFile();
362       ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
363       const ImageFile& rCompareIF = pCompareDoc->getImageFile();
364       std::ostringstream os;
365       double min, max, mean, mode, median, stddev;
366       rIF.statistics (min, max, mean, mode, median, stddev);
367       os << GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
368       rCompareIF.statistics (min, max, mean, mode, median, stddev);
369       os << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": minimum=" << min << ", maximum=" << max << ", mean=" << mean << ", mode=" << mode << ", median=" << median << ", stddev=" << stddev << "\n";
370       double d, r, e;
371       rIF.comparativeStatistics (rCompareIF, d, r, e);
372       os << "Comparative Statistics: d=" << d << ", r=" << r << ", e=" << e << "\n";
373       *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
374       if (dialogGetCompare.getMakeDifferenceImage()) {
375         ImageFile* pDifferenceImage = new ImageFile;
376         
377         pDifferenceImage->setArraySize (rIF.nx(), rIF.ny());
378         if (! rIF.subtractImages (rCompareIF, *pDifferenceImage)) {
379           *theApp->getLog() << "Unable to subtract images\n";
380           delete pDifferenceImage;
381           return;
382         }
383         ImageFileDocument* pDifferenceDoc = theApp->newImageDoc();
384         if (! pDifferenceDoc) {
385           sys_error (ERR_SEVERE, "Unable to create image file");
386           return;
387         }
388         pDifferenceDoc->setImageFile (pDifferenceImage);
389
390         wxString s = GetFrame()->GetTitle() + ": ";
391         pDifferenceImage->labelsCopy (rIF, s.c_str());
392         s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
393         pDifferenceImage->labelsCopy (rCompareIF, s.c_str());
394         std::ostringstream osLabel;
395         osLabel << "Compare image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() 
396           << " and " << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str() << ": "
397           << os.str().c_str();
398         pDifferenceImage->labelAdd (os.str().c_str());
399         pDifferenceDoc->Modify (true);
400         pDifferenceDoc->UpdateAllViews (this);
401         pDifferenceDoc->getView()->OnUpdate (this, NULL);
402         pDifferenceDoc->getView()->getFrame()->Show(true);
403       }
404       wxMessageBox(os.str().c_str(), "Image Comparison");
405     }
406   }
407 }
408
409 void
410 ImageFileView::OnInvertValues (wxCommandEvent& event)
411 {
412   ImageFile& rIF = GetDocument()->getImageFile();
413   rIF.invertPixelValues (rIF);
414   rIF.labelAdd ("Invert Pixel Values");
415   GetDocument()->Modify (true);
416   GetDocument()->UpdateAllViews (this);
417 }
418
419 void
420 ImageFileView::OnSquare (wxCommandEvent& event)
421 {
422   ImageFile& rIF = GetDocument()->getImageFile();
423   rIF.square (rIF);
424   rIF.labelAdd ("Square Pixel Values");
425   GetDocument()->Modify (true);
426   GetDocument()->UpdateAllViews (this);
427 }
428
429 void
430 ImageFileView::OnSquareRoot (wxCommandEvent& event)
431 {
432   ImageFile& rIF = GetDocument()->getImageFile();
433   rIF.sqrt (rIF);
434   rIF.labelAdd ("Square-root Pixel Values");
435   GetDocument()->Modify (true);
436   GetDocument()->UpdateAllViews (this);
437 }
438
439 void
440 ImageFileView::OnLog (wxCommandEvent& event)
441 {
442   ImageFile& rIF = GetDocument()->getImageFile();
443   rIF.log (rIF);
444   rIF.labelAdd ("Logrithm base-e Pixel Values");
445   GetDocument()->Modify (true);
446   GetDocument()->UpdateAllViews (this);
447 }
448
449 void
450 ImageFileView::OnExp (wxCommandEvent& event)
451 {
452   ImageFile& rIF = GetDocument()->getImageFile();
453   rIF.exp (rIF);
454   rIF.labelAdd ("Exponent base-e Pixel Values");
455   GetDocument()->Modify (true);
456   GetDocument()->UpdateAllViews (this);
457 }
458
459 void
460 ImageFileView::OnAdd (wxCommandEvent& event)
461 {
462   std::vector<ImageFileDocument*> vecIF;
463   theApp->getCompatibleImages (GetDocument(), vecIF);
464   
465   if (vecIF.size() == 0) {
466     wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
467   } else {
468     DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Add", vecIF, false);
469     
470     if (dialogGetCompare.ShowModal() == wxID_OK) {
471       ImageFile& rIF = GetDocument()->getImageFile();
472       ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
473       const ImageFile& rRHSIF = pRHSDoc->getImageFile();
474       ImageFileDocument* pNewDoc = theApp->newImageDoc();
475       if (! pNewDoc) {
476         sys_error (ERR_SEVERE, "Unable to create image file");
477         return;
478       }
479       ImageFile& newImage = pNewDoc->getImageFile();  
480       newImage.setArraySize (rIF.nx(), rIF.ny());
481       rIF.addImages (rRHSIF, newImage);
482       std::ostringstream os;
483       os << "Add image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and " 
484         << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
485       wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
486       newImage.labelsCopy (rIF, s.c_str());
487       s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
488       newImage.labelsCopy (rRHSIF, s.c_str());
489       newImage.labelAdd (os.str().c_str());
490       *theApp->getLog() << os.str().c_str() << "\n";
491       pNewDoc->Modify (true);
492       pNewDoc->UpdateAllViews (this);
493       pNewDoc->getView()->OnUpdate (this, NULL);
494       pNewDoc->getView()->getFrame()->Show(true);
495     }
496   }
497 }
498
499 void
500 ImageFileView::OnSubtract (wxCommandEvent& event)
501 {
502   std::vector<ImageFileDocument*> vecIF;
503   theApp->getCompatibleImages (GetDocument(), vecIF);
504   
505   if (vecIF.size() == 0) {
506     wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
507   } else {
508     DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Subtract", vecIF, false);
509     
510     if (dialogGetCompare.ShowModal() == wxID_OK) {
511       ImageFile& rIF = GetDocument()->getImageFile();
512       ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
513       const ImageFile& rRHSIF = pRHSDoc->getImageFile();
514       ImageFileDocument* pNewDoc = theApp->newImageDoc();
515       if (! pNewDoc) {
516         sys_error (ERR_SEVERE, "Unable to create image file");
517         return;
518       }
519       ImageFile& newImage = pNewDoc->getImageFile();  
520       newImage.setArraySize (rIF.nx(), rIF.ny());
521       rIF.subtractImages (rRHSIF, newImage);
522       std::ostringstream os;
523       os << "Subtract image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and " 
524         << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
525       wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
526       newImage.labelsCopy (rIF, s.c_str());
527       s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
528       newImage.labelsCopy (rRHSIF, s.c_str());
529       newImage.labelAdd (os.str().c_str());
530       *theApp->getLog() << os.str().c_str() << "\n";
531       pNewDoc->Modify (true);
532       pNewDoc->UpdateAllViews (this);
533       pNewDoc->getView()->OnUpdate (this, NULL);
534       pNewDoc->getView()->getFrame()->Show(true);
535     }
536   }
537 }
538
539 void
540 ImageFileView::OnMultiply (wxCommandEvent& event)
541 {
542   std::vector<ImageFileDocument*> vecIF;
543   theApp->getCompatibleImages (GetDocument(), vecIF);
544   
545   if (vecIF.size() == 0) {
546     wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
547   } else {
548     DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Multiply", vecIF, false);
549     
550     if (dialogGetCompare.ShowModal() == wxID_OK) {
551       ImageFile& rIF = GetDocument()->getImageFile();
552       ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
553       const ImageFile& rRHSIF = pRHSDoc->getImageFile();
554       ImageFileDocument* pNewDoc = theApp->newImageDoc();
555       if (! pNewDoc) {
556         sys_error (ERR_SEVERE, "Unable to create image file");
557         return;
558       }
559       ImageFile& newImage = pNewDoc->getImageFile();  
560       newImage.setArraySize (rIF.nx(), rIF.ny());
561       rIF.multiplyImages (rRHSIF, newImage);
562       std::ostringstream os;
563       os << "Multiply image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and " 
564         << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
565       wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
566       newImage.labelsCopy (rIF, s.c_str());
567       s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
568       newImage.labelsCopy (rRHSIF, s.c_str());
569       newImage.labelAdd (os.str().c_str());
570       *theApp->getLog() << os.str().c_str() << "\n";
571       pNewDoc->Modify (true);
572       pNewDoc->UpdateAllViews (this);
573       pNewDoc->getView()->OnUpdate (this, NULL);
574       pNewDoc->getView()->getFrame()->Show(true);
575     }
576   }
577 }
578
579 void
580 ImageFileView::OnDivide (wxCommandEvent& event)
581 {
582   std::vector<ImageFileDocument*> vecIF;
583   theApp->getCompatibleImages (GetDocument(), vecIF);
584   
585   if (vecIF.size() == 0) {
586     wxMessageBox ("There are no compatible image files open for comparision", "No comparison images");
587   } else {
588     DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Image to Divide", vecIF, false);
589     
590     if (dialogGetCompare.ShowModal() == wxID_OK) {
591       ImageFile& rIF = GetDocument()->getImageFile();
592       ImageFileDocument* pRHSDoc = dialogGetCompare.getImageFileDocument();
593       const ImageFile& rRHSIF = pRHSDoc->getImageFile();
594       ImageFileDocument* pNewDoc = theApp->newImageDoc();
595       if (! pNewDoc) {
596         sys_error (ERR_SEVERE, "Unable to create image file");
597         return;
598       }
599       ImageFile& newImage = pNewDoc->getImageFile();  
600       newImage.setArraySize (rIF.nx(), rIF.ny());
601       rIF.divideImages (rRHSIF, newImage);
602       std::ostringstream os;
603       os << "Divide image " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " by " 
604         << pRHSDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
605       wxString s = GetDocument()->GetFirstView()->GetFrame()->GetTitle() + ": ";
606       newImage.labelsCopy (rIF, s.c_str());
607       s = pRHSDoc->GetFirstView()->GetFrame()->GetTitle() + ": ";
608       newImage.labelsCopy (rRHSIF, s.c_str());
609       newImage.labelAdd (os.str().c_str());
610       *theApp->getLog() << os.str().c_str() << "\n";
611       pNewDoc->Modify (true);
612       pNewDoc->UpdateAllViews (this);
613       pNewDoc->getView()->OnUpdate (this, NULL);
614       pNewDoc->getView()->getFrame()->Show(true);
615     }
616   }
617 }
618
619
620 #ifdef HAVE_FFT
621 void
622 ImageFileView::OnFFT (wxCommandEvent& event)
623 {
624   ImageFile& rIF = GetDocument()->getImageFile();
625   rIF.fft (rIF);
626   rIF.labelAdd ("FFT Image");
627   m_bMinSpecified = false;
628   m_bMaxSpecified = false;
629   GetDocument()->Modify (true);
630   GetDocument()->UpdateAllViews (this);
631 }
632
633 void
634 ImageFileView::OnIFFT (wxCommandEvent& event)
635 {
636   ImageFile& rIF = GetDocument()->getImageFile();
637   rIF.ifft (rIF);
638   rIF.labelAdd ("IFFT Image");
639   m_bMinSpecified = false;
640   m_bMaxSpecified = false;
641   GetDocument()->Modify (true);
642   GetDocument()->UpdateAllViews (this);
643 }
644
645 void
646 ImageFileView::OnFFTRows (wxCommandEvent& event)
647 {
648   ImageFile& rIF = GetDocument()->getImageFile();
649   rIF.fftRows (rIF);
650   rIF.labelAdd ("FFT Rows");
651   m_bMinSpecified = false;
652   m_bMaxSpecified = false;
653   GetDocument()->Modify (true);
654   GetDocument()->UpdateAllViews (this);
655 }
656
657 void
658 ImageFileView::OnIFFTRows (wxCommandEvent& event)
659 {
660   ImageFile& rIF = GetDocument()->getImageFile();
661   rIF.ifftRows (rIF);
662   rIF.labelAdd ("IFFT Rows");
663   m_bMinSpecified = false;
664   m_bMaxSpecified = false;
665   GetDocument()->Modify (true);
666   GetDocument()->UpdateAllViews (this);
667 }
668
669 void
670 ImageFileView::OnFFTCols (wxCommandEvent& event)
671 {
672   ImageFile& rIF = GetDocument()->getImageFile();
673   rIF.fftCols (rIF);
674   rIF.labelAdd ("FFT Columns");
675   m_bMinSpecified = false;
676   m_bMaxSpecified = false;
677   GetDocument()->Modify (true);
678   GetDocument()->UpdateAllViews (this);
679 }
680
681 void
682 ImageFileView::OnIFFTCols (wxCommandEvent& event)
683 {
684   ImageFile& rIF = GetDocument()->getImageFile();
685   rIF.ifftCols (rIF);
686   rIF.labelAdd ("IFFT Columns");
687   m_bMinSpecified = false;
688   m_bMaxSpecified = false;
689   GetDocument()->Modify (true);
690   GetDocument()->UpdateAllViews (this);
691 }
692 #endif
693
694 void
695 ImageFileView::OnFourier (wxCommandEvent& event)
696 {
697   ImageFile& rIF = GetDocument()->getImageFile();
698   wxProgressDialog dlgProgress (wxString("Fourier"), wxString("Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
699   rIF.fourier (rIF);
700   rIF.labelAdd ("Fourier Image");
701   m_bMinSpecified = false;
702   m_bMaxSpecified = false;
703   GetDocument()->Modify (true);
704   GetDocument()->UpdateAllViews (this);
705 }
706
707 void
708 ImageFileView::OnInverseFourier (wxCommandEvent& event)
709 {
710   ImageFile& rIF = GetDocument()->getImageFile();
711   wxProgressDialog dlgProgress (wxString("Inverse Fourier"), wxString("Inverse Fourier Progress"), 1, getFrameForChild(), wxPD_APP_MODAL);
712   rIF.inverseFourier (rIF);
713   rIF.labelAdd ("Inverse Fourier Image");
714   m_bMinSpecified = false;
715   m_bMaxSpecified = false;
716   GetDocument()->Modify (true);
717   GetDocument()->UpdateAllViews (this);
718 }
719
720 void
721 ImageFileView::OnShuffleNaturalToFourierOrder (wxCommandEvent& event)
722 {
723   ImageFile& rIF = GetDocument()->getImageFile();
724   Fourier::shuffleNaturalToFourierOrder (rIF);
725   rIF.labelAdd ("Shuffle Natural To Fourier Order");
726   m_bMinSpecified = false;
727   m_bMaxSpecified = false;
728   GetDocument()->Modify (true);
729   GetDocument()->UpdateAllViews (this);
730 }
731
732 void
733 ImageFileView::OnShuffleFourierToNaturalOrder (wxCommandEvent& event)
734 {
735   ImageFile& rIF = GetDocument()->getImageFile();
736   Fourier::shuffleFourierToNaturalOrder (rIF);
737   rIF.labelAdd ("Shuffle Fourier To Natural Order");
738   m_bMinSpecified = false;
739   m_bMaxSpecified = false;
740   GetDocument()->Modify (true);
741   GetDocument()->UpdateAllViews (this);
742 }
743
744 void
745 ImageFileView::OnMagnitude (wxCommandEvent& event)
746 {
747   ImageFile& rIF = GetDocument()->getImageFile();
748   if (rIF.isComplex()) {
749     rIF.magnitude (rIF);
750     rIF.labelAdd ("Magnitude of complex-image");
751     m_bMinSpecified = false;
752     m_bMaxSpecified = false;
753     GetDocument()->Modify (true);
754     GetDocument()->UpdateAllViews (this);
755   }
756 }
757
758 void
759 ImageFileView::OnPhase (wxCommandEvent& event)
760 {
761   ImageFile& rIF = GetDocument()->getImageFile();
762   if (rIF.isComplex()) {
763     rIF.phase (rIF);
764     rIF.labelAdd ("Phase of complex-image");
765     m_bMinSpecified = false;
766     m_bMaxSpecified = false;
767     GetDocument()->Modify (true);
768     GetDocument()->UpdateAllViews (this);
769   }
770 }
771
772
773 ImageFileCanvas* 
774 ImageFileView::CreateCanvas (wxFrame* parent)
775 {
776   ImageFileCanvas* pCanvas;
777   int width, height;
778   parent->GetClientSize(&width, &height);
779   
780   pCanvas = new ImageFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
781   
782   pCanvas->SetScrollbars(20, 20, 50, 50);
783   pCanvas->SetBackgroundColour(*wxWHITE);
784   pCanvas->Clear();
785   
786   return pCanvas;
787 }
788
789 #if CTSIM_MDI
790 wxDocMDIChildFrame*
791 #else
792 wxDocChildFrame*
793 #endif
794 ImageFileView::CreateChildFrame(wxDocument *doc, wxView *view)
795 {
796 #if CTSIM_MDI
797   wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
798 #else
799   wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "ImageFile Frame", wxPoint(-1, -1), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
800 #endif
801   theApp->setIconForFrame (subframe);
802   
803   m_pFileMenu = new wxMenu;
804   
805   m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
806   m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
807   m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
808   m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
809   m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
810   m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
811   m_pFileMenu->Append(wxID_REVERT, "Re&vert");
812   
813   m_pFileMenu->AppendSeparator();
814   m_pFileMenu->Append(IFMENU_FILE_PROPERTIES, "P&roperties");
815   m_pFileMenu->Append(IFMENU_FILE_EXPORT, "&Export...");
816   
817   m_pFileMenu->AppendSeparator();
818   m_pFileMenu->Append(wxID_PRINT, "&Print...");
819   m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
820   m_pFileMenu->Append(wxID_PREVIEW, "Print Preview");
821 #ifdef CTSIM_MDI
822   m_pFileMenu->AppendSeparator();
823   m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
824 #endif
825   GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
826   GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
827   
828   wxMenu *view_menu = new wxMenu;
829   view_menu->Append(IFMENU_VIEW_SCALE_MINMAX, "Display Scale S&et...\tCtrl-E");
830   view_menu->Append(IFMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
831   view_menu->Append(IFMENU_VIEW_SCALE_FULL, "Display F&ull Scale\tCtrl-U");
832   
833   wxMenu* filter_menu = new wxMenu;
834   filter_menu->Append (IFMENU_FILTER_INVERTVALUES, "&Invert Values");
835   filter_menu->Append (IFMENU_FILTER_SQUARE, "&Square");
836   filter_menu->Append (IFMENU_FILTER_SQRT, "Square &Root");
837   filter_menu->Append (IFMENU_FILTER_LOG, "&Log");
838   filter_menu->Append (IFMENU_FILTER_EXP, "&Exp");
839   filter_menu->AppendSeparator();
840 #ifdef HAVE_FFT
841   filter_menu->Append (IFMENU_FILTER_FFT, "2D &FFT");
842   filter_menu->Append (IFMENU_FILTER_IFFT, "2D &IFFT");
843   filter_menu->Append (IFMENU_FILTER_FFT_ROWS, "FFT Rows");
844   filter_menu->Append (IFMENU_FILTER_IFFT_ROWS, "IFFT Rows");
845   filter_menu->Append (IFMENU_FILTER_FFT_COLS, "FFT Columns");
846   filter_menu->Append (IFMENU_FILTER_IFFT_COLS, "IFFT Columns");
847   filter_menu->Append (IFMENU_FILTER_FOURIER, "F&ourier");
848   filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "Inverse Fo&urier");
849 #else
850   filter_menu->Append (IFMENU_FILTER_FOURIER, "&Fourier");
851   filter_menu->Append (IFMENU_FILTER_INVERSE_FOURIER, "&Inverse Fourier");
852 #endif
853   filter_menu->Append (IFMENU_FILTER_SHUFFLEFOURIERTONATURALORDER, "S&huffle Fourier to Natural Order");
854   filter_menu->Append (IFMENU_FILTER_SHUFFLENATURALTOFOURIERORDER, "Shu&ffle Natural to Fourier Order");
855   filter_menu->Append (IFMENU_FILTER_MAGNITUDE, "&Magnitude");
856   filter_menu->Append (IFMENU_FILTER_PHASE, "&Phase");
857   
858   wxMenu* image_menu = new wxMenu;
859   image_menu->Append (IFMENU_IMAGE_ADD, "&Add...");
860   image_menu->Append (IFMENU_IMAGE_SUBTRACT, "&Subtract...");
861   image_menu->Append (IFMENU_IMAGE_MULTIPLY, "&Multiply...");
862   image_menu->Append (IFMENU_IMAGE_DIVIDE, "&Divide...");
863   image_menu->AppendSeparator();
864   image_menu->Append (IFMENU_IMAGE_SCALESIZE, "S&cale Size...");
865   image_menu->Append (IFMENU_IMAGE_CONVERT3D, "Convert &3-D\tCtrl-3");
866   
867   m_pMenuAnalyze = new wxMenu;
868   m_pMenuAnalyze->Append (IFMENU_PLOT_ROW, "Plot &Row");
869   m_pMenuAnalyze->Append (IFMENU_PLOT_COL, "Plot &Column");
870   m_pMenuAnalyze->Append (IFMENU_PLOT_HISTOGRAM, "Plot &Histogram");
871   m_pMenuAnalyze->AppendSeparator();
872   m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_ROW, "Plot FFT Row");
873   m_pMenuAnalyze->Append (IFMENU_PLOT_FFT_COL, "Plot FFT Column");
874   m_pMenuAnalyze->AppendSeparator();
875   m_pMenuAnalyze->Append (IFMENU_COMPARE_IMAGES, "Compare &Images...");
876   m_pMenuAnalyze->Append (IFMENU_COMPARE_ROW, "Compare &Row");
877   m_pMenuAnalyze->Append (IFMENU_COMPARE_COL, "Compare &Column");
878   m_pMenuAnalyze->Enable (IFMENU_PLOT_ROW, false);
879   m_pMenuAnalyze->Enable (IFMENU_PLOT_COL, false);
880   m_pMenuAnalyze->Enable (IFMENU_COMPARE_ROW, false);
881   m_pMenuAnalyze->Enable (IFMENU_COMPARE_COL, false);
882   m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_ROW, false);
883   m_pMenuAnalyze->Enable (IFMENU_PLOT_FFT_COL, false);
884   
885   wxMenu *help_menu = new wxMenu;
886   help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
887   help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
888   help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
889   
890   wxMenuBar *menu_bar = new wxMenuBar;
891   
892   menu_bar->Append(m_pFileMenu, "&File");
893   menu_bar->Append(view_menu, "&View");
894   menu_bar->Append(image_menu, "&Image");
895   menu_bar->Append(filter_menu, "Fi&lter");
896   menu_bar->Append(m_pMenuAnalyze, "&Analyze");
897   menu_bar->Append(help_menu, "&Help");
898   
899   subframe->SetMenuBar(menu_bar);
900   
901   subframe->Centre(wxBOTH);
902   
903   wxAcceleratorEntry accelEntries[11];
904   accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
905   accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
906   accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
907   accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
908   accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
909   accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
910   accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
911   accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('A'), IFMENU_VIEW_SCALE_AUTO);
912   accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('U'), IFMENU_VIEW_SCALE_FULL);
913   accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('E'), IFMENU_VIEW_SCALE_MINMAX);
914   accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('3'), IFMENU_IMAGE_CONVERT3D);
915   wxAcceleratorTable accelTable (11, accelEntries);
916   subframe->SetAcceleratorTable (accelTable);
917   
918   return subframe;
919 }
920
921
922 bool 
923 ImageFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
924 {
925   m_pFrame = CreateChildFrame(doc, this);
926   (m_pFrame);
927   
928   m_bMinSpecified = false;
929   m_bMaxSpecified = false;
930   m_dAutoScaleFactor = 1.;
931   
932   int width, height;
933   m_pFrame->GetClientSize (&width, &height);
934   m_pFrame->SetTitle("ImageFileView");
935   m_pCanvas = CreateCanvas (m_pFrame);
936   
937   int x, y;  // X requires a forced resize
938   m_pFrame->GetSize(&x, &y);
939   m_pFrame->SetSize(-1, -1, x, y);
940   m_pFrame->SetFocus();
941   m_pFrame->Show(true);
942   Activate(true);
943   
944   return true;
945 }
946
947 void 
948 ImageFileView::OnDraw (wxDC* dc)
949 {
950   wxSize sizeWindow = m_pFrame->GetClientSize();
951   wxSize sizeBest = m_pCanvas->GetBestSize();
952   if (sizeWindow.x > sizeBest.x || sizeWindow.y > sizeBest.y)
953     m_pFrame->SetClientSize (sizeBest);
954   
955   if (m_bitmap.Ok())
956     dc->DrawBitmap(m_bitmap, 0, 0, false);
957   
958   int xCursor, yCursor;
959   if (m_pCanvas->GetCurrentCursor (xCursor, yCursor))
960     m_pCanvas->DrawRubberBandCursor (*dc, xCursor, yCursor);
961 }
962
963
964 void 
965 ImageFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
966 {
967   const ImageFile& rIF = GetDocument()->getImageFile();
968   ImageFileArrayConst v = rIF.getArray();
969   int nx = rIF.nx();
970   int ny = rIF.ny();
971   if (v != NULL && nx != 0 && ny != 0) {
972     if (! m_bMinSpecified || ! m_bMaxSpecified) {
973       double min, max;
974       rIF.getMinMax (min, max);
975       if (! m_bMinSpecified)
976         m_dMinPixel = min;
977       if (! m_bMaxSpecified)
978         m_dMaxPixel = max;
979     }
980     double scaleWidth = m_dMaxPixel - m_dMinPixel;
981     
982     unsigned char* imageData = new unsigned char [nx * ny * 3];
983     for (int ix = 0; ix < nx; ix++) {
984       for (int iy = 0; iy < ny; iy++) {
985         double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
986         int intensity = static_cast<int>(scaleValue + 0.5);
987         intensity = clamp (intensity, 0, 255);
988         int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
989         imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
990       }
991     }
992     wxImage image (nx, ny, imageData, true);
993     m_bitmap = image.ConvertToBitmap();
994     delete imageData;
995     int xSize = nx;
996     int ySize = ny;
997     ySize = clamp (ySize, 0, 800);
998     m_pFrame->SetClientSize (xSize, ySize);
999     m_pCanvas->SetScrollbars(20, 20, nx/20, ny/20);
1000     m_pCanvas->SetBackgroundColour(*wxWHITE);
1001   } 
1002   
1003   if (m_pCanvas)
1004     m_pCanvas->Refresh();
1005 }
1006
1007 bool 
1008 ImageFileView::OnClose (bool deleteWindow)
1009 {
1010   //GetDocumentManager()->ActivateView (this, false, true);
1011   if (! GetDocument() || ! GetDocument()->Close())
1012     return false;
1013
1014   Activate (false);
1015   if (m_pCanvas) {
1016     m_pCanvas->setView(NULL);
1017     m_pCanvas = NULL;
1018   }
1019   wxString s(theApp->GetAppName());
1020   if (m_pFrame)
1021     m_pFrame->SetTitle(s);
1022   
1023   SetFrame(NULL);
1024   
1025   if (deleteWindow) {
1026     m_pFrame->Destroy();
1027     m_pFrame = NULL;
1028     if (GetDocument() && GetDocument()->getBadFileOpen())
1029       ::wxYield();  // wxWindows bug workaround
1030   }
1031   
1032   return true;
1033 }
1034
1035 void
1036 ImageFileView::OnExport (wxCommandEvent& event)
1037 {
1038   ImageFile& rIF = GetDocument()->getImageFile();
1039   ImageFileArrayConst v = rIF.getArray();
1040   int nx = rIF.nx();
1041   int ny = rIF.ny();
1042   if (v != NULL && nx != 0 && ny != 0) {
1043     if (! m_bMinSpecified || ! m_bMaxSpecified) {
1044       double min, max;
1045       rIF.getMinMax (min, max);
1046       if (! m_bMinSpecified)
1047         m_dMinPixel = min;
1048       if (! m_bMaxSpecified)
1049         m_dMaxPixel = max;
1050     }
1051     
1052     DialogExportParameters dialogExport (getFrameForChild(), m_iDefaultExportFormatID);
1053     if (dialogExport.ShowModal() == wxID_OK) {
1054       wxString strFormatName (dialogExport.getFormatName ());
1055       m_iDefaultExportFormatID = ImageFile::convertFormatNameToID (strFormatName.c_str());
1056       
1057       wxString strExt;
1058       wxString strWildcard;
1059       if (m_iDefaultExportFormatID == ImageFile::FORMAT_PGM || m_iDefaultExportFormatID == ImageFile::FORMAT_PGMASCII) {
1060         strExt = ".pgm";
1061         strWildcard = "PGM Files (*.pgm)|*.pgm";
1062       }
1063 #ifdef HAVE_PNG
1064       else if (m_iDefaultExportFormatID == ImageFile::FORMAT_PNG || m_iDefaultExportFormatID == ImageFile::FORMAT_PNG16) {
1065         strExt = ".png";
1066         strWildcard = "PNG Files (*.png)|*.png";
1067       }
1068 #endif
1069       
1070       const wxString& strFilename = wxFileSelector (wxString("Export Filename"), wxString(""), 
1071         wxString(""), strExt, strWildcard, wxOVERWRITE_PROMPT | wxHIDE_READONLY | wxSAVE);
1072       if (strFilename) {
1073         rIF.exportImage (strFormatName.c_str(), strFilename.c_str(), 1, 1, m_dMinPixel, m_dMaxPixel);
1074         *theApp->getLog() << "Exported file " << strFilename << "\n";
1075       }
1076     }
1077   }
1078 }
1079
1080 void
1081 ImageFileView::OnScaleSize (wxCommandEvent& event)
1082 {
1083   ImageFile& rIF = GetDocument()->getImageFile();
1084   unsigned int iOldNX = rIF.nx();
1085   unsigned int iOldNY = rIF.ny();
1086   
1087   DialogGetXYSize dialogGetXYSize (getFrameForChild(), "Set New X & Y Dimensions", iOldNX, iOldNY);
1088   if (dialogGetXYSize.ShowModal() == wxID_OK) {
1089     unsigned int iNewNX = dialogGetXYSize.getXSize();
1090     unsigned int iNewNY = dialogGetXYSize.getYSize();
1091     std::ostringstream os;
1092     os << "Scale Size from (" << iOldNX << "," << iOldNY << ") to (" << iNewNX << "," << iNewNY << ")";
1093     ImageFileDocument* pScaledDoc = theApp->newImageDoc();
1094     if (! pScaledDoc) {
1095       sys_error (ERR_SEVERE, "Unable to create image file");
1096       return;
1097     }
1098     ImageFile& rScaledIF = pScaledDoc->getImageFile();
1099     rScaledIF.setArraySize (iNewNX, iNewNY);
1100     rScaledIF.labelsCopy (rIF);
1101     rScaledIF.labelAdd (os.str().c_str());
1102     rIF.scaleImage (rScaledIF);
1103     *theApp->getLog() << os.str().c_str() << "\n";
1104     pScaledDoc->Modify (true);
1105     pScaledDoc->UpdateAllViews (this);
1106     pScaledDoc->getView()->OnUpdate (this, NULL);
1107     pScaledDoc->getView()->getFrame()->Show(true);
1108   }
1109 }
1110
1111 void
1112 ImageFileView::OnConvert3d (wxCommandEvent& event)
1113 {
1114   ImageFile& rIF = GetDocument()->getImageFile();
1115   Graph3dFileDocument* pGraph3d = theApp->newGraph3dDoc();
1116   pGraph3d->setBadFileOpen();
1117   pGraph3d->createFromImageFile (rIF);
1118   pGraph3d->getView()->getFrame()->SetClientSize (200, 200);
1119   pGraph3d->getView()->getFrame()->Show (true);
1120 }
1121   
1122 void
1123 ImageFileView::OnPlotRow (wxCommandEvent& event)
1124 {
1125   int xCursor, yCursor;
1126   if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1127     wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1128     return;
1129   }
1130   
1131   const ImageFile& rIF = GetDocument()->getImageFile();
1132   ImageFileArrayConst v = rIF.getArray();
1133   ImageFileArrayConst vImag = rIF.getImaginaryArray();
1134   int nx = rIF.nx();
1135   int ny = rIF.ny();
1136   
1137   if (v != NULL && yCursor < ny) {
1138     double* pX = new double [nx];
1139     double* pYReal = new double [nx];
1140     double *pYImag = NULL;
1141     double *pYMag = NULL;
1142     if (rIF.isComplex()) {
1143       pYImag = new double [nx];
1144       pYMag = new double [nx];
1145     }
1146     for (int i = 0; i < nx; i++) {
1147       pX[i] = i;
1148       pYReal[i] = v[i][yCursor];
1149       if (rIF.isComplex()) {
1150         pYImag[i] = vImag[i][yCursor];
1151         pYMag[i] = ::sqrt (v[i][yCursor] * v[i][yCursor] + vImag[i][yCursor] * vImag[i][yCursor]);
1152       }
1153     }
1154     PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1155     if (! pPlotDoc) {
1156       sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1157     } else {
1158       PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1159       std::ostringstream os;
1160       os << "Row " << yCursor;
1161       std::string title("title ");
1162       title += os.str();
1163       rPlotFile.addEzsetCommand (title.c_str());
1164       rPlotFile.addEzsetCommand ("xlabel Column");
1165       rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1166       rPlotFile.addEzsetCommand ("lxfrac 0");
1167       rPlotFile.addEzsetCommand ("box");
1168       rPlotFile.addEzsetCommand ("grid");
1169       rPlotFile.addEzsetCommand ("curve 1");
1170       rPlotFile.addEzsetCommand ("color 1");
1171       if (rIF.isComplex()) {
1172         rPlotFile.addEzsetCommand ("dash 1");
1173         rPlotFile.addEzsetCommand ("curve 2");
1174         rPlotFile.addEzsetCommand ("color 4");
1175         rPlotFile.addEzsetCommand ("dash 3");
1176         rPlotFile.addEzsetCommand ("curve 3");
1177         rPlotFile.addEzsetCommand ("color 0");
1178         rPlotFile.addEzsetCommand ("solid");
1179         rPlotFile.setCurveSize (4, nx);
1180       } else
1181         rPlotFile.setCurveSize (2, nx);
1182       rPlotFile.addColumn (0, pX);
1183       rPlotFile.addColumn (1, pYReal); 
1184       if (rIF.isComplex()) {
1185         rPlotFile.addColumn (2, pYImag);
1186         rPlotFile.addColumn (3, pYMag);
1187       }
1188       for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1189         rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1190       os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1191       *theApp->getLog() << os.str().c_str() << "\n";
1192       rPlotFile.addDescription (os.str().c_str());
1193     }
1194     delete pX;
1195     delete pYReal;
1196     if (rIF.isComplex()) {
1197       delete pYImag;
1198       delete pYMag;
1199     }
1200     pPlotDoc->Modify (true);
1201     pPlotDoc->UpdateAllViews ();
1202     pPlotDoc->getView()->OnUpdate (this, NULL);
1203     pPlotDoc->getView()->getFrame()->Show(true);
1204   }
1205 }
1206
1207 void
1208 ImageFileView::OnPlotCol (wxCommandEvent& event)
1209 {
1210   int xCursor, yCursor;
1211   if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1212     wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1213     return;
1214   }
1215   
1216   const ImageFile& rIF = GetDocument()->getImageFile();
1217   ImageFileArrayConst v = rIF.getArray();
1218   ImageFileArrayConst vImag = rIF.getImaginaryArray();
1219   int nx = rIF.nx();
1220   int ny = rIF.ny();
1221   
1222   if (v != NULL && xCursor < nx) {
1223     double* pX = new double [ny];
1224     double* pYReal = new double [ny];
1225     double* pYImag = NULL;
1226     double* pYMag = NULL;
1227     if (rIF.isComplex()) {
1228       pYImag = new double [ny];
1229       pYMag = new double [ny];
1230     }
1231     for (int i = 0; i < ny; i++) {
1232       pX[i] = i;
1233       pYReal[i] = v[xCursor][i];
1234       if (rIF.isComplex()) {
1235         pYImag[i] = vImag[xCursor][i];
1236         pYMag[i] = ::sqrt (v[xCursor][i] * v[xCursor][i] + vImag[xCursor][i] * vImag[xCursor][i]);
1237       }
1238     }
1239     PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1240     if (! pPlotDoc) {
1241       sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1242     } else {
1243       PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1244       std::ostringstream os;
1245       os << "Column " << xCursor;
1246       std::string title("title ");
1247       title += os.str();
1248       rPlotFile.addEzsetCommand (title.c_str());
1249       rPlotFile.addEzsetCommand ("xlabel Row");
1250       rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1251       rPlotFile.addEzsetCommand ("lxfrac 0");
1252       rPlotFile.addEzsetCommand ("box");
1253       rPlotFile.addEzsetCommand ("grid");
1254       rPlotFile.addEzsetCommand ("curve 1");
1255       rPlotFile.addEzsetCommand ("color 1");
1256       if (rIF.isComplex()) {
1257         rPlotFile.addEzsetCommand ("dash 1");
1258         rPlotFile.addEzsetCommand ("curve 2");
1259         rPlotFile.addEzsetCommand ("color 4");
1260         rPlotFile.addEzsetCommand ("dash 3");
1261         rPlotFile.addEzsetCommand ("curve 3");
1262         rPlotFile.addEzsetCommand ("color 0");
1263         rPlotFile.addEzsetCommand ("solid");
1264         rPlotFile.setCurveSize (4, ny);
1265       } else
1266         rPlotFile.setCurveSize (2, ny);
1267       rPlotFile.addColumn (0, pX);
1268       rPlotFile.addColumn (1, pYReal); 
1269       if (rIF.isComplex()) {
1270         rPlotFile.addColumn (2, pYImag);
1271         rPlotFile.addColumn (3, pYMag);
1272       }
1273       for (unsigned int iL = 0; iL < rIF.nLabels(); iL++)
1274         rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1275       os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1276       *theApp->getLog() << os.str().c_str() << "\n";
1277       rPlotFile.addDescription (os.str().c_str());
1278     }
1279     delete pX;
1280     delete pYReal;
1281     if (rIF.isComplex()) {
1282       delete pYImag;
1283       delete pYMag;
1284     }
1285     pPlotDoc->Modify (true);
1286     pPlotDoc->UpdateAllViews ();
1287     pPlotDoc->getView()->OnUpdate (this, NULL);
1288     pPlotDoc->getView()->getFrame()->Show(true);
1289   }
1290 }
1291
1292 #ifdef HAVE_FFT
1293 void
1294 ImageFileView::OnPlotFFTRow (wxCommandEvent& event)
1295 {
1296   int xCursor, yCursor;
1297   if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1298     wxMessageBox ("No row selected. Please use left mouse button on image to select column","Error");
1299     return;
1300   }
1301   
1302   const ImageFile& rIF = GetDocument()->getImageFile();
1303   ImageFileArrayConst v = rIF.getArray();
1304   ImageFileArrayConst vImag = rIF.getImaginaryArray();
1305   int nx = rIF.nx();
1306   int ny = rIF.ny();
1307   
1308   if (v != NULL && yCursor < ny) {
1309     fftw_complex* pcIn = new fftw_complex [nx];
1310     
1311     int i;
1312     for (i = 0; i < nx; i++) {
1313       pcIn[i].re = v[i][yCursor];
1314       if (rIF.isComplex())
1315         pcIn[i].im = vImag[i][yCursor];
1316       else
1317         pcIn[i].im = 0;
1318     }
1319     
1320     fftw_plan plan = fftw_create_plan (nx, FFTW_FORWARD, FFTW_IN_PLACE);
1321     fftw_one (plan, pcIn, NULL);
1322     fftw_destroy_plan (plan);
1323     
1324     double* pX = new double [nx];
1325     double* pYReal = new double [nx];
1326     double* pYImag = new double [nx];
1327     double* pYMag = new double [nx];
1328     for (i = 0; i < nx; i++) {
1329       pX[i] = i;
1330       pYReal[i] = pcIn[i].re;
1331       pYImag[i] = pcIn[i].im;
1332       pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1333     }
1334     Fourier::shuffleFourierToNaturalOrder (pYReal, nx);
1335     Fourier::shuffleFourierToNaturalOrder (pYImag, nx);
1336     Fourier::shuffleFourierToNaturalOrder (pYMag, nx);
1337     
1338     PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1339     if (! pPlotDoc) {
1340       sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1341     } else {
1342       PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1343       std::ostringstream os;
1344       os << "Row " << yCursor;
1345       std::string title("title ");
1346       title += os.str();
1347       rPlotFile.addEzsetCommand (title.c_str());
1348       rPlotFile.addEzsetCommand ("xlabel Column");
1349       rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1350       rPlotFile.addEzsetCommand ("lxfrac 0");
1351       rPlotFile.addEzsetCommand ("curve 1");
1352       rPlotFile.addEzsetCommand ("color 1");
1353       rPlotFile.addEzsetCommand ("dash 1");
1354       rPlotFile.addEzsetCommand ("curve 2");
1355       rPlotFile.addEzsetCommand ("color 4");
1356       rPlotFile.addEzsetCommand ("dash 3");
1357       rPlotFile.addEzsetCommand ("curve 3");
1358       rPlotFile.addEzsetCommand ("color 0");
1359       rPlotFile.addEzsetCommand ("solid");
1360       rPlotFile.addEzsetCommand ("box");
1361       rPlotFile.addEzsetCommand ("grid");
1362       rPlotFile.setCurveSize (4, nx);
1363       rPlotFile.addColumn (0, pX);
1364       rPlotFile.addColumn (1, pYReal);
1365       rPlotFile.addColumn (2, pYImag);
1366       rPlotFile.addColumn (3, pYMag);
1367       for (int iL = 0; iL < rIF.nLabels(); iL++)
1368         rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1369       os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1370       *theApp->getLog() << os.str().c_str() << "\n";
1371       rPlotFile.addDescription (os.str().c_str());
1372     }
1373     delete pX;
1374     delete pYReal;
1375     delete pYImag;
1376     delete pYMag;
1377     delete [] pcIn;
1378     
1379     pPlotDoc->Modify (true);
1380     pPlotDoc->UpdateAllViews ();
1381     pPlotDoc->getView()->OnUpdate (this, NULL);
1382     pPlotDoc->getView()->getFrame()->Show(true);
1383   }
1384 }
1385
1386 void
1387 ImageFileView::OnPlotFFTCol (wxCommandEvent& event)
1388 {
1389   int xCursor, yCursor;
1390   if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1391     wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1392     return;
1393   }
1394   
1395   const ImageFile& rIF = GetDocument()->getImageFile();
1396   ImageFileArrayConst v = rIF.getArray();
1397   ImageFileArrayConst vImag = rIF.getImaginaryArray();
1398   int nx = rIF.nx();
1399   int ny = rIF.ny();
1400   
1401   if (v != NULL && xCursor < nx) {
1402     fftw_complex* pcIn = new fftw_complex [ny];
1403     double *pdTemp = new double [ny];
1404     
1405     int i;
1406     for (i = 0; i < ny; i++)
1407       pdTemp[i] = v[xCursor][i];
1408     Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1409     for (i = 0; i < ny; i++) 
1410       pcIn[i].re = pdTemp[i];
1411     
1412     for (i = 0; i < ny; i++) {
1413       if (rIF.isComplex())
1414         pdTemp[i] = vImag[xCursor][i];
1415       else
1416         pdTemp[i] = 0;
1417     }
1418     Fourier::shuffleNaturalToFourierOrder (pdTemp, ny);
1419     for (i = 0; i < ny; i++)
1420       pcIn[i].im = pdTemp[i];
1421     
1422     fftw_plan plan = fftw_create_plan (ny, FFTW_BACKWARD, FFTW_IN_PLACE);
1423     fftw_one (plan, pcIn, NULL);
1424     fftw_destroy_plan (plan);
1425     
1426     double* pX = new double [ny];
1427     double* pYReal = new double [ny];
1428     double* pYImag = new double [ny];
1429     double* pYMag = new double [ny];
1430     for (i = 0; i < ny; i++) {
1431       pX[i] = i;
1432       pYReal[i] = pcIn[i].re;
1433       pYImag[i] = pcIn[i].im;
1434       pYMag[i] = ::sqrt (pcIn[i].re * pcIn[i].re + pcIn[i].im * pcIn[i].im);
1435     }
1436     
1437     PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1438     if (! pPlotDoc) {
1439       sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1440     } else {
1441       PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1442       std::ostringstream os;
1443       os << "Column " << xCursor;
1444       std::string title("title ");
1445       title += os.str();
1446       rPlotFile.addEzsetCommand (title.c_str());
1447       rPlotFile.addEzsetCommand ("xlabel Column");
1448       rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1449       rPlotFile.addEzsetCommand ("lxfrac 0");
1450       rPlotFile.addEzsetCommand ("curve 1");
1451       rPlotFile.addEzsetCommand ("color 1");
1452       rPlotFile.addEzsetCommand ("dash 1");
1453       rPlotFile.addEzsetCommand ("curve 2");
1454       rPlotFile.addEzsetCommand ("color 4");
1455       rPlotFile.addEzsetCommand ("dash 3");
1456       rPlotFile.addEzsetCommand ("curve 3");
1457       rPlotFile.addEzsetCommand ("color 0");
1458       rPlotFile.addEzsetCommand ("solid");
1459       rPlotFile.addEzsetCommand ("box");
1460       rPlotFile.addEzsetCommand ("grid");
1461       rPlotFile.setCurveSize (4, ny);
1462       rPlotFile.addColumn (0, pX);
1463       rPlotFile.addColumn (1, pYReal);
1464       rPlotFile.addColumn (2, pYImag);
1465       rPlotFile.addColumn (3, pYMag);
1466       for (int iL = 0; iL < rIF.nLabels(); iL++)
1467         rPlotFile.addDescription (rIF.labelGet(iL).getLabelString().c_str());
1468       os << " FFT Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1469       *theApp->getLog() << os.str().c_str() << "\n";
1470       rPlotFile.addDescription (os.str().c_str());
1471     }
1472     delete pX;
1473     delete pYReal;
1474     delete pYImag;
1475     delete pYMag;
1476     delete pdTemp;
1477     delete [] pcIn;
1478     
1479     pPlotDoc->Modify (true);
1480     pPlotDoc->UpdateAllViews ();
1481     pPlotDoc->getView()->OnUpdate (this, NULL);
1482     pPlotDoc->getView()->getFrame()->Show(true);
1483   }
1484 }
1485 #endif
1486
1487 void
1488 ImageFileView::OnCompareCol (wxCommandEvent& event)
1489 {
1490   int xCursor, yCursor;
1491   if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1492     wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1493     return;
1494   }
1495   
1496   std::vector<ImageFileDocument*> vecIFDoc;
1497   theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1498   if (vecIFDoc.size() == 0) {
1499     wxMessageBox ("No compatible images for Column Comparison", "Error");
1500     return;
1501   }
1502   DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1503   
1504   if (dialogGetCompare.ShowModal() == wxID_OK) {
1505     ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1506     const ImageFile& rIF = GetDocument()->getImageFile();
1507     const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1508     
1509     ImageFileArrayConst v1 = rIF.getArray();
1510     ImageFileArrayConst v2 = rCompareIF.getArray();
1511     int nx = rIF.nx();
1512     int ny = rIF.ny();
1513     
1514     if (v1 != NULL && xCursor < nx) {
1515       double* pX = new double [ny];
1516       double* pY1 = new double [ny];
1517       double* pY2 = new double [ny];
1518       for (int i = 0; i < ny; i++) {
1519         pX[i] = i;
1520         pY1[i] = v1[xCursor][i];
1521         pY2[i] = v2[xCursor][i];
1522       }
1523       PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1524       if (! pPlotDoc) {
1525         sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1526       } else {
1527         PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1528         std::ostringstream os;
1529         os << "Column " << xCursor << " Comparison";
1530         std::string title("title ");
1531         title += os.str();
1532         rPlotFile.addEzsetCommand (title.c_str());
1533         rPlotFile.addEzsetCommand ("xlabel Row");
1534         rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1535         rPlotFile.addEzsetCommand ("lxfrac 0");
1536         rPlotFile.addEzsetCommand ("curve 1");
1537         rPlotFile.addEzsetCommand ("color 2");
1538         rPlotFile.addEzsetCommand ("curve 2");
1539         rPlotFile.addEzsetCommand ("color 4");
1540         rPlotFile.addEzsetCommand ("dash 5");
1541         rPlotFile.addEzsetCommand ("box");
1542         rPlotFile.addEzsetCommand ("grid");
1543         rPlotFile.setCurveSize (3, ny);
1544         rPlotFile.addColumn (0, pX);
1545         rPlotFile.addColumn (1, pY1);
1546         rPlotFile.addColumn (2, pY2);
1547         
1548         unsigned int iL;
1549         for (iL = 0; iL < rIF.nLabels(); iL++) {
1550           std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1551           s += ": ";
1552           s += rIF.labelGet(iL).getLabelString();
1553           rPlotFile.addDescription (s.c_str());
1554         }
1555         for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1556           std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1557           s += ": ";
1558           s += rCompareIF.labelGet(iL).getLabelString();
1559           rPlotFile.addDescription (s.c_str());
1560         }
1561         os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1562           << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1563         *theApp->getLog() << os.str().c_str() << "\n";
1564         rPlotFile.addDescription (os.str().c_str());
1565       }
1566       delete pX;
1567       delete pY1;
1568       delete pY2;
1569       pPlotDoc->Modify (true);
1570       pPlotDoc->UpdateAllViews ();
1571       pPlotDoc->getView()->OnUpdate (this, NULL);
1572       pPlotDoc->getView()->getFrame()->Show(true);
1573     }
1574   }
1575 }
1576
1577 void
1578 ImageFileView::OnCompareRow (wxCommandEvent& event)
1579 {
1580   int xCursor, yCursor;
1581   if (! m_pCanvas->GetCurrentCursor (xCursor, yCursor)) {
1582     wxMessageBox ("No column selected. Please use left mouse button on image to select column","Error");
1583     return;
1584   }
1585   
1586   std::vector<ImageFileDocument*> vecIFDoc;
1587   theApp->getCompatibleImages (GetDocument(), vecIFDoc);
1588   
1589   if (vecIFDoc.size() == 0) {
1590     wxMessageBox ("No compatible images for Row Comparison", "Error");
1591     return;
1592   }
1593   
1594   DialogGetComparisonImage dialogGetCompare (getFrameForChild(), "Get Comparison Image", vecIFDoc, false);
1595   
1596   if (dialogGetCompare.ShowModal() == wxID_OK) {
1597     ImageFileDocument* pCompareDoc = dialogGetCompare.getImageFileDocument();
1598     const ImageFile& rIF = GetDocument()->getImageFile();
1599     const ImageFile& rCompareIF = pCompareDoc->getImageFile();
1600     
1601     ImageFileArrayConst v1 = rIF.getArray();
1602     ImageFileArrayConst v2 = rCompareIF.getArray();
1603     int nx = rIF.nx();
1604     int ny = rIF.ny();
1605     
1606     if (v1 != NULL && yCursor < ny) {
1607       double* pX = new double [nx];
1608       double* pY1 = new double [nx];
1609       double* pY2 = new double [nx];
1610       for (int i = 0; i < nx; i++) {
1611         pX[i] = i;
1612         pY1[i] = v1[i][yCursor];
1613         pY2[i] = v2[i][yCursor];
1614       }
1615       PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1616       if (! pPlotDoc) {
1617         sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1618       } else {
1619         PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1620         std::ostringstream os;
1621         os << "Row " << yCursor << " Comparison";
1622         std::string title("title ");
1623         title += os.str();
1624         rPlotFile.addEzsetCommand (title.c_str());
1625         rPlotFile.addEzsetCommand ("xlabel Column");
1626         rPlotFile.addEzsetCommand ("ylabel Pixel Value");
1627         rPlotFile.addEzsetCommand ("lxfrac 0");
1628         rPlotFile.addEzsetCommand ("curve 1");
1629         rPlotFile.addEzsetCommand ("color 2");
1630         rPlotFile.addEzsetCommand ("curve 2");
1631         rPlotFile.addEzsetCommand ("color 4");
1632         rPlotFile.addEzsetCommand ("dash 5");
1633         rPlotFile.addEzsetCommand ("box");
1634         rPlotFile.addEzsetCommand ("grid");
1635         rPlotFile.setCurveSize (3, nx);
1636         rPlotFile.addColumn (0, pX);
1637         rPlotFile.addColumn (1, pY1);
1638         rPlotFile.addColumn (2, pY2);
1639         unsigned int iL;
1640         for (iL = 0; iL < rIF.nLabels(); iL++) {
1641           std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1642           s += ": ";
1643           s += rIF.labelGet(iL).getLabelString();
1644           rPlotFile.addDescription (s.c_str());
1645         }
1646         for (iL = 0; iL < rCompareIF.nLabels(); iL++) {
1647           std::string s = pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1648           s += ": ";
1649           s += rCompareIF.labelGet(iL).getLabelString();
1650           rPlotFile.addDescription (s.c_str());
1651         }
1652         os << " Between " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str() << " and "
1653           << pCompareDoc->GetFirstView()->GetFrame()->GetTitle().c_str();
1654         *theApp->getLog() << os.str().c_str() << "\n";
1655         rPlotFile.addDescription (os.str().c_str());
1656       }
1657       delete pX;
1658       delete pY1;
1659       delete pY2;
1660       pPlotDoc->Modify (true);
1661       pPlotDoc->UpdateAllViews ();
1662       pPlotDoc->getView()->OnUpdate (this, NULL);
1663       pPlotDoc->getView()->getFrame()->Show(true);
1664     }
1665   }
1666 }
1667
1668 static int NUMBER_HISTOGRAM_BINS = 256;
1669
1670 void
1671 ImageFileView::OnPlotHistogram (wxCommandEvent& event)
1672
1673   const ImageFile& rIF = GetDocument()->getImageFile();
1674   ImageFileArrayConst v = rIF.getArray();
1675   int nx = rIF.nx();
1676   int ny = rIF.ny();
1677   
1678   if (v != NULL && nx > 0 && ny > 0) {
1679     PlotFileDocument* pPlotDoc = theApp->newPlotDoc();
1680     if (! pPlotDoc) {
1681       sys_error (ERR_SEVERE, "Internal error: unable to create Plot file");
1682       return;
1683     }
1684     
1685     double* pX = new double [NUMBER_HISTOGRAM_BINS];
1686     double* pY = new double [NUMBER_HISTOGRAM_BINS];
1687     double dMin, dMax;
1688     rIF.getMinMax (dMin, dMax);
1689     double dBinWidth = (dMax - dMin) / NUMBER_HISTOGRAM_BINS;
1690     
1691     for (int i = 0; i < NUMBER_HISTOGRAM_BINS; i++) {
1692       pX[i] = dMin + (i + 0.5) * dBinWidth;
1693       pY[i] = 0;
1694     }
1695     for (int ix = 0; ix < nx; ix++)
1696       for (int iy = 0; iy < ny; iy++) {
1697         int iBin = nearest<int> ((v[ix][iy] - dMin) / dBinWidth);
1698         if (iBin >= 0 && iBin < NUMBER_HISTOGRAM_BINS)
1699           pY[iBin] += 1;
1700       }
1701       
1702       PlotFile& rPlotFile = pPlotDoc->getPlotFile();
1703       std::ostringstream os;
1704       os << "Histogram";
1705       std::string title("title ");
1706       title += os.str();
1707       rPlotFile.addEzsetCommand (title.c_str());
1708       rPlotFile.addEzsetCommand ("xlabel Pixel Value");
1709       rPlotFile.addEzsetCommand ("ylabel Count");
1710       rPlotFile.addEzsetCommand ("box");
1711       rPlotFile.addEzsetCommand ("grid");
1712       rPlotFile.setCurveSize (2, NUMBER_HISTOGRAM_BINS);
1713       rPlotFile.addColumn (0, pX);
1714       rPlotFile.addColumn (1, pY);
1715       for (unsigned int iL = 0; iL < rIF.nLabels(); iL++) {
1716         std::string s = GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1717         s += ": ";
1718         s += rIF.labelGet(iL).getLabelString();
1719         rPlotFile.addDescription (s.c_str());
1720       }
1721       os << " Plot of " << GetDocument()->GetFirstView()->GetFrame()->GetTitle().c_str();
1722       *theApp->getLog() << os.str().c_str() << "\n";
1723       rPlotFile.addDescription (os.str().c_str());
1724       delete pX;
1725       delete pY;
1726       pPlotDoc->Modify (true);
1727       pPlotDoc->UpdateAllViews ();
1728       pPlotDoc->getView()->OnUpdate (this, NULL);
1729       pPlotDoc->getView()->getFrame()->Show(true);
1730   }
1731 }
1732
1733
1734 // PhantomCanvas
1735
1736 PhantomCanvas::PhantomCanvas (PhantomFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
1737 : wxScrolledWindow(frame, -1, pos, size, style)
1738 {
1739   m_pView = v;
1740 }
1741
1742 PhantomCanvas::~PhantomCanvas ()
1743 {
1744   m_pView = NULL;
1745 }
1746
1747 void 
1748 PhantomCanvas::OnDraw (wxDC& dc)
1749 {
1750   if (m_pView)
1751     m_pView->OnDraw(& dc);
1752 }
1753
1754
1755 // PhantomFileView
1756
1757 IMPLEMENT_DYNAMIC_CLASS(PhantomFileView, wxView)
1758
1759 BEGIN_EVENT_TABLE(PhantomFileView, wxView)
1760 EVT_MENU(PHMMENU_FILE_PROPERTIES, PhantomFileView::OnProperties)
1761 EVT_MENU(PHMMENU_PROCESS_RASTERIZE, PhantomFileView::OnRasterize)
1762 EVT_MENU(PHMMENU_PROCESS_PROJECTIONS, PhantomFileView::OnProjections)
1763 END_EVENT_TABLE()
1764
1765 PhantomFileView::PhantomFileView() 
1766 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pFileMenu(0)
1767 {
1768 #if defined(DEBUG) || defined(_DEBUG)
1769   m_iDefaultNDet = 165;
1770   m_iDefaultNView = 180;
1771 #else
1772   m_iDefaultNDet = 367;
1773   m_iDefaultNView = 320;
1774 #endif
1775   m_iDefaultNSample = 1;
1776   m_dDefaultRotation = 1;
1777   m_dDefaultFocalLength = 2;
1778   m_dDefaultFieldOfView = 1;
1779   m_iDefaultGeometry = Scanner::GEOMETRY_PARALLEL;
1780   m_iDefaultTrace = Trace::TRACE_NONE;
1781   
1782 #ifdef DEBUG 
1783   m_iDefaultRasterNX = 115;
1784   m_iDefaultRasterNY = 115;
1785   m_iDefaultRasterNSamples = 1;
1786 #else
1787   m_iDefaultRasterNX = 256;
1788   m_iDefaultRasterNY = 256;
1789   m_iDefaultRasterNSamples = 2;
1790 #endif
1791 }
1792
1793 PhantomFileView::~PhantomFileView()
1794 {
1795   GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
1796   GetDocumentManager()->ActivateView(this, FALSE, TRUE);
1797 }
1798
1799 void
1800 PhantomFileView::OnProperties (wxCommandEvent& event)
1801 {
1802   const int idPhantom = GetDocument()->getPhantomID();
1803   const wxString& namePhantom = GetDocument()->getPhantomName();
1804   std::ostringstream os;
1805   os << "Phantom " << namePhantom.c_str() << " (" << idPhantom << ")" << "\n";
1806   const Phantom& rPhantom = GetDocument()->getPhantom();
1807   rPhantom.printDefinitions (os);
1808 #if DEBUG
1809   rPhantom.print (os);
1810 #endif
1811   *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
1812   wxMessageBox (os.str().c_str(), "Phantom Properties");
1813 }
1814
1815
1816 void
1817 PhantomFileView::OnProjections (wxCommandEvent& event)
1818 {
1819   DialogGetProjectionParameters dialogProjection (getFrameForChild(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView, m_iDefaultGeometry, m_iDefaultTrace);
1820   int retVal = dialogProjection.ShowModal();
1821   if (retVal == wxID_OK) {
1822     m_iDefaultNDet = dialogProjection.getNDet();
1823     m_iDefaultNView = dialogProjection.getNView();
1824     m_iDefaultNSample = dialogProjection.getNSamples();
1825     m_iDefaultTrace = dialogProjection.getTrace();
1826     m_dDefaultRotation = dialogProjection.getRotAngle();
1827     m_dDefaultFocalLength = dialogProjection.getFocalLengthRatio();
1828     m_dDefaultFieldOfView = dialogProjection.getFieldOfViewRatio();
1829     wxString sGeometry = dialogProjection.getGeometry();
1830     m_iDefaultGeometry = Scanner::convertGeometryNameToID (sGeometry.c_str());
1831     
1832     if (m_iDefaultNDet > 0 && m_iDefaultNView > 0 && sGeometry != "") {
1833       const Phantom& rPhantom = GetDocument()->getPhantom();
1834       Projections* pProj = new Projections;
1835       Scanner theScanner (rPhantom, sGeometry.c_str(), m_iDefaultNDet, m_iDefaultNView, m_iDefaultNSample, 
1836                           m_dDefaultRotation, m_dDefaultFocalLength, m_dDefaultFieldOfView);
1837       if (theScanner.fail()) {
1838         *theApp->getLog() << "Failed making scanner: " << theScanner.failMessage().c_str() << "\n";
1839         return;
1840       }
1841       pProj->initFromScanner (theScanner);
1842       m_dDefaultRotation /= PI;  // convert back to PI units
1843       
1844       Timer timer;
1845       if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
1846         ProjectionsDialog dialogProjections (theScanner, *pProj, rPhantom, m_iDefaultTrace, dynamic_cast<wxWindow*>(getFrameForChild()));
1847         for (int iView = 0; iView < pProj->nView(); iView++) {
1848           ::wxYield();
1849           if (dialogProjections.isCancelled() || ! dialogProjections.projectView (iView)) {
1850             delete pProj;
1851             return;
1852           }
1853           ::wxYield();
1854           while (dialogProjections.isPaused()) {
1855             ::wxYield();
1856             ::wxUsleep(50);
1857           }
1858         }
1859       } else {
1860         wxProgressDialog dlgProgress (wxString("Projection"), wxString("Projection Progress"), pProj->nView() + 1, getFrameForChild(), wxPD_CAN_ABORT);
1861         for (int i = 0; i < pProj->nView(); i++) {
1862           theScanner.collectProjections (*pProj, rPhantom, i, 1, true, m_iDefaultTrace);
1863           if (! dlgProgress.Update (i+1)) {
1864             delete pProj;
1865             return;
1866           }
1867         }
1868       }
1869       
1870       std::ostringstream os;
1871       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();
1872       pProj->setCalcTime (timer.timerEnd());
1873       pProj->setRemark (os.str());
1874       *theApp->getLog() << os.str().c_str() << "\n";
1875       
1876       ::wxYield();
1877       ProjectionFileDocument* pProjectionDoc = theApp->newProjectionDoc();
1878       if (! pProjectionDoc) {
1879         sys_error (ERR_SEVERE, "Unable to create projection document");
1880         return;
1881       }
1882       pProjectionDoc->setProjections (pProj);
1883       ProjectionFileView* projView = pProjectionDoc->getView();
1884       if (projView) {
1885         projView->OnUpdate (projView, NULL);
1886         if (projView->getCanvas())
1887               projView->getCanvas()->SetClientSize (m_iDefaultNDet, m_iDefaultNView);
1888         if (wxFrame* pFrame = projView->getFrame()) {
1889           pFrame->Show(true);
1890           pFrame->SetFocus();
1891           pFrame->Raise();
1892         }
1893         GetDocumentManager()->ActivateView (projView, true, false);
1894       }
1895       ::wxYield();
1896       pProjectionDoc-> Modify(true);
1897       pProjectionDoc->UpdateAllViews (this);
1898     }
1899   }
1900 }
1901
1902
1903 void
1904 PhantomFileView::OnRasterize (wxCommandEvent& event)
1905 {
1906   DialogGetRasterParameters dialogRaster (getFrameForChild(), m_iDefaultRasterNX, m_iDefaultRasterNY, m_iDefaultRasterNSamples);
1907   int retVal = dialogRaster.ShowModal();
1908   if (retVal == wxID_OK) {
1909     m_iDefaultRasterNX = dialogRaster.getXSize();
1910     m_iDefaultRasterNY  = dialogRaster.getYSize();
1911     m_iDefaultRasterNSamples = dialogRaster.getNSamples();
1912     if (m_iDefaultRasterNSamples < 1)
1913       m_iDefaultRasterNSamples = 1;
1914     if (m_iDefaultRasterNX > 0 && m_iDefaultRasterNY > 0) {
1915       const Phantom& rPhantom = GetDocument()->getPhantom();
1916
1917       ImageFile* pImageFile = new ImageFile;
1918       
1919       pImageFile->setArraySize (m_iDefaultRasterNX, m_iDefaultRasterNY);
1920       wxProgressDialog dlgProgress (wxString("Rasterize"), wxString("Rasterization Progress"), 
1921                                     pImageFile->nx() + 1, getFrameForChild(), wxPD_CAN_ABORT);
1922       Timer timer;
1923       for (unsigned int i = 0; i < pImageFile->nx(); i++) {
1924         rPhantom.convertToImagefile (*pImageFile, m_iDefaultRasterNSamples, Trace::TRACE_NONE, i, 1, true);
1925         if (! dlgProgress.Update (i+1)) {
1926           delete pImageFile;
1927           return;
1928         }
1929       }
1930
1931       ImageFileDocument* pRasterDoc = theApp->newImageDoc();
1932       if (! pRasterDoc) {
1933         sys_error (ERR_SEVERE, "Unable to create image file");
1934         return;
1935       }
1936       pRasterDoc->setImageFile (pImageFile);
1937
1938       pRasterDoc->Modify (true);
1939       pRasterDoc->UpdateAllViews (this);
1940       pRasterDoc->getView()->getFrame()->Show(true);
1941       std::ostringstream os;
1942       os << "Rasterize Phantom " << rPhantom.name() << ": XSize=" << m_iDefaultRasterNX << ", YSize=" 
1943         << m_iDefaultRasterNY << ", nSamples=" << m_iDefaultRasterNSamples;
1944       *theApp->getLog() << os.str().c_str() << "\n";
1945       pImageFile->labelAdd (os.str().c_str(), timer.timerEnd());
1946       ImageFileView* rasterView = pRasterDoc->getView();
1947       if (rasterView) {
1948         rasterView->getFrame()->SetFocus();
1949         rasterView->OnUpdate (rasterView, NULL);
1950       }
1951       
1952     }
1953   }
1954 }
1955
1956
1957 PhantomCanvas* 
1958 PhantomFileView::CreateCanvas (wxFrame *parent)
1959 {
1960   PhantomCanvas* pCanvas;
1961   int width, height;
1962   parent->GetClientSize(&width, &height);
1963   
1964   pCanvas = new PhantomCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
1965   
1966   pCanvas->SetBackgroundColour(*wxWHITE);
1967   pCanvas->Clear();
1968   
1969   return pCanvas;
1970 }
1971
1972 #if CTSIM_MDI
1973 wxDocMDIChildFrame*
1974 #else
1975 wxDocChildFrame*
1976 #endif
1977 PhantomFileView::CreateChildFrame(wxDocument *doc, wxView *view)
1978 {
1979 #if CTSIM_MDI
1980   wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
1981 #else
1982   wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Phantom Frame", wxPoint(10, 10), wxSize(256, 256), wxDEFAULT_FRAME_STYLE);
1983 #endif
1984   theApp->setIconForFrame (subframe);
1985   
1986   m_pFileMenu = new wxMenu;
1987   
1988   m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
1989   m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
1990   m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
1991   m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
1992   m_pFileMenu->Append(wxID_CLOSE, "&Close");
1993   
1994   m_pFileMenu->AppendSeparator();
1995   m_pFileMenu->Append(PHMMENU_FILE_PROPERTIES, "P&roperties");
1996   
1997   m_pFileMenu->AppendSeparator();
1998   m_pFileMenu->Append(wxID_PRINT, "&Print...");
1999   m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2000   m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2001 #ifdef CTSIM_MDI
2002   m_pFileMenu->AppendSeparator();
2003   m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2004 #endif
2005   GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2006   GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2007   
2008   wxMenu *process_menu = new wxMenu;
2009   process_menu->Append(PHMMENU_PROCESS_RASTERIZE, "&Rasterize...\tCtrl-R");
2010   process_menu->Append(PHMMENU_PROCESS_PROJECTIONS, "&Projections...\tCtrl-J");
2011   
2012   wxMenu *help_menu = new wxMenu;
2013   help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2014   help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
2015   help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2016   
2017   wxMenuBar *menu_bar = new wxMenuBar;
2018   
2019   menu_bar->Append(m_pFileMenu, "&File");
2020   menu_bar->Append(process_menu, "&Process");
2021   menu_bar->Append(help_menu, "&Help");
2022   
2023   subframe->SetMenuBar(menu_bar);
2024   subframe->Centre(wxBOTH);
2025   
2026   wxAcceleratorEntry accelEntries[8];
2027   accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
2028   accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
2029   accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
2030   accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
2031   accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
2032   accelEntries[5].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
2033   accelEntries[6].Set (wxACCEL_CTRL, static_cast<int>('J'), PHMMENU_PROCESS_PROJECTIONS);
2034   accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('R'), PHMMENU_PROCESS_RASTERIZE);
2035   wxAcceleratorTable accelTable (8, accelEntries);
2036   subframe->SetAcceleratorTable (accelTable);
2037   
2038   return subframe;
2039 }
2040
2041
2042 bool 
2043 PhantomFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2044 {
2045   m_pFrame = CreateChildFrame(doc, this);
2046   SetFrame(m_pFrame);
2047   
2048   int width, height;
2049   m_pFrame->GetClientSize(&width, &height);
2050   m_pFrame->SetTitle("PhantomFileView");
2051   m_pCanvas = CreateCanvas (m_pFrame);
2052   
2053 #ifdef __X__
2054   int x, y;  // X requires a forced resize
2055   m_pFrame->GetSize(&x, &y);
2056   m_pFrame->SetSize(-1, -1, x, y);
2057 #endif
2058   
2059   m_pFrame->Show(true);
2060   Activate(true);
2061   
2062   return true;
2063 }
2064
2065 void 
2066 PhantomFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2067 {
2068   if (m_pCanvas)
2069     m_pCanvas->Refresh();
2070 }
2071
2072 bool 
2073 PhantomFileView::OnClose (bool deleteWindow)
2074 {
2075   //GetDocumentManager()->ActivateView (this, false, true);
2076   if (! GetDocument() || ! GetDocument()->Close())
2077     return false;
2078   
2079   Activate(false);
2080   if (m_pCanvas) {
2081     m_pCanvas->setView(NULL);
2082     m_pCanvas = NULL;
2083   }
2084   wxString s(wxTheApp->GetAppName());
2085   if (m_pFrame)
2086     m_pFrame->SetTitle(s);
2087   
2088   SetFrame(NULL);
2089   
2090   if (deleteWindow) {
2091     delete m_pFrame;
2092     m_pFrame = NULL;
2093     if (GetDocument() && GetDocument()->getBadFileOpen())
2094       ::wxYield();  // wxWindows bug workaround
2095   }
2096   
2097   return true;
2098 }
2099
2100 void
2101 PhantomFileView::OnDraw (wxDC* dc)
2102 {
2103   int xsize, ysize;
2104   m_pCanvas->GetClientSize (&xsize, &ysize);
2105   SGPDriver driver (dc, xsize, ysize);
2106   SGP sgp (driver);
2107   const Phantom& rPhantom = GetDocument()->getPhantom();
2108   sgp.setColor (C_RED);
2109   rPhantom.show (sgp);
2110 }
2111
2112 // ProjectionCanvas
2113
2114 ProjectionFileCanvas::ProjectionFileCanvas (ProjectionFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2115 : wxScrolledWindow(frame, -1, pos, size, style)
2116 {
2117   m_pView = v;
2118 }
2119
2120 ProjectionFileCanvas::~ProjectionFileCanvas ()
2121 {
2122   m_pView = NULL;
2123 }
2124
2125 void 
2126 ProjectionFileCanvas::OnDraw(wxDC& dc)
2127 {
2128   if (m_pView)
2129     m_pView->OnDraw(& dc);
2130 }
2131
2132 wxSize
2133 ProjectionFileCanvas::GetBestSize () const
2134 {
2135   wxSize best (0, 0);
2136   if (m_pView) {
2137     Projections& rProj = m_pView->GetDocument()->getProjections();
2138     best.Set (rProj.nDet(), rProj.nView());
2139   }
2140   
2141   return best;
2142 }
2143
2144
2145 // ProjectionFileView
2146
2147 IMPLEMENT_DYNAMIC_CLASS(ProjectionFileView, wxView)
2148
2149 BEGIN_EVENT_TABLE(ProjectionFileView, wxView)
2150 EVT_MENU(PJMENU_FILE_PROPERTIES, ProjectionFileView::OnProperties)
2151 EVT_MENU(PJMENU_RECONSTRUCT_FBP, ProjectionFileView::OnReconstructFBP)
2152 EVT_MENU(PJMENU_CONVERT_POLAR, ProjectionFileView::OnConvertPolar)
2153 EVT_MENU(PJMENU_CONVERT_FFT_POLAR, ProjectionFileView::OnConvertFFTPolar)
2154 END_EVENT_TABLE()
2155
2156 ProjectionFileView::ProjectionFileView() 
2157 : wxView(), m_pCanvas(NULL), m_pFrame(NULL), m_pFileMenu(0)
2158 {
2159 #ifdef DEBUG
2160   m_iDefaultNX = 115;
2161   m_iDefaultNY = 115;
2162 #else
2163   m_iDefaultNX = 256;
2164   m_iDefaultNY = 256;
2165 #endif
2166   
2167   m_iDefaultFilter = SignalFilter::FILTER_ABS_BANDLIMIT;
2168   m_dDefaultFilterParam = 1.;
2169 #if HAVE_FFTW
2170   m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_RFFTW;
2171   m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_INVERSE_FOURIER;
2172 #else
2173   m_iDefaultFilterMethod = ProcessSignal::FILTER_METHOD_CONVOLUTION;
2174   m_iDefaultFilterGeneration = ProcessSignal::FILTER_GENERATION_DIRECT;
2175 #endif
2176   m_iDefaultZeropad = 1;
2177   m_iDefaultBackprojector = Backprojector::BPROJ_IDIFF3;
2178   m_iDefaultInterpolation = Backprojector::INTERP_LINEAR;
2179   m_iDefaultInterpParam = 1;
2180   m_iDefaultTrace = Trace::TRACE_NONE;
2181   
2182   m_iDefaultPolarNX = 256;
2183   m_iDefaultPolarNY = 256;
2184   m_iDefaultPolarInterpolation = Projections::POLAR_INTERP_BILINEAR;
2185   m_iDefaultPolarZeropad = 1;
2186 }
2187
2188 ProjectionFileView::~ProjectionFileView()
2189 {
2190   GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2191   GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2192 }
2193
2194 void
2195 ProjectionFileView::OnProperties (wxCommandEvent& event)
2196 {
2197   const Projections& rProj = GetDocument()->getProjections();
2198   std::ostringstream os;
2199   rProj.printScanInfo(os);
2200   *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<\n";
2201   wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Projection File Properties", wxOK | wxICON_INFORMATION);
2202   dialogMsg.ShowModal();
2203 }
2204
2205
2206 void
2207 ProjectionFileView::OnConvertPolar (wxCommandEvent& event)
2208 {
2209   Projections& rProj = GetDocument()->getProjections();
2210   DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2211     m_iDefaultPolarInterpolation, -1);
2212   if (dialogPolar.ShowModal() == wxID_OK) {
2213     wxString strInterpolation (dialogPolar.getInterpolationName());
2214     m_iDefaultPolarNX = dialogPolar.getXSize();
2215     m_iDefaultPolarNY = dialogPolar.getYSize();
2216     ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2217     ImageFile& rIF = pPolarDoc->getImageFile();
2218     if (! pPolarDoc) {
2219       sys_error (ERR_SEVERE, "Unable to create image file");
2220       return;
2221     }
2222     rIF.setArraySize (m_iDefaultPolarNX, m_iDefaultPolarNY);
2223     m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2224     rProj.convertPolar (rIF, m_iDefaultPolarInterpolation);
2225     rIF.labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2226     std::ostringstream os;
2227     os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to polar image: xSize=" 
2228       << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation=" 
2229       << strInterpolation.c_str();
2230     *theApp->getLog() << os.str().c_str() << "\n";
2231     rIF.labelAdd (os.str().c_str());
2232     pPolarDoc->Modify (true);
2233     pPolarDoc->UpdateAllViews ();
2234     pPolarDoc->getView()->OnUpdate (this, NULL);
2235     pPolarDoc->getView()->getFrame()->Show(true);
2236   }
2237 }
2238
2239 void
2240 ProjectionFileView::OnConvertFFTPolar (wxCommandEvent& event)
2241 {
2242   Projections& rProj = GetDocument()->getProjections();
2243   DialogGetConvertPolarParameters dialogPolar (getFrameForChild(), "Convert to FFT Polar", m_iDefaultPolarNX, m_iDefaultPolarNY,
2244     m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad);
2245   if (dialogPolar.ShowModal() == wxID_OK) {
2246     wxString strInterpolation (dialogPolar.getInterpolationName());
2247     m_iDefaultPolarNX = dialogPolar.getXSize();
2248     m_iDefaultPolarNY = dialogPolar.getYSize();
2249     m_iDefaultPolarZeropad = dialogPolar.getZeropad();
2250     ImageFileDocument* pPolarDoc = theApp->newImageDoc();
2251     ImageFile& rIF = pPolarDoc->getImageFile();
2252     if (! pPolarDoc) {
2253       sys_error (ERR_SEVERE, "Unable to create image file");
2254       return;
2255     }
2256     rIF.setArraySize (m_iDefaultPolarNX, m_iDefaultPolarNY);
2257     m_iDefaultPolarInterpolation = Projections::convertInterpNameToID (strInterpolation.c_str());
2258     rProj.convertFFTPolar (rIF, m_iDefaultPolarInterpolation, m_iDefaultPolarZeropad);
2259     rIF.labelAdd (rProj.getLabel().getLabelString().c_str(), rProj.calcTime());
2260     std::ostringstream os;
2261     os << "Convert projection file " << GetFrame()->GetTitle().c_str() << " to FFT polar image: xSize=" 
2262       << m_iDefaultPolarNX << ", ySize=" << m_iDefaultPolarNY << ", interpolation=" 
2263       << strInterpolation.c_str() << ", zeropad=" << m_iDefaultPolarZeropad;
2264     *theApp->getLog() << os.str().c_str() << "\n";
2265     rIF.labelAdd (os.str().c_str());
2266     pPolarDoc->Modify (true);
2267     pPolarDoc->UpdateAllViews ();
2268     pPolarDoc->getView()->OnUpdate (this, NULL);
2269     pPolarDoc->getView()->getFrame()->Show(true);
2270   }
2271 }
2272
2273 void
2274 ProjectionFileView::OnReconstructFourier (wxCommandEvent& event)
2275 {
2276   wxMessageBox ("Fourier Reconstruction is not yet supported", "Unimplemented function");
2277 }
2278
2279 void
2280 ProjectionFileView::OnReconstructFBP (wxCommandEvent& event)
2281 {
2282   DialogGetReconstructionParameters dialogReconstruction (getFrameForChild(), m_iDefaultNX, m_iDefaultNY, m_iDefaultFilter, m_dDefaultFilterParam, m_iDefaultFilterMethod, m_iDefaultFilterGeneration, m_iDefaultZeropad, m_iDefaultInterpolation, m_iDefaultInterpParam, m_iDefaultBackprojector, m_iDefaultTrace);
2283   
2284   int retVal = dialogReconstruction.ShowModal();
2285   if (retVal == wxID_OK) {
2286     m_iDefaultNX = dialogReconstruction.getXSize();
2287     m_iDefaultNY = dialogReconstruction.getYSize();
2288     wxString optFilterName = dialogReconstruction.getFilterName();
2289     m_iDefaultFilter = SignalFilter::convertFilterNameToID (optFilterName.c_str());
2290     m_dDefaultFilterParam = dialogReconstruction.getFilterParam();
2291     wxString optFilterMethodName = dialogReconstruction.getFilterMethodName();
2292     m_iDefaultFilterMethod = ProcessSignal::convertFilterMethodNameToID(optFilterMethodName.c_str());
2293     m_iDefaultZeropad = dialogReconstruction.getZeropad();
2294     wxString optFilterGenerationName = dialogReconstruction.getFilterGenerationName();
2295     m_iDefaultFilterGeneration = ProcessSignal::convertFilterGenerationNameToID (optFilterGenerationName.c_str());
2296     wxString optInterpName = dialogReconstruction.getInterpName();
2297     m_iDefaultInterpolation = Backprojector::convertInterpNameToID (optInterpName.c_str());
2298     m_iDefaultInterpParam = dialogReconstruction.getInterpParam();
2299     wxString optBackprojectName = dialogReconstruction.getBackprojectName();
2300     m_iDefaultBackprojector = Backprojector::convertBackprojectNameToID (optBackprojectName.c_str());
2301     m_iDefaultTrace = dialogReconstruction.getTrace();
2302     if (m_iDefaultNX > 0 && m_iDefaultNY > 0) {
2303       const Projections& rProj = GetDocument()->getProjections();
2304
2305       ImageFile* pImageFile = new ImageFile;
2306       pImageFile->setArraySize (m_iDefaultNX, m_iDefaultNY);
2307       
2308       Reconstructor* pReconstructor = new Reconstructor (rProj, *pImageFile, optFilterName.c_str(), m_dDefaultFilterParam, optFilterMethodName.c_str(), m_iDefaultZeropad, optFilterGenerationName.c_str(), optInterpName.c_str(), m_iDefaultInterpParam, optBackprojectName.c_str(), m_iDefaultTrace);
2309       
2310       Timer timerRecon;
2311       if (m_iDefaultTrace > Trace::TRACE_CONSOLE) {
2312         ReconstructDialog* pDlgReconstruct = new ReconstructDialog (*pReconstructor, rProj, *pImageFile, m_iDefaultTrace, getFrameForChild());
2313         for (int iView = 0; iView < rProj.nView(); iView++) {
2314           ::wxYield();
2315           if (pDlgReconstruct->isCancelled() || ! pDlgReconstruct->reconstructView (iView)) {
2316             delete pDlgReconstruct;
2317             delete pReconstructor;
2318             delete pImageFile;
2319             return;
2320           }
2321           ::wxYield();
2322           while (pDlgReconstruct->isPaused()) {
2323             ::wxYield();
2324             ::wxUsleep(50);
2325           }
2326         }
2327         delete pDlgReconstruct;
2328       } else {
2329         wxProgressDialog dlgProgress (wxString("Reconstruction"), wxString("Reconstruction Progress"), rProj.nView() + 1, getFrameForChild(), wxPD_CAN_ABORT);
2330         for (int i = 0; i < rProj.nView(); i++) {
2331           pReconstructor->reconstructView (i, 1);
2332           if (! dlgProgress.Update (i + 1)) {
2333             delete pReconstructor;
2334             delete pImageFile;
2335             return;
2336           }
2337         }
2338       }
2339       delete pReconstructor;
2340       ImageFileDocument* pReconDoc = theApp->newImageDoc();
2341       if (! pReconDoc) {
2342         sys_error (ERR_SEVERE, "Unable to create image file");
2343         return;
2344       }
2345       pReconDoc->setImageFile (pImageFile);
2346       pReconDoc->Modify (true);
2347       pReconDoc->UpdateAllViews (this);
2348       if (ImageFileView* rasterView = pReconDoc->getView()) {
2349         rasterView->OnUpdate (rasterView, NULL);
2350         rasterView->getFrame()->SetFocus();
2351         rasterView->getFrame()->Show(true);
2352       }
2353       std::ostringstream os;
2354       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();
2355       *theApp->getLog() << os.str().c_str() << "\n";
2356       pImageFile->labelAdd (rProj.getLabel());
2357       pImageFile->labelAdd (os.str().c_str(), timerRecon.timerEnd());
2358     }
2359   }
2360 }
2361
2362
2363 ProjectionFileCanvas* 
2364 ProjectionFileView::CreateCanvas (wxFrame *parent)
2365 {
2366   ProjectionFileCanvas* pCanvas;
2367   int width, height;
2368   parent->GetClientSize(&width, &height);
2369   
2370   pCanvas = new ProjectionFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
2371   
2372   pCanvas->SetScrollbars(20, 20, 50, 50);
2373   pCanvas->SetBackgroundColour(*wxWHITE);
2374   pCanvas->Clear();
2375   
2376   return pCanvas;
2377 }
2378
2379 #if CTSIM_MDI
2380 wxDocMDIChildFrame*
2381 #else
2382 wxDocChildFrame*
2383 #endif
2384 ProjectionFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2385 {
2386 #ifdef CTSIM_MDI
2387   wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2388 #else
2389   wxDocChildFrame *subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "Projection Frame", wxPoint(10, 10), wxSize(0, 0), wxDEFAULT_FRAME_STYLE);
2390 #endif
2391   theApp->setIconForFrame (subframe);
2392   
2393   m_pFileMenu = new wxMenu;
2394   
2395   m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2396   m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2397   m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2398   m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2399   m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2400   m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2401   
2402   m_pFileMenu->AppendSeparator();
2403   m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
2404   
2405   m_pFileMenu->AppendSeparator();
2406   m_pFileMenu->Append(wxID_PRINT, "&Print...");
2407   m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2408   m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2409 #ifdef CTSIM_MDI
2410   m_pFileMenu->AppendSeparator();
2411   m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2412 #endif
2413   GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2414   GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2415   
2416   wxMenu *convert_menu = new wxMenu;
2417   convert_menu->Append (PJMENU_CONVERT_POLAR, "&Polar Image...\tCtrl-L");
2418   convert_menu->Append (PJMENU_CONVERT_FFT_POLAR, "&FFT->Polar Image...\tCtrl-I");
2419   
2420   wxMenu *reconstruct_menu = new wxMenu;
2421   reconstruct_menu->Append (PJMENU_RECONSTRUCT_FBP, "&Filtered Backprojection...\tCtrl-R", "Reconstruct image using filtered backprojection");
2422   reconstruct_menu->Append (PJMENU_RECONSTRUCT_FOURIER, "&Fourier...\tCtrl-E", "Reconstruct image using inverse Fourier");
2423   reconstruct_menu->Enable (PJMENU_RECONSTRUCT_FOURIER, false);
2424   
2425   wxMenu *help_menu = new wxMenu;
2426   help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2427   help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
2428   help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2429   
2430   wxMenuBar *menu_bar = new wxMenuBar;
2431   
2432   menu_bar->Append (m_pFileMenu, "&File");
2433   menu_bar->Append (convert_menu, "&Convert");
2434   menu_bar->Append (reconstruct_menu, "&Reconstruct");
2435   menu_bar->Append (help_menu, "&Help");
2436   
2437   subframe->SetMenuBar(menu_bar);  
2438   subframe->Centre(wxBOTH);
2439   
2440   wxAcceleratorEntry accelEntries[11];
2441   accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
2442   accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
2443   accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
2444   accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
2445   accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
2446   accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
2447   accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
2448   accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('L'), PJMENU_CONVERT_POLAR);
2449   accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('I'), PJMENU_CONVERT_FFT_POLAR);
2450   accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('R'), PJMENU_RECONSTRUCT_FBP);
2451   accelEntries[10].Set (wxACCEL_CTRL, static_cast<int>('E'), PJMENU_RECONSTRUCT_FOURIER);
2452   wxAcceleratorTable accelTable (11, accelEntries);
2453   subframe->SetAcceleratorTable (accelTable);
2454   
2455   return subframe;
2456 }
2457
2458
2459 bool 
2460 ProjectionFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2461 {
2462   m_pFrame = CreateChildFrame(doc, this);
2463   SetFrame(m_pFrame);
2464   
2465   int width, height;
2466   m_pFrame->GetClientSize (&width, &height);
2467   m_pFrame->SetTitle ("ProjectionFileView");
2468   m_pCanvas = CreateCanvas (m_pFrame);
2469   
2470 #ifdef __X__
2471   int x, y;  // X requires a forced resize
2472   m_pFrame->GetSize(&x, &y);
2473   m_pFrame->SetSize(-1, -1, x, y);
2474 #endif
2475   
2476   m_pFrame->Show(true);
2477   Activate(true);
2478   
2479   return true;
2480 }
2481
2482 void 
2483 ProjectionFileView::OnDraw (wxDC* dc)
2484 {
2485   wxSize clientSize = m_pFrame->GetClientSize();
2486   wxSize bestSize = m_pCanvas->GetBestSize();
2487   
2488   if (clientSize.x > bestSize.x || clientSize.y > bestSize.y)
2489     m_pFrame->SetClientSize (bestSize);
2490   
2491   if (m_bitmap.Ok())
2492     dc->DrawBitmap (m_bitmap, 0, 0, false);
2493 }
2494
2495
2496 void 
2497 ProjectionFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2498 {
2499   const Projections& rProj = GetDocument()->getProjections();
2500   const int nDet = rProj.nDet();
2501   const int nView = rProj.nView();
2502   if (nDet != 0 && nView != 0) {
2503     const DetectorArray& detarray = rProj.getDetectorArray(0);
2504     const DetectorValue* detval = detarray.detValues();
2505     double min = detval[0];
2506     double max = detval[0];
2507     for (int iy = 0; iy < nView; iy++) {
2508       const DetectorArray& detarray = rProj.getDetectorArray(iy);
2509       const DetectorValue* detval = detarray.detValues();
2510       for (int ix = 0; ix < nDet; ix++) {
2511         if (min > detval[ix])
2512           min = detval[ix];
2513         else if (max < detval[ix])
2514           max = detval[ix];
2515       }
2516     }
2517     
2518     unsigned char* imageData = new unsigned char [nDet * nView * 3];
2519     double scale = (max - min) / 255;
2520     for (int iy2 = 0; iy2 < nView; iy2++) {
2521       const DetectorArray& detarray = rProj.getDetectorArray (iy2);
2522       const DetectorValue* detval = detarray.detValues();
2523       for (int ix = 0; ix < nDet; ix++) {
2524         int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
2525         intensity = clamp(intensity, 0, 255);
2526         int baseAddr = (iy2 * nDet + ix) * 3;
2527         imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
2528       }
2529     }
2530     wxImage image (nDet, nView, imageData, true);
2531     m_bitmap = image.ConvertToBitmap();
2532     delete imageData;
2533     int xSize = nDet;
2534     int ySize = nView;
2535     xSize = clamp (xSize, 0, 800);
2536     ySize = clamp (ySize, 0, 800);
2537     m_pFrame->SetClientSize (xSize, ySize);
2538     m_pCanvas->SetScrollbars (20, 20, nDet/20, nView/20);
2539   }
2540   
2541   if (m_pCanvas)
2542     m_pCanvas->Refresh();
2543 }
2544
2545 bool 
2546 ProjectionFileView::OnClose (bool deleteWindow)
2547 {
2548   //GetDocumentManager()->ActivateView (this, false, true);
2549   if (! GetDocument() || ! GetDocument()->Close())
2550     return false;
2551   
2552   Activate(false);
2553   if (m_pCanvas) {
2554         m_pCanvas->setView(NULL);
2555     m_pCanvas = NULL;
2556   }
2557   wxString s(wxTheApp->GetAppName());
2558   if (m_pFrame)
2559     m_pFrame->SetTitle(s);
2560   
2561   SetFrame(NULL);
2562   
2563   if (deleteWindow) {
2564     delete m_pFrame;
2565     m_pFrame = NULL;
2566     if (GetDocument() && GetDocument()->getBadFileOpen())
2567       ::wxYield();  // wxWindows bug workaround
2568   }
2569
2570   return true;
2571 }
2572
2573
2574
2575 // PlotFileCanvas
2576 PlotFileCanvas::PlotFileCanvas (PlotFileView* v, wxFrame *frame, const wxPoint& pos, const wxSize& size, const long style)
2577 : wxScrolledWindow(frame, -1, pos, size, style)
2578 {
2579   m_pView = v;
2580 }
2581
2582 PlotFileCanvas::~PlotFileCanvas ()
2583 {
2584   m_pView = NULL;
2585 }
2586
2587 void 
2588 PlotFileCanvas::OnDraw(wxDC& dc)
2589 {
2590   if (m_pView)
2591     m_pView->OnDraw(& dc);
2592 }
2593
2594
2595 // PlotFileView
2596
2597 IMPLEMENT_DYNAMIC_CLASS(PlotFileView, wxView)
2598
2599 BEGIN_EVENT_TABLE(PlotFileView, wxView)
2600 EVT_MENU(PJMENU_FILE_PROPERTIES, PlotFileView::OnProperties)
2601 EVT_MENU(PLOTMENU_VIEW_SCALE_MINMAX, PlotFileView::OnScaleMinMax)
2602 EVT_MENU(PLOTMENU_VIEW_SCALE_AUTO, PlotFileView::OnScaleAuto)
2603 EVT_MENU(PLOTMENU_VIEW_SCALE_FULL, PlotFileView::OnScaleFull)
2604 END_EVENT_TABLE()
2605
2606 PlotFileView::PlotFileView() 
2607 : wxView(), m_pFrame(NULL), m_pCanvas(NULL), m_pEZPlot(NULL), m_pFileMenu(0), m_bMinSpecified(false), m_bMaxSpecified(false)
2608 {
2609 }
2610
2611 PlotFileView::~PlotFileView()
2612 {
2613   if (m_pEZPlot)
2614     delete m_pEZPlot;
2615   
2616   GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);  
2617 }
2618
2619 void
2620 PlotFileView::OnProperties (wxCommandEvent& event)
2621 {
2622   const PlotFile& rPlot = GetDocument()->getPlotFile();
2623   std::ostringstream os;
2624   os << "Columns: " << rPlot.getNumColumns() << ", Records: " << rPlot.getNumRecords() << "\n";
2625   rPlot.printHeadersBrief (os);
2626   *theApp->getLog() << ">>>>\n" << os.str().c_str() << "<<<<<\n";
2627   wxMessageDialog dialogMsg (getFrameForChild(), os.str().c_str(), "Plot File Properties", wxOK | wxICON_INFORMATION);
2628   dialogMsg.ShowModal();
2629 }
2630
2631
2632 void 
2633 PlotFileView::OnScaleAuto (wxCommandEvent& event)
2634 {
2635   const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2636   double min, max, mean, mode, median, stddev;
2637   rPlotFile.statistics (1, min, max, mean, mode, median, stddev);
2638   DialogAutoScaleParameters dialogAutoScale (getFrameForChild(), mean, mode, median, stddev, m_dAutoScaleFactor);
2639   int iRetVal = dialogAutoScale.ShowModal();
2640   if (iRetVal == wxID_OK) {
2641     m_bMinSpecified = true;
2642     m_bMaxSpecified = true;
2643     double dMin, dMax;
2644     if (dialogAutoScale.getMinMax (&dMin, &dMax)) {
2645       m_dMinPixel = dMin;
2646       m_dMaxPixel = dMax;
2647       m_dAutoScaleFactor = dialogAutoScale.getAutoScaleFactor();
2648       OnUpdate (this, NULL);
2649     }
2650   }
2651 }
2652
2653 void 
2654 PlotFileView::OnScaleMinMax (wxCommandEvent& event)
2655 {
2656   const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2657   double min;
2658   double max;
2659   
2660   if (! m_bMinSpecified || ! m_bMaxSpecified) {
2661     if (! rPlotFile.getMinMax (1, min, max)) {
2662       *theApp->getLog() << "Error: unable to find Min/Max\n";
2663       return;
2664     }
2665   }
2666   
2667   if (m_bMinSpecified)
2668     min = m_dMinPixel;
2669   if (m_bMaxSpecified)
2670     max = m_dMaxPixel;
2671   
2672   DialogGetMinMax dialogMinMax (getFrameForChild(), "Set Y-axis Minimum & Maximum", min, max);
2673   int retVal = dialogMinMax.ShowModal();
2674   if (retVal == wxID_OK) {
2675     m_bMinSpecified = true;
2676     m_bMaxSpecified = true;
2677     m_dMinPixel = dialogMinMax.getMinimum();
2678     m_dMaxPixel = dialogMinMax.getMaximum();
2679     OnUpdate (this, NULL);
2680   }
2681 }
2682
2683 void 
2684 PlotFileView::OnScaleFull (wxCommandEvent& event)
2685 {
2686   if (m_bMinSpecified || m_bMaxSpecified) {
2687     m_bMinSpecified = false;
2688     m_bMaxSpecified = false;
2689     OnUpdate (this, NULL);
2690   }
2691 }
2692
2693
2694 PlotFileCanvas* 
2695 PlotFileView::CreateCanvas (wxFrame* parent)
2696 {
2697   PlotFileCanvas* pCanvas;
2698   int width, height;
2699   parent->GetClientSize(&width, &height);
2700   
2701   pCanvas = new PlotFileCanvas (this, parent, wxPoint(0, 0), wxSize(width, height), 0);
2702   
2703   pCanvas->SetBackgroundColour(*wxWHITE);
2704   pCanvas->Clear();
2705   
2706   return pCanvas;
2707 }
2708
2709 #if CTSIM_MDI
2710 wxDocMDIChildFrame*
2711 #else
2712 wxDocChildFrame*
2713 #endif
2714 PlotFileView::CreateChildFrame(wxDocument *doc, wxView *view)
2715 {
2716 #ifdef CTSIM_MDI
2717   wxDocMDIChildFrame *subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2718 #else
2719   wxDocChildFrame *subframe = new wxDocChildFrame(doc, view, theApp->getMainFrame(), -1, "Plot Frame", wxPoint(10, 10), wxSize(500, 300), wxDEFAULT_FRAME_STYLE);
2720 #endif
2721   theApp->setIconForFrame (subframe);
2722   
2723   m_pFileMenu = new wxMenu;
2724   
2725   m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2726   m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2727   m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2728   m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2729   m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2730   m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2731   
2732   m_pFileMenu->AppendSeparator();
2733   m_pFileMenu->Append(PJMENU_FILE_PROPERTIES, "P&roperties");
2734   
2735   m_pFileMenu->AppendSeparator();
2736   m_pFileMenu->Append(wxID_PRINT, "&Print...");
2737   m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2738   m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2739 #ifdef CTSIM_MDI
2740   m_pFileMenu->AppendSeparator();
2741   m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2742 #endif
2743   GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
2744   GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
2745   
2746   wxMenu *view_menu = new wxMenu;
2747   view_menu->Append(PLOTMENU_VIEW_SCALE_MINMAX, "Display Scale &Set...\tCtrl-E");
2748   view_menu->Append(PLOTMENU_VIEW_SCALE_AUTO, "Display Scale &Auto...\tCtrl-A");
2749   view_menu->Append(PLOTMENU_VIEW_SCALE_FULL, "Display &Full Scale\tCtrl-U");
2750   
2751   wxMenu *help_menu = new wxMenu;
2752   help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
2753   help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
2754   help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
2755   
2756   wxMenuBar *menu_bar = new wxMenuBar;
2757   
2758   menu_bar->Append(m_pFileMenu, "&File");
2759   menu_bar->Append(view_menu, "&View");
2760   menu_bar->Append(help_menu, "&Help");
2761   
2762   subframe->SetMenuBar(menu_bar);
2763   subframe->Centre(wxBOTH);
2764   
2765   wxAcceleratorEntry accelEntries[10];
2766   accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
2767   accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
2768   accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
2769   accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
2770   accelEntries[4].Set (wxACCEL_CTRL, static_cast<int>('P'), MAINMENU_FILE_CREATE_PHANTOM);
2771   accelEntries[5].Set (wxACCEL_CTRL, static_cast<int>('F'), MAINMENU_FILE_CREATE_FILTER);
2772   accelEntries[6].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
2773   accelEntries[7].Set (wxACCEL_CTRL, static_cast<int>('E'), PLOTMENU_VIEW_SCALE_MINMAX);
2774   accelEntries[8].Set (wxACCEL_CTRL, static_cast<int>('A'), PLOTMENU_VIEW_SCALE_AUTO);
2775   accelEntries[9].Set (wxACCEL_CTRL, static_cast<int>('U'), PLOTMENU_VIEW_SCALE_FULL);
2776   wxAcceleratorTable accelTable (10, accelEntries);
2777   subframe->SetAcceleratorTable (accelTable);
2778   
2779   return subframe;
2780 }
2781
2782
2783 bool 
2784 PlotFileView::OnCreate (wxDocument *doc, long WXUNUSED(flags) )
2785 {
2786   m_pFrame = CreateChildFrame(doc, this);
2787   SetFrame(m_pFrame);
2788   
2789   m_bMinSpecified = false;
2790   m_bMaxSpecified = false;
2791   m_dAutoScaleFactor = 1.;
2792   
2793   int width, height;
2794   m_pFrame->GetClientSize(&width, &height);
2795   m_pFrame->SetTitle ("Plot File");
2796   m_pCanvas = CreateCanvas (m_pFrame);
2797   
2798 #ifdef __X__
2799   int x, y;  // X requires a forced resize
2800   m_pFrame->GetSize(&x, &y);
2801   m_pFrame->SetSize(-1, -1, x, y);
2802 #endif
2803   
2804   m_pFrame->Show(true);
2805   Activate(true);
2806   
2807   return true;
2808 }
2809
2810 void 
2811 PlotFileView::OnDraw (wxDC* dc)
2812 {
2813   const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2814   const int iNColumns = rPlotFile.getNumColumns();
2815   const int iNRecords = rPlotFile.getNumRecords();
2816   
2817   if (iNColumns > 0 && iNRecords > 0) {
2818     int xsize, ysize;
2819     m_pCanvas->GetClientSize (&xsize, &ysize);
2820     SGPDriver driver (dc, xsize, ysize);
2821     SGP sgp (driver);
2822     if (m_pEZPlot)
2823       m_pEZPlot->plot (&sgp);
2824   }
2825 }
2826
2827
2828 void 
2829 PlotFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2830 {
2831   const PlotFile& rPlotFile = GetDocument()->getPlotFile();
2832   const int iNColumns = rPlotFile.getNumColumns();
2833   const int iNRecords = rPlotFile.getNumRecords();
2834   
2835   if (iNColumns > 0 && iNRecords > 0) {
2836     if (m_pEZPlot)
2837       delete m_pEZPlot;
2838     m_pEZPlot = new EZPlot;
2839     
2840     for (unsigned int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++)
2841       m_pEZPlot->ezset (rPlotFile.getEzsetCommand (iEzset));
2842     
2843     if (m_bMinSpecified) {
2844       std::ostringstream os;
2845       os << "ymin " << m_dMinPixel;
2846       m_pEZPlot->ezset (os.str());
2847     }
2848     
2849     if (m_bMaxSpecified) {
2850       std::ostringstream os;
2851       os << "ymax " << m_dMaxPixel;
2852       m_pEZPlot->ezset (os.str());
2853     }
2854     
2855     m_pEZPlot->ezset("box");
2856     m_pEZPlot->ezset("grid");
2857     
2858     double* pdXaxis = new double [iNRecords];
2859     rPlotFile.getColumn (0, pdXaxis);
2860     
2861     double* pdY = new double [iNRecords];
2862     for (int iCol = 1; iCol < iNColumns; iCol++) {
2863       rPlotFile.getColumn (iCol, pdY);
2864       m_pEZPlot->addCurve (pdXaxis, pdY, iNRecords);
2865     }
2866     
2867     delete pdXaxis;
2868     delete pdY;
2869   }
2870   
2871   if (m_pCanvas)
2872     m_pCanvas->Refresh();
2873 }
2874
2875 bool 
2876 PlotFileView::OnClose (bool deleteWindow)
2877 {
2878   //GetDocumentManager()->ActivateView (this, false, true);
2879   if (! GetDocument() || ! GetDocument()->Close())
2880     return false;
2881   
2882   Activate(false);
2883   if (m_pCanvas) {
2884     m_pCanvas->setView (NULL);
2885     m_pCanvas = NULL;
2886   }
2887   wxString s(wxTheApp->GetAppName());
2888   if (m_pFrame)
2889     m_pFrame->SetTitle(s);
2890   
2891   SetFrame(NULL);
2892   if (deleteWindow) {
2893     delete m_pFrame;
2894     m_pFrame = NULL;
2895     if (GetDocument() && GetDocument()->getBadFileOpen())
2896       ::wxYield();  // wxWindows bug workaround
2897  }
2898
2899   return true;
2900 }
2901
2902
2903 ////////////////////////////////////////////////////////////////
2904
2905
2906 IMPLEMENT_DYNAMIC_CLASS(TextFileView, wxView)
2907
2908 TextFileView::~TextFileView() 
2909 {
2910   GetDocumentManager()->FileHistoryRemoveMenu (m_pFileMenu);
2911   GetDocumentManager()->ActivateView(this, FALSE, TRUE);;
2912 }
2913
2914 bool TextFileView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
2915 {
2916   m_pFrame = CreateChildFrame(doc, this);
2917   SetFrame (m_pFrame);
2918   
2919   int width, height;
2920   m_pFrame->GetClientSize(&width, &height);
2921   m_pFrame->SetTitle("TextFile");
2922   m_pCanvas = new TextFileCanvas (this, m_pFrame, wxPoint(0, 0), wxSize(width, height), wxTE_MULTILINE | wxTE_READONLY);
2923   m_pFrame->SetTitle("Log");
2924   
2925 #ifdef __X__
2926   // X seems to require a forced resize
2927   int x, y;
2928   frame->GetSize(&x, &y);
2929   frame->SetSize(-1, -1, x, y);
2930 #endif
2931   
2932   m_pFrame->Show (true);
2933   Activate (true);
2934   
2935   return true;
2936 }
2937
2938 // Handled by wxTextWindow
2939 void TextFileView::OnDraw(wxDC *WXUNUSED(dc) )
2940 {
2941 }
2942
2943 void TextFileView::OnUpdate (wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
2944 {
2945 }
2946
2947 bool 
2948 TextFileView::OnClose (bool deleteWindow)
2949 {
2950   if (! theApp->getMainFrame()->getShuttingDown())
2951     return false;
2952   
2953   Activate(false);
2954   //GetDocumentManager()->ActivateView (this, false, true);
2955   if (! GetDocument() || ! GetDocument()->Close())
2956     return false;
2957   
2958   SetFrame(NULL);
2959   if (deleteWindow) {
2960     delete m_pFrame;
2961     m_pFrame = NULL;
2962     if (GetDocument() && GetDocument()->getBadFileOpen())
2963       ::wxYield();  // wxWindows bug workaround
2964   }
2965
2966   return TRUE;
2967 }
2968
2969 #if CTSIM_MDI
2970 wxDocMDIChildFrame*
2971 #else
2972 wxDocChildFrame*
2973 #endif
2974 TextFileView::CreateChildFrame (wxDocument *doc, wxView *view)
2975 {
2976 #if CTSIM_MDI
2977   wxDocMDIChildFrame* subframe = new wxDocMDIChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(0,0), wxDEFAULT_FRAME_STYLE, "Log");
2978 #else
2979   wxDocChildFrame* subframe = new wxDocChildFrame (doc, view, theApp->getMainFrame(), -1, "TextFile Frame", wxPoint(-1, -1), wxSize(300, 150), wxDEFAULT_FRAME_STYLE, "Log");
2980 #endif
2981   theApp->setIconForFrame (subframe);
2982   
2983  m_pFileMenu = new wxMenu;
2984   
2985   m_pFileMenu->Append(MAINMENU_FILE_CREATE_PHANTOM, "Cr&eate Phantom...\tCtrl-P");
2986   m_pFileMenu->Append(MAINMENU_FILE_CREATE_FILTER, "Create &Filter...\tCtrl-F");
2987   m_pFileMenu->Append(wxID_OPEN, "&Open...\tCtrl-O");
2988   m_pFileMenu->Append(wxID_SAVE, "&Save\tCtrl-S");
2989   m_pFileMenu->Append(wxID_SAVEAS, "Save &As...");
2990   //  m_pFileMenu->Append(wxID_CLOSE, "&Close\tCtrl-W");
2991   
2992   m_pFileMenu->AppendSeparator();
2993   m_pFileMenu->Append(wxID_PRINT, "&Print...");
2994   m_pFileMenu->Append(wxID_PRINT_SETUP, "Print &Setup...");
2995   m_pFileMenu->Append(wxID_PREVIEW, "Print Pre&view");
2996 #ifdef CTSIM_MDI
2997   m_pFileMenu->AppendSeparator();
2998   m_pFileMenu->Append(MAINMENU_FILE_EXIT, "E&xit");
2999 #endif
3000   GetDocumentManager()->FileHistoryAddFilesToMenu(m_pFileMenu);
3001   GetDocumentManager()->FileHistoryUseMenu(m_pFileMenu);
3002   
3003   wxMenu *help_menu = new wxMenu;
3004   help_menu->Append(MAINMENU_HELP_CONTENTS, "&Contents\tF1");
3005   help_menu->Append(MAINMENU_HELP_TOPICS, "&Topics\tCtrl-H");
3006   help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
3007   
3008   wxMenuBar *menu_bar = new wxMenuBar;
3009   
3010   menu_bar->Append(m_pFileMenu, "&File");
3011   menu_bar->Append(help_menu, "&Help");
3012   
3013   subframe->SetMenuBar(menu_bar);
3014   subframe->Centre(wxBOTH);
3015   
3016   wxAcceleratorEntry accelEntries[5];
3017   accelEntries[0].Set (wxACCEL_CTRL, static_cast<int>('O'), wxID_OPEN);
3018   accelEntries[1].Set (wxACCEL_CTRL, static_cast<int>('S'), wxID_SAVE);
3019   accelEntries[2].Set (wxACCEL_CTRL, static_cast<int>('W'), wxID_CLOSE);
3020   accelEntries[3].Set (wxACCEL_CTRL, static_cast<int>('H'), MAINMENU_HELP_TOPICS);
3021   accelEntries[4].Set (wxACCEL_NORMAL, WXK_F1, MAINMENU_HELP_CONTENTS);
3022   wxAcceleratorTable accelTable (5, accelEntries);
3023   subframe->SetAcceleratorTable (accelTable);
3024   
3025   return subframe;
3026 }
3027
3028
3029 // Define a constructor for my text subwindow
3030 TextFileCanvas::TextFileCanvas (TextFileView* v, wxFrame* frame, const wxPoint& pos, const wxSize& size, long style)
3031 : wxTextCtrl (frame, -1, "", pos, size, style), m_pView(v)
3032 {
3033 }
3034
3035 TextFileCanvas::~TextFileCanvas ()
3036 {
3037   m_pView = NULL;
3038 }