]> Creatis software - gdcm.git/commitdiff
vtkGdcmReader takes into account the user supplied function to reorder the
authorjpr <jpr>
Sat, 30 Jul 2005 18:31:25 +0000 (18:31 +0000)
committerjpr <jpr>
Sat, 30 Jul 2005 18:31:25 +0000 (18:31 +0000)
pixels

vtk/vtkGdcmReader.cxx
vtk/vtkGdcmReader.h

index 2970000e2c20609df97f15d90b839caf82a509f0..786106ea5ba13b3fd0c674f3ade01b644a764a12 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: vtkGdcmReader.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/07/17 04:34:20 $
-  Version:   $Revision: 1.73 $
+  Date:      $Date: 2005/07/30 18:31:25 $
+  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
                                                                                 
 //-----------------------------------------------------------------------------
 // //////////////////////////////////////////////////////////////
+//
+//===>  Many users expect from vtkGdcmReader it 'orders' the images
+//     (that's the job of gdcm::SerieHelper ...)
+//     When user *knows* the files with same Serie UID 
+//        have same sizes, same 'pixel' type, same color convention, ...
+//     the right way to proceed is as follow :
+//
+//      gdcm::SerieHelper *sh= new gdcm::SerieHelper();
+//      // if user wants *not* to load some parts of the file headers
+//      sh->SetLoadMode(loadMode);
+//      // if user wants *not* to load some files 
+//      sh->AddRestriction(group, element, value, operator);
+//      sh->AddRestriction( ...
+//      sh->SetDirectory(directoryWithImages);
+//
+//      // if user wants to sort reverse order
+//      sh->SetSortOrderToReverse(); 
+//      // here, we suppose only the first Coherent File List is of interest
+//      gdcm::FileList *l = sh->GetFirstCoherentFileList();
+//      // if user is doesn't trust too much the files with same Serie UID 
+//      if ( !sh->IsCoherent(l) )
+//         return; // not same sizes, same 'pixel' type -> stop
+//      sh->OrderFileList(l);        // sort the list
+//
+//      vtkGdcmReader *reader = vtkGdcmReader::New();
+//      // if user wants to modify pixel order (Mirror, TopDown, 90°Rotate, ...)
+//      // he has to supply the function that does the job 
+//      // (a *very* simple example is given in vtkgdcmSerieViewer.cxx)
+//      reader->SetUserFunction (userSuppliedFunction);
+//      // to pass a 'Coherent File List' as produced by gdcm::SerieHelper
+//      reader->SetCoherentFileList(l); 
+//      reader->Update();
 // WARNING TODO CLEANME 
-// Actual limitations of this code:
+// Actual limitations of this code 
+//  when a Coherent File List from SerieHelper is not used (bad idea :-(
 //
 // /////// Redundant and unnecessary header parsing
 // In it's current state this code actually parses three times the Dicom
 //      is compared to this new value to find a modification in the class
 //      parameters
 //  2b/ the core of ExecuteData then needs gdcm::File (which in turns
-//      initialises gdcm::File in the constructor) in order to access
+//      initializes gdcm::File in the constructor) in order to access
 //      the data-image.
 //
 // Possible solution:
 // maintain a list of gdcm::Files (created by say ExecuteInformation) created
 // once and for all accross the life of vtkGdcmFile (it would only load
 // new gdcm::File if the user changes the list). ExecuteData would then use 
-// those gdcm::File and hence avoid calling the construtor:
-//  - advantage: the header of the files would only be parser once.
+// those gdcm::File and hence avoid calling the constructor:
+//  - advantage: the header of the files would only be parsed once.
 //  - drawback: once execute information is called (i.e. on creation of
 //              a vtkGdcmFile) the gdcm::File structure is loaded in memory.
 //              The average size of a gdcm::File being of 100Ko, 
 // time...
 //
 //
-//===>  Since many users expect from vtkGdcmReader it 'orders' the images
-//     (that's the job of gdcm::SerieHelper), user may now call 
-//      vtkGdcmReader::SetCoherentFileList() to pass a 'Coherent File List'
-//      as produced by gdcm::SerieHelper
-//     See the limitations of gdcm::SerieHelper before ... 
+
 // //////////////////////////////////////////////////////////////
 
 #include "gdcmFileHelper.h"
 #include <vtkPointData.h>
 #include <vtkLookupTable.h>
 
-vtkCxxRevisionMacro(vtkGdcmReader, "$Revision: 1.73 $");
+vtkCxxRevisionMacro(vtkGdcmReader, "$Revision: 1.74 $");
 vtkStandardNewMacro(vtkGdcmReader);
 
 //-----------------------------------------------------------------------------
@@ -105,6 +135,7 @@ vtkGdcmReader::vtkGdcmReader()
    this->LoadMode = 0; // Load everything (possible values : NO_SEQ, NO_SHADOW,
                        //                                    NO_SHADOWSEQ)
    this->CoherentFileList = 0;
+   this->UserFunction     = 0;
 }
 
 vtkGdcmReader::~vtkGdcmReader()
@@ -532,7 +563,7 @@ int vtkGdcmReader::CheckFileCoherence()
       {
          vtkErrorMacro(<< "Unable to open file " << filename->c_str());
          vtkErrorMacro(<< "Removing this file from read files: "
-                     << filename->c_str());
+                       << filename->c_str());
          *filename = "GDCM_UNREADABLE";
          continue;
       }
@@ -540,12 +571,11 @@ int vtkGdcmReader::CheckFileCoherence()
 
       // Stage 1.2: check for Gdcm parsability
 
-      //gdcm::File GdcmFile( filename->c_str() );
-
       // to save some parsing time.
       gdcm::File GdcmFile;
       GdcmFile.SetLoadMode( LoadMode );
-      GdcmFile.Load(filename->c_str() );
+      GdcmFile.SetFileName(filename->c_str() );
+      GdcmFile.Load( );
       if (!GdcmFile.IsReadable())
       {
          vtkErrorMacro(<< "Gdcm cannot parse file " << filename->c_str());
@@ -564,7 +594,7 @@ int vtkGdcmReader::CheckFileCoherence()
          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");
+                       << "   Removing this file from read files");
          *filename = "GDCM_UNREADABLE";
          continue;
       }
@@ -581,9 +611,9 @@ int vtkGdcmReader::CheckFileCoherence()
              || ( type != this->ImageType ) ) 
          {
             vtkErrorMacro(<< "This file is not coherent with previous ones: "
-                           << filename->c_str());
-            vtkErrorMacro(<< "Removing this file from readed files: "
-                           << filename->c_str());
+                          << filename->c_str());
+            vtkErrorMacro(<< "Removing this file from read files: "
+                          << filename->c_str());
             *filename = "GDCM_UNREADABLE";
             continue;
          }
@@ -592,19 +622,19 @@ int vtkGdcmReader::CheckFileCoherence()
          if ( NZ != ReferenceNZ )
          {
             vtkErrorMacro(<< "File is not coherent in Z with previous ones: "
-                           << filename->c_str());
+                          << filename->c_str());
          }
          else
          {
             vtkDebugMacro(<< "File is coherent with previous ones: "
-                           << filename->c_str());
+                          << filename->c_str());
          }
 
          // Stage 2.3: when the file is 'multiframe', notify the caller.
          if (NZ > 1)
          {
             vtkErrorMacro(<< "This file is a 'Multiframe' one: "
-                           << filename->c_str());
+                          << filename->c_str());
          }
 
          // Eventually, this file can be added on the stack. Update the
@@ -746,6 +776,8 @@ size_t vtkGdcmReader::DoTheLoadingJob (gdcm::File *f,
                                        unsigned long &updateProgressCount)
 {
    gdcm::FileHelper *fileH = new gdcm::FileHelper( f );
+   fileH->SetUserFunction( UserFunction );
+
    size_t size;
 
    // If the data structure of vtk for image/volume representation
index fd30e58bba9f028cbcd421076f9275ad61003eee..ba30d132ff6dcf26c01edd8e3194361d2bc0b58c 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: vtkGdcmReader.h,v $
   Language:  C++
-  Date:      $Date: 2005/07/17 04:34:20 $
-  Version:   $Revision: 1.23 $
+  Date:      $Date: 2005/07/30 18:31:25 $
+  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
@@ -27,6 +27,8 @@
 #include <string>
 #include <vector>
 
+typedef void (*VOID_FUNCTION_PUINT8_PFILE_POINTER)(uint8_t *, gdcm::File *);
+
 //-----------------------------------------------------------------------------
 class vtkLookupTable;
 
@@ -42,9 +44,10 @@ public:
    virtual void AddFileName(const char *name);
    virtual void SetFileName(const char *name);
    void SetCoherentFileList( std::vector<gdcm::File* > *cfl) {
-                                                      CoherentFileList = cfl; };    
+                                                      CoherentFileList = cfl; }    
    void SetCheckFileCoherenceLight();
-   
+   void SetUserFunction (VOID_FUNCTION_PUINT8_PFILE_POINTER userFunc )
+                        { UserFunction = userFunc; }   
    // Description:
    // If this flag is set and the DICOM reader encounters a dicom file with 
    // lookup table the data will be kept as unsigned chars and a lookuptable 
@@ -131,10 +134,13 @@ private:
    /// \brief Bit string integer (each one considered as a boolean)
    ///        Bit 0 : Skip Sequences,    if possible
    ///        Bit 1 : Skip Shadow Groups if possible
-  ///         Bit 2 : Skip Sequences inside a Shadow Group, if possible
+   ///        Bit 2 : Skip Sequences inside a Shadow Group, if possible
    ///        Probabely (?), some more to add
    int LoadMode;
 
+   /// Pointer to a user suplied function to allow modification of pixel order
+   VOID_FUNCTION_PUINT8_PFILE_POINTER UserFunction;
+
 };
 
 //-----------------------------------------------------------------------------