OTB  9.0.0
Orfeo Toolbox
otbPathListToHistogramGenerator.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 
22 #ifndef otbPathListToHistogramGenerator_hxx
23 #define otbPathListToHistogramGenerator_hxx
24 
26 
27 namespace otb
28 {
29 
30 template <class TPath, class TFunction>
32 {
33  m_HistogramGenerator = GeneratorType::New();
34 
35  this->SetNumberOfRequiredInputs(1);
36  this->SetNumberOfRequiredOutputs(1);
37 
38  this->itk::ProcessObject::SetNthOutput(0, this->MakeOutput(0).GetPointer());
39 }
40 
41 template <class TPath, class TFunction>
43 {
44  // Process object is not const-correct so the const_cast is required here
45  this->itk::ProcessObject::SetNthInput(0, const_cast<PathListType*>(path));
46 }
47 
48 template <class TPath, class TFunction>
50 {
51  if (this->GetNumberOfInputs() < 1)
52  {
53  return nullptr;
54  }
55  return static_cast<const PathListType*>(this->itk::ProcessObject::GetInput(0));
56 }
57 
61 template <class TPath, class TFunction>
63 {
64  this->GraftNthOutput(0, graft);
65 }
66 
71 template <class TPath, class TFunction>
72 void PathListToHistogramGenerator<TPath, TFunction>::GraftNthOutput(unsigned int idx, itk::DataObject* graft)
73 {
74  if (idx >= this->GetNumberOfOutputs())
75  {
76  itkExceptionMacro(<< "Requested to graft output " << idx << " but this filter only has " << this->GetNumberOfOutputs() << " Outputs.");
77  }
78 
79  if (!graft)
80  {
81  itkExceptionMacro(<< "Requested to graft output that is a NULL pointer");
82  }
83 
84  itk::DataObject* output = const_cast<HistogramType*>(this->GetOutput());
85 
86  // Call GraftImage to copy meta-information, regions, and the pixel container
87  output->Graft(graft);
88 }
89 
90 template <class TPath, class TFunction>
93 {
94  DataObjectPointer output;
95  output = static_cast<itk::DataObject*>(HistogramType::New().GetPointer());
96  return output;
97 }
98 
99 
100 template <class TPath, class TFunction>
102 {
103  return dynamic_cast<const HistogramType*>(this->itk::ProcessObject::GetOutput(0));
104 }
105 
106 template <class TPath, class TFunction>
108 {
109  // Get the input pathlist
110  typename PathListType::ConstPointer pathList = this->GetInput();
111 
112  // Path pointer
113  PathPointer vertexList;
114 
115  ListSamplePointer listSample = ListSampleType::New();
116  int nbElementPathList = pathList->Size();
117 
118  ListSampleVectorType ResultFunction;
119 
120  typename TFunction::Pointer function = TFunction::New();
121 
122  for (int noPathList = 0; noPathList < nbElementPathList; noPathList++)
123  {
124  vertexList = pathList->GetNthElement(noPathList); //(*pathList)[noPathList];
125  function->SetInputPath(vertexList);
126 
127  ResultFunction[0] = static_cast<MeasurementType>(function->Evaluate());
128  // Set the ListSample MeasurementVectorSize once before the PushBack
129  if (noPathList == 0)
130  listSample->SetMeasurementVectorSize(ResultFunction.Size());
131 
132  listSample->PushBack(ResultFunction);
133  }
134 
135  m_HistogramGenerator->SetInput(listSample);
136  m_HistogramGenerator->GraftOutput(const_cast<HistogramType*>(this->GetOutput()));
137  m_HistogramGenerator->Update();
138  this->GraftOutput(const_cast<HistogramType*>(m_HistogramGenerator->GetOutput()));
139 }
140 
141 template <class TPath, class TFunction>
143 {
144  m_HistogramGenerator->SetHistogramSize(size);
145 }
146 
147 template <class TPath, class TFunction>
149 {
150  m_HistogramGenerator->SetMarginalScale(marginalScale);
151 }
152 
153 template <class TPath, class TFunction>
155 {
156  m_HistogramGenerator->SetHistogramMin(histogramMin);
157 }
158 
159 template <class TPath, class TFunction>
161 {
162  m_HistogramGenerator->SetHistogramMax(histogramMax);
163 }
164 
165 template <class TPath, class TFunction>
167 {
168  m_HistogramGenerator->SetAutoMinMax(autoMinMax);
169 }
170 
171 template <class TPath, class TFunction>
172 void PathListToHistogramGenerator<TPath, TFunction>::PrintSelf(std::ostream& os, itk::Indent indent) const
173 {
174  Superclass::PrintSelf(os, indent);
175  os << "PathList = " << this->GetInput() << std::endl;
176  os << "HistogramGenerator = " << m_HistogramGenerator << std::endl;
177 }
178 
179 } // end of namespace otb
180 
181 #endif
otb::PathListToHistogramGenerator::MeasurementType
RealType MeasurementType
Definition: otbPathListToHistogramGenerator.h:72
otb::PathListToHistogramGenerator::GenerateData
void GenerateData() override
Definition: otbPathListToHistogramGenerator.hxx:107
otb::PathListToHistogramGenerator::SetAutoMinMax
void SetAutoMinMax(bool autoMinMax)
Definition: otbPathListToHistogramGenerator.hxx:166
otb::PathListToHistogramGenerator::SetHistogramMin
void SetHistogramMin(const MeasurementVectorType &histogramMin)
Definition: otbPathListToHistogramGenerator.hxx:154
otb::PathListToHistogramGenerator::SetMarginalScale
void SetMarginalScale(double marginalScale)
Definition: otbPathListToHistogramGenerator.hxx:148
otb::PathListToHistogramGenerator::ListSamplePointer
ListSampleType::Pointer ListSamplePointer
Definition: otbPathListToHistogramGenerator.h:75
otb::PathListToHistogramGenerator::SetInput
void SetInput(const PathListType *path)
Definition: otbPathListToHistogramGenerator.hxx:42
otbPathListToHistogramGenerator.h
otb::PathListToHistogramGenerator::GetInput
const PathListType * GetInput() const
Definition: otbPathListToHistogramGenerator.hxx:49
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::PathListToHistogramGenerator::DataObjectPointer
Superclass::DataObjectPointer DataObjectPointer
Definition: otbPathListToHistogramGenerator.h:90
otb::PathListToHistogramGenerator::SizeType
HistogramType::SizeType SizeType
Definition: otbPathListToHistogramGenerator.h:86
otb::PathListToHistogramGenerator::SetHistogramMax
void SetHistogramMax(const MeasurementVectorType &histogramMax)
Definition: otbPathListToHistogramGenerator.hxx:160
otb::PathListToHistogramGenerator::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbPathListToHistogramGenerator.hxx:172
otb::PathListToHistogramGenerator::PathListToHistogramGenerator
PathListToHistogramGenerator()
Definition: otbPathListToHistogramGenerator.hxx:31
otb::PathListToHistogramGenerator::MeasurementVectorType
HistogramType::MeasurementVectorType MeasurementVectorType
Definition: otbPathListToHistogramGenerator.h:87
otb::PathListToHistogramGenerator::SetNumberOfBins
void SetNumberOfBins(const SizeType &size)
Definition: otbPathListToHistogramGenerator.hxx:142
otb::PathListToHistogramGenerator::GraftNthOutput
void GraftNthOutput(unsigned int idx, itk::DataObject *graft)
Definition: otbPathListToHistogramGenerator.hxx:72
otb::ObjectList::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbObjectList.h:47
otb::PathListToHistogramGenerator::PathPointer
PathType::Pointer PathPointer
Definition: otbPathListToHistogramGenerator.h:65
otb::PathListToHistogramGenerator::DataObjectPointerArraySizeType
itk::ProcessObject::DataObjectPointerArraySizeType DataObjectPointerArraySizeType
Definition: otbPathListToHistogramGenerator.h:91
otb::PathListToHistogramGenerator::ListSampleVectorType
itk::Vector< MeasurementType, 1 > ListSampleVectorType
Definition: otbPathListToHistogramGenerator.h:73
otb::PathListToHistogramGenerator::HistogramType
itk::Statistics::Histogram< MeasurementType, FrequencyContainerType > HistogramType
Definition: otbPathListToHistogramGenerator.h:79
otb::PathListToHistogramGenerator::MakeOutput
DataObjectPointer MakeOutput(DataObjectPointerArraySizeType) override
Definition: otbPathListToHistogramGenerator.hxx:92
otb::ObjectList
This class is a generic all-purpose wrapping around an std::vector<itk::SmartPointer<ObjectType> >.
Definition: otbObjectList.h:40
otb::PathListToHistogramGenerator::GetOutput
const HistogramType * GetOutput() const
Definition: otbPathListToHistogramGenerator.hxx:101
otb::PathListToHistogramGenerator::GraftOutput
void GraftOutput(itk::DataObject *graft)
Definition: otbPathListToHistogramGenerator.hxx:62