diff --git a/Modules/Core/include/mitkAbstractAnnotationRenderer.h b/Modules/Core/include/mitkAbstractAnnotationRenderer.h index 49442dd95d..81b77c7605 100644 --- a/Modules/Core/include/mitkAbstractAnnotationRenderer.h +++ b/Modules/Core/include/mitkAbstractAnnotationRenderer.h @@ -1,74 +1,76 @@ /*=================================================================== * 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; + 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 e26cac2302..9bb8131c19 100644 --- a/Modules/Core/include/mitkAnnotationService.h +++ b/Modules/Core/include/mitkAnnotationService.h @@ -1,50 +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 mitkAnnotationService_h #define mitkAnnotationService_h #include #include +#include namespace mitk { class AbstractAnnotationRenderer; class 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); + 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)); + } private: AnnotationService(const AnnotationService&); AnnotationService& operator=(const AnnotationService&); static AnnotationRendererServices m_AnnotationRendererServices; }; } #endif diff --git a/Modules/Core/src/Rendering/mitkAnnotationService.cpp b/Modules/Core/src/Rendering/mitkAnnotationService.cpp index 30293afd48..51b7a54a6e 100644 --- a/Modules/Core/src/Rendering/mitkAnnotationService.cpp +++ b/Modules/Core/src/Rendering/mitkAnnotationService.cpp @@ -1,70 +1,55 @@ /*=================================================================== 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 -#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; } -template -void AnnotationService::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)); -} - } diff --git a/Modules/Overlays/include/mitkAnnotationPlacer.h b/Modules/Overlays/include/mitkAnnotationPlacer.h index 1d319c4fa7..6f32b13e7a 100644 --- a/Modules/Overlays/include/mitkAnnotationPlacer.h +++ b/Modules/Overlays/include/mitkAnnotationPlacer.h @@ -1,54 +1,56 @@ /*=================================================================== 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: /** \brief virtual destructor in order to derive from this class */ virtual ~AnnotationPlacer(); + virtual void RegisterAnnotationRenderer(const std::string &rendererID) override; + private: /** \brief copy constructor */ AnnotationPlacer( const AnnotationPlacer &); /** \brief assignment operator */ AnnotationPlacer &operator=(const AnnotationPlacer &); }; } // namespace mitk #endif // ANNOTATIONPLACER_H diff --git a/Modules/Overlays/include/mitkOverlayLayouter2D.h b/Modules/Overlays/include/mitkOverlayLayouter2D.h index ed8d3a574c..78e7d5b841 100644 --- a/Modules/Overlays/include/mitkOverlayLayouter2D.h +++ b/Modules/Overlays/include/mitkOverlayLayouter2D.h @@ -1,53 +1,55 @@ /*=================================================================== 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; + private: /** \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 7540e014c3..2e2b9ea481 100644 --- a/Modules/Overlays/src/mitkAnnotationPlacer.cpp +++ b/Modules/Overlays/src/mitkAnnotationPlacer.cpp @@ -1,32 +1,38 @@ /*=================================================================== 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 { AnnotationPlacer::~AnnotationPlacer() { } +void AnnotationPlacer::RegisterAnnotationRenderer(const std::string &rendererID) +{ + AnnotationService::RegisterAnnotationRenderer(rendererID); +} + } diff --git a/Modules/Overlays/src/mitkOverlayLayouter2D.cpp b/Modules/Overlays/src/mitkOverlayLayouter2D.cpp index b70f37b25a..db70280356 100644 --- a/Modules/Overlays/src/mitkOverlayLayouter2D.cpp +++ b/Modules/Overlays/src/mitkOverlayLayouter2D.cpp @@ -1,32 +1,38 @@ /*=================================================================== 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 { OverlayLayouter2D::~OverlayLayouter2D() { } +void OverlayLayouter2D::RegisterAnnotationRenderer(const std::string &rendererID) +{ + AnnotationService::RegisterAnnotationRenderer(rendererID); +} + }