From 4df8e3bc348eeccf8f5c23fc652b83a767e45a82 Mon Sep 17 00:00:00 2001 From: jpr Date: Sat, 30 Jul 2005 18:31:25 +0000 Subject: [PATCH] vtkGdcmReader takes into account the user supplied function to reorder the pixels --- vtk/vtkGdcmReader.cxx | 78 ++++++++++++++++++++++++++++++------------- vtk/vtkGdcmReader.h | 16 ++++++--- 2 files changed, 66 insertions(+), 28 deletions(-) diff --git a/vtk/vtkGdcmReader.cxx b/vtk/vtkGdcmReader.cxx index 2970000e..786106ea 100644 --- a/vtk/vtkGdcmReader.cxx +++ b/vtk/vtkGdcmReader.cxx @@ -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 @@ -18,8 +18,42 @@ //----------------------------------------------------------------------------- // ////////////////////////////////////////////////////////////// +// +//===> 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 @@ -48,15 +82,15 @@ // 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, @@ -72,11 +106,7 @@ // 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" @@ -92,7 +122,7 @@ #include #include -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 diff --git a/vtk/vtkGdcmReader.h b/vtk/vtkGdcmReader.h index fd30e58b..ba30d132 100644 --- a/vtk/vtkGdcmReader.h +++ b/vtk/vtkGdcmReader.h @@ -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 #include +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 *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; + }; //----------------------------------------------------------------------------- -- 2.45.1