OTB  9.0.0
Orfeo Toolbox
otbStreamingLargeFeatherMosaicFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999-2011 Insight Software Consortium
3  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
4  * Copyright (C) 2016-2019 IRSTEA
5  *
6  * This file is part of Orfeo Toolbox
7  *
8  * https://www.orfeo-toolbox.org/
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  * http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  */
22 #ifndef __StreamingLargeFeatherMosaicFilter_hxx
23 #define __StreamingLargeFeatherMosaicFilter_hxx
24 
26 
27 namespace otb
28 {
29 
33 template <class TInputImage, class TOutputImage, class TDistanceImage, class TInternalValueType>
35  const OutputImageRegionType& outputRegionForThread, itk::ThreadIdType threadId)
36 {
37 
38  // Debug info
39  itkDebugMacro(<< "Actually executing thread " << threadId << " in region " << outputRegionForThread);
40 
41  // Support progress methods/callbacks
42  itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
43 
44  // Get output pointer
45  OutputImageType* mosaicImage = this->GetOutput();
46 
47  // Get number of used inputs
48  const unsigned int nbOfUsedInputImages = Superclass::GetNumberOfUsedInputImages();
49 
50  // Get number of bands
51  const unsigned int nBands = Superclass::GetNumberOfBands();
52 
53  // Iterate through the thread region
54  IteratorType outputIt(mosaicImage, outputRegionForThread);
55 
56  // Prepare input pointers, interpolators, and valid regions (input images)
57  typename std::vector<InputImageType*> currentImage;
58  typename std::vector<InterpolatorPointerType> interp;
59  Superclass::PrepareImageAccessors(currentImage, interp);
60 
61  // Prepare input pointers, interpolators, and valid regions (distances images)
62  typename std::vector<DistanceImageType*> currentDistanceImage;
63  typename std::vector<DistanceImageInterpolatorPointer> distanceInterpolator;
64  Superclass::PrepareDistanceImageAccessors(currentDistanceImage, distanceInterpolator);
65 
66  // Temporary thread region (from input)
67  InputImageRegionType threadRegionInCurrentImage;
68 
69  // Temporary pixels
70  InternalPixelType interpolatedMathPixel, tempOutputPixel;
71  interpolatedMathPixel.SetSize(nBands);
72  tempOutputPixel.SetSize(nBands);
73 
74  InputImagePixelType interpolatedPixel;
75  InternalValueType pixelValue, distanceImagePixel, sumDistances;
76  bool isDataInCurrentOutputPixel;
77 
78  // Temporary coordinates
79  OutputImagePointType geoPoint;
80 
81  unsigned int band, i;
82 
83  for (outputIt.GoToBegin(); !outputIt.IsAtEnd(); ++outputIt)
84  {
85  // Current pixel --> Geographical point
86  mosaicImage->TransformIndexToPhysicalPoint(outputIt.GetIndex(), geoPoint);
87 
88  // Presence of at least one non-null pixel of the used input images
89  isDataInCurrentOutputPixel = false;
90  sumDistances = 0.0;
91 
92  // Transition pixels
93  tempOutputPixel.Fill(0.0);
94 
95  // Loop on used input images
96  for (i = 0; i < nbOfUsedInputImages; i++)
97  {
98 
99  // Check if the point is inside the transformed thread region
100  // (i.e. the region in the current input image which match the thread
101  // region)
102  if (interp[i]->IsInsideBuffer(geoPoint))
103  {
104  // Compute the interpolated pixel value
105  interpolatedPixel = interp[i]->Evaluate(geoPoint);
106 
107  // Check that interpolated pixel is not empty
108  if (Superclass::IsPixelNotEmpty(interpolatedPixel))
109  {
110  // Get the alpha channel pixel value for this channel
111  if (distanceInterpolator[i]->IsInsideBuffer(geoPoint))
112  {
113  distanceImagePixel = distanceInterpolator[i]->Evaluate(geoPoint);
114  distanceImagePixel -= Superclass::GetDistanceOffset();
115 
116  if (distanceImagePixel > 0)
117  {
118  // Update the presence of data for this pixel
119  isDataInCurrentOutputPixel = true;
120 
121  // sum coef
122  sumDistances += distanceImagePixel;
123 
124  /*
125  * 1. Cast the interpolated pixel into math pixel type
126  * 2. Multiply by feather coef
127  * 3. Compute sum
128  */
129  const unsigned int inputImageIndex = Superclass::GetUsedInputImageIndice(i);
130  for (band = 0; band < nBands; band++)
131  {
132  // Cast the interpolated pixel to a internal pixel type
133  interpolatedMathPixel[band] = static_cast<InternalValueType>(interpolatedPixel[band]);
134 
135  // Shift-scale the value
136  if (this->GetShiftScaleInputImages())
137  {
138  this->ShiftScaleValue(interpolatedMathPixel[band], inputImageIndex, band);
139  }
140 
141  // Multiply by Feather coef
142  interpolatedMathPixel[band] *= distanceImagePixel;
143 
144  // Summing
145  tempOutputPixel[band] += interpolatedMathPixel[band];
146 
147  } // loop on pixel bands
148 
149  } // distance > 0
150  } // Interpolated distance pixel not empty
151  else
152  {
153  itkWarningMacro(<< "Unable to evaluate distance at point " << geoPoint);
154  }
155  } // Interpolated pixel is not empty
156  } // point inside buffer
157  } // next image
158 
159  // Prepare output pixel
160  OutputImagePixelType outputPixel(Superclass::GetNoDataOutputPixel());
161 
162  if (isDataInCurrentOutputPixel)
163  {
164 
165  // Compute output pixel
166  for (band = 0; band < nBands; band++)
167  {
168 
169  // Normalize & cast
170  pixelValue = tempOutputPixel[band] / sumDistances;
171  Superclass::NormalizePixelValue(pixelValue);
172  outputPixel[band] = static_cast<OutputImageInternalPixelType>(pixelValue);
173  }
174 
175  } // if data presence
176 
177  // Update output pixel value
178  outputIt.Set(outputPixel);
179 
180  // Update progress
181  progress.CompletedPixel();
182 
183  } // next output pixel
184 }
185 
186 } // end namespace gtb
187 
188 #endif
otbStreamingLargeFeatherMosaicFilter.h
otb::StreamingLargeFeatherMosaicFilter::OutputImageRegionType
Superclass::OutputImageRegionType OutputImageRegionType
Definition: otbStreamingLargeFeatherMosaicFilter.h:84
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::StreamingLargeFeatherMosaicFilter::OutputImageType
Superclass::OutputImageType OutputImageType
Definition: otbStreamingLargeFeatherMosaicFilter.h:76
otb::StreamingLargeFeatherMosaicFilter::OutputImageInternalPixelType
Superclass::OutputImageInternalPixelType OutputImageInternalPixelType
Definition: otbStreamingLargeFeatherMosaicFilter.h:83
otb::StreamingLargeFeatherMosaicFilter::OutputImagePixelType
Superclass::OutputImagePixelType OutputImagePixelType
Definition: otbStreamingLargeFeatherMosaicFilter.h:79
otb::StreamingLargeFeatherMosaicFilter::InternalPixelType
Superclass::InternalPixelType InternalPixelType
Definition: otbStreamingLargeFeatherMosaicFilter.h:93
otb::StreamingLargeFeatherMosaicFilter::InternalValueType
Superclass::InternalValueType InternalValueType
Definition: otbStreamingLargeFeatherMosaicFilter.h:87
otb::StreamingLargeFeatherMosaicFilter::InputImageRegionType
Superclass::InputImageRegionType InputImageRegionType
Definition: otbStreamingLargeFeatherMosaicFilter.h:73
otb::StreamingLargeFeatherMosaicFilter::InputImagePixelType
Superclass::InputImagePixelType InputImagePixelType
Definition: otbStreamingLargeFeatherMosaicFilter.h:68
otb::StreamingLargeFeatherMosaicFilter::ThreadedGenerateData
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId) override
Definition: otbStreamingLargeFeatherMosaicFilter.hxx:34
otb::StreamingLargeFeatherMosaicFilter::IteratorType
Superclass::IteratorType IteratorType
Definition: otbStreamingLargeFeatherMosaicFilter.h:94
otb::StreamingLargeFeatherMosaicFilter::OutputImagePointType
Superclass::OutputImagePointType OutputImagePointType
Definition: otbStreamingLargeFeatherMosaicFilter.h:78