]> Creatis software - gdcm.git/commitdiff
* gdcmDocEntrySet::SQDepthLevel and gdcmDocEntrySet::BaseTagKey attributes
authorfrog <frog>
Thu, 16 Sep 2004 19:21:56 +0000 (19:21 +0000)
committerfrog <frog>
Thu, 16 Sep 2004 19:21:56 +0000 (19:21 +0000)
    moved away from gdcmDocEntrySet (since this class is an abstract class
    acting like an interface). SQDepthLevel and BaseTagKey are now
    in class
    - src/gdcmDocEntrySet.[h|cxx] removal of SQDepthLevel and BaseTagKey
      and associated accessors. Doxygenation of the class.
    - src/gdcmSQItem.[h|cxx] SQDepthLevel and BaseTagKey and associated
      accessors added.
    - src/gdcmSeqEntry.[h|cxx]: constructor doesn't handle depth anymore.
      Use SQDepthLevel accessor instead. ::Print() adapted.
    - src/gdcmElementSet.cxx changed according to changes in gdcmSeqEntry.
    - src/gdcmDocument.cxx changed accordingly.

ChangeLog
src/gdcmDocEntrySet.cxx
src/gdcmDocEntrySet.h
src/gdcmDocument.cxx
src/gdcmElementSet.cxx
src/gdcmSQItem.cxx
src/gdcmSQItem.h
src/gdcmSeqEntry.cxx
src/gdcmSeqEntry.h

index 36d6ee4f742ca1f9fe43f3f38c4a02de614bb627..bf85521c94b839f4de3b2d01cf49247b405bfe85 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2004-09-16 Eric Boix <Eric.Boix@creatis.insa-lyon.fr>
+  * gdcmDocEntrySet::SQDepthLevel and gdcmDocEntrySet::BaseTagKey attributes
+    moved away from gdcmDocEntrySet (since this class is an abstract class
+    acting like an interface). SQDepthLevel and BaseTagKey are now
+    in class 
+    - src/gdcmDocEntrySet.[h|cxx] removal of SQDepthLevel and BaseTagKey
+      and associated accessors. Doxygenation of the class.
+    - src/gdcmSQItem.[h|cxx] SQDepthLevel and BaseTagKey and associated
+      accessors added.
+    - src/gdcmSeqEntry.[h|cxx]: constructor doesn't handle depth anymore.
+      Use SQDepthLevel accessor instead. ::Print() adapted.
+    - src/gdcmElementSet.cxx changed according to changes in gdcmSeqEntry.
+    - src/gdcmDocument.cxx changed accordingly.
+
 2004-09-13 Eric Boix <Eric.Boix@creatis.insa-lyon.fr>
   * Preparation of writing a gdcmHeader iterator: generalisation of gdcmTagKey
     - The following is the doxygen comment of the typedef declaration
index ce1c25bf1128b8c8b58b9021670b3629ec55c893..d5ca85e24277d5fb037ee2c7ae274540a36e3f93 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntrySet.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/09/14 16:47:08 $
-  Version:   $Revision: 1.21 $
+  Date:      $Date: 2004/09/16 19:21:57 $
+  Version:   $Revision: 1.22 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 #include "gdcmValEntry.h"
 #include "gdcmBinEntry.h"
 
-//-----------------------------------------------------------------------------
-// Constructor / Destructor
-/**
- * \ingroup gdcmDocEntrySet
- * \brief   Constructor from a given gdcmDocEntrySet
- */
-gdcmDocEntrySet::gdcmDocEntrySet(int depthLevel)
-{
-   SQDepthLevel = depthLevel + 1;   //magic +1 !
-}
-/**
- * \brief   Canonical destructor.
- */
-gdcmDocEntrySet::~gdcmDocEntrySet()
-{
-}
-//-----------------------------------------------------------------------------
-// Print
-/*
- * \ingroup gdcmDocEntrySet
- * \brief   canonical Printer
- */
-
-
 //-----------------------------------------------------------------------------
 // Public
 
-
-
 /**
  * \brief   Build a new Val Entry from all the low level arguments. 
  *          Check for existence of dictionary entry, and build
@@ -117,23 +91,26 @@ gdcmBinEntry *gdcmDocEntrySet::NewBinEntryByNumber(uint16_t group,
  * @param   Group group   number of the underlying DictEntry
  * @param   Elem  element number of the underlying DictEntry
  */
-gdcmSeqEntry *gdcmDocEntrySet::NewSeqEntryByNumber(uint16_t Group,
+gdcmSeqEntrygdcmDocEntrySet::NewSeqEntryByNumber(uint16_t Group,
                                                    uint16_t Elem) 
 {
    // Find out if the tag we encountered is in the dictionaries:
-   gdcmDictEntry *DictEntry = GetDictEntryByNumber(Group, Elem);
-   if (!DictEntry)
+   gdcmDictEntry* DictEntry = GetDictEntryByNumber( Group, Elem );
+   if ( ! DictEntry )
+   {
       DictEntry = NewVirtualDictEntry(Group, Elem);
+   }
 
-   gdcmSeqEntry *NewEntry = new gdcmSeqEntry(DictEntry, 1); // FIXME : 1
-   if (!NewEntry
+   gdcmSeqEntry *NewEntry = new gdcmSeqEntry( DictEntry );
+   if ( !NewEntry 
    {
       dbg.Verbose(1, "gdcmDocument::NewSeqEntryByNumber",
                   "failed to allocate gdcmSeqEntry");
-      return NULL;
+      return 0;
    }
    return NewEntry;
 }
+
 //-----------------------------------------------------------------------------
 // Protected
 
index c77756822e43a9a5f09d89004a4ba2c49f43d2d3..c9e6b23421dcebc122df1ece28f46d99aa8afe92 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocEntrySet.h,v $
   Language:  C++
-  Date:      $Date: 2004/09/14 16:47:08 $
-  Version:   $Revision: 1.17 $
+  Date:      $Date: 2004/09/16 19:21:57 $
+  Version:   $Revision: 1.18 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 typedef std::string gdcmBaseTagKey;
 //-----------------------------------------------------------------------------
 
+/**
+ * \ref gdcmDocEntrySet is an abstract base class for \ref gdcmElementSet
+ * and \ref gdcmSQItem which are both containers for gdcmDocEntries.
+ * \ref gdcmElementSet is based on the STL map<> container
+ * (see \ref gdcmElementSet::TagHT), as opposed to \ref gdcmSQItem
+ * which is based on an STL list container (see \ref gdcmSQItem::docEntries).
+ * Since the syntax for adding a new element to a map<> or a list<>
+ * differ, \ref gdcmDocEntrySet is designed as an adapter to unify the
+ * interfaces of \ref gdcmDocEntrySet and \ref gdcmElementSet.
+ * As an illustration of this design, please refer to the implementation
+ * of \ref AddEntry (or any pure virtual method) in both derived classes.
+ * This adapter unification of interfaces enables the parsing of a
+ * DICOM header containing (optionaly heavily nested) sequences to be
+ * written recursively [see \ref gdcmDocument::ParseDES 
+ * which calls \ref gdcmDocument::ParseSQ, which in turns calls 
+ * \ref gdcmDocument::ParseDES ].
+ *
+ * \note Developpers should strongly resist to the temptation of adding
+ *       members to this class since this class is designed as an adapter 
+ *       in the form of an abstract base class.
+ */
 class GDCM_EXPORT gdcmDocEntrySet
 {
 public:
 
-   gdcmDocEntrySet(int depth = 0); 
-   virtual ~gdcmDocEntrySet();
+   gdcmDocEntrySet() {}
+   virtual ~gdcmDocEntrySet() {}
 
    /// \brief adds any type of entry to the entry set (pure vitual)
    virtual bool AddEntry(gdcmDocEntry *Entry) = 0; // pure virtual
@@ -41,17 +62,6 @@ public:
    /// \brief write any type of entry to the entry set
    virtual void Write (FILE *fp, FileType filetype) = 0;// pure virtual
 
-   /// \brief Gets the depth level of a Dicom Header Entry embedded in a
-   ///        SeQuence
-   int GetDepthLevel() { return SQDepthLevel; }
-
-   /// \brief Sets the depth level of a Dicom Header Entry embedded in a
-   /// SeQuence
-   void SetDepthLevel(int depth) { SQDepthLevel = depth; }
-
-   void           SetBaseTagKey( gdcmBaseTagKey key ) { BaseTagKey = key; }
-   gdcmBaseTagKey GetBaseTagKey( ) { return BaseTagKey; }
-
    virtual gdcmDocEntry* GetDocEntryByNumber(uint16_t group,
                                              uint16_t element) = 0;
    gdcmDocEntry *GetDocEntryByName(std::string const & name);
@@ -83,13 +93,6 @@ protected:
    gdcmDictEntry *GetDictEntryByName  (std::string const & name);
    gdcmDictEntry *GetDictEntryByNumber(uint16_t, uint16_t);
 
-   /// Gives the depth level of the element set inside SeQuences   
-   int SQDepthLevel;
-
-   /// \brief A TagKey of a gdcmDocEntry nested in a sequence is prepended
-   ///        with this BaseTagKey.
-   gdcmBaseTagKey BaseTagKey;
-private:
 };
 
 
index 37be3f68b76d7ba93d77ad6c15daeb07f6e0bb41..95bd114750c2c2c3c0fc18619d3bfc89444ffb97 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/09/16 06:48:00 $
-  Version:   $Revision: 1.79 $
+  Date:      $Date: 2004/09/16 19:21:57 $
+  Version:   $Revision: 1.80 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -107,8 +107,6 @@ gdcmDocument::gdcmDocument( std::string const & filename )
    long beg = ftell(Fp);
    lgt -= beg;
    
-   SQDepthLevel = 0;
-   
    (void)ParseDES( this, beg, lgt, false); // le Load sera fait a la volee
 
    rewind(Fp);
@@ -1186,7 +1184,7 @@ void* gdcmDocument::LoadEntryVoidArea(uint16_t group, uint16_t elem)
       delete[] a;
       return NULL;
    }
-   /// \TODO Drop any already existing void area! JPR
+   /// \todo Drop any already existing void area! JPR
    if( !SetEntryVoidAreaByNumber( a, group, elem ) );
    {
       dbg.Verbose(0, "gdcmDocument::LoadEntryVoidArea setting failed.");
@@ -1449,7 +1447,6 @@ long gdcmDocument::ParseDES(gdcmDocEntrySet *set,
    gdcmDocEntry *newDocEntry = 0;
    unsigned long l = 0;
    
-   int depth = set->GetDepthLevel();
    while (true)
    { 
       if ( !delim_mode && (ftell(Fp)-offset) >= l_max)
@@ -1468,11 +1465,26 @@ long gdcmDocument::ParseDES(gdcmDocEntrySet *set,
                
          if ( gdcmGlobal::GetVR()->IsVROfGdcmStringRepresentable(vr) )
          {
-            /////// ValEntry
+         /////////////////////// ValEntry
             gdcmValEntry* newValEntry =
                new gdcmValEntry( newDocEntry->GetDictEntry() );
             newValEntry->Copy( newDocEntry );
-            newValEntry->SetKey( set->GetBaseTagKey() + newValEntry->GetKey() );
+             
+            // When "set" is a gdcmDocument, then we are at the top of the
+            // hierarchy and the Key is simply of the form ( group, elem )...
+            if (gdcmDocument* dummy = dynamic_cast< gdcmDocument* > ( set ) )
+            {
+               newValEntry->SetKey( newValEntry->GetKey() );
+            }
+            // ...but when "set" is a gdcmSQItem, we are inserting this new
+            // valEntry in a sequence item. Hence the key has the
+            // generalized form (refer to \ref gdcmBaseTagKey):
+            if (gdcmSQItem* parentSQItem = dynamic_cast< gdcmSQItem* > ( set ) )
+            {
+               newValEntry->SetKey(  parentSQItem->GetBaseTagKey()
+                                   + newValEntry->GetKey() );
+            }
+             
             set->AddEntry( newValEntry );
             LoadDocEntry( newValEntry );
             if (newValEntry->IsItemDelimitor())
@@ -1493,11 +1505,26 @@ long gdcmDocument::ParseDES(gdcmDocEntrySet *set,
                                "nor BinEntry. Probably unknown VR.");
             }
 
-            ////// BinEntry or UNKOWN VR:
+         //////////////////// BinEntry or UNKOWN VR:
             gdcmBinEntry* newBinEntry =
                new gdcmBinEntry( newDocEntry->GetDictEntry() );
             newBinEntry->Copy( newDocEntry );
-            newBinEntry->SetKey( set->GetBaseTagKey() + newBinEntry->GetKey() );
+
+            // When "this" is a gdcmDocument the Key is simply of the
+            // form ( group, elem )...
+            if (gdcmDocument* dummy = dynamic_cast< gdcmDocument* > ( set ) )
+            {
+               newBinEntry->SetKey( newBinEntry->GetKey() );
+            }
+            // but when "this" is a SQItem, we are inserting this new
+            // valEntry in a sequence item, and the kay has the
+            // generalized form (refer to \ref gdcmBaseTagKey):
+            if (gdcmSQItem* parentSQItem = dynamic_cast< gdcmSQItem* > ( set ) )
+            {
+               newBinEntry->SetKey(  parentSQItem->GetBaseTagKey()
+                                   + newBinEntry->GetKey() );
+            }
+
             set->AddEntry( newBinEntry );
             LoadDocEntry( newBinEntry );
          }
@@ -1541,12 +1568,28 @@ long gdcmDocument::ParseDES(gdcmDocEntrySet *set,
          }
          // no other way to create it ...
          gdcmSeqEntry* newSeqEntry =
-            new gdcmSeqEntry( newDocEntry->GetDictEntry(),
-                              set->GetDepthLevel() );
+            new gdcmSeqEntry( newDocEntry->GetDictEntry() );
          newSeqEntry->Copy( newDocEntry );
          newSeqEntry->SetDelimitorMode( delim_mode );
-         newSeqEntry->SetDepthLevel( depth );
-         newSeqEntry->SetKey( set->GetBaseTagKey() + newSeqEntry->GetKey() );
+
+         // At the top of the hierarchy, stands a gdcmDocument. When "set"
+         // is a gdcmDocument, then we are building the first depth level.
+         // Hence the gdcmSeqEntry we are building simply has a depth
+         // level of one:
+         if (gdcmDocument* dummy = dynamic_cast< gdcmDocument* > ( set ) )
+         {
+            newSeqEntry->SetDepthLevel( 1 );
+            newSeqEntry->SetKey( newSeqEntry->GetKey() );
+         }
+         // But when "set" is allready a SQItem, we are building a nested
+         // sequence, and hence the depth level of the new gdcmSeqEntry
+         // we are building, is one level deeper:
+         if (gdcmSQItem* parentSQItem = dynamic_cast< gdcmSQItem* > ( set ) )
+         {
+            newSeqEntry->SetDepthLevel( parentSQItem->GetDepthLevel() + 1 );
+            newSeqEntry->SetKey(  parentSQItem->GetBaseTagKey()
+                                + newSeqEntry->GetKey() );
+         }
 
          if ( l != 0 )
          {  // Don't try to parse zero-length sequences
index a5017dd6194bb679a0f41ac30078762007daed3d..ee6d9658232f4d27ef7172f867193ff571b0e506 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmElementSet.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/09/03 14:04:02 $
-  Version:   $Revision: 1.18 $
+  Date:      $Date: 2004/09/16 19:21:57 $
+  Version:   $Revision: 1.19 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -28,8 +28,9 @@
  * \ingroup gdcmElementSet
  * \brief   Constructor from a given gdcmElementSet
  */
+//BOZ depthLevel is not usefull anymore
 gdcmElementSet::gdcmElementSet(int depthLevel) 
-              : gdcmDocEntrySet(depthLevel)
+              : gdcmDocEntrySet()
 {
 }
 
index 2299b946bc6af54bf7f2047e82c715c85f34ee51..1dc964c863466e3eb54ee92f6031ca30effe24d4 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSQItem.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/08/27 15:48:44 $
-  Version:   $Revision: 1.25 $
+  Date:      $Date: 2004/09/16 19:21:57 $
+  Version:   $Revision: 1.26 $
   
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -33,9 +33,9 @@
  * \brief   Constructor from a given gdcmSQItem
  */
 gdcmSQItem::gdcmSQItem(int depthLevel ) 
-          : gdcmDocEntrySet(depthLevel)
+          : gdcmDocEntrySet( )
 {
-   SQDepthLevel = depthLevel +1;
+   SQDepthLevel = depthLevel;
 }
 
 /**
index 946581b4a6f10723f2d9bba10035df2b342dd028..1b3cdad7e0814954acbde7b59d0d4c2192344a26 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSQItem.h,v $
   Language:  C++
-  Date:      $Date: 2004/08/31 15:39:48 $
-  Version:   $Revision: 1.14 $
+  Date:      $Date: 2004/09/16 19:21:57 $
+  Version:   $Revision: 1.15 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -57,9 +57,23 @@ public:
 
    /// \brief   returns the ordinal position of a given SQItem
    int GetSQItemNumber() { return SQItemNumber; };
+
    /// \brief   Sets the ordinal position of a given SQItem
    void SetSQItemNumber(int itemNumber) { SQItemNumber = itemNumber; };
 
+   /// Accessor on \ref SQDepthLevel.
+   int GetDepthLevel() { return SQDepthLevel; }
+                                                                                
+   /// Accessor on \ref SQDepthLevel.
+   void SetDepthLevel(int depth) { SQDepthLevel = depth; }
+
+   /// Accessor on \ref BaseTagKey.
+   void           SetBaseTagKey( gdcmBaseTagKey key ) { BaseTagKey = key; }
+
+   /// Accessor on \ref BaseTagKey.
+   gdcmBaseTagKey GetBaseTagKey( ) { return BaseTagKey; }
+
+
 protected:
 
 // Variables
@@ -73,9 +87,20 @@ protected:
    ///\brief pointer to the HTable of the gdcmDocument,
    ///       (because we don't know it within any gdcmObject nor any gdcmSQItem)
    TagDocEntryHT *PtagHT;
+
        
 private:
 
+   /// \brief Sequences can be nested. This \ref SQDepthLevel represents
+   ///        the level of the nesting of instances of this class.
+   ///        \ref SQDepthLevel and its \ref gdcmSeqEntry::SQDepthLevel
+   ///        counterpart are only defined on printing purposes
+   ///        (see \ref Print).
+   int SQDepthLevel;
+
+   /// \brief A TagKey of a gdcmDocEntry nested in a sequence is prepended
+   ///        with this BaseTagKey.
+   gdcmBaseTagKey BaseTagKey;
 
 };
 
index d31c2b10b38e93632fb8ae9f0a75043113bcd2e4..4323f941cdc8212189debeb83d2fd7c17575f786 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSeqEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/09/13 12:10:53 $
-  Version:   $Revision: 1.27 $
+  Date:      $Date: 2004/09/16 19:21:57 $
+  Version:   $Revision: 1.28 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
  * \ingroup gdcmSeqEntry
  * \brief   Constructor from a given gdcmSeqEntry
  */
-gdcmSeqEntry::gdcmSeqEntry(gdcmDictEntry* e, int depth
+gdcmSeqEntry::gdcmSeqEntry( gdcmDictEntry* e 
              : gdcmDocEntry(e)
 {
    UsableLength = 0;
    ReadLength = 0xffffffff;
-   SQDepthLevel = depth;
+   SQDepthLevel = -1;
 
    delimitor_mode = false;
    seq_term  = NULL;
@@ -72,7 +72,7 @@ gdcmSeqEntry::~gdcmSeqEntry() {
 /**
  * \brief   canonical Printer
  */
-void gdcmSeqEntry::Print(std::ostream &os)
+void gdcmSeqEntry::Print( std::ostream &os )
 {
    // First, Print the Dicom Element itself.
    SetPrintLevel(2);   
@@ -90,15 +90,20 @@ void gdcmSeqEntry::Print(std::ostream &os)
 
    // at end, print the sequence terminator item, if any
    if (delimitor_mode) {
-      for (int i=0;i<SQDepthLevel+1;i++)
+      for ( int i = 0; i < SQDepthLevel; i++ )
+      {
          os << "   | " ;
-      if (seq_term != NULL) {
+      }
+      if (seq_term != NULL)
+      {
          seq_term->Print(os);
          os << std::endl;
       } 
       else 
-         // fusible
+      {
+         // fuse
          os << "      -------------- should have a sequence terminator item";
+      }
    }                    
 }
 
index a0b0d67b2a8491a7bdc03766a2279b41144faddd..29381b401d1f033a60bba83867e55338b3b0f4f2 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmSeqEntry.h,v $
   Language:  C++
-  Date:      $Date: 2004/09/13 12:10:53 $
-  Version:   $Revision: 1.16 $
+  Date:      $Date: 2004/09/16 19:21:57 $
+  Version:   $Revision: 1.17 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -31,7 +31,7 @@ typedef std::list<gdcmSQItem *> ListSQItem;
 class GDCM_EXPORT gdcmSeqEntry : public gdcmDocEntry 
 {
 public:
-   gdcmSeqEntry(gdcmDictEntry* e, int depth);
+   gdcmSeqEntry( gdcmDictEntry* );
    gdcmSeqEntry(gdcmDocEntry* d,  int depth);
    virtual ~gdcmSeqEntry();
    
@@ -69,7 +69,10 @@ private:
    /// sequence terminator item 
    gdcmDocEntry *seq_term;
 
-   /// Gives the depth level of elements inside SeQuences
+   /// \brief Defines the depth level of this \ref gdcmSeqEntry inside
+   ///        the (optionaly) nested sequences. \ref SQDepthLevel
+   ///        and its \ref gdcmSQItem::SQDepthLevel counterpart
+   ///        are only defined on printing purposes (see \ref Print).
    int SQDepthLevel;
 };