21 #ifndef otbConcatenateVectorImageFilter_hxx
22 #define otbConcatenateVectorImageFilter_hxx
26 #include "itkImageRegionIterator.h"
27 #include "itkProgressReporter.h"
34 template <
class TInputImage1,
class TInputImage2,
class TOutputImage>
37 this->SetNumberOfRequiredInputs(2);
38 this->DynamicMultiThreadingOn();
44 template <
class TInputImage1,
class TInputImage2,
class TOutputImage>
53 template <
class TInputImage1,
class TInputImage2,
class TOutputImage>
56 this->SetNthInput(0,
const_cast<TInputImage1*
>(image));
63 template <
class TInputImage1,
class TInputImage2,
class TOutputImage>
66 this->SetNthInput(1,
const_cast<TInputImage2*
>(image));
73 template <
class TInputImage1,
class TInputImage2,
class TOutputImage>
77 return const_cast<InputImage1Type*
>(this->GetInput(0));
84 template <
class TInputImage1,
class TInputImage2,
class TOutputImage>
88 return const_cast<InputImage2Type*
>(this->GetInput(1));
91 template <
class TInputImage1,
class TInputImage2,
class TOutputImage>
95 Superclass::GenerateOutputInformation();
97 typename Superclass::InputImageConstPointer inputPtr1 = this->GetInput1();
98 typename Superclass::InputImageConstPointer inputPtr2 = this->GetInput2();
99 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
101 unsigned int nbComponentsPerPixel = inputPtr1->GetNumberOfComponentsPerPixel() + inputPtr2->GetNumberOfComponentsPerPixel();
104 outputPtr->SetNumberOfComponentsPerPixel(nbComponentsPerPixel);
107 template <
class TInputImage1,
class TInputImage2,
class TOutputImage>
110 Superclass::BeforeThreadedGenerateData();
112 typename Superclass::InputImageConstPointer inputPtr1 = this->GetInput1();
113 typename Superclass::InputImageConstPointer inputPtr2 = this->GetInput2();
114 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
116 if (inputPtr1->GetLargestPossibleRegion() != inputPtr2->GetLargestPossibleRegion())
118 itkExceptionMacro(<<
"InputImage1 and InputImage2 have different requested regions.");
125 template <
class TInputImage1,
class TInputImage2,
class TOutputImage>
129 InputImage1PointerType input1 = this->GetInput1();
130 InputImage2PointerType input2 = this->GetInput2();
131 OutputImagePointerType output = this->GetOutput();
135 typename InputImage1Type::RegionType inputRegionForThread;
136 this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread);
139 typedef itk::ImageRegionIterator<InputImage1Type> Input1IteratorType;
140 typedef itk::ImageRegionIterator<InputImage2Type> Input2IteratorType;
141 typedef itk::ImageRegionIterator<OutputImageType> OutputIteratorType;
144 Input1IteratorType input1It(input1, inputRegionForThread);
145 Input2IteratorType input2It(input2, inputRegionForThread);
146 OutputIteratorType outputIt(output, outputRegionForThread);
148 input1It.GoToBegin();
149 input2It.GoToBegin();
150 outputIt.GoToBegin();
152 typename OutputImageType::PixelType outputPix(outputIt.Get().GetSize());
154 const unsigned int l1 = input1It.Get().GetSize();
155 const unsigned int l2 = input2It.Get().GetSize();
158 while (!outputIt.IsAtEnd())
162 assert(l1 == input1It.Get().GetSize());
163 assert(l2 == input2It.Get().GetSize());
165 assert(l1 + l2 == outputPix.GetSize());
167 InputPixel1Type
const& pix1 = input1It.Get();
168 InputPixel2Type
const& pix2 = input2It.Get();
171 for (
unsigned int i = 0; i < l1; ++i)
174 outputPix[i] =
static_cast<typename OutputImageType::InternalPixelType
>(pix1[i]);
177 for (
unsigned int i = 0; i < l2; ++i)
180 outputPix[i + l1] =
static_cast<typename OutputImageType::InternalPixelType
>(pix2[i]);
183 outputIt.Set(outputPix);
void SetInput2(const TInputImage2 *image)
TInputImage2 InputImage2Type
InputImage2Type * GetInput2(void)
void GenerateOutputInformation() override
~ConcatenateVectorImageFilter() override
void BeforeThreadedGenerateData() override
InputImage1Type * GetInput1(void)
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
ConcatenateVectorImageFilter()
TInputImage1 InputImage1Type
void SetInput1(const TInputImage1 *image)
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.