18 #ifndef itkParabolicMorphUtils_h
19 #define itkParabolicMorphUtils_h
27 template<
class LineBufferType,
class RealType,
bool doDilate >
28 void DoLineCP(LineBufferType & LineBuf, LineBufferType & tmpLineBuf,
29 const RealType magnitude,
const RealType m_Extreme)
32 long koffset = 0, newcontact = 0;
34 const long LineLength = LineBuf.size();
37 for (
long pos = 0; pos < LineLength; pos++ )
39 RealType BaseVal = (RealType)m_Extreme;
41 for (
long krange = koffset; krange <= 0; krange++ )
44 RealType T = LineBuf[pos + krange] - magnitude * krange * krange;
46 if ( doDilate ? ( T >= BaseVal ) : ( T <= BaseVal ) )
52 tmpLineBuf[pos] = BaseVal;
53 koffset = newcontact - 1;
56 koffset = newcontact = 0;
57 for (
long pos = LineLength - 1; pos >= 0; pos-- )
59 RealType BaseVal = (RealType)m_Extreme;
60 for (
long krange = koffset; krange >= 0; krange-- )
62 RealType T = tmpLineBuf[pos + krange] - magnitude * krange * krange;
63 if ( doDilate ? ( T >= BaseVal ) : ( T <= BaseVal ) )
69 LineBuf[pos] = BaseVal;
70 koffset = newcontact + 1;
78 template<
class LineBufferType,
class IndexBufferType,
79 class EnvBufferType,
class RealType,
bool doDilate >
81 IndexBufferType & v, EnvBufferType & z,
82 const RealType magnitude)
105 F[0] = LineBuf[0] / magnitude;
106 const size_t N( LineBuf.size() );
108 for (
size_t q = 1; q < N; q++ )
113 F[q] = ( LineBuf[q] / magnitude ) - ( static_cast< RealType >( q ) *
static_cast< RealType
>( q ) );
120 s = ( F[q] - F[v[k]] ) / ( 2.0 * ( v[k] - static_cast< RealType >( q ) ) );
129 F[q] = ( LineBuf[q] / magnitude )
130 + ( static_cast< RealType >( q ) *
static_cast< RealType
>( q ) );
137 s = ( F[q] - F[v[k]] ) / ( 2.0 * ( static_cast< RealType >( q ) - v[k] ) );
145 itkAssertInDebugAndIgnoreInReleaseMacro( (
size_t)( k + 1 ) <= N );
152 for (
size_t q = 0; q < N; q++ )
154 while ( z[k + 1] < static_cast< typename IndexBufferType::ValueType >( q ) )
158 itkAssertInDebugAndIgnoreInReleaseMacro(static_cast< size_t >( v[k] ) < N);
159 itkAssertInDebugAndIgnoreInReleaseMacro(static_cast< size_t >( v[k] ) >= 0);
161 static_cast< RealType
>( ( F[v[k]]
162 - (
static_cast< RealType
>( q )
163 * ( static_cast< RealType >( q ) - 2 * v[k] ) ) ) * magnitude );
169 for (
size_t q = 0; q < N; q++ )
171 while ( z[k + 1] < static_cast< typename IndexBufferType::ValueType >( q ) )
175 itkAssertInDebugAndIgnoreInReleaseMacro(static_cast< size_t >( v[k] ) < N);
176 itkAssertInDebugAndIgnoreInReleaseMacro(static_cast< size_t >( v[k] ) >= 0);
178 ( (
static_cast< RealType
>( q ) * ( static_cast< RealType >( q ) - 2 * v[k] ) + F[v[k]] ) * magnitude );
183 template<
class TInIter,
class TOutIter,
class RealType,
184 class OutputPixelType,
bool doDilate >
187 const long LineLength,
188 const unsigned direction,
189 const int m_MagnitudeSign,
190 const bool m_UseImageSpacing,
191 const RealType m_Extreme,
192 const RealType image_scale,
193 const RealType Sigma,
194 int ParabolicAlgorithmChoice)
196 enum ParabolicAlgorithm {
207 RealType iscale = 1.0;
208 if ( m_UseImageSpacing )
210 iscale = image_scale;
212 if ( ParabolicAlgorithmChoice == NOCHOICE )
215 if ( ( 2.0 * Sigma ) < 0.2 )
217 ParabolicAlgorithmChoice = CONTACTPOINT;
221 ParabolicAlgorithmChoice = INTERSECTION;
225 if ( ParabolicAlgorithmChoice == CONTACTPOINT )
232 const RealType magnitudeCP = ( m_MagnitudeSign * iscale * iscale ) / ( 2.0 * Sigma );
234 LineBufferType LineBuf(LineLength);
235 LineBufferType tmpLineBuf(LineLength);
236 inputIterator.SetDirection(direction);
237 outputIterator.SetDirection(direction);
238 inputIterator.GoToBegin();
239 outputIterator.GoToBegin();
242 while ( !inputIterator.IsAtEnd() && !outputIterator.IsAtEnd() )
249 while ( !inputIterator.IsAtEndOfLine() )
251 LineBuf[i++] =
static_cast< RealType
>( inputIterator.Get() );
255 DoLineCP< LineBufferType, RealType, doDilate >(LineBuf, tmpLineBuf, magnitudeCP, m_Extreme);
258 while ( !outputIterator.IsAtEndOfLine() )
260 outputIterator.Set( static_cast< OutputPixelType >( LineBuf[j++] ) );
266 inputIterator.NextLine();
267 outputIterator.NextLine();
276 const RealType magnitudeInt = ( iscale * iscale ) / ( 2.0 * Sigma );
277 LineBufferType LineBuf(LineLength);
278 LineBufferType Fbuf(LineLength);
279 IndexBufferType Vbuf(LineLength);
280 LineBufferType Zbuf(LineLength + 1);
282 inputIterator.SetDirection(direction);
283 outputIterator.SetDirection(direction);
284 inputIterator.GoToBegin();
285 outputIterator.GoToBegin();
288 while ( !inputIterator.IsAtEnd() && !outputIterator.IsAtEnd() )
295 while ( !inputIterator.IsAtEndOfLine() )
297 LineBuf[i++] =
static_cast< RealType
>( inputIterator.Get() );
301 LineBufferType, RealType, doDilate >(LineBuf, Fbuf, Vbuf, Zbuf, magnitudeInt);
304 while ( !outputIterator.IsAtEndOfLine() )
306 outputIterator.Set( static_cast< OutputPixelType >( LineBuf[j++] ) );
312 inputIterator.NextLine();
313 outputIterator.NextLine();
void DoLineCP(LineBufferType &LineBuf, LineBufferType &tmpLineBuf, const RealType magnitude, const RealType m_Extreme)
void doOneDimension(TInIter &inputIterator, TOutIter &outputIterator, ProgressReporter &progress, const long LineLength, const unsigned direction, const int m_MagnitudeSign, const bool m_UseImageSpacing, const RealType m_Extreme, const RealType image_scale, const RealType Sigma, int ParabolicAlgorithmChoice)
void DoLineIntAlg(LineBufferType &LineBuf, EnvBufferType &F, IndexBufferType &v, EnvBufferType &z, const RealType magnitude)
static ITK_CONSTEXPR_FUNC T max(const T &)
Implements progress tracking for a filter.
static ITK_CONSTEXPR_FUNC T NonpositiveMin()