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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
|
/*=========================================================================
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 "gdcmTesting.h"
#include "gdcmSurfaceWriter.h"
#include "gdcmSurfaceReader.h"
#include "gdcmFileMetaInformation.h"
#include "gdcmFilename.h"
#include "gdcmSystem.h"
#include "gdcmAttribute.h"
namespace gdcm
{
int TestSurfaceWriter(const char *subdir, const char* filename)
{
SurfaceReader reader;
reader.SetFileName( filename );
if ( !reader.Read() )
{
int ret = 1;
gdcm::MediaStorage ms;
if( ms.SetFromFile( reader.GetFile() ) )
{
if( ms == gdcm::MediaStorage::SurfaceSegmentationStorage )
{
ret = 0;
}
}
if( !ret )
{
std::cerr << "Failed to read: " << filename << std::endl;
std::cerr << "MediaStorage is: " << ms.GetString() << std::endl;
}
return !ret;
}
// Get content of filename
const File & FReader = reader.GetFile();
const FileMetaInformation & fmiReader = FReader.GetHeader();
const DataSet & dsReader = FReader.GetDataSet();
// Create directory first:
std::string tmpdir = Testing::GetTempDirectory( subdir );
if( !System::FileIsDirectory( tmpdir.c_str() ) )
{
System::MakeDirectory( tmpdir.c_str() );
//return 1;
}
std::string outfilename = Testing::GetTempFilename( filename, subdir );
// Write file from content reader
SurfaceWriter writer;
writer.SetFileName( outfilename.c_str() );
SegmentReader::SegmentVector segments = reader.GetSegments();
writer.SetSegments( segments );
writer.SetNumberOfSurfaces( reader.GetNumberOfSurfaces() );
// Set content from filename
File & FWriter = writer.GetFile();
FWriter.SetHeader(fmiReader);
FWriter.SetDataSet(dsReader);
if( !writer.Write() )
{
std::cerr << "Failed to write: " << outfilename << std::endl;
return 1;
}
// reuse the filename, since outfilename is simply the new representation
// of the old filename
const char * ref = Testing::GetMD5FromFile(filename);
char digest[33] = {};
Testing::ComputeFileMD5(outfilename.c_str(), digest);
if( ref == nullptr )
{
// new regression file needs a md5 sum
std::cout << "Missing md5 " << digest << " for: " << outfilename << std::endl;
return 1;
}
else if( strcmp(digest, ref) != 0 )
{
std::cerr << "Found " << digest << " instead of " << ref << std::endl;
return 1;
}
return 0;
}
}
int TestSurfaceWriter(int argc, char *argv[])
{
if( argc == 2 )
{
const char *filename = argv[1];
return gdcm::TestSurfaceWriter(argv[0],filename);
}
// else
gdcm::Trace::DebugOff();
gdcm::Trace::WarningOff();
int r = 0, i = 0;
const char *filename;
const char * const *filenames = gdcm::Testing::GetFileNames();
while( (filename = filenames[i]) )
{
r += gdcm::TestSurfaceWriter(argv[0], filename );
++i;
}
return r;
}
|