From 0077a466af401999b712a48458e19be29d5ec938 Mon Sep 17 00:00:00 2001 From: David Sarrut Date: Wed, 12 Jun 2013 11:35:59 +0200 Subject: [PATCH] Check if it is really a rt-struct dicom before opening it --- common/clitkImage2DicomRTStructFilter.txx | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/common/clitkImage2DicomRTStructFilter.txx b/common/clitkImage2DicomRTStructFilter.txx index 051211b..1b241a9 100644 --- a/common/clitkImage2DicomRTStructFilter.txx +++ b/common/clitkImage2DicomRTStructFilter.txx @@ -88,10 +88,22 @@ clitk::Image2DicomRTStructFilter::SetROIName(std::string name, std::s template void clitk::Image2DicomRTStructFilter::Update() { + // Check this is a RT-Struct + gdcm::Reader gdcm_reader; + gdcm_reader.SetFileName(m_StructureSetFilename.c_str()); + if (!gdcm_reader.Read()) { + clitkExceptionMacro("Error could not open the file '" << m_StructureSetFilename << std::endl); + } + gdcm::MediaStorage ms; + ms.SetFromFile(gdcm_reader.GetFile()); + if (ms != gdcm::MediaStorage::RTStructureSetStorage) { + clitkExceptionMacro("File '" << m_StructureSetFilename << "' is not a DICOM-RT-Struct file." << std::endl); + } + // Read rt struct vtkSmartPointer reader = vtkGDCMPolyDataReader::New(); reader->SetFileName(m_StructureSetFilename.c_str()); - reader->Update(); + reader->Update(); // Get properties vtkRTStructSetProperties * p = reader->GetRTStructSetProperties(); -- 2.47.1