GDCM
3.0.24
SortImage.cxx
/*=========================================================================
Program: GDCM (Grassroots DICOM). A DICOM library
Copyright (c) 2006-2011 Mathieu Malaterre
All rights reserved.
See Copyright.txt or http://gdcm.sourceforge.net/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/*
*/
#include "
gdcmSorter.h
"
#include "
gdcmScanner.h
"
#include "
gdcmDataSet.h
"
#include "
gdcmAttribute.h
"
bool
mysort(
gdcm::DataSet
const
& ds1,
gdcm::DataSet
const
& ds2 )
{
//gdcm::Attribute<0x0020,0x0013> at1; // Instance Number
gdcm::Attribute<0x0018,0x1060>
at1;
// Trigger Time
gdcm::Attribute<0x0020,0x0032>
at11;
// Image Position (Patient)
at1.
Set
( ds1 );
at11.
Set
( ds1 );
//gdcm::Attribute<0x0020,0x0013> at2;
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;
}
// technically all files are in the same Frame of Reference, so this function
// should be a no-op
bool
mysort_dummy(
gdcm::DataSet
const
& ds1,
gdcm::DataSet
const
& ds2 )
{
gdcm::Attribute<0x0020,0x0052>
at1;
// FrameOfReferenceUID
at1.
Set
( ds1 );
gdcm::Attribute<0x0020,0x0052>
at2;
at2.
Set
( ds2 );
return
at1 < at2;
}
int
main(
int
argc,
char
*argv[])
{
if
(argc < 2 )
return
1;
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
() );
// IMPORTANT
sorter2.
SetSortFunction
( mysort_dummy );
sorter2.
StableSort
( sorter2.
GetFilenames
() );
// IMPORTANT
std::cout <<
"Sorter2:"
<< std::endl;
sorter2.
Print
( std::cout );
gdcm::Scanner
s;
s.
AddTag
(
gdcm::Tag
(0x20,0x32) );
// Image Position (Patient)
//s.AddTag( gdcm::Tag(0x20,0x37) ); // Image Orientation (Patient)
s.
Scan
( dir.
GetFilenames
() );
//s.Print( std::cout );
// Count how many different IPP there are:
const
gdcm::Scanner::ValuesType
&values = s.
GetValues
();
size_t
nvalues = values.size();
std::cout <<
"There are "
<< nvalues <<
" different type of values"
<< std::endl;
//std::cout << "nfiles=" << nfiles << 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;
}
gdcm::Attribute
Attribute class This class use template metaprograming tricks to let the user know when the template ...
Definition
gdcmAttribute.h:86
gdcm::Attribute::Set
void Set(DataSet const &ds)
Definition
gdcmAttribute.h:226
gdcm::DataSet
Class to represent a Data Set (which contains Data Elements)
Definition
gdcmDataSet.h:56
gdcm::Directory
Class for manipulation directories.
Definition
gdcmDirectory.h:43
gdcm::Directory::Load
unsigned int Load(FilenameType const &name, bool recursive=false)
gdcm::Directory::GetFilenames
FilenamesType const & GetFilenames() const
Set/Get the file names within the directory.
Definition
gdcmDirectory.h:58
gdcm::Directory::Print
void Print(std::ostream &os=std::cout) const
Print.
gdcm::Scanner
Scanner.
Definition
gdcmScanner.h:56
gdcm::Scanner::AddTag
void AddTag(Tag const &t)
Add a tag that will need to be read. Those are root level tags.
gdcm::Scanner::ValuesType
std::set< std::string > ValuesType
Definition
gdcmScanner.h:104
gdcm::Scanner::Scan
bool Scan(Directory::FilenamesType const &filenames)
Start the scan !
gdcm::Scanner::GetValues
ValuesType const & GetValues() const
Get all the values found (in lexicographic order)
Definition
gdcmScanner.h:107
gdcm::Sorter
Sorter.
Definition
gdcmSorter.h:40
gdcm::Sorter::SetSortFunction
void SetSortFunction(SortFunction f)
gdcm::Sorter::GetFilenames
const std::vector< std::string > & GetFilenames() const
Definition
gdcmSorter.h:51
gdcm::Sorter::Sort
virtual bool Sort(std::vector< std::string > const &filenames)
Typically the output of Directory::GetFilenames()
gdcm::Sorter::Print
void Print(std::ostream &os) const
Print.
gdcm::Sorter::StableSort
virtual bool StableSort(std::vector< std::string > const &filenames)
gdcm::Tag
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition
gdcmTag.h:39
gdcmAttribute.h
gdcmDataSet.h
gdcmScanner.h
gdcmSorter.h
Generated by
1.9.8