Orfeo Toolbox
3.16
Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
OTB
Code
Visualization
otbAmplitudeFunctor.h
Go to the documentation of this file.
1
/*=========================================================================
2
3
Program: ORFEO Toolbox
4
Language: C++
5
Date: $Date$
6
Version: $Revision$
7
8
9
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10
See OTBCopyright.txt for details.
11
12
13
This software is distributed WITHOUT ANY WARRANTY; without even
14
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15
PURPOSE. See the above copyright notices for more information.
16
17
=========================================================================*/
18
#ifndef __otbAmplitudeFunctor_h
19
#define __otbAmplitudeFunctor_h
20
21
#include "
otbChannelSelectorFunctor.h
"
22
23
namespace
otb
24
{
25
namespace
Function
26
{
34
template
<
class
TInputPixel>
35
class
AmplitudeFunctor
:
public
ChannelSelectorFunctor
<TInputPixel>
36
{
37
public
:
39
typedef
AmplitudeFunctor
Self
;
40
typedef
itk::Object
Superclass
;
41
typedef
itk::SmartPointer<Self>
Pointer
;
42
typedef
itk::SmartPointer<const Self>
ConstPointer
;
43
45
itkNewMacro(
Self
);
46
48
itkTypeMacro(
AmplitudeFunctor
,
itk::Object
);
49
50
typedef
TInputPixel
PixelType
;
51
typedef
typename
itk::NumericTraits<PixelType>::ValueType
ScalarType
;
52
typedef
itk::VariableLengthVector<ScalarType>
VectorPixelType
;
53
typedef
itk::RGBPixel<ScalarType>
RGBPixelType
;
54
typedef
itk::RGBAPixel<ScalarType>
RGBAPixelType
;
55
56
typedef
VectorPixelType
OutputPixelType
;
57
59
AmplitudeFunctor
()
60
{
61
std::vector<unsigned int> channels;
62
channels.push_back(0);
63
channels.push_back(1);
64
this->
SetChannelList
(channels);
65
}
66
68
virtual
~AmplitudeFunctor
() {}
69
70
const
char
*
GetDescription
()
const
71
{
return
"Amplitude"
; }
72
73
virtual
unsigned
int
GetOutputSize
()
const
74
{
75
return
1;
76
}
77
78
virtual
OutputPixelType
operator ()
(
const
VectorPixelType
& inPixel)
const
79
{
80
OutputPixelType
outPixel;
81
outPixel.
SetSize
(1);
82
assert((this->
GetChannelList
()).size() == 2);
83
assert((this->
GetChannelList
())[0] < inPixel.
Size
());
84
assert((this->
GetChannelList
())[1] < inPixel.
Size
());
85
outPixel[0] =
ComputeAmplitude
(inPixel[(this->
GetChannelList
())[0]], inPixel[(this->
GetChannelList
())[1]]);
86
return
outPixel;
87
}
88
89
virtual
OutputPixelType
operator ()
(
ScalarType
)
const
90
{
91
//FIXME we don't handle the std::complex<> yet
92
itkExceptionMacro(<<
"Can't compute amplitude from a scalar value"
);
93
}
94
95
virtual
OutputPixelType
operator ()
(
const
RGBPixelType
& inPixel)
const
96
{
97
OutputPixelType
outPixel;
98
outPixel.
SetSize
(1);
99
100
assert((this->
GetChannelList
()).size() == 2);
101
assert((this->
GetChannelList
())[0] < 3);
102
assert((this->
GetChannelList
())[1] < 3);
103
104
outPixel[0] =
ComputeAmplitude
(inPixel[(this->
GetChannelList
())[0]], inPixel[(this->
GetChannelList
())[1]]);
105
return
outPixel;
106
}
107
108
virtual
OutputPixelType
operator ()
(
const
RGBAPixelType
& inPixel)
const
109
{
110
OutputPixelType
outPixel;
111
outPixel.
SetSize
(1);
112
113
assert((this->
GetChannelList
()).size() == 2);
114
assert((this->
GetChannelList
())[0] < 4);
115
assert((this->
GetChannelList
())[1] < 4);
116
117
outPixel[0] =
ComputeAmplitude
(inPixel[(this->
GetChannelList
())[0]], inPixel[(this->
GetChannelList
())[1]]);
118
return
outPixel;
119
}
120
121
private
:
122
inline
ScalarType
ComputeAmplitude
(
ScalarType
a,
ScalarType
b)
const
123
{
124
return
vcl_sqrt(a * a + b * b);
125
}
126
127
};
128
}
129
}
130
131
#endif
Generated at Sun Feb 3 2013 00:16:03 for
Orfeo Toolbox
with
doxygen 1.8.1.1