Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

gdcmSeqEntry.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002                                                                                 
00003   Program:   gdcm
00004   Module:    $RCSfile: gdcmSeqEntry.cxx,v $
00005   Language:  C++
00006   Date:      $Date: 2005/02/05 01:37:09 $
00007   Version:   $Revision: 1.54 $
00008                                                                                 
00009   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
00010   l'Image). All rights reserved. See Doc/License.txt or
00011   http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
00012                                                                                 
00013      This software is distributed WITHOUT ANY WARRANTY; without even
00014      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00015      PURPOSE.  See the above copyright notices for more information.
00016                                                                                 
00017 =========================================================================*/
00018 
00019 #include "gdcmSeqEntry.h"
00020 #include "gdcmSQItem.h"
00021 #include "gdcmValEntry.h"
00022 #include "gdcmTS.h"
00023 #include "gdcmGlobal.h"
00024 #include "gdcmUtil.h"
00025 #include "gdcmDebug.h"
00026 
00027 #include <iostream>
00028 #include <iomanip>
00029 #include <fstream>
00030 
00031 namespace gdcm 
00032 {
00033 //-----------------------------------------------------------------------------
00034 // Constructor / Destructor
00038 SeqEntry::SeqEntry( DictEntry *e ) 
00039              : DocEntry(e)
00040 {
00041    Length       = 0;
00042    ReadLength   = 0xffffffff;
00043    SQDepthLevel = -1;
00044 
00045    DelimitorMode = false;
00046    SeqTerm  = NULL;
00047 }
00048 
00054 SeqEntry::SeqEntry( DocEntry *e, int depth )
00055              : DocEntry( e->GetDictEntry() )
00056 {
00057    Length       = 0;
00058    ReadLength   = 0xffffffff;
00059    SQDepthLevel = depth;
00060 
00061    ImplicitVR   = e->IsImplicitVR();
00062    Offset       = e->GetOffset();
00063    SeqTerm = NULL;
00064 }
00065 
00069 SeqEntry::~SeqEntry()
00070 {
00071    ClearSQItem();
00072 }
00073 
00074 //-----------------------------------------------------------------------------
00075 // Public
00076 /*
00077  * \brief   canonical Writer
00078  * @param fp pointer to an already open file
00079  * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...)
00080  */
00081 void SeqEntry::WriteContent(std::ofstream *fp, FileType filetype)
00082 {
00083    uint16_t seq_term_gr = 0xfffe;
00084    uint16_t seq_term_el = 0xe0dd;
00085    uint32_t seq_term_lg = 0xffffffff;
00086 
00087    //uint16_t item_term_gr = 0xfffe;
00088    //uint16_t item_term_el = 0xe00d;
00089    
00090    DocEntry::WriteContent(fp, filetype);
00091    for(ListSQItem::iterator cc  = Items.begin();
00092                             cc != Items.end();
00093                           ++cc)
00094    {        
00095       (*cc)->WriteContent(fp, filetype);
00096    }
00097    
00098    // we force the writting of a Sequence Delimitation item
00099    // because we wrote the Sequence as a 'no Length' sequence
00100    binary_write(*fp, seq_term_gr);
00101    binary_write(*fp, seq_term_el);
00102    binary_write(*fp, seq_term_lg);
00103 }
00104 
00111 void SeqEntry::AddSQItem(SQItem *sqItem, int itemNumber)
00112 {
00113 // FIXME : SQItemNumber is supposed to be the ordinal number of the SQItem
00114 //         within the Sequence.
00115 //         Either only 'push_back' is allowed, 
00116 //                and we just have to do something like SeqEntry::lastNb++
00117 //         Or we can add (or remove) anywhere, and SQItemNumber will be broken
00118    sqItem->SetSQItemNumber(itemNumber);
00119    Items.push_back(sqItem);
00120 }
00121 
00125 void SeqEntry::ClearSQItem()
00126 {
00127    for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc)
00128    {
00129       delete *cc;
00130    }
00131    if (SeqTerm)
00132    {
00133       delete SeqTerm;
00134    }
00135 }
00136 
00141 SQItem *SeqEntry::GetFirstSQItem()
00142 {
00143    ItSQItem = Items.begin();
00144    if (ItSQItem != Items.end())
00145       return *ItSQItem;
00146    return NULL;
00147 } 
00148 
00155 SQItem *SeqEntry::GetNextSQItem()
00156 {
00157    gdcmAssertMacro (ItSQItem != Items.end())
00158    {
00159       ++ItSQItem;
00160       if (ItSQItem != Items.end())
00161          return *ItSQItem;
00162    }
00163    return NULL;
00164 }
00165  
00172 SQItem *SeqEntry::GetSQItem(int nb)
00173 {
00174    if (nb<0)
00175    {
00176       return *(Items.begin());
00177    }
00178    int count = 0 ;
00179    for(ListSQItem::iterator cc = Items.begin();
00180                            cc != Items.end();
00181                            count ++, ++cc)
00182    {
00183       if (count == nb)
00184       {
00185          return *cc;
00186       }
00187    }
00188    return *(Items.end());
00189 }
00190 
00194 unsigned int SeqEntry::GetNumberOfSQItems()
00195 {
00196    return Items.size();
00197 }
00198 
00199    // TODO : Find a trick to insert a SequenceDelimitationItem 
00200         //       in the SeqEntry, at the end.
00201 /*
00202 void SeqEntry::InsertSequenceDelimitationItem()
00203 {
00204       gdcm::ValEntry *valEntry = NewValEntry( 0xfffe, 0xe0dd, "UL" );
00205 
00206       if ( !AddEntry(valEntry) )
00207       {
00208          gdcmWarningMacro("AddEntry failed although this is a creation.");
00209          delete valEntry;
00210       }
00211                    
00212 }
00213 */
00214 
00215 //-----------------------------------------------------------------------------
00216 // Protected
00217 
00218 
00219 //-----------------------------------------------------------------------------
00220 // Private
00221 
00222 //-----------------------------------------------------------------------------
00223 // Print
00227 void SeqEntry::Print( std::ostream &os, std::string const & )
00228 {
00229    // First, Print the Dicom Element itself.
00230    os << "S ";
00231    DocEntry::Print(os);
00232    os << std::endl;
00233 
00234    if (GetReadLength() == 0)
00235       return;
00236 
00237    // Then, Print each SQ Item   
00238    for(ListSQItem::iterator cc = Items.begin(); cc != Items.end(); ++cc)
00239    {
00240       (*cc)->SetPrintLevel(PrintLevel);
00241       (*cc)->Print(os);   
00242    }
00243 
00244    // at end, print the sequence terminator item, if any
00245    if (DelimitorMode)
00246    {
00247       for ( int i = 0; i < SQDepthLevel; i++ )
00248       {
00249          os << "   | " ;
00250       }
00251       if (SeqTerm != NULL)
00252       {
00253          SeqTerm->SetPrintLevel(PrintLevel);
00254          SeqTerm->Print(os);
00255          os << std::endl;
00256       } 
00257       else 
00258       {
00259          // fuse
00260          gdcmWarningMacro("  -------- should have a sequence terminator item");
00261       }
00262    }
00263 }
00264 
00265 //-----------------------------------------------------------------------------
00266 } // end namespace gdcm

Generated on Thu Feb 10 22:18:00 2005 for gdcm by doxygen 1.3.6