]> Creatis software - gdcm.git/commitdiff
* FIX now file names and directory name are written properly in the
authorjpr <jpr>
Wed, 17 Mar 2004 14:26:09 +0000 (14:26 +0000)
committerjpr <jpr>
Wed, 17 Mar 2004 14:26:09 +0000 (14:26 +0000)
                      DICOMDIR
           now gdcmDicomDir constructor may be call without any trick
              about the name

ChangeLog
src/gdcmDicomDir.cxx
src/gdcmDicomDir.h
src/gdcmDicomDirElement.h
src/gdcmDicomDirSerie.cxx
src/gdcmDirList.cxx
src/gdcmObject.cxx
src/gdcmParser.cxx
src/gdcmParser.h
src/gdcmUtil.cxx
src/gdcmUtil.h

index 54ca67eab2c9bc6c2c16b5bcd79628d1cfe184ba..48bbcc81e974814469e89a2be52b39240d62b773 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2004-03-17  Jean-Pierre Roux 
+     * REM (Eric Boix bug) : removal of meaningless  
+       gdcmDicomDirImage::NewImage function.       
+     * FIX now file names and directory name are written properly in the
+                      DICOMDIR
+           now gdcmDicomDir constructor may be call without any trick
+                     about the name
+
 2004-03-16  Eric Boix <Eric.Boix@creatis.insa-lyon.fr> 
      * FIX (JPR bug) : src/gdcmDicomDirImage.cxx added missing definition
        of gdcmDicomDirImage::NewImage as empty function.
index 14b5b41b1e1d2dda067458315e52fb77f7a1ecb2..f1c7e679db359efd404e77cc92e81e3909874821 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <sys/types.h>
 #include <errno.h>
+#include <unistd.h>
 
 //-----------------------------------------------------------------------------
 //  For full DICOMDIR description, see:
@@ -38,6 +39,10 @@ gdcmDicomDir::gdcmDicomDir(const char *Name, bool parseDir,
  // et quelle que soit la valeur de parseDir,
  // on a lance gdcmParser
  
+ cout << "---------------------------------------------- " << Name <<endl;
+
+      
    startMethod=            NULL;
    progressMethod=         NULL;
    endMethod=              NULL;
@@ -53,17 +58,26 @@ gdcmDicomDir::gdcmDicomDir(const char *Name, bool parseDir,
 
    metaElems=NULL;
 
-// Si on passe un root directory, on est assuré de n'avoir rien ramené
+// gdcmParser already  executed
+// Si on a passe un root directory, on est assuré de n'avoir rien ramené
 
    if( GetListEntry().begin()==GetListEntry().end() ) 
    {
      // Si, en plus, parseDir == false, ca devrait etre une erreur
       dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : entry list empty");
 
+      if(strlen(Name)==1 && Name[0]=='.') { // user passed '.' as Name
+                                            // we get current directory name
+         char*dummy=(char*) malloc(1000); // TODO : check with Windoze
+         getcwd(dummy,(size_t)1000);
+         SetFileName(dummy); // will be converted into a string
+         free(dummy);        // no longer needed   
+      }
+
       if(parseDir)
       {
          dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : Parse directory and create the DicomDir");
-         ParseDirectory();
+        ParseDirectory();
       }
    }
    else
@@ -141,7 +155,7 @@ void gdcmDicomDir::Print(std::ostream &os)
 /*
  * \ingroup gdcmDicomDir
  * \brief  This predicate, based on hopefully reasonable heuristics,
- *         decides whether or not the current gdcmParser was properly parsed
+ *         decides whether or not the current header was properly parsed
  *         and contains the mandatory information for being considered as
  *         a well formed and usable DicomDir.
  * @return true when gdcmParser is the one of a reasonable DicomDir,
@@ -161,11 +175,11 @@ bool gdcmDicomDir::IsReadable(void)
 
 /*
  * \ingroup gdcmDicomDir
- * \brief  fills whole the structure
+ * \brief  fills the whole structure, starting from a root Directory
  */
 void gdcmDicomDir::ParseDirectory(void)
 {
-   CreateDicomDirChainedList(GetPath());
+   CreateDicomDirChainedList(GetFileName());
    CreateDicomDir();
 }
 
@@ -189,8 +203,8 @@ void gdcmDicomDir::SetStartMethod(gdcmMethod *method,void *arg,gdcmMethod *argDe
 /*
  * \ingroup gdcmDicomDir
  * \brief   Set the method to delete the argument
- *          The argument is destroyed when the method is changed or when the class
- *          is destroyed
+ *          The argument is destroyed when the method is changed or when the
+ *          class is destroyed
  * @param   method Method to call to delete the argument
  */
 void gdcmDicomDir::SetStartMethodArgDelete(gdcmMethod *method) 
@@ -218,8 +232,8 @@ void gdcmDicomDir::SetProgressMethod(gdcmMethod *method,void *arg,gdcmMethod *ar
 /*
  * \ingroup gdcmDicomDir
  * \brief   Set the method to delete the argument
- *          The argument is destroyed when the method is changed or when the class
- *          is destroyed
+ *          The argument is destroyed when the method is changed or when the 
+ *          class is destroyed          
  * @param   method Method to call to delete the argument
  */
 void gdcmDicomDir::SetProgressMethodArgDelete(gdcmMethod *method)
@@ -289,15 +303,13 @@ bool gdcmDicomDir::Write(std::string fileName)
    WriteDicomDirEntries(fp1);
 
    fclose(fp1);
-
    return true;
 }
 
 /**
  * \ingroup gdcmParser
  * \brief   writes on disc according to the DICOMDIR format
- *          using the Chained List
- * \todo a reecrire en utilisant la structure arborescente
+ *          using the tree-like structure
  * @param   _fp already open file pointer
  */
 
@@ -369,7 +381,8 @@ void gdcmDicomDir::CreateDicomDirChainedList(std::string path)
    patients.clear();
 
    for(gdcmDirList::iterator it=fileList.begin(); 
-       it!=fileList.end(); ++it) 
+                             it!=fileList.end(); 
+                             ++it) 
    {
       progress=(float)(count+1)/(float)fileList.size();
       CallProgressMethod();
@@ -407,8 +420,7 @@ gdcmDicomDirPatient * gdcmDicomDir::NewPatient(void) {
    
    elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirPatientElements();  
    std::list<gdcmHeaderEntry *>::iterator debInsertion, finInsertion, i,j; 
-   
-      
+         
    debInsertion = metaElems->fin(); 
    ++debInsertion;
    finInsertion=debInsertion;
@@ -458,23 +470,6 @@ gdcmDicomDirPatient * gdcmDicomDir::NewPatient(void) {
    return p;   
 }
 
-/*
- * \ingroup gdcmDicomDir
- * \brief   Get the DicomDir path
- */
-std::string gdcmDicomDir::GetPath(void)
-{
-   std::string path=GetFileName();
-
-   int pos1=path.rfind("/");
-   int pos2=path.rfind("\\");
-   if(pos1>pos2)
-      path.resize(pos1);
-   else
-      path.resize(pos2);
-
-   return(path);
-}
 /*
  * \ingroup gdcmDicomDir
  * \brief   CallStartMethod
@@ -692,8 +687,8 @@ void gdcmDicomDir::AddDicomDirSerieToEnd(ListTag::iterator begin,ListTag::iterat
 /*
  * \ingroup gdcmDicomDir
  * \brief  for each Header of the chained list, add/update the Patient/Study/Serie/Image info 
- * @param   path
- * @param   list
+ * @param   path path of the root directory
+ * @param   list chained list of Headers
  */
 void gdcmDicomDir::SetElements(std::string &path, ListHeader &list)
 {
@@ -745,7 +740,7 @@ void gdcmDicomDir::SetElements(std::string &path, ListHeader &list)
  * \ingroup gdcmDicomDir
  * \brief   adds to the HTable and at the end of the Chained List
  *          the gdcmEntries (Dicom Elements) corresponding to the given type
- * @param   path file Path (only used when type = GDCM_DICOMDIR_IMAGE
+ * @param   path full path file name(only used when type = GDCM_DICOMDIR_IMAGE
  * @param   type gdcmObject type to create (GDCM_DICOMDIR_PATIENT, GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...)
  * @param   header gdcmHeader of the current file
  */
@@ -783,7 +778,6 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,gdcmHeader
    {
       tmpGr=it->group;
       tmpEl=it->elem;
-
       dictEntry=GetPubDict()->GetDictEntryByNumber(tmpGr,tmpEl);
       entry=new gdcmHeaderEntry(dictEntry);
       entry->SetOffset(0); // just to avoid missprinting
@@ -795,10 +789,10 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,gdcmHeader
 
       if(val==GDCM_UNFOUND) 
       {
-         if((tmpGr==0x0004) &&(tmpEl==0x1130) )
-         {
-            // TODO force the *end* File Name(remove path)
-            val=path;
+         if((tmpGr==0x0004) &&(tmpEl==0x1130) ) // File-set ID
+         {      
+          // force to the *end* File Name
+           val=GetName(path);              
          }
          else if( (tmpGr==0x0004) && (tmpEl==0x1500) ) // Only used for image
          {
@@ -807,8 +801,9 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,gdcmHeader
                dbg.Verbose(0, "gdcmDicomDir::SetElement : the base path of file name is incorrect");
                val=header->GetFileName();
             }
-            else
-               val=&(header->GetFileName()[path.length()]);
+            else {
+               val=&(header->GetFileName().c_str()[path.length()]);
+           }   
          }
          else
          {
@@ -827,7 +822,7 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,gdcmHeader
       {
          if(dictEntry->GetGroup()==0xfffe) 
         {
-            entry->SetLength(entry->GetValue().length()); //JPR                 
+            entry->SetLength(entry->GetValue().length());       
         }
         else if( (dictEntry->GetVR()=="UL") || (dictEntry->GetVR()=="SL") ) 
          {
index cd700d34ed680137727a18b80c0f102ca2dab45a..30f869468f2ea42c9a1688c58803abc54cbf3338 100644 (file)
@@ -35,7 +35,18 @@ public:
                    
    ~gdcmDicomDir(void);
 
-   void SetPrintLevel(int level) { printLevel = level; };
+   /**
+    * \ingroup gdcmParser
+    * \brief   Sets the print level for the Dicom Header 
+    * \note    0 for Light Print; 1 for 'medium' Print, 2 for Heavy
+    */
+   void SetPrintLevel(int level) 
+      { printLevel = level; };
+  /**
+    * \ingroup gdcmParser
+    * \brief   canonical Printer 
+    * \sa    SetPrintLevel
+  */     
    virtual void Print(std::ostream &os = std::cout);
 
 // Informations contained in the parser
@@ -86,7 +97,6 @@ public:
    
 protected:
    void CreateDicomDirChainedList(std::string path);
-   std::string GetPath(void);
 
    void CallStartMethod(void);
    void CallProgressMethod(void);
index a11f4846c8bdad20040a5bdeec4705c970ea0836..6a0e941012e10f34641f8fbf0243b82658036e64 100644 (file)
@@ -36,6 +36,11 @@ public:
    gdcmDicomDirElement(void);
    ~gdcmDicomDirElement(void);
 
+  /**
+    * \ingroup gdcmParser
+    * \brief   canonical Printer 
+    * \sa    SetPrintLevel
+  */ 
    void Print(std::ostream &os);
 
 
index 1415d6cdc8ff900a2bd982837c8f8d48b623f500..1571d28d3db111d23d18a2cb42f60d9ac5690460 100644 (file)
@@ -71,9 +71,7 @@ gdcmDicomDirImage * gdcmDicomDirSerie::NewImage(void) {
    FillObject(elemList);
    gdcmDicomDirImage *st = new gdcmDicomDirImage(i, j, ptagHT, plistEntries);
    images.push_front(st);
-   return st; 
-
-  
+   return st;   
 } 
 //-----------------------------------------------------------------------------
 // Protected
index 64eda53e87f85cc0145c058cd796d84bfa5d7450..21c0c21b6726e01809cb2024ec4c5603801aff5b 100644 (file)
@@ -57,7 +57,7 @@ gdcmDirList::~gdcmDirList(void)
 /*
  * \ingroup gdcmDirList
  * \brief   Get the directory name
- * @param   
+ * @return the directory name 
  */
 std::string gdcmDirList::GetDirName(void)
 {
@@ -86,7 +86,8 @@ void gdcmDirList::NormalizePath(std::string &dirName)
 /*
  * \ingroup gdcmDirList
  * \brief   Explore a directory with possibility of recursion
- * @param   
+ * @param  dirName directory to explore
+ * @param  recursive whether we want recursion or not
  */
 void gdcmDirList::Explore(std::string dirName,bool recursive)
 {
index debbfdd543160e55b1f4bf5580c643134af5db5f..eed5f4db1da979be43ce2e4e16074b8376e67bc5 100644 (file)
@@ -114,7 +114,7 @@ std::string gdcmObject::GetEntryByName(TagName name)  {
          if ( ! ptagHT->count(key)) {
           // we assume a Public Dictionnary *is* loaded
            gdcmDict *PubDict         = gdcmGlobal::GetDicts()->GetDefaultPubDict();
-           // if the invoqued (group,elem) doesn't exist inside the Dictionary
+           // if the invoked (group,elem) doesn't exist inside the Dictionary
           // we create a VirtualDictEntry
            gdcmDictEntry *DictEntry  = PubDict->GetDictEntryByNumber(group, element);
           if (DictEntry == NULL) {
index 5bee740526e38d34d2cb0e458c0d05aa83d3873a..03fdde5d55a873c1a69c6f3574ca2b2f36062b0d 100644 (file)
@@ -3,6 +3,7 @@
 #include "gdcmParser.h"
 #include "gdcmUtil.h"
 #include <errno.h>
+#include <unistd.h>
 
 // For nthos:
 #ifdef _MSC_VER
@@ -112,7 +113,7 @@ gdcmParser::gdcmParser(const char *inFilename,
    enableSequences=enable_sequences;
    ignoreShadow   =ignore_shadow;
    
-   SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE);
+   SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE); 
    filename = inFilename;
    Initialise();
 
@@ -183,7 +184,7 @@ void gdcmParser::PrintPubDict(std::ostream & os) {
 
 /**
   * \ingroup gdcmParser
-  * \brief   Prints The Dict Entries of THE shadow Dicom Dictionnry
+  * \brief   Prints The Dict Entries of THE shadow Dicom Dictionnary
   * @return
   */
 void gdcmParser::PrintShaDict(std::ostream & os) {
index 10943f5ff1010ffde2f93099b22a175200e5f2f5..4220bfba3955b4dbcc8d2fc852cdc1082246ae56 100644 (file)
@@ -159,7 +159,14 @@ protected:
    void WriteEntriesDeprecated(FILE *_fp,FileType type); // JPR
 
    void AddHeaderEntry       (gdcmHeaderEntry *);
-
+   
+   /**
+    * \ingroup gdcmParser
+    * \brief   Set the external File Name 
+    */
+   inline void SetFileName(char* fileName) 
+      {filename = fileName;}
+      
 // Variables
    /**
    * \brief File Pointer, open during Header parsing
@@ -260,7 +267,7 @@ private:
    
    // Deprecated (Not used) --> commented out
    //gdcmHeaderEntry *NewManualHeaderEntryToPubDict(std::string NewTagName,
-   //                                                  std::string VR);
+   //                                               std::string VR);
    
    guint32 GenerateFreeTagKeyInGroup(guint16 group);
 
index 336be556873df4b7f5d43dc39a9d622d52d099f8..cfef1bee4b38263a58f7277488a39418d0432489 100644 (file)
@@ -153,3 +153,58 @@ std::string _CreateCleanString(std::string s) {
 
    return(str);
 }
+
+///////////////////////////////////////////////////////////////////////////
+/*
+ * \brief   Add a SEPARATOR to the end of the name is necessary
+ * @param   
+ */
+void NormalizePath(std::string &name)
+{
+const char SEPARATOR_X      = '/';
+const char SEPARATOR_WIN    = '\\';
+const std::string SEPARATOR = "/";
+   int size=name.size();
+   if((name[size-1]!=SEPARATOR_X)&&(name[size-1]!=SEPARATOR_WIN))
+   {
+      name+=SEPARATOR;
+   }
+}
+
+///////////////////////////////////////////////////////////////////////////
+/*
+ * \brief   Get the (directory) path from a full path file name
+ */
+std::string GetPath(std::string fullName)
+{
+   int pos1=fullName.rfind("/");
+   int pos2=fullName.rfind("\\");
+   if(pos1>pos2)
+      fullName.resize(pos1);
+   else
+      fullName.resize(pos2);
+   return(fullName);
+}
+
+///////////////////////////////////////////////////////////////////////////
+/*
+ * \brief   Get the (last) name of a full path file name
+ */
+std::string GetName(std::string fullName)
+{   
+  int fin=fullName.length()-1;
+  char a =fullName.c_str()[fin];
+  if (a == '/' || a == '\\') {
+     fin--;
+  }
+  int deb;
+  for (int i=fin;i!=0;i--) {
+     if (fullName.c_str()[i] == '/' || fullName.c_str()[i] == '\\')  
+        break;
+      deb = i;
+  }    
+  std::string lastName;
+  for (int i=deb;i<fin+1;i++)
+    lastName=lastName+fullName.c_str()[i];
+  return(lastName);
+} 
index dcc1068c516012b043028c48615f04f12eedd63f..69cd609e56d6e9024e114c9f5e08d10c24e53d8f 100644 (file)
@@ -74,6 +74,9 @@ extern gdcmDebug dbg;
 char *_cleanString(char *v);
 std::string _CreateCleanString(std::string s);
 
+void NormalizePath(std::string &name);
+std::string GetPath(std::string fullName);
+std::string GetName(std::string fullName);
 //-----------------------------------------------------------------------------
 #endif