1 /*=========================================================================
4 Module: $RCSfile: exCTPET.cxx,v $
6 Date: $Date: 2007/05/23 14:18:05 $
7 Version: $Revision: 1.3 $
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.
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.
17 =========================================================================*/
19 #include "gdcmSerieHelper.h"
20 #include "gdcmDirList.h"
22 #include "gdcmDataEntry.h"
24 int main(int argc, char *argv[])
28 std::cerr << argv[0] << " reference directory" << std::endl;
32 // Get the reference & directory name
33 const char *reference = argv[1];
34 const char *directory = argv[2];
37 // Open another file B
41 // Same Frame of Reference
44 // A is CT and B is PT (PET)
47 // Same Image Position (no string comparison !!)
48 // Even if floating point comparison are dangerous, string comp will not work in general case
50 // Yes: We found a match
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);
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 );
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)
76 file->SetFileName( *it );
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);
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) )
93 std::cerr << "We found a match: " << *it << std::endl;