ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkMaskNegatedImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkMaskNegatedImageFilter_h
19 #define __itkMaskNegatedImageFilter_h
20 
22 #include "itkNumericTraits.h"
23 
24 namespace itk
25 {
26 namespace Functor
27 {
33 template< class TInput, class TMask, class TOutput = TInput >
35 {
36 public:
38 
41  bool operator!=(const MaskNegatedInput &) const
42  {
43  return false;
44  }
45 
46  bool operator==(const MaskNegatedInput & other) const
47  {
48  return !( *this != other );
49  }
50 
51  inline TOutput operator()(const TInput & A, const TMask & B) const
52  {
54  {
55  return m_OutsideValue;
56  }
57  else
58  {
59  return static_cast< TOutput >( A );
60  }
61  }
62 
64  void SetOutsideValue(const TOutput & outsideValue)
65  {
66  m_OutsideValue = outsideValue;
67  }
68 
70  const TOutput & GetOutsideValue() const
71  {
72  return m_OutsideValue;
73  }
74 
75 private:
76  TOutput m_OutsideValue;
77 };
78 }
112 template< class TInputImage, class TMaskImage, class TOutputImage = TInputImage >
113 class ITK_EXPORT MaskNegatedImageFilter:
114  public
115  BinaryFunctorImageFilter< TInputImage, TMaskImage, TOutputImage,
116  Functor::MaskNegatedInput<
117  typename TInputImage::PixelType,
118  typename TMaskImage::PixelType,
119  typename TOutputImage::PixelType > >
120 
121 {
122 public:
125  typedef BinaryFunctorImageFilter< TInputImage, TMaskImage, TOutputImage,
127  typename TInputImage::PixelType,
128  typename TMaskImage::PixelType,
129  typename TOutputImage::PixelType >
131 
134 
136  itkNewMacro(Self);
137 
139  itkTypeMacro(MaskNegatedImageFilter,
141 
143  typedef TMaskImage MaskImageType;
144 
146  void SetOutsideValue(const typename TOutputImage::PixelType & outsideValue)
147  {
148  if ( this->GetOutsideValue() != outsideValue )
149  {
150  this->Modified();
151  this->GetFunctor().SetOutsideValue(outsideValue);
152  }
153  }
155 
156  const typename TOutputImage::PixelType & GetOutsideValue() const
157  {
158  return this->GetFunctor().GetOutsideValue();
159  }
160 
165  void SetMaskImage(const MaskImageType *maskImage)
166  {
167  // Process object is not const-correct so the const casting is required.
168  this->SetNthInput( 1, const_cast< MaskImageType * >( maskImage ) );
169  }
170 
171  const MaskImageType * GetMaskImage()
172  {
173  return static_cast<const MaskImageType*>(this->ProcessObject::GetInput(1));
174  }
175 
176 #ifdef ITK_USE_CONCEPT_CHECKING
177 
178  itkConceptMacro( MaskEqualityComparableCheck,
180  itkConceptMacro( InputConvertibleToOutputCheck,
181  ( Concept::Convertible< typename TInputImage::PixelType,
182  typename TOutputImage::PixelType > ) );
183 
185 #endif
186 protected:
190 
191  void PrintSelf(std::ostream & os, Indent indent) const
192  {
193  Superclass::PrintSelf(os, indent);
194  os << indent << "OutsideValue: " << this->GetOutsideValue() << std::endl;
195  }
196 
197 private:
198  MaskNegatedImageFilter(const Self &); //purposely not implemented
199  void operator=(const Self &); //purposely not implemented
200 };
201 } // end namespace itk
202 
203 #endif
204