GDCM 3.0.24
ScanDirectory.cs

This is a C# example on how to use Scanner

/*=========================================================================
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.
=========================================================================*/
/*
* Usage:
* $ bin/ScanDirectory.exe /path/to/gdcmData/
*/
using System;
using gdcm;
// We will print each filename being processed
public class MyWatcher : SimpleSubjectWatcher
{
public MyWatcher(Subject s):base(s,"Override String"){}
protected override void ShowFileName(Subject caller, Event evt){
FileNameEvent fne = FileNameEvent.Cast(evt);
if( fne != null )
{
string fn = fne.GetFileName();
System.Console.WriteLine( "This is my Scanner. Processing FileName: " + fn );
}
else
{
System.Console.WriteLine( "This is my Anonymization. Unhandled Event type: " + evt.GetEventName() );
}
}
}
public class ScanDirectory
{
public static int Main(string[] args)
{
string directory = args[0];
Tag t = new Tag(0x8,0x80);
Directory d = new Directory();
uint nfiles = d.Load( directory );
if(nfiles == 0) return 1;
//System.Console.WriteLine( "Files:\n" + d.toString() );
// Use a StrictScanner, need to use a reference to pass the C++ pointer to
// MyWatcher implementation
SmartPtrStrictScan sscan = StrictScanner.New();
StrictScanner s = sscan.__ref__();
MyWatcher watcher = new MyWatcher(s);
s.AddTag( t );
bool b = s.Scan( d.GetFilenames() );
if(!b) return 1;
for(int i = 0; i < (int)nfiles; ++i)
{
if( !s.IsKey( d.GetFilenames()[i] ) )
{
System.Console.WriteLine( "File is not DICOM or could not be read: " + d.GetFilenames()[i] );
}
}
System.Console.WriteLine( "Scan:\n" + s.toString() );
System.Console.WriteLine( "success" );
return 0;
}
}
Class for manipulation directories.
Definition gdcmDirectory.h:43
unsigned int Load(FilenameType const &name, bool recursive=false)
FilenamesType const & GetFilenames() const
Set/Get the file names within the directory.
Definition gdcmDirectory.h:58
superclass for callback/observer methods
Definition gdcmEvent.h:27
virtual const char * GetEventName() const =0
FileNameEvent.
Definition gdcmFileNameEvent.h:30
const char * GetFileName() const
Definition gdcmFileNameEvent.h:48
SimpleSubjectWatcher.
Definition gdcmSimpleSubjectWatcher.h:32
StrictScanner.
Definition gdcmStrictScanner.h:56
void AddTag(Tag const &t)
Add a tag that will need to be read. Those are root level skip tags.
bool IsKey(const char *filename) const
static SmartPointer< StrictScanner > New()
for wrapped language: instantiate a reference counted object
Definition gdcmStrictScanner.h:157
bool Scan(Directory::FilenamesType const &filenames)
Start the scan !
Subject.
Definition gdcmSubject.h:29
Class to do system operation.
Definition gdcmSystem.h:27
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
Definition gdcmASN1.h:21