]> Creatis software - gdcm.git/blobdiff - src/gdcm.h
Ajout fonction
[gdcm.git] / src / gdcm.h
index 0c370c6603805560215bdffac716a8491519e851..1b387098e06b74288cbe19773152e69dc3643c06 100644 (file)
@@ -1,9 +1,11 @@
+// gdcm.h
+
 // gdcmlib Intro:  
 // * gdcmlib is a library dedicated to reading and writing dicom files.
 // * LGPL for the license
-// * lightweigth as opposed to CTN or DCMTK wich come bundled which try
+// * lightweigth as opposed to CTN or DCMTK which come bundled which try
 //   to implement the full DICOM standard (networking...). gdcmlib concentrates
-//   on reading and 
+//   on reading and writing
 // * Formats: this lib should be able to read ACR-NEMA v1 and v2, Dicom v3 (as
 //   stated in part10). [cf dcmtk/dcmdata/docs/datadict.txt]
 // * Targeted plateforms: Un*xes and Win32/VC++6.0
@@ -26,6 +28,30 @@ using namespace std;  // string type lives in the std namespace on VC++
 #include <list>
 #include <map>
 
+                     // The requirement for the hash table (or map) that
+                      // we shall use:
+                      // 1/ First, next, last (iterators)
+                      // 2/ should be sortable (i.e. sorted by TagKey). This
+                      //    condition shall be droped since the Win32/VC++
+                      //    implementation doesn't look a sorted one. Pffff....
+                      // 3/ Make sure we can setup some default size value,
+                      //    which should be around 4500 entries which is the
+                      //    average dictionary size (said JPR)
+                      //
+                      // En fait, je disais que dans LE Directory Dicom (dans son etat 2002)
+                      // il y a 1600 entrees.
+                      // Une valeur raisonable pour un  majorant du nombre d'entrees
+                      // dans une entete DICOM d'une image semble semble etre 300
+                      // Si on 'decortique' les elements SQ (ce qui ne semble pas etre fait pour le moment)
+                      // on risque en fait de depasser ... un nombre non previsible dans le cas d'une entree SQ
+                      // contenant lui même un tres grand nombre d'entrees ?!?)
+                      // Quant au nombre d'entrees dans un DICOMDIR, c'est encore pire : il n'est limité
+                      // que par la taille d'un CD-ROM (les DVD-ROM ne sont pas encore pris en compte)
+                      // On peut s'attendre a 30 entrees par fichier dicom présent sur le CD-ROM
+                      // REMARQUE : il faudra se pencher sur le pb de la creation du DICOMDIR lorsqu'on voudra 
+                      // exporter des images lisibles par les consoles cliniques 
+                      // et pas seulement importables dans e-film. 
+
 #ifdef __GNUC__
 #include <stdint.h>
 #define guint16 uint16_t
@@ -34,7 +60,7 @@ using namespace std;  // string type lives in the std namespace on VC++
 
 #ifdef _MSC_VER 
 typedef  unsigned short guint16;
-typedef  unsigned int guint32;
+typedef  unsigned int   guint32;
 #endif
 
 #ifdef _MSC_VER
@@ -43,6 +69,13 @@ typedef  unsigned int guint32;
 #define GDCM_EXPORT
 #endif
 
+//
+// ---------------------------------------------------- gdcmDictEntry
+//
+//     c'est une ligne du Dictionnaire Dicom
+//
+
+
 ////////////////////////////////////////////////////////////////////////////
 // Tag based hash tables.
 // We shall use as keys the strings (as the C++ type) obtained by
@@ -52,12 +85,13 @@ typedef  unsigned int guint32;
 // Then the corresponding TagKey shall be the string 0010|0010 (where
 // the | (pipe symbol) acts as a separator). Refer to 
 // gdcmDictEntry::TranslateToKey for this conversion function.
+
 typedef string TagKey;
 
 class GDCM_EXPORT gdcmDictEntry {
 private:
        guint16 group;    // e.g. 0x0010
-       guint16 element;  // e.g. 0x0010
+       guint16 element;  // e.g. 0x0103
        string  vr;       // Value Representation i.e. some clue about the nature
                          // of the data represented e.g. "FD" short for
                          // "Floating Point Double"
@@ -80,45 +114,81 @@ private:
        //         DcmDictRangeRestriction elementRestriction;
        //       };
 public:
-       gdcmDictEntry(guint16 group, guint16 element,
+       
+       // fabrique une ligne de Dictionnaire Dicom à partir des parametres en entrée
+
+       gdcmDictEntry(guint16 group, 
+                         guint16 element,
                      string vr     = "Unknown",
                      string fourth = "Unknown",
                      string name   = "Unknown");
+                                         
+       // fabrique une 'clé' par concaténation du numGroupe et du numElement
+
        static TagKey TranslateToKey(guint16 group, guint16 element);
-       guint16 GetGroup(void)  { return group;};
+       
+       guint16 GetGroup(void)  { return group; };
        guint16 GetElement(void){return element;};
-       string  GetVR(void)     {return vr; };
+       string  GetVR(void)     {return vr;     };
        void    SetVR(string);
+       void    SetKey(string k){ key = k;              }
        bool    IsVrUnknown(void);
        string  GetFourth(void) {return fourth;};
-       string  GetName(void)   {return name;};
-       string  GetKey(void)    {return key;};
+       string  GetName(void)   {return name;  };
+       string  GetKey(void)    {return key;   };
 };
   
+//
+// ---------------------------------------------------- gdcmDict
+// 
+//     c'est le Dictionnaire Dicom
+//
 ////////////////////////////////////////////////////////////////////////////
 // A single DICOM dictionary i.e. a container for a collection of dictionary
 // entries. There should be a single public dictionary (THE dictionary of
 // the actual DICOM v3) but as many shadow dictionaries as imagers 
 // combined with all software versions...
+
 typedef map<TagKey, gdcmDictEntry*> TagHT;
+       // Table de Hachage : (group,Elem) --> pointeur vers une ligne du Dictionnaire Dicom
 
 class GDCM_EXPORT gdcmDict {
        string name;
        string filename;
        TagHT entries;
 public:
+       // rempli le Dictionnaire Dicom à partir d'un fichier texte
        gdcmDict(const char* FileName);   // Read Dict from disk
-       // TODO Swig int AppendEntry(gdcmDictEntry* NewEntry);
+       
+       int AddNewEntry (gdcmDictEntry* NewEntry);
+       int ReplaceEntry(gdcmDictEntry* NewEntry);
+       int RemoveEntry (TagKey k);
+       int RemoveEntry (guint16 group, guint16 element);
+       
+       // renvoie une ligne de Dictionnaire Dicom à partir de (numGroup, numElement)
        gdcmDictEntry * GetTag(guint32 group, guint32 element);
+       
        void Print(ostream&);
        TagHT & GetEntries(void) { return entries; }
 };
 
+
+//
+// ---------------------------------------------------- gdcmDictSet
+//
+//     Ensemble de Dictionnaires Dicom (le public + 'des' privés)
+//     Au cas ou l'on traiterait un jour les 'dictionnaires privés'
+//      - pratiquement un par constructeur, par machine, et par version du logiciel -
+//
+//
+
 ////////////////////////////////////////////////////////////////////////////
 // Container for managing a set of loaded dictionaries. Sharing dictionaries
 // should avoid :
 // * reloading an allready loaded dictionary,
 // * having many in memory representations of the same dictionary.
+
 typedef string DictKey;
 typedef map<DictKey, gdcmDict*> DictSetHT;
 
@@ -138,15 +208,36 @@ public:
        // TODO Swig int LoadDictFromName(string filename);
        // TODO Swig int LoadAllDictFromDirectory(string DirectoryName);
        // TODO Swig string* GetAllDictNames();
+       //
+       // Question : ne faudra-t-il pas mettre LE dictionnaire DICOM dans un Directory
+       // et les eventuels 'dictionnaires prives' dans un autre?
+       // (pour eviter a un utilisateur mal dégourdi de tout saccager ?)
+       //
        int LoadDicomV3Dict(void);
        void Print(ostream&);
        gdcmDict* GetDict(DictKey DictName);
        gdcmDict* GetDefaultPublicDict(void);
 };
 
-////////////////////////////////////////////////////////////////////////////
+
+//
+// ---------------------------------------------------- ElValue
+//
+//     C'est un Element Dicom
+//     (ce qu'on a trouve dans l'entete de l'image
+//     + ce qu'on est allé chercher dans le Dictionnaire Dicom)
+//
+
+// QUESTION:
+//
+// Ne faudrait-il pas trouver un autre nom, qui preterait moins à confusion?
+// ElValue n'EST PAS la 'valeur d'un Element', mais la reunion d'infos
+// trouvees dans l'Entete du fichier ET dans le Dictionnaire DICOM
+//
+
 // The dicom header of a Dicom file contains a set of such ELement VALUES
 // (when successfuly parsed against a given Dicom dictionary)
+
 class GDCM_EXPORT ElValue {
 private:
        gdcmDictEntry *entry;
@@ -160,49 +251,82 @@ private:
 public:
        string  value;     // used to be char * valeurElem
        size_t Offset;     // Offset from the begining of file for direct user access
+       
        ElValue(gdcmDictEntry*);
        void SetDictEntry(gdcmDictEntry *NewEntry) { entry = NewEntry; };
-
        bool   IsVrUnknown(void) { return entry->IsVrUnknown(); };
-       void SetLength(guint32 l){LgrElem = l; };
-       void SetValue(string val){ value = val; };
-       void SetOffset(size_t of){ Offset = of; };
        void SetImplicitVr(void) { ImplicitVr = true; };
        bool  IsImplicitVr(void) { return ImplicitVr; };
-       void    SetVR(string);
-       string  GetVR(void);
-       string  GetValue(void)   { return value; };
-       guint32 GetLength(void)  { return LgrElem; };
-       size_t  GetOffset(void)  { return Offset; };
-       guint16 GetGroup(void)   { return entry->GetGroup(); };
+
+       guint16 GetGroup(void)   { return entry->GetGroup();   };       
        guint16 GetElement(void) { return entry->GetElement(); };
-       string  GetKey(void)     { return entry->GetKey(); };
-       string  GetName(void)    { return entry->GetName();};
+       string  GetKey(void)     { return entry->GetKey();     };
+       string  GetName(void)    { return entry->GetName();    };
+       
+       string  GetVR(void)              { return entry->GetVR(); };
+       void    SetVR(string v)  { entry->SetVR(v);       }; 
+               
+       // Question :
+       // Un champ privé, accessible en consultation et en modif (sans restriction)
+       // interet par rapport à un champ public ? 
+       // --> pouvoir en changer la définition sans toucher à l'API
+       
+       void SetLength(guint32 l){ LgrElem = l;         };
+       guint32 GetLength(void)  { return LgrElem;      };
+
+       void SetValue(string val){ value = val;         };
+       string  GetValue(void)   { return value;        };
+
+       void SetOffset(size_t of){ Offset = of;         };
+       size_t  GetOffset(void)  { return Offset;       };      
+
 };
 
+
+//
+// ---------------------------------------------------- ElValSet
+//
+//     ... un ensemble d'Elements Dicom 
+//     ... le résultat de l'analyse d'une entete d'image, par exemple
+
 ////////////////////////////////////////////////////////////////////////////
-// Container for a set of succefully parsed ElValues.
+// Container for a set of successfully parsed ElValues.
 typedef map<TagKey, ElValue*> TagElValueHT;
 typedef map<string, ElValue*> TagElValueNameHT;
 
 class GDCM_EXPORT ElValSet {
                // We need both accesses with a TagKey and the Dictentry.Name
+
        TagElValueHT tagHt;
        TagElValueNameHT NameHt;
-public:
-       void Add(ElValue*);
+public:        
+       void Add(ElValue*);             
        void Print(ostream &);
        void PrintByName(ostream &);
+       int  Write(FILE *fp);
        ElValue* GetElementByNumber(guint32 group, guint32 element);
-       ElValue* GetElementByName(string);
-       string GetElValueByNumber(guint32 group, guint32 element);
-       string GetElValueByName(string);
-       TagElValueHT & GetTagHt(void);
+       ElValue* GetElementByName  (string);
+       string   GetElValueByNumber(guint32 group, guint32 element);
+       string   GetElValueByName  (string);
+       
+       TagElValueHT & GetTagHt(void);  
+       
+       int SetElValueByNumber(string content, guint32 group, guint32 element);
+       int SetElValueByName(string content, string TagName);
 };
 
+
+//
+// ---------------------------------------------------- gdcmHeader
+//
+//     C'est le Dicom Header d'une image donnée
+//     (tous les elements Dicom qui la composent
+//     + des info 'de service')
+//
+
 ////////////////////////////////////////////////////////////////////////////
 // The typical usage of instances of class gdcmHeader is to classify a set of
-// dicom files according to header information e.g. to create a file hierachy
+// dicom files according to header information e.g. to create a file hierarchy
 // reflecting the Patient/Study/Serie informations, or extracting a given
 // SerieId. Accesing the content (image[s] or volume[s]) is beyond the
 // functionality of this class and belong to gdmcFile (see below).
@@ -212,15 +336,18 @@ public:
 // * the gdcmHeader::Set*Tag* family members cannot be defined as protected
 //   (Swig limitations for as Has_a dependency between gdcmFile and gdcmHeader)
  
+
 typedef string VRKey;
 typedef string VRAtr;
-typedef map<TagKey, VRAtr> VRHT;    // Value Representation Hash Table
+typedef map<VRKey, VRAtr> VRHT;    // Value Representation Hash Table
+
 
 class GDCM_EXPORT gdcmHeader {
        void SkipBytes(guint32);
 private:
        static VRHT *dicom_vr;
        // Dictionaries of data elements:
+
        static gdcmDictSet* Dicts;  // global dictionary container
        gdcmDict* RefPubDict;       // public dictionary
        gdcmDict* RefShaDict;       // shadow dictionary (optional)
@@ -229,13 +356,23 @@ private:
        ElValSet ShaElVals;         // parsed with Shadow Dictionary
        string filename;            // refering underlying file
        FILE * fp;
-       // The tag Image Location ((0028,0200) containing the address of
-       // the pixels) is not allways present. When we store this information
+       // The tag Image Location (0028,0200) - containing the address of
+       // the pixels - is not allways present. Then we store this information
+       // il etait facultatif en ACR-NEMA, il n'existe plus en DICOM 3
        // FIXME
+       
+       // Question :
+       // Qu'y a-t-il a corriger ?
+       //
        // outside of the elements:
+       
        guint16 grPixel;
        guint16 numPixel;
-       // Swap code (little, big, big-bad endian): this code is not fixed
+       // Ne faudrait-il pas une indication sur la presence ou non
+       // du 'groupe des pixels' dans l'entete?
+       // (voir pb du DICOMDIR)
+       
+       // Swap code (little, big, bad-big, bad-little endian): this code is not fixed
        // during parsing.FIXME sw should be an enum e.g.
        //enum EndianType {
                //LittleEndian, 
@@ -243,7 +380,8 @@ private:
                //BigEndian, 
                //BadBigEndian};
        int sw;
-       // Only the elements whose size are below this bound shall be loaded.
+
+       // Only the elements whose size is below this bound will be loaded.
        // By default, this upper bound is limited to 1024 (which looks reasonable
        // when one considers the definition of the various VR contents).
        guint32 MaxSizeLoadElementValue;
@@ -264,11 +402,24 @@ private:
        void SwitchSwapToBigEndian(void);
        void FixFoundLength(ElValue*, guint32);
        bool IsAnInteger(ElValue *);
-       bool IsBigEndianTransferSyntax(void);
+       
+       bool IsImplicitVRLittleEndianTransferSyntax(void);
+       bool IsExplicitVRLittleEndianTransferSyntax(void);
+       bool IsDeflatedExplicitVRLittleEndianTransferSyntax(void);
+       bool IsExplicitVRBigEndianTransferSyntax(void);
+       bool IsJPEGBaseLineProcess1TransferSyntax(void);
+       bool IsJPEGExtendedProcess2_4TransferSyntax(void);      
+       bool IsJPEGExtendedProcess3_5TransferSyntax(void);
+       bool IsJPEGSpectralSelectionProcess6_8TransferSyntax(void);     
+//
+// Euhhhhhhh
+// Il y en a encore DIX-SEPT, comme ça.
+// Il faudrait trouver qq chose + rusé ...
+//     
+               
        void SetMaxSizeLoadElementValue(long);
        ElValue       * ReadNextElement(void);
        gdcmDictEntry * IsInDicts(guint32, guint32);
-       size_t GetPixelOffset(void);
 protected:
        enum FileType {
                Unknown = 0,
@@ -285,26 +436,34 @@ public:
        virtual void ParseHeader(void);
        gdcmHeader(const char* filename);
        virtual ~gdcmHeader();
+       
+       size_t GetPixelOffset(void);
+       void   GetPixels(size_t, void *);
+       int    GetSwapCode(void) { return sw; }
 
        // TODO Swig int SetPubDict(string filename);
-       // When some proprietary shadow groups are disclosed, whe can set
-       // up an additional specific dictionary to access extra information.
+       // When some proprietary shadow groups are disclosed, we can set up
+       // an additional specific dictionary to access extra information.
        // TODO Swig int SetShaDict(string filename);
 
        // Retrieve all potentially available tag [tag = (group, element)] names
-       // from the standard (or public) dictionary. Typical usage: enable the
+       // from the standard (or public) dictionary. Typical usage : enable the
        // user of a GUI based interface to select his favorite fields for sorting
-       // or selection.
+       // or selecting.
        list<string> * GetPubTagNames(void);
        map<string, list<string> > * GetPubTagNamesByCategory(void);
        // Get the element values themselves:
+       
        string GetPubElValByName(string TagName);
        string GetPubElValByNumber(guint16 group, guint16 element);
+
        // Getting the element value representation (VR) might be needed by caller
-       // to convert the string typed content to caller's native type (think
-       // of C/C++ vs Python).
+       // to convert the string typed content to caller's native type 
+       // (think of C/C++ vs Python).
+
        string GetPubElValRepByName(string TagName);
        string GetPubElValRepByNumber(guint16 group, guint16 element);
+
        TagElValueHT & GetPubElVal(void) { return PubElVals.GetTagHt(); };
        void   PrintPubElVal(ostream & os = cout);
        void   PrintPubDict(ostream &);
@@ -324,28 +483,48 @@ public:
        string GetElValRepByName(string TagName);
        string GetElValRepByNumber(guint16 group, guint16 element);
 
-       // TODO Swig int SetPubElValByName(string content, string TagName);
-       // TODO Swig int SetPubElValByNumber(string content, guint16 group, guint16 element);
-       // TODO Swig int SetShaElValByName(string content, string ShadowTagName);
-       // TODO Swig int SetShaElValByNumber(string content, guint16 group, guint16 element);
+       int SetPubElValByName(string content, string TagName);
+       int SetPubElValByNumber(string content, guint16 group, guint16 element);
+       int SetShaElValByName(string content, string ShadowTagName);
+       int SetShaElValByNumber(string content, guint16 group, guint16 element);
 
-       // TODO Swig int GetSwapCode();
+       ElValSet GetPubElVals() { return(PubElVals); }
 };
 
+//
+// ---------------------------------------------------- gdcmFile
+//
+//     un fichier EST_UNE entete, ou A_UNE entete ?
+// 
+//     On dit 'EST_UNE' ...
+
+
 ////////////////////////////////////////////////////////////////////////////
 // In addition to Dicom header exploration, this class is designed
 // for accessing the image/volume content. One can also use it to
 // write Dicom files.
-////// QUESTION: this looks still like an open question wether the
+////// QUESTION: this looks still like an open question whether the
 //////           relationship between a gdcmFile and gdcmHeader is of
 //////           type IS_A or HAS_A !
-class GDCM_EXPORT gdcmFile: gdcmHeader
+
+class GDCM_EXPORT gdcmFile: public gdcmHeader
 {
 private:
+       // QUESTION :
+       // Data pointe sur quoi?
+       // sur les Pixels lus?
+       // --> j'ajoute un champ public : Pixels
+       // (il faudra que l'utilisateur puisse modifier les pixels ?)
+       
        void* Data;
        int Parsed;          // weather allready parsed
        string OrigFileName; // To avoid file overwrite
 public:
+       // je ne suis pas sur d'avoir compris *où* il serait légitime de ranger ca.
+       // on pourra tjs le deplacer, et mettre des accesseurs
+       void * Pixels;
+       size_t lgrTotale;
+       
        // Constructor dedicated to writing a new DICOMV3 part10 compliant
        // file (see SetFileName, SetDcmTag and Write)
        // TODO Swig gdcmFile();
@@ -355,32 +534,78 @@ public:
        //    the DICOM header is post-poned to first header information access.
        //    This avoid a double parsing of public part of the header when
        //    one sets an a posteriori shadow dictionary (efficiency can be
-       //    seen a a side effect).
+       //    seen as a side effect).
+       
        gdcmFile(string & filename);
+       
        // For promotion (performs a deepcopy of pointed header object)
        // TODO Swig gdcmFile(gdcmHeader* header);
        // TODO Swig ~gdcmFile();
 
        // On writing purposes. When instance was created through
        // gdcmFile(string filename) then the filename argument MUST be different
-       // from the constructor's one (no overwriting aloud).
+       // from the constructor's one (no overwriting allowed).
        // TODO Swig int SetFileName(string filename);
 
        // Allocates necessary memory, copies the data (image[s]/volume[s]) to
        // newly allocated zone and return a pointer to it:
-       // TODO Swig void * GetImageData();
+       
+        void * GetImageData();
+       
        // Returns size (in bytes) of required memory to contain data
        // represented in this file.
-       // TODO Swig size_t GetImageDataSize();
+       
+       size_t GetImageDataSize();
+       
        // Copies (at most MaxSize bytes) of data to caller's memory space.
        // Returns an error code on failure (if MaxSize is not big enough)
-       // TODO Swig int PutImageDataHere(void* destination, size_t MaxSize );
+       
+       int PutImageDataHere(void* destination, size_t MaxSize );
+       
+       // Question :
+       //
+       //      GetImageData et PutImageDataHere
+       // Get et Put pour 2 fonctions qui font presque la meme chose :-(
+       //
+       
        // Allocates ExpectedSize bytes of memory at this->Data and copies the
        // pointed data to it.
+       
+       // Question :
+       // Pourquoi dupliquer les pixels, alors qu'on les a deja en mémoire,
+       // et que Data (dans le gdcmHeader) est un pointeur ?
+       
        // TODO Swig int SetImageData(void * Data, size_t ExpectedSize);
+       
        // Push to disk.
+       // A NE PAS OUBLIER : que fait-on en cas de Transfert Syntax (dans l'entete)
+       // incohérente avec l'ordre des octets en mémoire  
        // TODO Swig int Write();
+       
+       // Ecrit sur disque les pixels d'UNE image
+       // Aucun test n'est fait sur l'"Endiannerie" du processeur.
+       // Ca sera à l'utilisateur d'appeler son Reader correctement
+               
+       int WriteRawData (string nomFichier);
+       int WriteDcm (string nomFichier);
 };
 
+//
+// ---------------------------------------------------- gdcmSerie
+//
+//     une serie EST_UN fichier ????
+//
+//
+
 //class gdcmSerie : gdcmFile;
+
+//
+// ---------------------------------------------------- gdcmMultiFrame
+//
+//     un fichierMultiFrame EST_UN fichier 
+//
+//
+
 //class gdcmMultiFrame : gdcmFile;
+
+