]> Creatis software - gdcm.git/blobdiff - src/gdcmHeader.cxx
modif DcmWrite
[gdcm.git] / src / gdcmHeader.cxx
index 4f208912ce4dbd387418bfc6cb3c4f814d2b9cfd..6eeebe416a421f5327dd32076ca87adf9581ada7 100644 (file)
@@ -13,9 +13,8 @@
 #include <sstream>
 #include "gdcmUtil.h"
 
-#define HEADER_LENGTH_TO_READ 256 // on ne lit plus que le debut
-
-#define DEBUG 1
+#define HEADER_LENGTH_TO_READ          256     // on ne lit plus que le debut
+#define _MaxSizeLoadElementValue_      1024    // longueur au dela de laquelle on ne charge plus les valeurs 
 
 namespace Error {
        struct FileReadError {
@@ -29,8 +28,15 @@ namespace Error {
 }
 
 //FIXME: this looks dirty to me...
+
 #define str2num(str, typeNum) *((typeNum *)(str))
 
+// str est un pointeur dans un tableau de caractères, qui doit contenir, 
+// à cet endroit la, la représentation binaire d'un entier (16 ou 32 bits)
+// je veux récupérer ça ... dans un entier.
+// s'il y a une autre solution, évitant des cast et les indirections,
+// je suis preneur
+
 VRHT * gdcmHeader::dicom_vr = (VRHT*)0;
 gdcmDictSet* gdcmHeader::Dicts = new gdcmDictSet();
 
@@ -42,7 +48,7 @@ void gdcmHeader::Initialise(void) {
 }
 
 gdcmHeader::gdcmHeader (const char* InFilename) {
-       SetMaxSizeLoadElementValue(1024);
+       SetMaxSizeLoadElementValue(_MaxSizeLoadElementValue_);
        filename = InFilename;
        Initialise();
        fp=fopen(InFilename,"rw");
@@ -118,7 +124,7 @@ void gdcmHeader::CheckSwap()
                net2host = false;
        
        // The easiest case is the one of a DICOM header, since it possesses a
-       // file preamble where it suffice to look for the sting "DICM".
+       // file preamble where it suffice to look for the string "DICM".
        lgrLue = fread(deb, 1, HEADER_LENGTH_TO_READ, fp);
        
        entCur = deb + 128;
@@ -238,11 +244,11 @@ void gdcmHeader::SwitchSwapToBigEndian(void) {
                sw = 3412;
 }
 
-void gdcmHeader::GetPixels(size_t lgrTotale, void* Pixels) {
+void gdcmHeader::GetPixels(size_t lgrTotale, void* _Pixels) {
        size_t pixelsOffset; 
        pixelsOffset = GetPixelOffset();
        fseek(fp, pixelsOffset, SEEK_SET);
-       fread(Pixels, 1, lgrTotale, fp);
+       fread(_Pixels, 1, lgrTotale, fp);
 }
 
 
@@ -492,6 +498,8 @@ bool gdcmHeader::IsJPEGSpectralSelectionProcess6_8TransferSyntax(void) {
 // Il y en a encore DIX-SEPT, comme ça.
 // Il faudrait trouver qq chose + rusé ...
 //
+// --> probablement TOUS les supprimer (Eric dixit)
+//
 
 
 void gdcmHeader::FixFoundLength(ElValue * ElVal, guint32 FoundLength) {
@@ -572,7 +580,7 @@ void gdcmHeader::FindLength(ElValue * ElVal) {
                //   in little endian, and big endian coding only starts at the next
                //   group. The corresponding code can be hard to analyse and adds
                //   many additional unnecessary tests for regular tags.
-               // * the second strategy consist in waiting for trouble, that shall appear
+               // * the second strategy consists in waiting for trouble, that shall appear
                //   when we find the first group with big endian encoding. This is
                //   easy to detect since the length of a "Group Length" tag (the
                //   ones with zero as element number) has to be of 4 (0x0004). When we
@@ -723,7 +731,9 @@ void gdcmHeader::LoadElementValue(ElValue * ElVal) {
        // The group length doesn't represent data to be loaded in memory, since
        // each element of the group shall be loaded individualy.
        if( elem == 0 )
-               SkipLoad = true;
+               //SkipLoad = true;              // modif sauvage JPR
+                                                               // On charge la longueur du groupe
+                                                               // quand l'element 0x0000 est présent !
 
        if ( SkipLoad ) {
                          // FIXME the following skip is not necessary
@@ -944,7 +954,7 @@ size_t gdcmHeader::GetPixelOffset(void) {
        guint16 grPixel;
        guint16 numPixel;
        string ImageLocation = GetPubElValByName("Image Location");
-       if ( ImageLocation == "UNFOUND" ) {
+       if ( ImageLocation == "gdcm::Unfound" ) {
                grPixel = 0x7fe0;
        } else {
                grPixel = (guint16) atoi( ImageLocation.c_str() );
@@ -1078,6 +1088,56 @@ string gdcmHeader::GetElValRepByName(string TagName) {
        return GetShaElValRepByName(TagName);
 }
 
+/**
+ * \ingroup gdcmHeader
+ * \brief   Modifie la valeur d'un ElValue déja existant
+ * \   dans le PubElVals du gdcmHeader,
+ * \   accédé par ses numero de groupe et d'element.
+ */
+int gdcmHeader::SetPubElValByNumber(string content, guint16 group, guint16 element) {
+       //TagKey key = gdcmDictEntry::TranslateToKey(group, element);
+       //PubElVals.tagHt[key]->SetValue(content);
+       
+       return (  PubElVals.SetElValueByNumber (content, group, element) );
+}
+
+
+/**
+ * \ingroup gdcmHeader
+ * \brief   Modifie la valeur d'un ElValue déja existant
+ * \   dans le PubElVals du gdcmHeader,
+ * \   accédé par son nom
+ */
+int gdcmHeader::SetPubElValByName(string content, string TagName) {
+       //TagKey key = gdcmDictEntry::TranslateToKey(group, element);
+       //PubElVals.tagHt[key]->SetValue(content);
+       
+       return (  PubElVals.SetElValueByName (content, TagName) );
+}
+
+
+/**
+ * \ingroup gdcmHeader
+ * \brief   Modifie la valeur d'un ElValue déja existant
+ * \   dans le ShaElVals du gdcmHeader,
+ * \   accédé par ses numero de groupe et d'element.
+ */
+int gdcmHeader::SetShaElValByNumber(string content, guint16 group, guint16 element) {
+       
+       return (  ShaElVals.SetElValueByNumber (content, group, element) );
+}
+
+
+/**
+ * \ingroup gdcmHeader
+ * \brief   Modifie la valeur d'un ElValue déja existant
+ * \   dans le ShaElVals du gdcmHeader,
+ * \   accédé par son nom
+ */
+int gdcmHeader::SetShaElValByName(string content, string TagName) {
+       
+       return (  ShaElVals.SetElValueByName (content, TagName) );
+}
 /**
  * \ingroup gdcmHeader
  * \brief   Parses the header of the file but does NOT load element values.
@@ -1100,15 +1160,10 @@ void gdcmHeader::ParseHeader(void) {
  */
 void gdcmHeader::LoadElements(void) {
 
-       if (DEBUG) printf("LoadElements : Entree\n");
-
        rewind(fp);   
-       if (DEBUG) printf("LoadElements : rewind\n");
 
        TagElValueHT ht = PubElVals.GetTagHt();
        
-       if (DEBUG) printf("LoadElements : GetTagHt\n");
-
        for (TagElValueHT::iterator tag = ht.begin(); tag != ht.end(); ++tag) {
                LoadElementValue(tag->second);
                }