ITK  5.4.0
Insight Toolkit
itkJoinImageFilter.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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 itkJoinImageFilter_h
19#define itkJoinImageFilter_h
20
22#include "itkPixelTraits.h"
23
24namespace itk
25{
26namespace Functor
27{
47template <typename TPixel1, typename TPixel2>
49{
50public:
51
54
59
61 static constexpr unsigned int Dimension1 = PixelTraits<TPixel1>::Dimension;
62 static constexpr unsigned int Dimension2 = PixelTraits<TPixel2>::Dimension;
63 static constexpr unsigned int JoinDimension = Dimension1 + Dimension2;
64
67
68 bool
69 operator==(const JoinFunctor &) const
70 {
71 return true;
72 }
73
75
77 inline JoinType
78 operator()(const TPixel1 & A, const TPixel2 & B) const
79 {
80 JoinType out;
81
82 // Copy A into the output, casting as necessary
83 this->FirstCopier(out, 0, A);
84
85 // Copy B into the output, starting where A left off,casting as necessary
86 this->SecondCopier(out, Dimension1, B);
87
88 return out;
89 }
90
91private:
99 {};
100 template <unsigned int VDimension>
102 {};
103
114 void
115 FirstCopier(JoinType & out, unsigned int idx, const TPixel1 & A) const
116 {
118 }
119
121 void
122 FirstCopier(CopierDispatchBase, JoinType & out, unsigned int idx, const TPixel1 & A) const
123 {
124 for (unsigned int i = 0; i < Dimension1; i++, idx++)
125 {
126 out[idx] = static_cast<JoinValueType>(A[i]);
127 }
128 }
132 void FirstCopier(CopierDispatch<1>, JoinType & out, unsigned int idx, const TPixel1 & A) const
133 {
134 out[idx] = static_cast<JoinValueType>(A);
135 }
136
142 void
143 SecondCopier(JoinType & out, unsigned int idx, const TPixel2 & B) const
144 {
146 }
147
149 void
150 SecondCopier(CopierDispatchBase, JoinType & out, unsigned int idx, const TPixel2 & B) const
151 {
152 for (unsigned int i = 0; i < Dimension2; i++, idx++)
153 {
154 out[idx] = static_cast<JoinValueType>(B[i]);
155 }
156 }
160 void SecondCopier(CopierDispatch<1>, JoinType & out, unsigned int idx, const TPixel2 & B) const
161 {
162 out[idx] = static_cast<JoinValueType>(B);
163 }
164}; // class JoinFunction
167template <typename TImage1, typename TImage2>
169{
172};
173} // namespace Functor
174
205template <typename TInputImage1, typename TInputImage2>
207 : public BinaryGeneratorImageFilter<TInputImage1,
208 TInputImage2,
209 typename Functor::MakeJoin<TInputImage1, TInputImage2>::ImageType>
210{
211public:
212 ITK_DISALLOW_COPY_AND_MOVE(JoinImageFilter);
213
215 static constexpr unsigned int OutputImageDimension = TInputImage1::ImageDimension;
216
219
223 using OutputImagePixelType = typename FunctorType::JoinType;
224
227
230
232 itkNewMacro(Self);
233
235 itkOverrideGetNameOfClassMacro(JoinImageFilter);
236
237#ifdef ITK_USE_CONCEPT_CHECKING
238 // Begin concept checking
241 itkConceptMacro(Input1Input2HasJoinTraitsCheck,
244 // End concept checking
245#endif
246
247protected:
249 ~JoinImageFilter() override = default;
250};
251} // end namespace itk
252
253#endif
Implements pixel-wise generic operation of two images, or of an image and a constant.
void SetFunctor(const std::function< ConstRefFunctionType > &f)
Join the components of two pixel types into a single pixel type.
typename PixelTraits< TPixel2 >::ValueType ValueType2
void FirstCopier(CopierDispatch< 1 >, JoinType &out, unsigned int idx, const TPixel1 &A) const
void SecondCopier(CopierDispatch< 1 >, JoinType &out, unsigned int idx, const TPixel2 &B) const
JoinType operator()(const TPixel1 &A, const TPixel2 &B) const
void FirstCopier(JoinType &out, unsigned int idx, const TPixel1 &A) const
static constexpr unsigned int JoinDimension
bool operator==(const JoinFunctor &) const
static constexpr unsigned int Dimension2
void SecondCopier(JoinType &out, unsigned int idx, const TPixel2 &B) const
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(JoinFunctor)
void SecondCopier(CopierDispatchBase, JoinType &out, unsigned int idx, const TPixel2 &B) const
typename JoinTraits< ValueType1, ValueType2 >::ValueType JoinValueType
typename PixelTraits< TPixel1 >::ValueType ValueType1
static constexpr unsigned int Dimension1
void FirstCopier(CopierDispatchBase, JoinType &out, unsigned int idx, const TPixel1 &A) const
Templated n-dimensional image class.
Definition: itkImage.h:89
Join two images, resulting in an image where each pixel has the components of the first image followe...
static constexpr unsigned int OutputImageDimension
typename Functor::MakeJoin< TInputImage1, TInputImage2 >::FunctorType FunctorType
~JoinImageFilter() override=default
typename Functor::MakeJoin< TInputImage1, TInputImage2 >::ImageType OutputImageType
typename FunctorType::JoinType OutputImagePixelType
Light weight base class for most itk classes.
Traits for a pixel that define the dimension and component type.
typename TPixelType::ValueType ValueType
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:63
#define itkConceptMacro(name, concept)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....