Add IPP sorter on file read. I am not sure if the DB indexer sorts files by Z location.
This commit is contained in:
@ -22,6 +22,7 @@ gfattori 08.11.2021
|
||||
#include "itkMatrix.h"
|
||||
#include "itkGDCMSeriesFileNames.h"
|
||||
#include "itkOrientImageFilter.h"
|
||||
#include <gdcmIPPSorter.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -371,32 +372,58 @@ void itkImageProcessor::SetCustom_2Dsize(int nX1, int nY1,int nX2,int nY2)
|
||||
|
||||
int itkImageProcessor::load3DSerieFromFiles( std::vector<std::string> v_fnames){
|
||||
|
||||
|
||||
tPatOrientation m_PatOrientation
|
||||
= tPatOrientation::NotDefined;
|
||||
|
||||
/* Since are not sure DB indexer to sort images,
|
||||
* we run the IPP sorter here. */
|
||||
using IppSorterType = gdcm::IPPSorter;
|
||||
IppSorterType ZSorter;
|
||||
|
||||
ZSorter.SetComputeZSpacing( true );
|
||||
ZSorter.SetZSpacingTolerance( 1e-3 );
|
||||
bool b = ZSorter.Sort(v_fnames);
|
||||
if( !b )
|
||||
{
|
||||
std::cerr << "Failed to sort files." << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
std::cout << "Sorting succeeded:" << std::endl;
|
||||
ZSorter.Print( std::cout );
|
||||
|
||||
std::cout << "Found z-spacing:" << std::endl;
|
||||
std::cout << ZSorter.GetZSpacing() << std::endl;
|
||||
|
||||
|
||||
const std::vector<std::string> & v_sortedFnames =
|
||||
ZSorter.GetFilenames();
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
using ImageIOType = itk::GDCMImageIO;
|
||||
ImageIOType::Pointer dicomIO = ImageIOType::New();
|
||||
|
||||
ImageSeriesReaderType3D::Pointer
|
||||
imageSeriesReader3D = ImageSeriesReaderType3D::New();
|
||||
|
||||
imageSeriesReader3D->SetImageIO(dicomIO);
|
||||
imageSeriesReader3D->SetFileNames(v_fnames);
|
||||
imageSeriesReader3D->SetNumberOfWorkUnits(8);
|
||||
imageSeriesReader3D->SetFileNames(v_sortedFnames);
|
||||
//imageSeriesReader3D->SetNumberOfWorkUnits(8);
|
||||
imageSeriesReader3D->ForceOrthogonalDirectionOff(); // properly read CTs with gantry tilt
|
||||
//imageSeriesReader3D->SetSpacingWarningRelThreshold();
|
||||
|
||||
imageSeriesReader3D->Update();
|
||||
|
||||
if(v_fnames.size()>0){
|
||||
|
||||
gdcm::Reader R;
|
||||
R.SetFileName(v_fnames.at(0).c_str());
|
||||
R.SetFileName(v_sortedFnames.at(0).c_str());
|
||||
if(!R.Read())
|
||||
{
|
||||
cerr<<"ERROR: cannot read file: "<<v_fnames.at(0).c_str()<<endl;
|
||||
cerr<<"ERROR: cannot read file: "<<v_sortedFnames.at(0).c_str()<<endl;
|
||||
return -1;
|
||||
}
|
||||
const gdcm::File &file = R.GetFile();
|
||||
|
Reference in New Issue
Block a user