From 78bd7fb31b49e7b7557c062a691f622f6dec58a0 Mon Sep 17 00:00:00 2001 From: tbaudier Date: Thu, 15 Mar 2018 11:12:09 +0100 Subject: [PATCH] Be sure Number of Frame of Rotation exists in dicom tags --- ...artitionEnergyWindowDicomGenericFilter.txx | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tools/clitkPartitionEnergyWindowDicomGenericFilter.txx b/tools/clitkPartitionEnergyWindowDicomGenericFilter.txx index 8b102bf..bf58925 100644 --- a/tools/clitkPartitionEnergyWindowDicomGenericFilter.txx +++ b/tools/clitkPartitionEnergyWindowDicomGenericFilter.txx @@ -182,15 +182,19 @@ PartitionEnergyWindowDicomGenericFilter::UpdateWithDimAndPixelTy series_number_att.SetFromDataSet(dsInput); int nbEnergyWindow = series_number_att.GetValue(); - const gdcm::DataElement &seqRotation = dsInput.GetDataElement(gdcm::Tag(0x54, 0x52)); - gdcm::SmartPointer sqiRotation = seqRotation.GetValueAsSQ(); - gdcm::Item &itemRotation = sqiRotation->GetItem(1); - const gdcm::DataElement &deRotation = itemRotation.GetDataElement(gdcm::Tag(0x54, 0x53)); - unsigned short SamplesPerPixelRotation = *((unsigned short *) deRotation.GetByteValue()->GetPointer()); - std::stringstream s_SamplesPerPixelRotation; - s_SamplesPerPixelRotation << SamplesPerPixelRotation; - std::string p_StrRotation = s_SamplesPerPixelRotation.str(); - int nbRotation = (int)atof(p_StrRotation.c_str()); + int nbRotation; + if (dsInput.FindDataElement(gdcm::Tag(0x54, 0x52))) { + const gdcm::DataElement &seqRotation = dsInput.GetDataElement(gdcm::Tag(0x54, 0x52)); + gdcm::SmartPointer sqiRotation = seqRotation.GetValueAsSQ(); + gdcm::Item &itemRotation = sqiRotation->GetItem(1); + const gdcm::DataElement &deRotation = itemRotation.GetDataElement(gdcm::Tag(0x54, 0x53)); + unsigned short SamplesPerPixelRotation = *((unsigned short *) deRotation.GetByteValue()->GetPointer()); + std::stringstream s_SamplesPerPixelRotation; + s_SamplesPerPixelRotation << SamplesPerPixelRotation; + std::string p_StrRotation = s_SamplesPerPixelRotation.str(); + nbRotation = (int)atof(p_StrRotation.c_str()); + } else + nbRotation = 1; int nbSlicePerEnergy = nbSlice / nbEnergyWindow; if (nbSlicePerEnergy*nbEnergyWindow != nbSlice) -- 2.47.1