]> Creatis software - gdcm.git/blobdiff - vtk/vtkGdcmReader.cxx
* vtk/vtkGdcm*.[h|cxx] : remove warnings. Add header to files
[gdcm.git] / vtk / vtkGdcmReader.cxx
index ae0c80999afeb23db64cc783415d4e224c74b52e..91556c82e9803f3999f1f3decf2ee05f470c3d8e 100644 (file)
@@ -1,4 +1,21 @@
-// vtkGdcmReader.cxx
+/*=========================================================================
+                                                                                
+  Program:   gdcm
+  Module:    $RCSfile: vtkGdcmReader.cxx,v $
+  Language:  C++
+  Date:      $Date: 2004/12/09 10:59:59 $
+  Version:   $Revision: 1.64 $
+                                                                                
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
+                                                                                
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+                                                                                
+=========================================================================*/
+                                                                                
 //-----------------------------------------------------------------------------
 // //////////////////////////////////////////////////////////////
 // WARNING TODO CLEANME 
@@ -58,7 +75,7 @@
 #include <vtkPointData.h>
 #include <vtkLookupTable.h>
 
-vtkCxxRevisionMacro(vtkGdcmReader, "$Revision: 1.59 $");
+vtkCxxRevisionMacro(vtkGdcmReader, "$Revision: 1.64 $");
 vtkStandardNewMacro(vtkGdcmReader);
 
 //-----------------------------------------------------------------------------
@@ -460,10 +477,10 @@ int vtkGdcmReader::CheckFileCoherence()
           && (type != "16U") && (type != "16S")
           && (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());
+         vtkErrorMacro(<< "Bad File Type for file " << filename->c_str() << "\n"
+                       << "   File type found : " << type.c_str() 
+                       << " (might be 8U, 8S, 16U, 16S, 32U, 32S) \n"
+                       << "   Removing this file from readed files");
          *filename = "GDCM_UNREADABLE";
          continue;
       }
@@ -548,9 +565,9 @@ int vtkGdcmReader::CheckFileCoherence()
          this->DataSpacing[2] = GdcmHeader.GetZSpacing();
 
          //Set image origin
-         this->DataOrigin[0] = GdcmHeader.GetXOrigin();
-         this->DataOrigin[1] = GdcmHeader.GetYOrigin();
-         this->DataOrigin[2] = GdcmHeader.GetZOrigin();
+         //this->DataOrigin[0] = GdcmHeader.GetXOrigin();
+         //this->DataOrigin[1] = GdcmHeader.GetYOrigin();
+         //this->DataOrigin[2] = GdcmHeader.GetZOrigin();
 
       }
    } // End of loop on filename
@@ -607,7 +624,7 @@ void vtkGdcmReader::AddInternalFileName(const char* name)
  */
 size_t vtkGdcmReader::LoadImageInMemory(
              std::string fileName, 
-             unsigned char * dest,
+             unsigned char *dest,
              const unsigned long updateProgressTarget,
              unsigned long & updateProgressCount)
 {
@@ -626,13 +643,14 @@ size_t vtkGdcmReader::LoadImageInMemory(
    int numLines   = file.GetHeader()->GetYSize();
    int numPlanes  = file.GetHeader()->GetZSize();
    int lineSize   = NumComponents * numColumns * file.GetHeader()->GetPixelSize();
+   int planeSize  = lineSize * numLines;
 
-   unsigned char * source;
+   unsigned char *src;
    
    if( file.GetHeader()->HasLUT() && AllowLookupTable )
    {
       size               = file.GetImageDataSize();
-      source             = (unsigned char*) file.GetImageDataRaw();
+      src                = (unsigned char*) file.GetImageDataRaw();
       unsigned char *lut = (unsigned char*) file.GetLutRGBA();
 
       if(!this->LookupTable)
@@ -656,20 +674,19 @@ size_t vtkGdcmReader::LoadImageInMemory(
    }
    else
    {
-      size        = file.GetImageDataSize();
-      source      = (unsigned char*)file.GetImageData();
+      size = file.GetImageDataSize();
+      src  = (unsigned char*)file.GetImageData();
    } 
-   
-   unsigned char * destination = dest + size - lineSize;
 
+   unsigned char *dst = dest + planeSize - lineSize;
    for (int plane = 0; plane < numPlanes; plane++)
    {
       for (int line = 0; line < numLines; line++)
       {
          // Copy one line at proper destination:
-         memcpy((void*)destination, (void*)source, lineSize);
-         source      += lineSize;
-         destination -= lineSize;
+         memcpy((void*)dst, (void*)src, lineSize);
+         src += lineSize;
+         dst -= lineSize;
          // Update progress related:
          if (!(updateProgressCount%updateProgressTarget))
          {
@@ -677,17 +694,9 @@ size_t vtkGdcmReader::LoadImageInMemory(
          }
          updateProgressCount++;
       }
+      dst += 2 * planeSize;
    }
    
-// DO NOT remove this commented out code .
-// Nobody knows what's expecting you ...
-// Just to 'see' what was actually read on disk :-(
-
-//   FILE * f2;
-//   f2 = fopen("SpuriousFile.RAW","wb");
-//   fwrite(Dest,size,1,f2);
-//   fclose(f2); 
-   
    return size;
 }