Orfeo Toolbox  3.16
otbWrapperComplexInputImageParameter.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 "itksys/SystemTools.hxx"
20 #include "otbImageFileReader.h"
21 #include "itkCastImageFilter.h"
23 #include "otbWrapperTypes.h"
24 
25 namespace otb
26 {
27 namespace Wrapper
28 {
29 
31 {
32  this->SetName("Complex Input Image");
33  this->SetKey("cin");
34  m_FileName="";
35  this->ClearValue();
36 }
37 
39 {
40 }
41 
42 void
43 ComplexInputImageParameter::SetFromFileName(const std::string& filename)
44 {
45  // First clear previous file choosen
46  this->ClearValue();
47 
48  // TODO : when the logger will be available, redirect the exception
49  // in the logger (like what is done in MsgReporter)
50  if (!filename.empty()
51  && itksys::SystemTools::FileExists(filename.c_str()))
52  {
54  reader->SetFileName(filename);
55  try
56  {
57  reader->UpdateOutputInformation();
58  }
59  catch(itk::ExceptionObject &)
60  {
61  }
62 
63  // the specified filename is valid => store the value
64  m_FileName = filename;
65  SetActive(true);
66  }
67 }
68 
69 
72 {
73  return this->GetImage<ComplexFloatVectorImageType>();
74 }
75 
76 
77 #define otbGetImageMacro(image) \
78  image##Type * \
79  ComplexInputImageParameter::Get##image () \
80  { \
81  return this->GetImage< image##Type > (); \
82  }
83 
84 otbGetImageMacro(ComplexFloatImage);
85 otbGetImageMacro(ComplexDoubleImage);
86 
87 otbGetImageMacro(ComplexFloatVectorImage);
88 otbGetImageMacro(ComplexDoubleVectorImage);
89 
90 template <class TOutputImage>
91 TOutputImage *
93 {
94  // 2 cases : the user set a filename vs. the user set an image
96  if( !m_FileName.empty() )
97  {
98  typedef otb::ImageFileReader<TOutputImage> ReaderType;
99  typename ReaderType::Pointer reader = ReaderType::New();
100  reader->SetFileName(m_FileName);
101  try
102  {
103  reader->UpdateOutputInformation();
104  }
105  catch(itk::ExceptionObject &)
106  {
107  this->ClearValue();
108  }
109 
110  m_Image = reader->GetOutput();
111  m_Reader = reader;
112 
113  // Pay attention, don't return m_Image because it is a ImageBase...
114  return reader->GetOutput();
115  }
117  else
118  {
119  if( m_Image.IsNull() )
120  {
121  itkExceptionMacro("No input image or filename detected...");
122  }
123  else
124  {
125  if (dynamic_cast<ComplexFloatVectorImageType*>(m_Image.GetPointer()))
126  {
127  return CastImage<ComplexFloatVectorImageType, TOutputImage>();
128  }
129  else if (dynamic_cast<ComplexDoubleVectorImageType*>(m_Image.GetPointer()))
130  {
131  return CastImage<ComplexDoubleVectorImageType, TOutputImage>();
132  }
133  else if (dynamic_cast<ComplexFloatImageType*>(m_Image.GetPointer()))
134  {
135  return CastImage<ComplexFloatImageType, TOutputImage>();
136  }
137  else if (dynamic_cast<ComplexDoubleImageType*>(m_Image.GetPointer()))
138  {
139  return CastImage<ComplexDoubleImageType, TOutputImage>();
140  }
141  else
142  {
143  itkExceptionMacro("Unknown image type");
144  }
145  }
146  }
147 }
148 
149 
150 template <class TComplexInputImage, class TOutputImage>
151 TOutputImage*
153 {
154  TComplexInputImage* realComplexInputImage = dynamic_cast<TComplexInputImage*>(m_Image.GetPointer());
155 
157  typename CasterType::Pointer caster = CasterType::New();
158 
159  caster->SetInput(realComplexInputImage);
160  caster->UpdateOutputInformation();
161 
162  m_Image = caster->GetOutput();
163  m_Caster = caster;
164 
165  return caster->GetOutput();
166 }
167 
168 
169 template <class TComplexInputImage, class TOutputImage>
170 TOutputImage*
172 {
173  TComplexInputImage* realComplexInputImage = dynamic_cast<TComplexInputImage*>(m_Image.GetPointer());
174 
176  typename CasterType::Pointer caster = CasterType::New();
177 
178  caster->SetInput(realComplexInputImage);
179  caster->UpdateOutputInformation();
180 
181  m_Image = caster->GetOutput();
182  m_Caster = caster;
183 
184  return caster->GetOutput();
185 }
186 
187 
188 #define otbCastImageMacro(ComplexInputImageType, OutputImageType, theMethod) \
189  template<> OutputImageType * \
190  ComplexInputImageParameter::CastImage<ComplexInputImageType , OutputImageType>() \
191  { \
192  return this->theMethod<ComplexInputImageType , OutputImageType>(); \
193  }
194 
195 #define otbGenericCastImageMacro(ComplexInputImageType, theMethod, prefix) \
196  otbCastImageMacro(ComplexInputImageType, ComplexFloat##prefix##ImageType, theMethod) \
197  otbCastImageMacro(ComplexInputImageType, ComplexDouble##prefix##ImageType, theMethod)
198 
199 
200 /*********************************************************************
201 ********************** Image -> Image
202 **********************************************************************/
203 
206 
207 
208 /*********************************************************************
209 ********************** VectorImage -> VectorImage
210 **********************************************************************/
213 
214  void
215 ComplexInputImageParameter::SetImage(ComplexFloatVectorImageType* image)
216 {
217  this->SetImage<ComplexFloatVectorImageType>( image );
218 }
219 
220 
221 template <class TComplexInputImage>
222 void
223 ComplexInputImageParameter::SetImage(TComplexInputImage* image)
224 {
225  m_Image = image;
226 }
227 
228 
229 bool
231 {
232  if( m_FileName.empty() && m_Image.IsNull() )
233  return false;
234  else
235  return true;
236 }
237 
238 void
240 {
241  m_Image = NULL;
242  m_Reader = NULL;
243  m_Caster = NULL;
244 }
245 
246 
247 }
248 }
249 

Generated at Sun Feb 3 2013 00:59:08 for Orfeo Toolbox with doxygen 1.8.1.1