Go to the documentation of this file.00001 #ifndef __itkParabolicUtils_h
00002 #define __itkParabolicUtils_h
00003
00004 #include <itkArray.h>
00005
00006 #include "itkProgressReporter.h"
00007 namespace itk {
00008 template <class LineBufferType, class RealType, bool doDilate>
00009 void DoLine(LineBufferType &LineBuf, LineBufferType &tmpLineBuf,
00010 const RealType magnitude, const RealType m_Extreme)
00011 {
00012
00013 long koffset = 0, newcontact=0;
00014
00015 const long LineLength = LineBuf.size();
00016
00017 for (long pos = 0; pos < LineLength; pos++)
00018 {
00019 RealType BaseVal = (RealType)m_Extreme;
00020
00021 for (long krange = koffset; krange <= 0; krange++)
00022 {
00023
00024 RealType T = LineBuf[pos + krange] - magnitude * krange * krange;
00025
00026 if (doDilate ? (T >= BaseVal) : (T <= BaseVal) )
00027 {
00028 BaseVal = T;
00029 newcontact = krange;
00030 }
00031 }
00032 tmpLineBuf[pos] = BaseVal;
00033 koffset = newcontact - 1;
00034 }
00035
00036 koffset = newcontact = 0;
00037 for (long pos = LineLength - 1; pos >= 0; pos--)
00038 {
00039 RealType BaseVal = (RealType)m_Extreme;
00040 for (long krange = koffset; krange >= 0; krange--)
00041 {
00042 RealType T = tmpLineBuf[pos + krange] - magnitude * krange * krange;
00043 if (doDilate ? (T >= BaseVal) : (T <= BaseVal))
00044 {
00045 BaseVal = T;
00046 newcontact = krange;
00047 }
00048 }
00049 LineBuf[pos] = BaseVal;
00050 koffset = newcontact + 1;
00051 }
00052 }
00053
00054 template <class TInIter, class TOutIter, class RealType,
00055 class OutputPixelType, bool doDilate>
00056 void doOneDimension(TInIter &inputIterator, TOutIter &outputIterator,
00057 ProgressReporter &progress,
00058 const long LineLength,
00059 const unsigned direction,
00060 const int m_MagnitudeSign,
00061 const bool m_UseImageSpacing,
00062 const RealType m_Extreme,
00063 const RealType image_scale,
00064 const RealType Sigma)
00065 {
00066
00067
00068
00069
00070 typedef typename itk::Array<RealType> LineBufferType;
00071 RealType iscale = 1.0;
00072 if (m_UseImageSpacing)
00073 {
00074 iscale = image_scale;
00075 }
00076 const RealType magnitude = m_MagnitudeSign * 1.0/(2.0 * Sigma/(iscale*iscale));
00077 LineBufferType LineBuf(LineLength);
00078 LineBufferType tmpLineBuf(LineLength);
00079 inputIterator.SetDirection(direction);
00080 outputIterator.SetDirection(direction);
00081 inputIterator.GoToBegin();
00082 outputIterator.GoToBegin();
00083
00084 while( !inputIterator.IsAtEnd() && !outputIterator.IsAtEnd() )
00085 {
00086
00087
00088
00089 unsigned int i=0;
00090 while( !inputIterator.IsAtEndOfLine() )
00091 {
00092 LineBuf[i++] = static_cast<RealType>(inputIterator.Get());
00093 ++inputIterator;
00094 }
00095
00096 DoLine<LineBufferType, RealType, doDilate>(LineBuf, tmpLineBuf, magnitude, m_Extreme);
00097
00098 unsigned int j=0;
00099 while( !outputIterator.IsAtEndOfLine() )
00100 {
00101 outputIterator.Set( static_cast<OutputPixelType>( LineBuf[j++] ) );
00102 ++outputIterator;
00103 }
00104
00105
00106 inputIterator.NextLine();
00107 outputIterator.NextLine();
00108 progress.CompletedPixel();
00109 }
00110 }
00111
00112
00113 }
00114 #endif