From d4e9c4039e268995501942736901458470241f7e Mon Sep 17 00:00:00 2001 From: David Sarrut Date: Thu, 12 Jul 2012 10:24:38 +0200 Subject: [PATCH] Add IsDicomRTStruct (bool) --- common/clitkDicomRT_StructureSet.cxx | 43 ++++++++++++++++++++++++++++ common/clitkDicomRT_StructureSet.h | 1 + 2 files changed, 44 insertions(+) diff --git a/common/clitkDicomRT_StructureSet.cxx b/common/clitkDicomRT_StructureSet.cxx index 4ac4705..a26804b 100644 --- a/common/clitkDicomRT_StructureSet.cxx +++ b/common/clitkDicomRT_StructureSet.cxx @@ -407,6 +407,49 @@ void clitk::DicomRT_StructureSet::Read(const std::string & filename) //-------------------------------------------------------------------- +//-------------------------------------------------------------------- +bool clitk::DicomRT_StructureSet::IsDicomRTStruct(const std::string & filename) +{ + // Open DICOM +#if GDCM_MAJOR_VERSION == 2 + // Read gdcm file + mReader = new gdcm::Reader; + mReader->SetFileName(filename.c_str()); + mReader->Read(); + mFile = &(mReader->GetFile()); + const gdcm::DataSet & ds = mFile->GetDataSet(); + + // Check file type + //Verify if the file is a RT-Structure-Set dicom file + gdcm::MediaStorage ms; + ms.SetFromFile(*mFile); + if( ms != gdcm::MediaStorage::RTStructureSetStorage ) return false; + + gdcm::Attribute<0x8,0x60> modality; + modality.SetFromDataSet( ds ); + if( modality.GetValue() != "RTSTRUCT" ) return false; + + return true; + + //---------------------------------------------------------------------------------------- +#else + mFile = new gdcm::File; + mFile->SetFileName(filename.c_str()); + mFile->SetMaxSizeLoadEntry(16384); // Needed ... + mFile->SetLoadMode(gdcm::LD_NOSHADOW); // don't load shadow tags (in order to save memory) + mFile->Load(); + + // Check file type + //Verify if the file is a RT-Structure-Set dicom file + if (!gdcm::Util::DicomStringEqual(mFile->GetEntryValue(0x0008,0x0016),"1.2.840.10008.5.1.4.1.1.481.3")) + return false; + if (!gdcm::Util::DicomStringEqual(mFile->GetEntryValue(0x0008,0x0060),"RTSTRUCT")) return false; + +#endif +} +//-------------------------------------------------------------------- + + //-------------------------------------------------------------------- int clitk::DicomRT_StructureSet::AddBinaryImageAsNewROI(vvImage * im, std::string n) { diff --git a/common/clitkDicomRT_StructureSet.h b/common/clitkDicomRT_StructureSet.h index d1cc37c..5761e14 100644 --- a/common/clitkDicomRT_StructureSet.h +++ b/common/clitkDicomRT_StructureSet.h @@ -49,6 +49,7 @@ public: void Print(std::ostream & os = std::cout) const; void Read(const std::string & filename); + bool IsDicomRTStruct(const std::string & filename); void Write(const std::string & filename); clitk::DicomRT_ROI * GetROIFromROINumber(int n); -- 2.45.1