1 /*=========================================================================
4 Module: $RCSfile: gdcmElementSet.cxx,v $
6 Date: $Date: 2005/10/26 06:07:26 $
7 Version: $Revision: 1.68 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #include "gdcmElementSet.h"
20 #include "gdcmDebug.h"
21 #include "gdcmSeqEntry.h"
22 #include "gdcmDataEntry.h"
26 //-----------------------------------------------------------------------------
27 // Constructor / Destructor
29 * \brief Constructor for a given ElementSet
31 ElementSet::ElementSet()
37 * \brief Canonical destructor.
39 ElementSet::~ElementSet()
44 //-----------------------------------------------------------------------------
47 * \brief Writes the Header Entries (Dicom Elements)
49 * @param fp ofstream to write to
50 * @param filetype filetype
52 void ElementSet::WriteContent(std::ofstream *fp, FileType filetype)
54 for (TagDocEntryHT::const_iterator i = TagHT.begin();
58 // FIXME : find a trick to know if current object is a
59 // gdcm::File or a gdcm::Document
60 //if ( dynamic_cast< File* > ( this ) ) { // ignore illegal groups }
62 // Skip 'Group Length' element, since it may be wrong.
63 // except for Group 0002
64 if ( (i->second)->GetElement() == 0x0000
65 && (i->second)->GetElement() != 0x0002 )
68 i->second->WriteContent(fp, filetype);
73 * \brief add a new Dicom Element pointer to the H Table
74 * @param newEntry entry to add
76 bool ElementSet::AddEntry(DocEntry *newEntry)
78 const TagKey &key = newEntry->GetKey();
80 if ( TagHT.count(key) == 1 )
82 gdcmWarningMacro( "Key already present: " << key );
87 TagHT.insert(TagDocEntryHT::value_type(newEntry->GetKey(), newEntry));
94 * \brief Clear the hash table from given entry AND delete the entry.
95 * @param entryToRemove Entry to remove AND delete.
97 bool ElementSet::RemoveEntry( DocEntry *entryToRemove)
99 const TagKey &key = entryToRemove->GetKey();
100 if ( TagHT.count(key) == 1 )
103 entryToRemove->Unregister();
107 gdcmWarningMacro( "Key not present : " << key);
112 * \brief delete all entries in the ElementSet
114 void ElementSet::ClearEntry()
116 for(TagDocEntryHT::iterator cc = TagHT.begin();cc != TagHT.end(); ++cc)
120 cc->second->Unregister();
127 * \brief Get the first entry while visiting *the* 'zero level' DocEntrySet
128 * (DocEntries out of any Sequence)
129 * \return The first DocEntry if found, otherwhise NULL
131 DocEntry *ElementSet::GetFirstEntry()
133 ItTagHT = TagHT.begin();
134 if (ItTagHT != TagHT.end())
135 return ItTagHT->second;
140 * \brief Get the next entry while visiting *the* 'zero level' DocEntrySet
141 * (DocEntries out of any Sequence)
142 * \note : meaningfull only if GetFirstEntry already called
143 * \return The next DocEntry if found, otherwhise NULL
145 DocEntry *ElementSet::GetNextEntry()
147 gdcmAssertMacro (ItTagHT != TagHT.end());
150 if (ItTagHT != TagHT.end())
151 return ItTagHT->second;
156 * \brief retrieves a Dicom Element using (group, element)
157 * @param group Group number of the searched Dicom Element
158 * @param elem Element number of the searched Dicom Element
161 DocEntry *ElementSet::GetDocEntry(uint16_t group, uint16_t elem)
163 TagKey key = DictEntry::TranslateToKey(group, elem);
164 TagDocEntryHT::iterator it = TagHT.find(key);
166 if ( it!=TagHT.end() )
171 //-----------------------------------------------------------------------------
174 //-----------------------------------------------------------------------------
177 //-----------------------------------------------------------------------------
180 * \brief Prints the Header Entries (Dicom Elements) from the H Table
181 * @param os ostream to write to
182 * @param indent Indentation string to be prepended during printing
184 void ElementSet::Print(std::ostream &os, std::string const & )
186 // Let's change the 'warning value' for Pixel Data,
187 // to avoid human reader to be confused by 'gdcm::NotLoaded'.
188 DataEntry *pixelElement = GetDataEntry(0x7fe0,0x0010);
189 if ( pixelElement != 0 )
191 pixelElement->SetFlag( DataEntry::FLAG_PIXELDATA );
194 for( TagDocEntryHT::const_iterator i = TagHT.begin(); i != TagHT.end(); ++i)
196 DocEntry *entry = i->second;
198 entry->SetPrintLevel(PrintLevel);
201 if ( dynamic_cast<SeqEntry *>(entry) )
203 // Avoid the newline for a sequence:
210 //-----------------------------------------------------------------------------
211 } // end namespace gdcm