OTB  9.0.0
Orfeo Toolbox
otbImageSimulationMethod.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 otbImageSimulationMethod_hxx
22 #define otbImageSimulationMethod_hxx
23 
25 
26 namespace otb
27 {
28 
29 template <class TInputVectorData, class TSpatialisation, class TSimulationStep1, class TSimulationStep2, class TFTM, class TOutputImage>
31 {
32  // instantiation
33  m_Spatialisation = SpatialisationType::New();
34  m_LabelMapToSimulatedImageFilter = LabelMapToSimulatedImageFilterType::New();
35  m_LabelMapToLabelImageFilter = LabelMapToLabelImageFilterType::New();
36 
37  // this->SetNumberOfRequiredOutputs(2);
38  // this->SetNthOutput(0, OutputImageType::New());
39  // this->SetNthOutput(1, OutputLabelImageType::New());
40 
41  // TODO fix this. But for now this is mandatory because ProlateInterpolateImageFunction
42  // only works with single channel images.
43  // m_FTMFilter = FTMFilterType::New();
44  // m_Interpolator = InterpolatorType::New();
45  // m_MultiToMonoChannelFilter = MultiToMonoChannelFilterType::New();
46  m_ImageList = ImageListType::New();
47  m_ImageListToVectorImageFilter = ImageListToVectorImageFilterType::New();
48 
49  // default value
50  m_NumberOfComponentsPerPixel = 3;
51  m_Radius = 3;
52  m_SatRSRFilename = "";
53  m_PathRoot = "";
54  m_Mean = 0.0;
55  m_Variance = 1e-8;
56 }
57 
58 // The 3 commented methods are needed for a true composite filters.
59 
60 // template <class TInputVectorData, class TSpatialisation, class TSimulationStep1, class TSimulationStep2, class TFTM, class TOutputImage>
61 // void
62 // ImageSimulationMethod< TInputVectorData, TSpatialisation, TSimulationStep1, TSimulationStep2, TFTM, TOutputImage>
63 // ::SetInput(const InputVectorDataType* object)
64 // {
65 // this->itk::ProcessObject::SetNthInput(0, const_cast<InputVectorDataType *>(object));
66 // }
67 //
68 // template <class TInputVectorData, class TSpatialisation, class TSimulationStep1, class TSimulationStep2, class TFTM, class TOutputImage>
69 // typename ImageSimulationMethod<TInputVectorData, TSpatialisation, TSimulationStep1, TSimulationStep2, TFTM, TOutputImage>::InputVectorDataType *
70 // ImageSimulationMethod< TInputVectorData, TSpatialisation, TSimulationStep1, TSimulationStep2, TFTM, TOutputImage>
71 // ::GetInput()
72 // {
73 // return static_cast<InputVectorDataType *>(this->itk::ProcessObject::GetInput(0));
74 // }
75 
77 // template <class TInputVectorData, class TSpatialisation, class TSimulationStep1, class TSimulationStep2, class TFTM, class TOutputImage>
78 // typename ImageSimulationMethod< TInputVectorData, TSpatialisation, TSimulationStep1, TSimulationStep2, TFTM, TOutputImage>::OutputImageType *
79 // ImageSimulationMethod< TInputVectorData, TSpatialisation, TSimulationStep1, TSimulationStep2, TFTM, TOutputImage>
80 // ::GetOutputReflectanceImage()
81 // {
82 // if(this->GetNumberOfOutputs() < 2)
83 // {
84 // //exit
85 // return 0;
86 // }
87 // return static_cast<OutputImageType *>(this->itk::ProcessObject::GetOutput(0));
88 // }
89 //
90 
92 // template <class TInputVectorData, class TSpatialisation, class TSimulationStep1, class TSimulationStep2, class TFTM, class TOutputImage>
93 // typename ImageSimulationMethod< TInputVectorData, TSpatialisation, TSimulationStep1, TSimulationStep2, TFTM, TOutputImage>::OutputLabelImageType *
94 // ImageSimulationMethod< TInputVectorData, TSpatialisation, TSimulationStep1, TSimulationStep2, TFTM, TOutputImage>
95 // ::GetOutputLabelImage()
96 // {
97 // if(this->GetNumberOfOutputs() < 2)
98 // {
99 // //exit
100 // return 0;
101 // }
102 // return static_cast<OutputLabelImageType *>(this->itk::ProcessObject::GetOutput(1));
103 // }
105 
107 template <class TInputVectorData, class TSpatialisation, class TSimulationStep1, class TSimulationStep2, class TFTM, class TOutputImage>
110 {
111  return m_ImageListToVectorImageFilter->GetOutput();
112 }
113 
115 template <class TInputVectorData, class TSpatialisation, class TSimulationStep1, class TSimulationStep2, class TFTM, class TOutputImage>
118 {
119  return m_LabelMapToLabelImageFilter->GetOutput();
120 }
121 
122 template <class TInputVectorData, class TSpatialisation, class TSimulationStep1, class TSimulationStep2, class TFTM, class TOutputImage>
124 {
125  Superclass::GenerateOutputInformation();
126 
127  OutputImageType* outputReflImage = this->GetOutputReflectanceImage();
128 
129  // m_Spatialisation->SetInput(m_InputVectorData);
130  m_Spatialisation->UpdateOutputInformation();
131 
132  outputReflImage->SetNumberOfComponentsPerPixel(m_NumberOfComponentsPerPixel);
133  outputReflImage->SetLargestPossibleRegion(m_Spatialisation->GetOutput()->GetLargestPossibleRegion());
134  outputReflImage->SetOrigin(m_Spatialisation->GetOutput()->GetOrigin());
135 
136  OutputLabelImageType* outputLabelImage = this->GetOutputLabelImage();
137  outputLabelImage->SetLargestPossibleRegion(m_Spatialisation->GetOutput()->GetLargestPossibleRegion());
138  outputLabelImage->SetOrigin(m_Spatialisation->GetOutput()->GetOrigin());
139 }
140 
141 template <class TInputVectorData, class TSpatialisation, class TSimulationStep1, class TSimulationStep2, class TFTM, class TOutputImage>
143 {
144 
145  // m_Spatialisation->SetInput(m_InputVectorData);
146  // m_Spatialisation->SetInitialLabel(1);
147  // m_Spatialisation->SetBackgroundValue(0);
148 
149  m_LabelMapToSimulatedImageFilter->SetInput(m_Spatialisation->GetOutput());
150  m_LabelMapToSimulatedImageFilter->SetNumberOfComponentsPerPixel(m_NumberOfComponentsPerPixel);
151  m_LabelMapToSimulatedImageFilter->SetSatRSRFilename(m_SatRSRFilename);
152  m_LabelMapToSimulatedImageFilter->SetNumberOfThreads(1);
153  m_LabelMapToSimulatedImageFilter->SetPathRoot(m_PathRoot);
154  m_LabelMapToSimulatedImageFilter->SetMean(m_Mean);
155  m_LabelMapToSimulatedImageFilter->SetVariance(m_Variance);
156 
157  m_LabelMapToLabelImageFilter->SetInput(m_Spatialisation->GetOutput());
158 
159  m_LabelMapToSimulatedImageFilter->UpdateOutputInformation();
160 
161  for (unsigned int i = 0; i < m_NumberOfComponentsPerPixel; ++i)
162  {
163 
164  MultiToMonoChannelFilterPointer multiToMonoChannelFilter = MultiToMonoChannelFilterType::New();
165  InterpolatorPointer interpolator = InterpolatorType::New();
166  FTMFilterPointer FTMFilter = FTMFilterType::New();
167 
168  multiToMonoChannelFilter->SetInput(m_LabelMapToSimulatedImageFilter->GetOutput());
169  multiToMonoChannelFilter->SetChannel(i + 1);
170  multiToMonoChannelFilter->SetExtractionRegion(m_LabelMapToSimulatedImageFilter->GetOutput()->GetLargestPossibleRegion());
171 
172  // TODO comment changer interpolateur !
173  interpolator->SetInputImage(multiToMonoChannelFilter->GetOutput());
174  interpolator->SetRadius(m_Radius);
175  interpolator->Initialize();
176 
177  multiToMonoChannelFilter->UpdateOutputInformation();
178 
179  FTMFilter->SetInterpolator(interpolator);
180  // FTMFilter->SetOutputSize(multiToMonoChannelFilter->GetOutput()->GetLargestPossibleRegion().GetSize());
181  FTMFilter->SetSize(multiToMonoChannelFilter->GetOutput()->GetLargestPossibleRegion().GetSize());
182  FTMFilter->SetOutputSpacing(multiToMonoChannelFilter->GetOutput()->GetSignedSpacing());
183  FTMFilter->SetOutputOrigin(multiToMonoChannelFilter->GetOutput()->GetOrigin());
184  FTMFilter->SetInput(multiToMonoChannelFilter->GetOutput());
185  FTMFilter->Update();
186 
187  m_ImageList->PushBack(FTMFilter->GetOutput());
188  }
189  m_ImageListToVectorImageFilter->SetInput(m_ImageList);
190 }
191 
192 // In case of a true composite filter
193 // template <class TInputVectorData, class TSpatialisation, class TSimulationStep1, class TSimulationStep2, class TFTM, class TOutputImage>
194 // void
195 // ImageSimulationMethod< TInputVectorData, TSpatialisation, TSimulationStep1, TSimulationStep2, TFTM, TOutputImage>
196 // ::GenerateData()
197 // {
198 //
199 // // m_Spatialisation->SetInput(m_InputVectorData);
200 // // m_Spatialisation->SetInitialLabel(1);
201 // // m_Spatialisation->SetBackgroundValue(0);
202 //
203 // m_LabelMapToSimulatedImageFilter->SetInput(m_Spatialisation->GetOutput());
204 // m_LabelMapToSimulatedImageFilter->SetNumberOfComponentsPerPixel(m_NumberOfComponentsPerPixel);
205 // m_LabelMapToSimulatedImageFilter->SetSatRSRFilename(m_SatRSRFilename);
206 // m_LabelMapToSimulatedImageFilter->SetNumberOfThreads(1);
207 // m_LabelMapToSimulatedImageFilter->SetPathRoot(m_PathRoot);
208 // m_LabelMapToSimulatedImageFilter->SetMean(m_Mean);
209 // m_LabelMapToSimulatedImageFilter->SetVariance(m_Variance);
210 //
211 // m_LabelMapToLabelImageFilter->SetInput(m_Spatialisation->GetOutput());
212 // m_LabelMapToLabelImageFilter->GraftNthOutput(0, this->GetOutputLabelImage());
213 // m_LabelMapToLabelImageFilter->Update();
214 // this->GraftNthOutput(1, m_LabelMapToLabelImageFilter->GetOutput());
215 //
216 // // m_LabelMapToSimulatedImageFilter->GraftNthOutput(0, this->GetOutputReflectanceImage());
217 // // m_LabelMapToSimulatedImageFilter->Update();
218 // // this->GraftNthOutput(0, m_LabelMapToSimulatedImageFilter->GetOutput());
219 //
220 // for(unsigned int i = 0; i<m_NumberOfComponentsPerPixel; ++i)
221 // {
222 //
223 // MultiToMonoChannelFilterPointer multiToMonoChannelFilter = MultiToMonoChannelFilterType::New();
224 // InterpolatorPointer interpolator = InterpolatorType::New();
225 // FTMFilterPointer FTMFilter = FTMFilterType::New();
226 //
227 // multiToMonoChannelFilter->SetInput(m_LabelMapToSimulatedImageFilter->GetOutput());
228 // multiToMonoChannelFilter->SetChannel(i+1);
229 // multiToMonoChannelFilter->SetExtractionRegion(m_LabelMapToSimulatedImageFilter->GetOutput()->GetLargestPossibleRegion());
230 //
231 //
232 // //TODO comment changer interpolateur !
233 // interpolator->SetInputImage(multiToMonoChannelFilter->GetOutput());
234 // interpolator->SetRadius(m_Radius);
235 // interpolator->Initialize();
236 //
237 // multiToMonoChannelFilter->UpdateOutputInformation();
238 //
239 // FTMFilter->SetInterpolator(interpolator);
240 // // FTMFilter->SetOutputSize(multiToMonoChannelFilter->GetOutput()->GetLargestPossibleRegion().GetSize());
241 // FTMFilter->SetSize(multiToMonoChannelFilter->GetOutput()->GetLargestPossibleRegion().GetSize());
242 // FTMFilter->SetOutputSpacing(multiToMonoChannelFilter->GetOutput()->GetSignedSpacing());
243 // FTMFilter->SetOutputOrigin(multiToMonoChannelFilter->GetOutput()->GetOrigin());
244 // FTMFilter->SetInput(multiToMonoChannelFilter->GetOutput());
245 // FTMFilter->Update();
246 //
247 // m_ImageList->PushBack(FTMFilter->GetOutput());
248 // }
249 // m_ImageListToVectorImageFilter->SetInput(m_ImageList);
250 //
251 // m_ImageListToVectorImageFilter->GraftNthOutput(0, this->GetOutputReflectanceImage());
252 // m_ImageListToVectorImageFilter->Update();
253 // this->GraftNthOutput(0, m_ImageListToVectorImageFilter->GetOutput());
254 //
255 // }
256 
257 
258 template <class TInputVectorData, class TSpatialisation, class TSimulationStep1, class TSimulationStep2, class TFTM, class TOutputImage>
260  itk::Indent indent) const
261 {
262  Superclass::PrintSelf(os, indent);
263 }
264 
265 } // end namespace otb
266 
267 #endif
otb::ImageSimulationMethod::GenerateOutputInformation
void GenerateOutputInformation() override
Definition: otbImageSimulationMethod.hxx:123
otb::ImageSimulationMethod::InterpolatorPointer
InterpolatorType::Pointer InterpolatorPointer
Definition: otbImageSimulationMethod.h:110
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::ImageSimulationMethod::GetOutputLabelImage
virtual OutputLabelImageType * GetOutputLabelImage()
Definition: otbImageSimulationMethod.hxx:117
otb::Image
Creation of an "otb" image which contains metadata.
Definition: otbImage.h:89
otb::ImageSimulationMethod::UpdateData
void UpdateData()
Definition: otbImageSimulationMethod.hxx:142
otb::ImageSimulationMethod::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbImageSimulationMethod.hxx:259
otb::ImageSimulationMethod::MultiToMonoChannelFilterPointer
MultiToMonoChannelFilterType::Pointer MultiToMonoChannelFilterPointer
Definition: otbImageSimulationMethod.h:102
otb::ImageSimulationMethod::GetOutputReflectanceImage
virtual OutputImageType * GetOutputReflectanceImage()
Definition: otbImageSimulationMethod.hxx:109
otb::ImageSimulationMethod::ImageSimulationMethod
ImageSimulationMethod()
Definition: otbImageSimulationMethod.hxx:30
otb::ImageSimulationMethod::FTMFilterPointer
FTMFilterType::Pointer FTMFilterPointer
Definition: otbImageSimulationMethod.h:113
otbImageSimulationMethod.h
otb::ImageSimulationMethod::OutputImageType
TOutputImage OutputImageType
Definition: otbImageSimulationMethod.h:91