diff OrthancStone/Sources/Toolbox/DicomStructureSet.cpp @ 1945:98952be6fb97

rendering plugin: rendering of multiple structures
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 02 Jun 2022 12:23:45 +0200
parents bd527bbc34df
children 07964689cb0b
line wrap: on
line diff
--- a/OrthancStone/Sources/Toolbox/DicomStructureSet.cpp	Thu Jun 02 11:45:28 2022 +0200
+++ b/OrthancStone/Sources/Toolbox/DicomStructureSet.cpp	Thu Jun 02 12:23:45 2022 +0200
@@ -401,6 +401,8 @@
     }
 
     structures_.resize(count);
+    structureNamesIndex_.clear();
+    
     for (size_t i = 0; i < count; i++)
     {
       structures_[i].interpretation_ = reader.GetStringValue
@@ -413,6 +415,16 @@
                             DICOM_TAG_ROI_NAME),
          "No name");
 
+      if (structureNamesIndex_.find(structures_[i].name_) == structureNamesIndex_.end())
+      {
+        structureNamesIndex_[structures_[i].name_] = i;
+      }
+      else
+      {
+        throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
+                                        "RT-STRUCT with twice the same name for a structure: " + structures_[i].name_);
+      }
+
       Vector color;
       if (FastParseVector(color, tags, Orthanc::DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
                                                           DICOM_TAG_ROI_DISPLAY_COLOR)) &&
@@ -1018,4 +1030,21 @@
       estimatedSliceThickness_ = LinearAlgebra::ComputeMedian(deltas);
     }
   }
+
+
+  bool DicomStructureSet::LookupStructureName(size_t& structureIndex /* out */,
+                                              const std::string& name) const
+  {
+    StructureNamesIndex::const_iterator found = structureNamesIndex_.find(name);
+
+    if (found == structureNamesIndex_.end())
+    {
+      return false;
+    }
+    else
+    {
+      structureIndex = found->second;
+      return true;
+    }
+  }
 }