2 //-----------------------------------------------------------------------------
3 #include "gdcmObject.h"
6 //-----------------------------------------------------------------------------
7 // Constructor / Destructor
11 * @param begin iterator on the first Header Entry (i.e Dicom Element)
12 * related to this 'Object'
13 * @param end iterator on the last Header Entry
14 * (i.e Dicom Element) related to this 'Object'
15 * @param ptagHT pointer to the HTable (gdcmObject needs it
16 * to build the gdcmHeaderEntries)
17 * @param plistEntries pointer to the chained List (gdcmObject needs it
18 * to build the gdcmHeaderEntries)
20 gdcmObject::gdcmObject(ListTag::iterator begin, ListTag::iterator end,
21 TagHeaderEntryHT *ptagHT, ListTag *plistEntries) {
24 this->ptagHT = ptagHT;
25 this->plistEntries = plistEntries;
27 dbg.Verbose(0, "gdcmObject::gdcmObject empty list");
32 * \brief Canonical destructor.
34 gdcmObject::~gdcmObject(void) {
37 //-----------------------------------------------------------------------------
41 * \brief Prints the Object
44 void gdcmObject::Print(std::ostream &os) {
47 //for(ListTag::iterator i=beginObj;i!=endObj;++i) // JPR
48 for(i=beginObj;;++i) {
49 (*i)->SetPrintLevel(printLevel);
51 if (i == endObj) break;
56 //-----------------------------------------------------------------------------
60 * \brief Get the value of an Header Entries (i.e Dicom Element) by number
63 std::string gdcmObject::GetEntryByNumber(guint16 group, guint16 element) {
64 //for(ListTag::iterator i=beginObj;i!=endObj;++i) // JPR
65 for(ListTag::iterator i=beginObj;;++i) {
66 if ( (*i)->GetGroup()==group && (*i)->GetElement()==element)
67 return (*i)->GetValue();
68 if (i == endObj) break;
75 * \brief Get the value of an Header Entries (i.e Dicom Element) by name
76 * @param name : name of the searched element.
79 std::string gdcmObject::GetEntryByName(TagName name) {
80 gdcmDict *PubDict=gdcmGlobal::GetDicts()->GetDefaultPubDict();
81 gdcmDictEntry *dictEntry = (*PubDict).GetDictEntryByName(name);
83 if( dictEntry == NULL)
85 return GetEntryByNumber(dictEntry->GetGroup(),dictEntry->GetElement());
90 * \brief Sets Entry (Dicom Element) value of an element,
91 * specified by it's tag (Group, Number)
92 * and the length, too ...
93 * If the Element is not found, it's just created !
94 * \warning we suppose, right now, the element belongs to a Public Group
96 * @param val string value to set
97 * @param group Group of the searched tag.
98 * @param element Element of the searched tag.
99 * @return true if element was found or created successfully
101 bool gdcmObject::SetEntryByNumber(std::string val,guint16 group,
105 for(ListTag::iterator i=beginObj;;++i) {
106 if ( (*i)->GetGroup() == 0xfffe && (*i)->GetElement() == 0xe000 )
108 if ( group < (*i)->GetGroup() ||
109 (group == (*i)->GetGroup() && element < (*i)->GetElement()) ){
110 // instead of ReplaceOrCreateByNumber
111 // that is a method of gdcmParser :-(
112 gdcmHeaderEntry *Entry;
113 TagKey key = gdcmDictEntry::TranslateToKey(group, element);
114 if ( ! ptagHT->count(key)) {
115 // we assume the element belongs to a Public Group (not a shadow one)
116 // we assume a Public Dictionnary *is* loaded
117 gdcmDict *PubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict();
118 // if the invoqued (group,elem) doesn't exist inside the Dictionary
119 // we create a VirtualDictEntry
120 gdcmDictEntry *DictEntry = PubDict->GetDictEntryByNumber(group, element);
121 if (DictEntry == NULL) {
122 DictEntry=gdcmGlobal::GetDicts()->NewVirtualDictEntry(group,element,"UN","??","??");
124 // we assume the constructor didn't fail
125 Entry = new gdcmHeaderEntry(DictEntry);
129 // better we don't assume too much !
130 // in the next release, gdcmObject will be used
131 // to describe any Header Entry ...
133 Entry = ptagHT->find(key)->second;
135 Entry->SetValue(val);
136 Entry->SetLength(val.length());
137 plistEntries->insert(i,Entry);
140 if (group == (*i)->GetGroup() && element == (*i)->GetElement() ) {
142 (*i)->SetLength(val.length());
148 * \ingroup gdcmObject
149 * \brief Builds a hash table (multimap) containing
150 * pointers to all Header Entries (i.e Dicom Element)
151 * related to this 'object'
154 TagHeaderEntryHT gdcmObject::GetEntry(void) {
156 //for(ListTag::iterator i=beginObj;i!=endObj;++i) // JPR
157 for(ListTag::iterator i=beginObj;;++i) {
158 HT.insert( PairHT( (*i)->GetKey(),(*i)) );
159 if (i == endObj) break;
165 * \ingroup gdcmObject
166 * \brief Builds a Chained List containing
167 * pointers to all Header Entries (i.e Dicom Element)
168 * related to this 'object'
171 ListTag gdcmObject::GetListEntry(void) {
173 //for(ListTag::iterator i=beginObj;i!=endObj;++i) // JPR
174 for(ListTag::iterator i=beginObj;;++i) {
176 if (i == endObj) break;
182 //-----------------------------------------------------------------------------
185 * \ingroup gdcmObject
186 * \brief add the 'Object' related Dicom Elements to the listEntries
187 * of a partially created DICOMDIR
189 void gdcmObject::FillObject(std::list<gdcmElement> elemList) {
190 std::list<gdcmElement>::iterator it;
192 gdcmDictEntry *dictEntry;
193 gdcmHeaderEntry *entry;
195 debInsertion = this->fin();
197 finInsertion=debInsertion;
199 for(it=elemList.begin();it!=elemList.end();++it)
203 dictEntry=gdcmGlobal::GetDicts()->GetDefaultPubDict()->GetDictEntryByNumber(tmpGr,tmpEl);
204 entry=new gdcmHeaderEntry(dictEntry);
205 entry->SetOffset(0); // just to avoid missprinting //JPR
206 entry->SetValue(it->value);
208 if(dictEntry->GetGroup()==0xfffe)
210 entry->SetLength(entry->GetValue().length());
212 else if( (dictEntry->GetVR()=="UL") || (dictEntry->GetVR()=="SL") )
216 else if( (dictEntry->GetVR()=="US") || (dictEntry->GetVR()=="SS") )
220 else if(dictEntry->GetVR()=="SQ")
222 entry->SetLength(0xffffffff);
226 entry->SetLength(entry->GetValue().length());
228 ptagHT->insert( PairHT(entry->GetKey(),entry) ); // add in the (multimap) H Table
229 plistEntries->insert(debInsertion ,entry); // en tete de liste des Patients
238 //-----------------------------------------------------------------------------
241 //-----------------------------------------------------------------------------