1 /*=========================================================================
4 Module: $RCSfile: gdcmSeqEntry.cxx,v $
6 Date: $Date: 2005/02/11 15:22:18 $
7 Version: $Revision: 1.55 $
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"
21 #include "gdcmValEntry.h"
23 #include "gdcmGlobal.h"
25 #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 DocEntry
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.
74 //-----------------------------------------------------------------------------
77 * \brief canonical Writer
78 * @param fp pointer to an already open file
79 * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...)
81 void SeqEntry::WriteContent(std::ofstream *fp, FileType filetype)
83 uint16_t seq_term_gr = 0xfffe;
84 uint16_t seq_term_el = 0xe0dd;
85 uint32_t seq_term_lg = 0xffffffff;
87 //uint16_t item_term_gr = 0xfffe;
88 //uint16_t item_term_el = 0xe00d;
90 DocEntry::WriteContent(fp, filetype);
91 for(ListSQItem::iterator cc = Items.begin();
95 (*cc)->WriteContent(fp, filetype);
98 // we force the writting of a Sequence Delimitation item
99 // because we wrote the Sequence as a 'no Length' sequence
100 binary_write(*fp, seq_term_gr);
101 binary_write(*fp, seq_term_el);
102 binary_write(*fp, seq_term_lg);
106 * \brief adds the passed ITEM to the ITEM chained List for this SeQuence.
107 * @param sqItem SQItem to be pushed back in the SeqEntry
108 * @param itemNumber ordinal number of the SQItem
109 * \note NOT end-user intendend method !
111 void SeqEntry::AddSQItem(SQItem *sqItem, int itemNumber)
113 // FIXME : SQItemNumber is supposed to be the ordinal number of the SQItem
114 // within the Sequence.
115 // Either only 'push_back' is allowed,
116 // and we just have to do something like SeqEntry::lastNb++
117 // Or we can add (or remove) anywhere, and SQItemNumber will be broken
118 sqItem->SetSQItemNumber(itemNumber);
119 Items.push_back(sqItem);
123 * \brief Remove all SQItem.
125 void SeqEntry::ClearSQItem()
127 for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc)
138 * \brief Get the first entry while visiting the SeqEntry
139 * \return The first SQItem if found, otherwhise NULL
141 SQItem *SeqEntry::GetFirstSQItem()
143 ItSQItem = Items.begin();
144 if (ItSQItem != Items.end())
150 * \brief Get the next SQItem while visiting the SeqEntry
151 * \note : meaningfull only if GetFirstEntry already called
152 * \return The next SQItem if found, otherwhise NULL
155 SQItem *SeqEntry::GetNextSQItem()
157 gdcmAssertMacro (ItSQItem != Items.end())
160 if (ItSQItem != Items.end())
167 * \brief return a pointer to the SQItem referenced by its ordinal number.
168 * Returns the first item when argument is negative.
169 * Returns the last item when argument is bigger than the total
172 SQItem *SeqEntry::GetSQItem(int nb)
176 return *(Items.begin());
179 for(ListSQItem::iterator cc = Items.begin();
188 return *(Items.end());
192 * \brief returns the number of SQItems within the current Sequence
194 unsigned int SeqEntry::GetNumberOfSQItems()
199 //-----------------------------------------------------------------------------
203 //-----------------------------------------------------------------------------
206 //-----------------------------------------------------------------------------
209 * \brief canonical Printer
211 void SeqEntry::Print( std::ostream &os, std::string const & )
213 // First, Print the Dicom Element itself.
218 if (GetReadLength() == 0)
221 // Then, Print each SQ Item
222 for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc)
224 (*cc)->SetPrintLevel(PrintLevel);
228 // at end, print the sequence terminator item, if any
231 for ( int i = 0; i < SQDepthLevel; i++ )
237 SeqTerm->SetPrintLevel(PrintLevel);
244 gdcmWarningMacro(" -------- should have a sequence terminator item");
249 //-----------------------------------------------------------------------------
250 } // end namespace gdcm