GDCM 3.0.24
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"
int main(int argc, char *argv[])
{
if( argc < 3 )
{
return 1;
}
const char * ref = argv[1];
const char * in = argv[2];
r1.SetFileName( ref );
if( !r1.Read() ) return 1;
r2.SetFileName( in );
if( !r2.Read() ) return 1;
// Fix Spatial info:
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
sopclassuid.SetFromDataSet( ds1 );
gdcm::Attribute<0x8,0x18> sopinstanceuid;
sopinstanceuid.SetFromDataSet( ds1 );
// Step 2: DERIVED object
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"
// CID 7203 "Image Derivation"
// DCM 113047 "Pixel by pixel mask"
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;
}
w.SetFile( r2.GetFile() );
w.SetFileName( "derived.dcm" );
if( !w.Write() )
{
return 1;
}
return 0;
}
Attribute class This class use template metaprograming tricks to let the user know when the template ...
Definition gdcmAttribute.h:86
ArrayType & GetValue(unsigned int idx=0)
Definition gdcmAttribute.h:154
void SetFromDataSet(DataSet const &ds)
Definition gdcmAttribute.h:229
Class to represent a Data Set (which contains Data Elements)
Definition gdcmDataSet.h:56
const DataElement & GetDataElement(const Tag &t) const
Definition gdcmDataSet.h:188
void Replace(const DataElement &de)
Replace a dataelement with another one.
Definition gdcmDataSet.h:150
FileDerivation class.
Definition gdcmFileDerivation.h:40
bool AddReference(const char *referencedsopclassuid, const char *referencedsopinstanceuid)
void SetPurposeOfReferenceCodeSequenceCodeValue(unsigned int codevalue)
Specify the Purpose Of Reference Code Value. Eg. 121320.
bool Derive()
Change.
void SetDerivationCodeSequenceCodeValue(unsigned int codevalue)
Specify the Derivation Code Sequence Code Value. Eg 113040.
void SetFile(const File &f)
Set/Get File.
Definition gdcmFileDerivation.h:75
a DICOM File
Definition gdcmFile.h:34
const DataSet & GetDataSet() const
Get Data Set.
Definition gdcmFile.h:57
Reader ala DOM (Document Object Model)
Definition gdcmReader.h:54
const File & GetFile() const
Set/Get File.
Definition gdcmReader.h:72
virtual bool Read()
Main function to read a file.
void SetFileName(const char *filename_native)
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
Writer ala DOM (Document Object Model)
Definition gdcmWriter.h:49
virtual bool Write()
Main function to tell the writer to write.
void SetFile(const File &f)
Set/Get the DICOM file (DataSet + Header)
Definition gdcmWriter.h:66
void SetFileName(const char *filename_native)
Set the filename of DICOM file to write: