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