#include "gdcmSorter.h"
#include "gdcmScanner.h"
#include "gdcmDataSet.h"
#include "gdcmAttribute.h"
bool mysort(gdcm::DataSet const & ds1, gdcm::DataSet const & ds2 )
{
gdcm::Attribute<0x0018,0x1060> at1;
gdcm::Attribute<0x0020,0x0032> at11;
at1.Set( ds1 );
at11.Set( ds1 );
gdcm::Attribute<0x0018,0x1060> at2;
gdcm::Attribute<0x0020,0x0032> at22;
at2.Set( ds2 );
at22.Set( ds2 );
if( at11 == at22 )
{
return at1 < at2;
}
return at11 < at22;
}
bool mysort_part1(gdcm::DataSet const & ds1, gdcm::DataSet const & ds2 )
{
gdcm::Attribute<0x0018,0x1060> at1;
at1.Set( ds1 );
gdcm::Attribute<0x0018,0x1060> at2;
at2.Set( ds2 );
return at1 < at2;
}
bool mysort_part2(gdcm::DataSet const & ds1, gdcm::DataSet const & ds2 )
{
gdcm::Attribute<0x0020,0x0032> at1;
at1.Set( ds1 );
gdcm::Attribute<0x0020,0x0032> at2;
at2.Set( ds2 );
return at1 < at2;
}
bool mysort_dummy(gdcm::DataSet const & ds1, gdcm::DataSet const & ds2 )
{
gdcm::Attribute<0x0020,0x0052> at1;
at1.Set( ds1 );
gdcm::Attribute<0x0020,0x0052> at2;
at2.Set( ds2 );
return at1 < at2;
}
int main(int argc, char *argv[])
{
const char *dirname = argv[1];
gdcm::Directory dir;
unsigned int nfiles = dir.Load( dirname );
dir.Print( std::cout );
gdcm::Sorter sorter;
sorter.SetSortFunction( mysort );
sorter.Sort( dir.GetFilenames() );
std::cout << "Sorter:" << std::endl;
sorter.Print( std::cout );
gdcm::Sorter sorter2;
sorter2.SetSortFunction( mysort_part1 );
sorter2.StableSort( dir.GetFilenames() );
sorter2.SetSortFunction( mysort_part2 );
sorter2.StableSort( sorter2.GetFilenames() );
sorter2.SetSortFunction( mysort_dummy );
sorter2.StableSort( sorter2.GetFilenames() );
std::cout << "Sorter2:" << std::endl;
sorter2.Print( std::cout );
gdcm::Scanner s;
s.AddTag( gdcm::Tag(0x20,0x32) );
s.Scan( dir.GetFilenames() );
const gdcm::Scanner::ValuesType &values = s.GetValues();
unsigned int nvalues = values.size();
std::cout << "There are " << nvalues << " different type of values" << std::endl;
if( nfiles % nvalues != 0 )
{
std::cerr << "Impossible: this is a not a proper series" << std::endl;
return 1;
}
std::cout << "Series is composed of " << (nfiles/nvalues) << " different 3D volumes" << std::endl;
return 0;
}