From: jpr Date: Thu, 7 Jul 2005 16:37:40 +0000 (+0000) Subject: On the way to gdcm2 ... X-Git-Tag: Version1.2.bp~350 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=fbd2698cb0545343abc2d8aefe92bab1f5b3eaa3;p=gdcm.git On the way to gdcm2 ... 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 ...) --- diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index 05981583..1226e495 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -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; diff --git a/src/gdcmDicomDir.h b/src/gdcmDicomDir.h index 0875bcfe..ea066735 100644 --- a/src/gdcmDicomDir.h +++ b/src/gdcmDicomDir.h @@ -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); diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index 0c450733..3386f159 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -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() ) diff --git a/src/gdcmDocument.h b/src/gdcmDocument.h index 0ee2f3a0..852bdcb5 100644 --- a/src/gdcmDocument.h +++ b/src/gdcmDocument.h @@ -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 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 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 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); diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index a166a0e7..214d8035 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -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 diff --git a/src/gdcmFile.h b/src/gdcmFile.h index b8264c05..3c0d8a25 100644 --- a/src/gdcmFile.h +++ b/src/gdcmFile.h @@ -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);