SimpleITK  2.0.0
sitkImage.h
Go to the documentation of this file.
1 /*=========================================================================
2 *
3 * Copyright NumFOCUS
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 
26 #include <vector>
27 #include <memory>
28 #include <type_traits>
29 
30 namespace itk
31 {
32 
33 // Forward declaration for pointer
34 class DataObject;
35 
36 template<class T>
37 class SmartPointer;
38 
39 namespace simple
40 {
41 
42  // This is the forward declaration of a class used internally to the
43  // Image class, but the actually interface is not exposed to simple
44  // ITK. A pointer to the implementation is used as per the pimple
45  // idiom.
46  class PimpleImageBase;
47 
76  {
77  public:
78  using Self = Image;
79 
80  virtual ~Image( );
81 
83  Image( );
84 
85  // copy constructor
86  Image( const Image &img );
87 
88  Image& operator=( const Image &img );
89 
90 #ifndef SWIG
91 
97  Image( Image &&img ) noexcept;
98  Image& operator=( Image &&img ) noexcept;
99 #endif
100 
101 
117  Image( unsigned int width, unsigned int height, PixelIDValueEnum valueEnum );
118  Image( unsigned int width, unsigned int height, unsigned int depth, PixelIDValueEnum valueEnum );
119  Image( const std::vector< unsigned int > &size, PixelIDValueEnum valueEnum, unsigned int numberOfComponents = 0 );
139  template <typename TImageType>
141  : Image( image.GetPointer() )
142  {}
143 
144  template <typename TImageType>
145  explicit Image( TImageType* image )
146  : m_PimpleImage( nullptr )
147  {
149  "invalid pixel type" );
150  this->InternalInitialization<ImageTypeToPixelIDValue<TImageType>::Result, TImageType::ImageDimension>( image );
151  }
168  itk::DataObject* GetITKBase( );
169  const itk::DataObject* GetITKBase( ) const;
178  PixelIDValueEnum GetPixelID( ) const;
179  PixelIDValueType GetPixelIDValue( ) const;
180 
182  std::string GetPixelIDTypeAsString( ) const;
183 
191  unsigned int GetDimension( ) const;
192 
198  unsigned int GetNumberOfComponentsPerPixel( ) const;
199 
208  uint64_t GetNumberOfPixels( ) const;
209 
213  std::vector< double > GetOrigin( ) const;
214  void SetOrigin( const std::vector< double > &origin );
223  std::vector< double > GetSpacing( ) const;
224  void SetSpacing( const std::vector< double > &spacing );
234  std::vector< double > GetDirection() const;
235  void SetDirection ( const std::vector< double > &direction );
239  std::vector< double > TransformIndexToPhysicalPoint( const std::vector< int64_t > &index ) const;
240 
242  std::vector< int64_t > TransformPhysicalPointToIndex( const std::vector< double >& point ) const;
243 
245  std::vector< double > TransformPhysicalPointToContinuousIndex( const std::vector< double >& point ) const;
246 
248  std::vector< double > TransformContinuousIndexToPhysicalPoint( const std::vector< double > &index) const;
249 
253  std::vector< unsigned int > GetSize( ) const;
254 
256  unsigned int GetWidth( ) const;
257 
259  unsigned int GetHeight( ) const;
260 
263  unsigned int GetDepth( ) const;
264 
265 
276  void CopyInformation( const Image &srcImage );
277 
284  std::vector<std::string> GetMetaDataKeys( ) const;
285 
288  bool HasMetaDataKey( const std::string &key ) const;
289 
298  std::string GetMetaData( const std::string &key ) const;
299 
304  void SetMetaData( const std::string &key, const std::string &value);
305 
311  bool EraseMetaData( const std::string &key );
312 
313  std::string ToString( ) const;
314 
330  int8_t GetPixelAsInt8( const std::vector<uint32_t> &idx) const;
331  uint8_t GetPixelAsUInt8( const std::vector<uint32_t> &idx) const;
332  int16_t GetPixelAsInt16( const std::vector<uint32_t> &idx ) const;
333  uint16_t GetPixelAsUInt16( const std::vector<uint32_t> &idx ) const;
334  int32_t GetPixelAsInt32( const std::vector<uint32_t> &idx ) const;
335  uint32_t GetPixelAsUInt32( const std::vector<uint32_t> &idx ) const;
336  int64_t GetPixelAsInt64( const std::vector<uint32_t> &idx ) const;
337  uint64_t GetPixelAsUInt64( const std::vector<uint32_t> &idx ) const;
338  float GetPixelAsFloat( const std::vector<uint32_t> &idx ) const;
339  double GetPixelAsDouble( const std::vector<uint32_t> &idx ) const;
340 
341  std::vector<int8_t> GetPixelAsVectorInt8( const std::vector<uint32_t> &idx) const;
342  std::vector<uint8_t> GetPixelAsVectorUInt8( const std::vector<uint32_t> &idx) const;
343  std::vector<int16_t> GetPixelAsVectorInt16( const std::vector<uint32_t> &idx ) const;
344  std::vector<uint16_t> GetPixelAsVectorUInt16( const std::vector<uint32_t> &idx ) const;
345  std::vector<int32_t> GetPixelAsVectorInt32( const std::vector<uint32_t> &idx ) const;
346  std::vector<uint32_t> GetPixelAsVectorUInt32( const std::vector<uint32_t> &idx ) const;
347  std::vector<int64_t> GetPixelAsVectorInt64( const std::vector<uint32_t> &idx ) const;
348  std::vector<uint64_t> GetPixelAsVectorUInt64( const std::vector<uint32_t> &idx ) const;
349  std::vector<float> GetPixelAsVectorFloat32( const std::vector<uint32_t> &idx ) const;
350  std::vector<double> GetPixelAsVectorFloat64( const std::vector<uint32_t> &idx ) const;
351 
352  std::complex<float> GetPixelAsComplexFloat32( const std::vector<uint32_t> &idx ) const;
353  std::complex<double> GetPixelAsComplexFloat64( const std::vector<uint32_t> &idx ) const;
372  void SetPixelAsInt8( const std::vector<uint32_t> &idx, int8_t v );
373  void SetPixelAsUInt8( const std::vector<uint32_t> &idx, uint8_t v );
374  void SetPixelAsInt16( const std::vector<uint32_t> &idx, int16_t v );
375  void SetPixelAsUInt16( const std::vector<uint32_t> &idx, uint16_t v );
376  void SetPixelAsInt32( const std::vector<uint32_t> &idx, int32_t v );
377  void SetPixelAsUInt32( const std::vector<uint32_t> &idx, uint32_t v );
378  void SetPixelAsInt64( const std::vector<uint32_t> &idx, int64_t v );
379  void SetPixelAsUInt64( const std::vector<uint32_t> &idx, uint64_t v );
380  void SetPixelAsFloat( const std::vector<uint32_t> &idx, float v );
381  void SetPixelAsDouble( const std::vector<uint32_t> &idx, double v );
382 
383  void SetPixelAsVectorInt8( const std::vector<uint32_t> &idx, const std::vector<int8_t> &v );
384  void SetPixelAsVectorUInt8( const std::vector<uint32_t> &idx, const std::vector<uint8_t> &v );
385  void SetPixelAsVectorInt16( const std::vector<uint32_t> &idx, const std::vector<int16_t> &v );
386  void SetPixelAsVectorUInt16( const std::vector<uint32_t> &idx, const std::vector<uint16_t> &v );
387  void SetPixelAsVectorInt32( const std::vector<uint32_t> &idx, const std::vector<int32_t> &v );
388  void SetPixelAsVectorUInt32( const std::vector<uint32_t> &idx, const std::vector<uint32_t> &v );
389  void SetPixelAsVectorInt64( const std::vector<uint32_t> &idx, const std::vector<int64_t> &v );
390  void SetPixelAsVectorUInt64( const std::vector<uint32_t> &idx, const std::vector<uint64_t> &v );
391  void SetPixelAsVectorFloat32( const std::vector<uint32_t> &idx, const std::vector<float> &v );
392  void SetPixelAsVectorFloat64( const std::vector<uint32_t> &idx, const std::vector<double> &v );
393 
394  void SetPixelAsComplexFloat32( const std::vector<uint32_t> &idx, const std::complex<float> v );
395  void SetPixelAsComplexFloat64( const std::vector<uint32_t> &idx, const std::complex<double> v );
396 
425  int8_t *GetBufferAsInt8( );
426  uint8_t *GetBufferAsUInt8( );
427  int16_t *GetBufferAsInt16( );
428  uint16_t *GetBufferAsUInt16( );
429  int32_t *GetBufferAsInt32( );
430  uint32_t *GetBufferAsUInt32( );
431  int64_t *GetBufferAsInt64( );
432  uint64_t *GetBufferAsUInt64( );
433  float *GetBufferAsFloat( );
434  double *GetBufferAsDouble( );
435  void *GetBufferAsVoid();
436 
437  const int8_t *GetBufferAsInt8( ) const;
438  const uint8_t *GetBufferAsUInt8( ) const;
439  const int16_t *GetBufferAsInt16( ) const;
440  const uint16_t *GetBufferAsUInt16( ) const;
441  const int32_t *GetBufferAsInt32( ) const;
442  const uint32_t *GetBufferAsUInt32( ) const;
443  const int64_t *GetBufferAsInt64( ) const;
444  const uint64_t *GetBufferAsUInt64( ) const;
445  const float *GetBufferAsFloat( ) const;
446  const double *GetBufferAsDouble( ) const;
447  const void *GetBufferAsVoid() const;
457  void MakeUnique( );
458 
461  bool IsUnique( ) const;
462 
463  protected:
464 
471  void Allocate ( const std::vector<unsigned int > &size, PixelIDValueEnum valueEnum, unsigned int numberOfComponents );
472 
480  template<class TImageType>
481  typename std::enable_if<IsBasic<TImageType>::Value>::type
482  AllocateInternal ( const std::vector<unsigned int > &size, unsigned int numberOfComponents );
483 
484  template<class TImageType>
485  typename std::enable_if<IsVector<TImageType>::Value>::type
486  AllocateInternal ( const std::vector<unsigned int > &size, unsigned int numberOfComponents );
487 
488  template<class TImageType>
489  typename std::enable_if<IsLabel<TImageType>::Value>::type
490  AllocateInternal ( const std::vector<unsigned int > &size, unsigned int numberOfComponents );
494  private:
495 
504  template <int VPixelIDValue, unsigned int VImageDimension>
505  void InternalInitialization( typename PixelIDToImageType<typename typelist::TypeAt<InstantiatedPixelIDTypeList,
506  VPixelIDValue>::Result,
507  VImageDimension>::ImageType *i );
508 
516  template<int VPixelIDValue, typename TImageType>
517  typename std::enable_if<!std::is_same<TImageType, void>::value>::type
518  ConditionalInternalInitialization( TImageType *i);
519 
520  template<int VPixelIDValue, typename TImageType>
521  typename std::enable_if<std::is_same<TImageType, void>::value>::type
522  ConditionalInternalInitialization( TImageType *) { assert( false ); }
528  template < class TMemberFunctionPointer >
530  {
531  using ObjectType = typename ::detail::FunctionTraits<TMemberFunctionPointer>::ClassType;
532 
533  template< typename TImageType >
534  TMemberFunctionPointer operator() ( ) const
535  {
536  return &ObjectType::template AllocateInternal< TImageType >;
537  }
538  };
539 
541  };
542 
543 }
544 }
545 
546 #endif
itk::simple::Image
The Image class for SimpleITK.
Definition: sitkImage.h:75
itk::uint8_t
::uint8_t uint8_t
itk::int16_t
::int16_t int16_t
sitkTemplateFunctions.h
itk::int8_t
::int8_t int8_t
itk::simple::PimpleImageBase
Private implementation idiom image base class.
Definition: sitkPimpleImageBase.h:40
sitkCommon.h
itk::SmartPointer
Definition: sitkImage.h:37
itk::simple::PixelIDValueEnum
PixelIDValueEnum
Enumerated values of pixelIDs.
Definition: sitkPixelIDValues.h:90
itk::int64_t
::int64_t int64_t
itk::simple::ImageTypeToPixelIDValue
Definition: sitkPixelIDValues.h:41
itk::simple::Image::AllocateMemberFunctionAddressor::ObjectType
typename ::detail::FunctionTraits< TMemberFunctionPointer >::ClassType ObjectType
Definition: sitkImage.h:531
sitkDetail.h
itk::uint64_t
::uint64_t uint64_t
itk::simple::Image::Image
Image(itk::SmartPointer< TImageType > image)
Construct an SimpleITK Image from an pointer to an ITK image.
Definition: sitkImage.h:140
SITKCommon_EXPORT
#define SITKCommon_EXPORT
Definition: sitkCommon.h:41
itk::simple::Image::AllocateMemberFunctionAddressor
Definition: sitkImage.h:529
itk::DataObject
class ITK_FORWARD_EXPORT DataObject
itk::simple::InstantiatedPixelIDTypeList
AllPixelIDTypeList InstantiatedPixelIDTypeList
Definition: sitkPixelIDTypeLists.h:207
itk::simple::Image::ConditionalInternalInitialization
std::enable_if< std::is_same< TImageType, void >::value >::type ConditionalInternalInitialization(TImageType *)
Definition: sitkImage.h:522
itk::simple::Image::Image
Image(TImageType *image)
Construct an SimpleITK Image from an pointer to an ITK image.
Definition: sitkImage.h:145
itk::simple::PixelIDToImageType
Definition: sitkPixelIDTypes.h:100
sitkPixelIDTokens.h
itk
itk::uint16_t
::uint16_t uint16_t
itk::int32_t
::int32_t int32_t
itk::uint32_t
::uint32_t uint32_t
itk::simple::sitkUnknown
@ sitkUnknown
Definition: sitkPixelIDValues.h:91
itk::simple::Image::m_PimpleImage
PimpleImageBase * m_PimpleImage
Definition: sitkImage.h:540
itk::simple::PixelIDValueType
int PixelIDValueType
Definition: sitkPixelIDValues.h:32
itk::DataObject