]> Creatis software - gdcm.git/blob - Example/exCTPET.cxx
Fix mistypings
[gdcm.git] / Example / exCTPET.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   gdcm
4   Module:    $RCSfile: exCTPET.cxx,v $
5   Language:  C++
6   Date:      $Date: 2007/05/23 14:18:05 $
7   Version:   $Revision: 1.3 $
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 #include "gdcmFile.h"
19 #include "gdcmSerieHelper.h"
20 #include "gdcmDirList.h"
21 #include "gdcmUtil.h"
22 #include "gdcmDataEntry.h"
23
24 int main(int argc, char *argv[])
25 {
26   if(argc < 3 )
27     {
28     std::cerr << argv[0] << " reference directory" << std::endl;
29     return 1;
30     }
31
32   // Get the reference & directory name
33   const char *reference = argv[1];
34   const char *directory = argv[2];
35
36   // Open a file A
37   // Open another file B
38   // Same Serie/Study ?
39   // No -> return
40   // Yes -> continue
41   // Same Frame of Reference
42   // No -> Return
43   // Yes -> continue
44   // A is CT and B is PT (PET)
45   // No -> return
46   // Yes -> continue
47   // Same Image Position (no string comparison !!)
48   // Even if floating point comparison are dangerous, string comp will not work in general case
49   // No -> Return
50   // Yes: We found a match
51
52   GDCM_NAME_SPACE::File *fileRef = GDCM_NAME_SPACE::File::New();
53   fileRef->SetFileName( reference );
54   fileRef->SetLoadMode(GDCM_NAME_SPACE::LD_NOSHADOW | GDCM_NAME_SPACE::LD_NOSEQ);
55   fileRef->Load();
56   // 0008 0060 CS 1 Modality
57   std::string modalityRef = fileRef->GetEntryString(0x0008,0x0060);
58   if( modalityRef == GDCM_NAME_SPACE::GDCM_UNFOUND ) return 1;
59   if ( !GDCM_NAME_SPACE::Util::DicomStringEqual(modalityRef, "CT") ) return 1;
60   // 0020 000d UI 1 Study Instance UID
61   // 0020 000e UI REL Series Instance UID
62   std::string series_uid_ref = fileRef->GetEntryString(0x0020, 0x000e);
63   // 0020 0052 UI 1 Frame of Reference UID
64   std::string frame_uid_ref = fileRef->GetEntryString(0x0020, 0x0052);
65   // 0020 0032 DS 3 Image Position (Patient)
66   GDCM_NAME_SPACE::DataEntry *imagePosRef = fileRef->GetDataEntry(0x0020,0x0032);
67   assert( imagePosRef->GetValueCount() == 3 );
68
69   GDCM_NAME_SPACE::DirList dirList( directory, true );
70   const GDCM_NAME_SPACE::DirListType filenames = dirList.GetFilenames();
71   GDCM_NAME_SPACE::DirListType::const_iterator it = filenames.begin();
72   GDCM_NAME_SPACE::File *file = GDCM_NAME_SPACE::File::New();
73   file->SetLoadMode(GDCM_NAME_SPACE::LD_NOSHADOW | GDCM_NAME_SPACE::LD_NOSEQ);
74   for( ; it != filenames.end(); ++it)
75     {
76     file->SetFileName( *it );
77     file->Load();
78     std::string modality   = file->GetEntryString(0x0008,0x0060);
79     // This is a dual modality: modality should be *different*
80     if( modality == modalityRef ) continue;
81     if ( !GDCM_NAME_SPACE::Util::DicomStringEqual(modality, "PT") ) continue;
82     std::string series_uid = file->GetEntryString(0x0020, 0x000e);
83     // Not same series !
84     if( series_uid == series_uid_ref ) continue;
85     std::string frame_uid = file->GetEntryString(0x0020, 0x0052);
86     if( frame_uid_ref != frame_uid ) continue;
87     GDCM_NAME_SPACE::DataEntry *imagePos = file->GetDataEntry(0x0020,0x0032);
88     assert( imagePos->GetValueCount() == 3 );
89     if( imagePos->GetValue(0) == imagePosRef->GetValue(0)
90      && imagePos->GetValue(1) == imagePosRef->GetValue(1)
91      && imagePos->GetValue(2) == imagePosRef->GetValue(2) )
92       {
93       std::cerr << "We found a match: " << *it << std::endl;
94       }
95     }
96   return 0;
97 }
98