Orfeo Toolbox  4.0
otbWrapperOutputImageParameter.cxx
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 =========================================================================*/
19 #include "otbClampImageFilter.h"
21 
22 namespace otb
23 {
24 namespace Wrapper
25 {
26 
28  : m_PixelType(ImagePixelType_float), m_RAMValue(0)
29 {
30  this->SetName("Output Image");
31  this->SetKey("out");
32 }
33 
34 
36 {
37 }
38 
40 {
48 
56 
59 }
60 
61 
62 #define otbClampAndWriteImageMacro(InputImageType, OutputImageType, writer) \
63  { \
64  typedef otb::ClampImageFilter<InputImageType, OutputImageType> ClampFilterType; \
65  typename ClampFilterType::Pointer clampFilter = ClampFilterType::New(); \
66  clampFilter->SetInput( dynamic_cast<InputImageType*>(m_Image.GetPointer()) ); \
67  writer->SetFileName( this->GetFileName() ); \
68  writer->SetInput(clampFilter->GetOutput()); \
69  writer->SetAutomaticAdaptativeStreaming(m_RAMValue); \
70  writer->Update(); \
71  }
72 
73 #define otbClampAndWriteVectorImageMacro(InputImageType, OutputImageType, writer) \
74  { \
75  typedef otb::ClampVectorImageFilter<InputImageType, OutputImageType> ClampFilterType; \
76  typename ClampFilterType::Pointer clampFilter = ClampFilterType::New(); \
77  clampFilter->SetInput( dynamic_cast<InputImageType*>(m_Image.GetPointer()) ); \
78  writer->SetFileName(this->GetFileName() ); \
79  writer->SetInput(clampFilter->GetOutput()); \
80  writer->SetAutomaticAdaptativeStreaming(m_RAMValue); \
81  writer->Update(); \
82  }
83 
84 
85 template <class TInputImageType>
86 void
88 {
89  switch(m_PixelType )
90  {
92  {
94  break;
95  }
97  {
99  break;
100  }
102  {
104  break;
105  }
107  {
109  break;
110  }
112  {
114  break;
115  }
117  {
119  break;
120  }
122  {
124  break;
125  }
126  }
127 }
128 
129 
130 template <class TInputVectorImageType>
131 void
133  {
134  switch(m_PixelType )
135  {
137  {
139  break;
140  }
142  {
144  break;
145  }
147  {
149  break;
150  }
152  {
154  break;
155  }
157  {
159  break;
160  }
162  {
164  break;
165  }
167  {
169  break;
170  }
171  }
172  }
173 
174 
175 template <class TInputRGBAImageType>
176 void
178  {
180  {
181  m_RGBAUInt8Writer->SetFileName( this->GetFileName() );
182  m_RGBAUInt8Writer->SetInput(dynamic_cast<UInt8RGBAImageType*>(m_Image.GetPointer()) );
183  m_RGBAUInt8Writer->SetAutomaticAdaptativeStreaming(m_RAMValue);
184  m_RGBAUInt8Writer->Update();
185  }
186  else
187  itkExceptionMacro("Unknown PixelType for RGBA Image. Only uint8 is supported.");
188  }
189 
190 template <class TInputRGBImageType>
191 void
193  {
195  {
196  m_RGBUInt8Writer->SetFileName( this->GetFileName() );
197  m_RGBUInt8Writer->SetInput(dynamic_cast<UInt8RGBImageType*>(m_Image.GetPointer()) );
198  m_RGBUInt8Writer->SetAutomaticAdaptativeStreaming(m_RAMValue);
199  m_RGBUInt8Writer->Update();
200  }
201  else
202  itkExceptionMacro("Unknown PixelType for RGB Image. Only uint8 is supported.");
203  }
204 
205 void
207 {
208  m_Image->UpdateOutputInformation();
209 
210  if (dynamic_cast<UInt8ImageType*>(m_Image.GetPointer()))
211  {
212  SwitchImageWrite<UInt8ImageType>();
213  }
214  else if (dynamic_cast<Int16ImageType*>(m_Image.GetPointer()))
215  {
216  SwitchImageWrite<Int16ImageType>();
217  }
218  else if (dynamic_cast<UInt16ImageType*>(m_Image.GetPointer()))
219  {
220  SwitchImageWrite<UInt16ImageType>();
221  }
222  else if (dynamic_cast<Int32ImageType*>(m_Image.GetPointer()))
223  {
224  SwitchImageWrite<Int32ImageType>();
225  }
226  else if (dynamic_cast<UInt32ImageType*>(m_Image.GetPointer()))
227  {
228  SwitchImageWrite<UInt32ImageType>();
229  }
230  else if (dynamic_cast<FloatImageType*>(m_Image.GetPointer()))
231  {
232  SwitchImageWrite<FloatImageType>();
233  }
234  else if (dynamic_cast<DoubleImageType*>(m_Image.GetPointer()))
235  {
236  SwitchImageWrite<DoubleImageType>();
237  }
238  else if (dynamic_cast<UInt8VectorImageType*>(m_Image.GetPointer()))
239  {
240  SwitchVectorImageWrite<UInt8VectorImageType>();
241  }
242  else if (dynamic_cast<Int16VectorImageType*>(m_Image.GetPointer()))
243  {
244  SwitchVectorImageWrite<Int16VectorImageType>();
245  }
246  else if (dynamic_cast<UInt16VectorImageType*>(m_Image.GetPointer()))
247  {
248  SwitchVectorImageWrite<UInt16VectorImageType>();
249  }
250  else if (dynamic_cast<Int32VectorImageType*>(m_Image.GetPointer()))
251  {
252  SwitchVectorImageWrite<Int32VectorImageType>();
253  }
254  else if (dynamic_cast<UInt32VectorImageType*>(m_Image.GetPointer()))
255  {
256  SwitchVectorImageWrite<UInt32VectorImageType>();
257  }
258  else if (dynamic_cast<FloatVectorImageType*>(m_Image.GetPointer()))
259  {
260  SwitchVectorImageWrite<FloatVectorImageType>();
261  }
262  else if (dynamic_cast<DoubleVectorImageType*>(m_Image.GetPointer()))
263  {
264  SwitchVectorImageWrite<DoubleVectorImageType>();
265  }
266  else if (dynamic_cast<UInt8RGBImageType*>(m_Image.GetPointer()))
267  {
268  SwitchRGBImageWrite<UInt8RGBImageType>();
269  }
270  else if (dynamic_cast<UInt8RGBAImageType*>(m_Image.GetPointer()))
271  {
272  SwitchRGBAImageWrite<UInt8RGBAImageType>();
273  }
274  else
275  {
276  itkExceptionMacro("Unknown image type");
277  }
278  }
279 
280 
283 {
284  int type = 0;
285  // 0 : image
286  // 1 : VectorImage
287  // 2 : RGBAImage
288  // 3 : RGBImage
289  itk::ProcessObject* writer = 0;
290  if (dynamic_cast<UInt8VectorImageType*> (m_Image.GetPointer())
291  || dynamic_cast<Int16VectorImageType*> (m_Image.GetPointer())
292  || dynamic_cast<UInt16VectorImageType*> (m_Image.GetPointer())
293  || dynamic_cast<Int32VectorImageType*> (m_Image.GetPointer())
294  || dynamic_cast<UInt32VectorImageType*> (m_Image.GetPointer())
295  || dynamic_cast<FloatVectorImageType*> (m_Image.GetPointer())
296  || dynamic_cast<DoubleVectorImageType*> (m_Image.GetPointer()))
297  {
298  type = 1;
299  }
300  else
301  if (dynamic_cast<UInt8RGBAImageType*> (m_Image.GetPointer()))
302  {
303  type = 2;
304  writer = m_RGBAUInt8Writer;
305  itkWarningMacro("UInt8RGBAImageType will be saved in UInt8 format.");
306  return writer;
307  }
308  else
309  if (dynamic_cast<UInt8RGBImageType*> (m_Image.GetPointer()))
310  {
311  type = 3;
312  writer = m_RGBUInt8Writer;
313  itkWarningMacro("UInt8RGBImageType will be saved in UInt8 format.");
314  return writer;
315  }
316 
317 
318  switch (GetPixelType())
319  {
321  {
322  if (type == 1)
323  writer = m_VectorUInt8Writer;
324  else
325  if (type == 0)
326  writer = m_UInt8Writer;
327  else
328  if (type == 2)
329  writer = m_RGBAUInt8Writer;
330  else writer = m_RGBUInt8Writer;
331  break;
332  }
334  {
335  if (type == 1)
336  writer = m_VectorInt16Writer;
337  else
338  if (type == 0) writer = m_Int16Writer;
339  break;
340  }
342  {
343  if (type == 1)
344  writer = m_VectorUInt16Writer;
345  else
346  if (type == 0) writer = m_UInt16Writer;
347  break;
348  }
350  {
351  if (type == 1)
352  writer = m_VectorInt32Writer;
353  else
354  if (type == 0) writer = m_Int32Writer;
355  break;
356  }
358  {
359  if (type == 1)
360  writer = m_VectorUInt32Writer;
361  else
362  if (type == 0) writer = m_UInt32Writer;
363  break;
364  }
366  {
367  if (type == 1)
368  writer = m_VectorFloatWriter;
369  else
370  if (type == 0) writer = m_FloatWriter;
371  break;
372  }
374  {
375  if (type == 1)
376  writer = m_VectorDoubleWriter;
377  else
378  if (type == 0) writer = m_DoubleWriter;
379  break;
380  }
381  }
382  if (0 == writer)
383  {
384  itkExceptionMacro("Unknown Writer type.");
385  }
386 
387  return writer;
388 }
389 
392 {
393  return m_Image;
394 }
395 
396 void
398 {
399  m_Image = image;
400  SetActive(true);
401 }
402 
403 bool
405 {
406  std::string filename(this->GetFileName());
407  return !filename.empty();
408 }
409 
410 }
411 }

Generated at Sat Mar 8 2014 16:28:50 for Orfeo Toolbox with doxygen 1.8.3.1