diff --git a/Modules/ROI/src/mitkROIMapperHelper.cpp b/Modules/ROI/src/mitkROIMapperHelper.cpp index cbf5b99bff..685d095794 100644 --- a/Modules/ROI/src/mitkROIMapperHelper.cpp +++ b/Modules/ROI/src/mitkROIMapperHelper.cpp @@ -1,130 +1,132 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #include "mitkROIMapperHelper.h" #include #include #include #include -void mitk::ROIMapperHelper::ApplyIndividualProperties(const IPropertyProvider* properties, vtkActor* actor) +void mitk::ROIMapperHelper::ApplyIndividualProperties(const IPropertyProvider& properties, TimeStepType t, vtkActor* actor) { auto* property = actor->GetProperty(); property->SetRepresentationToWireframe(); property->LightingOff(); - if (auto colorProperty = GetConstProperty("color", properties); colorProperty != nullptr) + const auto contextName = std::to_string(t); + + if (auto colorProperty = GetConstProperty("color", properties, contextName); colorProperty != nullptr) { const auto color = colorProperty->GetColor(); property->SetColor(color[0], color[1], color[2]); } - if (auto opacityProperty = GetConstProperty("opacity", properties); opacityProperty != nullptr) + if (auto opacityProperty = GetConstProperty("opacity", properties, contextName); opacityProperty != nullptr) { const auto opacity = opacityProperty->GetValue(); property->SetOpacity(property->GetOpacity() * opacity); } - if (auto lineWidthProperty = GetConstProperty("lineWidth", properties); lineWidthProperty != nullptr) + if (auto lineWidthProperty = GetConstProperty("lineWidth", properties, contextName); lineWidthProperty != nullptr) { const auto lineWidth = lineWidthProperty->GetValue(); property->SetLineWidth(lineWidth); } } vtkSmartPointer mitk::ROIMapperHelper::CreateCaptionActor(const std::string& caption, const Point3D& attachmentPoint, vtkProperty* property, const DataNode* dataNode, const BaseRenderer* renderer) { auto captionActor = vtkSmartPointer::New(); captionActor->SetPosition(property->GetLineWidth() * 0.5, property->GetLineWidth() * 0.5); captionActor->GetTextActor()->SetTextScaleModeToNone(); captionActor->SetAttachmentPoint(attachmentPoint[0], attachmentPoint[1], attachmentPoint[2]); captionActor->SetCaption(caption.c_str()); captionActor->BorderOff(); captionActor->LeaderOff(); auto* textProperty = captionActor->GetCaptionTextProperty(); textProperty->SetColor(property->GetColor()); textProperty->SetOpacity(property->GetOpacity()); textProperty->ShadowOff(); int fontSize = 16; dataNode->GetIntProperty("font.size", fontSize, renderer); textProperty->SetFontSize(fontSize); bool bold = false; dataNode->GetBoolProperty("font.bold", bold, renderer); textProperty->SetBold(bold); bool italic = false; dataNode->GetBoolProperty("font.italic", italic, renderer); textProperty->SetItalic(italic); return captionActor; } -std::string mitk::ROIMapperHelper::ParseCaption(const std::string& captionTemplate, const ROI::Element& roi) +std::string mitk::ROIMapperHelper::ParseCaption(const std::string& captionTemplate, const ROI::Element& roi, TimeStepType t) { std::regex regex(R"(\{([^}]*)\})"); // Anything between curly braces (considered as placeholder). auto start = captionTemplate.cbegin(); bool hasPlaceholders = false; std::string caption; std::smatch match; // Iterate through the caption template and substitute all // placeholders with corresponding data or property values. while (std::regex_search(start, captionTemplate.cend(), match, regex)) { hasPlaceholders = true; caption.append(match.prefix().first, match.prefix().second); if (match[1] == "ID") { - caption.append(std::to_string(roi.ID)); + caption.append(std::to_string(roi.GetID())); } else { - auto property = roi.GetConstProperty(match[1]); + auto property = roi.GetConstProperty(match[1], std::to_string(t)); if (property.IsNotNull()) caption.append(property->GetValueAsString()); } start = match.suffix().first; } if (match.suffix().matched) caption.append(match.suffix().first, match.suffix().second); if (hasPlaceholders) { boost::trim(caption); return caption; } return captionTemplate; } void mitk::ROIMapperHelper::SetDefaultProperties(DataNode* node, BaseRenderer* renderer, bool override) { node->AddProperty("opacity", FloatProperty::New(1.0f), renderer, override); node->AddProperty("font.bold", BoolProperty::New(false), renderer, override); node->AddProperty("font.italic", BoolProperty::New(false), renderer, override); node->AddProperty("font.size", IntProperty::New(16), renderer, override); node->AddProperty("caption", StringProperty::New("{ID}\n{name}"), renderer, override); } diff --git a/Modules/ROI/src/mitkROIMapperHelper.h b/Modules/ROI/src/mitkROIMapperHelper.h index 48161c27ad..e6239fba1a 100644 --- a/Modules/ROI/src/mitkROIMapperHelper.h +++ b/Modules/ROI/src/mitkROIMapperHelper.h @@ -1,48 +1,48 @@ /*============================================================================ The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center (DKFZ) All rights reserved. Use of this source code is governed by a 3-clause BSD license that can be found in the LICENSE file. ============================================================================*/ #ifndef mitkROIMapperHelper_h #define mitkROIMapperHelper_h #include #include #include #include #include namespace mitk { namespace ROIMapperHelper { - void ApplyIndividualProperties(const IPropertyProvider* properties, vtkActor* actor); + void ApplyIndividualProperties(const IPropertyProvider& properties, TimeStepType t, vtkActor* actor); vtkSmartPointer CreateCaptionActor(const std::string& caption, const Point3D& attachmentPoint, vtkProperty* property, const DataNode* dataNode, const BaseRenderer* renderer); - std::string ParseCaption(const std::string& captionTemplate, const ROI::Element& roi); + std::string ParseCaption(const std::string& captionTemplate, const ROI::Element& roi, TimeStepType t = 0); void SetDefaultProperties(DataNode* node, BaseRenderer* renderer, bool override); template - const T* GetConstProperty(const std::string& propertyKey, const mitk::IPropertyProvider* properties) + const T* GetConstProperty(const std::string& propertyKey, const mitk::IPropertyProvider& properties, const std::string& contextName = "") { - auto property = properties->GetConstProperty(propertyKey); + auto property = properties.GetConstProperty(propertyKey, contextName); if (property.IsNotNull()) return dynamic_cast(property.GetPointer()); return nullptr; } } } #endif