-string ElValSet::GetElValueByNumber(guint32 group, guint32 element) {
- TagKey key = gdcmDictEntry::TranslateToKey(group, element);
- if ( ! tagHt.count(key))
- return "gdcm::Unfound";
- if (tagHt.count(key) > 1)
- dbg.Verbose(0, "ElValSet::GetElValueByNumber",
- "multiple entries for this key (FIXME) !");
- return tagHt.find(key)->second->GetValue();
-}
-
-string ElValSet::GetElValueByName(string TagName) {
- if ( ! NameHt.count(TagName))
- return "gdcm::Unfound";
- if (NameHt.count(TagName) > 1)
- dbg.Verbose(0, "ElValSet::GetElValue",
- "multipe entries for this key (FIXME) !");
- return NameHt.find(TagName)->second->GetValue();
-}
-
-int ElValSet::SetElValueByNumber(string content, guint32 group, guint32 element) {
- TagKey key = gdcmDictEntry::TranslateToKey(group, element);
- if ( ! tagHt.count(key))
- return 0;
- if (tagHt.count(key) > 1) {
- dbg.Verbose(0, "ElValSet::SetElValueByNumber",
- "multiple entries for this key (FIXME) !");
- return (0);
- }
- tagHt[key]->SetValue(content);
- // Question : m à j LgrElem ?
- tagHt[key]->SetLength(strlen(content.c_str()));
- // Ou trouver les fonctions d'une classe donnée?
- // lgr d'une string, p.ex
- return(1);
-}
-
-
-int ElValSet::SetElValueByName(string content, string TagName) {
- if ( ! NameHt.count(TagName))
- return 0;
- if (NameHt.count(TagName) > 1) {
- dbg.Verbose(0, "ElValSet::SetElValue",
- "multipe entries for this key (FIXME) !");
- return 0;
- }
- NameHt.find(TagName)->second->SetValue(content);
- NameHt.find(TagName)->second->SetLength(strlen(content.c_str()));
- return(1);
-}
-
-
-
-int ElValSet::Write(FILE * _fp) {
-
-// ATTENTION : fonction non terminée (commitée a titre de precaution)
-
- guint16 gr, el;
- guint32 lgr;
- const char * val;
- string vr;
- guint32 val_int32;
- guint16 val_int16;
- void *ptr;
-
- string implicitVRTransfertSyntax = "1.2.840.10008.1.2";
-
-/* // Utilisées pour le calcul Group Length
- int deja = 0;
- guint32 lgrCalcGroupe;
- ElValue * elemZ, *elemZPrec;
- guint16 grCourant = 0;
-
-*/
+/**
+ * \ingroup gdcmElValSet
+ * \brief
+ * @param group
+ * @param element
+ * @return
+ */
+string gdcmElValSet::GetElValueByNumber(guint16 group, guint16 element) {
+ TagKey key = gdcmDictEntry::TranslateToKey(group, element);
+ if ( ! tagHt.count(key))
+ return GDCM_UNFOUND;
+ return tagHt.find(key)->second->GetValue();
+}
+
+/**
+ * \ingroup gdcmElValSet
+ * \brief
+ * @return
+ */
+string gdcmElValSet::GetElValueByName(string TagName) {
+ if ( ! NameHt.count(TagName))
+ return GDCM_UNFOUND;
+ return NameHt.find(TagName)->second->GetValue();
+}
+
+/**
+ * \ingroup gdcmElValSet
+ * \brief
+ * @param content
+ * @param group
+ * @param element
+ * @return
+ */
+int gdcmElValSet::SetElValueByNumber(string content,
+ guint16 group, guint16 element) {
+ TagKey key = gdcmDictEntry::TranslateToKey(group, element);
+ if ( ! tagHt.count(key))
+ return 0;
+ tagHt[key]->SetValue(content);
+ string vr = tagHt[key]->GetVR();
+ guint32 lgr;
+
+ if( (vr == "US") || (vr == "SS") )
+ lgr = 2;
+ else if( (vr == "UL") || (vr == "SL") )
+ lgr = 4;
+ else
+ lgr = content.length();
+ tagHt[key]->SetLength(lgr);
+ return 1;
+}
+
+/**
+ * \ingroup gdcmElValSet
+ * \brief
+ * @param content
+ * @param TagName
+ * @return
+ */
+int gdcmElValSet::SetElValueByName(string content, string TagName) {
+ if ( ! NameHt.count(TagName))
+ return 0;
+ NameHt[TagName]->SetValue(content);
+ string vr = NameHt[TagName]->GetVR();
+ guint32 lgr;
+
+ if( (vr == "US") || (vr == "SS") )
+ lgr = 2;
+ else if( (vr == "UL") || (vr == "SL") )
+ lgr = 4;
+ else
+ lgr = content.length();
+
+// TODO : WARNING: le cas de l'element des pixels (7fe0,0010) n'est pas traite
+// par SetElValueByName
+// il faudra utiliser SetElValueByNumber
+
+ NameHt[TagName]->SetLength(lgr);
+ return 1;
+}
+
+/**
+ * \ingroup gdcmElValSet
+ * \brief Generate a free TagKey i.e. a TagKey that is not present
+ * in the TagHt dictionary.
+ * @param group The generated tag must belong to this group.
+ * @return The element of tag with given group which is fee.
+ */
+guint32 gdcmElValSet::GenerateFreeTagKeyInGroup(guint16 group) {
+ for (guint32 elem = 0; elem < UINT32_MAX; elem++) {
+ TagKey key = gdcmDictEntry::TranslateToKey(group, elem);
+ if (tagHt.count(key) == 0)
+ return elem;
+ }
+ return UINT32_MAX;
+}
+
+/**
+ * \ingroup gdcmElValSet
+ * \brief
+ * @param area
+ * @param group
+ * @param element
+ * @return
+ */
+int gdcmElValSet::SetVoidAreaByNumber(void * area,
+ guint16 group, guint16 element) {
+ TagKey key = gdcmDictEntry::TranslateToKey(group, element);
+ if ( ! tagHt.count(key))
+ return 0;
+ tagHt[key]->SetVoidArea(area);
+ return 1 ;
+}
+
+/**
+ * \ingroup gdcmElValSet
+ * \brief
+ * @param length
+ * @param group
+ * @param element
+ * @return int acts as a boolean
+ */
+int gdcmElValSet::SetElValueLengthByNumber(guint32 length,
+ guint16 group, guint16 element) {
+ TagKey key = gdcmDictEntry::TranslateToKey(group, element);
+ if ( ! tagHt.count(key))
+ return 0;
+ tagHt[key]->SetLength(length);
+ return 1 ;
+}
+/**
+ * \ingroup gdcmElValSet
+ * \brief
+ * @param length
+ * @param TagName
+ * @return
+ */
+int gdcmElValSet::SetElValueLengthByName(guint32 length, string TagName) {
+ if ( ! NameHt.count(TagName))
+ return 0;
+ NameHt.find(TagName)->second->SetLength(length);
+ return 1 ;
+}
+
+/**
+ * \ingroup gdcmElValSet
+ * \brief Re-computes the length of a ACR-NEMA/Dicom group from a DcmHeader
+ * @param SkipSequence TRUE if we don't want to write Sequences (ACR-NEMA Files)
+ * @param type
+ */
+void gdcmElValSet::UpdateGroupLength(bool SkipSequence, FileType type) {
+ guint16 gr, el;
+ string vr;
+
+ gdcmElValue *elem;
+ char trash[10];
+ string str_trash;
+
+ GroupKey key;
+ GroupHT groupHt; // to hold the length of each group
+ TagKey tk;
+ // remember :
+ // typedef std::map<GroupKey, int> GroupHT;
+
+ gdcmElValue *elemZ;
+
+ // for each Tag in the DCM Header
+
+ for (TagElValueHT::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)
+
+ // pas SEQUENCE en 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);
+ 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 gdcmElValue(tagZ);
+ elemZ->SetLength(4);
+ Add(elemZ); // create it
+ } else {
+ elemZ=GetElementByNumber(gr_bid, 0x0000);
+ }
+ sprintf(trash ,"%d",g->second);
+ str_trash=trash;
+ elemZ->SetValue(str_trash);
+ }
+}
+
+/**
+ * \ingroup gdcmElValSet
+ * \brief
+ * @param type
+ * @param _fp
+ * @return
+ */
+void gdcmElValSet::WriteElements(FileType type, FILE * _fp) {
+ guint16 gr, el;
+ guint32 lgr;
+ const char * val;
+ string vr;
+ guint32 val_uint32;
+ guint16 val_uint16;
+
+ vector<string> tokens;
+
+ void *ptr;
+
+ // Tout ceci ne marche QUE parce qu'on est sur un proc Little Endian
+ // restent à tester les echecs en écriture (apres chaque fwrite)
+
+ for (TagElValueHT::iterator tag2=tagHt.begin();
+ tag2 != tagHt.end();
+ ++tag2){
+
+ gr = tag2->second->GetGroup();
+ el = tag2->second->GetElement();
+ lgr = tag2->second->GetLength();
+ val = tag2->second->GetValue().c_str();
+ vr = tag2->second->GetVR();
+
+ // cout << "Tag "<< hex << gr << " " << el << "\n";
+
+ if ( type == ACR ) {
+ if (gr < 0x0008) continue; // ignore pure DICOM V3 groups
+ if (gr %2) continue; // ignore shadow groups
+ if (vr == "SQ" ) continue; // ignore Sequences
+ if (gr == 0xfffe ) continue; // ignore delimiters
+ }