1 /*****************************************************************************
4 ** Name: reconstruct.cpp Reconstruction class
5 ** Programmer: Kevin Rosenberg
6 ** Date Started: Aug 84
8 ** This is part of the CTSim program
9 ** Copyright (C) 1983-2000 Kevin Rosenberg
11 ** $Id: reconstruct.cpp,v 1.1 2000/09/02 05:13:57 kevin Exp $
13 ** This program is free software; you can redistribute it and/or modify
14 ** it under the terms of the GNU General Public License (version 2) as
15 ** published by the Free Software Foundation.
17 ** This program is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ** GNU General Public License for more details.
22 ** You should have received a copy of the GNU General Public License
23 ** along with this program; if not, write to the Free Software
24 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 ******************************************************************************/
31 * Reconstructor::Reconstructor Reconstruct Image from Projections
34 * im = proj.reconstruct (im, filt_type, filt_param, interp_type)
35 * IMAGE *im Output image
36 * int filt_type Type of convolution filter to use
37 * double filt_param Filter specific parameter
38 * Currently, used only with Hamming filters
39 * int interp_type Type of interpolation method to use
43 * Calculate one-dimensional filter in spatial domain
44 * Allocate & clear (zero) the 2d output image array
45 * For each projection view
46 * Convolve raysum array with filter
47 * Backproject raysums and add (summate) to image array
52 Reconstructor::Reconstructor (const Projections& rProj, ImageFile& rIF, const char* const filterName, double filt_param, const char* const filterMethodName, const int zeropad, const char* filterGenerationName, const char* const interpName, int interpFactor, const char* const backprojectName, const int iTrace, SGP* pSGP)
53 : m_rProj(rProj), m_rImagefile(rIF), m_pProcessSignal(0), m_pBackprojector(0), m_iTrace(iTrace), m_bFail(false), m_adPlotXAxis(0)
55 m_nFilteredProjections = m_rProj.nDet() * interpFactor;
57 #ifdef HAVE_BSPLINE_INTERP
58 int spline_order = 0, zoom_factor = 0;
59 if (interp_type == I_BSPLINE) {
60 zoom_factor = interpFactor;
63 m_nFilteredProjections = (m_nDet - 1) * (zoom_factor + 1) + 1;
67 double filterBW = 1. / m_rProj.detInc();
68 m_pProcessSignal = new ProcessSignal (filterName, filterMethodName, filterBW, m_rProj.detInc(), m_rProj.nDet(), filt_param, "spatial", filterGenerationName, zeropad, interpFactor, iTrace, m_rProj.geometry(), m_rProj.focalLength(), pSGP);
70 if (m_pProcessSignal->fail()) {
72 m_strFailMessage = "Error creating ProcessSignal: ";
73 m_strFailMessage += m_pProcessSignal->failMessage();
74 delete m_pProcessSignal; m_pProcessSignal = NULL;
78 m_pBackprojector = new Backprojector (m_rProj, m_rImagefile, backprojectName, interpName, interpFactor);
79 if (m_pBackprojector->fail()) {
81 m_strFailMessage = "Error creating backprojector: ";
82 m_strFailMessage += m_pBackprojector->failMessage();
83 delete m_pBackprojector; m_pBackprojector = NULL;
84 delete m_pProcessSignal; m_pProcessSignal = NULL;
89 m_adPlotXAxis = new double [m_rProj.nDet()];
90 double x = - ((m_rProj.nDet() - 1) / 2) * m_rProj.detInc();
91 double xInc = m_rProj.detInc();
93 for (int i = 0; i < m_rProj.nDet(); i++, x += xInc)
98 Reconstructor::~Reconstructor ()
100 delete m_pBackprojector;
101 delete m_pProcessSignal;
102 delete m_adPlotXAxis;
107 Reconstructor::plotFilter (SGP* pSGP)
110 int nVecFilter = m_pProcessSignal->getNFilterPoints();
111 double adPlotXAxis [nVecFilter];
113 if (nVecFilter > 0 && pSGP) {
114 double f = m_pProcessSignal->getFilterMin();
115 double filterInc = m_pProcessSignal->getFilterIncrement();
116 for (int i = 0; i < nVecFilter; i++, f += filterInc)
119 if (m_pProcessSignal->getFilter()) {
120 EZPlot ezplot (*pSGP);
122 ezplot.ezset ("title Filter Response");
123 ezplot.addCurve (adPlotXAxis, m_pProcessSignal->getFilter(), nVecFilter);
132 Reconstructor::reconstructAllViews ()
134 reconstructView (0, m_rProj.nView());
135 delete m_pBackprojector; m_pBackprojector = NULL;
140 Reconstructor::reconstructView (int iStartView, int iViewCount, SGP* pSGP)
142 double adFilteredProj [m_nFilteredProjections]; // filtered projections
145 iViewCount = m_rProj.nView() - iStartView;
147 for (int iView = iStartView; iView < (iStartView + iViewCount); iView++) {
148 if (m_iTrace == Trace::TRACE_CONSOLE)
149 cout <<"Reconstructing view " << iView << " (last = " << m_rProj.nView() - 1 << ")\n";
151 const DetectorArray& rDetArray = m_rProj.getDetectorArray (iView);
152 const DetectorValue* detval = rDetArray.detValues();
154 m_pProcessSignal->filterSignal (detval, adFilteredProj);
156 #ifdef HAVE_BSPLINE_INTERP
157 if (interp_type == I_BSPLINE)
158 bspline (m_rProj.nDet(), zoom_factor, spline_order, adFilteredProj, adFilteredProj);
161 if (trace >= Trace::TRACE_PLOT && interp_type == I_BSPLINE && pSGP) {
162 bspline (m_rProj.nDet(), zoom_factor, spline_order, adFilteredProj, adFilteredProj);
163 ezplot_1d (adFilteredProj, m_nFilteredProjections);
168 m_pBackprojector->BackprojectView (adFilteredProj, rDetArray.viewAngle());
171 if (m_iTrace >= Trace::TRACE_PLOT && pSGP) {
172 EZPlot ezplotProj (*pSGP);
174 ezplotProj.ezset ("clear");
175 ezplotProj.ezset ("title Raw Projection");
176 ezplotProj.ezset ("xticks major 5");
177 ezplotProj.ezset ("xlabel ");
178 ezplotProj.ezset ("ylabel ");
179 ezplotProj.ezset ("yporigin .5");
180 ezplotProj.ezset ("ylength .5");
181 ezplotProj.ezset ("box.");
182 ezplotProj.ezset ("grid.");
183 ezplotProj.addCurve (m_adPlotXAxis, detval, m_rProj.nDet());
185 ezplotProj.ezset ("clear");
186 ezplotProj.ezset ("title Filtered Projection");
187 ezplotProj.ezset ("xticks major 5");
188 ezplotProj.ezset ("xlabel ");
189 ezplotProj.ezset ("ylabel ");
190 ezplotProj.ezset ("ylength .5");
191 ezplotProj.ezset ("box");
192 ezplotProj.ezset ("grid");
193 ezplotProj.addCurve (m_adPlotXAxis, adFilteredProj, m_nFilteredProjections);