GDCM  2.2.6
GenFakeIdentifyFile.cxx
/*=========================================================================
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 "gdcmReader.h"
#include "gdcmGlobal.h"
#include "gdcmWriter.h"
#include "gdcmItem.h"
#include "gdcmAttribute.h"
#include "gdcmFile.h"
#include "gdcmTag.h"
#include "gdcmDict.h"
#include "gdcmDictEntry.h"
#include "gdcmDicts.h"
#include "gdcmAnonymizer.h"
#include <cstdlib>
#include <cstring>
gdcm::DataElement CreateFakeElement(gdcm::Tag const &tag, bool toremove)
{
static const gdcm::Dicts &dicts = g.GetDicts();
static const gdcm::Dict &pubdict = dicts.GetPublicDict();
static size_t countglobal = 0;
static std::vector<gdcm::Tag> balcptags =
size_t count = countglobal % balcptags.size();
const gdcm::DictEntry &dictentry = pubdict.GetDictEntry(tag);
de.SetTag( tag );
using gdcm::VR;
const VR &vr = dictentry.GetVR();
//if( vr != VR::INVALID )
if( vr.IsDual() )
{
if( vr == VR::US_SS )
{
de.SetVR( VR::US );
}
else if( vr == VR::US_SS_OW )
{
de.SetVR( VR::OW );
}
else if( vr == VR::OB_OW )
{
de.SetVR( VR::OB );
}
}
else
{
de.SetVR( vr );
}
const char str[] = "BasicApplicationLevelConfidentialityProfileAttributes";
const char safe[] = "This is safe to keep";
if( de.GetVR() != VR::SQ )
{
if( toremove )
de.SetByteValue( str, (uint32_t)strlen(str) );
else
de.SetByteValue( safe, (uint32_t)strlen(safe) );
}
else
{
// Create an item
// Insert sequence into data set
assert(de.GetVR() == gdcm::VR::SQ );
sq->SetLengthToUndefined();
de.SetValue(*sq);
//ds.Insert(de);
if( !toremove )
{
nds.Insert( CreateFakeElement( balcptags[count], true ) );
countglobal++;
}
else
{
gdcm::Attribute<0x0008,0x0000> at1 = { 0 }; // This element has no reason to be 'anonymized'...
nds.Insert( at1.GetAsDataElement() );
nds.Insert( at2.GetAsDataElement() );
}
sq->AddItem(it);
}
return de;
}
/*
*/
int main(int argc, char *argv[])
{
if( argc < 2 )
{
std::cerr << argv[0] << " output.dcm" << std::endl;
return 1;
}
using gdcm::Tag;
using gdcm::VR;
const char *outfilename = argv[1];
std::vector<gdcm::Tag> balcptags =
gdcm::File &f = w.GetFile();
// Add attribute that need to be anonymized:
std::vector<gdcm::Tag>::const_iterator it = balcptags.begin();
for(; it != balcptags.end(); ++it)
{
ds.Insert( CreateFakeElement( *it, true ) );
}
// Add attribute that do NOT need to be anonymized:
static const gdcm::Dicts &dicts = g.GetDicts();
static const gdcm::Dict &pubdict = dicts.GetPublicDict();
using gdcm::Dict;
Dict::ConstIterator dictit = pubdict.Begin();
for(; dictit != pubdict.End(); ++dictit)
{
const gdcm::Tag &dicttag = dictit->first;
if( dicttag == Tag(0x6e65,0x6146) ) break;
//const gdcm::DictEntry &dictentry = dictit->second;
ds.Insert( CreateFakeElement( dicttag, false ) );
}
ds.Remove( gdcm::Tag(0x400,0x500) );
ds.Remove( gdcm::Tag(0x12,0x62) );
ds.Remove( gdcm::Tag(0x12,0x63) );
// Make sure to override any UID stuff
gdcm::DataElement de( Tag(0x8,0x18) ); // SOP Instance UID
de.SetVR( VR::UI );
const char *u = uid.Generate();
de.SetByteValue( u, (uint32_t)strlen(u) );
//ds.Insert( de );
ds.Replace( de );
de.SetTag( Tag(0x8,0x16) ); // SOP Class UID
de.SetVR( VR::UI );
de.SetByteValue( ms.GetString(), (uint32_t)strlen(ms.GetString()));
ds.Replace( de ); // replace !
//fmi.SetDataSetTransferSyntax( gdcm::TransferSyntax::ImplicitVRLittleEndian );
w.SetFileName( outfilename );
if (!w.Write() )
{
return 1;
}
return 0;
}

Generated on Sat Dec 21 2013 05:56:15 for GDCM by doxygen 1.8.5
SourceForge.net Logo