]> Creatis software - gdcm.git/commitdiff
In ordrer to avoid missbehaviour :
authorjpr <jpr>
Tue, 25 Jan 2005 15:21:20 +0000 (15:21 +0000)
committerjpr <jpr>
Tue, 25 Jan 2005 15:21:20 +0000 (15:21 +0000)
gdcm::DocEntry is now specialized in
- gdcm::SeqEntry (Dicom Sequence) as opposed to :
- gdcm::ContentEntry (Dicom entry with a 'content')

gdcm::ValContent is now specialized in
 - gdcm::ValEntry (Dicom entry with a std::string representable value, i.e.
 characters value, or integers)
 - gdcm::BinEntry (Dicom entry with a non strig representable value

 (user hasn't any longer to thing about the precedence of his dynamic_casts)

src/CMakeLists.txt
src/gdcmBinEntry.cxx
src/gdcmBinEntry.h
src/gdcmContentEntry.cxx [new file with mode: 0644]
src/gdcmContentEntry.h [new file with mode: 0644]
src/gdcmFileHelper.cxx
src/gdcmValEntry.cxx
src/gdcmValEntry.h

index bf8086287519c1f38bc114a129ca0e098abc574b..29b710f9e4d32eff8cb8e79e554a5dd3f61144be 100644 (file)
@@ -15,6 +15,7 @@ INCLUDE_DIRECTORIES(
 SET(libgdcm_la_SOURCES
    gdcmBase.cxx
    gdcmBinEntry.cxx
+   gdcmContentEntry.cxx
    gdcmDebug.cxx
    gdcmDicomDir.cxx
    gdcmDicomDirElement.cxx
index 2650076b02014ab595eed0ccaf9435260b03d41d..a28e9a5a9edbc27f073ba6fada602613c059de51 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmBinEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/24 16:10:52 $
-  Version:   $Revision: 1.56 $
+  Date:      $Date: 2005/01/25 15:21:20 $
+  Version:   $Revision: 1.57 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -17,6 +17,8 @@
 =========================================================================*/
 
 #include "gdcmBinEntry.h"
+#include "gdcmContentEntry.h"
+
 #include "gdcmDebug.h"
 
 #include <fstream>
@@ -32,7 +34,7 @@ namespace gdcm
 /**
  * \brief   Constructor from a given BinEntry
  */
-BinEntry::BinEntry(DictEntry *e) : ValEntry(e)
+BinEntry::BinEntry(DictEntry *e) : ContentEntry(e)
 {
    BinArea = 0;
    SelfArea = true;
@@ -42,7 +44,7 @@ BinEntry::BinEntry(DictEntry *e) : ValEntry(e)
  * \brief   Constructor from a given BinEntry
  * @param   e Pointer to existing Doc entry
  */
-BinEntry::BinEntry(DocEntry *e) : ValEntry(e->GetDictEntry())
+BinEntry::BinEntry(DocEntry *e) : ContentEntry(e->GetDictEntry())
 {
    Copy(e);
 
index 7ff241cb1c557fa5e24bc06cb9bb405a7c28242c..7e3e9ac9c83b05ccfc764e7f527729e5ed7bb018 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmBinEntry.h,v $
   Language:  C++
-  Date:      $Date: 2005/01/21 11:40:55 $
-  Version:   $Revision: 1.32 $
+  Date:      $Date: 2005/01/25 15:21:20 $
+  Version:   $Revision: 1.33 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -19,7 +19,7 @@
 #ifndef GDCMBINENTRY_H
 #define GDCMBINENTRY_H
 
-#include "gdcmValEntry.h"
+#include "gdcmContentEntry.h"
 #include <iostream>
 
 namespace gdcm 
@@ -28,13 +28,14 @@ namespace gdcm
 //-----------------------------------------------------------------------------
 /**
  * \brief   Any Dicom Document (File or DicomDir) contains 
- *           a set of DocEntry entries 
- *          (when successfuly parsed against a given Dicom dictionary)
- *          BinEntry is a specialisation of ValEntry (for non std::string
- *          representable values)
+ *           a set of DocEntry - Dicom entries - 
+ *          BinEntry is an elementary DocEntry (i.e. a ContentEntry, 
+ *           as opposite to SeqEntry) whose content is non std::string
+ *          representable
+ *          BinEntry is a specialisation of ContentEntry
  */
  
-class GDCM_EXPORT BinEntry  : public ValEntry
+class GDCM_EXPORT BinEntry  : public ContentEntry
 {
 public:
    BinEntry( DictEntry *e );
@@ -46,18 +47,18 @@ public:
    void WriteContent( std::ofstream *fp, FileType ft);
 
    /// \brief Returns the area value of the current Dicom Entry
-   ///  when it's not string-translatable (e.g : a LUT table)         
+   ///  when it's not string-translatable (e.g : LUT table, overlay, icon)         
    uint8_t *GetBinArea()  { return BinArea; }
+
    void  SetBinArea( uint8_t *area, bool self = true );
 
-   /// Sets the value (string) of the current Dicom Entry
-   virtual void SetValue(std::string const &val) { SetValueOnly(val); };
 private:
-   /// \brief unsecure memory area to hold 'non string' values 
+   /// \brief memory area to hold 'non std::string' representable values 
    ///       (ie : Lookup Tables, overlays, icons)   
    uint8_t *BinArea;
    bool SelfArea;
 };
+
 } // end namespace gdcm
 //-----------------------------------------------------------------------------
 #endif
diff --git a/src/gdcmContentEntry.cxx b/src/gdcmContentEntry.cxx
new file mode 100644 (file)
index 0000000..2e4530c
--- /dev/null
@@ -0,0 +1,127 @@
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: gdcmContentEntry.cxx,v $
+  Language:  C++
+  Date:      $Date: 2005/01/25 15:21:20 $
+  Version:   $Revision: 1.1 $
+                                                                                
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
+                                                                                
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+                                                                                
+=========================================================================*/
+
+#include "gdcmContentEntry.h"
+#include "gdcmVR.h"
+#include "gdcmTS.h"
+#include "gdcmGlobal.h"
+#include "gdcmUtil.h"
+#include "gdcmDebug.h"
+
+#include <fstream>
+
+namespace gdcm 
+{
+
+// CLEAN ME
+#define MAX_SIZE_PRINT_ELEMENT_VALUE 128
+
+//-----------------------------------------------------------------------------
+// Constructor / Destructor
+/**
+ * \brief   Constructor from a given DictEntry
+ * @param   e Pointer to existing dictionary entry
+ */
+ContentEntry::ContentEntry(DictEntry *e) : DocEntry(e)
+{
+}
+
+/**
+ * \brief   Constructor from a given DocEntry
+ * @param   e Pointer to existing Doc entry
+ */
+ContentEntry::ContentEntry(DocEntry *e)
+             : DocEntry(e->GetDictEntry())
+{
+   Copy(e);
+}
+
+
+/**
+ * \brief   Canonical destructor.
+ */
+ContentEntry::~ContentEntry ()
+{
+}
+
+//-----------------------------------------------------------------------------
+// Public
+
+/**
+ * \brief   Writes the std::string representable' value of a ContentEntry
+ * @param fp already open ofstream pointer
+ * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...)
+ */
+void ContentEntry::WriteContent(std::ofstream *fp, FileType filetype)
+{
+   DocEntry::WriteContent(fp, filetype);
+
+   if ( GetGroup() == 0xfffe )
+   {
+      return; //delimitors have NO value
+   }
+
+   const VRKey &vr = GetVR();
+   unsigned int lgr = GetLength();
+   if (vr == "US" || vr == "SS")
+   {
+      // some 'Short integer' fields may be multivaluated
+      // each single value is separated from the next one by '\'
+      // we split the string and write each value as a short int
+      std::vector<std::string> tokens;
+      tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
+      Util::Tokenize (GetValue(), tokens, "\\");
+      for (unsigned int i=0; i<tokens.size();i++)
+      {
+         uint16_t val_uint16 = atoi(tokens[i].c_str());
+         binary_write( *fp, val_uint16);
+      }
+      tokens.clear();
+      return;
+   }
+   if (vr == "UL" || vr == "SL")
+   {
+      // Some 'Integer' fields may be multivaluated (multiple instances 
+      // of integer). But each single integer value is separated from the
+      // next one by '\' (backslash character). Hence we split the string
+      // along the '\' and write each value as an int:
+      std::vector<std::string> tokens;
+      tokens.erase(tokens.begin(),tokens.end()); // clean any previous value
+      Util::Tokenize (GetValue(), tokens, "\\");
+      for (unsigned int i=0; i<tokens.size();i++)
+      {
+         uint32_t val_uint32 = atoi(tokens[i].c_str());
+         binary_write( *fp, val_uint32);
+      }
+      tokens.clear();
+      return;
+   } 
+
+   gdcmAssertMacro( lgr == GetValue().length() );
+   binary_write(*fp, GetValue());
+} 
+
+//-----------------------------------------------------------------------------
+// Protected
+
+//-----------------------------------------------------------------------------
+// Private
+
+//-----------------------------------------------------------------------------
+} // end namespace gdcm
+
diff --git a/src/gdcmContentEntry.h b/src/gdcmContentEntry.h
new file mode 100644 (file)
index 0000000..95c87d2
--- /dev/null
@@ -0,0 +1,73 @@
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: gdcmContentEntry.h,v $
+  Language:  C++
+  Date:      $Date: 2005/01/25 15:21:20 $
+  Version:   $Revision: 1.1 $
+                                                                                
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
+                                                                                
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+                                                                                
+=========================================================================*/
+
+#ifndef GDCMCONTENTENTRY_H
+#define GDCMCONTENTENTRY_H
+
+#include "gdcmDocEntry.h"
+
+#include <iostream>
+
+namespace gdcm 
+{
+//-----------------------------------------------------------------------------
+/**
+ * \brief   Any Dicom Document (File or DicomDir) contains 
+ *           a set of DocEntry  - Dicom entries -
+ *           (when successfuly parsed against a given Dicom dictionary)
+ *          ContentEntry is an elementary DocEntry (as opposed to SeqEntry).
+ *          Depending on the type of its content,
+ *          ContentEntry is specialized as a ValEntry or a BinEntry
+ */
+class GDCM_EXPORT ContentEntry  : public DocEntry
+{
+public:
+   virtual void WriteContent(std::ofstream *fp, FileType filetype) = 0;
+
+   // Accessors are protected, not to be invoked by end user
+   /// Sets the value (string) of the current Dicom entry
+   virtual void SetValue(std::string const &val) { Value = val; };
+   void SetValueOnly(std::string const &val) { Value = val; };
+
+   /// \brief Returns the 'Value' (e.g. "Dupond Marcel") converted 
+   /// into a 'string', event if it's physically stored on disk as an integer
+   std::string const &GetValue() const { return Value; };
+
+protected:
+
+   // Contructors are protected, not to be invoked by end user.
+   ContentEntry(DictEntry *e);
+   ContentEntry(DocEntry *d); 
+   // Destructor is protected, not to be invoked by end user.
+   ~ContentEntry();
+   
+private:
+// Members :
+  
+   /// \brief Dicom entry value, internaly represented as a std::string.
+   ///        The Value Representation (\ref VR) is independently used
+   ///        in order to interpret (decode) this field.
+   std::string Value;
+};
+
+} // end namespace gdcm
+
+//-----------------------------------------------------------------------------
+#endif
+
index 03e85e1f9c9b52b21595b9ed680a48acbc32406f..9d30a55d4bdeeedad3fde43672b22f05fba8325b 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFileHelper.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/24 16:44:54 $
-  Version:   $Revision: 1.5 $
+  Date:      $Date: 2005/01/25 15:21:20 $
+  Version:   $Revision: 1.6 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -23,6 +23,8 @@
 #include "gdcmDebug.h"
 #include "gdcmUtil.h"
 #include "gdcmBinEntry.h"
+#include "gdcmValEntry.h"
+#include "gdcmContentEntry.h"
 #include "gdcmFile.h"
 #include "gdcmPixelReadConvert.h"
 #include "gdcmPixelWriteConvert.h"
@@ -626,16 +628,18 @@ bool FileHelper::CheckWriteIntegrity()
          case WMODE_RAW :
             if( decSize!=PixelWriteConverter->GetUserDataSize() )
             {
-               gdcmVerboseMacro( "Data size is incorrect (Raw)" << decSize 
-                    << " / " << PixelWriteConverter->GetUserDataSize() );
+               gdcmVerboseMacro( "Data size (Raw) is incorrect. Should be " 
+                           << decSize << " / Found :" 
+                           << PixelWriteConverter->GetUserDataSize() );
                return false;
             }
             break;
          case WMODE_RGB :
             if( rgbSize!=PixelWriteConverter->GetUserDataSize() )
             {
-               gdcmVerboseMacro( "Data size is incorrect (RGB)" << decSize
-                   << " / " << PixelWriteConverter->GetUserDataSize() );
+               gdcmVerboseMacro( "Data size (RGB) is incorrect. Should be " 
+                          << decSize << " / Found " 
+                          << PixelWriteConverter->GetUserDataSize() );
                return false;
             }
             break;
index 40a36a6d7479a6975ab2f7085fffe682cc26f290..ae44be0abeecc4c808f9ea0bb72c9ab50eaf46b3 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmValEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/24 16:10:53 $
-  Version:   $Revision: 1.50 $
+  Date:      $Date: 2005/01/25 15:21:20 $
+  Version:   $Revision: 1.51 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -37,7 +37,7 @@ namespace gdcm
  * \brief   Constructor from a given DictEntry
  * @param   e Pointer to existing dictionary entry
  */
-ValEntry::ValEntry(DictEntry *e) : DocEntry(e)
+ValEntry::ValEntry(DictEntry *e) : ContentEntry(e)
 {
 }
 
@@ -46,7 +46,7 @@ ValEntry::ValEntry(DictEntry *e) : DocEntry(e)
  * @param   e Pointer to existing Doc entry
  */
 ValEntry::ValEntry(DocEntry *e)
-             : DocEntry(e->GetDictEntry())
+             : ContentEntry(e->GetDictEntry())
 {
    Copy(e);
 }
index 34275c6d2b7c8e755bc2c62ddb652a1adaade31c..05ae4f188256b9667f31593f79bbc69741c42d70 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmValEntry.h,v $
   Language:  C++
-  Date:      $Date: 2005/01/21 11:40:56 $
-  Version:   $Revision: 1.37 $
+  Date:      $Date: 2005/01/25 15:21:20 $
+  Version:   $Revision: 1.38 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 #define GDCMVALENTRY_H
 
 #include "gdcmDocEntry.h"
+#include "gdcmContentEntry.h"
 
 #include <iostream>
 
 namespace gdcm 
 {
 //-----------------------------------------------------------------------------
+
 /**
- * \brief   Any Dicom Document (File header or DicomDir) contains 
+ * \brief   Any Dicom Document (File or DicomDir) contains 
  *           a set of DocEntry  - Dicom entries -
- *          (when successfuly parsed against a given Dicom dictionary)
- *          ValEntry is an elementary DocEntry (as opposed to SeqEntry)
- */
-class GDCM_EXPORT ValEntry  : public DocEntry
+ *          ValEntry is an elementary DocEntry (i.e. a ContentEntry, 
+ *           as opposed to SeqEntry)
+ *          whose content is 'std::string representable' : characters,
+ *          or integers (loaded in memory as a std::string)
+ *          ValEntry is a specialisation of ContentEntry
+ */ 
+class GDCM_EXPORT ValEntry  : public ContentEntry
 {
 public:
+
+   // Contructors and Destructor are public.
    ValEntry(DictEntry *e);
    ValEntry(DocEntry *d); 
+
    ~ValEntry();
 
-   /// \brief Returns the 'Value' (e.g. "Dupond Marcel") converted into a
-   /// 'string', event if it's physically stored as an integer in the header of the
-   /// current Document (File or DicomDir)
-   std::string const &GetValue() const { return Value; };
-    
-   /// Sets the value (string) of the current Dicom entry.
-   /// The size is updated
-   virtual void SetValue(std::string const &val);
+   // Other accessors are inherited from gdcm::ContentEntry
 
-   virtual void Print(std::ostream &os = std::cout, std::string const & indent = ""); 
+   void Print(std::ostream &os = std::cout, 
+              std::string const & indent = ""); 
 
-   virtual void WriteContent(std::ofstream *fp, FileType filetype);
+   void WriteContent(std::ofstream *fp, FileType filetype); 
+   
+   /// Sets the value (string) of the current Dicom entry.
+   /// The size is updated
+   void SetValue(std::string const &val);
 
 protected:
-   /// Sets the value (string) of the current Dicom entry
-   void SetValueOnly(std::string const &val) { Value = val; }; 
    
 private:
-// Members :
-  
-   /// \brief Dicom entry value, internaly represented as a std::string.
-   ///        The Value Representation (\ref VR) is independently used
-   ///        in order to interpret (decode) this field.
-   std::string Value;
+
 };
+
 } // end namespace gdcm
 
 //-----------------------------------------------------------------------------