From f5c47bcc13869c12ebdd1124283094c6fd666ec5 Mon Sep 17 00:00:00 2001 From: "eduardo.davila@creatis.insa-lyon.fr" Date: Mon, 28 Sep 2026 16:56:19 +0200 Subject: [PATCH] #3547 change gdcm1 to gdcm2 --- kernel/src/bbtkBlackBox.cxx | 1 - .../bbgdcmvtkGetXCoherentInfoGdcmReader.cxx | 154 ++++++++++++++++-- .../src/bbgdcmvtkGetXCoherentInfoGdcmReader.h | 20 ++- 3 files changed, 156 insertions(+), 19 deletions(-) diff --git a/kernel/src/bbtkBlackBox.cxx b/kernel/src/bbtkBlackBox.cxx index 9477c484..348af879 100644 --- a/kernel/src/bbtkBlackBox.cxx +++ b/kernel/src/bbtkBlackBox.cxx @@ -24,7 +24,6 @@ # knowledge of the CeCILL-B license and that you accept its terms. # ------------------------------------------------------------------------ */ - /*========================================================================= Program: bbtk Module: $RCSfile: bbtkBlackBox.cxx,v $ diff --git a/packages/gdcmvtk/src/bbgdcmvtkGetXCoherentInfoGdcmReader.cxx b/packages/gdcmvtk/src/bbgdcmvtkGetXCoherentInfoGdcmReader.cxx index 56a4e4b7..a3287da5 100644 --- a/packages/gdcmvtk/src/bbgdcmvtkGetXCoherentInfoGdcmReader.cxx +++ b/packages/gdcmvtk/src/bbgdcmvtkGetXCoherentInfoGdcmReader.cxx @@ -31,19 +31,28 @@ #include "vtkImageData.h" #include + #if defined USE_GDCM #include "gdcmFileHelper.h" #endif - #if defined USE_GDCM2 - #include - #include - #include - #include - #include "vtkStringArray.h" + + #include "gdcmReader.h" + #include "gdcmGlobal.h" +// #include "gdcmDicts.h" +// #include "gdcmDict.h" + #include "gdcmAttribute.h" + #include "gdcmStringFilter.h" + + #include + #include + #include + #include "gdcmIPPSorter.h" + #include "vtkStringArray.h" #endif + namespace bbgdcmvtk { @@ -278,11 +287,16 @@ void GetXCoherentInfoGdcmReader::Process() #if defined USE_GDCM2 void GetXCoherentInfoGdcmReader::Process() { -// printf("GetXCoherentInfoGdcmReader %d files.\n", bbGetInputIn().size() ); + /* Old version of GDCM2 + + printf("GetXCoherentInfoGdcmReader %d files.\n", bbGetInputIn().size() ); // Read the *first* image file (a SET of file names is given as input) gdcm::Reader *read = new gdcm::Reader(); + printf("EED GetXCoherentInfoGdcmReader::Process 0.0\n"); reader->SetFileName( bbGetInputIn()[0].c_str() ); - bool res = read->Read(); + printf("EED GetXCoherentInfoGdcmReader::Process 0.1\n"); + bool res = read->Read(); + printf("EED GetXCoherentInfoGdcmReader::Process 0.2\n"); if ( !res ) { delete read; @@ -290,6 +304,8 @@ void GetXCoherentInfoGdcmReader::Process() return; } + printf("EED GetXCoherentInfoGdcmReader::Process 1\n"); + // Get info from the first image file const gdcm::File &f = read->GetFile(); int i; @@ -305,6 +321,8 @@ void GetXCoherentInfoGdcmReader::Process() } bbSetOutputIOP(v_iop ); + printf("EED GetXCoherentInfoGdcmReader::Process 2\n"); + std::vector v_ipp; const gdcm::DataElement &deIpp = f.GetDataSet().GetDataElement(gdcm::Tag((0x0020,0x0032))); deIpp.GetValue().Print(ss); @@ -329,13 +347,15 @@ void GetXCoherentInfoGdcmReader::Process() //int nbFiles; double zspacing = 0.; - zspacing = s.GetZSpacing(); + zspacing = s.GetZSpacing(); std::vector v_pixelspacing = gdcm::ImageHelper::GetSpacingValue(f); v_pixelspacing.push_back( v_pixelspacing[0] ); v_pixelspacing.push_back( v_pixelspacing[1] ); v_pixelspacing.push_back( zspacing ); bbSetOutputPixelSpacing(v_pixelspacing); + printf("EED GetXCoherentInfoGdcmReader::Process 3\n"); + if (reader!=NULL) { reader->Delete(); @@ -349,16 +369,130 @@ void GetXCoherentInfoGdcmReader::Process() const std::string &f = *it; files->InsertNextValue( f.c_str() ); } + printf("EED GetXCoherentInfoGdcmReader::Process 4\n"); + reader->SetFileNames(files); reader->Update(); bbSetOutputOut( reader->GetOutput() ); + */ + + //EED 2026-05-26 + gdcm::IPPSorter s; + s.SetComputeZSpacing( true ); +// s.SetZSpacingTolerance( 1e-4 ); + s.SetZSpacingTolerance( 1e-4 ); + + std::vector< std::string > im = bbGetInputIn(); + bool b = s.Sort( im ); + + if( !b ) + { + std::cerr << "Failed to sort DICOM Files:" << std::endl; + //return ; + } + double ippzspacing = s.GetZSpacing(); + const std::vector &sorted = s.GetFilenames(); + vtkStringArray *files = vtkStringArray::New(); + std::vector< std::string >::const_iterator it = sorted.begin(); + for( ; it != sorted.end(); ++it) + { + const std::string &f = *it; + files->InsertNextValue( f.c_str() ); + } + reader = vtkGDCMImageReader2::New(); + reader->SetFileNames( files ); + reader->SetFileLowerLeft( true ); + reader->Update(); + double imageSpc[3]; + double imageOrigin[3]; + std::vector v_iop; + std::vector v_ipp; + std::vector v_pixelspacing; + reader->GetOutput()->GetSpacing( imageSpc); + changeInformation = vtkImageChangeInformation::New(); + changeInformation->SetInputData( reader->GetOutput() ); + reader->GetOutput()->GetOrigin(imageOrigin); + changeInformation->SetOutputSpacing( imageSpc[0], imageSpc[1], ippzspacing ); + changeInformation->Update(); + vtkImageData* outputimage = changeInformation->GetOutput(); + outputimage->GetSpacing( imageSpc ); + outputimage->GetOrigin( imageOrigin ); // this is the same of tag<0x0020,0x0032> + + // --------------------------------------- + // Instantiate the reader: + gdcm::Reader reader; + reader.SetFileName( sorted[0].c_str() ); + if( !reader.Read() ) + { + printf("EED Warning!!! (A) GetXCoherentInfoGdcmReader Cant read dicom file\n"); + } + gdcm::File &file = reader.GetFile(); + gdcm::DataSet &ds = file.GetDataSet(); + + gdcm::Attribute<0x0020,0x0037> at; // Tag Image Orientation Patient + at.SetFromDataSet( ds ); + v_iop.push_back( at.GetValue(0) ); + v_iop.push_back( at.GetValue(1) ); + v_iop.push_back( at.GetValue(2) ); + v_iop.push_back( at.GetValue(3) ); + v_iop.push_back( at.GetValue(4) ); + v_iop.push_back( at.GetValue(5) ); + v_ipp.push_back( imageOrigin[0] ); + v_ipp.push_back( imageOrigin[1] ); + v_ipp.push_back( imageOrigin[2] ); + v_pixelspacing.push_back( imageSpc[0] ); + v_pixelspacing.push_back( imageSpc[1] ); + v_pixelspacing.push_back( imageSpc[2] ); + + // --------------------------------------- + // For earch image + VectorMapInfoDicom vectormapinfodicom; + gdcm::StringFilter sf; + int iImage, sizeImages = sorted.size(); + for ( iImage=0 ; iImage( bbGetInputDicomTags()[iTag] , valueTag ) ); + } // for + vectormapinfodicom.push_back( mapinfodicom ); + + } // for iImage + // --------------------------------------- + bbSetOutputIOP( v_iop ); + bbSetOutputIPP( v_ipp ); + bbSetOutputPixelSpacing( v_pixelspacing ); + bbSetOutputOut( outputimage ); + bbSetOutputOutFileNames( sorted ); + bbSetOutputDicomInfo( vectormapinfodicom ); + } #endif // endif USE_GDCM2 void GetXCoherentInfoGdcmReader::bbUserSetDefaultValues() { - reader=NULL; + reader = NULL; std::vector init; init.push_back(""); bbSetInputIn(init); diff --git a/packages/gdcmvtk/src/bbgdcmvtkGetXCoherentInfoGdcmReader.h b/packages/gdcmvtk/src/bbgdcmvtkGetXCoherentInfoGdcmReader.h index 4133ac2b..b88e05ae 100644 --- a/packages/gdcmvtk/src/bbgdcmvtkGetXCoherentInfoGdcmReader.h +++ b/packages/gdcmvtk/src/bbgdcmvtkGetXCoherentInfoGdcmReader.h @@ -34,15 +34,17 @@ #include "iostream" #if defined(USE_GDCM) -#include "vtkGdcmReader.h" + #include "vtkGdcmReader.h" + #include "gdcmFile.h" + #include "gdcmSerieHelper.h" #endif #if defined(USE_GDCM2) -#include "vtkGDCMImageReader.h" + #include "vtkVersion.h" + #include "vtkGDCMImageReader2.h" + #include "vtkImageChangeInformation.h" #endif -#include "gdcmFile.h" -#include "gdcmSerieHelper.h" #include "vtkImageData.h" namespace bbgdcmvtk @@ -82,12 +84,14 @@ class bbgdcmvtk_EXPORT GetXCoherentInfoGdcmReader private: #if defined USE_GDCM - GDCM_NAME_SPACE::File *f; - GDCM_NAME_SPACE::SerieHelper *sh; - vtkGdcmReader *reader; + GDCM_NAME_SPACE::File *f; + GDCM_NAME_SPACE::SerieHelper *sh; + vtkGdcmReader *reader; #endif #if defined USE_GDCM2 - vtkGDCMImageReader *reader; +// vtkGDCMImageReader *reader; + vtkGDCMImageReader2 *reader; + vtkImageChangeInformation *changeInformation; #endif }; -- 2.56.0