]> Creatis software - gdcm.git/blob - src/gdcmDocEntrySet.cxx
general commit of (future) new classes.
[gdcm.git] / src / gdcmDocEntrySet.cxx
1 // gdcmDocEntrySet.cxx
2 //-----------------------------------------------------------------------------
3 //
4 #include <errno.h>
5 #include "gdcmDebug.h"
6 #include "gdcmCommon.h"
7 #include "gdcmGlobal.h"
8 #include "gdcmDocEntrySet.h"
9 #include "gdcmException.h"
10 #include "gdcmDocEntry.h"
11 #include "gdcmSeqEntry.h"
12 #include "gdcmValEntry.h"
13 #include "gdcmBinEntry.h"
14
15 //-----------------------------------------------------------------------------
16 // Constructor / Destructor
17 /**
18  * \ingroup gdcmDocEntrySet
19  * \brief   Constructor from a given gdcmDocEntrySet
20  */
21 gdcmDocEntrySet::gdcmDocEntrySet() {
22 }
23 /**
24  * \brief   Canonical destructor.
25  */
26 gdcmDocEntrySet::~gdcmDocEntrySet(){
27 }
28 //-----------------------------------------------------------------------------
29 // Print
30 /*
31  * \ingroup gdcmDocEntrySet
32  * \brief   canonical Printer
33  */
34
35
36 //-----------------------------------------------------------------------------
37 // Public
38 //bool gdcmDocEntrySet::AddEntry(gdcmDocEntry *Entry){return true;}
39
40 //-----------------------------------------------------------------------------
41 // Protected
42
43
44
45 //-----------------------------------------------------------------------------
46 // Private
47
48 /**
49  * \brief   Parses an EntrySet (Document header or SQ Item )
50  * \       and load element values (a voir !)
51  * @return  false anything wrong happens 
52  */
53  
54  /* just to keep the code
55  
56 bool gdcmDocEntrySet::LoadDocEntrySet(bool exception_on_error) 
57                    throw(gdcmFormatError) {
58    (void)exception_on_error;
59
60    gdcmDocEntry  *newDocEntry = (gdcmDocEntry *)0;     
61    gdcmValEntry  *newValEntry = (gdcmValEntry *)0; 
62    gdcmBinEntry  *newBinEntry = (gdcmBinEntry *)0; 
63    gdcmSeqEntry  *newSeqEntry = (gdcmSeqEntry *)0;  
64    
65    string vr;
66    while (newDocEntry = ReadNextDocEntry()) { 
67    // TODO (?) : liberation du DocEntry ainsi cree, 
68    // apres copie dans un ValEntry, SeqEntry, BinEntry   
69       vr = newDocEntry->GetVR();
70          
71       if (vr == "SQ" ) {
72       // --- SeqEntry
73       
74          newSeqEntry = new gdcmSeqEntry((gdcmDictEntry*)NULL);
75          if (!newSeqEntry) {
76             dbg.Verbose(1, "gdcmDocEntrySet::LoadDocEntrySet",
77                            "failed to allocate gdcmSeqEntry");
78             return false;                                
79          }       
80          newSeqEntry->Copy(newDocEntry);            
81       // TODO
82       // SEQUENCE; appel 'récursif' de ??? pour charger la 'valeur'
83       //           (ensemble d' ITEMs, en fait, 
84       //            chaque ITEM etant chargé avec LoadDocEntrySet)
85             
86          //SkipDocEntry(newSeqEntry); // voir ce qu'on fait pour une SeQuence
87          AddEntry(newSeqEntry); // on appele la fonction generique, 
88                                 // ou une fonction spécialisée ?
89          
90       } else  if (vr == "AE" || vr == "AS" || vr == "DA" || vr == "PN" || 
91                   vr == "UI" || vr == "TM" || vr == "SH" || vr == "LO" ||
92                   vr == "CS" || vr == "IS" || vr == "LO" || vr == "LT" ||
93                   vr == "SH" || vr == "ST" ||             
94                   vr == "SL" || vr == "SS" || vr == "UL" || vr == "US"
95                                                                         ) {
96       // --- ValEntry             
97                   
98          newValEntry = new gdcmValEntry((gdcmDictEntry*)NULL);
99          if (!newValEntry) {
100             dbg.Verbose(1, "gdcmDocEntrySet::LoadDocEntrySet",
101                            "failed to allocate gdcmValEntry");
102             return false;                                
103          }       
104          newValEntry->Copy(newDocEntry);
105          //SkipDocEntry(newValEntry); //le skip devrait etre fait dans le Read 
106          AddEntry(newValEntry); // on appele la fonction generique, 
107                                 // ou une fonction spécialisée ? 
108
109         // Maybe the following VR do correspond to a BinEntry 
110                 
111         //AT Attribute Tag; // OK        // 2 16-bit unsigned short integers
112         //FL Floating Point Single; // 32-bit IEEE 754:1985 float
113         //FD Floating Point Double; // 64-bit IEEE 754:1985 double
114         //UN Unknown;               // Any length of bytes
115         //UT Unlimited Text;        // At most 2^32 -1 chars
116         //OB Other Byte String;     // String of bytes (VR independant)
117         //OW Other Word String;     // String of 16-bit words (VR dependant)                                              
118       } else { 
119       // --- BinEntry
120       
121          newBinEntry = new gdcmBinEntry((gdcmDictEntry*)NULL);     
122          if (!newBinEntry) {
123             dbg.Verbose(1, "gdcmDocEntrySet::LoadDocEntrySet",
124                            "failed to allocate gdcmBinEntry");
125             return false;                                
126          }      
127          newBinEntry->Copy(newDocEntry);
128         // SkipDocEntry(newBinEntry); //le skip devrait etre fait dans le Read 
129          AddEntry(newBinEntry); // on appele la fonction generique, 
130                                 // ou une fonction spécialisée ?              
131       }                      
132    }   
133
134
135
136    // TODO : il n'y a plus de Chained List qui contient toutes les Entries 
137    //        Le chargement des valeurs devra se faire à la volée  
138    // Be carefull : merging this two loops may cause troubles ...
139    
140 /* 
141    rewind(fp);  
142    for (ListTag::iterator i = GetListEntry().begin();                           
143         i != GetListEntry().end();                                                
144         ++i)                                                                      
145    {                                                                            
146       LoadDocEntry(*i);                                                      
147    }                                                                            
148    rewind(fp);
149    
150    */
151  
152  /* TO DO : deporter den fin de parsing du DOCUMENT (pas du EntrySet) 
153   
154    // --------------------------------------------------------------
155    // Special Patch to allow gdcm to read ACR-LibIDO formated images
156    //
157    // if recognition code tells us we deal with a LibIDO image
158    // we switch lineNumber and columnNumber
159    //
160    std::string RecCode;
161    RecCode = GetEntryByNumber(0x0008, 0x0010); // recognition code
162    if (RecCode == "ACRNEMA_LIBIDO_1.1" ||
163        RecCode == "CANRME_AILIBOD1_1." )  // for brain-damaged softwares
164                                           // with "little-endian strings"
165    {
166          filetype = ACR_LIBIDO; 
167          std::string rows    = GetEntryByNumber(0x0028, 0x0010);
168          std::string columns = GetEntryByNumber(0x0028, 0x0011);
169          SetEntryByNumber(columns, 0x0028, 0x0010);
170          SetEntryByNumber(rows   , 0x0028, 0x0011);
171    }
172    // ----------------- End of Special Patch ---------------- 
173    */ 
174    
175    /* 
176    return true;
177 }
178
179 */
180
181
182
183 //-----------------------------------------------------------------------------