ITK
4.2.0
Insight Segmentation and Registration Toolkit
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
ITK
Modules
Filtering
ImageFusion
include
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
<
class
TInputPixel,
class
TLabel,
class
TRGBPixel >
47
class
LabelOverlayFunctor
48
{
49
public
:
50
LabelOverlayFunctor
()
51
{
52
// provide some default value for external use (outside
53
// LabelOverlayFunctorImageFilter) Inside LabelOverlayFunctorImageFilter,
54
// the values are always initialized
55
m_BackgroundValue
=
NumericTraits< TLabel >::Zero
;
56
}
57
58
inline
TRGBPixel
operator()
(
const
TInputPixel & p1,
const
TLabel & p2)
const
59
{
60
TRGBPixel rgbPixel;
61
NumericTraits<TRGBPixel>::SetLength
(rgbPixel, 3);
62
63
if
( p2 ==
m_BackgroundValue
)
64
{
65
// value is background
66
// return a gray pixel with the same intensity than the input pixel
67
typename
TRGBPixel::ValueType p =
68
static_cast<
typename TRGBPixel::ValueType
>
( p1 );
69
rgbPixel[0] = p;
70
rgbPixel[1] = p;
71
rgbPixel[2] = p;
72
return
rgbPixel;
73
}
74
75
// taint the input pixel with the colored one returned by
76
// the color functor.
77
TRGBPixel opaque =
m_RGBFunctor
(p2);
78
for
(
unsigned
int
i = 0; i < 3; i++ )
79
{
80
rgbPixel[i] =
static_cast<
typename TRGBPixel::ValueType
>
(
81
opaque[i] *
m_Opacity
+ p1 * ( 1.0 -
m_Opacity
) );
82
}
83
return
rgbPixel;
84
}
85
86
bool
operator!=
(
const
LabelOverlayFunctor
& l)
const
87
{
88
bool
value = l.
m_Opacity
!=
m_Opacity
89
||
m_BackgroundValue
!= l.
m_BackgroundValue
;
90
91
return
value;
92
}
93
94
~LabelOverlayFunctor
() {}
95
96
void
SetOpacity
(
double
opacity)
97
{
98
m_Opacity
= opacity;
99
}
100
101
void
SetBackgroundValue
(TLabel v)
102
{
103
m_BackgroundValue
= v;
104
m_RGBFunctor
.SetBackgroundValue(v);
105
}
106
107
void
ResetColors
()
108
{
109
m_RGBFunctor
.ResetColors();
110
}
111
112
unsigned
int
GetNumberOfColors
()
const
113
{
114
return
m_RGBFunctor
.GetNumberOfColors();
115
}
116
118
typedef
typename
TRGBPixel::ComponentType
ComponentType
;
119
120
void
AddColor
(
ComponentType
r,
ComponentType
g,
ComponentType
b)
121
{
122
m_RGBFunctor
.AddColor(r, g, b);
123
}
124
125
protected
:
126
private
:
127
double
m_Opacity
;
128
TLabel
m_BackgroundValue
;
129
130
typename
Functor::LabelToRGBFunctor< TLabel, TRGBPixel >
m_RGBFunctor
;
131
};
132
}
// end namespace functor
133
}
// end namespace itk
134
135
#endif
136
Generated on Tue Jul 10 2012 23:33:38 for ITK by
1.8.1