1 /*=========================================================================
4 Module: $RCSfile: gdcmSeqEntry.cxx,v $
6 Date: $Date: 2005/02/05 01:37:09 $
7 Version: $Revision: 1.54 $
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"
32 //-----------------------------------------------------------------------------
33 // Constructor / Destructor
35 * \brief Constructor from a given SeqEntry
37 SeqEntry::SeqEntry( DictEntry *e )
41 ReadLength = 0xffffffff;
44 DelimitorMode = false;
49 * \brief Constructor from a given SeqEntry
50 * @param e Pointer to existing Doc entry
51 * @param depth depth level of the current Seq entry
53 SeqEntry::SeqEntry( DocEntry *e, int depth )
54 : DocEntry( e->GetDictEntry() )
57 ReadLength = 0xffffffff;
60 ImplicitVR = e->IsImplicitVR();
61 Offset = e->GetOffset();
66 * \brief Canonical destructor.
73 //-----------------------------------------------------------------------------
76 * \brief canonical Writer
77 * @param fp pointer to an already open file
78 * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...)
80 void SeqEntry::WriteContent(std::ofstream *fp, FileType filetype)
82 uint16_t seq_term_gr = 0xfffe;
83 uint16_t seq_term_el = 0xe0dd;
84 uint32_t seq_term_lg = 0xffffffff;
86 //uint16_t item_term_gr = 0xfffe;
87 //uint16_t item_term_el = 0xe00d;
89 DocEntry::WriteContent(fp, filetype);
90 for(ListSQItem::iterator cc = Items.begin();
94 (*cc)->WriteContent(fp, filetype);
97 // we force the writting of a Sequence Delimitation item
98 // because we wrote the Sequence as a 'no Length' sequence
99 binary_write(*fp, seq_term_gr);
100 binary_write(*fp, seq_term_el);
101 binary_write(*fp, seq_term_lg);
105 * \brief adds the passed ITEM to the ITEM chained List for this SeQuence.
106 * @param sqItem SQItem to be pushed back in the SeqEntry
107 * @param itemNumber ordinal number of the SQItem
108 * \note NOT end-user intendend method !
110 void SeqEntry::AddSQItem(SQItem *sqItem, int itemNumber)
112 // FIXME : SQItemNumber is supposed to be the ordinal number of the SQItem
113 // within the Sequence.
114 // Either only 'push_back' is allowed,
115 // and we just have to do something like SeqEntry::lastNb++
116 // Or we can add (or remove) anywhere, and SQItemNumber will be broken
117 sqItem->SetSQItemNumber(itemNumber);
118 Items.push_back(sqItem);
122 * \brief Remove all SQItem.
124 void SeqEntry::ClearSQItem()
126 for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc)
137 * \brief Get the first entry while visiting the SeqEntry
138 * \return The first SQItem if found, otherwhise NULL
140 SQItem *SeqEntry::GetFirstSQItem()
142 ItSQItem = Items.begin();
143 if (ItSQItem != Items.end())
149 * \brief Get the next SQItem while visiting the SeqEntry
150 * \note : meaningfull only if GetFirstEntry already called
151 * \return The next SQItem if found, otherwhise NULL
154 SQItem *SeqEntry::GetNextSQItem()
156 gdcmAssertMacro (ItSQItem != Items.end())
159 if (ItSQItem != Items.end())
166 * \brief return a pointer to the SQItem referenced by its ordinal number.
167 * Returns the first item when argument is negative.
168 * Returns the last item when argument is bigger than the total
171 SQItem *SeqEntry::GetSQItem(int nb)
175 return *(Items.begin());
178 for(ListSQItem::iterator cc = Items.begin();
187 return *(Items.end());
191 * \brief returns the number of SQItems within the current Sequence
193 unsigned int SeqEntry::GetNumberOfSQItems()
198 //-----------------------------------------------------------------------------
202 //-----------------------------------------------------------------------------
205 //-----------------------------------------------------------------------------
208 * \brief canonical Printer
210 void SeqEntry::Print( std::ostream &os, std::string const & )
212 // First, Print the Dicom Element itself.
217 if (GetReadLength() == 0)
220 // Then, Print each SQ Item
221 for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc)
223 (*cc)->SetPrintLevel(PrintLevel);
227 // at end, print the sequence terminator item, if any
230 for ( int i = 0; i < SQDepthLevel; i++ )
236 SeqTerm->SetPrintLevel(PrintLevel);
243 gdcmWarningMacro(" -------- should have a sequence terminator item");
248 //-----------------------------------------------------------------------------
249 } // end namespace gdcm