]> Creatis software - gdcm.git/blob - src/gdcmDicomDirObject.cxx
STYLE: ivars should start with a capital letter. Accessors should be const to avoid...
[gdcm.git] / src / gdcmDicomDirObject.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: gdcmDicomDirObject.cxx,v $
5   Language:  C++
6   Date:      $Date: 2004/10/25 03:35:19 $
7   Version:   $Revision: 1.6 $
8                                                                                 
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.
12                                                                                 
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.
16                                                                                 
17 =========================================================================*/
18
19 #include "gdcmDicomDirObject.h"
20 #include "gdcmGlobal.h"
21 #include "gdcmDebug.h"
22 #include "gdcmValEntry.h"
23 namespace gdcm 
24 {
25
26 //-----------------------------------------------------------------------------
27 /**
28  * \ingroup DicomDirObject
29  * \brief  Constructor 
30  *          
31  * @param ptagHT pointer to the HTable (DicomDirObject needs it 
32  *               to build the DocEntries)
33  * @param depth Sequence depth level
34  */
35   
36 DicomDirObject::DicomDirObject(TagDocEntryHT *ptagHT, int depth) 
37           : SQItem (depth)
38 {
39    PtagHT = ptagHT;
40 }
41
42
43 /**
44  * \ingroup DicomDirObject
45  * \brief   Canonical destructor.
46  */
47 DicomDirObject::~DicomDirObject()
48 {
49 }
50
51
52
53 //-----------------------------------------------------------------------------
54 // Public
55
56
57 /**
58  * \ingroup DicomDirObject
59  * \brief   Builds a hash table (multimap) containing 
60  *          pointers to all Header Entries (i.e Dicom Element)
61  *          related to this 'object'
62  * @return
63  */ 
64 TagDocEntryHT DicomDirObject::GetEntry()
65 {
66    TagDocEntryHT HT;
67    DocEntries = GetDocEntries();   
68    for(ListDocEntry::iterator i = DocEntries.begin(); 
69                               i != DocEntries.end(); ++i)
70    {
71       HT[(*i)->GetKey()] = *i;
72    }
73    return HT;
74 }
75
76 //-----------------------------------------------------------------------------
77 // Protected
78 /**
79  * \brief   add the 'Object' related Dicom Elements to the listEntries
80  *          of a partially created DICOMDIR
81  */
82 void DicomDirObject::FillObject(ListDicomDirMetaElem const & elemList)
83 {
84   // FillObject rempli le SQItem qui sera accroche au bon endroit
85
86    std::list<Element>::const_iterator it;
87    uint16_t tmpGr,tmpEl;
88    DictEntry *dictEntry;
89    ValEntry *entry;
90       
91    // for all the Elements found in they own part of the DicomDir dict.     
92    for(it = elemList.begin(); it != elemList.end(); ++it)
93    {
94       tmpGr = it->Group;
95       tmpEl = it->Elem;
96       dictEntry = Global::GetDicts()->GetDefaultPubDict()->GetDictEntryByNumber(tmpGr,tmpEl);
97       entry = new ValEntry(dictEntry);
98       entry->SetOffset(0); // just to avoid further missprinting
99       entry->SetValue(it->Value);
100
101       // dealing with value length ...
102   
103       if(dictEntry->GetGroup()==0xfffe) 
104       {
105          entry->SetLength(entry->GetValue().length());
106       }
107       else if( dictEntry->GetVR() == "UL" || dictEntry->GetVR() == "SL" ) 
108       {
109          entry->SetLength(4);
110       } 
111       else if( dictEntry->GetVR() == "US" || dictEntry->GetVR() == "SS" ) 
112       {
113          entry->SetLength(2); 
114       } 
115       else if( dictEntry->GetVR() == "SQ" )
116       {
117          entry->SetLength(0xffffffff);
118       }
119       else
120       {
121          entry->SetLength(entry->GetValue().length()); 
122       }                                
123       AddDocEntry(entry);
124    }   
125 }   
126 } // end namespace gdcm
127