]> Creatis software - clitk.git/blobdiff - common/clitkDicomRT_StructureSet.cxx
_WIN32 is always defined and WIN32 maybe isn't, see
[clitk.git] / common / clitkDicomRT_StructureSet.cxx
index b10984ad56df49bf0c07786f5a1466ddcc749974..a26804b1839a49f0a3d6e5c51693ccc09c98dead 100644 (file)
@@ -180,8 +180,23 @@ void clitk::DicomRT_StructureSet::Write(const std::string & filename)
   const gdcm::DataElement &roicsq = ds.GetDataElement( troicsq );
   gdcm::DataElement de2(roicsq);
   de2.SetValue(*mROIContoursSequenceOfItems);
-  ds.Replace(de);
-  
+  ds.Replace(de2);
+
+  //DEBUG
+  gdcm::DataSet & a = mROIContoursSequenceOfItems->GetItem(1).GetNestedDataSet();
+  gdcm::Tag tcsq(0x3006,0x0040);
+  const gdcm::DataElement& csq = a.GetDataElement( tcsq );
+  gdcm::SmartPointer<gdcm::SequenceOfItems> sqi2 = csq.GetValueAsSQ();
+  gdcm::Item & j = sqi2->GetItem(1);
+  gdcm::DataSet & b = j.GetNestedDataSet();
+  gdcm::Attribute<0x3006,0x0050> at;
+  gdcm::Tag tcontourdata(0x3006,0x0050);
+  gdcm::DataElement contourdata = b.GetDataElement( tcontourdata );
+  at.SetFromDataElement( contourdata );
+  const double* points = at.GetValues();
+  DD(points[0]);
+
+
   // Write dicom
   gdcm::Writer writer;
   //writer.CheckFileMetaInformationOff();
@@ -392,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)
 {