ITK  4.8.0
Insight Segmentation and Registration Toolkit
itkLabelOverlayFunctor.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 itkLabelOverlayFunctor_h
19 #define itkLabelOverlayFunctor_h
20 
21 #include "itkLabelToRGBFunctor.h"
22 
23 namespace itk
24 {
25 namespace Functor
26 {
46 template< typename TInputPixel, typename TLabel, typename TRGBPixel >
48 {
49 public:
51  {
52  // provide some default value for external use (outside
53  // LabelOverlayFunctorImageFilter) Inside LabelOverlayFunctorImageFilter,
54  // the values are always initialized
55  m_Opacity = 1.0;
57  }
58 
59  inline TRGBPixel operator()(const TInputPixel & p1, const TLabel & p2) const
60  {
61  TRGBPixel rgbPixel;
63 
64  if ( p2 == m_BackgroundValue )
65  {
66  // value is background
67  // return a gray pixel with the same intensity than the input pixel
68  typename TRGBPixel::ValueType p =
69  static_cast< typename TRGBPixel::ValueType >( p1 );
70  rgbPixel[0] = p;
71  rgbPixel[1] = p;
72  rgbPixel[2] = p;
73  return rgbPixel;
74  }
75 
76  // taint the input pixel with the colored one returned by
77  // the color functor.
78  TRGBPixel opaque = m_RGBFunctor(p2);
79  // the following has been unrolled due to a bug with apple's
80  // llvm-gcc-4.2 build 5658
81  const double p1_blend= p1 * ( 1.0 - m_Opacity );
82  rgbPixel[0] = static_cast< typename TRGBPixel::ValueType >( opaque[0] * m_Opacity + p1_blend );
83  rgbPixel[1] = static_cast< typename TRGBPixel::ValueType >( opaque[1] * m_Opacity + p1_blend );
84  rgbPixel[2] = static_cast< typename TRGBPixel::ValueType >( opaque[2] * m_Opacity + p1_blend );
85 
86  return rgbPixel;
87  }
88 
89  bool operator!=(const LabelOverlayFunctor & l) const
90  {
91  bool areDifferent = l.m_Opacity != m_Opacity
93  || l.m_RGBFunctor != m_RGBFunctor;
94  return areDifferent;
95  }
96 
97  bool operator==(const LabelOverlayFunctor & l) const
98  {
99  return !(*this != l);
100  }
101 
103 
104  void SetOpacity(double opacity)
105  {
106  m_Opacity = opacity;
107  }
108 
109  void SetBackgroundValue(TLabel v)
110  {
111  m_BackgroundValue = v;
112  m_RGBFunctor.SetBackgroundValue(v);
113  }
114 
115  void ResetColors()
116  {
117  m_RGBFunctor.ResetColors();
118  }
119 
120  unsigned int GetNumberOfColors() const
121  {
122  return m_RGBFunctor.GetNumberOfColors();
123  }
124 
126  typedef typename TRGBPixel::ComponentType ComponentType;
127 
129  {
130  m_RGBFunctor.AddColor(r, g, b);
131  }
132 
133 protected:
134 
135 private:
136  double m_Opacity;
138 
140 };
141 } // end namespace functor
142 } // end namespace itk
143 
144 #endif
bool operator==(const LabelOverlayFunctor &l) const
Functor for applying a colormap to a label image and combine it with a grayscale image.
static void SetLength(T &m, const unsigned int s)
Functor for converting labels into RGB triplets.
bool operator!=(const LabelOverlayFunctor &l) const
TRGBPixel operator()(const TInputPixel &p1, const TLabel &p2) const
void AddColor(ComponentType r, ComponentType g, ComponentType b)
Functor::LabelToRGBFunctor< TLabel, TRGBPixel > m_RGBFunctor