OTB  10.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-2024 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)
36 {
37 
38  // Get output pointer
39  OutputImageType* mosaicImage = this->GetOutput();
40 
41  // Get number of used inputs
42  const unsigned int nbOfUsedInputImages = Superclass::GetNumberOfUsedInputImages();
43 
44  // Get number of bands
45  const unsigned int nBands = Superclass::GetNumberOfBands();
46 
47  // Iterate through the thread region
48  IteratorType outputIt(mosaicImage, outputRegionForThread);
49 
50  // Prepare input pointers, interpolators, and valid regions (input images)
51  typename std::vector<InputImageType*> currentImage;
52  typename std::vector<InterpolatorPointerType> interp;
53  Superclass::PrepareImageAccessors(currentImage, interp);
54 
55  // Prepare input pointers, interpolators, and valid regions (distances images)
56  typename std::vector<DistanceImageType*> currentDistanceImage;
57  typename std::vector<DistanceImageInterpolatorPointer> distanceInterpolator;
58  Superclass::PrepareDistanceImageAccessors(currentDistanceImage, distanceInterpolator);
59 
60  // Temporary thread region (from input)
61  InputImageRegionType threadRegionInCurrentImage;
62 
63  // Temporary pixels
64  InternalPixelType interpolatedMathPixel, tempOutputPixel;
65  interpolatedMathPixel.SetSize(nBands);
66  tempOutputPixel.SetSize(nBands);
67 
68  InputImagePixelType interpolatedPixel;
69  InternalValueType pixelValue, distanceImagePixel, sumDistances;
70  bool isDataInCurrentOutputPixel;
71 
72  // Temporary coordinates
73  OutputImagePointType geoPoint;
74 
75  unsigned int band, i;
76 
77  for (outputIt.GoToBegin(); !outputIt.IsAtEnd(); ++outputIt)
78  {
79  // Current pixel --> Geographical point
80  mosaicImage->TransformIndexToPhysicalPoint(outputIt.GetIndex(), geoPoint);
81 
82  // Presence of at least one non-null pixel of the used input images
83  isDataInCurrentOutputPixel = false;
84  sumDistances = 0.0;
85 
86  // Transition pixels
87  tempOutputPixel.Fill(0.0);
88 
89  // Loop on used input images
90  for (i = 0; i < nbOfUsedInputImages; i++)
91  {
92 
93  // Check if the point is inside the transformed thread region
94  // (i.e. the region in the current input image which match the thread
95  // region)
96  if (interp[i]->IsInsideBuffer(geoPoint))
97  {
98  // Compute the interpolated pixel value
99  interpolatedPixel = interp[i]->Evaluate(geoPoint);
100 
101  // Check that interpolated pixel is not empty
102  if (Superclass::IsPixelNotEmpty(interpolatedPixel))
103  {
104  // Get the alpha channel pixel value for this channel
105  if (distanceInterpolator[i]->IsInsideBuffer(geoPoint))
106  {
107  distanceImagePixel = distanceInterpolator[i]->Evaluate(geoPoint);
108  distanceImagePixel -= Superclass::GetDistanceOffset();
109 
110  if (distanceImagePixel > 0)
111  {
112  // Update the presence of data for this pixel
113  isDataInCurrentOutputPixel = true;
114 
115  // sum coef
116  sumDistances += distanceImagePixel;
117 
118  /*
119  * 1. Cast the interpolated pixel into math pixel type
120  * 2. Multiply by feather coef
121  * 3. Compute sum
122  */
123  const unsigned int inputImageIndex = Superclass::GetUsedInputImageIndice(i);
124  for (band = 0; band < nBands; band++)
125  {
126  // Cast the interpolated pixel to a internal pixel type
127  interpolatedMathPixel[band] = static_cast<InternalValueType>(interpolatedPixel[band]);
128 
129  // Shift-scale the value
130  if (this->GetShiftScaleInputImages())
131  {
132  this->ShiftScaleValue(interpolatedMathPixel[band], inputImageIndex, band);
133  }
134 
135  // Multiply by Feather coef
136  interpolatedMathPixel[band] *= distanceImagePixel;
137 
138  // Summing
139  tempOutputPixel[band] += interpolatedMathPixel[band];
140 
141  } // loop on pixel bands
142 
143  } // distance > 0
144  } // Interpolated distance pixel not empty
145  else
146  {
147  itkWarningMacro(<< "Unable to evaluate distance at point " << geoPoint);
148  }
149  } // Interpolated pixel is not empty
150  } // point inside buffer
151  } // next image
152 
153  // Prepare output pixel
154  OutputImagePixelType outputPixel(Superclass::GetNoDataOutputPixel());
155 
156  if (isDataInCurrentOutputPixel)
157  {
158 
159  // Compute output pixel
160  for (band = 0; band < nBands; band++)
161  {
162 
163  // Normalize & cast
164  pixelValue = tempOutputPixel[band] / sumDistances;
165  Superclass::NormalizePixelValue(pixelValue);
166  outputPixel[band] = static_cast<OutputImageInternalPixelType>(pixelValue);
167  }
168 
169  } // if data presence
170 
171  // Update output pixel value
172  outputIt.Set(outputPixel);
173 
174  } // next output pixel
175 }
176 
177 } // end namespace gtb
178 
179 #endif
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
Superclass::OutputImageInternalPixelType OutputImageInternalPixelType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.