2 //-----------------------------------------------------------------------------
4 #include "gdcmDocEntrySet.h"
5 #include "gdcmException.h"
7 //-----------------------------------------------------------------------------
8 // Constructor / Destructor
10 * \ingroup gdcmDocEntrySEt
11 * \brief Constructor from a given gdcmDocEntrySet
13 gdcmDocEntrySet::gdcmDocEntrySet() {
16 * \brief Canonical destructor.
18 gdcmDocEntrySet::~gdcmDocEntrySet(){
20 //-----------------------------------------------------------------------------
23 * \ingroup gdcmDocEntrySet
24 * \brief canonical Printer
28 //-----------------------------------------------------------------------------
32 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
39 * \brief Parses an EntrySet (Document header or SQ Item )
40 * \ and load element values (a voir !)
41 * @return false anything wrong happens
43 bool gdcmDocEntrySet::LoadDocEntrySet(bool exception_on_error)
44 throw(gdcmFormatError) {
45 (void)exception_on_error;
47 gdcmDocEntry *newDocEntry = (gdcmDocEntry *)0;
48 gdcmValEntry *newValEntry = (gdcmValEntry *)0;
49 gdcmBinEntry *newBinEntry = (gdcmBinEntry *)0;
50 gdcmSeqEntry *newSeqEntry = (gdcmSeqEntry *)0;
51 //gdcmDictEntry *NewTag = (gdcmDictEntry *)0;
53 while (newDocEntry = ReadNextDocEntry())) {
54 // TODO (?) : liberation du DocEntry ainsi cree,
55 // apres copie dans un ValEntry, SeqEntry, BinEntry
56 vr = newDocEntry->getVR();
61 newSeqEntry = (gdcmSeqEntry *)0;
63 dbg.Verbose(1, "gdcmDocEntrySet::LoadDocEntrySet",
64 "failed to allocate gdcmSeqEntry");
67 newSeqEntry->Copy(newDocEntry);
69 // SEQUENCE; appel 'récursif' de ??? pour charger la 'valeur'
70 // (ensemble d' ITEMs, en fait,
71 // chaque ITEM etant chargé avec LoadDocEntrySet)
73 SkipDocEntry(newSeqEntry); // voir ce qu'on fait pour une SeQuence
74 AddDocEntry(newSeqEntry);
76 } else if (vr == "AE" || vr == "AS" || vr == "DA" || vr == "PN" ||
77 vr == "UI" || vr == "TM" ) {
80 newValEntry = (gdcmValEntry *)0;
82 dbg.Verbose(1, "gdcmDocEntrySet::LoadDocEntrySet",
83 "failed to allocate gdcmValEntry");
86 newValEntry->Copy(newDocEntry);
87 SkipDocEntry(newValEntry);
88 AddDocEntry(newValEntry);
93 NewBinEntry = new gdcmBinEntry(DictEntry);
95 dbg.Verbose(1, "gdcmDocEntrySet::LoadDocEntrySet",
96 "failed to allocate gdcmBinEntry");
99 newBinEntry->Copy(newDocEntry);
100 SkipDocEntry(newBinEntry);
101 AddDocEntry(newBinEntry);
107 // TODO : il n'y a plus de Chained List qui contient toutes les Entries
108 // Le chargement des valeurs devra se faire à la volée
109 // Be carefull : merging this two loops may cause troubles ...
110 for (ListTag::iterator i = GetListEntry().begin();
111 i != GetListEntry().end();
118 // --------------------------------------------------------------
119 // Special Patch to allow gdcm to read ACR-LibIDO formated images
121 // if recognition code tells us we deal with a LibIDO image
122 // we switch lineNumber and columnNumber
125 RecCode = GetEntryByNumber(0x0008, 0x0010); // recognition code
126 if (RecCode == "ACRNEMA_LIBIDO_1.1" ||
127 RecCode == "CANRME_AILIBOD1_1." ) // for brain-damaged softwares
128 // with "little-endian strings"
130 filetype = ACR_LIBIDO;
131 std::string rows = GetEntryByNumber(0x0028, 0x0010);
132 std::string columns = GetEntryByNumber(0x0028, 0x0011);
133 SetEntryByNumber(columns, 0x0028, 0x0010);
134 SetEntryByNumber(rows , 0x0028, 0x0011);
136 // ----------------- End of Special Patch ----------------
143 * \brief Check the correspondance between the VR of the header entry
144 * and the taken VR. If they are different, the header entry is
145 * updated with the new VR.
146 * @param Entry Header Entry to check
147 * @param vr Dicom Value Representation
148 * @return false if the VR is incorrect of if the VR isn't referenced
149 * otherwise, it returns true
152 // NE MARCHE PAS EN L'ETAT :
153 // On a besoin de VR pour 'fabriquer', au choix ValEntry, BinEntry, ou SeqEntry.
156 bool gdcmDocEntrySet::CheckEntryVR(gdcmHeaderEntry *Entry, VRKey vr)
158 char msg[100]; // for sprintf
159 bool RealExplicit = true;
161 // Assume we are reading a falsely explicit VR file i.e. we reached
162 // a tag where we expect reading a VR but are in fact we read the
163 // first to bytes of the length. Then we will interogate (through find)
164 // the dicom_vr dictionary with oddities like "\004\0" which crashes
165 // both GCC and VC++ implementations of the STL map. Hence when the
166 // expected VR read happens to be non-ascii characters we consider
167 // we hit falsely explicit VR tag.
169 if ( (!isalpha(vr[0])) && (!isalpha(vr[1])) )
170 RealExplicit = false;
172 // CLEANME searching the dicom_vr at each occurence is expensive.
173 // PostPone this test in an optional integrity check at the end
174 // of parsing or only in debug mode.
175 if ( RealExplicit && !gdcmGlobal::GetVR()->Count(vr) )
180 // We thought this was explicit VR, but we end up with an
181 // implicit VR tag. Let's backtrack.
182 sprintf(msg,"Falsely explicit vr file (%04x,%04x)\n",
183 Entry->GetGroup(),Entry->GetElement());
184 dbg.Verbose(1, "gdcmParser::FindVR: ",msg);
185 if (Entry->GetGroup()%2 && Entry->GetElement() == 0x0000) { // Group length is UL !
186 gdcmDictEntry* NewEntry = NewVirtualDictEntry(
187 Entry->GetGroup(),Entry->GetElement(),
188 "UL","FIXME","Group Length");
189 Entry->SetDictEntry(NewEntry);
194 if ( Entry->IsVRUnknown() )
196 // When not a dictionary entry, we can safely overwrite the VR.
197 if (Entry->GetElement() == 0x0000) { // Group length is UL !
203 else if ( Entry->GetVR() != vr )
205 // The VR present in the file and the dictionary disagree. We assume
206 // the file writer knew best and use the VR of the file. Since it would
207 // be unwise to overwrite the VR of a dictionary (since it would
208 // compromise it's next user), we need to clone the actual DictEntry
209 // and change the VR for the read one.
210 gdcmDictEntry* NewEntry = NewVirtualDictEntry(
211 Entry->GetGroup(),Entry->GetElement(),
212 vr,"FIXME",Entry->GetName());
213 Entry->SetDictEntry(NewEntry);
221 //-----------------------------------------------------------------------------