#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
{
#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;
return;
}
+ printf("EED GetXCoherentInfoGdcmReader::Process 1\n");
+
// Get info from the first image file
const gdcm::File &f = read->GetFile();
int i;
}
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);
//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();
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);