GDCM 3.0.24
MergeTwoFiles.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.
=========================================================================*/
/*
* This example will show how one can read in two DICOM files, use the dataset
* from file1 and use image from file2 to save it in a 3rd file.
*
* Eg:
* MergeTwoFiles gdcmData/012345.002.050.dcm gdcmData/test.acr merge.dcm
*/
#include "gdcmReader.h"
#include "gdcmWriter.h"
#include "gdcmDataSet.h"
#include "gdcmAttribute.h"
int main(int argc, char *argv[])
{
if( argc < 3 )
{
return 1;
}
const char *file1 = argv[1];
const char *file2 = argv[2];
const char *file3 = argv[3];
// Read file1
reader1.SetFileName( file1 );
if( !reader1.Read() )
{
return 1;
}
// Read file2
reader2.SetFileName( file2 );
if( !reader2.Read() )
{
return 1;
}
// Ok now let's take the DataSet from file1 and the Image from file2
// Warning: if file2 is -for example- a Secondary Capture Storage, then it has no
// Image Orientation (Patient) thus any Image Orientation (Patient) from file1
// will be discarded...
// let's be fancy. In case reader2 contains explicit, but reader1 is implicit
// we would rather see an implicit output
{
}
writer.SetFileName( file3 );
writer.SetFile( reader1.GetFile() );
// ImageWriter will always use all of gdcm::Image information an override anything wrong from
// reader1.GetFile(), including the Transfer Syntax
writer.SetImage( reader2.GetImage() );
gdcm::DataSet &ds = reader1.GetFile().GetDataSet();
// Make sure that SOPInstanceUID are different
// Simply removing it is sufficient as gdcm::ImageWriter will generate one by default
// if not found.
ds.Remove( gdcm::Tag(0x0008,0x0018) );
if( !writer.Write() )
{
return 1;
}
return 0;
}
void SetTransferSyntax(TransferSyntax const &ts)
Transfer syntax.
Definition gdcmBitmap.h:69
Class to represent a Data Set (which contains Data Elements)
Definition gdcmDataSet.h:56
SizeType Remove(const Tag &tag)
Completely remove a dataelement from the dataset.
Definition gdcmDataSet.h:172
const TransferSyntax & GetDataSetTransferSyntax() const
Definition gdcmFileMetaInformation.h:53
const DataSet & GetDataSet() const
Get Data Set.
Definition gdcmFile.h:57
const FileMetaInformation & GetHeader() const
Get File Meta Information.
Definition gdcmFile.h:48
ImageReader.
Definition gdcmImageReader.h:34
const Image & GetImage() const
Return the read image.
bool Read() override
ImageWriter.
Definition gdcmImageWriter.h:33
bool Write() override
Write.
virtual void SetImage(Pixmap const &img)
const File & GetFile() const
Set/Get File.
Definition gdcmReader.h:72
void SetFileName(const char *filename_native)
Class to represent a DICOM Data Element (Attribute) Tag (Group, Element).
Definition gdcmTag.h:39
@ ImplicitVRLittleEndian
Definition gdcmTransferSyntax.h:62
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: