# HG changeset patch # User Sebastien Jodogne # Date 1559022537 -7200 # Node ID 5aa7285005868638bc58b6b63a1b4b837c92a5a5 # Parent 9f3b2027a4a97e0e5f85132d13e92c755f64a1f2 optimizing constructor of DicomStructureSet diff -r 9f3b2027a4a9 -r 5aa728500586 Framework/Toolbox/DicomStructureSet.cpp --- 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(structures_[i].green_) << "," << static_cast(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) || diff -r 9f3b2027a4a9 -r 5aa728500586 Framework/Toolbox/DicomStructureSet.h --- 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); diff -r 9f3b2027a4a9 -r 5aa728500586 Framework/Toolbox/LinearAlgebra.cpp --- 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 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(Orthanc::Toolbox::StripSpaces(items[i])); + target[i] = boost::lexical_cast(items[i]); } catch (boost::bad_lexical_cast&) {