SimpleITK  1.2.4
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 forward 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 
79  {
80  public:
81  typedef Image Self;
82 
83  virtual ~Image( );
84 
86  Image( void );
87 
88  // copy constructor
89  Image( const Image &img );
90  Image& operator=( const Image &img );
91 
107  Image( unsigned int width, unsigned int height, PixelIDValueEnum valueEnum );
108  Image( unsigned int width, unsigned int height, unsigned int depth, PixelIDValueEnum valueEnum );
109  Image( const std::vector< unsigned int > &size, PixelIDValueEnum valueEnum, unsigned int numberOfComponents = 0 );
129  template <typename TImageType>
131  : m_PimpleImage( SITK_NULLPTR )
132  {
134  "invalid pixel type" );
135  this->InternalInitialization<ImageTypeToPixelIDValue<TImageType>::Result, TImageType::ImageDimension>( image.GetPointer() );
136  }
137  template <typename TImageType>
138  explicit Image( TImageType* image )
139  : m_PimpleImage( SITK_NULLPTR )
140  {
142  "invalid pixel type" );
143  this->InternalInitialization<ImageTypeToPixelIDValue<TImageType>::Result, TImageType::ImageDimension>( image );
144  }
159  itk::DataObject* GetITKBase( void );
160  const itk::DataObject* GetITKBase( void ) const;
169  PixelIDValueEnum GetPixelID( void ) const;
170  PixelIDValueType GetPixelIDValue( void ) const;
171 
173  std::string GetPixelIDTypeAsString( void ) const;
174 
182  unsigned int GetDimension( void ) const;
183 
189  unsigned int GetNumberOfComponentsPerPixel( void ) const;
190 
199  uint64_t GetNumberOfPixels( void ) const;
200 
204  std::vector< double > GetOrigin( void ) const;
205  void SetOrigin( const std::vector< double > &origin );
214  std::vector< double > GetSpacing( void ) const;
215  void SetSpacing( const std::vector< double > &spacing );
225  std::vector< double > GetDirection() const;
226  void SetDirection ( const std::vector< double > &direction );
230  std::vector< double > TransformIndexToPhysicalPoint( const std::vector< int64_t > &index ) const;
231 
233  std::vector< int64_t > TransformPhysicalPointToIndex( const std::vector< double >& point ) const;
234 
236  std::vector< double > TransformPhysicalPointToContinuousIndex( const std::vector< double >& point ) const;
237 
239  std::vector< double > TransformContinuousIndexToPhysicalPoint( const std::vector< double > &index) const;
240 
244  std::vector< unsigned int > GetSize( void ) const;
245 
247  unsigned int GetWidth( void ) const;
248 
250  unsigned int GetHeight( void ) const;
251 
254  unsigned int GetDepth( void ) const;
255 
256 
267  void CopyInformation( const Image &srcImage );
268 
275  std::vector<std::string> GetMetaDataKeys( void ) const;
276 
279  bool HasMetaDataKey( const std::string &key ) const;
280 
289  std::string GetMetaData( const std::string &key ) const;
290 
295  void SetMetaData( const std::string &key, const std::string &value);
296 
302  bool EraseMetaData( const std::string &key );
303 
304  std::string ToString( void ) const;
305 
321  int8_t GetPixelAsInt8( const std::vector<uint32_t> &idx) const;
322  uint8_t GetPixelAsUInt8( const std::vector<uint32_t> &idx) const;
323  int16_t GetPixelAsInt16( const std::vector<uint32_t> &idx ) const;
324  uint16_t GetPixelAsUInt16( const std::vector<uint32_t> &idx ) const;
325  int32_t GetPixelAsInt32( const std::vector<uint32_t> &idx ) const;
326  uint32_t GetPixelAsUInt32( const std::vector<uint32_t> &idx ) const;
327  int64_t GetPixelAsInt64( const std::vector<uint32_t> &idx ) const;
328  uint64_t GetPixelAsUInt64( const std::vector<uint32_t> &idx ) const;
329  float GetPixelAsFloat( const std::vector<uint32_t> &idx ) const;
330  double GetPixelAsDouble( const std::vector<uint32_t> &idx ) const;
331 
332  std::vector<int8_t> GetPixelAsVectorInt8( const std::vector<uint32_t> &idx) const;
333  std::vector<uint8_t> GetPixelAsVectorUInt8( const std::vector<uint32_t> &idx) const;
334  std::vector<int16_t> GetPixelAsVectorInt16( const std::vector<uint32_t> &idx ) const;
335  std::vector<uint16_t> GetPixelAsVectorUInt16( const std::vector<uint32_t> &idx ) const;
336  std::vector<int32_t> GetPixelAsVectorInt32( const std::vector<uint32_t> &idx ) const;
337  std::vector<uint32_t> GetPixelAsVectorUInt32( const std::vector<uint32_t> &idx ) const;
338  std::vector<int64_t> GetPixelAsVectorInt64( const std::vector<uint32_t> &idx ) const;
339  std::vector<uint64_t> GetPixelAsVectorUInt64( const std::vector<uint32_t> &idx ) const;
340  std::vector<float> GetPixelAsVectorFloat32( const std::vector<uint32_t> &idx ) const;
341  std::vector<double> GetPixelAsVectorFloat64( const std::vector<uint32_t> &idx ) const;
342 
343  std::complex<float> GetPixelAsComplexFloat32( const std::vector<uint32_t> &idx ) const;
344  std::complex<double> GetPixelAsComplexFloat64( const std::vector<uint32_t> &idx ) const;
363  void SetPixelAsInt8( const std::vector<uint32_t> &idx, int8_t v );
364  void SetPixelAsUInt8( const std::vector<uint32_t> &idx, uint8_t v );
365  void SetPixelAsInt16( const std::vector<uint32_t> &idx, int16_t v );
366  void SetPixelAsUInt16( const std::vector<uint32_t> &idx, uint16_t v );
367  void SetPixelAsInt32( const std::vector<uint32_t> &idx, int32_t v );
368  void SetPixelAsUInt32( const std::vector<uint32_t> &idx, uint32_t v );
369  void SetPixelAsInt64( const std::vector<uint32_t> &idx, int64_t v );
370  void SetPixelAsUInt64( const std::vector<uint32_t> &idx, uint64_t v );
371  void SetPixelAsFloat( const std::vector<uint32_t> &idx, float v );
372  void SetPixelAsDouble( const std::vector<uint32_t> &idx, double v );
373 
374  void SetPixelAsVectorInt8( const std::vector<uint32_t> &idx, const std::vector<int8_t> &v );
375  void SetPixelAsVectorUInt8( const std::vector<uint32_t> &idx, const std::vector<uint8_t> &v );
376  void SetPixelAsVectorInt16( const std::vector<uint32_t> &idx, const std::vector<int16_t> &v );
377  void SetPixelAsVectorUInt16( const std::vector<uint32_t> &idx, const std::vector<uint16_t> &v );
378  void SetPixelAsVectorInt32( const std::vector<uint32_t> &idx, const std::vector<int32_t> &v );
379  void SetPixelAsVectorUInt32( const std::vector<uint32_t> &idx, const std::vector<uint32_t> &v );
380  void SetPixelAsVectorInt64( const std::vector<uint32_t> &idx, const std::vector<int64_t> &v );
381  void SetPixelAsVectorUInt64( const std::vector<uint32_t> &idx, const std::vector<uint64_t> &v );
382  void SetPixelAsVectorFloat32( const std::vector<uint32_t> &idx, const std::vector<float> &v );
383  void SetPixelAsVectorFloat64( const std::vector<uint32_t> &idx, const std::vector<double> &v );
384 
385  void SetPixelAsComplexFloat32( const std::vector<uint32_t> &idx, const std::complex<float> v );
386  void SetPixelAsComplexFloat64( const std::vector<uint32_t> &idx, const std::complex<double> v );
387 
413  int8_t *GetBufferAsInt8( );
414  uint8_t *GetBufferAsUInt8( );
415  int16_t *GetBufferAsInt16( );
416  uint16_t *GetBufferAsUInt16( );
417  int32_t *GetBufferAsInt32( );
418  uint32_t *GetBufferAsUInt32( );
419  int64_t *GetBufferAsInt64( );
420  uint64_t *GetBufferAsUInt64( );
421  float *GetBufferAsFloat( );
422  double *GetBufferAsDouble( );
423 
424  const int8_t *GetBufferAsInt8( ) const;
425  const uint8_t *GetBufferAsUInt8( ) const;
426  const int16_t *GetBufferAsInt16( ) const;
427  const uint16_t *GetBufferAsUInt16( ) const;
428  const int32_t *GetBufferAsInt32( ) const;
429  const uint32_t *GetBufferAsUInt32( ) const;
430  const int64_t *GetBufferAsInt64( ) const;
431  const uint64_t *GetBufferAsUInt64( ) const;
432  const float *GetBufferAsFloat( ) const;
433  const double *GetBufferAsDouble( ) const;
443  void MakeUnique( void );
444 
445  protected:
446 
453  void Allocate ( unsigned int width, unsigned int height, unsigned int depth, unsigned int dim4, PixelIDValueEnum valueEnum, unsigned int numberOfComponents );
454 
462  template<class TImageType>
464  AllocateInternal ( unsigned int width, unsigned int height, unsigned int depth, unsigned int dim4, unsigned int numberOfComponents );
465 
466  template<class TImageType>
468  AllocateInternal ( unsigned int width, unsigned int height, unsigned int depth, unsigned int dim4, unsigned int numberOfComponents );
469 
470  template<class TImageType>
472  AllocateInternal ( unsigned int width, unsigned int height, unsigned int depth, unsigned int dim4, unsigned int numberOfComponents );
476  private:
477 
486  template <int VPixelIDValue, unsigned int VImageDimension>
487  void InternalInitialization( typename PixelIDToImageType<typename typelist::TypeAt<InstantiatedPixelIDTypeList,
488  VPixelIDValue>::Result,
489  VImageDimension>::ImageType *i );
490 
498  template<int VPixelIDValue, typename TImageType>
500  ConditionalInternalInitialization( TImageType *i);
501 
502  template<int VPixelIDValue, typename TImageType>
504  ConditionalInternalInitialization( TImageType *) { assert( false ); }
510  template < class TMemberFunctionPointer >
512  {
513  typedef typename ::detail::FunctionTraits<TMemberFunctionPointer>::ClassType ObjectType;
514 
515  template< typename TImageType >
516  TMemberFunctionPointer operator() ( void ) const
517  {
518  return &ObjectType::template AllocateInternal< TImageType >;
519  }
520  };
521 
523  };
524 
525 }
526 }
527 
528 #endif
AllPixelIDTypeList InstantiatedPixelIDTypeList
PimpleImageBase * m_PimpleImage
Definition: sitkImage.h:522
#define SITK_NULLPTR
Definition: sitkMacro.h:110
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:504
::uint8_t uint8_t
Image(itk::SmartPointer< TImageType > image)
Construct an SimpleITK Image from an pointer to an ITK image.
Definition: sitkImage.h:130
::uint16_t uint16_t
Image(TImageType *image)
Construct an SimpleITK Image from an pointer to an ITK image.
Definition: sitkImage.h:138
#define SITKCommon_EXPORT
Definition: sitkCommon.h:41
::uint32_t uint32_t
The Image class for SimpleITK.
Definition: sitkImage.h:78
::detail::FunctionTraits< TMemberFunctionPointer >::ClassType ObjectType
Definition: sitkImage.h:513
Private implementation idiom image base class.
#define sitkStaticAssert(expr, str)
Definition: sitkMacro.h:126
::int64_t int64_t
::int8_t int8_t
::int32_t int32_t
::uint64_t uint64_t
::int16_t int16_t