]> Creatis software - gdcm.git/blobdiff - vtk/vtkGdcmReader.cxx
* src/gdcmDict.cxx, gdcmElValSet.cxx : bug fix under windows for prints.
[gdcm.git] / vtk / vtkGdcmReader.cxx
index aaa0d53b21ebc5b00032012a2f70a8d71753d844..1e0852bdbab52c64923cf2d9c62321b20455b80e 100644 (file)
@@ -1,4 +1,4 @@
-// $Header: /cvs/public/gdcm/vtk/vtkGdcmReader.cxx,v 1.22 2003/10/30 17:06:02 jpr Exp $
+// $Header: /cvs/public/gdcm/vtk/vtkGdcmReader.cxx,v 1.29 2003/12/22 12:46:19 regrain Exp $
 // //////////////////////////////////////////////////////////////
 // WARNING TODO CLENAME 
 // Actual limitations of this code:
 // time...
 // //////////////////////////////////////////////////////////////
 
-#include <stdio.h>
+#include "gdcmFile.h"
+#include "gdcmHeaderHelper.h"
+#include "vtkGdcmReader.h"
+
+//#include <stdio.h>
 #include <vtkObjectFactory.h>
 #include <vtkImageData.h>
 #include <vtkPointData.h>
-#include "vtkGdcmReader.h"
-#include "gdcm.h"
-#include "gdcmHeaderHelper.h"
+#include <vtkLookupTable.h>
+
 
 vtkGdcmReader::vtkGdcmReader()
 {
   // Constructor
+  this->LookupTable = NULL;
 }
 
 //----------------------------------------------------------------------------
@@ -60,6 +64,7 @@ vtkGdcmReader::~vtkGdcmReader()
 { 
   this->RemoveAllFileName();
   this->InternalFileNameList.clear();
+  if(this->LookupTable) this->LookupTable->Delete();
 }
 
 //----------------------------------------------------------------------------
@@ -239,6 +244,7 @@ int vtkGdcmReader::CheckFileCoherence()
          && (type != "32U") && (type != "32S") )
        {
        vtkErrorMacro("Bad File Type for file" << FileName->c_str());
+       vtkErrorMacro("                      " << type.c_str());
        vtkErrorMacro("Removing this file from readed files "
                      << FileName->c_str());
        *FileName = "GDCM_UNREADABLE";
@@ -307,7 +313,15 @@ int vtkGdcmReader::CheckFileCoherence()
        ReturnedTotalNumberOfPlanes += NZ - 1; // First plane already added
        this->ImageType = type;
        this->PixelSize = GdcmHeader.GetPixelSize();
-       this->NumComponents = GdcmHeader.GetNumberOfScalarComponents(); //rgb or mono
+       
+       if( GdcmHeader.HasLUT() )
+         {
+         this->NumComponents = GdcmHeader.GetNumberOfScalarComponentsRaw();
+         }
+       else
+         {
+         this->NumComponents = GdcmHeader.GetNumberOfScalarComponents(); //rgb or mono
+         }
        
        //Set image spacing
        this->DataSpacing[0] = GdcmHeader.GetXSpacing();
@@ -357,7 +371,7 @@ void vtkGdcmReader::ExecuteInformation()
     }
       
   // if the user has not set the extent, but has set the VOI
-  // set the zaxis extent to the VOI z axis
+  // set the z axis extent to the VOI z axis
   if (this->DataExtent[4]==0 && this->DataExtent[5] == 0 &&
      (this->DataVOI[4] || this->DataVOI[5]))
     {
@@ -449,7 +463,7 @@ size_t vtkGdcmReader::LoadImageInMemory(
 {
   vtkDebugMacro("Copying to memory image" << FileName.c_str());
   gdcmFile GdcmFile(FileName.c_str());
-  size_t size = GdcmFile.GetImageDataSize();
+  size_t size;
 
   // If the data structure of vtk for image/volume representation
   // were straigthforwards the following would suffice:
@@ -457,11 +471,38 @@ size_t vtkGdcmReader::LoadImageInMemory(
   // But vtk chooses to invert the lines of an image, that is the last
   // line comes first (for some axis related reasons?). Hence we need
   // to load the image line by line, starting from the end.
-  int NumColumns = GdcmFile.GetXSize();
-  int NumLines   = GdcmFile.GetYSize();
-  int NumPlanes  = GdcmFile.GetZSize();
-  int LineSize   = NumComponents * NumColumns * GdcmFile.GetPixelSize();
-  unsigned char * Source      = (unsigned char*)GdcmFile.GetImageData();
+  int NumColumns = GdcmFile.GetHeader()->GetXSize();
+  int NumLines   = GdcmFile.GetHeader()->GetYSize();
+  int NumPlanes  = GdcmFile.GetHeader()->GetZSize();
+  int LineSize   = NumComponents * NumColumns * GdcmFile.GetHeader()->GetPixelSize();
+
+  unsigned char * Source;
+  if( GdcmFile.GetHeader()->HasLUT() )
+    {
+    size               = GdcmFile.GetImageDataSizeRaw();
+    Source             = (unsigned char*) GdcmFile.GetImageDataRaw();
+    unsigned char *Lut =                  GdcmFile.GetHeader()->GetLUTRGBA();
+  
+    if(!this->LookupTable) this->LookupTable = vtkLookupTable::New();
+    this->LookupTable->SetNumberOfTableValues(256);
+    for (int tmp=0; tmp<256; tmp++)
+      {
+      this->LookupTable->SetTableValue(tmp,
+        (float)Lut[4*tmp+0]/255.0,
+        (float)Lut[4*tmp+1]/255.0,
+        (float)Lut[4*tmp+2]/255.0,
+        1);
+      }
+    this->LookupTable->SetRange(0,255);
+    vtkDataSetAttributes *a=this->GetOutput()->GetPointData();
+    a->GetScalars()->SetLookupTable(this->LookupTable);
+    free(Lut);
+    }
+  else
+    {
+    size        = GdcmFile.GetImageDataSize();
+    Source      = (unsigned char*)GdcmFile.GetImageData();
+    }
   unsigned char * pSource     = Source; //pointer for later deletion
   unsigned char * Destination = Dest + size - LineSize;