1 /*========================================================================= 2 3 Program: GDCM (Grassroots DICOM). A DICOM library 4 5 Copyright (c) 2006-2011 Mathieu Malaterre 6 All rights reserved. 7 See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details. 8 9 This software is distributed WITHOUT ANY WARRANTY; without even 10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 11 PURPOSE. See the above copyright notice for more information. 12 13 =========================================================================*/ 14 #ifndef GDCMIMAGE_H 15 #define GDCMIMAGE_H 16 17 #include "gdcmPixmap.h" 18 19 #include <vector> 20 21 namespace gdcm 22 { 23 24 /** 25 * \brief Image 26 * \details This is the container for an Image in the general sense. 27 * From this container you should be able to request information like: 28 * - Origin 29 * - Dimension 30 * - PixelFormat 31 * ... 32 * But also to retrieve the image as a raw buffer (char *) 33 * Since we have to deal with both RAW data and JPEG stream (which 34 * internally encode all the above information) this API might seems 35 * redundant. One way to solve that would be to subclass Image 36 * with JPEGImage which would from the stream extract the header info 37 * and fill it to please Image...well except origin for instance 38 * 39 * Basically you can see it as a storage for the Pixel Data element (7fe0,0010). 40 * 41 * \warning This class does some heuristics to guess the Spacing but is not 42 * compatible with DICOM CP-586. In case of doubt use PixmapReader instead 43 * 44 * \see ImageReader PixmapReader 45 */ 46 class GDCM_EXPORT Image : public Pixmap 47 { 48 public: Image()49 Image ():Spacing(),SC(),Intercept(0),Slope(1) { 50 //DirectionCosines.resize(6); 51 Origin.resize( 3 /*NumberOfDimensions*/ ); // fill with 0 52 DirectionCosines.resize( 6 ); // fill with 0 53 DirectionCosines[0] = 1; 54 DirectionCosines[4] = 1; 55 Spacing.resize( 3 /*NumberOfDimensions*/, 1 ); // fill with 1 56 57 } 58 ~Image() override = default; 59 60 /// Return a 3-tuples specifying the spacing 61 /// NOTE: 3rd value can be an arbitrary 1 value when the spacing was not specified (ex. 2D image). 62 /// WARNING: when the spacing is not specifier, a default value of 1 will be returned 63 const double *GetSpacing() const; 64 double GetSpacing(unsigned int idx) const; 65 void SetSpacing(const double spacing[3]); 66 void SetSpacing(unsigned int idx, double spacing); 67 68 /// Return a 3-tuples specifying the origin 69 /// Will return (0,0,0) if the origin was not specified. 70 const double *GetOrigin() const; 71 double GetOrigin(unsigned int idx) const; 72 void SetOrigin(const float origin[3]); 73 void SetOrigin(const double origin[3]); 74 void SetOrigin(unsigned int idx, double ori); 75 76 /// Return a 6-tuples specifying the direction cosines 77 /// A default value of (1,0,0,0,1,0) will be return when the direction cosines was not specified. 78 const double *GetDirectionCosines() const; 79 double GetDirectionCosines(unsigned int idx) const; 80 void SetDirectionCosines(const float dircos[6]); 81 void SetDirectionCosines(const double dircos[6]); 82 void SetDirectionCosines(unsigned int idx, double dircos); 83 84 /// print 85 void Print(std::ostream &os) const override; 86 87 /// intercept SetIntercept(double intercept)88 void SetIntercept(double intercept) { Intercept = intercept; } GetIntercept()89 double GetIntercept() const { return Intercept; } 90 91 /// slope SetSlope(double slope)92 void SetSlope(double slope) { Slope = slope; } GetSlope()93 double GetSlope() const { return Slope; } 94 95 private: 96 std::vector<double> Spacing; 97 std::vector<double> Origin; 98 std::vector<double> DirectionCosines; 99 100 // I believe the following 3 ivars can be derived from TS ... 101 SwapCode SC; 102 double Intercept; 103 double Slope; 104 }; 105 106 /** 107 * \example DecompressImage.cs 108 * This is a C# example on how to use Image 109 */ 110 111 } // end namespace gdcm 112 113 #endif //GDCMIMAGE_H 114