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