Orfeo Toolbox  3.16
itkVTKImageExport.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkVTKImageExport.txx,v $
5  Language: C++
6  Date: $Date: 2007-10-05 10:29:52 $
7  Version: $Revision: 1.17 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkVTKImageExport_txx
18 #define __itkVTKImageExport_txx
19 
20 #include "itkVTKImageExport.h"
21 
22 #include "itkPixelTraits.h"
23 
24 namespace itk
25 {
26 
31 template <class TInputImage>
33 {
34  typedef typename TInputImage::PixelType PixelType;
35  typedef typename PixelTraits< PixelType >::ValueType ScalarType;
36 
37  if(typeid(ScalarType) == typeid(double))
38  {
39  m_ScalarTypeName = "double";
40  }
41  else if(typeid(ScalarType) == typeid(float))
42  {
43  m_ScalarTypeName = "float";
44  }
45  else if(typeid(ScalarType) == typeid(long))
46  {
47  m_ScalarTypeName = "long";
48  }
49  else if(typeid(ScalarType) == typeid(unsigned long))
50  {
51  m_ScalarTypeName = "unsigned long";
52  }
53  else if(typeid(ScalarType) == typeid(int))
54  {
55  m_ScalarTypeName = "int";
56  }
57  else if(typeid(ScalarType) == typeid(unsigned int))
58  {
59  m_ScalarTypeName = "unsigned int";
60  }
61  else if(typeid(ScalarType) == typeid(short))
62  {
63  m_ScalarTypeName = "short";
64  }
65  else if(typeid(ScalarType) == typeid(unsigned short))
66  {
67  m_ScalarTypeName = "unsigned short";
68  }
69  else if(typeid(ScalarType) == typeid(char))
70  {
71  m_ScalarTypeName = "char";
72  }
73  else if(typeid(ScalarType) == typeid(unsigned char))
74  {
75  m_ScalarTypeName = "unsigned char";
76  }
77  else if(typeid(ScalarType) == typeid(signed char))
78  {
79  m_ScalarTypeName = "signed char";
80  }
81  else
82  {
83  itkExceptionMacro(<<"Type currently not supported");
84  }
85 }
86 
87 template <class TInputImage>
89  Indent indent) const
90 {
91  Superclass::PrintSelf(os, indent);
92 }
93 
94 
98 template <class TInputImage>
100 {
102  const_cast<TInputImage*>(input) );
103 }
104 
105 
109 template <class TInputImage>
112 {
113  return static_cast<TInputImage*>(
114  this->ProcessObject::GetInput(0));
115 }
116 
117 
123 template <class TInputImage>
125 {
126  InputImagePointer input = this->GetInput();
127  if( !input )
128  {
129  itkExceptionMacro(<< "Need to set an input");
130  return 0;
131  }
132 
133  InputRegionType region = input->GetLargestPossibleRegion();
134  InputSizeType size = region.GetSize();
135  InputIndexType index = region.GetIndex();
136 
137  unsigned int i=0;
138  // Fill in the known portion of the extent.
139  for(;i < InputImageDimension;++i)
140  {
141  m_WholeExtent[i*2] = int(index[i]);
142  m_WholeExtent[i*2+1] = int(index[i]+size[i])-1;
143  }
144  // Fill in the extent for dimensions up to three.
145  for(;i < 3; ++i)
146  {
147  m_WholeExtent[i*2] = 0;
148  m_WholeExtent[i*2+1] = 0;
149  }
150  return m_WholeExtent;
151 }
152 
153 
158 template <class TInputImage>
160 {
161  InputImagePointer input = this->GetInput();
162  if( !input )
163  {
164  itkExceptionMacro(<< "Need to set an input");
165  return 0;
166  }
167 
168  const typename TInputImage::SpacingType& spacing = input->GetSpacing();
169 
170  unsigned int i=0;
171  // Fill in the known portion of the spacing.
172  for(;i < InputImageDimension;++i)
173  {
174  m_DataSpacing[i] = static_cast<double>(spacing[i]);
175  }
176  // Fill up the spacing with defaults up to three dimensions.
177  for(;i < 3;++i)
178  {
179  m_DataSpacing[i] = 1;
180  }
181  return m_DataSpacing;
182 }
183 
188 template <class TInputImage>
190 {
191  InputImagePointer input = this->GetInput();
192  const typename TInputImage::SpacingType& spacing = input->GetSpacing();
193 
194  unsigned int i=0;
195  // Fill in the known portion of the spacing.
196  for(;i < InputImageDimension;++i)
197  {
198  m_FloatDataSpacing[i] = static_cast<float>(spacing[i]);
199  }
200  // Fill up the spacing with defaults up to three dimensions.
201  for(;i < 3;++i)
202  {
203  m_FloatDataSpacing[i] = 1;
204  }
205  return m_FloatDataSpacing;
206 }
207 
208 
213 template <class TInputImage>
215 {
216  InputImagePointer input = this->GetInput();
217  if( !input )
218  {
219  itkExceptionMacro(<< "Need to set an input");
220  return 0;
221  }
222 
223  const typename TInputImage::PointType& origin = input->GetOrigin();
224 
225  unsigned int i=0;
226  // Fill in the known portion of the origin.
227  for(;i < InputImageDimension;++i)
228  {
229  m_DataOrigin[i] = static_cast<double>(origin[i]);
230  }
231  // Fill up the origin with defaults up to three dimensions.
232  for(;i < 3;++i)
233  {
234  m_DataOrigin[i] = 0;
235  }
236  return m_DataOrigin;
237 }
238 
243 template <class TInputImage>
245 {
246  InputImagePointer input = this->GetInput();
247  const typename TInputImage::PointType& origin = input->GetOrigin();
248 
249  unsigned int i=0;
250  // Fill in the known portion of the origin.
251  for(;i < InputImageDimension;++i)
252  {
253  m_FloatDataOrigin[i] = static_cast<float>(origin[i]);
254  }
255  // Fill up the origin with defaults up to three dimensions.
256  for(;i < 3;++i)
257  {
258  m_FloatDataOrigin[i] = 0;
259  }
260  return m_FloatDataOrigin;
261 }
262 
263 
268 template <class TInputImage>
270 {
271  return m_ScalarTypeName.c_str();
272 }
273 
274 
281 template <class TInputImage>
283 {
284  typedef typename TInputImage::PixelType PixelType;
285  typedef typename PixelTraits< PixelType >::ValueType ValueType;
286 
287  // on the assumption that there is no padding in this pixel type...
288  return sizeof( PixelType ) / sizeof( ValueType );
289 }
290 
291 
298 template <class TInputImage>
300 {
301  InputSizeType size;
302  InputIndexType index;
303 
304  for(unsigned int i=0;i < InputImageDimension;++i)
305  {
306  index[i] = extent[i*2];
307  size[i] = (extent[i*2+1]-extent[i*2])+1;
308  }
309 
310  InputRegionType region;
311  region.SetSize(size);
312  region.SetIndex(index);
313 
314  InputImagePointer input = this->GetInput();
315  if( !input )
316  {
317  itkExceptionMacro(<< "Need to set an input");
318  return;
319  }
320 
321  input->SetRequestedRegion(region);
322 }
323 
324 
331 template <class TInputImage>
333 {
334  InputImagePointer input = this->GetInput();
335  if( !input )
336  {
337  itkExceptionMacro(<< "Need to set an input");
338  return 0;
339  }
340 
341  InputRegionType region = input->GetBufferedRegion();
342  InputSizeType size = region.GetSize();
343  InputIndexType index = region.GetIndex();
344 
345  unsigned int i=0;
346  for(;i < InputImageDimension;++i)
347  {
348  m_DataExtent[i*2] = int(index[i]);
349  m_DataExtent[i*2+1] = int(index[i]+size[i])-1;
350  }
351  for(;i < 3; ++i)
352  {
353  m_DataExtent[i*2] = 0;
354  m_DataExtent[i*2+1] = 0;
355  }
356  return m_DataExtent;
357 }
358 
359 
364 template <class TInputImage>
366 {
367  InputImagePointer input = this->GetInput();
368  if( !input )
369  {
370  itkExceptionMacro(<< "Need to set an input");
371  return 0;
372  }
373 
374  return input->GetBufferPointer();
375 }
376 
377 } // end namespace itk
378 
379 #endif

Generated at Sun Feb 3 2013 00:14:15 for Orfeo Toolbox with doxygen 1.8.1.1