GDCM: ScanDirectory.cs

GDCM 3.2.10

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;
}
}
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::Event
superclass for callback/observer methods
Definition gdcmEvent.h:27
gdcm::Event::GetEventName
virtual const char * GetEventName() const =0
gdcm::FileNameEvent
FileNameEvent.
Definition gdcmFileNameEvent.h:30
gdcm::FileNameEvent::GetFileName
const char * GetFileName() const
Definition gdcmFileNameEvent.h:48
gdcm::SimpleSubjectWatcher
SimpleSubjectWatcher.
Definition gdcmSimpleSubjectWatcher.h:32
gdcm::StrictScanner
StrictScanner.
Definition gdcmStrictScanner.h:56
gdcm::StrictScanner::AddTag
void AddTag(Tag const &t)
Add a tag that will need to be read. Those are root level skip tags.
gdcm::StrictScanner::IsKey
bool IsKey(const char *filename) const
gdcm::StrictScanner::New
static SmartPointer< StrictScanner > New()
for wrapped language: instantiate a reference counted object
Definition gdcmStrictScanner.h:157
gdcm::StrictScanner::Scan
bool Scan(Directory::FilenamesType const &filenames)
Start the scan !
gdcm::Subject
Subject.
Definition gdcmSubject.h:29
gdcm::System
Class to do system operation.
Definition gdcmSystem.h:27
gdcm::Tag
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
gdcm
Definition gdcmASN1.h:21