changeset 786:5aa728500586

optimizing constructor of DicomStructureSet
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 28 May 2019 07:48:57 +0200
parents 9f3b2027a4a9
children c83a45f864b2 9f68155c75b0
files Framework/Toolbox/DicomStructureSet.cpp Framework/Toolbox/DicomStructureSet.h Framework/Toolbox/LinearAlgebra.cpp
diffstat 3 files changed, 38 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Toolbox/DicomStructureSet.cpp	Mon May 27 17:20:59 2019 +0200
+++ b/Framework/Toolbox/DicomStructureSet.cpp	Tue May 28 07:48:57 2019 +0200
@@ -422,24 +422,43 @@
                    << static_cast<int>(structures_[i].green_) << ","
                    << static_cast<int>(structures_[i].blue_) << ")";
 
+
+      // These temporary variables avoid allocating many vectors in the loop below
+      OrthancPlugins::DicomPath countPointsPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
+                                                DICOM_TAG_CONTOUR_SEQUENCE, 0,
+                                                DICOM_TAG_NUMBER_OF_CONTOUR_POINTS);
+
+      OrthancPlugins::DicomPath geometricTypePath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
+                                                  DICOM_TAG_CONTOUR_SEQUENCE, 0,
+                                                  DICOM_TAG_CONTOUR_GEOMETRIC_TYPE);
+      
+      OrthancPlugins::DicomPath imageSequencePath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
+                                                  DICOM_TAG_CONTOUR_SEQUENCE, 0,
+                                                  DICOM_TAG_CONTOUR_IMAGE_SEQUENCE);
+
+      OrthancPlugins::DicomPath referencedInstancePath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
+                                                       DICOM_TAG_CONTOUR_SEQUENCE, 0,
+                                                       DICOM_TAG_CONTOUR_IMAGE_SEQUENCE, 0,
+                                                       DICOM_TAG_REFERENCED_SOP_INSTANCE_UID);
+
+      OrthancPlugins::DicomPath contourDataPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
+                                                DICOM_TAG_CONTOUR_SEQUENCE, 0,
+                                                DICOM_TAG_CONTOUR_DATA);
+
       for (size_t j = 0; j < countSlices; j++)
       {
         unsigned int countPoints;
 
-        if (!reader.GetUnsignedIntegerValue
-            (countPoints, OrthancPlugins::DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
-                                                    DICOM_TAG_CONTOUR_SEQUENCE, j,
-                                                    DICOM_TAG_NUMBER_OF_CONTOUR_POINTS)))
+        countPointsPath.SetPrefixIndex(1, j);
+        if (!reader.GetUnsignedIntegerValue(countPoints, countPointsPath))
         {
           throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
         }
             
         //LOG(INFO) << "Parsing slice containing " << countPoints << " vertices";
 
-        std::string type = reader.GetMandatoryStringValue
-          (OrthancPlugins::DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
-                                     DICOM_TAG_CONTOUR_SEQUENCE, j,
-                                     DICOM_TAG_CONTOUR_GEOMETRIC_TYPE));
+        geometricTypePath.SetPrefixIndex(1, j);
+        std::string type = reader.GetMandatoryStringValue(geometricTypePath);
         if (type != "CLOSED_PLANAR")
         {
           LOG(WARNING) << "Ignoring contour with geometry type: " << type;
@@ -447,24 +466,19 @@
         }
 
         size_t size;
-        if (!tags.GetSequenceSize(size, OrthancPlugins::DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
-                                                                  DICOM_TAG_CONTOUR_SEQUENCE, j,
-                                                                  DICOM_TAG_CONTOUR_IMAGE_SEQUENCE)) ||
+
+        imageSequencePath.SetPrefixIndex(1, j);
+        if (!tags.GetSequenceSize(size, imageSequencePath) ||
             size != 1)
         {
           throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);          
         }
 
-        std::string sopInstanceUid = reader.GetMandatoryStringValue
-          (OrthancPlugins::DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
-                                     DICOM_TAG_CONTOUR_SEQUENCE, j,
-                                     DICOM_TAG_CONTOUR_IMAGE_SEQUENCE, 0,
-                                     DICOM_TAG_REFERENCED_SOP_INSTANCE_UID));
-        
-        std::string slicesData = reader.GetMandatoryStringValue
-          (OrthancPlugins::DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
-                                     DICOM_TAG_CONTOUR_SEQUENCE, j,
-                                     DICOM_TAG_CONTOUR_DATA));
+        referencedInstancePath.SetPrefixIndex(1, j);
+        std::string sopInstanceUid = reader.GetMandatoryStringValue(referencedInstancePath);
+
+        contourDataPath.SetPrefixIndex(1, j);        
+        std::string slicesData = reader.GetMandatoryStringValue(contourDataPath);
 
         Vector points;
         if (!LinearAlgebra::ParseVector(points, slicesData) ||
--- a/Framework/Toolbox/DicomStructureSet.h	Mon May 27 17:20:59 2019 +0200
+++ b/Framework/Toolbox/DicomStructureSet.h	Tue May 28 07:48:57 2019 +0200
@@ -170,6 +170,7 @@
 
     Vector GetNormal() const;
 
+    // TODO - Remove
     static DicomStructureSet* SynchronousLoad(OrthancPlugins::IOrthancConnection& orthanc,
                                               const std::string& instanceId);
 
--- a/Framework/Toolbox/LinearAlgebra.cpp	Mon May 27 17:20:59 2019 +0200
+++ b/Framework/Toolbox/LinearAlgebra.cpp	Tue May 28 07:48:57 2019 +0200
@@ -63,7 +63,7 @@
                      const std::string& value)
     {
       std::vector<std::string> items;
-      Orthanc::Toolbox::TokenizeString(items, value, '\\');
+      Orthanc::Toolbox::TokenizeString(items, Orthanc::Toolbox::StripSpaces(value), '\\');
 
       target.resize(items.size());
 
@@ -71,7 +71,7 @@
       {
         try
         {
-          target[i] = boost::lexical_cast<double>(Orthanc::Toolbox::StripSpaces(items[i]));
+          target[i] = boost::lexical_cast<double>(items[i]);
         }
         catch (boost::bad_lexical_cast&)
         {