1 /*=========================================================================
4 Module: $RCSfile: gdcmSeqEntry.cxx,v $
6 Date: $Date: 2005/01/24 16:10:53 $
7 Version: $Revision: 1.50 $
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 "gdcmSeqEntry.h"
20 #include "gdcmSQItem.h"
22 #include "gdcmGlobal.h"
24 #include "gdcmDebug.h"
33 //-----------------------------------------------------------------------------
34 // Constructor / Destructor
36 * \brief Constructor from a given SeqEntry
38 SeqEntry::SeqEntry( DictEntry *e )
42 ReadLength = 0xffffffff;
45 DelimitorMode = false;
50 * \brief Constructor from a given SeqEntry
51 * @param e Pointer to existing Doc entry
52 * @param depth depth level of the current Seq entry
54 SeqEntry::SeqEntry( DocEntry *e, int depth )
55 : DocEntry( e->GetDictEntry() )
58 ReadLength = 0xffffffff;
61 ImplicitVR = e->IsImplicitVR();
62 Offset = e->GetOffset();
67 * \brief Canonical destructor.
71 for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc)
81 //-----------------------------------------------------------------------------
84 * \brief canonical Printer
86 void SeqEntry::Print( std::ostream &os, std::string const & )
88 // First, Print the Dicom Element itself.
93 if (GetReadLength() == 0)
96 // Then, Print each SQ Item
97 for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc)
99 (*cc)->SetPrintLevel(PrintLevel);
103 // at end, print the sequence terminator item, if any
106 for ( int i = 0; i < SQDepthLevel; i++ )
112 SeqTerm->SetPrintLevel(PrintLevel);
119 gdcmVerboseMacro(" -------- should have a sequence terminator item");
124 //-----------------------------------------------------------------------------
127 * \brief canonical Writer
128 * @param fp pointer to an already open file
129 * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...)
131 void SeqEntry::WriteContent(std::ofstream *fp, FileType filetype)
133 uint16_t seq_term_gr = 0xfffe;
134 uint16_t seq_term_el = 0xe0dd;
135 uint32_t seq_term_lg = 0xffffffff;
137 //uint16_t item_term_gr = 0xfffe;
138 //uint16_t item_term_el = 0xe00d;
140 DocEntry::WriteContent(fp, filetype);
141 for(ListSQItem::iterator cc = Items.begin();
145 (*cc)->WriteContent(fp, filetype);
148 // we force the writting of a Sequence Delimitation item
149 // because we wrote the Sequence as a 'no Length' sequence
150 binary_write(*fp, seq_term_gr);
151 binary_write(*fp, seq_term_el);
152 binary_write(*fp, seq_term_lg);
156 * \brief Get the first entry while visiting the SeqEntry
157 * \return The first SQItem if found, otherwhise NULL
159 SQItem *SeqEntry::GetFirstSQItem()
161 ItSQItem = Items.begin();
162 if (ItSQItem != Items.end())
168 * \brief Get the next SQItem while visiting the SeqEntry
169 * \note : meaningfull only if GetFirstEntry already called
170 * \return The next SQItem if found, otherwhise NULL
173 SQItem *SeqEntry::GetNextSQItem()
175 gdcmAssertMacro (ItSQItem != Items.end())
178 if (ItSQItem != Items.end())
185 * \brief return a pointer to the SQItem referenced by its ordinal number.
186 * Returns the first item when argument is negative.
187 * Returns the last item when argument is bigger than the total
190 SQItem *SeqEntry::GetSQItem(int nb)
194 return *(Items.begin());
197 for(ListSQItem::iterator cc = Items.begin();
206 return *(Items.end());
209 /// \brief retuens the number of SQItems within the current Sequence
210 unsigned int SeqEntry::GetNumberOfSQItems()
215 /// \brief adds the passed ITEM to the ITEM chained List for this SeQuence.
216 void SeqEntry::AddSQItem(SQItem *sqItem, int itemNumber)
218 sqItem->SetSQItemNumber(itemNumber);
219 Items.push_back(sqItem);
222 //-----------------------------------------------------------------------------
226 //-----------------------------------------------------------------------------
229 //-----------------------------------------------------------------------------
230 } // end namespace gdcm