]> Creatis software - gdcm.git/commitdiff
Now, user can ask gdcm::DicomDir to skip SeqEntries or shadow groups, when
authorjpr <jpr>
Thu, 14 Apr 2005 14:26:19 +0000 (14:26 +0000)
committerjpr <jpr>
Thu, 14 Apr 2005 14:26:19 +0000 (14:26 +0000)
possible :

     // Old style (still available) :
     dcmdir = new gdcm::DicomDir(dirName, true);

    // new style (user is allowed no to load Sequences an/or Shadow Groups)
    dcmdir = new gdcm::DicomDir( );
    dcmdir->SetParseDir(true);
    dcmdir->SetLoadMode(NO_SEQ | NO_SHADOW);
    dcmdir->Load(dirName);

src/gdcmDicomDir.cxx
src/gdcmDicomDir.h
src/gdcmDocument.h
src/gdcmFile.cxx

index 9145817176fed5f65f028c9f21af06b5c0dd2ffc..27b840f24c2b20d3bcabb7935ba0f3812827fafb 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDir.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/03/09 19:29:38 $
-  Version:   $Revision: 1.136 $
+  Date:      $Date: 2005/04/14 14:26:19 $
+  Version:   $Revision: 1.137 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -130,51 +130,59 @@ DicomDir::DicomDir()
  *                        and wants to use it 
  */
 DicomDir::DicomDir(std::string const &fileName, bool parseDir ):
-   Document( fileName )
+   Document( )
 {
    // At this step, Document constructor is already executed,
    // whatever user passed (a root directory or a DICOMDIR)
    // and whatever the value of parseDir was.
    // (nothing is cheked in Document constructor, to avoid overhead)
 
-   Initialize();  // sets all private fields to NULL
+   ParseDir = parseDir;
+   SetLoadMode (0x00000000); // concerns only dicom files
+   Load( fileName );
+}
 
-   // if user passed a root directory, sure we didn't get anything
+/**
+ * \brief  Canonical destructor 
+ */
+DicomDir::~DicomDir() 
+{
+   SetStartMethod(NULL);
+   SetProgressMethod(NULL);
+   SetEndMethod(NULL);
 
-   if ( GetFirstEntry() == 0 ) // when user passed a Directory to parse
+   ClearPatient();
+   if ( MetaElems )
    {
-      if (!parseDir)
-         gdcmWarningMacro( "Entry HT empty for file: "<<fileName);
+      delete MetaElems;
+   }
+}
 
-   // Only if user passed a root directory
-   // ------------------------------------
-      if ( fileName == "." )
-      {
-         // user passed '.' as Name
-         // we get current directory name
-         char dummy[1000];
-         getcwd(dummy, (size_t)1000);
-         SetFileName( dummy ); // will be converted into a string
-      }
+//-----------------------------------------------------------------------------
+// Public
 
-      if ( parseDir ) // user asked for a recursive parsing of a root directory
-      {
-         NewMeta();
+void DicomDir::Load(std::string const &fileName ) 
+{
+   Filename = fileName;
+   // We should clean out anything that already exists.
+
+   Initialize();  // sets all private fields to NULL
 
-         gdcmWarningMacro( "Parse directory and create the DicomDir");
-         ParseDirectory();
+   if (!ParseDir)
+   {
+   // Only if user passed a DICOMDIR
+   // ------------------------------
+      Fp = 0;
+      if ( !OpenFile() )
+      {
+         return;
       }
-      /*
-      else
+      Document::Load(fileName);
+      if ( GetFirstEntry() == 0 ) // when user passed a Directory to parse
       {
-         //  user may just call ParseDirectory() *after* constructor
+         gdcmWarningMacro( "Entry HT empty for file: "<< fileName);
+         return;
       }
-      */
-   }
-   // Only if user passed a DICOMDIR
-   // ------------------------------
-   else 
-   {
       // Directory record sequence
       DocEntry *e = GetDocEntry(0x0004, 0x1220);
       if ( !e )
@@ -185,26 +193,24 @@ DicomDir::DicomDir(std::string const &fileName, bool parseDir ):
       else
          CreateDicomDir();
    }
-}
-
-/**
- * \brief  Canonical destructor 
- */
-DicomDir::~DicomDir() 
-{
-   SetStartMethod(NULL);
-   SetProgressMethod(NULL);
-   SetEndMethod(NULL);
-
-   ClearPatient();
-   if ( MetaElems )
+   else
    {
-      delete MetaElems;
+   // Only if user passed a root directory
+   // ------------------------------------
+      if ( fileName == "." )
+      {
+         // user passed '.' as Name
+         // we get current directory name
+         char dummy[1000];
+         getcwd(dummy, (size_t)1000);
+         SetFileName( dummy ); // will be converted into a string
+      }
+      NewMeta();
+      gdcmWarningMacro( "Parse directory and create the DicomDir : " << Filename );
+      ParseDirectory();
    }
 }
 
-//-----------------------------------------------------------------------------
-// Public
 /**
  * \brief  This predicate, based on hopefully reasonable heuristics,
  *         decides whether or not the current document was properly parsed
@@ -349,6 +355,7 @@ void DicomDir::SetStartMethod( DicomDir::Method *method, void *arg,
    StartMethodArgDelete = argDelete;
 }
 
+
 /**
  * \brief   Set the progress method to call when the parsing of the
  *          directory progress
@@ -516,6 +523,15 @@ bool DicomDir::AnonymizeDicomDir()
    }
    return true;
 }
+
+
+
+
+
+
+
+
+
 //-----------------------------------------------------------------------------
 // Protected
 /**
@@ -528,7 +544,7 @@ void DicomDir::CreateDicomDirChainedList(std::string const &path)
    DirList dirList(path,1); // gets recursively the file list
    unsigned int count = 0;
    VectDocument list;
-   File *header;
+   File *f;
 
    DirListType fileList = dirList.GetFilenames();
 
@@ -543,22 +559,25 @@ void DicomDir::CreateDicomDirChainedList(std::string const &path)
          break;
       }
 
-      header = new File( it->c_str() );
-      if( !header )
-      {
-         gdcmWarningMacro( "Failure in new gdcm::File " << it->c_str() );
-         continue;
-      }
+   f = new File( );
+   f->SetLoadMode(LoadMode); // we allow user not to load Sequences...
+   f->Load( it->c_str() );
+
+//     if( !f )
+//     {
+//         gdcmWarningMacro( "Failure in new gdcm::File " << it->c_str() );
+//         continue;
+//      }
       
-      if( header->IsReadable() )
+      if( f->IsReadable() )
       {
          // Add the file to the chained list:
-         list.push_back(header);
+         list.push_back(f);
          gdcmWarningMacro( "Readable " << it->c_str() );
        }
        else
        {
-          delete header;
+          delete f;
        }
        count++;
    }
@@ -638,7 +657,7 @@ void DicomDir::Initialize()
 }
 
 /**
- * \brief create a 'DicomDir' from a DICOMDIR Header 
+ * \brief create a 'gdcm::DicomDir' from a DICOMDIR Header 
  */
 void DicomDir::CreateDicomDir()
 {
index ea93005a293eb66bd16c84b1738139ea9be69950..81ebbbbf2ec4eeb885662931f17294189e9b6163 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDir.h,v $
   Language:  C++
-  Date:      $Date: 2005/03/09 19:29:38 $
-  Version:   $Revision: 1.58 $
+  Date:      $Date: 2005/04/14 14:26:19 $
+  Version:   $Revision: 1.59 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -56,8 +56,10 @@ public:
                    
    ~DicomDir();
 
+   void Load( std::string const &filename );
    void Print(std::ostream &os = std::cout, std::string const &indent = "" );
 
+   void SetParseDir(bool parseDir)  { ParseDir = parseDir; };
    // Informations contained in the parser
    virtual bool IsReadable();
 
@@ -168,6 +170,7 @@ private:
    float Progress;
    /// value of the ??? for any progress bar   
    bool Abort;
+   bool ParseDir;
 };
 } // end namespace gdcm
 //-----------------------------------------------------------------------------
index de3ff47b45e19841340ba946c3604bf06f1aa682..711dc121451b5258ef433304195c07976918496b 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.h,v $
   Language:  C++
-  Date:      $Date: 2005/03/22 11:23:51 $
-  Version:   $Revision: 1.107 $
+  Date:      $Date: 2005/04/14 14:26:19 $
+  Version:   $Revision: 1.108 $
  
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -49,7 +49,7 @@ public:
 typedef std::list<Element> ListElements;
 
 // Loading
-void Load( std::string const &filename ); 
+   virtual void Load( std::string const &filename ); 
 
 // Dictionaries
    Dict *GetPubDict();
@@ -155,6 +155,12 @@ protected:
    /// List of element to Anonymize
    ListElements AnonymizeList;
 
+   /// \brief Bit string integer (each one considered as a boolean)
+   ///        Bit 0 : Skip Sequences,    if possible
+   ///        Bit 1 : Skip Shadow Groups if possible
+   ///        Some more to add
+   int LoadMode;
+
 private:
 // Methods
    void Initialize();
@@ -205,11 +211,6 @@ private:
 //  void BuildFlatHashTableRecurse( TagDocEntryHT &builtHT,
 //                                  DocEntrySet *set );
 
-   /// \brief Bit string integer (each one considered as a boolean)
-   ///        Bit 0 : Skip Sequences,    if possible
-   ///        Bit 1 : Skip Shadow Groups if possible
-   ///        Some more to add
-   int LoadMode;
 };
 
 } // end namespace gdcm
index 7351ff415ec13f7d919f8bd970e62c2d3fbac398..d18ce400659f2308d23de69d412f952ed3bbef2a 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/03/22 11:37:15 $
-  Version:   $Revision: 1.231 $
+  Date:      $Date: 2005/04/14 14:26:19 $
+  Version:   $Revision: 1.232 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -827,20 +827,21 @@ std::string File::GetPixelType()
 }
 
 /**
- * \brief   Check whether the pixels are signed or UNsigned data.
- * \warning The method defaults to false (UNsigned) when information is Missing.
+ * \brief   Check whether the pixels are signed (1) or UNsigned (0) data.
+ * \warning The method defaults to false (UNsigned) when tag 0028|0103
+ *          is missing.
  *          The responsability of checking this value is left to the caller.
  * @return  True when signed, false when UNsigned
  */
 bool File::IsSignedPixelData()
 {
-   std::string strSize = GetEntryValue( 0x0028, 0x0103 );
-   if ( strSize == GDCM_UNFOUND )
+   std::string strSign = GetEntryValue( 0x0028, 0x0103 );
+   if ( strSign == GDCM_UNFOUND )
    {
       gdcmWarningMacro( "(0028,0103) is supposed to be mandatory");
       return false;
    }
-   int sign = atoi( strSize.c_str() );
+   int sign = atoi( strSign.c_str() );
    if ( sign == 0 ) 
    {
       return false;