21 #ifndef otbConcatenateVectorImageFilter_hxx
22 #define otbConcatenateVectorImageFilter_hxx
25 #include "itkImageRegionIterator.h"
26 #include "itkProgressReporter.h"
33 template <
class TInputImage1,
class TInputImage2,
class TOutputImage>
36 this->SetNumberOfRequiredInputs(2);
42 template <
class TInputImage1,
class TInputImage2,
class TOutputImage>
51 template <
class TInputImage1,
class TInputImage2,
class TOutputImage>
54 this->SetNthInput(0,
const_cast<TInputImage1*
>(image));
61 template <
class TInputImage1,
class TInputImage2,
class TOutputImage>
64 this->SetNthInput(1,
const_cast<TInputImage2*
>(image));
71 template <
class TInputImage1,
class TInputImage2,
class TOutputImage>
75 return const_cast<InputImage1Type*
>(this->GetInput(0));
82 template <
class TInputImage1,
class TInputImage2,
class TOutputImage>
86 return const_cast<InputImage2Type*
>(this->GetInput(1));
89 template <
class TInputImage1,
class TInputImage2,
class TOutputImage>
93 Superclass::GenerateOutputInformation();
95 typename Superclass::InputImageConstPointer inputPtr1 = this->GetInput1();
96 typename Superclass::InputImageConstPointer inputPtr2 = this->GetInput2();
97 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
99 unsigned int nbComponentsPerPixel = inputPtr1->GetNumberOfComponentsPerPixel() + inputPtr2->GetNumberOfComponentsPerPixel();
102 outputPtr->SetNumberOfComponentsPerPixel(nbComponentsPerPixel);
105 template <
class TInputImage1,
class TInputImage2,
class TOutputImage>
108 Superclass::BeforeThreadedGenerateData();
110 typename Superclass::InputImageConstPointer inputPtr1 = this->GetInput1();
111 typename Superclass::InputImageConstPointer inputPtr2 = this->GetInput2();
112 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
114 if (inputPtr1->GetLargestPossibleRegion() != inputPtr2->GetLargestPossibleRegion())
116 itkExceptionMacro(<<
"InputImage1 and InputImage2 have different requested regions.");
123 template <
class TInputImage1,
class TInputImage2,
class TOutputImage>
125 itk::ThreadIdType threadId)
128 InputImage1PointerType input1 = this->GetInput1();
129 InputImage2PointerType input2 = this->GetInput2();
130 OutputImagePointerType output = this->GetOutput();
133 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
136 typename InputImage1Type::RegionType inputRegionForThread;
137 this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread);
140 typedef itk::ImageRegionIterator<InputImage1Type> Input1IteratorType;
141 typedef itk::ImageRegionIterator<InputImage2Type> Input2IteratorType;
142 typedef itk::ImageRegionIterator<OutputImageType> OutputIteratorType;
145 Input1IteratorType input1It(input1, inputRegionForThread);
146 Input2IteratorType input2It(input2, inputRegionForThread);
147 OutputIteratorType outputIt(output, outputRegionForThread);
149 input1It.GoToBegin();
150 input2It.GoToBegin();
151 outputIt.GoToBegin();
153 typename OutputImageType::PixelType outputPix(outputIt.Get().GetSize());
155 const unsigned int l1 = input1It.Get().GetSize();
156 const unsigned int l2 = input2It.Get().GetSize();
159 while (!outputIt.IsAtEnd())
163 assert(l1 == input1It.Get().GetSize());
164 assert(l2 == input2It.Get().GetSize());
166 assert(l1 + l2 == outputPix.GetSize());
168 InputPixel1Type
const& pix1 = input1It.Get();
169 InputPixel2Type
const& pix2 = input2It.Get();
172 for (
unsigned int i = 0; i < l1; ++i)
175 outputPix[i] =
static_cast<typename OutputImageType::InternalPixelType
>(pix1[i]);
178 for (
unsigned int i = 0; i < l2; ++i)
181 outputPix[i + l1] =
static_cast<typename OutputImageType::InternalPixelType
>(pix2[i]);
184 outputIt.Set(outputPix);