- if((*it)->IsImplicitVR())
- vr="Implicit";
- else
- vr=(*it)->GetVR();
-
- (*it)->SetValue(GetHeaderEntryUnvalue(*it));
- if(entry){
- // Set the new entry and the new value
- (*it)->SetDictEntry(entry);
- CheckHeaderEntryVR(*it,vr);
-
- (*it)->SetValue(GetHeaderEntryValue(*it));
- }
- else
- {
- // Remove precedent value transformation
- (*it)->SetDictEntry(NewVirtualDictEntry((*it)->GetGroup(),(*it)->GetElement(),vr));
- }
- }
-}
-
-/**
- * \brief Searches within the Doc Entries for a Dicom Element of
- * a given tag.
- * @param tagName name of the searched Dicom Element.
- * @return Corresponding Dicom Element when it exists, and NULL
- * otherwise.
- */
- gdcmHeaderEntry *gdcmDocument::GetHeaderEntryByName(std::string tagName) {
- gdcmDictEntry *dictEntry = RefPubDict->GetDictEntryByName(tagName);
- if( dictEntry == NULL)
- return NULL;
-
- return(GetHeaderEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement()));
-}
-
-/**
- * \brief retrieves a Dicom Element (the first one) using (group, element)
- * \warning (group, element) IS NOT an identifier inside the Dicom Header
- * if you think it's NOT UNIQUE, check the count number
- * and use iterators to retrieve ALL the Dicoms Elements within
- * a given couple (group, element)
- * @param group Group number of the searched Dicom Element
- * @param element Element number of the searched Dicom Element
- * @return
- */
-gdcmHeaderEntry* gdcmDocument::GetHeaderEntryByNumber(guint16 group, guint16 element)
-{
- TagKey key = gdcmDictEntry::TranslateToKey(group, element);
- if ( ! tagHT.count(key))
- return NULL;
- return tagHT.find(key)->second;
-}
-
-/**
- * \brief retrieves the Dicom Elements (all of them) using (group, element)
- * @param group Group number of the searched Dicom Element.
- * @param element Element number of the searched Dicom Element.
- * @return a range (i.e.pair<,>) containing all elements whose key is group|element)
- */
-
-IterHT gdcmDocument::GetHeaderEntrySameNumber(guint16 group, guint16 element){
- TagKey key = gdcmDictEntry::TranslateToKey(group, element);
- return (tagHT.equal_range(key));
-}
-
-/**
- * \brief Loads the element while preserving the current
- * underlying file position indicator as opposed to
- * to LoadHeaderEntry that modifies it.
- * @param entry Header Entry whose value shall be loaded.
- * @return
- */
-void gdcmDocument::LoadHeaderEntrySafe(gdcmHeaderEntry * entry) {
- long PositionOnEntry = ftell(fp);
- LoadHeaderEntry(entry);
- fseek(fp, PositionOnEntry, SEEK_SET);
-}
-
-/**
- * \brief Re-computes the length of a ACR-NEMA/Dicom group from a DcmHeader
- * \warning : to be re-written using the chained list instead of the H table.
- * \warning : DO NOT use (doesn't work any longer because of the multimap)
- * \todo : to be re-written using the chained list instead of the H table
- * @param SkipSequence TRUE if we don't want to write Sequences (ACR-NEMA Files)
- * @param type Type of the File (ExplicitVR,ImplicitVR, ACR, ...)
- */
-void gdcmDocument::UpdateGroupLength(bool SkipSequence, FileType type) {
- guint16 gr, el;
- std::string vr;
-
- gdcmHeaderEntry *elem;
- char trash[10];
- std::string str_trash;
-
- GroupKey key;
- GroupHT groupHt; // to hold the length of each group
- TagKey tk;
- // remember :
- // typedef std::map<GroupKey, int> GroupHT;
-
- gdcmHeaderEntry *elemZ;
-
- // for each Tag in the DCM Header
-
- for (TagHeaderEntryHT::iterator tag2 = tagHT.begin();
- tag2 != tagHT.end();
- ++tag2)
- {
- elem = tag2->second;
- gr = elem->GetGroup();
- el = elem->GetElement();
- vr = elem->GetVR();
-
- sprintf(trash, "%04x", gr);
- key = trash; // generate 'group tag'
-
- // if the caller decided not to take SEQUENCEs into account
- // e.g : he wants to write an ACR-NEMA File
-
- if (SkipSequence && vr == "SQ")
- continue;
-
- // Still unsolved problem :
- // we cannot find the 'Sequence Delimitation Item'
- // since it's at the end of the Hash Table
- // (fffe,e0dd)
-
- // there is SEQUENCE in ACR-NEMA
- // WARNING :
- // --> la descente a l'interieur' des SQ
- // devrait etre faite avec une liste chainee, pas avec une HTable...
-
- if ( groupHt.count(key) == 0) // we just read the first elem of a given group
- {
- if (el == 0x0000) // the first elem is 0x0000
- {
- groupHt[key] = 0; // initialize group length
- }
- else
- {
- groupHt[key] = 2 + 2 + 4 + elem->GetLength(); // non 0x0000 first group elem
- }
- }
- else // any elem but the first
- {
- if (type == ExplicitVR)
- {
- if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") )
- {
- groupHt[key] += 4; // explicit VR AND OB, OW, SQ : 4 more bytes
- }
- }
- groupHt[key] += 2 + 2 + 4 + elem->GetLength();
- }
- }
-
- unsigned short int gr_bid;
-
- for (GroupHT::iterator g = groupHt.begin(); // for each group we found
- g != groupHt.end();
- ++g)
- {
- // FIXME: g++ -Wall -Wstrict-prototypes reports on following line:
- // warning: unsigned int format, different type arg
- sscanf(g->first.c_str(),"%x",&gr_bid); //FIXME
- tk = g->first + "|0000"; // generate the element full tag
-
- if ( tagHT.count(tk) == 0) // if element 0x0000 not found
- {
- gdcmDictEntry * tagZ = new gdcmDictEntry(gr_bid, 0x0000, "UL");
- elemZ = new gdcmHeaderEntry(tagZ);
- elemZ->SetLength(4);
- AddHeaderEntry(elemZ); // create it
- }
- else
- {
- elemZ=GetHeaderEntryByNumber(gr_bid, 0x0000);
- }
- sprintf(trash ,"%d",g->second);
- str_trash=trash;
- elemZ->SetValue(str_trash);
- }
-}
-
-/**
- * \brief Writes in a file (according to the requested format)
- * the group, the element, the value representation and the length
- * of a single gdcmHeaderEntry passed as argument.
- * @param tag pointer on the gdcmHeaderEntry to be written
- * @param _fp already open file pointer
- * @param type type of the File to be written
- */
-void gdcmDocument::WriteEntryTagVRLength(gdcmHeaderEntry *tag,
- FILE *_fp,
- FileType type)
-{
- guint16 group = tag->GetGroup();
- std::string vr = tag->GetVR();
- guint16 el = tag->GetElement();
- guint32 lgr = tag->GetReadLength();
-
- if ( (group == 0xfffe) && (el == 0x0000) )
- // Fix in order to make some MR PHILIPS images e-film readable
- // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm:
- // we just *always* ignore spurious fffe|0000 tag !
- return;
-
- fwrite ( &group,(size_t)2 ,(size_t)1 ,_fp); //group
- fwrite ( &el,(size_t)2 ,(size_t)1 ,_fp); //element
-
- if ( type == ExplicitVR ) {