GDCM 3.2.1

Cleaner.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.
=========================================================================*/
/*
* Usage:
* $ export LD_LIBRARY_PATH=$HOME/Projects/gdcm/debug-gcc/bin
* $ mono bin/Cleaner.exe gdcmData/012345.002.050.dcm out.dcm
*/
using System;
using gdcm;
public class MyWatcher : SimpleSubjectWatcher
{
public MyWatcher(Subject s):base(s,"Override String"){}
protected override void StartFilter() {
System.Console.WriteLine( "This is my start" );
}
protected override void EndFilter(){
System.Console.WriteLine( "This is my end" );
}
protected override void ShowProgress(Subject caller, Event evt){
ProgressEvent pe = ProgressEvent.Cast(evt);
System.Console.WriteLine( "This is my progress: " + pe.GetProgress() );
}
protected override void ShowIteration(){
System.Console.WriteLine( "This is my iteration" );
}
protected override void ShowAnonymization(Subject caller, Event evt){
/*
* A couple of explanation are necessary here to understand how SWIG work
* http://www.swig.org/Doc1.3/Java.html#adding_downcasts
*
* System.Console.WriteLine( "This is my Anonymization. Type: " + evt.GetEventName() );
* System.Type type = evt.GetType();
* System.Console.WriteLine( "This is my Anonymization. System.Type: " + type.ToString() );
* System.Console.WriteLine( "This is my Anonymization. CheckEvent: " + ae.CheckEvent( evt ) );
* System.Console.WriteLine( "This is my Anonymization. Processing Tag #" + ae.GetTag().toString() );
*/
AnonymizeEvent ae = AnonymizeEvent.Cast(evt);
if( ae != null )
{
Tag t = ae.GetTag();
System.Console.WriteLine( "This is my Anonymization. Processing Tag #" + t.toString() );
}
else
{
System.Console.WriteLine( "This is my Anonymization. Unhandled Event type: " + evt.GetEventName() );
}
}
protected override void ShowAbort(){
System.Console.WriteLine( "This is my abort" );
}
}
public class Cleaner
{
public static int Main(string[] args)
{
gdcm.Global global = gdcm.Global.GetInstance();
if( !global.LoadResourcesFiles() )
{
System.Console.WriteLine( "Could not LoadResourcesFiles" );
return 1;
}
string file1 = args[0];
string file2 = args[1];
Reader reader = new Reader();
reader.SetFileName( file1 );
bool ret = reader.Read();
if( !ret )
{
return 1;
}
SmartPtrCleaner scleaner = gdcm.Cleaner.New();
gdcm.Cleaner cleaner = scleaner.__ref__();
//SimpleSubjectWatcher watcher = new SimpleSubjectWatcher(cleaner, "Anonymizer");
MyWatcher watcher = new MyWatcher(cleaner);
cleaner.SetFile( reader.GetFile() );
cleaner.Empty( new gdcm.VR(gdcm.VR.VRType.PN) );
gdcm.DPath dpath = new gdcm.DPath();
dpath.ConstructFromString( "/0010,0010" );
cleaner.Preserve( dpath );
gdcm.Tag t1 = new gdcm.Tag(0x10, 0x30);
cleaner.Empty( t1 );
gdcm.PrivateTag pt0 = new gdcm.PrivateTag( new gdcm.Tag(0x29,0x60), "SIEMENS MEDCOM HEADER2" );
cleaner.Remove( pt0 );
gdcm.PrivateTag pt1 = new gdcm.PrivateTag( new gdcm.Tag(0x29,0x10), "SIEMENS CSA HEADER" );
gdcm.PrivateTag pt2 = new gdcm.PrivateTag( new gdcm.Tag(0x29,0x20), "SIEMENS CSA HEADER" );
cleaner.Scrub( pt1 );
cleaner.Scrub( pt2 );
if( !cleaner.Clean() )
{
return 1;
}
Writer writer = new Writer();
writer.SetFileName( file2 );
writer.SetFile( cleaner.GetFile() );
ret = writer.Write();
if( !ret )
{
return 1;
}
return 0;
}
}
gdcm::AnonymizeEvent
AnonymizeEvent.
Definition gdcmAnonymizeEvent.h:30
gdcm::AnonymizeEvent::GetTag
Tag const & GetTag() const
Definition gdcmAnonymizeEvent.h:46
gdcm::Cleaner
Cleaner.
Definition gdcmCleaner.h:30
gdcm::Cleaner::Clean
bool Clean()
main loop
gdcm::Cleaner::Scrub
bool Scrub(Tag const &t)
Clean digital tash (typically SIEMENS CSA header):
gdcm::Cleaner::SetFile
void SetFile(const File &f)
Set/Get File.
Definition gdcmCleaner.h:83
gdcm::Cleaner::Preserve
bool Preserve(DPath const &dpath)
Preserve.
gdcm::Cleaner::GetFile
File & GetFile()
Definition gdcmCleaner.h:85
gdcm::Cleaner::Empty
bool Empty(Tag const &t)
gdcm::Cleaner::Remove
bool Remove(Tag const &t)
gdcm::DPath::ConstructFromString
bool ConstructFromString(const char *path)
gdcm::Event
superclass for callback/observer methods
Definition gdcmEvent.h:27
gdcm::Event::GetEventName
virtual const char * GetEventName() const =0
gdcm::Global
Global.
Definition gdcmGlobal.h:50
gdcm::Global::LoadResourcesFiles
bool LoadResourcesFiles()
gdcm::Global::GetInstance
static Global & GetInstance()
return the singleton instance
gdcm::ProgressEvent
ProgressEvent.
Definition gdcmProgressEvent.h:30
gdcm::ProgressEvent::GetProgress
double GetProgress() const
Definition gdcmProgressEvent.h:47
gdcm::Reader::GetFile
const File & GetFile() const
Set/Get File.
Definition gdcmReader.h:72
gdcm::Reader::Read
virtual bool Read()
Main function to read a file.
gdcm::Reader::SetFileName
void SetFileName(const char *filename_native)
gdcm::SimpleSubjectWatcher
SimpleSubjectWatcher.
Definition gdcmSimpleSubjectWatcher.h:32
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::Writer::Write
virtual bool Write()
Main function to tell the writer to write.
gdcm::Writer::SetFile
void SetFile(const File &f)
Set/Get the DICOM file (DataSet + Header)
Definition gdcmWriter.h:66
gdcm::Writer::SetFileName
void SetFileName(const char *filename_native)
Set the filename of DICOM file to write:
gdcm
Definition gdcmASN1.h:21