** This is part of the CTSim program
** Copyright (C) 1983-2000 Kevin Rosenberg
**
-** $Id: views.cpp,v 1.2 2000/07/15 08:36:13 kevin Exp $
+** $Id: views.cpp,v 1.3 2000/07/18 03:14:35 kevin Exp $
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License (version 2) as
#include "ctsim.h"
#include "docs.h"
#include "views.h"
+#include "dialogs.h"
#include <sstream>
-#include "ct.h"
// ImageFileCanvas
IMPLEMENT_DYNAMIC_CLASS(ImageFileView, wxView)
BEGIN_EVENT_TABLE(ImageFileView, wxView)
- EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
- EVT_MENU(IFMENU_VIEW_WINDOW_AUTO, ImageFileView::OnWindowAuto)
+ EVT_MENU(IFMENU_FILE_PROPERTIES, ImageFileView::OnProperties)
+ EVT_MENU(IFMENU_VIEW_WINDOW_MINMAX, ImageFileView::OnWindowMinMax)
+ EVT_MENU(IFMENU_VIEW_WINDOW_AUTO, ImageFileView::OnWindowAuto)
END_EVENT_TABLE()
ImageFileView::ImageFileView(void)
const string& rFilename = rIF.getFilename();
rIF.statistics (min, max, mean, mode, median, stddev);
ostringstream os;
- os << "file: " << rFilename << "\nmin: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmode: "<<mode<<"\nstddev: "<<stddev;
+ os << "file: " << rFilename << "\nmin: "<<min<<"\nmax: "<<max<<"\nmean: "<<mean<<"\nmode: "<<mode<<"\nstddev: "<<stddev << "\n";
*theApp->getLog() << os.str().c_str();
}
}
ImageFileView::OnWindowAuto (wxCommandEvent& event)
{
*theApp->getLog() << "ImageFile: Window Auto\n";
- m_minPixel = .2;
- m_maxPixel = .22;
- m_bMinSpecified = true;
- m_bMaxSpecified = true;
- OnUpdate(this, NULL);
+}
+
+void
+ImageFileView::OnWindowMinMax (wxCommandEvent& event)
+{
+ const ImageFile& rIF = GetDocument()->getImageFile();
+ double min, max;
+ if (! m_bMinSpecified && ! m_bMaxSpecified)
+ rIF.getMinMax (min, max);
+
+ if (m_bMinSpecified)
+ min = m_dMinPixel;
+ if (m_bMaxSpecified)
+ max = m_dMaxPixel;
+
+ DialogGetImageMinMax dialogMinMax (m_frame, rIF, min, max);
+ int retVal = dialogMinMax.ShowModal();
+ if (retVal == wxID_OK) {
+ m_bMinSpecified = true;
+ m_bMaxSpecified = true;
+ m_dMinPixel = dialogMinMax.getMinimum();
+ m_dMaxPixel = dialogMinMax.getMaximum();
+ OnUpdate (this, NULL);
+ }
}
wxMenu *view_menu = new wxMenu;
view_menu->Append(IFMENU_VIEW_WINDOW_AUTO, "&Window auto");
+ view_menu->Append(IFMENU_VIEW_WINDOW_MINMAX, "&Set Window Min/Max");
wxMenu *help_menu = new wxMenu;
help_menu->Append(MAINMENU_HELP_ABOUT, "&About");
double min, max;
rIF.getMinMax (min, max);
if (! m_bMinSpecified)
- m_minPixel = min;
+ m_dMinPixel = min;
if (! m_bMaxSpecified)
- m_maxPixel = max;
+ m_dMaxPixel = max;
}
- double scaleWidth = m_maxPixel - m_minPixel;
+ double scaleWidth = m_dMaxPixel - m_dMinPixel;
unsigned char imageData [nx * ny * 3];
for (int ix = 0; ix < nx; ix++) {
for (int iy = 0; iy < ny; iy++) {
- double scaleValue = ((v[ix][iy] - m_minPixel) / scaleWidth) * 255;
+ double scaleValue = ((v[ix][iy] - m_dMinPixel) / scaleWidth) * 255;
int intensity = static_cast<int>(scaleValue + 0.5);
intensity = clamp (intensity, 0, 255);
int baseAddr = ((ny - 1 - iy) * nx + ix) * 3;
m_bitmap = image.ConvertToBitmap();
}
- if (m_canvas) {
+ if (m_canvas)
m_canvas->Refresh();
- }
-
-#ifdef __WXMSW__
- if (m_canvas)
- m_canvas->Refresh();
-#else
- if (m_canvas) {
- wxClientDC dc(m_canvas);
- dc.Clear();
- OnDraw (&dc);
- }
-#endif
}
bool
ostringstream os;
os << "Phantom " << namePhantom << " (" << static_cast<int>(idPhantom) << ")\n";
*theApp->getLog() << os.str().c_str();
- const Phantom& rPhantom = GetDocument()->getPhantom();
#if DEBUG
+ const Phantom& rPhantom = GetDocument()->getPhantom();
rPhantom.print();
#endif
}
void
PhantomView::OnProjections (wxCommandEvent& event)
{
+ const Phantom& rPhantom = GetDocument()->getPhantom();
+ ProjectionFileDocument* pProjectionDoc = dynamic_cast<ProjectionFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.pj", wxDOC_SILENT));
+ Projections& rProj = pProjectionDoc->getProjections();
+ Scanner theScanner (rPhantom, "parallel", 367, 320, 2, PI);
+ rProj.initFromScanner (theScanner);
+ theScanner.collectProjections (rProj, rPhantom, 0, TRACE_NONE);
+ pProjectionDoc->Modify(true);
+ pProjectionDoc->UpdateAllViews(this);
}
ImageFileDocument* pRasterDoc = dynamic_cast<ImageFileDocument*>(theApp->getDocManager()->CreateDocument("untitled.if", wxDOC_SILENT));
ImageFile& imageFile = pRasterDoc->getImageFile();
imageFile.setArraySize (256, 256);
- imageFile.arrayDataClear();
rPhantom.convertToImagefile (imageFile, 1, TRACE_NONE);
pRasterDoc->Modify(true);
pRasterDoc->UpdateAllViews(this);
void
PhantomView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint) )
{
- if (m_canvas) {
+ if (m_canvas)
m_canvas->Refresh();
- }
-
-#ifdef __WXMSW__
- if (m_canvas)
- m_canvas->Refresh();
-#else
- if (m_canvas) {
- wxClientDC dc(m_canvas);
- dc.Clear();
- OnDraw (&dc);
- }
-#endif
}
bool
const Projections& rProj = GetDocument()->getProjections();
const int nDet = rProj.nDet();
const int nView = rProj.nView();
- const DetectorArray& detarray = rProj.getDetectorArray(0);
- const DetectorValue* detval = detarray.detValues();
- double min = detval[0];
- double max = detval[0];
- for (int iy = 0; iy < nView; iy++) {
- const DetectorArray& detarray = rProj.getDetectorArray(iy);
- const DetectorValue* detval = detarray.detValues();
- for (int ix = 0; ix < nDet; ix++) {
- if (min > detval[ix])
- min = detval[ix];
- else if (max < detval[ix])
- max = detval[ix];
- }
- }
+ if (nDet != 0 && nView != 0) {
+ const DetectorArray& detarray = rProj.getDetectorArray(0);
+ const DetectorValue* detval = detarray.detValues();
+ double min = detval[0];
+ double max = detval[0];
+ for (int iy = 0; iy < nView; iy++) {
+ const DetectorArray& detarray = rProj.getDetectorArray(iy);
+ const DetectorValue* detval = detarray.detValues();
+ for (int ix = 0; ix < nDet; ix++) {
+ if (min > detval[ix])
+ min = detval[ix];
+ else if (max < detval[ix])
+ max = detval[ix];
+ }
+ }
- unsigned char imageData [nDet * nView * 3];
- double scale = (max - min) / 255;
- for (int iy = 0; iy < nView; iy++) {
- const DetectorArray& detarray = rProj.getDetectorArray(iy);
- const DetectorValue* detval = detarray.detValues();
- for (int ix = 0; ix < nDet; ix++) {
- int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
- intensity = clamp(intensity, 0, 255);
- int baseAddr = (iy * nDet + ix) * 3;
- imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
- }
- }
- wxImage image (nDet, nView, imageData, true);
- m_bitmap = image.ConvertToBitmap();
-
- if (m_canvas) {
- m_canvas->Refresh();
+ unsigned char imageData [nDet * nView * 3];
+ double scale = (max - min) / 255;
+ for (int iy = 0; iy < nView; iy++) {
+ const DetectorArray& detarray = rProj.getDetectorArray(iy);
+ const DetectorValue* detval = detarray.detValues();
+ for (int ix = 0; ix < nDet; ix++) {
+ int intensity = static_cast<int>(((detval[ix] - min) / scale) + 0.5);
+ intensity = clamp(intensity, 0, 255);
+ int baseAddr = (iy * nDet + ix) * 3;
+ imageData[baseAddr] = imageData[baseAddr+1] = imageData[baseAddr+2] = intensity;
+ }
+ }
+ wxImage image (nDet, nView, imageData, true);
+ m_bitmap = image.ConvertToBitmap();
}
-#ifdef __WXMSW__
- if (m_canvas)
- m_canvas->Refresh();
-#else
- if (m_canvas) {
- wxClientDC dc(m_canvas);
- dc.Clear();
- OnDraw (&dc);
- }
-#endif
+ if (m_canvas)
+ m_canvas->Refresh();
}
bool