18 #ifndef itkParabolicMorphUtils_h
19 #define itkParabolicMorphUtils_h
26 template<
class LineBufferType,
class RealType,
bool doDilate >
27 void DoLineCP(LineBufferType & LineBuf, LineBufferType & tmpLineBuf,
28 const RealType magnitude,
const RealType m_Extreme)
31 long koffset = 0, newcontact = 0;
33 const long LineLength = LineBuf.size();
36 for (
long pos = 0; pos < LineLength; pos++ )
38 auto BaseVal = (RealType)m_Extreme;
40 for (
long krange = koffset; krange <= 0; krange++ )
43 RealType T = LineBuf[pos + krange] - magnitude * krange * krange;
45 if ( doDilate ? ( T >= BaseVal ) : ( T <= BaseVal ) )
51 tmpLineBuf[pos] = BaseVal;
52 koffset = newcontact - 1;
55 koffset = newcontact = 0;
56 for (
long pos = LineLength - 1; pos >= 0; pos-- )
58 auto BaseVal = (RealType)m_Extreme;
59 for (
long krange = koffset; krange >= 0; krange-- )
61 RealType T = tmpLineBuf[pos + krange] - magnitude * krange * krange;
62 if ( doDilate ? ( T >= BaseVal ) : ( T <= BaseVal ) )
68 LineBuf[pos] = BaseVal;
69 koffset = newcontact + 1;
77 template<
class LineBufferType,
class IndexBufferType,
78 class EnvBufferType,
class RealType,
bool doDilate >
80 IndexBufferType & v, EnvBufferType & z,
81 const RealType magnitude)
104 F[0] = LineBuf[0] / magnitude;
105 const size_t N( LineBuf.size() );
107 for (
size_t q = 1; q < N; q++ )
112 F[q] = ( LineBuf[q] / magnitude ) - ( static_cast< RealType >( q ) *
static_cast< RealType
>( q ) );
119 s = ( F[q] - F[v[k]] ) / ( 2.0 * ( v[k] - static_cast< RealType >( q ) ) );
128 F[q] = ( LineBuf[q] / magnitude )
129 + ( static_cast< RealType >( q ) *
static_cast< RealType
>( q ) );
136 s = ( F[q] - F[v[k]] ) / ( 2.0 * ( static_cast< RealType >( q ) - v[k] ) );
144 itkAssertInDebugAndIgnoreInReleaseMacro( (
size_t)( k + 1 ) <= N );
151 for (
size_t q = 0; q < N; q++ )
153 while ( z[k + 1] < static_cast< typename IndexBufferType::ValueType >( q ) )
157 itkAssertInDebugAndIgnoreInReleaseMacro(static_cast< size_t >( v[k] ) < N);
158 itkAssertInDebugAndIgnoreInReleaseMacro(static_cast< size_t >( v[k] ) >= 0);
160 static_cast< RealType
>( ( F[v[k]]
161 - (
static_cast< RealType
>( q )
162 * ( static_cast< RealType >( q ) - 2 * v[k] ) ) ) * magnitude );
168 for (
size_t q = 0; q < N; q++ )
170 while ( z[k + 1] < static_cast< typename IndexBufferType::ValueType >( q ) )
174 itkAssertInDebugAndIgnoreInReleaseMacro(static_cast< size_t >( v[k] ) < N);
175 itkAssertInDebugAndIgnoreInReleaseMacro(static_cast< size_t >( v[k] ) >= 0);
177 ( (
static_cast< RealType
>( q ) * ( static_cast< RealType >( q ) - 2 * v[k] ) + F[v[k]] ) * magnitude );
182 template<
class TInIter,
class TOutIter,
class RealType,
183 class OutputPixelType,
bool doDilate >
185 const long LineLength,
186 const unsigned direction,
187 const int m_MagnitudeSign,
188 const bool m_UseImageSpacing,
189 const RealType m_Extreme,
190 const RealType image_scale,
191 const RealType Sigma,
192 int ParabolicAlgorithmChoice)
194 enum ParabolicAlgorithm {
205 RealType iscale = 1.0;
206 if ( m_UseImageSpacing )
208 iscale = image_scale;
210 if ( ParabolicAlgorithmChoice == NOCHOICE )
213 if ( ( 2.0 * Sigma ) < 0.2 )
215 ParabolicAlgorithmChoice = CONTACTPOINT;
219 ParabolicAlgorithmChoice = INTERSECTION;
223 if ( ParabolicAlgorithmChoice == CONTACTPOINT )
230 const RealType magnitudeCP = ( m_MagnitudeSign * iscale * iscale ) / ( 2.0 * Sigma );
232 LineBufferType LineBuf(LineLength);
233 LineBufferType tmpLineBuf(LineLength);
234 inputIterator.SetDirection(direction);
235 outputIterator.SetDirection(direction);
236 inputIterator.GoToBegin();
237 outputIterator.GoToBegin();
240 while ( !inputIterator.IsAtEnd() && !outputIterator.IsAtEnd() )
247 while ( !inputIterator.IsAtEndOfLine() )
249 LineBuf[i++] =
static_cast< RealType
>( inputIterator.Get() );
253 DoLineCP< LineBufferType, RealType, doDilate >(LineBuf, tmpLineBuf, magnitudeCP, m_Extreme);
256 while ( !outputIterator.IsAtEndOfLine() )
258 outputIterator.Set( static_cast< OutputPixelType >( LineBuf[j++] ) );
264 inputIterator.NextLine();
265 outputIterator.NextLine();
273 const RealType magnitudeInt = ( iscale * iscale ) / ( 2.0 * Sigma );
274 LineBufferType LineBuf(LineLength);
275 LineBufferType Fbuf(LineLength);
276 IndexBufferType Vbuf(LineLength);
277 LineBufferType Zbuf(LineLength + 1);
279 inputIterator.SetDirection(direction);
280 outputIterator.SetDirection(direction);
281 inputIterator.GoToBegin();
282 outputIterator.GoToBegin();
285 while ( !inputIterator.IsAtEnd() && !outputIterator.IsAtEnd() )
292 while ( !inputIterator.IsAtEndOfLine() )
294 LineBuf[i++] =
static_cast< RealType
>( inputIterator.Get() );
298 LineBufferType, RealType, doDilate >(LineBuf, Fbuf, Vbuf, Zbuf, magnitudeInt);
301 while ( !outputIterator.IsAtEndOfLine() )
303 outputIterator.Set( static_cast< OutputPixelType >( LineBuf[j++] ) );
309 inputIterator.NextLine();
310 outputIterator.NextLine();
void DoLineCP(LineBufferType &LineBuf, LineBufferType &tmpLineBuf, const RealType magnitude, const RealType m_Extreme)
Define numeric traits for std::vector.
void DoLineIntAlg(LineBufferType &LineBuf, EnvBufferType &F, IndexBufferType &v, EnvBufferType &z, const RealType magnitude)
void doOneDimension(TInIter &inputIterator, TOutIter &outputIterator, 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)