]> Creatis software - gdcm.git/commitdiff
On the way to gdcm2 ...
authorjpr <jpr>
Thu, 7 Jul 2005 16:37:40 +0000 (16:37 +0000)
committerjpr <jpr>
Thu, 7 Jul 2005 16:37:40 +0000 (16:37 +0000)
Now, the stand way to use a file is :

gdcm::File *f = new gdcm::File();
f->SetLoadMode ( user say here what he wants *not* to load );
f->SetFileName("myFile.gdcm");
f->Load();

Old styles are kept, not to break the C++ API.
   - gdcm::File *f = new gdcm::File("myFile.gdcm");
- f->Load("myFile.gdcm");

Due to the syntaxic abilities of Python maybe some troubles will occur
(not sure ...)

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

index 05981583d5024377644d51c73a35125e6bc54fe2..1226e49598d9b3ca02ef9a6a7d47d7f3d0d8f9ff 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDir.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/07/03 12:45:53 $
-  Version:   $Revision: 1.143 $
+  Date:      $Date: 2005/07/07 16:37:40 $
+  Version:   $Revision: 1.144 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -164,11 +164,52 @@ DicomDir::~DicomDir()
 //-----------------------------------------------------------------------------
 // Public
 
+/**
+ * \brief   Loader. use SetLoadMode(), SetFileName() before !  
+ * @return false if file cannot be open or no swap info was found,
+ *         or no tag was found.
+ */
+bool DicomDir::Load( ) 
+{
+   // We should clean out anything that already exists.
+   Initialize();  // sets all private fields to NULL
+
+   if (!ParseDir)
+   {
+      if ( ! this->Document::Load( ) )
+         return false;
+   }
+    return DoTheLoadingJob( );   
+}
+
+/**
+ * \brief   Loader. (DEPRECATED : not to break the API)
+ * @param   fileName file to be open for parsing
+ * @return false if file cannot be open or no swap info was found,
+ *         or no tag was found.
+ */
 bool DicomDir::Load(std::string const &fileName ) 
 {
-   Filename = fileName;
    // We should clean out anything that already exists.
+   Initialize();  // sets all private fields to NULL
 
+   SetFileName( fileName );
+   if (!ParseDir)
+   {
+      if ( ! this->Document::Load( ) )
+         return false;
+   }
+   return DoTheLoadingJob( );
+}
+
+/**
+ * \brief   Does the Loading Job (internal use only)
+ * @return false if file cannot be open or no swap info was found,
+ *         or no tag was found.
+ */
+bool DicomDir::DoTheLoadingJob( ) 
+{
+   // We should clean out anything that already exists.
    Initialize();  // sets all private fields to NULL
 
    if (!ParseDir)
@@ -180,10 +221,14 @@ bool DicomDir::Load(std::string const &fileName )
       {
          return false;
       }
-      Document::Load(fileName);
+      if (!Document::Load() )
+      {
+         return false;
+      }
+
       if ( GetFirstEntry() == 0 ) // when user passed a Directory to parse
       {
-         gdcmWarningMacro( "Entry HT empty for file: "<< fileName);
+         gdcmWarningMacro( "Entry HT empty for file: "<< GetFileName());
          return false;
       }
       // Directory record sequence
@@ -191,7 +236,7 @@ bool DicomDir::Load(std::string const &fileName )
       if ( !e )
       {
          gdcmWarningMacro( "NO 'Directory record sequence' (0x0004,0x1220)"
-                          << " in file " << fileName);
+                          << " in file " << GetFileName());
          return false;
       }
       else
@@ -201,7 +246,7 @@ bool DicomDir::Load(std::string const &fileName )
    {
    // Only if user passed a root directory
    // ------------------------------------
-      if ( fileName == "." )
+      if ( GetFileName() == "." )
       {
          // user passed '.' as Name
          // we get current directory name
@@ -210,8 +255,8 @@ bool DicomDir::Load(std::string const &fileName )
          SetFileName( dummy ); // will be converted into a string
       }
       NewMeta();
-      gdcmWarningMacro( "Parse directory and create the DicomDir : " << Filename );
-
+      gdcmWarningMacro( "Parse directory and create the DicomDir : " 
+                         << GetFileName() );
       ParseDirectory();
    }
    return true;
index 0875bcfedcd3541a16e3a6754db914a7447560af..ea066735f51864325dba574ad93adae238cc1355 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDicomDir.h,v $
   Language:  C++
-  Date:      $Date: 2005/05/03 09:43:04 $
-  Version:   $Revision: 1.60 $
+  Date:      $Date: 2005/07/07 16:37:41 $
+  Version:   $Revision: 1.61 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -57,6 +57,7 @@ public:
    ~DicomDir();
 
    bool Load( std::string const &filename );
+   bool Load( );
    void Print(std::ostream &os = std::cout, std::string const &indent = "" );
 
    void SetParseDir(bool parseDir)  { ParseDir = parseDir; };
@@ -126,7 +127,7 @@ protected:
 private:
    void Initialize();
    void CreateDicomDir();
-
+   bool DoTheLoadingJob();
    bool AddPatientToEnd(DicomDirPatient *dd);
    bool AddStudyToEnd  (DicomDirStudy *dd);
    bool AddSerieToEnd  (DicomDirSerie *dd);
index 0c4507338b017a15dcef0edde0f0c0f42f1a7bb7..3386f159c86a72b0bc6a036ab8a3e551fcefb18d 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/07/07 13:55:39 $
-  Version:   $Revision: 1.261 $
+  Date:      $Date: 2005/07/07 16:37:40 $
+  Version:   $Revision: 1.262 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -62,11 +62,13 @@ Document::Document()
    // Load will set it to true if sucessfull
    Group0002Parsed = false;
    IsDocumentAlreadyLoaded = false;
+   IsDocumentModified = true;
    LoadMode = 0x00000000; // default : load everything, later
+   SetFileName("");
 }
 
 /**
- * \brief   Constructor (not to break the API) 
+ * \brief   Constructor (DEPRECATED : not to break the API) 
  * @param   fileName 'Document' (File or DicomDir) to be open for parsing
  */
 Document::Document( std::string const &fileName )
@@ -83,8 +85,10 @@ Document::Document( std::string const &fileName )
 
    // Load will set it to true if sucessfull
    IsDocumentAlreadyLoaded = false;
+   IsDocumentModified = true;
 
-   Load(fileName);
+   SetFileName(fileName);
+   Load( );
 }
 /**
  * \brief   Canonical destructor.
@@ -99,16 +103,41 @@ Document::~Document ()
 // Public
 
 /**
- * \brief   Loader  
+ * \brief   Loader. use SetLoadMode(), SetFileName() before ! 
+ * @return false if file cannot be open or no swap info was found,
+ *         or no tag was found.
+ */
+bool Document::Load(  ) 
+{
+   if ( GetFileName() == "" )
+   {
+      gdcmWarningMacro( "Use SetFileName, before !" );
+      return false;
+   }
+   return DoTheLoadingDocumentJob( );
+} 
+/**
+ * \brief   Loader. (DEPRECATED : not to break the API)   
  * @param   fileName 'Document' (File or DicomDir) to be open for parsing
  * @return false if file cannot be open or no swap info was found,
  *         or no tag was found.
  */
 bool Document::Load( std::string const &fileName ) 
 {
-   if ( IsDocumentAlreadyLoaded )
-   {
- // time waste hunting
+   Filename = fileName;
+   return DoTheLoadingDocumentJob( );
+}
+
+/**
+ * \brief   Performs the Loading Job (internal use only)  
+ * @return false if file cannot be open or no swap info was found,
+ *         or no tag was found.
+ */
+bool Document::DoTheLoadingDocumentJob(  ) 
+{
+   if ( ! IsDocumentModified ) // Nothing to do !
+      return true;
+
  //     if ( Filename == fileName )
  //     {
  //        gdcmWarningMacro( "The file was already parsed inside this "
@@ -117,17 +146,14 @@ bool Document::Load( std::string const &fileName )
  //        return true;
  //     }
   
-      gdcmWarningMacro( "A file was already parsed inside this "
-                        << "gdcm::Document (previous name was: "
-                        << Filename.c_str() << ". New name is :"
-                        << fileName );
+   //gdcmWarningMacro( "A file was already parsed inside this "
+   //                  << "gdcm::Document (previous name was: "
+   //                  << Filename.c_str() << ". New name is :"
+   //                  << fileName );
      // clean out the Entries, if already parsed
      // (probabely a mistake from the user)
  
-      ClearEntry();
-   }
-
-   Filename = fileName;
+   ClearEntry();
 
    Fp = 0;
    if ( !OpenFile() )
index 0ee2f3a07091b3b91452dfc83a6434ae7ad52f93..852bdcb5eefad77a1146dcf3807131eb3365054b 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.h,v $
   Language:  C++
-  Date:      $Date: 2005/06/29 15:58:33 $
-  Version:   $Revision: 1.113 $
+  Date:      $Date: 2005/07/07 16:37:41 $
+  Version:   $Revision: 1.114 $
  
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -50,7 +50,8 @@ public:
 typedef std::list<Element> ListElements;
 
 // Loading
-   virtual bool Load( std::string const &filename ); 
+   virtual bool Load( std::string const &filename );
+   virtual bool Load( ); 
 
 // Dictionaries
    Dict *GetPubDict();
@@ -84,7 +85,8 @@ typedef std::list<Element> ListElements;
    /// Accessor to \ref Filename
    const std::string &GetFileName() const { return Filename; }
    /// Accessor to \ref Filename
-   void SetFileName(std::string const &fileName) { Filename = fileName; }
+   void SetFileName(std::string const &fileName) { if (Filename != fileName)
+                                 Filename = fileName, IsDocumentModified = true; }
 
    std::ifstream *OpenFile();
    bool CloseFile();
@@ -108,7 +110,8 @@ typedef std::list<Element> ListElements;
  *        of *each* Shadow Group. The parser will fail if the size is wrong !
  * @param   mode Load mode to be used    
  */
-   void SetLoadMode (int mode) { LoadMode = mode; }
+   void SetLoadMode (int mode) { if (LoadMode != mode) 
+                                   LoadMode = mode, IsDocumentModified = true; }
 
 protected:
 // Methods
@@ -172,12 +175,14 @@ protected:
    /// Whether the gdcm::Document is already parsed/loaded
    /// - False from the creation of the gdcm::Document untill 
    ///   gdcm::Document:Load()
-   bool IsDocumentAlreadyLoaded;
+   bool IsDocumentAlreadyLoaded; // FIXME : probabely useless now
+
+   bool IsDocumentModified;
 
 private:
 // Methods
    void Initialize();
-
+   bool DoTheLoadingDocumentJob();
    // Read
    void ParseDES(DocEntrySet *set, long offset, long l_max, bool delim_mode);
    void ParseSQ (SeqEntry *seq,    long offset, long l_max, bool delim_mode);
index a166a0e75ecf691f92c5c9213ea0bccd6ccfaab9..214d8035162bb3cdb4828970230063a55e1cf02e 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/07/07 10:12:32 $
-  Version:   $Revision: 1.248 $
+  Date:      $Date: 2005/07/07 16:37:40 $
+  Version:   $Revision: 1.249 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -86,18 +86,41 @@ File::~File ()
 
 //-----------------------------------------------------------------------------
 // Public
-
 /**
  * \brief   Loader  
+ * @return false if file cannot be open or no swap info was found,
+ *         or no tag was found.
+ */
+bool File::Load( ) 
+{
+   if ( ! this->Document::Load( ) )
+      return false;
+
+    return DoTheLoadingJob( );   
+}
+/**
+ * \brief   Loader. (DEPRECATED : not to break the API)
  * @param   fileName file to be open for parsing
  * @return false if file cannot be open or no swap info was found,
  *         or no tag was found.
  */
 bool File::Load( std::string const &fileName ) 
 {
-   if ( ! this->Document::Load( fileName ) )
+   SetFileName( fileName );
+   if ( ! this->Document::Load( ) )
       return false;
 
+   return DoTheLoadingJob( );
+}
+
+/**
+ * \brief   Does the Loading Job (internal use only)
+ * @return false if file cannot be open or no swap info was found,
+ *         or no tag was found.
+ */
+bool File::DoTheLoadingJob( ) 
+{
+
    // for some ACR-NEMA images GrPixel, NumPixel is *not* 7fe0,0010
    // We may encounter the 'RETired' (0x0028, 0x0200) tag
    // (Image Location") . This entry contains the number of
index b8264c05eb90c245c78914807ec2bca9161289c5..3c0d8a25b7f23c5c5e973390b2c9ab879c37f4d4 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.h,v $
   Language:  C++
-  Date:      $Date: 2005/06/10 14:05:38 $
-  Version:   $Revision: 1.107 $
+  Date:      $Date: 2005/07/07 16:37:41 $
+  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
@@ -101,7 +101,7 @@ public:
 
    // Loading
    bool Load( std::string const &filename );
+   bool Load(); 
    // Standard values and informations contained in the header
    bool IsReadable();
 
@@ -189,6 +189,7 @@ protected:
    uint16_t GrPixel;
 
 private:
+   bool DoTheLoadingJob();
    void ComputeRLEInfo();
    void ComputeJPEGFragmentInfo();
    bool     ReadTag(uint16_t, uint16_t);