1 /*=========================================================================
4 Module: $RCSfile: gdcmSQItem.cxx,v $
6 Date: $Date: 2005/01/30 17:30:57 $
7 Version: $Revision: 1.62 $
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 "gdcmSQItem.h"
20 #include "gdcmSeqEntry.h"
21 #include "gdcmValEntry.h"
22 #include "gdcmBinEntry.h"
23 #include "gdcmGlobal.h"
24 #include "gdcmDictSet.h"
26 #include "gdcmDebug.h"
32 //-----------------------------------------------------------------------------
33 // Constructor / Destructor
35 * \brief Constructor from a given SQItem
37 SQItem::SQItem(int depthLevel )
40 SQDepthLevel = depthLevel;
45 * \brief Canonical destructor.
52 //-----------------------------------------------------------------------------
55 * \brief canonical Printer
56 * @param os Stream to print to.
57 * @param indent Indentation string to be prepended during printing.
59 void SQItem::Print(std::ostream &os, std::string const &)
65 for (int i = 0; i < SQDepthLevel; ++i)
70 os << s.str() << " --- SQItem number " << SQItemNumber << std::endl;
71 for (ListDocEntry::iterator i = DocEntries.begin();
72 i != DocEntries.end();
76 bool PrintEndLine = true;
79 Entry->SetPrintLevel(PrintLevel);
81 if ( dynamic_cast<SeqEntry*>(Entry) )
93 * \brief canonical Writer
94 * @param fp file pointer to an already open file.
95 * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...)
97 void SQItem::WriteContent(std::ofstream *fp, FileType filetype)
100 uint16_t item[4] = { 0xfffe, 0xe000, 0xffff, 0xffff };
101 uint16_t itemt[4]= { 0xfffe, 0xe00d, 0xffff, 0xffff };
103 //we force the writting of an 'Item' Start Element
104 // because we want to write the Item as a 'no Length' item
107 binary_write( *fp, item[j]); // fffe e000 ffff ffff
110 for (ListDocEntry::iterator it = DocEntries.begin();
111 it != DocEntries.end();
114 // we skip delimitors (start and end one) because
115 // we force them as 'no length'
116 if ( (*it)->GetGroup() == 0xfffe )
121 // Fix in order to make some MR PHILIPS images e-film readable
122 // see gdcmData/gdcm-MR-PHILIPS-16-Multi-Seq.dcm:
123 // we just *always* ignore spurious fffe|0000 tag !
124 if ( (*it)->GetGroup() == 0xfffe && (*it)->GetElement() == 0x0000 )
126 break; // FIXME : continue; ?!?
129 (*it)->WriteContent(fp, filetype);
132 //we force the writting of an 'Item Delimitation' item
133 // because we wrote the Item as a 'no Length' item
136 binary_write( *fp, itemt[j]); // fffe e000 ffff ffff
141 //-----------------------------------------------------------------------------
144 * \brief Remove all entry in the Sequence Item
146 void SQItem::ClearEntry()
148 for(ListDocEntry::iterator cc = DocEntries.begin();
149 cc != DocEntries.end();
158 * \brief adds any Entry (Dicom Element) to the Sequence Item
159 * @param entry Entry to add
161 bool SQItem::AddEntry(DocEntry *entry)
163 DocEntries.push_back(entry);
168 * \brief Clear the std::list from given entry AND delete the entry.
169 * @param entryToRemove Entry to remove AND delete.
170 * @return true if the entry was found and removed; false otherwise
172 bool SQItem::RemoveEntry( DocEntry *entryToRemove)
174 for(ListDocEntry::iterator it = DocEntries.begin();
175 it != DocEntries.end();
178 if( *it == entryToRemove)
180 DocEntries.erase(it);
181 gdcmVerboseMacro( "One element erased: " << entryToRemove->GetKey() );
182 delete entryToRemove;
186 gdcmVerboseMacro( "Entry not found: " << entryToRemove->GetKey() );
191 * \brief Clear the std::list from given entry BUT keep the entry.
192 * @param entryToRemove Entry to remove.
193 * @return true if the entry was found and removed; false otherwise
195 bool SQItem::RemoveEntryNoDestroy(DocEntry *entryToRemove)
197 for(ListDocEntry::iterator it = DocEntries.begin();
198 it != DocEntries.end();
201 if( *it == entryToRemove)
203 DocEntries.erase(it);
204 gdcmVerboseMacro( "One element erased, no destroyed: "
205 << entryToRemove->GetKey() );
210 gdcmVerboseMacro( "Entry not found:" << entryToRemove->GetKey() );
215 * \brief Get the first Dicom entry while visiting the SQItem
216 * \return The first DocEntry if found, otherwhise 0
218 DocEntry *SQItem::GetFirstEntry()
220 ItDocEntries = DocEntries.begin();
221 if (ItDocEntries != DocEntries.end())
222 return *ItDocEntries;
227 * \brief Get the next Dicom entry while visiting the chained list
228 * \return The next DocEntry if found, otherwhise NULL
230 DocEntry *SQItem::GetNextEntry()
233 if (ItDocEntries != DocEntries.end())
234 return *ItDocEntries;
239 * \brief Gets a Dicom Element inside a SQ Item Entry
240 * @param group Group number of the Entry
241 * @param elem Element number of the Entry
242 * @return Entry whose (group,elem) was passed. 0 if not found
244 DocEntry *SQItem::GetDocEntry(uint16_t group, uint16_t elem)
246 for(ListDocEntry::iterator i = DocEntries.begin();
247 i != DocEntries.end(); ++i)
249 if ( (*i)->GetGroup() == group && (*i)->GetElement() == elem )
255 //-----------------------------------------------------------------------------
258 //-----------------------------------------------------------------------------
262 //-----------------------------------------------------------------------------
264 } // end namespace gdcm