6#ifndef iipr_CRectDerivativeProcessor_included
7#define iipr_CRectDerivativeProcessor_included
31 template<
typename InData,
typename OutData,
typename ValueType>
32 static bool CalculateDerivative(
const InData* channelData,
int samplesCount,
double filterLength, OutData* results);
34 template<
typename ValueType>
61 const istd::IPolymorphic* inputPtr,
63 bool allowAsync =
false,
70 QByteArray m_filterParamsId;
71 bool m_doublePrecision;
79 return m_filterParamsId;
85 m_filterParamsId = id;
91 m_doublePrecision = on;
95template<
typename InData,
typename OutData,
typename ValueType>
98 if (samplesCount < 2){
102 ValueType halfRealLength = qMax(1.0, filterLength * 0.5);
104 int sumOffset = int(halfRealLength);
105 ValueType sumLastAlpha = halfRealLength - sumOffset;
106 ValueType sumLastAlphaInv = 1 - sumLastAlpha;
108 int projectionWidth = samplesCount - 1;
110 ValueType leftSum = 0;
111 ValueType leftWeight = 0;
112 ValueType rightSum = channelData[0] * sumLastAlpha;
113 ValueType rightWeight = sumLastAlpha;
115 for (
int x = -sumOffset; x < projectionWidth; ++x){
116 if (x < projectionWidth - sumOffset){
117 rightSum += channelData[x + sumOffset + 1] * sumLastAlpha +
118 channelData[x + sumOffset] * sumLastAlphaInv;
122 else if (x == projectionWidth - sumOffset){
123 rightSum += channelData[x + sumOffset] * sumLastAlphaInv;
125 rightWeight += sumLastAlphaInv;
129 ValueType diff = channelData[x];
133 leftSum -= channelData[x - sumOffset] * sumLastAlphaInv;
134 leftSum -= channelData[x - sumOffset - 1] * sumLastAlpha;
136 else if (x == sumOffset){
137 leftSum -= channelData[x - sumOffset] * sumLastAlphaInv;
139 leftWeight += sumLastAlpha;
148 results[x] = rightSum / rightWeight - leftSum / leftWeight;
156template <
typename ValueType>
161 if ((samplesCount < 2) || (channelsCount < 1)){
165 ValueType halfRealLength = qMax(1.0, filterLength * 0.5);
167 int sumOffset = int(halfRealLength);
168 ValueType sumLastAlpha = halfRealLength - sumOffset;
169 ValueType sumLastAlphaInv = 1 - sumLastAlpha;
171 int projectionWidth = samplesCount - 1;
174 std::vector<ValueType> channelData(samplesCount);
176 for (
int channelIndex = 0; channelIndex < channelsCount; ++channelIndex){
177 for (
int i = 0; i < samplesCount; ++i){
178 channelData[i] = source.
GetSample(i, channelIndex);
181 ValueType leftSum = 0;
182 ValueType leftWeight = 0;
183 ValueType rightSum = channelData[0] * sumLastAlpha;
184 ValueType rightWeight = sumLastAlpha;
186 for (
int x = -sumOffset; x < projectionWidth; ++x){
187 if (x < projectionWidth - sumOffset){
188 rightSum += channelData[x + sumOffset + 1] * sumLastAlpha + channelData[x + sumOffset] * sumLastAlphaInv;
192 else if (x == projectionWidth - sumOffset){
193 rightSum += channelData[x + sumOffset] * sumLastAlphaInv;
194 rightWeight += sumLastAlphaInv;
198 ValueType diff = channelData[x];
202 leftSum -= channelData[x - sumOffset] * sumLastAlphaInv;
203 leftSum -= channelData[x - sumOffset - 1] * sumLastAlpha;
205 else if (x == sumOffset){
206 leftSum -= channelData[x - sumOffset] * sumLastAlphaInv;
207 leftWeight += sumLastAlpha;
216 results.
SetSample(x, channelIndex, rightSum / rightWeight - leftSum / leftWeight);
Calculate derivative of projection using rectangular filter kernel.
void UseDoublePrecision(bool on)
Sets calculation precision to use (true = double, false = float).
CRectDerivativeProcessor()
void SetFilterParamsId(const QByteArray &id)
Set parameter ID used to extract caliper parameter object from parameter set.
static bool DoDerivativeProcessing(const imeas::IDataSequence &source, double filterLength, imeas::IDataSequence &results, bool doublePrecision=false)
Do extremum features analyze.
static imeas::INumericConstraints * GetFilterConstraints()
const QByteArray & GetFilterParamsId() const
Get parameter ID used to extract caliper parameter object from parameter set.
static bool CalculateDerivative(const InData *channelData, int samplesCount, double filterLength, OutData *results)
virtual iproc::CTaskState DoProcessing(const iprm::IParamsSet *paramsPtr, const istd::IPolymorphic *inputPtr, istd::IChangeable *outputPtr, bool allowAsync=false, iproc::IProgressManager *progressManagerPtr=nullptr)
General definition of sequence contains samples in regular time grid.
virtual void SetSample(int index, int channel, double value)=0
Set sample value at specified index.
virtual double GetSample(int index, int channel=0) const =0
Get sample value at specified index.
virtual int GetSamplesCount() const =0
Get size of this raster sequence.
virtual int GetChannelsCount() const =0
Get number of channels.
Describe additional meta information for set of numeric values.
Set of general parameters.
Represent state of asynchronous operation.
Consume information about progress of some process.
Wrapper of iproc::IProcessor for simple synchrone processor implementations.
Common interface for data model objects, which can be changed.
Contains the image processing classes.