gdcmPixelFormat.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program: GDCM (Grassroots DICOM). A DICOM library
00004   Module:  $URL$
00005 
00006   Copyright (c) 2006-2009 Mathieu Malaterre
00007   All rights reserved.
00008   See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00015 
00016 #ifndef __gdcmPixelFormat_h
00017 #define __gdcmPixelFormat_h
00018 
00019 #include "gdcmTypes.h"
00020 #include <iostream>
00021 #include <assert.h>
00022 
00023 namespace gdcm
00024 {
00025 
00037 class GDCM_EXPORT PixelFormat
00038 {
00039   friend class Bitmap;
00040   friend std::ostream& operator<<(std::ostream &_os, const PixelFormat &pf);
00041 public:
00042   // When adding a type please add its dual type (its unsigned conterpart)
00043   typedef enum {
00044     UINT8,
00045     INT8,
00046     UINT12,
00047     INT12,
00048     UINT16,
00049     INT16,
00050     UINT32,  // For some DICOM files (RT or SC)
00051     INT32,   //                        "   "
00052     FLOAT16, // sure why not...
00053     FLOAT32, // good ol' 'float'
00054     FLOAT64, // aka 'double'
00055     UNKNOWN // aka BitsAllocated == 0 && PixelRepresentation == 0
00056   } ScalarType;
00057 
00058   // default cstor:
00059   explicit PixelFormat (
00060     unsigned short samplesperpixel = 1,
00061     unsigned short bitsallocated = 8,
00062     unsigned short bitsstored = 8,
00063     unsigned short highbit = 7,
00064     unsigned short pixelrepresentation = 0 ) :
00065   SamplesPerPixel(samplesperpixel),
00066   BitsAllocated(bitsallocated),
00067   BitsStored(bitsstored),
00068   HighBit(highbit),
00069   PixelRepresentation(pixelrepresentation) {}
00070   // helper, for the common case
00071   PixelFormat(ScalarType st);
00072   ~PixelFormat() {}
00073 
00074   // For transparency of use
00075   operator ScalarType() const { return GetScalarType(); }
00076 
00078   unsigned short GetSamplesPerPixel() const;
00079   void SetSamplesPerPixel(unsigned short spp)
00080     {
00081     SamplesPerPixel = spp;
00082     }
00083 
00085   unsigned short GetBitsAllocated() const
00086     {
00087     return BitsAllocated;
00088     }
00089   void SetBitsAllocated(unsigned short ba)
00090     {
00091     BitsAllocated = ba;
00092     }
00093 
00095   unsigned short GetBitsStored() const
00096     {
00097     return BitsStored;
00098     }
00099   void SetBitsStored(unsigned short bs)
00100     {
00101     BitsStored = bs;
00102     }
00103 
00105   unsigned short GetHighBit() const
00106     {
00107     return HighBit;
00108     }
00109   void SetHighBit(unsigned short hb)
00110     {
00111     HighBit = hb;
00112     }
00113 
00115   unsigned short GetPixelRepresentation() const
00116     {
00117     assert( PixelRepresentation == 0
00118          || PixelRepresentation == 1 );
00119     return PixelRepresentation;
00120     }
00121   void SetPixelRepresentation(unsigned short pr)
00122     {
00123     assert( PixelRepresentation == 0
00124          || PixelRepresentation == 1 );
00125     PixelRepresentation = pr;
00126     }
00127 
00129   ScalarType GetScalarType() const;
00130   // BUG: You need to call SetScalarType *before* SetSamplesPerPixel
00131   void SetScalarType(ScalarType st);
00132   const char *GetScalarTypeAsString() const;
00133 
00139   uint8_t GetPixelSize() const;
00140 
00142   void Print(std::ostream &os) const;
00143 
00145   int64_t GetMin() const;
00146 
00148   int64_t GetMax() const;
00149 
00150 protected:
00152   bool Validate();
00153 
00154 private:
00155   // D 0028|0002 [US] [Samples per Pixel] [1]
00156   unsigned short SamplesPerPixel;
00157   // D 0028|0100 [US] [Bits Allocated] [8]
00158   unsigned short BitsAllocated;
00159   // D 0028|0101 [US] [Bits Stored] [8]
00160   unsigned short BitsStored;
00161   // D 0028|0102 [US] [High Bit] [7]
00162   unsigned short HighBit;
00163   // D 0028|0103 [US] [Pixel Representation] [0]
00164   unsigned short PixelRepresentation;
00165 };
00166 //-----------------------------------------------------------------------------
00167 inline std::ostream& operator<<(std::ostream &os, const PixelFormat &pf)
00168 {
00169   pf.Print( os );
00170   return os;
00171 }
00172 
00173 } // end namespace gdcm
00174 
00175 #endif //__gdcmPixelFormat_h
00176 

Generated on Sun Mar 7 03:17:21 2010 for GDCM by doxygen 1.6.3
SourceForge.net Logo