plastimatch
Loading...
Searching...
No Matches
itkAndConstantToImageFilter.h
Go to the documentation of this file.
1/* -----------------------------------------------------------------------
2 See COPYRIGHT.TXT and LICENSE.TXT for copyright and license information
3 ----------------------------------------------------------------------- */
4#ifndef __itkAndConstantToImageFilter_h
5#define __itkAndConstantToImageFilter_h
6
7#include "itkUnaryFunctorImageFilter.h"
8#include "itkNumericTraits.h"
9
10namespace itk
11{
12
13/* Thanks for broilerplate code:
14 * \author Tom Vercauteren, INRIA & Mauna Kea Technologies
15 * which is based on filters from the Insight Journal paper:
16 * http://hdl.handle.net/1926/510
17 */
18namespace Functor {
19
20template< class TInput, class TConstant, class TOutput>
22{
23public:
24 AndConstantTo() : m_Constant(NumericTraits<TConstant>::One) {};
26 bool operator!=( const AndConstantTo & other ) const
27 {
28 return !(*this == other);
29 }
30 bool operator==( const AndConstantTo & other ) const
31 {
32 return other.m_Constant == m_Constant;
33 }
34 inline TOutput operator()( const TInput & A ) const
35 {
36 // Because the user has to specify the constant we don't
37 // check if the cte is not 0;
38 return static_cast<TOutput>( ((A & m_Constant) > 0) );
39 }
40 void SetConstant(TConstant ct) {this->m_Constant = ct; }
41 const TConstant & GetConstant() const { return m_Constant; }
42
43 TConstant m_Constant;
44};
45}
46
47template <class TInputImage, class TConstant, class TOutputImage>
48class ITK_EXPORT AndConstantToImageFilter :
49 public
50UnaryFunctorImageFilter<TInputImage,TOutputImage,
51 Functor::AndConstantTo<
52 typename TInputImage::PixelType, TConstant,
53 typename TOutputImage::PixelType> >
54{
55 public:
58 typedef UnaryFunctorImageFilter<
59 TInputImage,TOutputImage,
61 typename TInputImage::PixelType, TConstant,
62 typename TOutputImage::PixelType> > Superclass;
63
64 typedef SmartPointer<Self> Pointer;
65 typedef SmartPointer<const Self> ConstPointer;
66
69
71 itkTypeMacro(AndConstantToImageFilter, UnaryFunctorImageFilter);
72
73
76 void SetConstant(TConstant ct)
77 {
78 if( ct != this->GetFunctor().GetConstant() )
79 {
80 this->GetFunctor().SetConstant(ct);
81 this->Modified();
82 }
83 }
84 const TConstant & GetConstant() const
85 {
86 return this->GetFunctor().GetConstant();
87 }
88
89#ifdef ITK_USE_CONCEPT_CHECKING
91 itkConceptMacro(InputConvertibleToOutputCheck,
92 (Concept::Convertible<typename TInputImage::PixelType,
93 typename TOutputImage::PixelType>));
94 itkConceptMacro(Input1Input2OutputAndOperatorCheck,
95 (Concept::AdditiveOperators<typename TInputImage::PixelType,
96 TConstant,
97 typename TOutputImage::PixelType>));
99#endif
100
101 protected:
104
105 void PrintSelf(std::ostream &os, Indent indent) const
106 {
107 Superclass::PrintSelf(os, indent);
108 os << indent << "Constant: "
109 << static_cast<typename NumericTraits<TConstant>::PrintType>(this->GetConstant())
110 << std::endl;
111 }
112
113 private:
114 AndConstantToImageFilter(const Self&); //purposely not implemented
115 void operator=(const Self&); //purposely not implemented
116
117};
118
119
120} // end namespace itk
121
122#endif
Definition: itkAndConstantToImageFilter.h:54
SmartPointer< const Self > ConstPointer
Definition: itkAndConstantToImageFilter.h:65
SmartPointer< Self > Pointer
Definition: itkAndConstantToImageFilter.h:64
UnaryFunctorImageFilter< TInputImage, TOutputImage, Functor::AndConstantTo< typename TInputImage::PixelType, TConstant, typename TOutputImage::PixelType > > Superclass
Definition: itkAndConstantToImageFilter.h:62
itkTypeMacro(AndConstantToImageFilter, UnaryFunctorImageFilter)
const TConstant & GetConstant() const
Definition: itkAndConstantToImageFilter.h:84
void SetConstant(TConstant ct)
Definition: itkAndConstantToImageFilter.h:76
AndConstantToImageFilter()
Definition: itkAndConstantToImageFilter.h:102
void PrintSelf(std::ostream &os, Indent indent) const
Definition: itkAndConstantToImageFilter.h:105
virtual ~AndConstantToImageFilter()
Definition: itkAndConstantToImageFilter.h:103
AndConstantToImageFilter Self
Definition: itkAndConstantToImageFilter.h:57
Definition: itkAndConstantToImageFilter.h:22
bool operator!=(const AndConstantTo &other) const
Definition: itkAndConstantToImageFilter.h:26
bool operator==(const AndConstantTo &other) const
Definition: itkAndConstantToImageFilter.h:30
AndConstantTo()
Definition: itkAndConstantToImageFilter.h:24
void SetConstant(TConstant ct)
Definition: itkAndConstantToImageFilter.h:40
const TConstant & GetConstant() const
Definition: itkAndConstantToImageFilter.h:41
~AndConstantTo()
Definition: itkAndConstantToImageFilter.h:25
TOutput operator()(const TInput &A) const
Definition: itkAndConstantToImageFilter.h:34
TConstant m_Constant
Definition: itkAndConstantToImageFilter.h:43
Definition: direction_cosines.h:19