19 #ifndef itkContourExtractor2DImageFilter_h
20 #define itkContourExtractor2DImageFilter_h
22 #include <itkConceptChecking.h>
24 #include <itkNumericTraits.h>
25 #include <itkPolyLineParametricPath.h>
28 #include <unordered_map>
90 template <
class TInputImage>
130 itkSetMacro(ReverseContourOrientation,
bool);
131 itkGetConstReferenceMacro(ReverseContourOrientation,
bool);
132 itkBooleanMacro(ReverseContourOrientation);
137 itkSetMacro(VertexConnectHighPixels,
bool);
138 itkGetConstReferenceMacro(VertexConnectHighPixels,
bool);
139 itkBooleanMacro(VertexConnectHighPixels);
155 #ifdef ITK_USE_CONCEPT_CHECKING
157 itkConceptMacro(DimensionShouldBe2, (Concept::SameDimension<itkGetStaticConstMacro(InputImageDimension), 2>));
158 itkConceptMacro(InputPixelTypeComparable, (Concept::Comparable<InputPixelType>));
159 itkConceptMacro(InputHasPixelTraitsCheck, (Concept::HasPixelTraits<InputPixelType>));
160 itkConceptMacro(InputHasNumericTraitsCheck, (Concept::HasNumericTraits<InputPixelType>));
167 void PrintSelf(std::ostream &os, Indent indent)
const override;
184 void operator=(
const Self &);
187 bool m_ReverseContourOrientation;
188 bool m_VertexConnectHighPixels;
189 bool m_UseCustomRegion;
191 unsigned int m_NumberOfContoursCreated;
208 class ContourType :
public std::deque<VertexType>
211 unsigned int m_ContourNumber;
217 typedef std::list<ContourType> ContourContainer;
218 typedef typename ContourContainer::iterator ContourRef;
223 typedef typename VertexType::CoordRepType CoordinateType;
224 inline size_t operator()(
const VertexType &k)
const
230 const size_t hashVertex1 = this->float_hash(k[0] * 0xbeef);
231 const size_t hashVertex2 = this->float_hash(k[1]);
232 const size_t hashValue = hashVertex1 ^ hashVertex2;
237 inline size_t float_hash(
const CoordinateType &k)
const
244 CoordinateType mantissa = std::frexp(k, &exponent);
245 size_t value =
static_cast<size_t>(std::fabs(mantissa));
246 value = (2 * value - 1) * ~0U;
263 typedef std::unordered_map<VertexType, ContourRef, VertexHash> VertexToContourMap;
264 typedef typename VertexToContourMap::iterator VertexMapIterator;
265 typedef typename VertexToContourMap::value_type VertexContourRefPair;
268 ContourContainer m_Contours;
271 VertexToContourMap m_ContourStarts;
272 VertexToContourMap m_ContourEnds;
277 #ifndef ITK_MANUAL_INSTANTIATION
278 #include <itkContourExtractor2DImageFilter.tpp>
Base class for filters that take an image as input and produce an path as output.