1 /*=========================================================================
4 Module: $RCSfile: exCTPET.cxx,v $
6 Date: $Date: 2006/01/02 21:54:23 $
7 Version: $Revision: 1.1 $
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 << "RTFM" << std::endl;
32 // Get the directory name
33 const char *directory = argv[1];
36 std::cout << "Dir Name :[" << directory << "]" << std::endl;
38 s = gdcm::SerieHelper::New();
39 s->SetLoadMode(gdcm::LD_NOSHADOW | gdcm::LD_NOSEQ);
40 // 0008|0060 [CS] [Modality] [CT]
41 gdcm::TagKey modality(0x0008,0x0060);
42 s->AddRestriction(modality, "CT", gdcm::GDCM_EQUAL); // Keep only files where
43 // restriction is true
44 s->SetDirectory(directory, true); // true : recursive exploration
46 // std::cout << " ---------------------------------------- Finish parsing :["
47 // << directory << "]" << std::endl;
50 // std::cout << " ---------------------------------------- Finish printing (1)"
54 // For all the Single SerieUID Files Sets of the gdcm::Serie
55 gdcm::FileList *l = s->GetFirstSingleSerieUIDFileSet();
59 //if ( l->size() > 3 ) // Why not ? Just an example, for testing
61 //std::cout << "Sort list : " << nbFiles << " long" << std::endl;
62 s->OrderFileList(l); // sort the list
64 l = s->GetNextSingleSerieUIDFileSet();
70 // Open another file B
74 // Same Frame of Reference
77 // A is CT and B is PT (PET)
80 // Same Image Position (no string comparison !!)
81 // Even if floating point comparison are dangerous, string comp will not work in general case
83 // Yes: We found a match
85 const char filename1[] = "/tmp/PETCT/case1/WHOLEB001_CT001.dcm";
86 const char filename2[] = "/tmp/PETCT/case1/CT_PET001_CT100.dcm";
87 gdcm::File *fileRef = gdcm::File::New();
88 fileRef->SetFileName( filename2 );
90 // 0008 0060 CS 1 Modality
91 std::string modalityRef = fileRef->GetEntryString(0x0008,0x0060);
92 if( modalityRef == gdcm::GDCM_UNFOUND ) return 1;
93 if ( !gdcm::Util::DicomStringEqual(modalityRef, "CT") ) return 1;
94 // 0020 000d UI 1 Study Instance UID
95 // 0020 000e UI REL Series Instance UID
96 std::string series_uid_ref = fileRef->GetEntryString(0x0020, 0x000e);
97 // 0020 0052 UI 1 Frame of Reference UID
98 std::string frame_uid_ref = fileRef->GetEntryString(0x0020, 0x0052);
99 // 0020 0032 DS 3 Image Position (Patient)
100 gdcm::DataEntry *imagePosRef = fileRef->GetDataEntry(0x0020,0x0032);
101 assert( imagePosRef->GetValueCount() == 3 );
103 gdcm::DirList dirList( directory, true );
104 const gdcm::DirListType filenames = dirList.GetFilenames();
105 gdcm::DirListType::const_iterator it = filenames.begin();
106 gdcm::File *file = gdcm::File::New();
107 for( ; it != filenames.end(); ++it)
109 file->SetFileName( *it );
111 std::string modality = file->GetEntryString(0x0008,0x0060);
112 // This is a dual modality: modality should be *different*
113 if( modality == modalityRef ) continue;
114 if ( !gdcm::Util::DicomStringEqual(modality, "PT") ) continue;
115 std::string series_uid = file->GetEntryString(0x0020, 0x000e);
117 if( series_uid == series_uid_ref ) continue;
118 std::string frame_uid = file->GetEntryString(0x0020, 0x0052);
119 if( frame_uid_ref != frame_uid ) continue;
120 gdcm::DataEntry *imagePos = file->GetDataEntry(0x0020,0x0032);
121 assert( imagePos->GetValueCount() == 3 );
122 if( imagePos->GetValue(0) == imagePosRef->GetValue(0)
123 && imagePos->GetValue(1) == imagePosRef->GetValue(1)
124 && imagePos->GetValue(2) == imagePosRef->GetValue(2) )
126 std::cerr << "We found a match: " << *it << std::endl;