** This is part of the CTSim program
** Copyright (C) 1983-2000 Kevin Rosenberg
**
-** $Id: procsignal.cpp,v 1.3 2000/08/25 15:59:13 kevin Exp $
+** $Id: procsignal.cpp,v 1.6 2000/09/02 05:10:39 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
// CLASS IDENTIFICATION
// ProcessSignal
//
-ProcessSignal::ProcessSignal (const char* szFilterName, const char* szFilterMethodName, double dBandwidth, double dSignalIncrement, int nSignalPoints, double dFilterParam, const char* szDomainName, const char* szFilterGenerationName, int iZeropad, int iPreinterpolationFactor, int iTraceLevel)
+ProcessSignal::ProcessSignal (const char* szFilterName, const char* szFilterMethodName, double dBandwidth, double dSignalIncrement, int nSignalPoints, double dFilterParam, const char* szDomainName, const char* szFilterGenerationName, int iZeropad, int iPreinterpolationFactor, int iTraceLevel, int iGeometry, double dFocalLength, SGP* pSGP)
: m_adFourierCosTable(NULL), m_adFourierSinTable(NULL), m_adFilter(NULL), m_fail(false)
{
m_idFilterMethod = convertFilterMethodNameToID (szFilterMethodName);
return;
}
- init (m_idFilter, m_idFilterMethod, dBandwidth, dSignalIncrement, nSignalPoints, dFilterParam, m_idDomain, m_idFilterGeneration, iZeropad, iPreinterpolationFactor, iTraceLevel);
+ init (m_idFilter, m_idFilterMethod, dBandwidth, dSignalIncrement, nSignalPoints, dFilterParam, m_idDomain, m_idFilterGeneration, iZeropad, iPreinterpolationFactor, iTraceLevel, iGeometry, dFocalLength, pSGP);
}
void
-ProcessSignal::init (const int idFilter, const int idFilterMethod, double dBandwidth, double dSignalIncrement, int nSignalPoints, double dFilterParam, const int idDomain, const int idFilterGeneration, const int iZeropad, const int iPreinterpolationFactor, int iTraceLevel)
+ProcessSignal::init (const int idFilter, const int idFilterMethod, double dBandwidth, double dSignalIncrement, int nSignalPoints, double dFilterParam, const int idDomain, const int idFilterGeneration, const int iZeropad, const int iPreinterpolationFactor, int iTraceLevel, int iGeometry, double dFocalLength, SGP* pSGP)
{
m_idFilter = idFilter;
m_idDomain = idDomain;
m_idFilterMethod = idFilterMethod;
m_idFilterGeneration = idFilterGeneration;
+ m_idGeometry = iGeometry;
+ m_dFocalLength = dFocalLength;
+
if (m_idFilter == SignalFilter::FILTER_INVALID || m_idDomain == SignalFilter::DOMAIN_INVALID || m_idFilterMethod == FILTER_METHOD_INVALID || m_idFilterGeneration == FILTER_GENERATION_INVALID) {
m_fail = true;
return;
m_iZeropad = iZeropad;
m_iPreinterpolationFactor = iPreinterpolationFactor;
+ // scale signalInc/BW to signalInc/2 to adjust for imaginary detector
+ // through origin of phantom, see Kak-Slaney Fig 3.22, for Collinear
+ if (m_idGeometry == Scanner::GEOMETRY_EQUILINEAR) {
+ m_dSignalInc /= 2;
+ m_dBandwidth *= 2;
+ }
+
if (m_idFilterMethod == FILTER_METHOD_FFT) {
#if HAVE_FFTW
m_idFilterMethod = FILTER_METHOD_RFFTW;
m_adFilter = new double[ m_nFilterPoints ];
double adFrequencyFilter [m_nFilterPoints];
filter.copyFilterData (adFrequencyFilter, 0, m_nFilterPoints);
- if (m_traceLevel >= TRACE_PLOT) {
- SGPDriver sgpDriver ("Frequency Filter: Natural Order");
- SGP sgp (sgpDriver);
- EZPlot ezplot (sgp);
-
- ezplot.ezset ("title Filter Response: Natural Order");
- ezplot.addCurve (adFrequencyFilter, m_nFilterPoints);
- ezplot.plot();
- cio_put_str ("Press any key to continue");
- cio_kb_getc ();
+ EZPlot* pEZPlot = NULL;
+ if (pSGP && m_traceLevel >= Trace::TRACE_PLOT) {
+ pEZPlot = new EZPlot (*pSGP);
+ pEZPlot->ezset ("title Filter Response: Natural Order");
+ pEZPlot->ezset ("ylength 0.25");
+ pEZPlot->addCurve (adFrequencyFilter, m_nFilterPoints);
+ pEZPlot->plot();
}
shuffleNaturalToFourierOrder (adFrequencyFilter, m_nFilterPoints);
- if (m_traceLevel >= TRACE_PLOT) {
- SGPDriver sgpDriver ("Frequency Filter: Fourier Order");
- SGP sgp (sgpDriver);
- EZPlot ezplot (sgp);
-
- ezplot.ezset ("title Filter Response: Fourier Order");
- ezplot.addCurve (adFrequencyFilter, m_nFilterPoints);
- ezplot.plot();
- cio_put_str ("Press any key to continue");
- cio_kb_getc ();
+ if (pEZPlot && m_traceLevel >= Trace::TRACE_PLOT) {
+ pEZPlot->ezset ("title Filter Response: Fourier Order");
+ pEZPlot->ezset ("ylength 0.25");
+ pEZPlot->ezset ("yporigin 0.25");
+ pEZPlot->addCurve (adFrequencyFilter, m_nFilterPoints);
+ pEZPlot->plot();
}
ProcessSignal::finiteFourierTransform (adFrequencyFilter, m_adFilter, m_nFilterPoints, -1);
- if (m_traceLevel >= TRACE_PLOT) {
- SGPDriver sgpDriver ("Inverse Fourier Frequency: Fourier Order");
- SGP sgp (sgpDriver);
- EZPlot ezplot (sgp);
-
- ezplot.ezset ("title Inverse Fourier Frequency: Fourier Order");
- ezplot.addCurve (m_adFilter, m_nFilterPoints);
- ezplot.plot();
- cio_put_str ("Press any key to continue");
- cio_kb_getc ();
+ if (pEZPlot && m_traceLevel >= Trace::TRACE_PLOT) {
+ pEZPlot->ezset ("title Inverse Fourier Frequency: Fourier Order");
+ pEZPlot->ezset ("ylength 0.25");
+ pEZPlot->ezset ("yporigin 0.50");
+ pEZPlot->addCurve (m_adFilter, m_nFilterPoints);
+ pEZPlot->plot();
}
shuffleFourierToNaturalOrder (m_adFilter, m_nFilterPoints);
- if (m_traceLevel >= TRACE_PLOT) {
- SGPDriver sgpDriver ("Inverse Fourier Frequency: Natural Order");
- SGP sgp (sgpDriver);
- EZPlot ezplot (sgp);
-
- ezplot.ezset ("title Inverse Fourier Frequency: Natural Order");
- ezplot.addCurve (m_adFilter, m_nFilterPoints);
- ezplot.plot();
- cio_put_str ("Press any key to continue");
- cio_kb_getc ();
+ if (pEZPlot && m_traceLevel >= Trace::TRACE_PLOT) {
+ pEZPlot->ezset ("title Inverse Fourier Frequency: Natural Order");
+ pEZPlot->ezset ("ylength 0.25");
+ pEZPlot->ezset ("yporigin 0.75");
+ pEZPlot->addCurve (m_adFilter, m_nFilterPoints);
+ pEZPlot->plot();
+ delete pEZPlot;
}
for (int i = 0; i < m_nFilterPoints; i++) {
m_adFilter[i] /= m_dSignalInc;
}
}
- }
+ if (m_idGeometry == Scanner::GEOMETRY_EQUILINEAR) {
+ for (int i = 0; i < m_nFilterPoints; i++)
+ m_adFilter[i] *= 0.5;
+ } else if (m_idGeometry == Scanner::GEOMETRY_EQUIANGULAR) {
+ for (int i = 0; i < m_nFilterPoints; i++) {
+ int iDetFromZero = i - ((m_nFilterPoints - 1) / 2);
+ double sinScale = sin (iDetFromZero * m_dSignalInc);
+ if (fabs(sinScale) < 1E-7)
+ sinScale = 1;
+ else
+ sinScale = (iDetFromZero * m_dSignalInc) / sinScale;
+ double dScale = 0.5 * sinScale * sinScale;
+ m_adFilter[i] *= dScale;
+ }
+ } // if (geometry)
+ } // if (spatial filtering)
- // Frequency-based filtering
- else if (m_bFrequencyFiltering) {
+ else if (m_bFrequencyFiltering) { // Frequency-based filtering
if (m_idFilterGeneration == FILTER_GENERATION_DIRECT) {
// calculate number of filter points with zeropadding
nextPowerOf2++;
nextPowerOf2 += (m_iZeropad - 1);
m_nFilterPoints = 1 << nextPowerOf2;
- if (m_traceLevel >= TRACE_TEXT)
- cout << "nFilterPoints = " << m_nFilterPoints << endl;
+#ifdef DEBUG
+ if (m_traceLevel >= Trace::TRACE_CONSOLE)
+ cout << "nFilterPoints = " << m_nFilterPoints << endl;
+#endif
}
m_nOutputPoints = m_nFilterPoints * m_iPreinterpolationFactor;
SignalFilter filter (m_idFilter, m_dFilterMin, m_dFilterMax, m_nFilterPoints, m_dBandwidth, m_dFilterParam, SignalFilter::DOMAIN_FREQUENCY);
m_adFilter = new double [m_nFilterPoints];
filter.copyFilterData (m_adFilter, 0, m_nFilterPoints);
- if (m_traceLevel >= TRACE_PLOT) {
- SGPDriver sgpDriver ("Frequency Filter: Natural Order");
- SGP sgp (sgpDriver);
- EZPlot ezplot (sgp);
-
- ezplot.ezset ("title Filter Filter: Natural Order");
- ezplot.addCurve (m_adFilter, m_nFilterPoints);
- ezplot.plot();
- cio_put_str ("Press any key to continue");
- cio_kb_getc ();
+
+ if (m_idGeometry == Scanner::GEOMETRY_EQUILINEAR) {
+ for (int i = 0; i < m_nFilterPoints; i++)
+ m_adFilter[i] *= 0.5;
+ } else if (m_idGeometry == Scanner::GEOMETRY_EQUIANGULAR) {
+ for (int i = 0; i < m_nFilterPoints; i++) {
+ int iDetFromZero = i - ((m_nFilterPoints - 1) / 2);
+ double sinScale = sin (iDetFromZero * m_dSignalInc);
+ if (fabs(sinScale) < 1E-7)
+ sinScale = 1;
+ else
+ sinScale = (iDetFromZero * m_dSignalInc) / sinScale;
+ double dScale = 0.5 * sinScale * sinScale;
+ // m_adFilter[i] *= dScale;
+ }
+ }
+ EZPlot* pEZPlot = NULL;
+ if (pSGP && m_traceLevel >= Trace::TRACE_PLOT) {
+ pEZPlot = new EZPlot (*pSGP);
+ pEZPlot->ezset ("title Filter Filter: Natural Order");
+ pEZPlot->ezset ("ylength 0.50");
+ pEZPlot->ezset ("yporigin 0.00");
+ pEZPlot->addCurve (m_adFilter, m_nFilterPoints);
+ pEZPlot->plot();
}
shuffleNaturalToFourierOrder (m_adFilter, m_nFilterPoints);
- if (m_traceLevel >= TRACE_PLOT) {
- SGPDriver sgpDriver ("Frequency Filter: Fourier Order");
- SGP sgp (sgpDriver);
- EZPlot ezplot (sgp);
-
- ezplot.ezset ("title Filter Filter: Fourier Order");
- ezplot.addCurve (m_adFilter, m_nFilterPoints);
- ezplot.plot();
- cio_put_str ("Press any key to continue");
- cio_kb_getc ();
- }
+ if (pEZPlot && m_traceLevel >= Trace::TRACE_PLOT) {
+ pEZPlot->ezset ("title Filter Filter: Fourier Order");
+ pEZPlot->ezset ("ylength 0.50");
+ pEZPlot->ezset ("yporigin 0.50");
+ pEZPlot->addCurve (m_adFilter, m_nFilterPoints);
+ pEZPlot->plot();
+ delete pEZPlot;
+ }
} else if (m_idFilterGeneration == FILTER_GENERATION_INVERSE_FOURIER) {
// calculate number of filter points with zeropadding
int nSpatialPoints = 2 * (m_nSignalPoints - 1) + 1;
m_nFilterPoints = 1 << nextPowerOf2;
}
m_nOutputPoints = m_nFilterPoints * m_iPreinterpolationFactor;
- if (m_traceLevel >= TRACE_TEXT)
+#ifdef DEBUG
+ if (m_traceLevel >= Trace::TRACE_CONSOLE)
cout << "nFilterPoints = " << m_nFilterPoints << endl;
+#endif
double adSpatialFilter [m_nFilterPoints];
SignalFilter filter (m_idFilter, m_dFilterMin, m_dFilterMax, nSpatialPoints, m_dBandwidth, m_dFilterParam, SignalFilter::DOMAIN_SPATIAL);
filter.copyFilterData (adSpatialFilter, 0, nSpatialPoints);
- if (m_traceLevel >= TRACE_PLOT) {
- SGPDriver sgpDriver ("Spatial Filter: Natural Order");
- SGP sgp (sgpDriver);
- EZPlot ezplot (sgp);
-
- ezplot.ezset ("title Spatial Filter: Natural Order");
- ezplot.addCurve (adSpatialFilter, nSpatialPoints);
- ezplot.plot();
- cio_put_str ("Press any key to continue");
- cio_kb_getc ();
+ EZPlot* pEZPlot = NULL;
+ if (pSGP && m_traceLevel >= Trace::TRACE_PLOT) {
+ pEZPlot = new EZPlot (*pSGP);
+ pEZPlot->ezset ("title Spatial Filter: Natural Order");
+ pEZPlot->ezset ("ylength 0.50");
+ pEZPlot->ezset ("yporigin 0.00");
+ pEZPlot->addCurve (adSpatialFilter, nSpatialPoints);
+ pEZPlot->plot();
+ delete pEZPlot;
+ }
+ if (m_idGeometry == Scanner::GEOMETRY_EQUILINEAR) {
+ for (int i = 0; i < m_nFilterPoints; i++)
+ adSpatialFilter[i] *= 0.5;
+ } else if (m_idGeometry == Scanner::GEOMETRY_EQUIANGULAR) {
+ for (int i = 0; i < m_nFilterPoints; i++) {
+ int iDetFromZero = i - ((m_nFilterPoints - 1) / 2);
+ double sinScale = sin (iDetFromZero * m_dSignalInc);
+ if (fabs(sinScale) < 1E-7)
+ sinScale = 1;
+ else
+ sinScale = (iDetFromZero * m_dSignalInc) / sinScale;
+ double dScale = 0.5 * sinScale * sinScale;
+ adSpatialFilter[i] *= dScale;
+ }
}
for (int i = nSpatialPoints; i < m_nFilterPoints; i++)
adSpatialFilter[i] = 0;
finiteFourierTransform (adSpatialFilter, acInverseFilter, m_nFilterPoints, 1);
for (int i = 0; i < m_nFilterPoints; i++)
m_adFilter[i] = abs(acInverseFilter[i]) * m_dSignalInc;
- if (m_traceLevel >= TRACE_PLOT) {
- SGPDriver sgpDriver ("Spatial Filter: Inverse");
- SGP sgp (sgpDriver);
- EZPlot ezplot (sgp);
-
- ezplot.ezset ("title Spatial Filter: Inverse");
- ezplot.addCurve (m_adFilter, m_nFilterPoints);
- ezplot.plot();
- cio_put_str ("Press any key to continue");
- cio_kb_getc ();
+ if (pEZPlot && m_traceLevel >= Trace::TRACE_PLOT) {
+ pEZPlot->ezset ("title Spatial Filter: Inverse");
+ pEZPlot->ezset ("ylength 0.50");
+ pEZPlot->ezset ("yporigin 0.50");
+ pEZPlot->addCurve (m_adFilter, m_nFilterPoints);
+ pEZPlot->plot();
+ delete pEZPlot;
}
}
}
}
void
-ProcessSignal::filterSignal (const float input[], double output[]) const
+ProcessSignal::filterSignal (const float constInput[], double output[]) const
{
+ double input [m_nSignalPoints];
+ for (int i = 0; i < m_nSignalPoints; i++)
+ input[i] = constInput[i];
+
+ if (m_idGeometry == Scanner::GEOMETRY_EQUILINEAR) {
+ for (int i = 0; i < m_nSignalPoints; i++) {
+ int iDetFromCenter = i - (m_nSignalPoints / 2);
+ input[i] *= m_dFocalLength / sqrt (m_dFocalLength * m_dFocalLength + iDetFromCenter * iDetFromCenter * m_dSignalInc * m_dSignalInc);
+ }
+ } else if (m_idGeometry == Scanner::GEOMETRY_EQUIANGULAR) {
+ for (int i = 0; i < m_nSignalPoints; i++) {
+ int iDetFromCenter = i - (m_nSignalPoints / 2);
+ input[i] *= m_dFocalLength * cos (iDetFromCenter * m_dSignalInc);
+ }
+ }
if (m_idFilterMethod == FILTER_METHOD_CONVOLUTION) {
- for (int i = 0; i < m_nSignalPoints; i++)
- output[i] = convolve (input, m_dSignalInc, i, m_nSignalPoints);
+ for (int i = 0; i < m_nSignalPoints; i++)
+ output[i] = convolve (input, m_dSignalInc, i, m_nSignalPoints);
} else if (m_idFilterMethod == FILTER_METHOD_FOURIER) {
double inputSignal[m_nFilterPoints];
for (int i = 0; i < m_nSignalPoints; i++)