]> Creatis software - gdcm.git/blobdiff - src/gdcmHeader.cxx
* Added python wrappers of vtkGdcmReader vtk class (see the
[gdcm.git] / src / gdcmHeader.cxx
index 7588e008f181abf29f7350615c43f2577b595d21..002aed724d6b6b5b27e84427cb6fc68248b9dc44 100644 (file)
@@ -1,4 +1,4 @@
-// gdcmHeader.cxx
+// $Header: /cvs/public/gdcm/src/Attic/gdcmHeader.cxx,v 1.65 2003/05/12 14:32:43 frog Exp $
 
 #include <stdio.h>
 #include <cerrno>
 // Refer to gdcmHeader::SetMaxSizeLoadElementValue()
 #define _MaxSizeLoadElementValue_   1024
 
-VRHT * gdcmHeader::dicom_vr = (VRHT*)0;
-
 void gdcmHeader::Initialise(void) {
-   if (!gdcmHeader::dicom_vr)
-      InitVRDict();
-   Dicts = new gdcmDictSet();
+   dicom_vr = gdcmGlobal::GetVR();
+   Dicts = gdcmGlobal::GetDicts();
    RefPubDict = Dicts->GetDefaultPubDict();
    RefShaDict = (gdcmDict*)0;
 }
@@ -32,7 +29,8 @@ gdcmHeader::gdcmHeader(const char *InFilename, bool exception_on_error) {
   SetMaxSizeLoadElementValue(_MaxSizeLoadElementValue_);
   filename = InFilename;
   Initialise();
-  OpenFile(exception_on_error);
+  if ( !OpenFile(exception_on_error))
+     return;
   ParseHeader();
   LoadElements();
   CloseFile();
@@ -45,10 +43,9 @@ bool gdcmHeader::OpenFile(bool exception_on_error)
     if(!fp)
       throw gdcmFileError("gdcmHeader::gdcmHeader(const char *, bool)");
   }
-  else
-    dbg.Error(!fp, "gdcmHeader::gdcmHeader cannot open file", filename.c_str());
   if ( fp )
      return true;
+  dbg.Verbose(0, "gdcmHeader::gdcmHeader cannot open file", filename.c_str());
   return false;
 }
 
@@ -61,45 +58,13 @@ bool gdcmHeader::CloseFile(void) {
 }
 
 gdcmHeader::~gdcmHeader (void) {
-   //FIXME obviously there is much to be done here !
+   dicom_vr = (gdcmVR*)0;
+   Dicts    = (gdcmDictSet*)0;
+   RefPubDict = (gdcmDict*)0;
+   RefShaDict = (gdcmDict*)0;
    return;
 }
 
-void gdcmHeader::InitVRDict (void) {
-   if (dicom_vr) {
-      dbg.Verbose(0, "gdcmHeader::InitVRDict:", "VR dictionary allready set");
-      return;
-   }
-   VRHT *vr = new VRHT;
-   (*vr)["AE"] = "Application Entity";       // At most 16 bytes
-   (*vr)["AS"] = "Age String";               // Exactly 4 bytes
-   (*vr)["AT"] = "Attribute Tag";            // 2 16-bit unsigned short integers
-   (*vr)["CS"] = "Code String";              // At most 16 bytes
-   (*vr)["DA"] = "Date";                     // Exactly 8 bytes
-   (*vr)["DS"] = "Decimal String";           // At most 16 bytes
-   (*vr)["DT"] = "Date Time";                // At most 26 bytes
-   (*vr)["FL"] = "Floating Point Single";    // 32-bit IEEE 754:1985 float
-   (*vr)["FD"] = "Floating Point Double";    // 64-bit IEEE 754:1985 double
-   (*vr)["IS"] = "Integer String";           // At most 12 bytes
-   (*vr)["LO"] = "Long String";              // At most 64 chars
-   (*vr)["LT"] = "Long Text";                // At most 10240 chars
-   (*vr)["OB"] = "Other Byte String";        // String of bytes (vr independant)
-   (*vr)["OW"] = "Other Word String";        // String of 16-bit words (vr dep)
-   (*vr)["PN"] = "Person Name";              // At most 64 chars
-   (*vr)["SH"] = "Short String";             // At most 16 chars
-   (*vr)["SL"] = "Signed Long";              // Exactly 4 bytes
-   (*vr)["SQ"] = "Sequence of Items";        // Not Applicable
-   (*vr)["SS"] = "Signed Short";             // Exactly 2 bytes
-   (*vr)["ST"] = "Short Text";               // At most 1024 chars
-   (*vr)["TM"] = "Time";                     // At most 16 bytes
-   (*vr)["UI"] = "Unique Identifier";        // At most 64 bytes
-   (*vr)["UL"] = "Unsigned Long ";           // Exactly 4 bytes
-   (*vr)["UN"] = "Unknown";                  // Any length of bytes
-   (*vr)["US"] = "Unsigned Short ";          // Exactly 2 bytes
-   (*vr)["UT"] = "Unlimited Text";           // At most 2^32 -1 chars
-   dicom_vr = vr; 
-}
-
 // Fourth semantics:
 // CMD      Command        
 // META     Meta Information 
@@ -324,7 +289,7 @@ void gdcmHeader::FindVR( gdcmElValue *ElVal) {
    // CLEANME searching the dicom_vr at each occurence is expensive.
    // PostPone this test in an optional integrity check at the end
    // of parsing or only in debug mode.
-   if ( RealExplicit && !dicom_vr->count(vr) )
+   if ( RealExplicit && !dicom_vr->Count(vr) )
       RealExplicit= false;
 
    if ( RealExplicit ) {
@@ -463,6 +428,7 @@ bool gdcmHeader::IsJPEGLossless(void) {
       return false;
    LoadElementValueSafe(Element);
    const char * Transfert = Element->GetValue().c_str();
+   printf("TransfertSyntx %s\n",Transfert);
    if ( memcmp(Transfert+strlen(Transfert)-2 ,"70",2)==0) return true;
    if ( memcmp(Transfert+strlen(Transfert)-2 ,"55",2)==0) return true;
    return false;
@@ -851,6 +817,7 @@ void gdcmHeader::LoadElementValue(gdcmElValue * ElVal) {
       return;
    }
    ElVal->SetValue(NewValue);
+   free(NewValue);
 }
 
 /**
@@ -896,6 +863,18 @@ guint32 gdcmHeader::ReadInt32(void) {
    return g;
 }
 
+
+gdcmElValue* gdcmHeader::GetElValueByNumber(guint16 Group, guint16 Elem) {
+
+   gdcmElValue* elValue = PubElValSet.GetElementByNumber(Group, Elem);  
+   if (!elValue) {
+      dbg.Verbose(1, "gdcmHeader::GetElValueByNumber",
+                  "failed to Locate gdcmElValue");
+      return (gdcmElValue*)0;
+   }
+   return elValue;
+}
+
 /**
  * \ingroup gdcmHeader
  * \brief   Build a new Element Value from all the low level arguments. 
@@ -1002,10 +981,11 @@ bool gdcmHeader::IsAnInteger(gdcmElValue * ElVal) {
       if (length == 4)
          return true;
       else {
-         printf("Erroneous Group Length element length %d\n",length);
+         printf("Erroneous Group Length element length (%04x , %04x) : %d\n",
+            group, element,length);
                     
          dbg.Error("gdcmHeader::IsAnInteger",
-                   "Erroneous Group Length element length.");     
+            "Erroneous Group Length element length.");     
       }
    }
  
@@ -1324,7 +1304,11 @@ string gdcmHeader::GetElValRepByName(string TagName) {
  */
 int gdcmHeader::SetPubElValByNumber(string content, guint16 group,
                                     guint16 element)
+                                    
+//TODO  : homogeneiser les noms : SetPubElValByNumber   qui appelle PubElValSet.SetElValueByNumber 
+//        pourquoi pas            SetPubElValueByNumber ??
 {
+
    return (  PubElValSet.SetElValueByNumber (content, group, element) );
 }
 
@@ -1456,18 +1440,36 @@ int gdcmHeader::GetZSize(void) {
    return 1;
 }
 
+/**
+ * \ingroup gdcmHeader
+ * \brief   Return the size (in bytes) of a single pixel of data.
+ * @return  The size in bytes of a single pixel of data.
+ *
+ */
+int gdcmHeader::GetPixelSize(void) {
+   string PixelType = GetPixelType();
+   if (PixelType == "8U" || PixelType == "8S")
+      return 1;
+   if (PixelType == "16U" || PixelType == "16S")
+      return 2;
+   if (PixelType == "32U" || PixelType == "32S")
+      return 4;
+   dbg.Verbose(0, "gdcmHeader::GetPixelSize: Unknown pixel type");
+   return 0;
+}
+
 /**
  * \ingroup gdcmHeader
  * \brief   Build the Pixel Type of the image.
  *          Possible values are:
- *          - U8  unsigned  8 bit,
- *          - S8    signed  8 bit,
- *          - U16 unsigned 16 bit,
- *          - S16   signed 16 bit,
- *          - U32 unsigned 32 bit,
- *          - S32   signed 32 bit,
+ *          - 8U  unsigned  8 bit,
+ *          - 8S    signed  8 bit,
+ *          - 16U unsigned 16 bit,
+ *          - 16S   signed 16 bit,
+ *          - 32U unsigned 32 bit,
+ *          - 32S   signed 32 bit,
  * \warning 12 bit images appear as 16 bit.
- * @return 
+ * @return  
  */
 string gdcmHeader::GetPixelType(void) {
    string BitsAlloc;