GDCM 3.2.1

DeriveSeries.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 "gdcmAttribute.h"
#include "gdcmFileDerivation.h"
#include "gdcmUIDGenerator.h"
int main(int argc, char *argv[])
{
if( argc < 3 )
{
return 1;
}
const char * ref = argv[1];
const char * in = argv[2];
gdcm::Reader r1;
r1.SetFileName( ref );
if( !r1.Read() ) return 1;
gdcm::Reader r2;
r2.SetFileName( in );
if( !r2.Read() ) return 1;
// Fix Spatial info:
gdcm::DataSet & ds1 = r1.GetFile().GetDataSet();
gdcm::File & file2 = r2.GetFile();
gdcm::DataSet & ds2 = file2.GetDataSet();
//gdcm::Attribute<0x8,0x8> img_type = { "ORIGINAL", "PRIMARY" };
ds2.Replace( ds1.GetDataElement( gdcm::Tag(0x0008,0x0008) ));
ds2.Replace( ds1.GetDataElement( gdcm::Tag(0x0020,0x0032) ));
ds2.Replace( ds1.GetDataElement( gdcm::Tag(0x0020,0x0037) ));
ds2.Replace( ds1.GetDataElement( gdcm::Tag(0x0018,0x0088) )); // Spacing between slices
ds2.Replace( ds1.GetDataElement( gdcm::Tag(0x0020,0x0013) )); // Instance Number
ds2.Replace( ds1.GetDataElement( gdcm::Tag(0x0018,0x5100) )); // Patient Position
ds2.Replace( ds1.GetDataElement( gdcm::Tag(0x0018,0x0050) )); // Slice Thickness
ds2.Replace( ds1.GetDataElement( gdcm::Tag(0x0008,0x0070) )); // Manufacturer
ds2.Replace( ds1.GetDataElement( gdcm::Tag(0x0018,0x0081) )); // Echo Time
ds2.Replace( ds1.GetDataElement( gdcm::Tag(0x0020,0x1041) )); // Slice Location
gdcm::Attribute<0x8,0x16> sopclassuid;
sopclassuid.SetFromDataSet( ds1 );
gdcm::Attribute<0x8,0x18> sopinstanceuid;
sopinstanceuid.SetFromDataSet( ds1 );
// Step 2: DERIVED object
gdcm::FileDerivation fd;
fd.AddReference( sopclassuid.GetValue(), sopinstanceuid.GetValue() );
// http://dicom.nema.org/MEDICAL/dicom/current/output/chtml/part16/chapter_D.html#DCM_121321
// CID 7202 "Source Image Purposes of Reference"
// DCM 121321 "Mask image for image processing operation"
fd.SetPurposeOfReferenceCodeSequenceCodeValue( 121321 );
// CID 7203 "Image Derivation"
// DCM 113047 "Pixel by pixel mask"
fd.SetDerivationCodeSequenceCodeValue( 113047 );
fd.SetFile( file2 );
// If all Code Value are ok the filter will execute properly
if( !fd.Derive() )
{
std::cerr << "Sorry could not derive using input info" << std::endl;
return 1;
}
gdcm::Writer w;
w.SetFile( r2.GetFile() );
w.SetFileName( "derived.dcm" );
if( !w.Write() )
{
return 1;
}
return 0;
}
gdcm::Attribute
Attribute class This class use template metaprograming tricks to let the user know when the template ...
Definition gdcmAttribute.h:86
gdcm::Attribute::GetValue
ArrayType & GetValue(unsigned int idx=0)
Definition gdcmAttribute.h:154
gdcm::Attribute::SetFromDataSet
void SetFromDataSet(DataSet const &ds)
Definition gdcmAttribute.h:229
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::Replace
void Replace(const DataElement &de)
Replace a dataelement with another one.
Definition gdcmDataSet.h:150
gdcm::FileDerivation
FileDerivation class.
Definition gdcmFileDerivation.h:40
gdcm::FileDerivation::AddReference
bool AddReference(const char *referencedsopclassuid, const char *referencedsopinstanceuid)
gdcm::FileDerivation::SetPurposeOfReferenceCodeSequenceCodeValue
void SetPurposeOfReferenceCodeSequenceCodeValue(unsigned int codevalue)
Specify the Purpose Of Reference Code Value. Eg. 121320.
gdcm::FileDerivation::Derive
bool Derive()
Change.
gdcm::FileDerivation::SetDerivationCodeSequenceCodeValue
void SetDerivationCodeSequenceCodeValue(unsigned int codevalue)
Specify the Derivation Code Sequence Code Value. Eg 113040.
gdcm::FileDerivation::SetFile
void SetFile(const File &f)
Set/Get File.
Definition gdcmFileDerivation.h:75
gdcm::File
a DICOM File
Definition gdcmFile.h:34
gdcm::File::GetDataSet
const DataSet & GetDataSet() const
Get Data Set.
Definition gdcmFile.h:57
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::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:
gdcmAttribute.h
gdcmFileDerivation.h
gdcmReader.h
gdcmUIDGenerator.h
gdcmWriter.h