]> Creatis software - gdcm.git/blobdiff - src/gdcmDicomDir.cxx
* FIX : src/gdcmDicomDir.cxx : make windows compilable
[gdcm.git] / src / gdcmDicomDir.cxx
index d61e5c11a58efe4f2f8dcbc90e7b7f96e08c3dc4..b109d1efc8fa3882097be3e7e190ed9b701861cc 100644 (file)
 
 #include <sys/types.h>
 #include <errno.h>
-#include <unistd.h>
+
+#ifdef _MSC_VER 
+   #include <direct.h>
+#else
+   #include <unistd.h>
+#endif
 
 //-----------------------------------------------------------------------------
 //  For full DICOMDIR description, see:
@@ -64,8 +69,12 @@ gdcmDicomDir::gdcmDicomDir(const char *Name, bool parseDir,
 
       if(strlen(Name)==1 && Name[0]=='.') { // user passed '.' as Name
                                             // we get current directory name
-         char*dummy=(char*) malloc(1000);   // TODO : check with Windoze
+         char*dummy=(char*) malloc(1000);   // TODO : check with Windoze // JPR
+#ifdef _MSC_VER
+         _getcwd(dummy,(size_t)1000);
+#else
          getcwd(dummy,(size_t)1000);
+#endif
          SetFileName(dummy); // will be converted into a string
          free(dummy);        // no longer needed   
       }
@@ -76,8 +85,12 @@ gdcmDicomDir::gdcmDicomDir(const char *Name, bool parseDir,
         ParseDirectory();
       }
    }
-   else
+   else {
       CreateDicomDir();
+      CheckBoundaries(); // to maintain consistency between 
+                         // home-made gdcmDicomDir 
+                        // and the ones comming from a DICOMDIR file
+   } 
 }
 
 /*
@@ -294,7 +307,7 @@ bool gdcmDicomDir::Write(std::string fileName)
    fwrite(filePreamble,128,1,fp1);
    fwrite("DICM",4,1,fp1);
    free(filePreamble);        
-   //UpdateDirectoryRecordSequenceLength(); // a reecrire en utilisant 
+   //UpdateDirectoryRecordSequenceLength(); // a reecrire en utilisant   JPR
                                             // la structure arborescente JPR
    WriteDicomDirEntries(fp1);
 
@@ -397,12 +410,48 @@ void gdcmDicomDir::CreateDicomDirChainedList(std::string path)
    std::sort(list.begin(),list.end(),gdcmDicomDir::HeaderLessThan);
 
    std::string tmp=fileList.GetDirName();
+      
    //for each Header of the chained list, add/update the Patient/Study/Serie/Image info
    SetElements(tmp,list);
-
+      
    CallEndMethod();
 }
 
+
+
+void gdcmDicomDir::CheckBoundaries()
+{   
+   ListDicomDirPatient::iterator  itPatient;
+   ListDicomDirStudy::iterator    itStudy;
+   ListDicomDirSerie::iterator    itSerie;
+   ListDicomDirImage::iterator    itImage; 
+   ListTag::iterator i,j; 
+   
+   GetDicomDirMeta()->ResetBoundaries(0);   
+
+   itPatient = GetDicomDirPatients().begin(); 
+   while ( itPatient != GetDicomDirPatients().end() ) {
+      (*itPatient)->ResetBoundaries(1);            
+      itStudy = ((*itPatient)->GetDicomDirStudies()).begin();        
+      while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) {   
+         (*itStudy)->ResetBoundaries(1); 
+         itSerie = ((*itStudy)->GetDicomDirSeries()).begin();
+         while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) {
+            (*itSerie)->ResetBoundaries(1);
+            itImage = ((*itSerie)->GetDicomDirImages()).begin();
+            while (itImage != (*itSerie)->GetDicomDirImages().end() ) {
+               (*itImage)->ResetBoundaries(1);
+               ++itImage;                  
+           }
+           ++itSerie;                                
+         }
+        ++itStudy;            
+      } 
+      ++itPatient;     
+   }
+} 
+
+
 /*
  * \ingroup gdcmDicomDir
  * \brief   adds a new Patient to a partially created DICOMDIR