ChangeSequenceUltrasound.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 "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;
}
gdcm::DataElement
Class to represent a Data Element either Implicit or Explicit.
Definition gdcmDataElement.h:59
gdcm::DataElement::GetValueAsSQ
SmartPointer< SequenceOfItems > GetValueAsSQ() const
gdcm::DataElement::SetByteValue
void SetByteValue(const char *array, VL length)
Definition gdcmDataElement.h:126
gdcm::DataSet
Class to represent a Data Set (which contains Data Elements).
Definition gdcmDataSet.h:56
gdcm::DataSet::GetDataElement
const DataElement & GetDataElement(const Tag &t) const
Definition gdcmDataSet.h:188
gdcm::DataSet::FindDataElement
bool FindDataElement(const PrivateTag &t) const
Look up if private tag 't' is present in the dataset:
gdcm::DataSet::Replace
void Replace(const DataElement &de)
Replace a dataelement with another one.
Definition gdcmDataSet.h:150
gdcm::File
a DICOM File
Definition gdcmFile.h:34
gdcm::File::GetDataSet
const DataSet & GetDataSet() const
Get Data Set.
Definition gdcmFile.h:57
gdcm::Item
Class to represent an Item.
Definition gdcmItem.h:46
gdcm::Item::GetNestedDataSet
const DataSet & GetNestedDataSet() const
Definition gdcmItem.h:80
gdcm::Reader
Reader ala DOM (Document Object Model).
Definition gdcmReader.h:54
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::SmartPointer
Class for Smart Pointer.
Definition gdcmSmartPointer.h:40
gdcm::Tag
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
gdcm::Writer
Writer ala DOM (Document Object Model).
Definition gdcmWriter.h:49
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:
gdcmDataSetHelper.h
gdcmReader.h
gdcmSmartPointer.h
gdcmWriter.h