+ gdcm::Attribute<0x8,0x60> modality;
+ modality.SetFromDataSet( ds );
+ if( modality.GetValue() != "RTSTRUCT" )
+ {
+ std::cerr << "Error. the file " << filename
+ << " is not a Dicom Struct ? (must have 0x0008,0x0060 = RTSTRUCT [RT Structure Set Storage])"
+ << std::endl;
+ exit(0);
+ }
+
+ // Read global info
+ gdcm::Attribute<0x20,0x10> studyid;
+ studyid.SetFromDataSet( ds );
+ gdcm::Attribute<0x8,0x20> studytime;
+ studytime.SetFromDataSet( ds );
+ gdcm::Attribute<0x8,0x30> studydate;
+ studydate.SetFromDataSet( ds );
+ gdcm::Attribute<0x3006,0x02> label;
+ label.SetFromDataSet( ds );
+ gdcm::Attribute<0x3006,0x04> atname;
+ atname.SetFromDataSet( ds );
+ gdcm::Attribute<0x3006,0x09> time;
+ time.SetFromDataSet( ds );
+
+ mStudyID = studyid.GetValue();
+ mStudyTime = studytime.GetValue();
+ mStudyDate = studydate.GetValue();
+ mLabel = label.GetValue();
+ mName = atname.GetValue();
+ mTime = time.GetValue();
+
+ // Temporary store the list of items
+ std::map<int, gdcm::Item*> mMapOfROIInfo;
+ std::map<int, gdcm::Item*> mMapOfROIContours;
+
+ //----------------------------------
+ // Read all ROI Names and number
+ // 0x3006,0x0020 = [ Structure Set ROI Sequence ]
+ gdcm::Tag tssroisq(0x3006,0x0020);
+ const gdcm::DataElement &ssroisq = ds.GetDataElement( tssroisq );
+ mROIInfoSequenceOfItems = ssroisq.GetValueAsSQ();
+ gdcm::SmartPointer<gdcm::SequenceOfItems> & roi_seq = mROIInfoSequenceOfItems;
+ assert(roi_seq); // TODO error message
+ for(unsigned int ridx = 0; ridx < roi_seq->GetNumberOfItems(); ++ridx)
+ {
+ gdcm::Item & item = roi_seq->GetItem( ridx + 1); // Item starts at 1
+ const gdcm::DataSet& nestedds = item.GetNestedDataSet();
+
+ gdcm::Attribute<0x3006,0x26> roiname;
+ roiname.SetFromDataSet( nestedds );
+ std::string name = roiname.GetValue(); // 0x3006,0x0026 = [ROI Name]
+
+ // 0x3006,0x0022 = [ROI Number]
+ int nb = ReadROINumber(item);
+
+ // Store the item
+ mMapOfROIInfo[nb] = &item;
+
+ // Check if such a number already exist
+ if (mMapOfROIName.find(nb) != mMapOfROIName.end()) {
+ std::cerr << "WARNING. A Roi already exist with the number "
+ << nb << ". I replace." << std::endl;
+ }
+ // Add in map
+ mMapOfROIName[nb] = name;
+ }
+
+ //----------------------------------
+ // Read all ROI item
+ // 0x3006,0x0039 = [ ROI Contour Sequence ]
+ gdcm::Tag troicsq(0x3006,0x0039);
+ const gdcm::DataElement &roicsq = ds.GetDataElement( troicsq );
+ gdcm::SmartPointer<gdcm::SequenceOfItems> roi_contour_seq = roicsq.GetValueAsSQ();
+ mROIContoursSequenceOfItems = roi_contour_seq;
+ assert(roi_contour_seq); // TODO error message
+ for(unsigned int ridx = 0; ridx < roi_contour_seq->GetNumberOfItems(); ++ridx) {
+ gdcm::Item & item = roi_contour_seq->GetItem( ridx + 1); // Item starts at 1
+ // ROI number [Referenced ROI Number]
+ const gdcm::DataSet& nestedds = item.GetNestedDataSet();
+ gdcm::Attribute<0x3006,0x0084> referencedroinumber;
+ referencedroinumber.SetFromDataSet( nestedds );
+ int nb = referencedroinumber.GetValue();
+ // Store the item
+ mMapOfROIContours[nb] = &item;
+ }
+
+ //----------------------------------
+ // Create the ROIs
+ for(std::map<int, gdcm::Item*>::iterator i = mMapOfROIInfo.begin(); i != mMapOfROIInfo.end(); i++) {
+ int nb = i->first;//ReadROINumber(i);//mROIIndex[i];
+ // Create the roi
+ DicomRT_ROI::Pointer roi = DicomRT_ROI::New();
+ roi->Read(mMapOfROIInfo[nb], mMapOfROIContours[nb]);
+ // mListOfROI.push_back(roi);
+ // mMapOfROIIndex[nb] = i;
+ mROIs[nb] = roi;
+ }
+
+ //----------------------------------------------------------------------------------------
+ //----------------------------------------------------------------------------------------
+ //----------------------------------------------------------------------------------------
+#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();
+