]> Creatis software - gdcm.git/blob - src/gdcmDicomDir.cxx
*** empty log message ***
[gdcm.git] / src / gdcmDicomDir.cxx
1 // gdcmDicomDir.cxx
2 //-----------------------------------------------------------------------------
3 #include "gdcmDicomDir.h"
4 #include "gdcmPatient.h"
5 #include "gdcmStudy.h"
6 #include "gdcmSerie.h"
7 #include "gdcmImage.h"
8
9 #include <string>
10
11 gdcmDicomDir::gdcmDicomDir(std::string & FileName,
12                            bool exception_on_error):
13    gdcmParser(FileName.c_str(),exception_on_error, true )  {
14
15
16    gdcmPatient *patCur;
17    gdcmStudy   *studCur;
18    gdcmSerie   *serCur;
19    gdcmImage   *imaCur; 
20      
21    ListTag::iterator i, j;
22    
23    
24      if ( GetListEntry().begin() ==   GetListEntry().end() ) {
25         cout << "ListEntry vide " << endl;
26      }     
27  
28      i = GetListEntry().begin();              
29      while ( i != GetListEntry().end() ) {
30
31        // std::cout << std::hex << (*i)->GetGroup() << 
32        //                  " " << (*i)->GetElement() << endl;
33
34         std::string v = (*i)->GetValue();               
35         if (v == "PATIENT ") {
36            patCur=new gdcmPatient();
37            //cout << "PATIENT" << endl,
38            patCur->beginObj =i; 
39            GetPatients().push_back(patCur);          
40         }       
41
42         if (v == "STUDY ") {
43             //cout << "STUDY" << endl,
44            studCur=new gdcmStudy();
45            studCur->beginObj = patCur->endObj = i;                 
46            lPatient::iterator aa = GetPatients().end();
47            --aa;
48            (*aa)->GetStudies().push_back(studCur);
49         }
50            studCur=new gdcmStudy();
51          
52         if (v == "SERIES") {
53            //cout << "SERIES" << endl,
54            serCur=new gdcmSerie();
55
56            serCur->beginObj  = studCur->endObj= i;              
57            lPatient::iterator aa = GetPatients().end();
58            --aa;
59            lStudy::iterator bb = (*aa)->GetStudies().end();
60            --bb;
61            (*bb)->GetSeries().push_back(serCur);
62         }
63                 
64         if (v == "IMAGE ") {
65            //cout << "IMAGE" << endl;
66            imaCur=new gdcmImage();
67            imaCur->beginObj  = serCur->endObj= i;               
68
69            lPatient::iterator aa = GetPatients().end();
70            --aa;
71            lStudy::iterator bb = (*aa)->GetStudies().end();
72            --bb;
73            lSerie::iterator cc = (*bb)->GetSeries().end();
74            --cc; 
75            (*cc)->GetImages().push_back(imaCur);
76            
77            
78            /* ---
79            // ce n'est pas sur une nouvelle IMAGE, qu'il faut intervenir
80            // mais lorsqu'on rencontre un 'non IMAGE' apres des 'IMAGE'
81            lImage::iterator dd = (*cc)->GetImages().end();
82
83            if ( (*cc)->GetImages().begin() != dd ) {
84               --dd;
85               (*dd)->endObj = i;           
86            }
87          --- */                    
88         }                                 
89         ++i; 
90       }      
91 }
92
93
94 gdcmDicomDir::~gdcmDicomDir() {
95    lPatient::iterator cc = GetPatients().begin();
96    while  (cc != GetPatients().end() ) {
97       //cout << "delete PATIENT" << endl;
98       delete *cc;
99       ++cc;
100    }
101 }