From 15ebed734d7ef4727dff24b21d00d929b9162f90 Mon Sep 17 00:00:00 2001 From: tbaudier Date: Fri, 19 May 2017 17:04:29 +0200 Subject: [PATCH] Add code to write dicom sequence tag in gateSimulation2Dicom --- ...clitkGateSimulation2DicomGenericFilter.txx | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/tools/clitkGateSimulation2DicomGenericFilter.txx b/tools/clitkGateSimulation2DicomGenericFilter.txx index f7678c1..3b54bdc 100644 --- a/tools/clitkGateSimulation2DicomGenericFilter.txx +++ b/tools/clitkGateSimulation2DicomGenericFilter.txx @@ -35,6 +35,7 @@ #include #include #include +#include #else #include "gdcmFile.h" #include "gdcmUtil.h" @@ -333,6 +334,58 @@ outputArray.push_back(outputDict); std::cerr << "Error: Exception thrown while writing the series!!" << std::endl; std::cerr << excp << std::endl; } + + gdcm::Reader reader2; + reader2.SetFileName( fileNamesOutput[0].c_str() ); + reader2.Read(); + + gdcm::File &file = reader2.GetFile(); + gdcm::DataSet &ds2 = file.GetDataSet(); + + //const unsigned int nitems = 1000; + const unsigned int ptr_len = 42; /*94967296 / nitems; */ + //assert( ptr_len == 42949672 ); + char *ptr = new char[ptr_len]; + memset(ptr,0,ptr_len); + + // Create a Sequence + gdcm::SmartPointer sq = new gdcm::SequenceOfItems(); + sq->SetLengthToUndefined(); + + //const char owner_str[] = "GDCM CONFORMANCE TESTS"; + //gdcm::DataElement owner( gdcm::Tag(0x54, 0x52) ); + //owner.SetByteValue(owner_str, (uint32_t)strlen(owner_str)); + //owner.SetVR( gdcm::VR::LO ); + + // Create a dataelement + gdcm::DataElement de( gdcm::Tag(0x54, 0x53) ); + de.SetByteValue(NumberToString(rotationNumber).c_str(), 1); + de.SetVR( gdcm::VR::OB ); + + // Create an item + gdcm::Item it; + it.SetVLToUndefined(); + gdcm::DataSet &nds = it.GetNestedDataSet(); + //nds.Insert(owner); + nds.Insert(de); + + sq->AddItem(it); + + // Insert sequence into data set + gdcm::DataElement des( gdcm::Tag(0x54, 0x52) ); + des.SetVR(gdcm::VR::SQ); + des.SetValue(*sq); + des.SetVLToUndefined(); + + //ds2.Insert(owner); + ds2.Insert(des); + + gdcm::Writer w; + w.SetFile( file ); + //w.SetCheckFileMetaInformation( true ); + w.SetFileName( fileNamesOutput[0].c_str() ); + w.Write(); + #else std::cout << "Use GDCM2" << std::endl; #endif -- 2.47.1