1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
/*=========================================================================
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 "gdcmWriter.h"
#include "gdcmSmartPointer.h"
#include "gdcmDataSetHelper.h"
/*
./ChangeSequenceUltrasound gdcmData/D_CLUNIE_CT1_J2KI.dcm myoutput.dcm
This is the exact C++ translation of the original python example: ManipulateSequence.py
*/
int main(int argc, char* argv[] )
{
if( argc < 3 )
{
std::cerr << argv[0] << " input.dcm output.dcm" << std::endl;
return 1;
}
const char *filename = argv[1];
const char *outfilename = argv[2];
gdcm::Reader reader;
reader.SetFileName( filename );
if (! reader.Read() )
{
return 1;
}
gdcm::File &file = reader.GetFile();
gdcm::DataSet &ds = file.GetDataSet();
gdcm::Tag tsis(0x0008,0x2112); // SourceImageSequence
if ( ds.FindDataElement( tsis ) )
{
const gdcm::DataElement &sis = ds.GetDataElement( tsis );
gdcm::SmartPointer<gdcm::SequenceOfItems> sqsis = sis.GetValueAsSQ();
if ( sqsis && sqsis->GetNumberOfItems() )
{
gdcm::Item &item1 = sqsis->GetItem(1);
gdcm::DataSet &nestedds = item1.GetNestedDataSet();
gdcm::Tag tprcs(0x0040,0xa170); // PurposeOfReferenceCodeSequence
if( nestedds.FindDataElement( tprcs ) )
{
const gdcm::DataElement &prcs = nestedds.GetDataElement( tprcs );
gdcm::SmartPointer<gdcm::SequenceOfItems> sqprcs = prcs.GetValueAsSQ();
if ( sqprcs && sqprcs->GetNumberOfItems() )
{
gdcm::Item &item2 = sqprcs->GetItem(1);
gdcm::DataSet &nestedds2 = item2.GetNestedDataSet();
// (0008,0104) LO [Uncompressed predecessor] # 24, 1 CodeMeaning
gdcm::Tag tcm(0x0008,0x0104);
if( nestedds2.FindDataElement( tcm ) )
{
gdcm::DataElement cm = nestedds2.GetDataElement( tcm );
std::string mystr = "GDCM was here";
cm.SetByteValue( mystr.c_str(), (uint32_t)mystr.size() );
nestedds2.Replace( cm );
}
}
}
}
}
gdcm::Writer writer;
writer.SetFile( file );
writer.SetFileName( outfilename );
if ( !writer.Write() )
{
return 1;
}
return 0;
}
|