diff --git a/Modules/Core/include/mitkAbstractAnnotationRenderer.h b/Modules/Core/include/mitkAbstractAnnotationRenderer.h index 81b77c7605..5f3b3ca9f7 100644 --- a/Modules/Core/include/mitkAbstractAnnotationRenderer.h +++ b/Modules/Core/include/mitkAbstractAnnotationRenderer.h @@ -1,76 +1,74 @@ /*=================================================================== * 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 ABSTRACTANNOTATIONRENDERER_H #define ABSTRACTANNOTATIONRENDERER_H #include #include #include "mitkOverlay.h" #include "mitkServiceInterface.h" #include "usGetModuleContext.h" #include "mitkOverlayServiceTracker.h" namespace mitk { class BaseRenderer; /** @brief Baseclass of Overlay layouters */ /** *A AbstractAnnotationRenderer can be implemented to control a set of Overlays by means of position and size. *AbstractAnnotationRenderer::PrepareLayout() should be implemented with a routine to set the position of the internal m_ManagedOverlays List. *A layouter is always connected to one BaseRenderer, so there is one instance of the layouter for each BaseRenderer. *One type of layouter should always have a unique identifier. *@ingroup Overlays */ class MITKCORE_EXPORT AbstractAnnotationRenderer { public: AbstractAnnotationRenderer(const std::string& rendererID); /** \brief virtual destructor in order to derive from this class */ virtual ~AbstractAnnotationRenderer(); - virtual std::string GetID() = 0; - std::string GetRendererID(); - - virtual void RegisterAnnotationRenderer(const std::string& rendererID) = 0; + virtual const std::string GetID() const = 0; + const std::string GetRendererID() const; static const std::string US_INTERFACE_NAME; static const std::string US_PROPKEY_ID; static const std::string US_PROPKEY_RENDERER_ID; private: /** \brief copy constructor */ AbstractAnnotationRenderer( const AbstractAnnotationRenderer &); /** \brief assignment operator */ AbstractAnnotationRenderer &operator=(const AbstractAnnotationRenderer &); OverlayServiceTracker* m_OverlayServiceTracker; const std::string m_RendererID; }; } // namespace mitk MITK_DECLARE_SERVICE_INTERFACE(mitk::AbstractAnnotationRenderer, "org.mitk.services.AbstractAnnotationRenderer") #endif // ABSTRACTANNOTATIONRENDERER_H diff --git a/Modules/Core/include/mitkAnnotationService.h b/Modules/Core/include/mitkAnnotationService.h index 9bb8131c19..b98f648f6f 100644 --- a/Modules/Core/include/mitkAnnotationService.h +++ b/Modules/Core/include/mitkAnnotationService.h @@ -1,61 +1,48 @@ /*=================================================================== 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 mitkAnnotationService_h #define mitkAnnotationService_h #include #include -#include +#include namespace mitk { class AbstractAnnotationRenderer; - class AnnotationService + class MITKCORE_EXPORT AnnotationService { public: typedef std::vector > AnnotationRendererServices; - AnnotationService(); ~AnnotationService(); static AbstractAnnotationRenderer* GetAnnotationRenderer(const std::string& arTypeID, const std::string& rendererID); - template - static void RegisterAnnotationRenderer(const std::string &rendererID) - { - std::unique_ptr ar(new T(rendererID)); - // Define ServiceProps - us::ServiceProperties props; - props[ AbstractAnnotationRenderer::US_PROPKEY_RENDERER_ID ] = rendererID; - props[ AbstractAnnotationRenderer::US_PROPKEY_ID ] = ar->GetID(); - - us::GetModuleContext()->RegisterService(ar.get(),props); - m_AnnotationRendererServices.push_back(std::move(ar)); - } + static void RegisterAnnotationRenderer(AbstractAnnotationRenderer* annotationRenderer); private: AnnotationService(const AnnotationService&); AnnotationService& operator=(const AnnotationService&); - static AnnotationRendererServices m_AnnotationRendererServices; }; } #endif diff --git a/Modules/Core/src/Rendering/mitkAbstractAnnotationRenderer.cpp b/Modules/Core/src/Rendering/mitkAbstractAnnotationRenderer.cpp index a6878627be..2dff8a94a8 100644 --- a/Modules/Core/src/Rendering/mitkAbstractAnnotationRenderer.cpp +++ b/Modules/Core/src/Rendering/mitkAbstractAnnotationRenderer.cpp @@ -1,36 +1,36 @@ /*=================================================================== 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 "mitkAbstractAnnotationRenderer.h" #include const std::string mitk::AbstractAnnotationRenderer::US_INTERFACE_NAME = "org.mitk.services.AbstractAnnotationRenderer"; const std::string mitk::AbstractAnnotationRenderer::US_PROPKEY_ID = US_INTERFACE_NAME + ".id"; const std::string mitk::AbstractAnnotationRenderer::US_PROPKEY_RENDERER_ID = US_INTERFACE_NAME + ".rendererId"; mitk::AbstractAnnotationRenderer::AbstractAnnotationRenderer(const std::string& rendererID) :m_RendererID(rendererID) { } mitk::AbstractAnnotationRenderer::~AbstractAnnotationRenderer() { } -std::string mitk::AbstractAnnotationRenderer::GetRendererID() +const std::string mitk::AbstractAnnotationRenderer::GetRendererID() const { return m_RendererID; } diff --git a/Modules/Core/src/Rendering/mitkAnnotationService.cpp b/Modules/Core/src/Rendering/mitkAnnotationService.cpp index 51b7a54a6e..99bd0fe0bb 100644 --- a/Modules/Core/src/Rendering/mitkAnnotationService.cpp +++ b/Modules/Core/src/Rendering/mitkAnnotationService.cpp @@ -1,55 +1,68 @@ /*=================================================================== 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 "mitkAnnotationService.h" +#include namespace mitk { AnnotationService::AnnotationService() { } AnnotationService::~AnnotationService() { } AbstractAnnotationRenderer *AnnotationService::GetAnnotationRenderer(const std::string &arTypeID, const std::string &rendererID) { //get the context us::ModuleContext* context = us::GetModuleContext(); //specify a filter that defines the requested type std::string filter = "(&(" + AbstractAnnotationRenderer::US_PROPKEY_ID + "=" + arTypeID + ")("+ AbstractAnnotationRenderer::US_PROPKEY_RENDERER_ID + "=" + rendererID + "))"; //find the fitting service std::vector serviceReferences = context->GetServiceReferences(AbstractAnnotationRenderer::US_INTERFACE_NAME, filter); //check if a service reference was found. It is also possible that several //services were found. This is not checked here, just the first one is taken. AbstractAnnotationRenderer* ar = nullptr; if ( serviceReferences.size() ) { ar = context->GetService(serviceReferences.front()); } //no service reference was found or found service reference has no valid source return ar; } +void AnnotationService::RegisterAnnotationRenderer(AbstractAnnotationRenderer *annotationRenderer) +{ + static AnnotationRendererServices AnnotationRendererServices; + // Define ServiceProps + us::ServiceProperties props; + props[ AbstractAnnotationRenderer::US_PROPKEY_RENDERER_ID ] = annotationRenderer->GetRendererID(); + props[ AbstractAnnotationRenderer::US_PROPKEY_ID ] = annotationRenderer->GetID(); + + us::GetModuleContext()->RegisterService(annotationRenderer,props); + AnnotationRendererServices.push_back(std::unique_ptr(annotationRenderer)); +} + } diff --git a/Modules/Overlays/include/mitkAnnotationPlacer.h b/Modules/Overlays/include/mitkAnnotationPlacer.h index 6f32b13e7a..5784c050df 100644 --- a/Modules/Overlays/include/mitkAnnotationPlacer.h +++ b/Modules/Overlays/include/mitkAnnotationPlacer.h @@ -1,56 +1,60 @@ /*=================================================================== 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 ANNOTATIONPLACER_H #define ANNOTATIONPLACER_H #include "MitkOverlaysExports.h" #include "mitkOverlay.h" #include "mitkAbstractAnnotationRenderer.h" namespace mitk { class BaseRenderer; /** \brief The AnnotationPlacer updates and manages Overlays and the respective Layouters. */ /** An Instance of the AnnotationPlacer can be registered to several BaseRenderer instances in order to * call the update method of each Overlay during the rendering phase of the renderer. * See \ref OverlaysPage for more info. */ class MITKOVERLAYS_EXPORT AnnotationPlacer : public AbstractAnnotationRenderer { - public: +public: + /** \brief virtual destructor in order to derive from this class */ + virtual ~AnnotationPlacer(); - /** \brief virtual destructor in order to derive from this class */ - virtual ~AnnotationPlacer(); + const std::string GetID() const; - virtual void RegisterAnnotationRenderer(const std::string &rendererID) override; + static AnnotationPlacer* GetAnnotationRenderer(const std::string& rendererID); private: + AnnotationPlacer(const std::string& rendererID); + /** \brief copy constructor */ AnnotationPlacer( const AnnotationPlacer &); /** \brief assignment operator */ AnnotationPlacer &operator=(const AnnotationPlacer &); + static const std::string ANNOTATIONRENDERER_ID; }; } // namespace mitk #endif // ANNOTATIONPLACER_H diff --git a/Modules/Overlays/include/mitkOverlayLayouter2D.h b/Modules/Overlays/include/mitkOverlayLayouter2D.h index 78e7d5b841..37a3f840f3 100644 --- a/Modules/Overlays/include/mitkOverlayLayouter2D.h +++ b/Modules/Overlays/include/mitkOverlayLayouter2D.h @@ -1,55 +1,61 @@ /*=================================================================== 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 OVERLAYLAYOUTER2D_H #define OVERLAYLAYOUTER2D_H #include "MitkOverlaysExports.h" #include "mitkAbstractAnnotationRenderer.h" namespace mitk { class BaseRenderer; /** \brief The OverlayLayouter2D updates and manages Overlays and the respective Layouters. */ /** An Instance of the OverlayLayouter2D can be registered to several BaseRenderer instances in order to * call the update method of each Overlay during the rendering phase of the renderer. * See \ref OverlaysPage for more info. */ class MITKOVERLAYS_EXPORT OverlayLayouter2D : public AbstractAnnotationRenderer { public: /** \brief virtual destructor in order to derive from this class */ virtual ~OverlayLayouter2D(); - virtual void RegisterAnnotationRenderer(const std::string &rendererID) override; + const std::string GetID() const; + + static OverlayLayouter2D *GetAnnotationRenderer(const std::string& rendererID); + + static const std::string ANNOTATIONRENDERER_ID; private: + OverlayLayouter2D(const std::string& rendererID); + /** \brief copy constructor */ OverlayLayouter2D( const OverlayLayouter2D &); /** \brief assignment operator */ OverlayLayouter2D &operator=(const OverlayLayouter2D &); }; } // namespace mitk #endif // OVERLAYLAYOUTER2D_H diff --git a/Modules/Overlays/src/mitkAnnotationPlacer.cpp b/Modules/Overlays/src/mitkAnnotationPlacer.cpp index 2e2b9ea481..1cf57f1565 100644 --- a/Modules/Overlays/src/mitkAnnotationPlacer.cpp +++ b/Modules/Overlays/src/mitkAnnotationPlacer.cpp @@ -1,38 +1,60 @@ /*=================================================================== 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 "mitkAnnotationPlacer.h" #include "mitkBaseRenderer.h" #include #include "mitkOverlay2DLayouter.h" #include "mitkAnnotationService.h" namespace mitk { +const std::string mitk::AnnotationPlacer::ANNOTATIONRENDERER_ID = "AnnotationPlacer"; + +AnnotationPlacer::AnnotationPlacer(const std::string& rendererID): + AbstractAnnotationRenderer(rendererID) +{ + +} AnnotationPlacer::~AnnotationPlacer() { } -void AnnotationPlacer::RegisterAnnotationRenderer(const std::string &rendererID) +const std::string AnnotationPlacer::GetID() const +{ + return ANNOTATIONRENDERER_ID; +} + +AnnotationPlacer *AnnotationPlacer::GetAnnotationRenderer(const std::string &rendererID) { - AnnotationService::RegisterAnnotationRenderer(rendererID); + AnnotationPlacer* result = nullptr; + AbstractAnnotationRenderer* registeredService = + AnnotationService::GetAnnotationRenderer(ANNOTATIONRENDERER_ID,rendererID); + if(registeredService) + result = dynamic_cast(registeredService); + if(!result) + { + result = new AnnotationPlacer(rendererID); + AnnotationService::RegisterAnnotationRenderer(result); + } + return result; } } diff --git a/Modules/Overlays/src/mitkOverlayLayouter2D.cpp b/Modules/Overlays/src/mitkOverlayLayouter2D.cpp index db70280356..57b5b7eacd 100644 --- a/Modules/Overlays/src/mitkOverlayLayouter2D.cpp +++ b/Modules/Overlays/src/mitkOverlayLayouter2D.cpp @@ -1,38 +1,60 @@ /*=================================================================== 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 "mitkOverlayLayouter2D.h" #include "mitkBaseRenderer.h" #include #include "mitkOverlay2DLayouter.h" #include "mitkAnnotationService.h" namespace mitk { +const std::string mitk::OverlayLayouter2D::ANNOTATIONRENDERER_ID = "OverlayLayouter2D"; + +OverlayLayouter2D::OverlayLayouter2D(const std::string& rendererID): + AbstractAnnotationRenderer(rendererID) +{ + +} + OverlayLayouter2D::~OverlayLayouter2D() { } -void OverlayLayouter2D::RegisterAnnotationRenderer(const std::string &rendererID) +const std::string OverlayLayouter2D::GetID() const { - AnnotationService::RegisterAnnotationRenderer(rendererID); + return ANNOTATIONRENDERER_ID; } +OverlayLayouter2D *OverlayLayouter2D::GetAnnotationRenderer(const std::string &rendererID) +{ + OverlayLayouter2D* result = nullptr; + AbstractAnnotationRenderer* registeredService = + AnnotationService::GetAnnotationRenderer(ANNOTATIONRENDERER_ID,rendererID); + if(registeredService) + result = dynamic_cast(registeredService); + if(!result) + { + result = new OverlayLayouter2D(rendererID); + AnnotationService::RegisterAnnotationRenderer(result); + } + return result; +} }