]> Creatis software - clitk.git/blobdiff - vv/vvMeshReader.cxx
change form width
[clitk.git] / vv / vvMeshReader.cxx
index 92939bdc0d5442ee5cc6eb27df8af9ae9bb9addd..fb0baf47a10c0edd5cd9ef7edb01dbab36db1bf6 100644 (file)
@@ -3,7 +3,7 @@
 
   Authors belong to:
   - University of LYON              http://www.universite-lyon.fr/
-  - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
+  - Léon Bérard cancer center       http://www.centreleonberard.fr
   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
 
   This software is distributed WITHOUT ANY WARRANTY; without even
 
   - BSD        See included LICENSE.txt file
   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-======================================================================-====*/
+===========================================================================**/
 #include <algorithm>
 
 #include <QApplication>
 
-#include <gdcm.h>
-#include <gdcmSQItem.h>
+#include <gdcmFile.h>
+#if GDCM_MAJOR_VERSION == 2
+  #include <gdcmReader.h>
+  #include <gdcmTag.h>
+  #include <gdcmAttribute.h>
+#else
+  #include <gdcm.h>
+  #include <gdcmSQItem.h>
+#endif
 
 #include <vtkSmartPointer.h>
 #include <vtkAppendPolyData.h>
@@ -80,6 +87,36 @@ void vvMeshReader::run()
 std::vector<std::pair<int,std::string> > vvMeshReader::GetROINames()
 {
   assert(filename!="");
+  std::vector<std::pair<int, std::string> > roi_names;
+#if GDCM_MAJOR_VERSION == 2
+  // duplicate code from  clitk::DicomRT_StructureSet::Read
+  gdcm::Reader reader;
+  reader.SetFileName( filename.c_str() );
+  reader.Read();
+
+  const gdcm::DataSet &ds = reader.GetFile().GetDataSet();
+
+  gdcm::Tag tssroisq(0x3006,0x0020);
+  const gdcm::DataElement &ssroisq = ds.GetDataElement( tssroisq );
+  gdcm::SmartPointer<gdcm::SequenceOfItems> roi_seq = ssroisq.GetValueAsSQ();
+  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();
+    if( nestedds.FindDataElement( gdcm::Tag(0x3006,0x22) ) )
+      {
+      gdcm::Attribute<0x3006,0x26> roiname;
+      roiname.SetFromDataSet( nestedds );
+      std::string name = roiname.GetValue();      // 0x3006,0x0026 = [ROI Name]
+      gdcm::Attribute<0x3006,0x0022> roinumber;
+      roinumber.SetFromDataSet( nestedds );
+      int nb = roinumber.GetValue();  // 0x3006,0x0022 = [ROI Number]
+
+      roi_names.push_back(make_pair(nb,name));
+      }
+    }
+#else
   gdcm::File reader;
   reader.SetFileName(filename.c_str());
   reader.SetMaxSizeLoadEntry(16384);
@@ -87,23 +124,25 @@ std::vector<std::pair<int,std::string> > vvMeshReader::GetROINames()
 
   gdcm::SeqEntry * roi_info=reader.GetSeqEntry(0x3006,0x0020);
   assert(roi_info);
-  std::vector<std::pair<int, std::string> > roi_names;
   // DD("ici");
   //int n=0;
   for (gdcm::SQItem* i=roi_info->GetFirstSQItem(); i!=0; i=roi_info->GetNextSQItem())
     if (i->GetEntryValue(0x3006,0x0022)!= gdcm::GDCM_UNFOUND)
       roi_names.push_back(make_pair(atoi(i->GetEntryValue(0x3006,0x0022).c_str()),i->GetEntryValue(0x3006,0x0026)));
+#endif
   return roi_names;
 }
 
 std::vector<vvMesh::Pointer> vvMeshReader::readSelectedContours()
 {
+  std::vector<vvMesh::Pointer> result;
+#if GDCM_MAJOR_VERSION == 2
+#else
   gdcm::File reader;
   reader.SetFileName(filename.c_str());
   reader.SetMaxSizeLoadEntry(16384);
   reader.Load();
 
-  std::vector<vvMesh::Pointer> result;
   gdcm::SeqEntry * rois=reader.GetSeqEntry(0x3006,0x0039);
   ///We need to iterate both on the contours themselves, and on the contour info
   gdcm::SeqEntry * roi_info=reader.GetSeqEntry(0x3006,0x0020);
@@ -160,6 +199,7 @@ std::vector<vvMesh::Pointer> vvMeshReader::readSelectedContours()
     }
     k=roi_info->GetNextSQItem(); //increment the second loop variable
   }
+#endif
   return result;
 }