| 76 | } |
| 77 | |
| 78 | std::string mitk::ROIMapperHelper::ParseCaption(const std::string& captionTemplate, const ROI::Element& roi, TimeStepType t) |
| 79 | { |
| 80 | std::regex regex(R"(\{([^}]*)\})"); // Anything between curly braces (considered as placeholder). |
| 81 | |
| 82 | auto start = captionTemplate.cbegin(); |
| 83 | bool hasPlaceholders = false; |
| 84 | std::string caption; |
| 85 | std::smatch match; |
| 86 | |
| 87 | // Iterate through the caption template and substitute all |
| 88 | // placeholders with corresponding data or property values. |
| 89 | |
| 90 | while (std::regex_search(start, captionTemplate.cend(), match, regex)) |
| 91 | { |
| 92 | hasPlaceholders = true; |
| 93 | |
| 94 | caption.append(match.prefix().first, match.prefix().second); |
| 95 | |
| 96 | if (match[1] == "ID") |
| 97 | { |
| 98 | caption.append(std::to_string(roi.GetID())); |
| 99 | } |
| 100 | else |
| 101 | { |
| 102 | auto property = roi.GetConstProperty(match[1], t); |
| 103 | |
| 104 | if (property.IsNotNull()) |
| 105 | caption.append(property->GetValueAsString()); |
| 106 | } |
| 107 | |
| 108 | start = match.suffix().first; |
| 109 | } |
| 110 | |
| 111 | if (match.suffix().matched) |
| 112 | caption.append(match.suffix().first, match.suffix().second); |
| 113 | |
| 114 | if (hasPlaceholders) |
| 115 | { |
| 116 | boost::trim(caption); |
| 117 | return caption; |
| 118 | } |
| 119 | |
| 120 | return captionTemplate; |
| 121 | } |
| 122 | |
| 123 | void mitk::ROIMapperHelper::SetDefaultProperties(DataNode* node, BaseRenderer* renderer, bool override) |
| 124 | { |
nothing calls this directly
no test coverage detected