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