]> Creatis software - gdcm.git/commitdiff
ENH: Cleanup
authormalaterre <malaterre>
Mon, 2 Jan 2006 22:02:50 +0000 (22:02 +0000)
committermalaterre <malaterre>
Mon, 2 Jan 2006 22:02:50 +0000 (22:02 +0000)
Example/exCTPET.cxx

index e52598b90f464f6ef960f4ea5679201f3240c7a5..38ad5bbcacceb3ce7f0b73d7799eca3b2a813d73 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: exCTPET.cxx,v $
   Language:  C++
-  Date:      $Date: 2006/01/02 21:54:23 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2006/01/02 22:02:50 $
+  Version:   $Revision: 1.2 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 
 int main(int argc, char *argv[])
 {
-  if(argc < 2 )
+  if(argc < 3 )
     {
-    std::cerr << "RTFM" << std::endl;
+    std::cerr << argv[0] << " reference directory" << std::endl;
     return 1;
     }
 
-  // Get the directory name
-  const char *directory = argv[1];
-#if 0
-  gdcm::SerieHelper *s;
-   std::cout << "Dir Name :[" << directory << "]" << std::endl;
-
-   s = gdcm::SerieHelper::New();
-   s->SetLoadMode(gdcm::LD_NOSHADOW | gdcm::LD_NOSEQ);
-   // 0008|0060 [CS] [Modality] [CT]   
-   gdcm::TagKey modality(0x0008,0x0060);
-   s->AddRestriction(modality, "CT", gdcm::GDCM_EQUAL); // Keep only files where
-                                              // restriction is true
-   s->SetDirectory(directory, true); // true : recursive exploration
-
-//   std::cout << " ---------------------------------------- Finish parsing :["
-//             << directory << "]" << std::endl;
-//
-//   s->Print();
-//   std::cout << " ---------------------------------------- Finish printing (1)"
-//             << std::endl;
-
-   int nbFiles;
-   // For all the Single SerieUID Files Sets of the gdcm::Serie
-   gdcm::FileList *l = s->GetFirstSingleSerieUIDFileSet();
-   while (l)
-   { 
-      nbFiles = l->size() ;
-      //if ( l->size() > 3 ) // Why not ? Just an example, for testing
-      {
-         //std::cout << "Sort list : " << nbFiles << " long" << std::endl;
-         s->OrderFileList(l);  // sort the list
-      }
-      l = s->GetNextSingleSerieUIDFileSet();
-   } 
-  s->Delete();
-#endif
+  // Get the reference & directory name
+  const char *reference = argv[1];
+  const char *directory = argv[2];
 
   // Open a file A
   // Open another file B
@@ -82,17 +49,16 @@ int main(int argc, char *argv[])
   // No -> Return
   // Yes: We found a match
 
-  const char filename1[] = "/tmp/PETCT/case1/WHOLEB001_CT001.dcm";
-  const char filename2[] = "/tmp/PETCT/case1/CT_PET001_CT100.dcm";
   gdcm::File *fileRef = gdcm::File::New();
-  fileRef->SetFileName( filename2 );
+  fileRef->SetFileName( reference );
+  fileRef->SetLoadMode(gdcm::LD_NOSHADOW | gdcm::LD_NOSEQ);
   fileRef->Load();
   // 0008 0060 CS 1 Modality
   std::string modalityRef = fileRef->GetEntryString(0x0008,0x0060);
   if( modalityRef == gdcm::GDCM_UNFOUND ) return 1;
   if ( !gdcm::Util::DicomStringEqual(modalityRef, "CT") ) return 1;
-    // 0020 000d UI 1 Study Instance UID
-    // 0020 000e UI REL Series Instance UID
+  // 0020 000d UI 1 Study Instance UID
+  // 0020 000e UI REL Series Instance UID
   std::string series_uid_ref = fileRef->GetEntryString(0x0020, 0x000e);
   // 0020 0052 UI 1 Frame of Reference UID
   std::string frame_uid_ref = fileRef->GetEntryString(0x0020, 0x0052);
@@ -104,6 +70,7 @@ int main(int argc, char *argv[])
   const gdcm::DirListType filenames = dirList.GetFilenames();
   gdcm::DirListType::const_iterator it = filenames.begin();
   gdcm::File *file = gdcm::File::New();
+  file->SetLoadMode(gdcm::LD_NOSHADOW | gdcm::LD_NOSEQ);
   for( ; it != filenames.end(); ++it)
     {
     file->SetFileName( *it );
@@ -120,8 +87,8 @@ int main(int argc, char *argv[])
     gdcm::DataEntry *imagePos = file->GetDataEntry(0x0020,0x0032);
     assert( imagePos->GetValueCount() == 3 );
     if( imagePos->GetValue(0) == imagePosRef->GetValue(0)
-      && imagePos->GetValue(1) == imagePosRef->GetValue(1)
-      && imagePos->GetValue(2) == imagePosRef->GetValue(2) )
+     && imagePos->GetValue(1) == imagePosRef->GetValue(1)
+     && imagePos->GetValue(2) == imagePosRef->GetValue(2) )
       {
       std::cerr << "We found a match: " << *it << std::endl;
       }