]> Creatis software - bbtk.git/commitdiff
#3547 change gdcm1 to gdcm2 vtk9itk5wx3-macos
authoreduardo.davila@creatis.insa-lyon.fr <eduardo.davila@creatis.insa-lyon.fr>
Mon, 28 Sep 2026 14:56:19 +0000 (16:56 +0200)
committereduardo.davila@creatis.insa-lyon.fr <eduardo.davila@creatis.insa-lyon.fr>
Mon, 28 Sep 2026 14:56:19 +0000 (16:56 +0200)
kernel/src/bbtkBlackBox.cxx
packages/gdcmvtk/src/bbgdcmvtkGetXCoherentInfoGdcmReader.cxx
packages/gdcmvtk/src/bbgdcmvtkGetXCoherentInfoGdcmReader.h

index 9477c48..348af87 100644 (file)
@@ -24,7 +24,6 @@
  #  knowledge of the CeCILL-B license and that you accept its terms.
  # ------------------------------------------------------------------------ */
 
-
 /*=========================================================================
   Program:   bbtk
   Module:    $RCSfile: bbtkBlackBox.cxx,v $
index 56a4e4b..a3287da 100644 (file)
 #include "vtkImageData.h"
 #include <vtkIndent.h>
 
+
 #if defined USE_GDCM
        #include "gdcmFileHelper.h"
 #endif
 
-
 #if defined USE_GDCM2
-       #include <gdcmReader.h>
-       #include <gdcmImageHelper.h>
-       #include <gdcmIPPSorter.h>
-       #include <vtkGDCMImageReader.h>
-       #include "vtkStringArray.h"
+
+    #include "gdcmReader.h"
+    #include "gdcmGlobal.h"
+//    #include "gdcmDicts.h"
+//    #include "gdcmDict.h"
+    #include "gdcmAttribute.h"
+    #include "gdcmStringFilter.h"
+
+    #include <gdcmDict.h>
+    #include <gdcmDicts.h>
+    #include <gdcmGlobal.h>
+    #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<double> 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<double> 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<std::string>              &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<double> v_iop;
+    std::vector<double> v_ipp;
+    std::vector<double> 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<sizeImages ; iImage++ )
+    {
+        gdcm::Reader reader;
+        reader.SetFileName( sorted[iImage].c_str() );
+        if( !reader.Read() )
+        {
+            printf("EED Warning!!!  (B)  GetXCoherentInfoGdcmReader Cant read dicom file\n");
+        }
+        sf.SetFile( reader.GetFile() );
+
+        MapInfoDicom mapinfodicom;
+        std::string stringTagGroup;
+        std::string stringTagAttribute;
+        std::string keyTag;
+        std::string valueTag;
+        gdcm::Tag   tmpTag;
+        int iTag,sizeTag=bbGetInputDicomTags().size();
+        for (iTag=0; iTag<sizeTag;  iTag++)
+        {
+            keyTag              = bbGetInputDicomTags()[iTag];
+            stringTagGroup      = keyTag.substr(1,4);
+            stringTagAttribute  = keyTag.substr(6,4);
+            tmpTag.SetElementTag( std::stoi(stringTagGroup,0,16) , std::stoi(stringTagAttribute,0,16) );
+            valueTag = sf.ToString(tmpTag);
+            mapinfodicom.insert ( std::pair<std::string,std::string>( 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<std::string> init;
    init.push_back("");
    bbSetInputIn(init);  
index 4133ac2..b88e05a 100644 (file)
 #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
 };