1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
/*=========================================================================
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 "gdcmIPPSorter.h"
#include "gdcmDirectory.h"
#include "gdcmTesting.h"
#include "gdcmSystem.h"
#include "gdcmTrace.h"
#include "gdcmReader.h"
#include "gdcmWriter.h"
int TestIPPSorter3(int , char *[])
{
const char *directory = gdcm::Testing::GetDataRoot();
std::vector<std::string> filenames;
// let's take 4 files that can be sorted:
std::string file0 = std::string(directory) + "/SIEMENS_MAGNETOM-12-MONO2-FileSeq0.dcm";
std::string file1 = std::string(directory) + "/SIEMENS_MAGNETOM-12-MONO2-FileSeq1.dcm";
std::string file2 = std::string(directory) + "/SIEMENS_MAGNETOM-12-MONO2-FileSeq2.dcm";
std::string file3 = std::string(directory) + "/SIEMENS_MAGNETOM-12-MONO2-FileSeq3.dcm";
// Make a fake copy:
const char * reference = file0.c_str();
gdcm::Reader reader;
reader.SetFileName( reference );
if( !reader.Read() ) return 1;
// Create directory first:
const char subdir[] = "TestIPPSorter3";
std::string tmpdir = gdcm::Testing::GetTempDirectory( subdir );
if( !gdcm::System::FileIsDirectory( tmpdir.c_str() ) )
{
gdcm::System::MakeDirectory( tmpdir.c_str() );
//return 1;
}
std::string outfilename = gdcm::Testing::GetTempFilename( reference, subdir );
// Tweak the orientation just a little:
// [001.000000E+00\-0.000000E+00\-0.000000E+00\00.000000E+00\01.000000E+00\-0.000000E+00]
gdcm::Writer writer;
writer.SetFileName( outfilename.c_str() );
//const char iop_orig[] = "1\\-0\\-0\\0\\1\\-0";
const char iop[] = R"(1\-0\-0\0\0.99999\0.00001)";
gdcm::DataElement de( gdcm::Tag(0x0020,0x0037) );
de.SetByteValue( iop, (uint32_t)strlen( iop ) );
reader.GetFile().GetDataSet().Replace( de );
writer.SetFile( reader.GetFile() );
if( !writer.Write() )
{
return 1;
}
// let's push them in random order (oh my god how are we going to succeed ??)
filenames.push_back( file1 );
filenames.push_back( file3 );
filenames.push_back( outfilename );
filenames.push_back( file2 );
//filenames.push_back( file0 );
gdcm::IPPSorter s;
s.SetComputeZSpacing( true );
s.SetZSpacingTolerance( 1e-10 );
s.SetDirectionCosinesTolerance( 1e-6 );
bool b = s.Sort( filenames );
if( b )
{
std::cerr << "Success to sort (we should have failed): " << directory << std::endl;
return 1;
}
// Lower the threshold:
s.SetDirectionCosinesTolerance( 1e-5 );
b = s.Sort( filenames );
if( !b )
{
std::cerr << "Failed to sort: " << directory << std::endl;
return 1;
}
// std::cout << "Sorting succeeded:" << std::endl;
// s.Print( std::cout );
double zspacing = s.GetZSpacing();
if(!zspacing)
{
std::cerr << "computation of ZSpacing failed." << std::endl;
return 1;
}
std::cout << "Found z-spacing:" << std::endl;
std::cout << s.GetZSpacing() << std::endl;
return 0;
}
|