GDCM: MetaImageMD5Activiz.cs

GDCM 3.2.10

MetaImageMD5Activiz.cs
/*=========================================================================
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.
=========================================================================*/
using Kitware.VTK;
using Kitware.VTK.GDCM;
using gdcm;
/*
* $ export MONO_PATH=/usr/lib/cli/ActiViz.NET/:/usr/lib/cli/Kitware.mummy.Runtime-1.0
* $ mono ./bin/MetaImageMD5Activiz.exe gdcmData/012345.002.050.dcm
*/
public class MetaImageMD5Activiz
{
public static int ProcessOneMHDMD5(string filename)
{
vtkGDCMImageReader reader = vtkGDCMImageReader. New();
reader.FileLowerLeftOn();
reader.DebugOff();
int canread = reader. CanReadFile( filename );
if( canread == 0 )
{
string refms = gdcm.Testing. GetMediaStorageFromFile(filename);
if( gdcm.MediaStorage. IsImage( gdcm.MediaStorage. GetMSType(refms) ) )
{
System.Console.Write( "Problem with file: " + filename + "\n" );
return 1;
}
// not an image
return 0;
}
reader.SetFileName( filename );
reader.Update();
// System.Console.Write(reader.GetOutput());
vtkMetaImageWriter writer = vtkMetaImageWriter.New();
writer.SetCompression( false );
writer.SetInput( reader.GetOutput() );
string subdir = "MetaImageMD5Activiz";
string tmpdir = gdcm.Testing. GetTempDirectory( subdir );
if( !gdcm.PosixEmulation.FileIsDirectory( tmpdir ) )
{
gdcm.PosixEmulation.MakeDirectory( tmpdir );
}
string mhdfile = gdcm.Testing. GetTempFilename( filename, subdir );
string rawfile = mhdfile;
mhdfile += ".mhd";
rawfile += ".raw";
writer.SetFileName( mhdfile );
writer.Write();
string digestmhd = gdcm.Testing. ComputeFileMD5( mhdfile );
string digestraw = gdcm.Testing.ComputeFileMD5( rawfile );
string mhdref = vtkGDCMTesting. GetMHDMD5FromFile(filename);
string rawref = vtkGDCMTesting. GetRAWMD5FromFile(filename);
if( mhdref != digestmhd )
{
System.Console.Write( "Problem with mhd file: " + filename + "\n" );
System.Console.Write( digestmhd );
System.Console.Write( "\n" );
System.Console.Write( mhdref );
System.Console.Write( "\n" );
return 1;
}
if( rawref != digestraw )
{
System.Console.Write( "Problem with raw file: " + filename + "\n" );
System.Console.Write( digestraw );
System.Console.Write( "\n" );
System.Console.Write( rawref );
System.Console.Write( "\n" );
return 1;
}
return 0;
}
public static int Main(string[] args)
{
if ( args.Length == 1 )
{
string filename = args[0];
return ProcessOneMHDMD5( filename );
}
// Loop over all gdcmData
gdcm.Trace. DebugOff();
gdcm.Trace. WarningOff();
gdcm.Trace. ErrorOff();
uint n = gdcm.Testing. GetNumberOfFileNames();
int ret = 0;
for( uint i = 0; i < n; ++i )
{
string filename = gdcm.Testing. GetFileName( i );
ret += ProcessOneMHDMD5( filename );
}
return ret;
}
}
gdcm::MediaStorage
MediaStorage.
Definition gdcmMediaStorage.h:44
gdcm::MediaStorage::IsImage
static bool IsImage(MSType ts)
gdcm::MediaStorage::GetMSType
static MSType GetMSType(const char *str)
gdcm::System
Class to do system operation.
Definition gdcmSystem.h:27
gdcm::Testing
class for testing
Definition gdcmTesting.h:32
gdcm::Testing::GetFileName
static const char * GetFileName(unsigned int file)
gdcm::Testing::GetMediaStorageFromFile
static const char * GetMediaStorageFromFile(const char *filepath)
gdcm::Testing::GetTempFilename
static const char * GetTempFilename(const char *filename, const char *subdir=nullptr)
NOT THREAD SAFE.
gdcm::Testing::GetTempDirectory
static const char * GetTempDirectory(const char *subdir=nullptr)
gdcm::Testing::GetNumberOfFileNames
static unsigned int GetNumberOfFileNames()
gdcm::Testing::ComputeFileMD5
static bool ComputeFileMD5(const char *filename, char digest_str[33])
gdcm::Trace
Trace.
Definition gdcmTrace.h:42
gdcm::Trace::WarningOff
static void WarningOff()
gdcm::Trace::ErrorOff
static void ErrorOff()
gdcm::Trace::DebugOff
static void DebugOff()
vtkGDCMImageReader
Definition vtkGDCMImageReader.h:105
vtkGDCMImageReader::New
static vtkGDCMImageReader * New()
vtkGDCMImageReader::CanReadFile
virtual int CanReadFile(const char *fname)
vtkGDCMTesting
Definition vtkGDCMTesting.h:28
vtkGDCMTesting::GetMHDMD5FromFile
static const char * GetMHDMD5FromFile(const char *filepath)
vtkGDCMTesting::GetRAWMD5FromFile
static const char * GetRAWMD5FromFile(const char *filepath)
gdcm
Definition gdcmASN1.h:21