| 1 |
/***************************************************************************** |
| 2 |
** FILE IDENTIFICATION |
| 3 |
** |
| 4 |
** Name: filter.h |
| 5 |
** Purpose: Signal filter header file |
| 6 |
** Programmer: Kevin Rosenberg |
| 7 |
** Date Started: June 2000 |
| 8 |
** |
| 9 |
** This is part of the CTSim program |
| 10 |
** Copyright (c) 1983-2009 Kevin Rosenberg |
| 11 |
** |
| 12 |
** This program is free software; you can redistribute it and/or modify |
| 13 |
** it under the terms of the GNU General Public License (version 2) as |
| 14 |
** published by the Free Software Foundation. |
| 15 |
** |
| 16 |
** This program is distributed in the hope that it will be useful, |
| 17 |
** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 |
** GNU General Public License for more details. |
| 20 |
** |
| 21 |
** You should have received a copy of the GNU General Public License |
| 22 |
** along with this program; if not, write to the Free Software |
| 23 |
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 |
******************************************************************************/ |
| 25 |
|
| 26 |
#ifndef PROCSIGNAL_H |
| 27 |
#define PROCSIGNAL_H |
| 28 |
|
| 29 |
|
| 30 |
#ifdef HAVE_CONFIG_H |
| 31 |
#include "config.h" |
| 32 |
#endif |
| 33 |
#ifdef HAVE_FFTW |
| 34 |
#include <fftw3.h> |
| 35 |
#endif |
| 36 |
|
| 37 |
#include <complex> |
| 38 |
|
| 39 |
class SignalFilter; |
| 40 |
class SGP; |
| 41 |
|
| 42 |
typedef std::complex<double> CTSimComplex; |
| 43 |
|
| 44 |
|
| 45 |
class ProcessSignal { |
| 46 |
public: |
| 47 |
static const int FILTER_METHOD_INVALID; |
| 48 |
static const int FILTER_METHOD_CONVOLUTION; |
| 49 |
static const int FILTER_METHOD_FOURIER; |
| 50 |
static const int FILTER_METHOD_FOURIER_TABLE; |
| 51 |
static const int FILTER_METHOD_FFT; |
| 52 |
#if HAVE_FFTW |
| 53 |
static const int FILTER_METHOD_FFTW; |
| 54 |
static const int FILTER_METHOD_RFFTW; |
| 55 |
#endif |
| 56 |
|
| 57 |
static const int FILTER_GENERATION_INVALID; |
| 58 |
static const int FILTER_GENERATION_DIRECT; |
| 59 |
static const int FILTER_GENERATION_INVERSE_FOURIER; |
| 60 |
|
| 61 |
enum { |
| 62 |
FORWARD = -1, |
| 63 |
BACKWARD = 1, |
| 64 |
}; |
| 65 |
|
| 66 |
ProcessSignal (const char* szFilterName, const char* szFilterMethodName,double bw, double signalIncrement, |
| 67 |
int n, double param, const char* szDomainName, const char* szFilterGenerationName, |
| 68 |
const int zeropad, const int preinterpolationFactor, const int iTraceLevel, int iGeometry, |
| 69 |
double dFocalLength, double dSourceDetectorLength, SGP* pSGP = NULL); |
| 70 |
|
| 71 |
~ProcessSignal(); |
| 72 |
|
| 73 |
void filterSignal (const float input[], double output[]) const; |
| 74 |
|
| 75 |
bool fail(void) const {return m_fail;} |
| 76 |
const std::string& failMessage(void) const {return m_failMessage;} |
| 77 |
|
| 78 |
void setTraceLevel (int traceLevel) {m_traceLevel = traceLevel; } |
| 79 |
|
| 80 |
int getNFilterPoints (void) const { return m_nFilterPoints; } |
| 81 |
const double getFilterMin(void) const {return m_dFilterMin;} |
| 82 |
const double getFilterMax(void) const {return m_dFilterMax;} |
| 83 |
const double getFilterIncrement(void) const {return m_dFilterInc;} |
| 84 |
double* getFilter(void) {return m_adFilter;} |
| 85 |
const double* getFilter(void) const {return m_adFilter;} |
| 86 |
|
| 87 |
const int idFilterGeneration() const { return m_idFilterGeneration;} |
| 88 |
|
| 89 |
static const int getFilterGenerationCount() {return s_iFilterGenerationCount;} |
| 90 |
static const char* const* getFilterGenerationNameArray() {return s_aszFilterGenerationName;} |
| 91 |
static const char* const* getFilterGenerationTitleArray() {return s_aszFilterGenerationTitle;} |
| 92 |
static int convertFilterGenerationNameToID (const char* const fgName); |
| 93 |
static const char* convertFilterGenerationIDToName (const int idFG); |
| 94 |
static const char* convertFilterGenerationIDToTitle (const int idFG); |
| 95 |
|
| 96 |
static const int getFilterMethodCount() {return s_iFilterMethodCount;} |
| 97 |
static const char* const* getFilterMethodNameArray() {return s_aszFilterMethodName;} |
| 98 |
static const char* const* getFilterMethodTitleArray() {return s_aszFilterMethodTitle;} |
| 99 |
static int convertFilterMethodNameToID (const char* const filterMethodName); |
| 100 |
static const char* convertFilterMethodIDToName (const int idFilterMethod); |
| 101 |
static const char* convertFilterMethodIDToTitle (const int idFilterMethod); |
| 102 |
|
| 103 |
// transforms using direct trigometric calculation |
| 104 |
static void finiteFourierTransform (const double input[], double output[], const int n, const int direction); |
| 105 |
static void finiteFourierTransform (const double input[], std::complex<double> output[], const int n, const int direction); |
| 106 |
static void finiteFourierTransform (const std::complex<double> input[], std::complex<double> output[], const int n, const int direction); |
| 107 |
static void finiteFourierTransform (const std::complex<double> input[], double output[], const int n, const int direction); |
| 108 |
|
| 109 |
static int addZeropadFactor (int n, int iZeropad); |
| 110 |
|
| 111 |
private: |
| 112 |
std::string m_nameFilterMethod; |
| 113 |
std::string m_nameFilterGeneration; |
| 114 |
int m_idFilterMethod; |
| 115 |
int m_idFilterGeneration; |
| 116 |
int m_nSignalPoints; |
| 117 |
double* m_adFourierCosTable; |
| 118 |
double* m_adFourierSinTable; |
| 119 |
int m_nFilterPoints; |
| 120 |
double m_dSignalInc; |
| 121 |
double m_dFilterInc; |
| 122 |
double m_dFilterMin; |
| 123 |
double m_dFilterMax; |
| 124 |
double* m_adFilter; |
| 125 |
bool m_bFrequencyFiltering; |
| 126 |
|
| 127 |
// Variables also kept in SignalFilter class |
| 128 |
int m_idFilter; |
| 129 |
int m_idDomain; |
| 130 |
|
| 131 |
int m_traceLevel; |
| 132 |
double m_dBandwidth; |
| 133 |
double m_dFilterParam; |
| 134 |
int m_iZeropad; |
| 135 |
int m_nOutputPoints; |
| 136 |
int m_iPreinterpolationFactor; |
| 137 |
int m_idGeometry; |
| 138 |
double m_dFocalLength; |
| 139 |
double m_dSourceDetectorLength; |
| 140 |
|
| 141 |
bool m_fail; |
| 142 |
std::string m_failMessage; |
| 143 |
|
| 144 |
static const char* const s_aszFilterMethodName[]; |
| 145 |
static const char* const s_aszFilterMethodTitle[]; |
| 146 |
static const int s_iFilterMethodCount; |
| 147 |
static const char* const s_aszFilterGenerationName[]; |
| 148 |
static const char* const s_aszFilterGenerationTitle[]; |
| 149 |
static const int s_iFilterGenerationCount; |
| 150 |
|
| 151 |
#ifdef HAVE_FFTW |
| 152 |
double *m_adRealFftInput, *m_adRealFftOutput, *m_adRealFftSignal, *m_adRealFftBackwardOutput; |
| 153 |
fftw_plan m_realPlanForward, m_realPlanBackward; |
| 154 |
fftw_complex *m_adComplexFftInput, *m_adComplexFftOutput, *m_adComplexFftSignal, *m_adComplexFftBackwardOutput; |
| 155 |
fftw_plan m_complexPlanForward, m_complexPlanBackward; |
| 156 |
#endif |
| 157 |
|
| 158 |
void init (const int idFilter, int idFilterMethod, double dBandwidth, double dSignalIncrement, |
| 159 |
int nSignalPoints, double dFilterParam, const int idDomain, int idFilterGeneration, const int iZeropad, |
| 160 |
const int iPreinterpolationFactor, const int iTraceLevel, const int iGeometry, double dFocalLength, |
| 161 |
double dSourceDetectorLength, SGP* pSGP); |
| 162 |
|
| 163 |
// transforms that use precalculated trig tables, therefore don't |
| 164 |
// require number of data points (n) as an argument |
| 165 |
void finiteFourierTransform (const double input[], std::complex<double> output[], const int direction) const; |
| 166 |
void finiteFourierTransform (const std::complex<double> input[], std::complex<double> output[], const int direction) const; |
| 167 |
void finiteFourierTransform (const std::complex<double> input[], double output[], const int direction) const; |
| 168 |
|
| 169 |
double convolve (const double func[], const double filter[], const double dx, const int n, const int np) const; |
| 170 |
double convolve (const double f[], const double dx, const int n, const int np) const; |
| 171 |
double convolve (const float f[], const double dx, const int n, const int np) const; |
| 172 |
|
| 173 |
}; |
| 174 |
|
| 175 |
|
| 176 |
#endif |