diff --git a/Modules/Annotation/include/mitkAnnotationFactory.h b/Modules/Annotation/include/mitkAnnotationFactory.h index 59565b9038..bee17d448d 100644 --- a/Modules/Annotation/include/mitkAnnotationFactory.h +++ b/Modules/Annotation/include/mitkAnnotationFactory.h @@ -1,81 +1,102 @@ -#pragma once +/*=================================================================== + + The Medical Imaging Interaction Toolkit (MITK) + + Copyright (c) German Cancer Research Center, + Division of Medical and Biological Informatics. + All rights reserved. + + This software is distributed WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. + + See LICENSE.txt or http://www.mitk.org for details. + + ===================================================================*/ + +#ifndef MITKANNOTATIONFACTORY_H +#define MITKANNOTATIONFACTORY_H + +// mitk #include "MitkAnnotationExports.h" #include "mitkAnnotation.h" #include "mitkCommon.h" #include "mitkDynamicAnnotation.h" #include "mitkLayoutAnnotationRenderer.h" -#include -#include + +// boost +#include + +// stl #include namespace mitk { /* * Responsibilities * Read json configuration * Create Annotations * Listen to slice change events * Observe (relevant) property modification and deletion * Data container for dynamic annotations */ class MITKANNOTATION_EXPORT AnnotationFactory : public itk::Object { - public: public: mitkClassMacroNoParent(AnnotationFactory); itkFactorylessNewMacro(AnnotationFactory); using ActionFunctionMap = std::unordered_map; using EventMap = std::unordered_map; + using AnnotationVector = std::vector; + void CreateAnnotationsFromJson(const std::string &fileName, ActionFunctionMap actionFunctionMap = ActionFunctionMap(), EventMap eventMap = EventMap()); - void SetProviderForAnnotation(itk::Object::Pointer provider, DynamicAnnotation &annotation); + void SaveConfigurationToJsonFile(const std::string &fileName); + void AddSingleAnnotation(DynamicAnnotation annotation); Annotation::Pointer GetAnnotationByName(const std::string &name); void SetProvider(const std::string &providerJsonKey, itk::Object::Pointer provider); void SetProviderForAllPropertyAnnotations(BaseData *provider); - std::vector GetManagedAnnotationIds(); - unsigned int GetAmountOfPendingAnnotations(); - - void SaveConfigurationToJsonFile(const std::string &fileName); - bool Update(); - void SliceChanged(Object *caller, const itk::EventObject &event); + // for testing + std::vector GetManagedAnnotationIds(); + unsigned int GetAmountOfPendingAnnotations() const; private: - using AnnotationVector = std::vector; + // private listener functions + void ObserveSliceChangedEvents(BaseRenderer *renderer); + void OnSliceChanged(Object *caller, const itk::EventObject &event); + // private helper functions static std::vector JsonToAnnotationInfoVector(boost::property_tree::ptree const &root); - LayoutAnnotationRenderer::Alignment GetAlignment(const std::string alignmentName) const; - void ObserveSliceChangedEvents(BaseRenderer *renderer); + static void SetProviderForAnnotation(itk::Object::Pointer provider, DynamicAnnotation &annotation); + LayoutAnnotationRenderer::Alignment GetAlignment(const std::string &alignmentName) const; bool RegisterAnnotation(DynamicAnnotation dynamicAnnotation); - void OnPropertyDeleted(const itk::Object *caller, const itk::EventObject &event); - void OnPropertyModified(const itk::Object *caller, const itk::EventObject &event); + // private data members AnnotationVector m_Annotations; AnnotationVector m_WaitingAnnotations; std::unordered_map m_SliceNavigationControllerTags; - - std::weak_ptr m_PropertyListOwner; - WeakPointer m_PropertyProvider; - unsigned m_Slice; - unsigned m_TimeStep; + unsigned m_Slice = 0; + unsigned m_TimeStep = 0; const std::unordered_map m_Defaults = { {AnnotationConstants::NAME, "Unnamed Annotation"}, {AnnotationConstants::DEFAULT, "NA"}, {AnnotationConstants::PREFIX, ""}, {AnnotationConstants::SUFFIX, ""}, {AnnotationConstants::TYPE, "text"}, {AnnotationConstants::PROVIDER, ""}, {AnnotationConstants::EVENT, ""}, {AnnotationConstants::ACTION, ""}, {AnnotationConstants::WINDOW, "stdmulti.widget1"}, {AnnotationConstants::LAYOUT, "TopLeft"}, }; }; } // namespace mitk +#endif // MITKANNOTATIONFACTORY_H diff --git a/Modules/Annotation/include/mitkDynamicAnnotation.h b/Modules/Annotation/include/mitkDynamicAnnotation.h index dd8780693e..4e897ed02f 100644 --- a/Modules/Annotation/include/mitkDynamicAnnotation.h +++ b/Modules/Annotation/include/mitkDynamicAnnotation.h @@ -1,159 +1,178 @@ -#pragma once +/*=================================================================== + + The Medical Imaging Interaction Toolkit (MITK) + + Copyright (c) German Cancer Research Center, + Division of Medical and Biological Informatics. + All rights reserved. + + This software is distributed WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. + + See LICENSE.txt or http://www.mitk.org for details. + + ===================================================================*/ + +#ifndef MITKDYNAMICANNOTATION_H +#define MITKDYNAMICANNOTATION_H + #include "mitkAnnotation.h" #include "mitkLogMacros.h" #include #include #include #include #include // namespace mitk //{ // class DataProvider : public itk::Object // { // public: // using OnEventAction = std::function; // mitkClassMacroItkParent(DataProvider, itk::Object); // mitkNewMacro4Param(DataProvider, std::string, WeakPointer, itk::EventObject *, OnEventAction); // // std::string Fetch() { return m_Result; }; // template // std::string Fetch(Args...); // // protected: // DataProvider(std::string name, WeakPointer provider, itk::EventObject *trigger, OnEventAction // action); // // std::string m_Name; // WeakPointer m_Provider; // const itk::EventObject *m_Trigger; // OnEventAction m_Action; // std::string m_Result; // // std::vector tags; // }; // class SliceProvider : public DataProvider // { // SliceProvider(WeakPointer sliceNavigationController) // : DataProvider("slice", // sliceNavigationController.Lock().GetPointer(), // SliceNavigationController::GeometrySliceEvent(nullptr, 0).MakeObject(), // [](const itk::Object *caller, const itk::EventObject &event) { // auto sliceEvent = dynamic_cast(&event); // if (sliceEvent) // { // return std::to_string(sliceEvent->GetPos()); // } // return std::string{"Slice Error"}; // }){}; // }; // class TimeProvider : public DataProvider // { // TimeProvider(WeakPointer sliceNavigationController) // : DataProvider("timeStep", // sliceNavigationController.Lock().GetPointer(), // SliceNavigationController::GeometryTimeEvent(nullptr, 0).MakeObject(), // [](const itk::Object *caller, const itk::EventObject &event) { // auto timeEvent = dynamic_cast(&event); // if (timeEvent) // { // return std::to_string(timeEvent->GetPos()); // } // return std::string{"Time Error"}; // }){}; // }; // template // class DependantProvider : public DataProvider // { // DependantProvider(); // // void SetProviders(Providers... providers) { m_Providers = std::tuple{providers...}; } // // virtual std::string Fetch(Providers... providers) = 0; // // std::tuple m_Providers; // }; // // class DicomProvider : public DependantProvider // { // std::string Fetch(SliceProvider sliceProvider, TimeProvider timeProvider) override // { // // }; // }; // // // SetText("Nr. " + DicomProvider.fetch(SliceProvider.fetch(), TimeProvider.fetch(), // // BaseData->GetProp("DICOM.0010.0010")); // // class DynamicAnnotation : public itk::Object // { // using Config = std::unordered_map; // using ProviderCollection = std::vector; // using TextSetter = std::function)>; // // public: // mitkClassMacroItkParent(DynamicAnnotation, itk::Object); // mitkNewMacro2Param(DynamicAnnotation, Annotation::Pointer, Config); // // void AddProvider(DataProvider::Pointer provider); // void SetTextAssemblyFunction(TextSetter function); // // private: // DynamicAnnotation(Annotation::Pointer annotation, std::unordered_map config); // // mitk::Annotation::Pointer m_Annotation; // Config m_Config; // ProviderCollection m_Providers; // }; //} // namespace mitk namespace mitk { namespace AnnotationConstants { const std::string NAME = "name"; const std::string DEFAULT = "defaultValue"; const std::string PREFIX = "prefix"; const std::string SUFFIX = "suffix"; const std::string LAYOUT = "layout"; const std::string TYPE = "type"; const std::string PROVIDER = "provider"; const std::string EVENT = "event"; const std::string ACTION = "action"; const std::string WINDOW = "window"; const std::string SLICENAVIGATIONCONTROLLER = "SliceNavigationController"; const std::string PATH = "path"; } // namespace AnnotationConstants struct DynamicAnnotation { using OnEventAction = std::function; using OnSliceChanged = std::function; using OnTimeStepChanged = std::function; DynamicAnnotation() : ptr(nullptr), config({}), providerInfo(DataProvider()) { MITK_INFO << "DynamicAnnotation constructor"; }; mitk::Annotation::Pointer ptr; std::unordered_map config; struct DataProvider { DataProvider() : object(nullptr), dataChangedEvent(nullptr) { MITK_INFO << "DataProvider constructor"; }; itk::Object::Pointer object; const itk::EventObject *dataChangedEvent; OnEventAction dataRetrievalAction; OnSliceChanged sliceChanged; OnTimeStepChanged timeStepChanged; std::vector tags; } providerInfo; void SetText(const std::string &text) { const auto &prefix = this->config[AnnotationConstants::PREFIX]; const auto &suffix = this->config[AnnotationConstants::SUFFIX]; this->ptr->SetText(prefix + text + suffix); } }; -} // namespace mitk \ No newline at end of file +} // namespace mitk +#endif // MITKDYNAMICANNOTATION_H diff --git a/Modules/Annotation/src/mitkAnnotationFactory.cpp b/Modules/Annotation/src/mitkAnnotationFactory.cpp index 5efcf4a206..0a7de3a311 100644 --- a/Modules/Annotation/src/mitkAnnotationFactory.cpp +++ b/Modules/Annotation/src/mitkAnnotationFactory.cpp @@ -1,436 +1,438 @@ +/*=================================================================== + + The Medical Imaging Interaction Toolkit (MITK) + + Copyright (c) German Cancer Research Center, + Division of Medical and Biological Informatics. + All rights reserved. + + This software is distributed WITHOUT ANY WARRANTY; without + even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. + + See LICENSE.txt or http://www.mitk.org for details. + + ===================================================================*/ + #include "mitkAnnotationFactory.h" #include "mitkAnnotationUtils.h" #include "mitkColorBarAnnotation.h" #include "mitkDynamicAnnotation.h" #include "mitkLayoutAnnotationRenderer.h" #include "mitkLogoAnnotation.h" #include "mitkScaleLegendAnnotation.h" #include "mitkTemporoSpatialStringProperty.h" #include "mitkTextAnnotation2D.h" #include #include class PropertyDeletedCommand : public itk::Command { public: void Execute(Object *caller, const itk::EventObject &event) override { Execute(const_cast(caller), event); }; void Execute(const Object *caller, const itk::EventObject &event) override { MITK_INFO << "Property " << caller->GetNameOfClass() << " deleted"; }; }; class ItkRetrievalCommand : public itk::Command { mitk::DynamicAnnotation::OnEventAction m_OnEventAction; std::string m_AnnotationId; public: - ItkRetrievalCommand(mitk::DynamicAnnotation::OnEventAction dataRetrievalAction, const std::string &annotationId) - : m_OnEventAction(dataRetrievalAction), m_AnnotationId(annotationId){}; + ItkRetrievalCommand(mitk::DynamicAnnotation::OnEventAction dataRetrievalAction, std::string annotationId) + : m_OnEventAction(std::move(dataRetrievalAction)), m_AnnotationId(std::move(annotationId)){}; void Execute(Object *caller, const itk::EventObject &event) override { Execute(const_cast(caller), event); }; void Execute(const Object *caller, const itk::EventObject &event) override { auto annotation = mitk::AnnotationUtils::GetAnnotation(m_AnnotationId); if (annotation) { // TODO remove hardcoded 0 slice and time auto updatedText = m_OnEventAction(caller, event, 0, 0); MITK_INFO << "Annotation " << annotation->GetName() << " set to " << updatedText; annotation->SetText(updatedText); } }; }; std::vector mitk::AnnotationFactory::JsonToAnnotationInfoVector( boost::property_tree::ptree const &root) { std::vector elements; auto annotations = root.begin(); if (annotations->first == "annotations") { for (const auto &window : annotations->second) { for (const auto &layout : window.second) { for (const auto &object : layout.second) { DynamicAnnotation annotation; annotation.config[AnnotationConstants::WINDOW] = window.first; annotation.config[AnnotationConstants::LAYOUT] = layout.first; for (const auto &property : object.second) { annotation.config[property.first] = property.second.get_value(); } if (annotation.config[AnnotationConstants::DEFAULT].empty()) { annotation.config[AnnotationConstants::DEFAULT] = annotation.config[AnnotationConstants::NAME]; } elements.push_back(annotation); } } } } return elements; } -mitk::LayoutAnnotationRenderer::Alignment mitk::AnnotationFactory::GetAlignment(const std::string alignmentName) const +mitk::LayoutAnnotationRenderer::Alignment mitk::AnnotationFactory::GetAlignment(const std::string &alignmentName) const { static const auto alignmentMap = std::unordered_map{ {"TopLeft", LayoutAnnotationRenderer::TopLeft}, {"Top", LayoutAnnotationRenderer::Top}, {"TopRight", LayoutAnnotationRenderer::TopRight}, {"Left", LayoutAnnotationRenderer::Left}, {"Right", LayoutAnnotationRenderer::Right}, {"BottomLeft", LayoutAnnotationRenderer::BottomLeft}, {"Bottom", LayoutAnnotationRenderer::Bottom}, {"BottomRight", LayoutAnnotationRenderer::BottomRight}}; const auto alignment = alignmentMap.find(alignmentName); const auto &defaultFallback = m_Defaults.at(AnnotationConstants::LAYOUT); return alignment != std::end(alignmentMap) ? alignment->second : alignmentMap.at(defaultFallback); } void mitk::AnnotationFactory::ObserveSliceChangedEvents(BaseRenderer *renderer) { if (!renderer) return; auto name = renderer->GetName(); if (m_SliceNavigationControllerTags.find(name) == std::end(m_SliceNavigationControllerTags)) { auto sliceCommand = itk::MemberCommand::New(); - sliceCommand->SetCallbackFunction(this, &AnnotationFactory::SliceChanged); + sliceCommand->SetCallbackFunction(this, &AnnotationFactory::OnSliceChanged); auto sliceController = renderer->GetSliceNavigationController(); auto tag = sliceController->AddObserver(SliceNavigationController::GeometrySliceEvent(nullptr, 0), sliceCommand); m_SliceNavigationControllerTags.insert({name, tag}); } } bool mitk::AnnotationFactory::RegisterAnnotation(DynamicAnnotation dynamicAnnotation) { const auto alignment = GetAlignment(dynamicAnnotation.config[AnnotationConstants::LAYOUT]); dynamicAnnotation.ptr->SetName(dynamicAnnotation.config[AnnotationConstants::NAME]); dynamicAnnotation.ptr->SetText(dynamicAnnotation.config[AnnotationConstants::DEFAULT]); MITK_INFO << dynamicAnnotation.config[AnnotationConstants::NAME]; const auto renderer = BaseRenderer::GetByName(dynamicAnnotation.config[AnnotationConstants::WINDOW]); if (renderer) { ObserveSliceChangedEvents(renderer); LayoutAnnotationRenderer::AddAnnotation(dynamicAnnotation.ptr, renderer, alignment); m_Annotations.push_back(dynamicAnnotation); // TODO wait so each annotation gets a unique id see T25927 std::this_thread::sleep_for(std::chrono::seconds(2)); if (dynamicAnnotation.config[AnnotationConstants::PROVIDER] == AnnotationConstants::SLICENAVIGATIONCONTROLLER) { SetProviderForAnnotation(renderer->GetSliceNavigationController(), dynamicAnnotation); } return true; } return false; } -void mitk::AnnotationFactory::SliceChanged(Object *caller, const itk::EventObject &event) +void mitk::AnnotationFactory::OnSliceChanged(Object *caller, const itk::EventObject &event) { - auto geometryEvent = dynamic_cast(&event); + const auto geometryEvent = dynamic_cast(&event); if (!geometryEvent) return; m_Slice = geometryEvent->GetPos(); - auto sliceNavController = dynamic_cast(caller); + const auto sliceNavController = dynamic_cast(caller); if (!sliceNavController) return; - auto renderer = sliceNavController->GetRenderer(); + const auto renderer = sliceNavController->GetRenderer(); if (!renderer) return; - auto rendererName = renderer->GetName(); + const auto rendererName = renderer->GetName(); for (auto &annotation : m_Annotations) { if (annotation.config[AnnotationConstants::TYPE] == "property" && annotation.config[AnnotationConstants::WINDOW] == rendererName) { annotation.SetText(annotation.providerInfo.dataRetrievalAction( annotation.providerInfo.object, *annotation.providerInfo.dataChangedEvent, m_Slice, m_TimeStep)); } } } void mitk::AnnotationFactory::CreateAnnotationsFromJson(const std::string &fileName, ActionFunctionMap actionFunctionMap, EventMap eventMap) { boost::property_tree::ptree root; - read_json(R"(D:\Arbeit\Programming\mitk_m\Plugins\org.mitk.annotations\resources\annotations.json)", root); + read_json(fileName, root); auto annotations = JsonToAnnotationInfoVector(root); for (auto annotation : annotations) { const auto &type = annotation.config[AnnotationConstants::TYPE]; if (type == "text") { annotation.ptr = mitk::TextAnnotation2D::New(); } else if (type == "property") { annotation.ptr = mitk::TextAnnotation2D::New(); annotation.providerInfo.dataChangedEvent = itk::ModifiedEvent().MakeObject(); const auto &defaultName = annotation.config[AnnotationConstants::DEFAULT]; annotation.providerInfo.dataRetrievalAction = [defaultName](const itk::Object *caller, const itk::EventObject &, unsigned int slice, unsigned int timeStep) { - auto dicomProperty = dynamic_cast(caller); + const auto dicomProperty = dynamic_cast(caller); if (dicomProperty) { return dicomProperty->GetValueBySlice(slice); } - auto property = dynamic_cast(caller); + const auto property = dynamic_cast(caller); if (property) { return property->GetValueAsString(); } return defaultName + " (NA)"; }; } else if (type == "custom") { if (annotation.config[AnnotationConstants::EVENT].empty() || annotation.config[AnnotationConstants::ACTION].empty()) { throw std::logic_error("A custom annotation needs to have an event and an action specified"); } annotation.ptr = TextAnnotation2D::New(); annotation.providerInfo.dataChangedEvent = eventMap[annotation.config[AnnotationConstants::EVENT]]; annotation.providerInfo.dataRetrievalAction = actionFunctionMap[annotation.config[AnnotationConstants::ACTION]]; } else if (type == "colorBar") { annotation.ptr = ColorBarAnnotation::New(); } else if (type == "scaleLegend") { annotation.ptr = ScaleLegendAnnotation::New(); } else if (type == "logo") { auto logoAnnotation = LogoAnnotation::New(); auto path = annotation.config[AnnotationConstants::PATH]; logoAnnotation->SetLogoImagePath(path); logoAnnotation->LoadLogoImageFromPath(); annotation.ptr = logoAnnotation; } else { throw std::logic_error("Unknown or missing annotation type"); } if (!RegisterAnnotation(annotation)) { // Registration of annotation failed probably due to missing base renderer // Store annotation for delayed registration m_WaitingAnnotations.push_back(annotation); } } } void mitk::AnnotationFactory::SetProviderForAnnotation(itk::Object::Pointer provider, DynamicAnnotation &annotation) { if (provider.IsNotNull() && provider != annotation.providerInfo.object) { if (annotation.providerInfo.object) { for (const auto &tag : annotation.providerInfo.tags) { annotation.providerInfo.object->RemoveObserver(tag); } } annotation.providerInfo.object = provider; if (annotation.providerInfo.dataChangedEvent) { annotation.providerInfo.tags.push_back(annotation.providerInfo.object->AddObserver( *annotation.providerInfo.dataChangedEvent, new ItkRetrievalCommand(annotation.providerInfo.dataRetrievalAction, annotation.ptr->GetMicroserviceID()))); } if (annotation.config[AnnotationConstants::TYPE] == "property") { annotation.providerInfo.tags.push_back( annotation.providerInfo.object->AddObserver(itk::DeleteEvent(), new PropertyDeletedCommand())); } } } void mitk::AnnotationFactory::AddSingleAnnotation(DynamicAnnotation annotation) { if (annotation.ptr) { try { - auto id = annotation.ptr->GetMicroserviceID(); + const auto id = annotation.ptr->GetMicroserviceID(); if (AnnotationUtils::GetAnnotation(id)) { // The annotation has already been fully set up so just add it to the managed annotations m_Annotations.push_back(annotation); } else { MITK_ERROR << "An annotation with a valid ID can't be fetched through the microservice registry. Not adding it " "to the managed annotations"; } } catch (const std::logic_error &e) { MITK_ERROR << e.what() << "\nWhen adding single annotations they should already be registered through a layout renderer. " "Trying this for you now."; // The annotation probably hasn't been registered yet so try it if (!RegisterAnnotation(annotation)) { m_WaitingAnnotations.push_back(annotation); } } } } mitk::Annotation::Pointer mitk::AnnotationFactory::GetAnnotationByName(const std::string &name) { for (const auto &annotation : m_Annotations) { if (annotation.ptr->GetName() == name) { return annotation.ptr; } } return nullptr; } void mitk::AnnotationFactory::SetProvider(const std::string &providerJsonKey, itk::Object::Pointer provider) { for (auto &annotation : m_Annotations) { if (providerJsonKey == annotation.config[AnnotationConstants::PROVIDER]) { SetProviderForAnnotation(provider, annotation); } } } void mitk::AnnotationFactory::SetProviderForAllPropertyAnnotations(BaseData *provider) { - Update(); // TODO temporary semi fix - - if (provider) - { - if (!m_PropertyProvider.IsExpired()) - { - // TODO unsubscribe - } - m_PropertyProvider = provider->GetPropertyList(); - if (!m_PropertyProvider.IsExpired()) - { - m_PropertyProvider.Lock()->AddObserver(itk::ModifiedEvent(), new PropertyDeletedCommand()); - m_PropertyProvider.Lock()->AddObserver(itk::DeleteEvent(), new PropertyDeletedCommand()); - } - } + Update(); // TODO temporary fix for delaying the registration of annotations until the render windows are present for (auto &annotation : m_Annotations) { if (annotation.config[AnnotationConstants::TYPE] != "property") continue; // if provider has property auto propertyName = annotation.config[AnnotationConstants::PROVIDER]; auto property = provider->GetProperty(propertyName.c_str()); if (property) { // set provider (in case the property exists but is empty state this in the annotations text SetProviderForAnnotation(property.GetPointer(), annotation); annotation.ptr->SetColor(0, 200, 0); annotation.SetText(annotation.providerInfo.dataRetrievalAction( annotation.providerInfo.object, *annotation.providerInfo.dataChangedEvent, 0, 0)); if (annotation.ptr->GetText().empty()) { annotation.ptr->SetColor(0, 0, 200); annotation.SetText(annotation.config[AnnotationConstants::DEFAULT] + " (empty)"); } } else { annotation.ptr->SetColor(200, 0, 0); annotation.SetText(annotation.config[AnnotationConstants::DEFAULT] + " (NA)"); } } } std::vector mitk::AnnotationFactory::GetManagedAnnotationIds() { auto ids = std::vector{}; for (const auto &annotation : m_Annotations) { ids.push_back(annotation.ptr->GetMicroserviceID()); } return ids; } -unsigned mitk::AnnotationFactory::GetAmountOfPendingAnnotations() +unsigned mitk::AnnotationFactory::GetAmountOfPendingAnnotations() const { return m_WaitingAnnotations.size(); } void mitk::AnnotationFactory::SaveConfigurationToJsonFile(const std::string &fileName) { using boost::property_tree::ptree; ptree root; - auto createNodes = [&root](DynamicAnnotation &annotation) { + const auto createNodes = [&root](DynamicAnnotation &annotation) { const auto &window = annotation.config[AnnotationConstants::WINDOW]; const auto &layout = annotation.config[AnnotationConstants::LAYOUT]; - ptree::path_type path{"annotations:" + window + ":" + layout, ':'}; + const ptree::path_type path{"annotations:" + window + ":" + layout, ':'}; ptree object; for (const auto &pair : annotation.config) { if (pair.first == AnnotationConstants::WINDOW || pair.first == AnnotationConstants::LAYOUT) continue; object.put(pair.first, pair.second); } ptree layoutNode = root.get_child_optional(path).has_value() ? root.get_child(path) : ptree{}; layoutNode.push_back(std::make_pair("", object)); root.put_child(path, layoutNode); }; std::for_each(std::begin(m_Annotations), std::end(m_Annotations), createNodes); std::for_each(std::begin(m_WaitingAnnotations), std::end(m_WaitingAnnotations), createNodes); ofstream out; out.open(fileName); if (out.is_open()) { boost::property_tree::write_json(out, root); } else { MITK_ERROR << "Error opening file"; } } bool mitk::AnnotationFactory::Update() { const auto firstElementToErase = std::remove_if(m_WaitingAnnotations.begin(), m_WaitingAnnotations.end(), [this](DynamicAnnotation da) { return RegisterAnnotation(da); }); m_WaitingAnnotations.erase(firstElementToErase, m_WaitingAnnotations.end()); return m_WaitingAnnotations.empty(); }