OTB  9.0.0
Orfeo Toolbox
otbSparseWvltToAngleMapperListFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbSparseWvltToAngleMapperListFilter_hxx
22 #define otbSparseWvltToAngleMapperListFilter_hxx
24 
25 #include <vnl/vnl_math.h>
26 
27 #include "itkProgressReporter.h"
28 
29 namespace otb
30 {
31 
32 template <class TInputImageList, class TOutputSampleList, unsigned int VNbInputImages>
34 {
35  this->SetNumberOfRequiredInputs(NumberOfInputImages);
36 
37  // Generate the output sample list
38  typename OutputSampleListObjectType::Pointer outputPtr = static_cast<OutputSampleListObjectType*>(this->MakeOutput(0).GetPointer());
39  this->ProcessObject::SetNthOutput(0, outputPtr.GetPointer());
40 
41  m_ThresholdValue = static_cast<ValueType>(10.);
42 }
43 
44 template <class TInputImageList, class TOutputSampleList, unsigned int VNbInputImages>
46 {
47  this->itk::ProcessObject::SetNthInput(i, const_cast<InputImageListType*>(img));
48 }
49 
50 template <class TInputImageList, class TOutputSampleList, unsigned int VNbInputImages>
52 {
53  if (i >= this->GetNumberOfInputs())
54  {
55  return nullptr;
56  }
57 
58  return static_cast<const InputImageListType*>(this->itk::ProcessObject::GetInput(i));
59 }
60 
61 template <class TInputImageList, class TOutputSampleList, unsigned int VNbInputImages>
64 {
65  typename OutputSampleListObjectType::Pointer outputPtr = OutputSampleListObjectType::New();
66  OutputSampleListPointer outputSampleList = OutputSampleListType::New();
67  outputPtr->Set(outputSampleList);
68  return static_cast<DataObjectPointer>(outputPtr);
69 }
70 
71 template <class TInputImageList, class TOutputSampleList, unsigned int VNbInputImages>
74 {
75  typename OutputSampleListObjectType::Pointer dataObjectPointer = static_cast<OutputSampleListObjectType*>(this->ProcessObject::GetOutput(0));
76  return const_cast<OutputSampleListType*>(dataObjectPointer->Get());
77 }
78 
79 template <class TInputImageList, class TOutputSampleList, unsigned int VNbInputImages>
82 {
83  return static_cast<OutputSampleListObjectType*>(this->ProcessObject::GetOutput(0));
84 }
85 
86 template <class TInputImageList, class TOutputSampleList, unsigned int VNbInputImages>
88 {
89  Superclass::PrintSelf(os, indent);
90  os << indent << "Threshold : " << m_ThresholdValue << "\n";
91 }
92 
93 template <class TInputImageList, class TOutputSampleList, unsigned int VNbInputImages>
95 {
96  InputImageListConstIteratorVectorType it(NumberOfInputImages);
97  for (unsigned int i = 0; i < NumberOfInputImages; ++i)
98  it[i] = this->GetInput(i)->Begin();
99 
100  OutputSampleListType* outputList = this->GetOutputSampleList();
101 
102  // Set-up progress reporting
103  itk::ProgressReporter progress(this, 0, this->GetInput(0)->Size());
104 
105  bool iteratorsNotAtEnd = true;
106  while (iteratorsNotAtEnd)
107  {
108  ImageConstIteratorVectorType imgIt(NumberOfInputImages);
109  for (unsigned int i = 0; i < NumberOfInputImages; ++i)
110  {
111  imgIt[i] = ImageConstIteratorType(it[i].Get(), it[i].Get()->GetLargestPossibleRegion());
112  imgIt[i].GoToBegin();
113  }
114 
115  bool localIteratorsNotAtEnd = true;
116  while (localIteratorsNotAtEnd)
117  {
118  if (IsToGenerate(imgIt))
119  {
120  outputList->PushBack(GenerateData(imgIt));
121  }
122 
123  for (unsigned int i = 0; i < NumberOfInputImages; ++i)
124  {
125  ++(imgIt[i]);
126  if (imgIt[i].IsAtEnd())
127  localIteratorsNotAtEnd = false;
128  }
129  }
130 
131  for (unsigned int i = 0; i < NumberOfInputImages; ++i)
132  {
133  ++(it[i]);
134  if (it[i] != this->GetInput(i)->End())
135  iteratorsNotAtEnd = false;
136  }
137 
138  progress.CompletedPixel();
139  }
140 }
141 
142 template <class TInputImageList, class TOutputSampleList, unsigned int VNbInputImages>
144 {
145  for (unsigned int i = 0; i < NumberOfInputImages; ++i)
146  {
147  if (it[i].Get() < m_ThresholdValue)
148  return false;
149  }
150 
151  return true;
152 }
153 
154 template <class TInputImageList, class TOutputSampleList, unsigned int VNbInputImages>
157 {
158  return FromEuclideanToSphericalSpace(it);
159 }
160 
161 template <class TInputImageList, class TOutputSampleList, unsigned int VNbInputImages>
164  const ImageConstIteratorVectorType& it) const
165 {
166  // First, get the modulus of the vector
167  double modulus = 0;
168  for (unsigned int i = 0; i < NumberOfInputImages; ++i)
169  {
170  modulus += std::pow(static_cast<double>(it[i].Get()), 2.);
171  }
172  // The modulus cannot be nul since it is over the threshold...
173  modulus = std::sqrt(modulus);
174 
175  // FIXME test if NaN nor infinite
176 
178  angle.Fill(static_cast<OutputValueType>(0.));
179 
180  if (NumberOfInputImages == 2)
181  {
182  if (it[1].Get() < 0)
183  {
184  angle[0] = std::acos(it[0].Get() / modulus);
185  }
186  else
187  {
188  angle[0] = -std::acos(it[0].Get() / modulus);
189  }
190  }
191  else
192  {
193  for (unsigned int k = 0; k < angle.Size() - 1; ++k)
194  {
195  double phase = std::acos(it[k].Get() / modulus);
196  angle[k] = phase;
197  modulus *= std::sin(phase);
198 
199  // FIXME test also if not finite
200  if (modulus < 1e-5)
201  {
202  while (++k < angle.Size())
203  angle[k] = 0.;
204  return angle;
205  }
206  }
207 
208  /*
209  * With this sign modification, we can put the same
210  * images for all the components and recover the good direction
211  */
212  double sign = NumberOfInputImages == 3 ? -1. : 1.;
213  if (it[NumberOfInputImages - 1].Get() < 0)
214  {
215  angle[angle.Size() - 1] = sign * std::acos(it[NumberOfInputImages - 2].Get() / modulus);
216  }
217  else
218  {
219  angle[angle.Size() - 1] = -sign * std::acos(it[NumberOfInputImages - 2].Get() / modulus);
220  }
221  }
222 
223  return angle;
224 }
225 
226 } // end of namespace otb
227 
228 #endif
otb::SparseWvltToAngleMapperListFilter::GetOutputSampleList
OutputSampleListType * GetOutputSampleList()
Definition: otbSparseWvltToAngleMapperListFilter.hxx:73
otb::SparseWvltToAngleMapperListFilter::InputImageListConstIteratorVectorType
std::vector< InputImageListConstIteratorType > InputImageListConstIteratorVectorType
Definition: otbSparseWvltToAngleMapperListFilter.h:86
otb::SparseWvltToAngleMapperListFilter::ValueType
InputImageType::ValueType ValueType
Definition: otbSparseWvltToAngleMapperListFilter.h:74
otb::SparseWvltToAngleMapperListFilter::GenerateData
void GenerateData() override
Definition: otbSparseWvltToAngleMapperListFilter.hxx:94
otb::SparseWvltToAngleMapperListFilter::GetOutput
OutputSampleListObjectType * GetOutput()
Definition: otbSparseWvltToAngleMapperListFilter.hxx:81
otb::SparseWvltToAngleMapperListFilter::DataObjectPointerArraySizeType
itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
Definition: otbSparseWvltToAngleMapperListFilter.h:97
otb::SparseWvltToAngleMapperListFilter::FromEuclideanToSphericalSpace
virtual OutputMeasurementVectorType FromEuclideanToSphericalSpace(const ImageConstIteratorVectorType &) const
Definition: otbSparseWvltToAngleMapperListFilter.hxx:163
otb::SparseWvltToAngleMapperListFilter::OutputValueType
OutputMeasurementVectorType::ValueType OutputValueType
Definition: otbSparseWvltToAngleMapperListFilter.h:81
otb::SparseWvltToAngleMapperListFilter::OutputSampleListObjectType
itk::DataObjectDecorator< OutputSampleListType > OutputSampleListObjectType
Definition: otbSparseWvltToAngleMapperListFilter.h:96
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::SparseWvltToAngleMapperListFilter::DataObjectPointer
itk::DataObject::Pointer DataObjectPointer
Definition: otbSparseWvltToAngleMapperListFilter.h:95
otb::SparseWvltToAngleMapperListFilter::GetInput
const InputImageListType * GetInput(unsigned int i) const
Definition: otbSparseWvltToAngleMapperListFilter.hxx:51
otb::SparseWvltToAngleMapperListFilter::MakeOutput
DataObjectPointer MakeOutput(DataObjectPointerArraySizeType idx) override
Definition: otbSparseWvltToAngleMapperListFilter.hxx:63
otb::SparseWvltToAngleMapperListFilter::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbSparseWvltToAngleMapperListFilter.hxx:87
otb::SparseWvltToAngleMapperListFilter::IsToGenerate
virtual bool IsToGenerate(const ImageConstIteratorVectorType &) const
Definition: otbSparseWvltToAngleMapperListFilter.hxx:143
otb::SparseWvltToAngleMapperListFilter::OutputSampleListType
TOutputSampleList OutputSampleListType
Definition: otbSparseWvltToAngleMapperListFilter.h:77
otb::SparseWvltToAngleMapperListFilter::OutputSampleListPointer
OutputSampleListType::Pointer OutputSampleListPointer
Definition: otbSparseWvltToAngleMapperListFilter.h:78
otb::SparseWvltToAngleMapperListFilter::SparseWvltToAngleMapperListFilter
SparseWvltToAngleMapperListFilter()
Definition: otbSparseWvltToAngleMapperListFilter.hxx:33
otb::SparseWvltToAngleMapperListFilter::OutputMeasurementVectorType
OutputSampleListType::MeasurementVectorType OutputMeasurementVectorType
Definition: otbSparseWvltToAngleMapperListFilter.h:80
otb::SparseWvltToAngleMapperListFilter::InputImageListType
TInputImageList InputImageListType
Definition: otbSparseWvltToAngleMapperListFilter.h:66
otb::SparseWvltToAngleMapperListFilter::SetInput
void SetInput(unsigned int i, const InputImageListType *)
Definition: otbSparseWvltToAngleMapperListFilter.hxx:45
otb::SparseWvltToAngleMapperListFilter::ImageConstIteratorType
itk::ImageRegionConstIterator< InputImageType > ImageConstIteratorType
Definition: otbSparseWvltToAngleMapperListFilter.h:84
otb::SparseWvltToAngleMapperListFilter::ImageConstIteratorVectorType
std::vector< ImageConstIteratorType > ImageConstIteratorVectorType
Definition: otbSparseWvltToAngleMapperListFilter.h:85
otbSparseWvltToAngleMapperListFilter.h