]> Creatis software - gdcm.git/commitdiff
some DICOMDIR writting purpose modif
authorjpr <jpr>
Fri, 30 Jan 2004 10:38:34 +0000 (10:38 +0000)
committerjpr <jpr>
Fri, 30 Jan 2004 10:38:34 +0000 (10:38 +0000)
src/gdcmCommon.h
src/gdcmDicomDir.cxx
src/gdcmDicomDir.h
src/gdcmFile.cxx
src/gdcmHeader.cxx
src/gdcmHeaderEntry.cxx
src/gdcmParser.cxx
src/gdcmParser.h

index 3775c317f7ee3b926738de241e18032c36f9dc33..5647a486f3ab2d61b46ce586e5fb786057394fc9 100644 (file)
@@ -69,7 +69,8 @@ enum FileType {
       ExplicitVR,
       ImplicitVR,
       ACR,
-      ACR_LIBIDO
+      ACR_LIBIDO,
+      DICOMDIR
 };
 
 //For now gdcm is not willing cmake, try to be more quiet
index a3441303ef220a83a36ce8074f886bc6be3f03ba..078c357514d0e5157380b64ca239907483b94db8 100644 (file)
@@ -25,7 +25,6 @@ gdcmDicomDir::gdcmDicomDir(std::string & FileName,
    {
       dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir entry list empty");
    }     
-
    CreateDicomDir();
 }
 
@@ -35,14 +34,18 @@ gdcmDicomDir::gdcmDicomDir(std::string & FileName,
  * \brief   
  * @param   exception_on_error
  */
-gdcmDicomDir::gdcmDicomDir(bool exception_on_error):                           
+gdcmDicomDir::gdcmDicomDir(ListTag *l,
+                           bool exception_on_error):                           
    gdcmParser(exception_on_error )  
 {    
-
+   listEntries=*l;
+   CreateDicomDir();
 }
 
-
-
+/*
+ * \ingroup gdcmDicomDir
+ * \brief  Canonical destructor 
+ */
 gdcmDicomDir::~gdcmDicomDir() 
 {
    for(ListPatient::iterator cc = patients.begin();cc!=patients.end();++cc)
@@ -51,6 +54,8 @@ gdcmDicomDir::~gdcmDicomDir()
    }
 }
 
+
+
 //-----------------------------------------------------------------------------
 // Print
 void gdcmDicomDir::Print(std::ostream &os)
@@ -65,12 +70,45 @@ void gdcmDicomDir::Print(std::ostream &os)
 //-----------------------------------------------------------------------------
 // Public
 
+
+/**
+ * \ingroup gdcmDicomDir
+ * \brief   writes on disc a DICOMDIR
+ * \ warning does NOT add the missing elements in the header :
+ * \         it's up to the user doing it !
+ * @param  fileName file to be written to 
+ * @return
+ */
+bool gdcmDicomDir::Write(std::string fileName) {
+
+   FILE * fp1;
+   fp1 = fopen(fileName.c_str(),"wb");
+   if (fp1 == NULL) {
+      printf("Failed to open (write) File [%s] \n",fileName.c_str());
+      return (false);
+   }
+   char * filePreamble;  
+   filePreamble=(char*)calloc(128,1);
+   fwrite(filePreamble,128,1,fp1);
+   fwrite("DICM",4,1,fp1);
+   free (filePreamble);
+   WriteEntries(DICOMDIR,fp1);
+    
+   return true;
+
+}
+
 //-----------------------------------------------------------------------------
 // Protected
 
 //-----------------------------------------------------------------------------
 // Private
-void gdcmDicomDir::CreateDicomDir(void)
+/*
+ * \ingroup gdcmDicomDir
+ * \brief   
+ * @param   
+ */
+void gdcmDicomDir::CreateDicomDir()
 {
    // The list is parsed. When a tag is found :
    //  1 - we save the beginning iterator
@@ -83,9 +121,9 @@ void gdcmDicomDir::CreateDicomDir(void)
    ListTag::iterator begin;
    ListTag::iterator end;
 
-   begin=GetListEntry().begin();
+   begin=listEntries.begin();
    end=begin;
-   for(ListTag::iterator i=GetListEntry().begin();i != GetListEntry().end();++i) 
+   for(ListTag::iterator i=listEntries.begin();i != listEntries.end();++i) 
    {
       // std::cout << std::hex << (*i)->GetGroup() << 
       //                  " " << (*i)->GetElement() << endl;
@@ -93,7 +131,7 @@ void gdcmDicomDir::CreateDicomDir(void)
       std::string v = (*i)->GetValue();
       if (v == "PATIENT ") 
       {
-//         std::cout<<"PATIENT"<<std::endl;
+       //  std::cout<<"PATIENT"<<std::endl;
          end=i;
          AddObjectToEnd(type,begin,end);
 
@@ -103,7 +141,7 @@ void gdcmDicomDir::CreateDicomDir(void)
 
       if (v == "STUDY ")
       {
-//         std::cout<<"STUDY"<<std::endl;
+       //  std::cout<<"STUDY"<<std::endl;
          end=i;
          AddObjectToEnd(type,begin,end);
 
@@ -113,7 +151,7 @@ void gdcmDicomDir::CreateDicomDir(void)
 
       if (v == "SERIES") 
       {
-//         std::cout<<"SERIES"<<std::endl;
+       //  std::cout<<"SERIES"<<std::endl;
          end=i;
          AddObjectToEnd(type,begin,end);
 
@@ -123,7 +161,7 @@ void gdcmDicomDir::CreateDicomDir(void)
 
       if (v == "IMAGE ") 
       {
-//         std::cout<<"IMAGE"<<std::endl;
+       //  std::cout<<"IMAGE"<<std::endl;
          end=i;
          AddObjectToEnd(type,begin,end);
 
@@ -135,7 +173,11 @@ void gdcmDicomDir::CreateDicomDir(void)
    end=GetListEntry().end();
    AddObjectToEnd(type,begin,end);
 }
-
+/*
+ * \ingroup gdcmDicomDir
+ * \brief   
+ * @param   
+ */
 void gdcmDicomDir::AddObjectToEnd(gdcmDicomDirType type,ListTag::iterator begin,ListTag::iterator end)
 {
    if(begin==end)
@@ -158,12 +200,22 @@ void gdcmDicomDir::AddObjectToEnd(gdcmDicomDirType type,ListTag::iterator begin,
    }
 }
 
+/*
+ * \ingroup gdcmDicomDir
+ * \brief   
+ * @param   
+ */
 void gdcmDicomDir::AddPatientToEnd(ListTag::iterator begin,ListTag::iterator end)
 {
    patients.push_back(new gdcmPatient(begin,end));
 }
 
-void gdcmDicomDir::AddStudyToEnd(ListTag::iterator begin,ListTag::iterator end)
+/*
+ * \ingroup gdcmDicomDir
+ * \brief   
+ * @param   
+ */
+ void gdcmDicomDir::AddStudyToEnd(ListTag::iterator begin,ListTag::iterator end)
 {
    if(patients.size()>0)
    {
@@ -172,7 +224,11 @@ void gdcmDicomDir::AddStudyToEnd(ListTag::iterator begin,ListTag::iterator end)
       (*itp)->AddStudy(new gdcmStudy(begin,end));
    }
 }
-
+/*
+ * \ingroup gdcmDicomDir
+ * \brief   
+ * @param   
+ */
 void gdcmDicomDir::AddSerieToEnd(ListTag::iterator begin,ListTag::iterator end)
 {
    if(patients.size()>0)
@@ -189,7 +245,12 @@ void gdcmDicomDir::AddSerieToEnd(ListTag::iterator begin,ListTag::iterator end)
    }
 }
 
-void gdcmDicomDir::AddImageToEnd(ListTag::iterator begin,ListTag::iterator end)
+/*
+ * \ingroup gdcmDicomDir
+ * \brief   
+ * @param   
+ */
+ void gdcmDicomDir::AddImageToEnd(ListTag::iterator begin,ListTag::iterator end)
 {
    if(patients.size()>0)
    {
index ed91ea9658282cab962a1eb682c6784b635a797e..d5c70ffa88272c97e28ef2ced24552737a7b6635 100644 (file)
@@ -19,8 +19,8 @@ typedef std::list<gdcmPatient *> ListPatient;
 class GDCM_EXPORT gdcmDicomDir: public gdcmParser 
 {
 public:
-   gdcmDicomDir(bool exception_on_error = false);
-   gdcmDicomDir(std::string &FileName,bool exception_on_error = false );
+   gdcmDicomDir(ListTag *l,           bool exception_on_error = false);
+   gdcmDicomDir(std::string &FileName,bool exception_on_error = false);
    
    ~gdcmDicomDir(void);
 
@@ -28,6 +28,8 @@ public:
    virtual void Print(std::ostream &os = std::cout);
 
    inline ListPatient &GetPatients() {return patients;};
+   bool   Write(std::string fileName);
+
 
    typedef enum
    {
index 4b9022fc77f1936d1ddcc061f923cee1277f7b27..6dfb630cf92002c072039c36509d3b5d9eb1fc8a 100644 (file)
@@ -541,8 +541,8 @@ bool gdcmFile::SetImageData(void * inData, size_t ExpectedSize) {
 
 /**
  * \ingroup   gdcmFile
- * \brief Ecrit sur disque les pixels d'UNE image
- *        Aucun test n'est fait sur l'"Endiannerie" du processeur.
+ * \brief Writes on disk A SINGLE Dicom file
+ *        NO test is performed on  processor "Endiannity".
  *        Ca sera à l'utilisateur d'appeler son Reader correctement
  *        (Equivalent a IdImaWriteRawFile) 
  *
@@ -565,10 +565,8 @@ bool gdcmFile::WriteRawData (std::string fileName) {
 
 /**
  * \ingroup   gdcmFile
- * \brief Ecrit sur disque UNE image Dicom
- *        Aucun test n'est fait sur l'"Endiannerie" du processeur.
- *         Ca fonctionnera correctement (?) sur processeur Intel
- *         (Equivalent a IdDcmWrite) 
+ * \brief Writes on disk A SINGLE Dicom file
+ *        NO test is performed on  processor "Endiannity".
  *
  * @param fileName name of the file to be created
  *                 (any already existing file is overwritten)
@@ -638,7 +636,7 @@ bool gdcmFile::WriteBase (std::string fileName, FileType type) {
    FILE * fp1;
    fp1 = fopen(fileName.c_str(),"wb");
    if (fp1 == NULL) {
-      printf("Echec ouverture (ecriture) Fichier [%s] \n",fileName.c_str());
+      printf("Failed to open (write) File [%s] \n",fileName.c_str());
       return (false);
    }
 
@@ -648,6 +646,7 @@ bool gdcmFile::WriteBase (std::string fileName, FileType type) {
       filePreamble=(char*)calloc(128,1);
       fwrite(filePreamble,128,1,fp1);
       fwrite("DICM",4,1,fp1);
+      free (filePreamble);
    }
 
    // --------------------------------------------------------------
index bfe4b672c6b97698329b972bbcbdd260bfac8e8e..fdfc651c33d222fa063a699145714855c5d8be3e 100644 (file)
@@ -9,12 +9,6 @@
 #include "gdcmUtil.h"
 #include "gdcmTS.h"
 
-//-----------------------------------------------------------------------------
-// Refer to gdcmHeader::CheckSwap()
-//const unsigned int gdcmHeader::HEADER_LENGTH_TO_READ = 256;
-
-// Refer to gdcmHeader::SetMaxSizeLoadEntry()
-//const unsigned int gdcmHeader::MAX_SIZE_LOAD_ELEMENT_VALUE = 4096;
 
 //-----------------------------------------------------------------------------
 // Constructor / Destructor
@@ -60,6 +54,7 @@ gdcmHeader::~gdcmHeader (void) {
 //-----------------------------------------------------------------------------
 // Print
 
+// see gdcmParser.cxx
 //-----------------------------------------------------------------------------
 // Public
 /**
index e53120744a3385ac0f75921753cd04a5ca6439f3..34424cc558af85db02f9a1b2353e856ef43c645f 100644 (file)
@@ -13,6 +13,9 @@
 #endif
 #include <iomanip> // for std::ios::left, ...
 
+
+#define MAX_SIZE_PRINT_ELEMENT_VALUE 64
+
 //-----------------------------------------------------------------------------
 // Constructor / Destructor
 /**
@@ -76,12 +79,17 @@ void gdcmHeaderEntry::Print(std::ostream & os) {
    if (printLevel>=1) {      
       s.setf(std::ios::left);
       s << std::setw(66-GetName().length()) << " ";             
-   } 
+   }
+    
+   s << "[" << GetName()<< "]";
+
      
-   s << "[" << GetName()<< "]";       
-   if( (GetLength()<64) || (printLevel>=3) )
+           
+   if( (GetLength()<MAX_SIZE_PRINT_ELEMENT_VALUE) || 
+       (printLevel>=3)  || 
+       (d2.find("gdcm::NotLoaded.") < d2.length()) )
       s << " [" << d2 << "]";
-   else
+   else 
       s << " [ gdcm::too long for print (" << GetLength() << ") ]";
 
    // Display the UID value (instead of displaying the rough code)  
index fc523630d76271f9ffb1b76d19583710f4f88328..93f2f56f0767306992aa7bc80d43d65d98048278 100644 (file)
 // Refer to gdcmParser::CheckSwap()
 const unsigned int gdcmParser::HEADER_LENGTH_TO_READ = 256;
 
-// Refer to gdcmParser::SetMaxSizeLoadElementValue()
+// Refer to gdcmParser::SetMaxSizeLoadEntry()
 const unsigned int gdcmParser::MAX_SIZE_LOAD_ELEMENT_VALUE = 4096;
 
+// Refer to gdcmParser::SetMaxSizePrintEntry()
+// TODO : Right now, better see "define, in gdcmHederEntry.cxx
+const unsigned int gdcmParser::MAX_SIZE_PRINT_ELEMENT_VALUE = 64;
+
 //-----------------------------------------------------------------------------
 // Constructor / Destructor
 /**
@@ -1071,7 +1075,7 @@ void gdcmParser::WriteEntries(FileType type, FILE * _fp)
       
       // === Deal with the value
       //     -------------------
-      if (vr == "SQ")  continue; // vo "value" to write for the SEQuences
+      if (vr == "SQ")  continue; // no "value" to write for the SEQuences
       if (gr == 0xfffe)continue;
       
       if (vr == "US" || vr == "SS") 
@@ -2105,7 +2109,6 @@ void gdcmParser::SwitchSwapToBigEndian(void)
  * \ingroup gdcmParser
  * \brief   
  * @param NewSize
- * @return 
  */
 void gdcmParser::SetMaxSizeLoadEntry(long NewSize) 
 {
@@ -2119,6 +2122,28 @@ void gdcmParser::SetMaxSizeLoadEntry(long NewSize)
    MaxSizeLoadEntry = NewSize;
 }
 
+
+/**
+ * \ingroup gdcmParser
+ * \brief
+ * \warning TODO : not yet usable 
+ *          (see MAX_SIZE_PRINT_ELEMENT_VALUE 
+ *           in gdcmHeaderEntry gdcmLoadEntry)
+ *             
+ * @param NewSize
+ */
+void gdcmParser::SetMaxSizePrintEntry(long NewSize) 
+{
+   if (NewSize < 0)
+      return;
+   if ((guint32)NewSize >= (guint32)0xffffffff) 
+   {
+      MaxSizePrintEntry = 0xffffffff;
+      return;
+   }
+   MaxSizePrintEntry = NewSize;
+}
+
 /**
  * \ingroup gdcmParser
  * \brief   Searches both the public and the shadow dictionary (when they
index cf2cc9470c349f893c003850f03f0278294ab6a3..65bbdc714cb5a481e8aa88d814dcbc7a9e020c90 100644 (file)
@@ -139,6 +139,7 @@ protected:
 
    static const unsigned int HEADER_LENGTH_TO_READ; 
    static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE;
+   static const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE;
 
 protected:
    int enableSequences;
@@ -175,6 +176,7 @@ private:
    void CheckSwap(void);
    void SwitchSwapToBigEndian(void);
    void SetMaxSizeLoadEntry(long);
+   void SetMaxSizePrintEntry(long);
 
    // DictEntry  related utilities
    gdcmDictEntry *GetDictEntryByName  (std::string Name);
@@ -221,6 +223,11 @@ private:
    // this upper bound is fixed to 1024 bytes (which might look reasonable
    // when one considers the definition of the various VR contents).
    guint32 MaxSizeLoadEntry;
+   // Size treshold above which an element value will NOT be *printed* in 
+   // order no to polute the screen output. By default,
+   // this upper bound is fixed to 64 bytes.   
+   guint32 MaxSizePrintEntry;
+
 };
 
 //-----------------------------------------------------------------------------