- * @param element Element number of the searched Dicom Element
- * @return
- */
-gdcmDocEntry* gdcmDocument::GetDocEntryByNumber(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::GetDocEntrySameNumber(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 LoadDocEntry that modifies it.
- * @param entry Header Entry whose value shall be loaded.
- * @return
- */
-void gdcmDocument::LoadDocEntrySafe(gdcmDocEntry * entry) {
- long PositionOnEntry = ftell(fp);
- LoadDocEntry(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, ...)
- */
-
- /* Probabely useless, now !
-
-void gdcmDocument::UpdateGroupLength(bool SkipSequence, FileType type) {
- guint16 gr, el;
- std::string vr;
-
- gdcmDocEntry *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;
-
- gdcmDocEntry *elemZ;
-
- // for each Tag in the DCM Header
-
- for (TagDocEntryHT::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 gdcmDocEntry(tagZ);
- elemZ->SetLength(4);
- AddEntry(elemZ); // create it
- }
- else
- {
- elemZ=GetDocEntryByNumber(gr_bid, 0x0000);
- }
- sprintf(trash ,"%d",g->second);
- str_trash=trash;
- //elemZ->SetValue(str_trash); // to go on compiling
- }
-}
-
-*/
-
-/**
- * \brief Writes in a file (according to the requested format)
- * the group, the element, the value representation and the length
- * of a single gdcmDocEntry passed as argument.
- * @param tag pointer on the gdcmDocEntry to be written
- * @param _fp already open file pointer
- * @param type type of the File to be written
- */
-void gdcmDocument::WriteEntryTagVRLength(gdcmDocEntry *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 == gdcmExplicitVR ) {
-
- // Special case of delimiters:
- if (group == 0xfffe) {
- // Delimiters have NO Value Representation and have NO length.
- // Hence we skip writing the VR and length and we pad by writing
- // 0xffffffff
-
- int ff=0xffffffff;
- fwrite (&ff,(size_t)4 ,(size_t)1 ,_fp);
- return;
- }
-
- guint16 z=0;
- guint16 shortLgr = lgr;
- if (vr == "unkn") { // Unknown was 'written'
- // deal with Little Endian
- fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,_fp);
- fwrite ( &z, (size_t)2 ,(size_t)1 ,_fp);
- } else {
- fwrite (vr.c_str(),(size_t)2 ,(size_t)1 ,_fp);
- if ( (vr == "OB") || (vr == "OW") || (vr == "SQ") )
- {
- fwrite ( &z, (size_t)2 ,(size_t)1 ,_fp);
- fwrite ( &lgr,(size_t)4 ,(size_t)1 ,_fp);
- } else {
- fwrite ( &shortLgr,(size_t)2 ,(size_t)1 ,_fp);
- }
- }
- }
- else // IMPLICIT VR
- {
- fwrite ( &lgr,(size_t)4 ,(size_t)1 ,_fp);
- }
-}
-
-/**
- * \brief Writes in a file (according to the requested format)
- * the value of a single gdcmDocEntry passed as argument.
- * @param tag Pointer on the gdcmDocEntry to be written
- * @param _fp Already open file pointer
- * @param type type of the File to be written
- */
-
- // TODO : to be re -written recursively !
-
-void gdcmDocument::WriteEntryValue(gdcmDocEntry *tag, FILE *_fp,FileType type)
-{
- (void)type;
- guint16 group = tag->GetGroup();
- std::string vr = tag->GetVR();
- guint32 lgr = tag->GetReadLength();
-
- if (vr == "SQ")
- // SeQuences have no value:
- return;
- if (group == 0xfffe)
- // Delimiters have no associated value:
- return;
-
- void *voidArea;
- // voidArea = tag->GetVoidArea();
- // to go on compiling
- if (voidArea != NULL)
- { // there is a 'non string' LUT, overlay, etc
- fwrite ( voidArea,(size_t)lgr ,(size_t)1 ,_fp); // Elem value
- return;
- }
-
- if (vr == "US" || vr == "SS")
- {
- // some 'Short integer' fields may be mulivaluated
- // each single value is separated from the next one by '\'
- // we split the string and write each value as a short int
- std::vector<std::string> tokens;
- tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
- Tokenize (tag->GetValue(), tokens, "\\");
- for (unsigned int i=0; i<tokens.size();i++)
- {
- guint16 val_uint16 = atoi(tokens[i].c_str());
- void *ptr = &val_uint16;
- fwrite ( ptr,(size_t)2 ,(size_t)1 ,_fp);
- }
- tokens.clear();
- return;
- }
- // some 'Integer' fields may be mulivaluated
- // each single value is separated from the next one by '\'
- // we split the string and write each value as an int
- if (vr == "UL" || vr == "SL")
- {
- std::vector<std::string> tokens;
- tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
- Tokenize (tag->GetValue(), tokens, "\\");
- for (unsigned int i=0; i<tokens.size();i++)
- {
- guint32 val_uint32 = atoi(tokens[i].c_str());
- void *ptr = &val_uint32;
- fwrite ( ptr,(size_t)4 ,(size_t)1 ,_fp);
- }
- tokens.clear();
- return;
- }
- fwrite (tag->GetValue().c_str(), (size_t)lgr ,(size_t)1, _fp); // Elem value
-}
-
-/**
- * \brief Writes in a file (according to the requested format)
- * a single gdcmDocEntry passed as argument.
- * \sa WriteEntryValue, WriteEntryTagVRLength.
- * @param tag Pointer on the gdcmDocEntry to be written
- * @param _fp Already open file pointer
- * @param type type of the File to be written