]> Creatis software - gdcm.git/commitdiff
Cosmetic modif
authorjpr <jpr>
Fri, 10 Sep 2004 18:54:38 +0000 (18:54 +0000)
committerjpr <jpr>
Fri, 10 Sep 2004 18:54:38 +0000 (18:54 +0000)
(Still don't solve Mathieu's pb on TestCopyDicom :-(

src/gdcmDocument.cxx
src/gdcmFile.cxx
src/gdcmFile.h
src/gdcmHeader.cxx
src/gdcmVR.cxx
src/gdcmValEntry.cxx

index e1dd5332337f11e10cd7a158daa0d867aae70783..9b5b2ac4e7f03d731f94e20a56c93b2a3b378f87 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmDocument.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/09/10 14:32:04 $
-  Version:   $Revision: 1.73 $
+  Date:      $Date: 2004/09/10 18:54:38 $
+  Version:   $Revision: 1.74 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -1034,7 +1034,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
    SetEntryVoidAreaByNumber(a, group, elem);
 
    return a;
@@ -1539,10 +1539,9 @@ void gdcmDocument::LoadDocEntry(gdcmDocEntry* entry)
    // When we find a BinEntry not very much can be done :
    if (gdcmBinEntry* binEntryPtr = dynamic_cast< gdcmBinEntry* >(entry) )
    {
-
-      LoadEntryVoidArea(binEntryPtr);
       s << "gdcm::Loaded (BinEntry)";
       binEntryPtr->SetValue(s.str());
+      LoadEntryVoidArea(binEntryPtr); // last one, not to erase length !
       return;
    }
     
index 000b5baeec758361b04d00ac8114851ff7472fd6..b3eb62e680299e2f8d0ba6a44de98e652057a7ed 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/09/09 17:49:25 $
-  Version:   $Revision: 1.123 $
+  Date:      $Date: 2004/09/10 18:54:38 $
+  Version:   $Revision: 1.124 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -38,26 +38,12 @@ typedef std::pair<TagDocEntryHT::iterator,TagDocEntryHT::iterator> IterHT;
  *        user sets an a posteriori shadow dictionary (efficiency can be
  *        seen as a side effect).   
  * @param header already built gdcmHeader
- * @return
  */
 gdcmFile::gdcmFile(gdcmHeader *header)
 {
    Header     = header;
    SelfHeader = false;
-   
-   PixelRead  = -1; // no ImageData read yet.
-   LastAllocatedPixelDataLength = 0;
-   PixelData = NULL;
-   
-   InitialSpp = "";     
-   InitialPhotInt = "";
-   InitialPlanConfig = "";
-   InitialBitsAllocated = "";
-       
-   if (Header->IsReadable())
-   {
-      SetPixelDataSizeFromHeader();
-   }
+   SetInitialValues();
 }
 
 /**
@@ -79,19 +65,65 @@ gdcmFile::gdcmFile(std::string const & filename )
 {
    Header = new gdcmHeader( filename );
    SelfHeader = true;
-   
+   SetInitialValues();
+}
+
+/**
+ * \ingroup   gdcmFile
+ * \brief Sets some initial for the Constructor
+ */
+void gdcmFile::SetInitialValues()
+{   
    PixelRead  = -1; // no ImageData read yet.
    LastAllocatedPixelDataLength = 0;
-   PixelData = NULL;
+   Pixel_Data = 0;
 
    InitialSpp = "";     
    InitialPhotInt = "";
    InitialPlanConfig = "";
    InitialBitsAllocated = "";
-           
+  
+   InitialRedLUTDescr   = 0;
+   InitialGreenLUTDescr = 0;
+   InitialBlueLUTDescr  = 0;
+   InitialRedLUTData    = 0;
+   InitialGreenLUTData  = 0;
+   InitialBlueLUTData   = 0; 
+                
    if ( Header->IsReadable() )
    {
       SetPixelDataSizeFromHeader();
+      
+      // the following values *may* be modified 
+      // by gdcmFile::GetImageDataIntoVectorRaw
+      // we save their initial value.
+      InitialSpp           = Header->GetEntryByNumber(0x0028,0x0002);
+      InitialPhotInt       = Header->GetEntryByNumber(0x0028,0x0004);
+      InitialPlanConfig    = Header->GetEntryByNumber(0x0028,0x0006);
+      InitialBitsAllocated = Header->GetEntryByNumber(0x0028,0x0100);
+               
+      // the following entries *may* be removed
+      // by gdcmFile::GetImageDataIntoVectorRaw  
+      // we save them.
+
+     // we SHALL save them !
+     // (some troubles, now)
+     /*
+      InitialRedLUTDescr   = Header->GetDocEntryByNumber(0x0028,0x1101);
+      InitialGreenLUTDescr = Header->GetDocEntryByNumber(0x0028,0x1102);
+      InitialBlueLUTDescr  = Header->GetDocEntryByNumber(0x0028,0x1103);
+      InitialRedLUTData    = Header->GetDocEntryByNumber(0x0028,0x1201);
+      InitialGreenLUTData  = Header->GetDocEntryByNumber(0x0028,0x1202);
+      InitialBlueLUTData   = Header->GetDocEntryByNumber(0x0028,0x1203); 
+      
+      if (InitialRedLUTData == NULL)
+         std::cout << "echec InitialRedLUTData " << std::endl;
+      else  
+      { 
+         printf("%p\n",InitialRedLUTData);
+         InitialRedLUTData->Print(); std::cout <<std::endl;
+      }
+     */        
    }
 }
 
@@ -102,12 +134,33 @@ gdcmFile::gdcmFile(std::string const & filename )
  *        it is destroyed by the gdcmFile
  */
 gdcmFile::~gdcmFile()
-{
+{ 
    if( SelfHeader )
    {
       delete Header;
    }
    Header = 0;
+
+   if ( InitialRedLUTDescr )           
+      delete InitialRedLUTDescr;
+     
+   if ( InitialGreenLUTDescr )
+      delete InitialGreenLUTDescr;
+      
+   if ( InitialBlueLUTDescr )      
+      delete InitialBlueLUTDescr; 
+          
+/* LATER ...
+       
+   if ( InitialRedLUTData )      
+      delete InitialRedLUTData;
+   
+   if ( InitialGreenLUTData != NULL)
+      delete InitialGreenLUTData;
+      
+   if ( InitialBlueLUTData != NULL)      
+      delete InitialBlueLUTData;      
+*/  
 }
 
 //-----------------------------------------------------------------------------
@@ -122,6 +175,7 @@ gdcmFile::~gdcmFile()
  *            image(s) pixels (multiframes taken into account) 
  * \warning : it is NOT the group 7FE0 length
  *          (no interest for compressed images).
+ * \warning : not end user intended ?
  */
 void gdcmFile::SetPixelDataSizeFromHeader()
 {
@@ -167,7 +221,8 @@ void gdcmFile::SetPixelDataSizeFromHeader()
          nb =16;
       }
    }
-   ImageDataSize =  ImageDataSizeRaw = Header->GetXSize() * Header->GetYSize() 
+   ImageDataSize =
+   ImageDataSizeRaw = Header->GetXSize() * Header->GetYSize() 
                 * Header->GetZSize() * (nb/8) * Header->GetSamplesPerPixel();
    std::string str_PhotometricInterpretation = 
                              Header->GetEntryByNumber(0x0028,0x0004);
@@ -181,21 +236,6 @@ void gdcmFile::SetPixelDataSizeFromHeader()
    }
 }
 
-
-/**
- * \ingroup   gdcmFile
- * \brief     Returns the size (in bytes) of required memory to hold
- *            the pixel data represented in this file, if user DOESN'T want 
- *            to get RGB pixels image when it's stored as a PALETTE COLOR image
- *            -the (vtk) user is supposed to know how to deal with LUTs-  
- * \warning   to be used with GetImagePixelsRaw()
- * @return    The size of pixel data in bytes.
- */
-size_t gdcmFile::GetImageDataSizeRaw()
-{
-   return ImageDataSizeRaw;
-}
-
 /**
  * \ingroup gdcmFile
  * \brief   - Allocates necessary memory, 
@@ -210,27 +250,32 @@ size_t gdcmFile::GetImageDataSizeRaw()
 void *gdcmFile::GetImageData()
 {
    // FIXME (Mathieu)
-   // I need to deallocate PixelData before doing any allocation:
+   // I need to deallocate Pixel_Data before doing any allocation:
    
-   if ( PixelData )
-      if ( LastAllocatedPixelDataLength != ImageDataSize)
-         free (PixelData);
-   PixelData = new uint8_t[ImageDataSize];
-   if ( PixelData )
+   if ( Pixel_Data )
+     if ( LastAllocatedPixelDataLength != ImageDataSize ) 
+        free(Pixel_Data);
+   if ( !Pixel_Data )
+      Pixel_Data = new uint8_t[ImageDataSize];
+    
+   if ( Pixel_Data )
    {
       LastAllocatedPixelDataLength = ImageDataSize;
-         
-      GetImageDataIntoVector(PixelData, ImageDataSize);
-      // Will be 7fe0, 0010 in standard case
-      GetHeader()->SetEntryVoidAreaByNumber( PixelData, 
-         GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel());
-      // Now, the value is loaded.
+
+      // we load the pixels (and transform grey level + LUT into RGB)
+      GetImageDataIntoVector(Pixel_Data, ImageDataSize);
+
+      // We say the value *is* loaded.
       GetHeader()->SetEntryByNumber( GDCM_BINLOADED,
          GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel());
+
+      // Will be 7fe0, 0010 in standard case
+      GetHeader()->SetEntryVoidAreaByNumber( Pixel_Data, 
+         GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel()); 
    }      
    PixelRead = 0; // no PixelRaw
 
-   return PixelData;
+   return Pixel_Data;
 }
 
 /**
@@ -337,27 +382,32 @@ void * gdcmFile::GetImageDataRaw ()
       imgDataSize = ImageDataSize;
     
    // FIXME (Mathieu)
-   // I need to deallocate PixelData before doing any allocation:
+   // I need to deallocate Pixel_Data before doing any allocation:
    
-   if ( PixelData )
-      if ( LastAllocatedPixelDataLength != imgDataSize)
-         free (PixelData);
-   PixelData = new uint8_t[imgDataSize];
-   if ( PixelData )
+   if ( Pixel_Data )
+      if ( LastAllocatedPixelDataLength != imgDataSize )
+         free(Pixel_Data);
+   if ( !Pixel_Data ) 
+      Pixel_Data = new uint8_t[imgDataSize];
+
+   if ( Pixel_Data )
    {
       LastAllocatedPixelDataLength = imgDataSize;
       
-      GetImageDataIntoVectorRaw(PixelData, imgDataSize);
-      // will be 7fe0, 0010 in standard cases
-      GetHeader()->SetEntryVoidAreaByNumber(PixelData, 
-         GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel()); 
-      // Now, the value is loaded.
+      // we load the pixels ( grey level or RGB, but NO transformation)
+       GetImageDataIntoVectorRaw(Pixel_Data, imgDataSize);
+
+      // We say the value *is* loaded.
       GetHeader()->SetEntryByNumber( GDCM_BINLOADED,
          GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel());
+      // will be 7fe0, 0010 in standard cases
+      GetHeader()->SetEntryVoidAreaByNumber(Pixel_Data, 
+         GetHeader()->GetGrPixel(), GetHeader()->GetNumPixel());
    } 
    PixelRead = 1; // PixelRaw
 
-   return PixelData;
+   return Pixel_Data;
 }
 
 /**
@@ -679,7 +729,7 @@ bool gdcmFile::SetImageData(void *inData, size_t expectedSize)
 {
    Header->SetImageDataSize( expectedSize );
 // FIXME : if already allocated, memory leak !
-   PixelData     = inData;
+   Pixel_Data     = inData;
    ImageDataSize = ImageDataSizeRaw = expectedSize;
    PixelRead     = 1;
 // FIXME : 7fe0, 0010 IS NOT set ...
@@ -704,7 +754,7 @@ bool gdcmFile::WriteRawData(std::string const & fileName)
       printf("Fail to open (write) file [%s] \n", fileName.c_str());
       return false;
    }
-   fwrite (PixelData, ImageDataSize, 1, fp1);
+   fwrite (Pixel_Data, ImageDataSize, 1, fp1);
    fclose (fp1);
 
    return true;
@@ -848,7 +898,7 @@ bool gdcmFile::WriteBase (std::string const & fileName, FileType type)
    }
    // ----------------- End of Special Patch ----------------
    
-   // fwrite(PixelData, ImageDataSize, 1, fp1);  // should be useless, now
+   // fwrite(Pixel_Data, ImageDataSize, 1, fp1);  // should be useless, now
    fclose (fp1);
 
    return true;
index 908370961863810ff393fd9bf7c9e625f16758df..a78434c2e76be7ddf56f3155ba4ff01e14ebe90d 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmFile.h,v $
   Language:  C++
-  Date:      $Date: 2004/09/03 07:57:10 $
-  Version:   $Revision: 1.44 $
+  Date:      $Date: 2004/09/10 18:54:39 $
+  Version:   $Revision: 1.45 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -46,7 +46,12 @@ public:
 ///            the pixel data represented in this file.
    size_t GetImageDataSize(){ return ImageDataSize; };
 
-   size_t GetImageDataSizeRaw();
+   
+/// \brief     Returns the size (in bytes) of required memory to hold
+///            the pixel data represented in this file, if user DOESN'T want 
+///            to get RGB pixels image when it's stored as a PALETTE COLOR image
+///            -the (vtk) user is supposed to know how to deal with LUTs-     
+   size_t GetImageDataSizeRaw(){ return ImageDataSizeRaw; };
 
    void * GetImageData();
    size_t GetImageDataIntoVector(void* destination, size_t maxSize);
@@ -89,7 +94,7 @@ protected:
 
 private:
    void SwapZone(void* im, int swap, int lgr, int nb);
-   
+   void gdcmFile::SetInitialValues();  
    bool ReadPixelData(void * destination);
    
    // For JPEG 8 Bits, body in file gdcmJpeg.cxx
@@ -117,7 +122,7 @@ private:
    bool SelfHeader;
 
    /// \brief to hold the Pixels (when read)
-   void* PixelData;
+   void* Pixel_Data;  // (was PixelData; should be removed)
    
    /// \brief Area length to receive the pixels
    size_t ImageDataSizeRaw;
@@ -137,7 +142,10 @@ private:
   /// \brief length of the last allocated area devoided to receive Pixels
   ///        ( to allow us not to (free + new) if un necessary )     
    size_t LastAllocatedPixelDataLength; 
-   
+
+  // Initial values of some fields that can be modified during reading process
+  // if user asked to transform gray level + LUT image into RGB image
+     
   /// \brief Samples Per Pixel           (0x0028,0x0002), as found on disk
    std::string InitialSpp;
   /// \brief Photometric Interpretation  (0x0028,0x0004), as found on disk
@@ -147,6 +155,22 @@ private:
   /// \brief Bits Allocated              (0x0028,0x0100), as found on disk
    std::string InitialBitsAllocated;
    
+  // some DocEntry that can be moved ou of the H table during reading process
+  // if user asked to transform gray level + LUT image into RGB image
+   
+  /// \brief Red Palette Color Lookup Table Descriptor   0028 1101 as read
+  gdcmDocEntry* InitialRedLUTDescr;  
+  /// \brief Green Palette Color Lookup Table Descriptor 0028 1102 as read
+  gdcmDocEntry* InitialGreenLUTDescr;
+  /// \brief Blue Palette Color Lookup Table Descriptor  0028 1103 as read
+  gdcmDocEntry* InitialBlueLUTDescr;
+  
+  /// \brief Red Palette Color Lookup Table Data         0028 1201 as read
+  gdcmDocEntry* InitialRedLUTData;  
+  /// \brief Green Palette Color Lookup Table Data       0028 1202 as read
+  gdcmDocEntry* InitialGreenLUTData;
+  /// \brief Blue Palette Color Lookup Table Data        0028 1203 as read
+  gdcmDocEntry* InitialBlueLUTData;
 
 };
 
index 654a1b08e831d8ffb4ad4a503c74cf51c525878b..6eb2f39b96e20f84ee8295e6b4509f41778fddf8 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmHeader.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/09/09 17:49:25 $
-  Version:   $Revision: 1.184 $
+  Date:      $Date: 2004/09/10 18:54:39 $
+  Version:   $Revision: 1.185 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -108,10 +108,7 @@ void gdcmHeader::Write(FILE* fp,FileType filetype)
       SetEntryByNumber("16", 0x0028,0x0100);
    }
 
-  // correct Pixel group Length if necessary
-
-   // TODO : create a gdcmHeader::Write method and move this part.
-   //        (only gdcmHeader knows GrPixel, NumPixel)
+  // TODO : correct 'Pixel group' Length if necessary
 
    int i_lgPix = GetEntryLengthByNumber(GrPixel, NumPixel);
    if (i_lgPix != -2)
index 3fcb456cd0774173e51602ae22be8882d0a67ead..c400af1489e6200db6120feb75d53fe0b650c765 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmVR.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/07/02 13:55:28 $
-  Version:   $Revision: 1.15 $
+  Date:      $Date: 2004/09/10 18:54:39 $
+  Version:   $Revision: 1.16 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -99,10 +99,16 @@ int gdcmVR::Count(gdcmVRKey key)
  *          corresponds to the Value Representation of a \ref gdcmBinEntry .
  *          This predicate is the negation of
  *          \ref gdcmVR::IsVROfGdcmStringRepresentable .
- * @param   tested value represenation to check for.
+ * @param   tested value representation to check for.
  */
 bool gdcmVR::IsVROfGdcmBinaryRepresentable(gdcmVRKey tested)
 {
+   //std::cout << "gdcmVR::IsVROfGdcmBinaryRepresentable===================="
+   //   << tested << std::endl;
+
+   if ( tested == "unkn")
+      return true;
+
    if ( ! Count(tested) )
    {
       dbg.Verbose(0, "gdcmVR::IsVROfGdcmBinaryRepresentable: tested not a VR!");
@@ -122,10 +128,11 @@ bool gdcmVR::IsVROfGdcmBinaryRepresentable(gdcmVRKey tested)
  * \brief   Simple predicate that checks wether the given argument
  *          corresponds to the Value Representation of a \ref gdcmValEntry
  *          but NOT a \ref gdcmBinEntry.
- * @param   tested value represenation to check for.
+ * @param   tested value representation to check for.
  */
 bool gdcmVR::IsVROfGdcmStringRepresentable(gdcmVRKey tested)
 {
+
    if ( ! Count(tested) )
    {
       dbg.Verbose(0, "gdcmVR::IsVROfGdcmStringRepresentable: tested not a VR!");
index ebf6947fc12477124ee21ebfc2bb47f359815d9f..c1018fcaa2a235a3e3795d6018cb29549e4600b1 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmValEntry.cxx,v $
   Language:  C++
-  Date:      $Date: 2004/09/09 17:49:25 $
-  Version:   $Revision: 1.23 $
+  Date:      $Date: 2004/09/10 18:54:39 $
+  Version:   $Revision: 1.24 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -182,6 +182,8 @@ void gdcmValEntry::Print(std::ostream & os)
 void gdcmValEntry::Write(FILE *fp, FileType filetype)
 {
    gdcmDocEntry::Write(fp, filetype);
+
+   //std::cout << "=====================================" << GetVR() << std::endl;
       
    if ( GetGroup() == 0xfffe ) 
    {