SimpleITK  2.2.0.dev41
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 
199  unsigned int GetNumberOfComponentsPerPixel( ) const;
200 
209  uint64_t GetNumberOfPixels( ) const;
210 
215  unsigned int GetSizeOfPixelComponent( ) const;
216 
220  std::vector< double > GetOrigin( ) const;
221  void SetOrigin( const std::vector< double > &origin );
230  std::vector< double > GetSpacing( ) const;
231  void SetSpacing( const std::vector< double > &spacing );
241  std::vector< double > GetDirection() const;
242  void SetDirection ( const std::vector< double > &direction );
246  std::vector< double > TransformIndexToPhysicalPoint( const std::vector< int64_t > &index ) const;
247 
249  std::vector< int64_t > TransformPhysicalPointToIndex( const std::vector< double >& point ) const;
250 
252  std::vector< double > TransformPhysicalPointToContinuousIndex( const std::vector< double >& point ) const;
253 
255  std::vector< double > TransformContinuousIndexToPhysicalPoint( const std::vector< double > &index) const;
256 
260  std::vector< unsigned int > GetSize( ) const;
261 
263  unsigned int GetWidth( ) const;
264 
266  unsigned int GetHeight( ) const;
267 
270  unsigned int GetDepth( ) const;
271 
272 
283  void CopyInformation( const Image &srcImage );
284 
291  std::vector<std::string> GetMetaDataKeys( ) const;
292 
295  bool HasMetaDataKey( const std::string &key ) const;
296 
305  std::string GetMetaData( const std::string &key ) const;
306 
311  void SetMetaData( const std::string &key, const std::string &value);
312 
318  bool EraseMetaData( const std::string &key );
319 
320  std::string ToString( ) const;
321 
337  int8_t GetPixelAsInt8( const std::vector<uint32_t> &idx) const;
338  uint8_t GetPixelAsUInt8( const std::vector<uint32_t> &idx) const;
339  int16_t GetPixelAsInt16( const std::vector<uint32_t> &idx ) const;
340  uint16_t GetPixelAsUInt16( const std::vector<uint32_t> &idx ) const;
341  int32_t GetPixelAsInt32( const std::vector<uint32_t> &idx ) const;
342  uint32_t GetPixelAsUInt32( const std::vector<uint32_t> &idx ) const;
343  int64_t GetPixelAsInt64( const std::vector<uint32_t> &idx ) const;
344  uint64_t GetPixelAsUInt64( const std::vector<uint32_t> &idx ) const;
345  float GetPixelAsFloat( const std::vector<uint32_t> &idx ) const;
346  double GetPixelAsDouble( const std::vector<uint32_t> &idx ) const;
347 
348  std::vector<int8_t> GetPixelAsVectorInt8( const std::vector<uint32_t> &idx) const;
349  std::vector<uint8_t> GetPixelAsVectorUInt8( const std::vector<uint32_t> &idx) const;
350  std::vector<int16_t> GetPixelAsVectorInt16( const std::vector<uint32_t> &idx ) const;
351  std::vector<uint16_t> GetPixelAsVectorUInt16( const std::vector<uint32_t> &idx ) const;
352  std::vector<int32_t> GetPixelAsVectorInt32( const std::vector<uint32_t> &idx ) const;
353  std::vector<uint32_t> GetPixelAsVectorUInt32( const std::vector<uint32_t> &idx ) const;
354  std::vector<int64_t> GetPixelAsVectorInt64( const std::vector<uint32_t> &idx ) const;
355  std::vector<uint64_t> GetPixelAsVectorUInt64( const std::vector<uint32_t> &idx ) const;
356  std::vector<float> GetPixelAsVectorFloat32( const std::vector<uint32_t> &idx ) const;
357  std::vector<double> GetPixelAsVectorFloat64( const std::vector<uint32_t> &idx ) const;
358 
359  std::complex<float> GetPixelAsComplexFloat32( const std::vector<uint32_t> &idx ) const;
360  std::complex<double> GetPixelAsComplexFloat64( const std::vector<uint32_t> &idx ) const;
379  void SetPixelAsInt8( const std::vector<uint32_t> &idx, int8_t v );
380  void SetPixelAsUInt8( const std::vector<uint32_t> &idx, uint8_t v );
381  void SetPixelAsInt16( const std::vector<uint32_t> &idx, int16_t v );
382  void SetPixelAsUInt16( const std::vector<uint32_t> &idx, uint16_t v );
383  void SetPixelAsInt32( const std::vector<uint32_t> &idx, int32_t v );
384  void SetPixelAsUInt32( const std::vector<uint32_t> &idx, uint32_t v );
385  void SetPixelAsInt64( const std::vector<uint32_t> &idx, int64_t v );
386  void SetPixelAsUInt64( const std::vector<uint32_t> &idx, uint64_t v );
387  void SetPixelAsFloat( const std::vector<uint32_t> &idx, float v );
388  void SetPixelAsDouble( const std::vector<uint32_t> &idx, double v );
389 
390  void SetPixelAsVectorInt8( const std::vector<uint32_t> &idx, const std::vector<int8_t> &v );
391  void SetPixelAsVectorUInt8( const std::vector<uint32_t> &idx, const std::vector<uint8_t> &v );
392  void SetPixelAsVectorInt16( const std::vector<uint32_t> &idx, const std::vector<int16_t> &v );
393  void SetPixelAsVectorUInt16( const std::vector<uint32_t> &idx, const std::vector<uint16_t> &v );
394  void SetPixelAsVectorInt32( const std::vector<uint32_t> &idx, const std::vector<int32_t> &v );
395  void SetPixelAsVectorUInt32( const std::vector<uint32_t> &idx, const std::vector<uint32_t> &v );
396  void SetPixelAsVectorInt64( const std::vector<uint32_t> &idx, const std::vector<int64_t> &v );
397  void SetPixelAsVectorUInt64( const std::vector<uint32_t> &idx, const std::vector<uint64_t> &v );
398  void SetPixelAsVectorFloat32( const std::vector<uint32_t> &idx, const std::vector<float> &v );
399  void SetPixelAsVectorFloat64( const std::vector<uint32_t> &idx, const std::vector<double> &v );
400 
401  void SetPixelAsComplexFloat32( const std::vector<uint32_t> &idx, const std::complex<float> v );
402  void SetPixelAsComplexFloat64( const std::vector<uint32_t> &idx, const std::complex<double> v );
403 
432  int8_t *GetBufferAsInt8( );
433  uint8_t *GetBufferAsUInt8( );
434  int16_t *GetBufferAsInt16( );
435  uint16_t *GetBufferAsUInt16( );
436  int32_t *GetBufferAsInt32( );
437  uint32_t *GetBufferAsUInt32( );
438  int64_t *GetBufferAsInt64( );
439  uint64_t *GetBufferAsUInt64( );
440  float *GetBufferAsFloat( );
441  double *GetBufferAsDouble( );
442  void *GetBufferAsVoid();
443 
444  const int8_t *GetBufferAsInt8( ) const;
445  const uint8_t *GetBufferAsUInt8( ) const;
446  const int16_t *GetBufferAsInt16( ) const;
447  const uint16_t *GetBufferAsUInt16( ) const;
448  const int32_t *GetBufferAsInt32( ) const;
449  const uint32_t *GetBufferAsUInt32( ) const;
450  const int64_t *GetBufferAsInt64( ) const;
451  const uint64_t *GetBufferAsUInt64( ) const;
452  const float *GetBufferAsFloat( ) const;
453  const double *GetBufferAsDouble( ) const;
454  const void *GetBufferAsVoid() const;
464  void MakeUnique( );
465 
468  bool IsUnique( ) const;
469 
470  protected:
471 
478  void Allocate ( const std::vector<unsigned int > &size, PixelIDValueEnum valueEnum, unsigned int numberOfComponents );
479 
487  template<class TImageType>
488  typename std::enable_if<IsBasic<TImageType>::Value>::type
489  AllocateInternal ( const std::vector<unsigned int > &size, unsigned int numberOfComponents );
490 
491  template<class TImageType>
492  typename std::enable_if<IsVector<TImageType>::Value>::type
493  AllocateInternal ( const std::vector<unsigned int > &size, unsigned int numberOfComponents );
494 
495  template<class TImageType>
496  typename std::enable_if<IsLabel<TImageType>::Value>::type
497  AllocateInternal ( const std::vector<unsigned int > &size, unsigned int numberOfComponents );
501  private:
502 
511  template <int VPixelIDValue, unsigned int VImageDimension>
512  void InternalInitialization( typename PixelIDToImageType<typename typelist::TypeAt<InstantiatedPixelIDTypeList,
513  VPixelIDValue>::Result,
514  VImageDimension>::ImageType *i );
515 
523  template<int VPixelIDValue, typename TImageType>
524  typename std::enable_if<!std::is_same<TImageType, void>::value>::type
525  ConditionalInternalInitialization( TImageType *i);
526 
527  template<int VPixelIDValue, typename TImageType>
528  typename std::enable_if<std::is_same<TImageType, void>::value>::type
529  ConditionalInternalInitialization( TImageType *) { assert( false ); }
535  template < class TMemberFunctionPointer >
537  {
538  using ObjectType = typename ::detail::FunctionTraits<TMemberFunctionPointer>::ClassType;
539 
540  template< typename TImageType >
541  TMemberFunctionPointer operator() ( ) const
542  {
543  return &ObjectType::template AllocateInternal< TImageType >;
544  }
545  };
546 
548  };
549 
550 }
551 }
552 
553 #endif
itk::simple::Image
The Image class for SimpleITK.
Definition: sitkImage.h:75
itk::uint64_t
std::uint64_t uint64_t
sitkTemplateFunctions.h
itk::simple::PimpleImageBase
Private implementation idiom image base class.
Definition: sitkPimpleImageBase.h:40
sitkCommon.h
itk::uint32_t
std::uint32_t uint32_t
itk::SmartPointer
Definition: sitkImage.h:37
itk::simple::PixelIDValueEnum
PixelIDValueEnum
Enumerated values of pixelIDs.
Definition: sitkPixelIDValues.h:90
itk::simple::ImageTypeToPixelIDValue
Definition: sitkPixelIDValues.h:41
itk::simple::Image::AllocateMemberFunctionAddressor::ObjectType
typename ::detail::FunctionTraits< TMemberFunctionPointer >::ClassType ObjectType
Definition: sitkImage.h:538
sitkDetail.h
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::int64_t
std::int64_t int64_t
itk::int8_t
std::int8_t int8_t
itk::simple::Image::AllocateMemberFunctionAddressor
Definition: sitkImage.h:536
itk::DataObject
class ITK_FORWARD_EXPORT DataObject
itk::uint8_t
std::uint8_t uint8_t
itk::simple::InstantiatedPixelIDTypeList
AllPixelIDTypeList InstantiatedPixelIDTypeList
Definition: sitkPixelIDTypeLists.h:210
itk::simple::Image::ConditionalInternalInitialization
std::enable_if< std::is_same< TImageType, void >::value >::type ConditionalInternalInitialization(TImageType *)
Definition: sitkImage.h:529
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
std::uint16_t uint16_t
itk::int32_t
std::int32_t int32_t
itk::simple::sitkUnknown
@ sitkUnknown
Definition: sitkPixelIDValues.h:91
itk::simple::Image::m_PimpleImage
PimpleImageBase * m_PimpleImage
Definition: sitkImage.h:547
itk::simple::PixelIDValueType
int PixelIDValueType
Definition: sitkPixelIDValues.h:32
itk::DataObject
itk::int16_t
std::int16_t int16_t