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-2001 Kevin Rosenberg
11 ** $Id: reconstruct.cpp,v 1.11 2001/01/30 05:05:41 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 = new double [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()) {
122 ezplot.ezset ("title Filter Response");
123 ezplot.addCurve (adPlotXAxis, m_pProcessSignal->getFilter(), nVecFilter);
133 Reconstructor::reconstructAllViews ()
135 reconstructView (0, m_rProj.nView());
136 delete m_pBackprojector; m_pBackprojector = NULL;
141 Reconstructor::reconstructView (int iStartView, int iViewCount, SGP* pSGP, bool bBackprojectView, double dGraphWidth)
143 double* adFilteredProj = new double [m_nFilteredProjections]; // filtered projections
146 iViewCount = m_rProj.nView() - iStartView;
148 for (int iView = iStartView; iView < (iStartView + iViewCount); iView++) {
149 if (m_iTrace == Trace::TRACE_CONSOLE)
150 std::cout <<"Reconstructing view " << iView << " (last = " << m_rProj.nView() - 1 << ")\n";
152 const DetectorArray& rDetArray = m_rProj.getDetectorArray (iView);
153 const DetectorValue* detval = rDetArray.detValues();
155 m_pProcessSignal->filterSignal (detval, adFilteredProj);
157 #ifdef HAVE_BSPLINE_INTERP
158 if (interp_type == I_BSPLINE)
159 bspline (m_rProj.nDet(), zoom_factor, spline_order, adFilteredProj, adFilteredProj);
162 if (trace >= Trace::TRACE_PLOT && interp_type == I_BSPLINE && pSGP) {
163 bspline (m_rProj.nDet(), zoom_factor, spline_order, adFilteredProj, adFilteredProj);
164 ezplot_1d (adFilteredProj, m_nFilteredProjections);
169 if (bBackprojectView)
170 m_pBackprojector->BackprojectView (adFilteredProj, rDetArray.viewAngle());
173 if (m_iTrace >= Trace::TRACE_PLOT && pSGP) {
176 std::ostringstream osXLength;
177 osXLength << "xlength " << dGraphWidth;
179 ezplotProj.ezset ("clear");
180 ezplotProj.ezset ("title Filtered Projection");
181 ezplotProj.ezset ("xticks major 5");
182 ezplotProj.ezset ("xlabel ");
183 ezplotProj.ezset ("ylabel ");
184 ezplotProj.ezset ("yticks major 5");
185 ezplotProj.ezset ("yporigin 0.10");
186 ezplotProj.ezset ("ylength 0.45");
187 ezplotProj.ezset (osXLength.str().c_str());
188 ezplotProj.ezset ("box");
189 ezplotProj.ezset ("grid");
190 ezplotProj.addCurve (m_adPlotXAxis, adFilteredProj, m_nFilteredProjections);
191 pSGP->setTextPointSize (12);
192 ezplotProj.plot (pSGP);
194 ezplotProj.ezset ("clear");
195 ezplotProj.ezset ("title Raw Projection");
196 ezplotProj.ezset ("xticks major 5");
197 ezplotProj.ezset ("yticks major 5");
198 ezplotProj.ezset ("xlabel ");
199 ezplotProj.ezset ("ylabel ");
200 ezplotProj.ezset ("yporigin 0.55");
201 ezplotProj.ezset ("ylength 0.45");
202 ezplotProj.ezset (osXLength.str().c_str());
203 ezplotProj.ezset ("box.");
204 ezplotProj.ezset ("grid.");
205 ezplotProj.addCurve (m_adPlotXAxis, detval, m_rProj.nDet());
206 pSGP->setTextPointSize (12);
207 ezplotProj.plot (pSGP);
212 delete adFilteredProj;