SimpleITK  
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 #include "sitkInterpolator.h"
26 
27 #include <vector>
28 #include <memory>
29 #include <type_traits>
30 
31 namespace itk
32 {
33 
34 // Forward declaration for pointer
35 class DataObject;
36 
37 template<class T>
38 class SmartPointer;
39 
40 namespace simple
41 {
42 
43  // This is the forward declaration of a class used internally to the
44  // Image class, but the actual interface is not exposed to simple
45  // ITK. A pointer to the implementation is used as per the pimple
46  // idiom.
47  class PimpleImageBase;
48 
77  {
78  public:
79  using Self = Image;
80 
81  virtual ~Image( );
82 
84  Image( );
85 
86  // copy constructor
87  Image( const Image &img );
88 
89  Image& operator=( const Image &img );
90 
91 #ifndef SWIG
92 
98  Image( Image &&img ) noexcept;
99  Image& operator=( Image &&img ) noexcept;
100 #endif
101 
102 
118  Image( unsigned int width, unsigned int height, PixelIDValueEnum valueEnum );
119  Image( unsigned int width, unsigned int height, unsigned int depth, PixelIDValueEnum valueEnum );
120  Image( const std::vector< unsigned int > &size, PixelIDValueEnum valueEnum, unsigned int numberOfComponents = 0 );
140  template <typename TImageType>
142  : Image( image.GetPointer() )
143  {}
144 
145  template <typename TImageType>
146  explicit Image( TImageType* image )
147  : m_PimpleImage( Self::DispatchedInternalInitialization<TImageType>(image) )
148  {
150  const unsigned int dimension = TImageType::ImageDimension;
151 
152  static_assert(type != sitkUnknown, "invalid pixel type");
153  static_assert(dimension >= 2 && dimension <= SITK_MAX_DIMENSION, "Unsupported image dimension.");
154 
155  //this->InternalInitialization(type, dimension, image);
156  }
173  itk::DataObject* GetITKBase( );
174  const itk::DataObject* GetITKBase( ) const;
183  PixelIDValueEnum GetPixelID( ) const;
184  PixelIDValueType GetPixelIDValue( ) const;
185 
187  std::string GetPixelIDTypeAsString( ) const;
188 
196  unsigned int GetDimension( ) const;
197 
204  unsigned int GetNumberOfComponentsPerPixel( ) const;
205 
214  uint64_t GetNumberOfPixels( ) const;
215 
220  unsigned int GetSizeOfPixelComponent( ) const;
221 
225  std::vector< double > GetOrigin( ) const;
226  void SetOrigin( const std::vector< double > &origin );
235  std::vector< double > GetSpacing( ) const;
236  void SetSpacing( const std::vector< double > &spacing );
246  std::vector< double > GetDirection() const;
247  void SetDirection ( const std::vector< double > &direction );
251  std::vector< double > TransformIndexToPhysicalPoint( const std::vector< int64_t > &index ) const;
252 
254  std::vector< int64_t > TransformPhysicalPointToIndex( const std::vector< double >& point ) const;
255 
257  std::vector< double > TransformPhysicalPointToContinuousIndex( const std::vector< double >& point ) const;
258 
260  std::vector< double > TransformContinuousIndexToPhysicalPoint( const std::vector< double > &index) const;
261 
273  std::vector<double> EvaluateAtContinuousIndex( const std::vector<double> &index, InterpolatorEnum interp = sitkLinear) const;
274 
286  std::vector<double> EvaluateAtPhysicalPoint( const std::vector<double> &point, InterpolatorEnum interp = sitkLinear) const;
287 
291  std::vector< unsigned int > GetSize( ) const;
292 
294  unsigned int GetWidth( ) const;
295 
297  unsigned int GetHeight( ) const;
298 
301  unsigned int GetDepth( ) const;
302 
303 
314  void CopyInformation( const Image &srcImage );
315 
322  std::vector<std::string> GetMetaDataKeys( ) const;
323 
326  bool HasMetaDataKey( const std::string &key ) const;
327 
336  std::string GetMetaData( const std::string &key ) const;
337 
342  void SetMetaData( const std::string &key, const std::string &value);
343 
349  bool EraseMetaData( const std::string &key );
350 
351  std::string ToString( ) const;
352 
368  int8_t GetPixelAsInt8( const std::vector<uint32_t> &idx) const;
369  uint8_t GetPixelAsUInt8( const std::vector<uint32_t> &idx) const;
370  int16_t GetPixelAsInt16( const std::vector<uint32_t> &idx ) const;
371  uint16_t GetPixelAsUInt16( const std::vector<uint32_t> &idx ) const;
372  int32_t GetPixelAsInt32( const std::vector<uint32_t> &idx ) const;
373  uint32_t GetPixelAsUInt32( const std::vector<uint32_t> &idx ) const;
374  int64_t GetPixelAsInt64( const std::vector<uint32_t> &idx ) const;
375  uint64_t GetPixelAsUInt64( const std::vector<uint32_t> &idx ) const;
376  float GetPixelAsFloat( const std::vector<uint32_t> &idx ) const;
377  double GetPixelAsDouble( const std::vector<uint32_t> &idx ) const;
378 
379  std::vector<int8_t> GetPixelAsVectorInt8( const std::vector<uint32_t> &idx) const;
380  std::vector<uint8_t> GetPixelAsVectorUInt8( const std::vector<uint32_t> &idx) const;
381  std::vector<int16_t> GetPixelAsVectorInt16( const std::vector<uint32_t> &idx ) const;
382  std::vector<uint16_t> GetPixelAsVectorUInt16( const std::vector<uint32_t> &idx ) const;
383  std::vector<int32_t> GetPixelAsVectorInt32( const std::vector<uint32_t> &idx ) const;
384  std::vector<uint32_t> GetPixelAsVectorUInt32( const std::vector<uint32_t> &idx ) const;
385  std::vector<int64_t> GetPixelAsVectorInt64( const std::vector<uint32_t> &idx ) const;
386  std::vector<uint64_t> GetPixelAsVectorUInt64( const std::vector<uint32_t> &idx ) const;
387  std::vector<float> GetPixelAsVectorFloat32( const std::vector<uint32_t> &idx ) const;
388  std::vector<double> GetPixelAsVectorFloat64( const std::vector<uint32_t> &idx ) const;
389 
390  std::complex<float> GetPixelAsComplexFloat32( const std::vector<uint32_t> &idx ) const;
391  std::complex<double> GetPixelAsComplexFloat64( const std::vector<uint32_t> &idx ) const;
410  void SetPixelAsInt8( const std::vector<uint32_t> &idx, int8_t v );
411  void SetPixelAsUInt8( const std::vector<uint32_t> &idx, uint8_t v );
412  void SetPixelAsInt16( const std::vector<uint32_t> &idx, int16_t v );
413  void SetPixelAsUInt16( const std::vector<uint32_t> &idx, uint16_t v );
414  void SetPixelAsInt32( const std::vector<uint32_t> &idx, int32_t v );
415  void SetPixelAsUInt32( const std::vector<uint32_t> &idx, uint32_t v );
416  void SetPixelAsInt64( const std::vector<uint32_t> &idx, int64_t v );
417  void SetPixelAsUInt64( const std::vector<uint32_t> &idx, uint64_t v );
418  void SetPixelAsFloat( const std::vector<uint32_t> &idx, float v );
419  void SetPixelAsDouble( const std::vector<uint32_t> &idx, double v );
420 
421  void SetPixelAsVectorInt8( const std::vector<uint32_t> &idx, const std::vector<int8_t> &v );
422  void SetPixelAsVectorUInt8( const std::vector<uint32_t> &idx, const std::vector<uint8_t> &v );
423  void SetPixelAsVectorInt16( const std::vector<uint32_t> &idx, const std::vector<int16_t> &v );
424  void SetPixelAsVectorUInt16( const std::vector<uint32_t> &idx, const std::vector<uint16_t> &v );
425  void SetPixelAsVectorInt32( const std::vector<uint32_t> &idx, const std::vector<int32_t> &v );
426  void SetPixelAsVectorUInt32( const std::vector<uint32_t> &idx, const std::vector<uint32_t> &v );
427  void SetPixelAsVectorInt64( const std::vector<uint32_t> &idx, const std::vector<int64_t> &v );
428  void SetPixelAsVectorUInt64( const std::vector<uint32_t> &idx, const std::vector<uint64_t> &v );
429  void SetPixelAsVectorFloat32( const std::vector<uint32_t> &idx, const std::vector<float> &v );
430  void SetPixelAsVectorFloat64( const std::vector<uint32_t> &idx, const std::vector<double> &v );
431 
432  void SetPixelAsComplexFloat32( const std::vector<uint32_t> &idx, const std::complex<float> v );
433  void SetPixelAsComplexFloat64( const std::vector<uint32_t> &idx, const std::complex<double> v );
434 
463  int8_t *GetBufferAsInt8( );
464  uint8_t *GetBufferAsUInt8( );
465  int16_t *GetBufferAsInt16( );
466  uint16_t *GetBufferAsUInt16( );
467  int32_t *GetBufferAsInt32( );
468  uint32_t *GetBufferAsUInt32( );
469  int64_t *GetBufferAsInt64( );
470  uint64_t *GetBufferAsUInt64( );
471  float *GetBufferAsFloat( );
472  double *GetBufferAsDouble( );
473  void *GetBufferAsVoid();
474 
475  const int8_t *GetBufferAsInt8( ) const;
476  const uint8_t *GetBufferAsUInt8( ) const;
477  const int16_t *GetBufferAsInt16( ) const;
478  const uint16_t *GetBufferAsUInt16( ) const;
479  const int32_t *GetBufferAsInt32( ) const;
480  const uint32_t *GetBufferAsUInt32( ) const;
481  const int64_t *GetBufferAsInt64( ) const;
482  const uint64_t *GetBufferAsUInt64( ) const;
483  const float *GetBufferAsFloat( ) const;
484  const double *GetBufferAsDouble( ) const;
485  const void *GetBufferAsVoid() const;
495  void MakeUnique( );
496 
499  bool IsUnique( ) const;
500 
501  protected:
502 
509  void Allocate ( const std::vector<unsigned int > &size, PixelIDValueEnum valueEnum, unsigned int numberOfComponents );
510 
518  template<class TImageType>
519  typename std::enable_if<IsBasic<TImageType>::Value>::type
520  AllocateInternal ( const std::vector<unsigned int > &size, unsigned int numberOfComponents );
521 
522  template<class TImageType>
523  typename std::enable_if<IsVector<TImageType>::Value>::type
524  AllocateInternal ( const std::vector<unsigned int > &size, unsigned int numberOfComponents );
525 
526  template<class TImageType>
527  typename std::enable_if<IsLabel<TImageType>::Value>::type
528  AllocateInternal ( const std::vector<unsigned int > &size, unsigned int numberOfComponents );
532  private:
533 
542  void InternalInitialization( PixelIDValueType type, unsigned int dimension, itk::DataObject *image );
543 
544  template <typename TImageType>
545  PimpleImageBase * DispatchedInternalInitialization(itk::DataObject *image);
546 
547 
548  friend struct DispatchedInternalInitialiationAddressor;
549  friend struct AllocateMemberFunctionAddressor;
550 
551 
553  };
554 
555 }
556 }
557 
558 #endif
itk::simple::Image
The Image class for SimpleITK.
Definition: sitkImage.h:76
itk::uint64_t
std::uint64_t uint64_t
itk::simple::sitkLinear
@ sitkLinear
N-D linear interpolation.
Definition: sitkInterpolator.h:39
itk::simple::InterpolatorEnum
InterpolatorEnum
Definition: sitkInterpolator.h:30
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:38
itk::simple::PixelIDValueEnum
PixelIDValueEnum
Enumerated values of pixelIDs.
Definition: sitkPixelIDValues.h:93
itk::simple::ImageTypeToPixelIDValue
Definition: sitkPixelIDValues.h:42
sitkDetail.h
SITK_MAX_DIMENSION
#define SITK_MAX_DIMENSION
Definition: sitkConfigure.h:30
itk::simple::Image::Image
Image(itk::SmartPointer< TImageType > image)
Construct an SimpleITK Image from an pointer to an ITK image.
Definition: sitkImage.h:141
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::DataObject
class ITK_FORWARD_EXPORT DataObject
itk::uint8_t
std::uint8_t uint8_t
sitkInterpolator.h
itk::simple::Image::Image
Image(TImageType *image)
Construct an SimpleITK Image from an pointer to an ITK image.
Definition: sitkImage.h:146
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:94
itk::simple::Image::m_PimpleImage
PimpleImageBase * m_PimpleImage
Definition: sitkImage.h:552
itk::simple::PixelIDValueType
int PixelIDValueType
Definition: sitkPixelIDValues.h:32
itk::DataObject
itk::int16_t
std::int16_t int16_t