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