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