SimpleITK  1.0.1
sitkImage.h
Go to the documentation of this file.
1 /*=========================================================================
2 *
3 * Copyright Insight Software Consortium
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18 #ifndef sitkImage_h
19 #define sitkImage_h
20 
21 #include "sitkCommon.h"
22 #include "sitkTemplateFunctions.h"
23 #include "sitkDetail.h"
24 #include "sitkPixelIDTokens.h"
25 #include "sitkEnableIf.h"
26 
27 #include "nsstd/type_traits.h"
28 #include "nsstd/auto_ptr.h"
29 
30 #include <vector>
31 #include <memory>
32 
33 namespace itk
34 {
35 
36 // Forward decalaration for pointer
37 class DataObject;
38 
39 template<class T>
40 class SmartPointer;
41 
42 namespace simple
43 {
44 
45  // This is the foward declaration of a class used internally to the
46  // Image class, but the actually interface is not exposed to simple
47  // ITK. A pointer to the implementation is used as per the pimple
48  // idiom.
49  class PimpleImageBase;
50 
55  {
56  public:
57  typedef Image Self;
58 
59  virtual ~Image( );
60 
62  Image( void );
63 
64  // copy constructor
65  Image( const Image &img );
66  Image& operator=( const Image &img );
67 
83  Image( unsigned int width, unsigned int height, PixelIDValueEnum valueEnum );
84  Image( unsigned int width, unsigned int height, unsigned int depth, PixelIDValueEnum valueEnum );
85  Image( const std::vector< unsigned int > &size, PixelIDValueEnum valueEnum, unsigned int numberOfComponents = 0 );
105  template <typename TImageType>
107  : m_PimpleImage( NULL )
108  {
110  "invalid pixel type" );
111  this->InternalInitialization<ImageTypeToPixelIDValue<TImageType>::Result, TImageType::ImageDimension>( image.GetPointer() );
112  }
113  template <typename TImageType>
114  explicit Image( TImageType* image )
115  : m_PimpleImage( NULL )
116  {
118  "invalid pixel type" );
119  this->InternalInitialization<ImageTypeToPixelIDValue<TImageType>::Result, TImageType::ImageDimension>( image );
120  }
135  itk::DataObject* GetITKBase( void );
136  const itk::DataObject* GetITKBase( void ) const;
139  // could return -1 if in valid
140  PixelIDValueEnum GetPixelID( void ) const;
141  PixelIDValueType GetPixelIDValue( void ) const;
142 
143  unsigned int GetDimension( void ) const;
144 
150  unsigned int GetNumberOfComponentsPerPixel( void ) const;
151 
160  uint64_t GetNumberOfPixels( void ) const;
161 
165  std::vector< double > GetOrigin( void ) const;
166  void SetOrigin( const std::vector< double > &origin );
172  std::vector< double > GetSpacing( void ) const;
173  void SetSpacing( const std::vector< double > &spacing );
183  std::vector< double > GetDirection() const;
184  void SetDirection ( const std::vector< double > &direction );
188  std::vector< double > TransformIndexToPhysicalPoint( const std::vector< int64_t > &index ) const;
189 
191  std::vector< int64_t > TransformPhysicalPointToIndex( const std::vector< double >& point ) const;
192 
194  std::vector< double > TransformPhysicalPointToContinuousIndex( const std::vector< double >& point ) const;
195 
197  std::vector< double > TransformContinuousIndexToPhysicalPoint( const std::vector< double > &index) const;
198 
199  std::vector< unsigned int > GetSize( void ) const;
200 
201  unsigned int GetHeight( void ) const;
202  unsigned int GetWidth( void ) const;
203  unsigned int GetDepth( void ) const;
204 
205 
216  void CopyInformation( const Image &srcImage );
217 
224  std::vector<std::string> GetMetaDataKeys( void ) const;
225 
228  bool HasMetaDataKey( const std::string &key ) const;
229 
238  std::string GetMetaData( const std::string &key ) const;
239 
244  void SetMetaData( const std::string &key, const std::string &value);
245 
251  bool EraseMetaData( const std::string &key );
252 
253  std::string GetPixelIDTypeAsString( void ) const;
254 
255  std::string ToString( void ) const;
256 
272  int8_t GetPixelAsInt8( const std::vector<uint32_t> &idx) const;
273  uint8_t GetPixelAsUInt8( const std::vector<uint32_t> &idx) const;
274  int16_t GetPixelAsInt16( const std::vector<uint32_t> &idx ) const;
275  uint16_t GetPixelAsUInt16( const std::vector<uint32_t> &idx ) const;
276  int32_t GetPixelAsInt32( const std::vector<uint32_t> &idx ) const;
277  uint32_t GetPixelAsUInt32( const std::vector<uint32_t> &idx ) const;
278  int64_t GetPixelAsInt64( const std::vector<uint32_t> &idx ) const;
279  uint64_t GetPixelAsUInt64( const std::vector<uint32_t> &idx ) const;
280  float GetPixelAsFloat( const std::vector<uint32_t> &idx ) const;
281  double GetPixelAsDouble( const std::vector<uint32_t> &idx ) const;
282 
283  std::vector<int8_t> GetPixelAsVectorInt8( const std::vector<uint32_t> &idx) const;
284  std::vector<uint8_t> GetPixelAsVectorUInt8( const std::vector<uint32_t> &idx) const;
285  std::vector<int16_t> GetPixelAsVectorInt16( const std::vector<uint32_t> &idx ) const;
286  std::vector<uint16_t> GetPixelAsVectorUInt16( const std::vector<uint32_t> &idx ) const;
287  std::vector<int32_t> GetPixelAsVectorInt32( const std::vector<uint32_t> &idx ) const;
288  std::vector<uint32_t> GetPixelAsVectorUInt32( const std::vector<uint32_t> &idx ) const;
289  std::vector<int64_t> GetPixelAsVectorInt64( const std::vector<uint32_t> &idx ) const;
290  std::vector<uint64_t> GetPixelAsVectorUInt64( const std::vector<uint32_t> &idx ) const;
291  std::vector<float> GetPixelAsVectorFloat32( const std::vector<uint32_t> &idx ) const;
292  std::vector<double> GetPixelAsVectorFloat64( const std::vector<uint32_t> &idx ) const;
293 
294  std::complex<float> GetPixelAsComplexFloat32( const std::vector<uint32_t> &idx ) const;
295  std::complex<double> GetPixelAsComplexFloat64( const std::vector<uint32_t> &idx ) const;
314  void SetPixelAsInt8( const std::vector<uint32_t> &idx, int8_t v );
315  void SetPixelAsUInt8( const std::vector<uint32_t> &idx, uint8_t v );
316  void SetPixelAsInt16( const std::vector<uint32_t> &idx, int16_t v );
317  void SetPixelAsUInt16( const std::vector<uint32_t> &idx, uint16_t v );
318  void SetPixelAsInt32( const std::vector<uint32_t> &idx, int32_t v );
319  void SetPixelAsUInt32( const std::vector<uint32_t> &idx, uint32_t v );
320  void SetPixelAsInt64( const std::vector<uint32_t> &idx, int64_t v );
321  void SetPixelAsUInt64( const std::vector<uint32_t> &idx, uint64_t v );
322  void SetPixelAsFloat( const std::vector<uint32_t> &idx, float v );
323  void SetPixelAsDouble( const std::vector<uint32_t> &idx, double v );
324 
325  void SetPixelAsVectorInt8( const std::vector<uint32_t> &idx, const std::vector<int8_t> &v );
326  void SetPixelAsVectorUInt8( const std::vector<uint32_t> &idx, const std::vector<uint8_t> &v );
327  void SetPixelAsVectorInt16( const std::vector<uint32_t> &idx, const std::vector<int16_t> &v );
328  void SetPixelAsVectorUInt16( const std::vector<uint32_t> &idx, const std::vector<uint16_t> &v );
329  void SetPixelAsVectorInt32( const std::vector<uint32_t> &idx, const std::vector<int32_t> &v );
330  void SetPixelAsVectorUInt32( const std::vector<uint32_t> &idx, const std::vector<uint32_t> &v );
331  void SetPixelAsVectorInt64( const std::vector<uint32_t> &idx, const std::vector<int64_t> &v );
332  void SetPixelAsVectorUInt64( const std::vector<uint32_t> &idx, const std::vector<uint64_t> &v );
333  void SetPixelAsVectorFloat32( const std::vector<uint32_t> &idx, const std::vector<float> &v );
334  void SetPixelAsVectorFloat64( const std::vector<uint32_t> &idx, const std::vector<double> &v );
335 
336  void SetPixelAsComplexFloat32( const std::vector<uint32_t> &idx, const std::complex<float> v );
337  void SetPixelAsComplexFloat64( const std::vector<uint32_t> &idx, const std::complex<double> v );
338 
364  int8_t *GetBufferAsInt8( );
365  uint8_t *GetBufferAsUInt8( );
366  int16_t *GetBufferAsInt16( );
367  uint16_t *GetBufferAsUInt16( );
368  int32_t *GetBufferAsInt32( );
369  uint32_t *GetBufferAsUInt32( );
370  int64_t *GetBufferAsInt64( );
371  uint64_t *GetBufferAsUInt64( );
372  float *GetBufferAsFloat( );
373  double *GetBufferAsDouble( );
374 
375  const int8_t *GetBufferAsInt8( ) const;
376  const uint8_t *GetBufferAsUInt8( ) const;
377  const int16_t *GetBufferAsInt16( ) const;
378  const uint16_t *GetBufferAsUInt16( ) const;
379  const int32_t *GetBufferAsInt32( ) const;
380  const uint32_t *GetBufferAsUInt32( ) const;
381  const int64_t *GetBufferAsInt64( ) const;
382  const uint64_t *GetBufferAsUInt64( ) const;
383  const float *GetBufferAsFloat( ) const;
384  const double *GetBufferAsDouble( ) const;
394  void MakeUnique( void );
395 
396  protected:
397 
404  void Allocate ( unsigned int width, unsigned int height, unsigned int depth, unsigned int dim4, PixelIDValueEnum valueEnum, unsigned int numberOfComponents );
405 
413  template<class TImageType>
415  AllocateInternal ( unsigned int width, unsigned int height, unsigned int depth, unsigned int dim4, unsigned int numberOfComponents );
416 
417  template<class TImageType>
419  AllocateInternal ( unsigned int width, unsigned int height, unsigned int depth, unsigned int dim4, unsigned int numberOfComponents );
420 
421  template<class TImageType>
423  AllocateInternal ( unsigned int width, unsigned int height, unsigned int depth, unsigned int dim4, unsigned int numberOfComponents );
427  private:
428 
437  template <int VPixelIDValue, unsigned int VImageDimension>
438  void InternalInitialization( typename PixelIDToImageType<typename typelist::TypeAt<InstantiatedPixelIDTypeList,
439  VPixelIDValue>::Result,
440  VImageDimension>::ImageType *i );
441 
449  template<int VPixelIDValue, typename TImageType>
451  ConditionalInternalInitialization( TImageType *i);
452 
453  template<int VPixelIDValue, typename TImageType>
455  ConditionalInternalInitialization( TImageType *) { assert( false ); }
461  template < class TMemberFunctionPointer >
463  {
464  typedef typename ::detail::FunctionTraits<TMemberFunctionPointer>::ClassType ObjectType;
465 
466  template< typename TImageType >
467  TMemberFunctionPointer operator() ( void ) const
468  {
469  return &ObjectType::template AllocateInternal< TImageType >;
470  }
471  };
472 
474  };
475 
476 }
477 }
478 
479 #endif
AllPixelIDTypeList InstantiatedPixelIDTypeList
PimpleImageBase * m_PimpleImage
Definition: sitkImage.h:473
ObjectType * GetPointer() const noexcept
PixelIDValueEnum
Enumerated values of pixelIDs.
class ITK_FORWARD_EXPORT DataObject
EnableIf< nsstd::is_same< TImageType, void >::value >::Type ConditionalInternalInitialization(TImageType *)
Definition: sitkImage.h:455
::uint8_t uint8_t
Image(itk::SmartPointer< TImageType > image)
Construct an SimpleITK Image from an pointer to an ITK image.
Definition: sitkImage.h:106
::uint16_t uint16_t
Image(TImageType *image)
Construct an SimpleITK Image from an pointer to an ITK image.
Definition: sitkImage.h:114
#define SITKCommon_EXPORT
Definition: sitkCommon.h:41
::uint32_t uint32_t
The main Image class for SimpleITK.
Definition: sitkImage.h:54
::detail::FunctionTraits< TMemberFunctionPointer >::ClassType ObjectType
Definition: sitkImage.h:464
Private implementation idiom image base class.
#define sitkStaticAssert(expr, str)
Definition: sitkMacro.h:115
::int64_t int64_t
::int8_t int8_t
::int32_t int32_t
::uint64_t uint64_t
::int16_t int16_t