GDCM 3.2.1

TemplateEmptyImage.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 "gdcmFileStreamer.h"
#include "gdcmTag.h"
#include "gdcmTrace.h"
#include "gdcmImageRegionReader.h"
#include "gdcmImageHelper.h"
#include "gdcmWriter.h"
#include "gdcmImageWriter.h"
#include "gdcmTagKeywords.h"
#include "gdcmUIDGenerator.h"
int main(int argc, char *argv[])
{
if( argc < 2 ) return 1;
const char * filename = argv[1];
gdcm::ImageRegionReader irr;
irr.SetFileName( filename );
const bool b3 = irr.ReadInformation();
std::cout << b3 << std::endl;
gdcm::Image & img = irr.GetImage();
std::cout << img << std::endl;
// const gdcm::Region & r = irr.GetRegion();
// std::cout << r << std::endl;
gdcm::ImageWriter w;
gdcm::File & file = w.GetFile();
gdcm::DataSet & ds = file.GetDataSet();
gdcm::UIDGenerator uid;
namespace kwd = gdcm::Keywords;
kwd::FrameOfReferenceUID frameref;
frameref.SetValue( uid.Generate() );
// ContentDate
char date[22];
const size_t datelen = 8;
int res = gdcm::System::GetCurrentDateTime(date);
(void)res;
kwd::ContentDate contentdate;
// Do not copy the whole cstring:
contentdate.SetValue( gdcm::DAComp( date, datelen ) );
ds.Insert( contentdate.GetAsDataElement() );
// ContentTime
const size_t timelen = 6 + 1 + 6; // time + milliseconds
kwd::ContentTime contenttime;
// Do not copy the whole cstring:
contenttime.SetValue( gdcm::TMComp(date+datelen, timelen) );
ds.Insert( contenttime.GetAsDataElement() );
gdcm::MediaStorage ms0 = w.ComputeTargetMediaStorage();
std::cout << ms0 << std::endl;
kwd::SeriesNumber seriesnumber = { 1 };
kwd::InstanceNumber instancenum = { 1 };
kwd::StudyID studyid = { "St1" };
kwd::PatientID patientid = { "P1" };
kwd::SOPClassUID sopclassuid;
kwd::PositionReferenceIndicator pri;
//kwd::Laterality lat;
//kwd::BodyPartExamined bodypartex = { "HEAD" };
kwd::BodyPartExamined bodypartex = { "ANKLE" };
kwd::PatientOrientation pator;
kwd::BurnedInAnnotation bia = { "NO" };
kwd::ConversionType convtype = { "SYN" };
kwd::PresentationLUTShape plutshape = { "IDENTITY" }; // MONOCHROME2
// gdcm will pick the Word in case Byte class is not compatible:
gdcm::MediaStorage ms = gdcm::MediaStorage::MultiframeGrayscaleByteSecondaryCaptureImageStorage;
sopclassuid.SetValue( ms.GetString() );
ds.Insert( instancenum.GetAsDataElement() );
ds.Insert( sopclassuid.GetAsDataElement() );
ds.Insert( seriesnumber.GetAsDataElement() );
ds.Insert( patientid.GetAsDataElement() );
ds.Insert( studyid.GetAsDataElement() );
ds.Insert( frameref.GetAsDataElement() );
ds.Insert( pri.GetAsDataElement() );
//ds.Insert( lat.GetAsDataElement() );
ds.Insert( bodypartex.GetAsDataElement() );
ds.Insert( pator.GetAsDataElement() );
ds.Insert( bia.GetAsDataElement() );
ds.Insert( convtype.GetAsDataElement() );
ds.Insert( plutshape.GetAsDataElement() );
// gdcm::MediaStorage ms1 = w.ComputeTargetMediaStorage();
// std::cout << ms1 << std::endl;
std::cout << ds << std::endl;
gdcm::PixelFormat & pf = img.GetPixelFormat();
pf.SetPixelRepresentation(0); // always overwrite
img.SetSlope(1);
img.SetIntercept(0);
w.SetImage( img );
w.SetFileName( "TemplateImage.dcm" );
if( !w.Write() )
{
return 1;
}
return 0;
}
gdcm::Bitmap::GetPixelFormat
const PixelFormat & GetPixelFormat() const
Get/Set PixelFormat.
Definition gdcmBitmap.h:107
gdcm::DataSet
Class to represent a Data Set (which contains Data Elements)
Definition gdcmDataSet.h:56
gdcm::DataSet::Insert
void Insert(const DataElement &de)
Definition gdcmDataSet.h:128
gdcm::File
a DICOM File
Definition gdcmFile.h:34
gdcm::File::GetDataSet
const DataSet & GetDataSet() const
Get Data Set.
Definition gdcmFile.h:57
gdcm::ImageReader::GetImage
const Image & GetImage() const
Return the read image.
gdcm::ImageRegionReader
ImageRegionReader.
Definition gdcmImageRegionReader.h:35
gdcm::ImageRegionReader::ReadInformation
bool ReadInformation()
gdcm::ImageWriter
ImageWriter.
Definition gdcmImageWriter.h:33
gdcm::ImageWriter::ComputeTargetMediaStorage
MediaStorage ComputeTargetMediaStorage()
gdcm::ImageWriter::Write
bool Write() override
Write.
gdcm::Image
Image.
Definition gdcmImage.h:47
gdcm::Image::SetSlope
void SetSlope(double slope)
slope
Definition gdcmImage.h:92
gdcm::Image::SetIntercept
void SetIntercept(double intercept)
intercept
Definition gdcmImage.h:88
gdcm::MediaStorage
MediaStorage.
Definition gdcmMediaStorage.h:44
gdcm::MediaStorage::MultiframeGrayscaleByteSecondaryCaptureImageStorage
@ MultiframeGrayscaleByteSecondaryCaptureImageStorage
Definition gdcmMediaStorage.h:67
gdcm::MediaStorage::GetString
const char * GetString() const
Return the Media String of the object.
gdcm::PixelFormat
PixelFormat.
Definition gdcmPixelFormat.h:46
gdcm::PixelFormat::SetPixelRepresentation
void SetPixelRepresentation(unsigned short pr)
Definition gdcmPixelFormat.h:177
gdcm::PixmapWriter::SetImage
virtual void SetImage(Pixmap const &img)
gdcm::Reader::SetFileName
void SetFileName(const char *filename_native)
gdcm::System::GetCurrentDateTime
static bool GetCurrentDateTime(char date[22])
gdcm::UIDGenerator
Class for generating unique UID.
Definition gdcmUIDGenerator.h:28
gdcm::UIDGenerator::Generate
const char * Generate()
gdcm::Writer::GetFile
File & GetFile()
Definition gdcmWriter.h:67
gdcm::Writer::SetFileName
void SetFileName(const char *filename_native)
Set the filename of DICOM file to write:
gdcmFileStreamer.h
gdcmImageHelper.h
gdcmImageRegionReader.h
gdcmImageWriter.h
gdcmTag.h
gdcmTrace.h
gdcmUIDGenerator.h
gdcmWriter.h
gdcm::DAComp
String<'\\', 64 > DAComp
Definition gdcmVR.h:265
gdcm::TMComp
String<'\\', 16 > TMComp
Definition gdcmVR.h:274