diff --git a/Modules/Core/include/mitkAbstractAnnotationRenderer.h b/Modules/Core/include/mitkAbstractAnnotationRenderer.h index 3064f19b80..152f3b4916 100644 --- a/Modules/Core/include/mitkAbstractAnnotationRenderer.h +++ b/Modules/Core/include/mitkAbstractAnnotationRenderer.h @@ -1,73 +1,79 @@ /*=================================================================== * 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 { +#include "usServiceTracker.h" +#include +#include -class BaseRenderer; +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 { + /** @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 us::ServiceTracker + { + public: + typedef us::ServiceTracker Superclass; + AbstractAnnotationRenderer(const std::string &rendererID, const std::string &arID); -public: + /** \brief virtual destructor in order to derive from this class */ + virtual ~AbstractAnnotationRenderer(); - explicit AbstractAnnotationRenderer(const std::string& rendererID); + const std::string GetID() const; + const std::string GetRendererID() const; - /** \brief virtual destructor in order to derive from this class */ - virtual ~AbstractAnnotationRenderer(); + static const std::string US_INTERFACE_NAME; + static const std::string US_PROPKEY_ID; + static const std::string US_PROPKEY_RENDERER_ID; - virtual const std::string GetID() const = 0; - const std::string GetRendererID() const; + private: + /** \brief copy constructor */ + AbstractAnnotationRenderer(const AbstractAnnotationRenderer &); - static const std::string US_INTERFACE_NAME; - static const std::string US_PROPKEY_ID; - static const std::string US_PROPKEY_RENDERER_ID; + /** \brief assignment operator */ + AbstractAnnotationRenderer &operator=(const AbstractAnnotationRenderer &); -private: + TrackedType AddingService(const ServiceReferenceType &reference) override; - /** \brief copy constructor */ - AbstractAnnotationRenderer( const AbstractAnnotationRenderer &); + void ModifiedService(const ServiceReferenceType & /*reference*/, TrackedType tracked) override; - /** \brief assignment operator */ - AbstractAnnotationRenderer &operator=(const AbstractAnnotationRenderer &); + void RemovedService(const ServiceReferenceType & /*reference*/, TrackedType tracked) override; - OverlayServiceTracker* m_OverlayServiceTracker; + std::vector m_OverlayServices; - const std::string m_RendererID; -}; + const std::string m_RendererID; + const std::string m_ID; + }; } // namespace mitk MITK_DECLARE_SERVICE_INTERFACE(mitk::AbstractAnnotationRenderer, "org.mitk.services.AbstractAnnotationRenderer") #endif // ABSTRACTANNOTATIONRENDERER_H - - diff --git a/Modules/Core/include/mitkOverlay.h b/Modules/Core/include/mitkOverlay.h index ab81c3bdea..1bad27220e 100644 --- a/Modules/Core/include/mitkOverlay.h +++ b/Modules/Core/include/mitkOverlay.h @@ -1,450 +1,451 @@ /*=================================================================== 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 OVERLAY_H #define OVERLAY_H #include "mitkServiceInterface.h" #include "usServiceRegistration.h" #include #include #include namespace mitk { class AbstractOverlayLayouter; /** \brief Base class for all overlays */ /** This class is to be implemented in order to create overlays which are managed by the OverlayManager and can be placed by a AbstractOverlayLayouter. This class contains an internal Propertylist, and another PropertyList for each BaseRenderer. A property that is specified for a specific renderer always overrides the general internal property of the same name. AddOverlay, RemoveOverlay and UpdateOverlay methods have to be implemented.*/ class MITKCORE_EXPORT Overlay : public itk::Object { friend class AbstractOverlayLayouter; public: /** \brief Container for position and size on the display.*/ struct Bounds { itk::Point Position; itk::Point Size; }; /** \brief Base class for mapper specific rendering ressources. */ class MITKCORE_EXPORT BaseLocalStorage { public: bool IsGenerateDataRequired(mitk::BaseRenderer *renderer, mitk::Overlay *overlay); inline void UpdateGenerateDataTime() { m_LastGenerateDataTime.Modified(); } inline itk::TimeStamp &GetLastGenerateDataTime() { return m_LastGenerateDataTime; } protected: /** \brief timestamp of last update of stored data */ itk::TimeStamp m_LastGenerateDataTime; }; /** * @brief Set the property (instance of BaseProperty) with key @a propertyKey in the PropertyList * of the @a renderer (if NULL, use BaseRenderer-independent PropertyList). This is set-by-value. * * @warning Change in semantics since Aug 25th 2006. Check your usage of this method if you do * more with properties than just call SetProperty( "key", new SomeProperty("value") ). * * @sa GetProperty * @sa m_PropertyList * @sa m_MapOfPropertyLists */ void SetProperty(const std::string &propertyKey, const BaseProperty::Pointer &property); /** * @brief Replace the property (instance of BaseProperty) with key @a propertyKey in the PropertyList * of the @a renderer (if NULL, use BaseRenderer-independent PropertyList). This is set-by-reference. * * If @a renderer is @a NULL the property is set in the BaseRenderer-independent * PropertyList of this Overlay. * @sa GetProperty * @sa m_PropertyList * @sa m_MapOfPropertyLists */ void ReplaceProperty(const std::string &propertyKey, const BaseProperty::Pointer &property); /** * @brief Add the property (instance of BaseProperty) if it does * not exist (or always if \a overwrite is \a true) * with key @a propertyKey in the PropertyList * of the @a renderer (if NULL, use BaseRenderer-independent * PropertyList). This is set-by-value. * * For \a overwrite == \a false the property is \em not changed * if it already exists. For \a overwrite == \a true the method * is identical to SetProperty. * * @sa SetProperty * @sa GetProperty * @sa m_PropertyList * @sa m_MapOfPropertyLists */ void AddProperty(const std::string &propertyKey, const BaseProperty::Pointer &property, bool overwrite = false); /** * @brief Add values from another PropertyList. * * Overwrites values in m_PropertyList only when possible (i.e. when types are compatible). * If you want to allow for object type changes (replacing a "visible":BoolProperty with "visible":IntProperty, * set the @param replace. * * @param replace true: if @param pList contains a property "visible" of type ColorProperty and our m_PropertyList * also has a "visible" property of a different type (e.g. BoolProperty), change the type, i.e. replace the objects * behind the pointer. * * @sa SetProperty * @sa ReplaceProperty * @sa m_PropertyList */ void ConcatenatePropertyList(PropertyList *pList, bool replace = false); /** * @brief Get the property (instance of BaseProperty) with key @a propertyKey from the PropertyList * of the @a renderer, if available there, otherwise use the BaseRenderer-independent PropertyList. * * If @a renderer is @a NULL or the @a propertyKey cannot be found * in the PropertyList specific to @a renderer or is disabled there, the BaseRenderer-independent * PropertyList of this Overlay is queried. * @sa GetPropertyList * @sa m_PropertyList * @sa m_MapOfPropertyLists */ mitk::BaseProperty *GetProperty(const std::string &propertyKey) const; /** * @brief Get the property of type T with key @a propertyKey from the PropertyList * of the @a renderer, if available there, otherwise use the BaseRenderer-independent PropertyList. * * If @a renderer is @a NULL or the @a propertyKey cannot be found * in the PropertyList specific to @a renderer or is disabled there, the BaseRenderer-independent * PropertyList of this Overlay is queried. * @sa GetPropertyList * @sa m_PropertyList * @sa m_MapOfPropertyLists */ template bool GetProperty(itk::SmartPointer &property, const std::string &propertyKey) const { property = dynamic_cast(GetProperty(propertyKey)); return property.IsNotNull(); } /** * @brief Get the property of type T with key @a propertyKey from the PropertyList * of the @a renderer, if available there, otherwise use the BaseRenderer-independent PropertyList. * * If @a renderer is @a NULL or the @a propertyKey cannot be found * in the PropertyList specific to @a renderer or is disabled there, the BaseRenderer-independent * PropertyList of this Overlay is queried. * @sa GetPropertyList * @sa m_PropertyList * @sa m_MapOfPropertyLists */ template bool GetProperty(T *&property, const std::string &propertyKey) const { property = dynamic_cast(GetProperty(propertyKey)); return property != nullptr; } /** * @brief Convenience access method for GenericProperty properties * (T being the type of the second parameter) * @return @a true property was found */ template bool GetPropertyValue(const std::string &propertyKey, T &value) const { GenericProperty *gp = dynamic_cast *>(GetProperty(propertyKey)); if (gp != nullptr) { value = gp->GetValue(); return true; } return false; } /** * @brief Convenience access method for bool properties (instances of * BoolProperty) * @return @a true property was found */ bool GetBoolProperty(const std::string &propertyKey, bool &boolValue) const; /** * @brief Convenience access method for int properties (instances of * IntProperty) * @return @a true property was found */ bool GetIntProperty(const std::string &propertyKey, int &intValue) const; /** * @brief Convenience access method for float properties (instances of * FloatProperty) * @return @a true property was found */ bool GetFloatProperty(const std::string &propertyKey, float &floatValue) const; /** * @brief Convenience access method for string properties (instances of * StringProperty) * @return @a true property was found */ bool GetStringProperty(const std::string &propertyKey, std::string &string) const; /** * @brief Convenience method for setting int properties (instances of * IntProperty) */ void SetIntProperty(const std::string &propertyKey, int intValue); /** * @brief Convenience method for setting int properties (instances of * IntProperty) */ void SetBoolProperty(const std::string &propertyKey, bool boolValue); /** * @brief Convenience method for setting int properties (instances of * IntProperty) */ void SetFloatProperty(const std::string &propertyKey, float floatValue); /** * @brief Convenience method for setting int properties (instances of * IntProperty) */ void SetStringProperty(const std::string &propertyKey, const std::string &string); /** * @brief Convenience access method for boolean properties (instances * of BoolProperty). Return value is the value of the property. If the property is * not found, the value of @a defaultIsOn is returned. * * Thus, the return value has a different meaning than in the * GetBoolProperty method! * @sa GetBoolProperty */ bool IsOn(const std::string &propertyKey, bool defaultIsOn = true) const { GetBoolProperty(propertyKey, defaultIsOn); return defaultIsOn; } /** * @brief Convenience access method for accessing the name of an object (instance of * StringProperty with property-key "name") * @return @a true property was found */ bool GetName(std::string &nodeName, const std::string &propertyKey = "name") const; /** * @brief Extra convenience access method for accessing the name of an object (instance of * StringProperty with property-key "name"). * * This method does not take the renderer specific * propertylists into account, because the name of an object should never be renderer specific. * @returns a std::string with the name of the object (content of "name" Property). * If there is no "name" Property, an empty string will be returned. */ virtual std::string GetName() const; /** * @brief Extra convenience access method to set the name of an object. * * The name will be stored in the non-renderer-specific PropertyList in a StringProperty named "name". */ virtual void SetName(const std::string &name); /** * @brief Convenience access method for color properties (instances of * ColorProperty) * @return @a true property was found */ bool GetColor(float rgb[], const std::string &propertyKey = "color") const; /** * @brief Convenience method for setting color properties (instances of * ColorProperty) */ void SetColor(const mitk::Color &color, const std::string &propertyKey = "color"); /** * @brief Convenience method for setting color properties (instances of * ColorProperty) */ void SetColor(float red, float green, float blue, const std::string &propertyKey = "color"); /** * @brief Convenience method for setting color properties (instances of * ColorProperty) */ void SetColor(const float rgb[], const std::string &propertyKey = "color"); /** * @brief Convenience access method for opacity properties (instances of * FloatProperty) * @return @a true property was found */ bool GetOpacity(float &opacity, const std::string &propertyKey = "opacity") const; /** * @brief Convenience method for setting opacity properties (instances of * FloatProperty) */ void SetOpacity(float opacity, const std::string &propertyKey = "opacity"); void SetText(std::string text); std::string GetText() const; void SetFontSize(int fontSize); int GetFontSize() const; /** * @brief Convenience access method for visibility properties (instances * of BoolProperty with property-key "visible") * @return @a true property was found * @sa IsVisible */ bool GetVisibility(bool &visible, const std::string &propertyKey = "visible") const; /** * @brief Convenience access method for visibility properties (instances * of BoolProperty). Return value is the visibility. Default is * visible==true, i.e., true is returned even if the property (@a * propertyKey) is not found. * * Thus, the return value has a different meaning than in the * GetVisibility method! * @sa GetVisibility * @sa IsOn */ bool IsVisible(const std::string &propertyKey = "visible", bool defaultIsOn = true) const; /** * @brief Convenience method for setting visibility properties (instances * of BoolProperty) * @param visible If set to true, the data will be rendered. If false, the render will skip this data. * @param renderer Specify a renderer if the visibility shall be specific to a renderer * @param propertykey Can be used to specify a user defined name of the visibility propery. */ void SetVisibility(bool visible, const std::string &propertyKey = "visible"); /** \brief Adds the overlay to the specified renderer. Update Overlay should be called soon in order to apply all * properties*/ virtual void AddToBaseRenderer(BaseRenderer *renderer) = 0; /** \brief Adds the overlay to the specified renderer. Update Overlay should be called soon in order to apply all * properties*/ virtual void AddToRenderer(BaseRenderer *renderer, vtkRenderer *vtkrenderer) = 0; /** \brief Removes the overlay from the specified renderer. It is not visible anymore then.*/ virtual void RemoveFromBaseRenderer(BaseRenderer *renderer) = 0; /** \brief Removes the overlay from the specified renderer. It is not visible anymore then.*/ virtual void RemoveFromRenderer(BaseRenderer *renderer, vtkRenderer *vtkrenderer) = 0; /** \brief Applies all properties and should be called before the rendering procedure.*/ virtual void Update(BaseRenderer *renderer) = 0; /** \brief Returns position and size of the overlay on the display.*/ virtual Bounds GetBoundsOnDisplay(BaseRenderer *renderer) const; /** \brief Sets position and size of the overlay on the display.*/ virtual void SetBoundsOnDisplay(BaseRenderer *renderer, const Bounds &); void SetForceInForeground(bool forceForeground); bool IsForceInForeground() const; PropertyList *GetPropertyList() const; /** *\brief Returns the id that this device is registered with. The id will only be valid, if the * Overlay has been registered using RegisterAsMicroservice(). */ std::string GetMicroserviceID(); /** *\brief These Constants are used in conjunction with Microservices */ static const std::string US_INTERFACE_NAME; - static const std::string US_PROPKEY_DEVICENAME; + static const std::string US_PROPKEY_OVERLAYNAME; static const std::string US_PROPKEY_ID; - static const std::string US_PROPKEY_ISACTIVE; // NOT IMPLEMENTED YET! + static const std::string US_PROPKEY_RENDERER_ID; + static const std::string US_PROPKEY_AR_ID; /** *\brief Registers this object as a Microservice, making it available to every module and/or plugin. * To unregister, call UnregisterMicroservice(). */ virtual void RegisterAsMicroservice(); /** *\brief Registers this object as a Microservice, making it available to every module and/or plugin. */ virtual void UnRegisterMicroservice(); mitkClassMacroItkParent(Overlay, itk::Object); protected: /** \brief explicit constructor which disallows implicit conversions */ Overlay(); /** \brief virtual destructor in order to derive from this class */ virtual ~Overlay(); /** * @brief BaseRenderer-independent PropertyList * * Properties herein can be overwritten specifically for each BaseRenderer * by the BaseRenderer-specific properties defined in m_MapOfPropertyLists. */ PropertyList::Pointer m_PropertyList; /** * @brief Timestamp of the last change of m_Data */ itk::TimeStamp m_DataReferenceChangedTime; - void SetUSProperty(const std::string& propertyKey, us::Any value); + void SetUSProperty(const std::string &propertyKey, us::Any value); private: /** \brief render this overlay on a foreground renderer */ bool m_ForceInForeground; /** \brief copy constructor */ Overlay(const Overlay &); /** \brief assignment operator */ Overlay &operator=(const Overlay &); /** \brief Reference to the layouter in which this overlay is managed. */ AbstractOverlayLayouter *m_LayoutedBy; private: us::ServiceRegistration m_ServiceRegistration; }; } // namespace mitk MITK_DECLARE_SERVICE_INTERFACE(mitk::Overlay, "org.mitk.services.Overlay") #endif // OVERLAY_H diff --git a/Modules/Core/include/mitkOverlayServiceTracker.h b/Modules/Core/include/mitkOverlayServiceTracker.h index 2df6ab13d6..07774f8550 100644 --- a/Modules/Core/include/mitkOverlayServiceTracker.h +++ b/Modules/Core/include/mitkOverlayServiceTracker.h @@ -1,46 +1,44 @@ /*=================================================================== 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 MITKOVERLAYSERVICETRACKER_H #define MITKOVERLAYSERVICETRACKER_H -#include "usServiceTracker.h" #include "mitkOverlay.h" +#include "usServiceTracker.h" -namespace mitk { - -class OverlayServiceTracker : public us::ServiceTracker +namespace mitk { + class OverlayServiceTracker : public us::ServiceTracker + { + public: + OverlayServiceTracker(const us::LDAPFilter &filter); -public: - - OverlayServiceTracker(const us::LDAPFilter &filter); - -private: - - typedef us::ServiceTracker Superclass; + private: + typedef us::ServiceTracker Superclass; - TrackedType AddingService(const ServiceReferenceType &reference) override; + TrackedType AddingService(const ServiceReferenceType &reference) override; - void RemovedService(const ServiceReferenceType& /*reference*/, TrackedType tracked) override; + void ModifiedService(const ServiceReferenceType & /*reference*/, TrackedType tracked) override; - std::vector m_OverlayServices; + void RemovedService(const ServiceReferenceType & /*reference*/, TrackedType tracked) override; -}; + std::vector m_OverlayServices; + }; } // end of namespace mitk #endif // MITKOVERLAYSERVICETRACKER_H diff --git a/Modules/Core/src/Rendering/mitkAbstractAnnotationRenderer.cpp b/Modules/Core/src/Rendering/mitkAbstractAnnotationRenderer.cpp index 656a8dfd6c..86b76f6cbd 100644 --- a/Modules/Core/src/Rendering/mitkAbstractAnnotationRenderer.cpp +++ b/Modules/Core/src/Rendering/mitkAbstractAnnotationRenderer.cpp @@ -1,48 +1,62 @@ /*=================================================================== 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 #include "usGetModuleContext.h" -#include "mitkOverlay.h" +#include namespace mitk { - -const std::string AbstractAnnotationRenderer::US_INTERFACE_NAME = "org.mitk.services.AbstractAnnotationRenderer"; -const std::string AbstractAnnotationRenderer::US_PROPKEY_ID = US_INTERFACE_NAME + ".id"; -const std::string AbstractAnnotationRenderer::US_PROPKEY_RENDERER_ID = US_INTERFACE_NAME + ".rendererId"; - -AbstractAnnotationRenderer::AbstractAnnotationRenderer(const std::string& rendererID) - :m_RendererID(rendererID) -{ - std::string specificRenderer = "(rendererName=" + rendererID +")"; - std::string classInteractionEventObserver = "(" + us::ServiceConstants::OBJECTCLASS() + "=" + ")"; - us::LDAPFilter filter( "(&(|"+ specificRenderer + ")"+classInteractionEventObserver+")" ); - - m_OverlayServiceTracker = new OverlayServiceTracker(filter); -} - -AbstractAnnotationRenderer::~AbstractAnnotationRenderer() -{ -} - -const std::string AbstractAnnotationRenderer::GetRendererID() const -{ - return m_RendererID; -} - + const std::string AbstractAnnotationRenderer::US_INTERFACE_NAME = "org.mitk.services.AbstractAnnotationRenderer"; + const std::string AbstractAnnotationRenderer::US_PROPKEY_ID = US_INTERFACE_NAME + ".id"; + const std::string AbstractAnnotationRenderer::US_PROPKEY_RENDERER_ID = US_INTERFACE_NAME + ".rendererId"; + + AbstractAnnotationRenderer::AbstractAnnotationRenderer(const std::string &rendererID, const std::string &arID) + : Superclass(us::GetModuleContext(), + us::LDAPFilter("(&(" + Overlay::US_PROPKEY_RENDERER_ID + "=" + rendererID + ")(" + + Overlay::US_PROPKEY_AR_ID + "=" + arID + "))")), + m_RendererID(rendererID), + m_ID(arID) + { + } + + AbstractAnnotationRenderer::~AbstractAnnotationRenderer() {} + const std::string AbstractAnnotationRenderer::GetRendererID() const { return m_RendererID; } + const std::string AbstractAnnotationRenderer::GetID() const { return m_ID; } + AbstractAnnotationRenderer::TrackedType AbstractAnnotationRenderer::AddingService( + const AbstractAnnotationRenderer::ServiceReferenceType &reference) + { + Overlay *overlay = Superclass::AddingService(reference); + if (overlay) + { + m_OverlayServices.push_back(overlay); + } + return overlay; + } + + void AbstractAnnotationRenderer::ModifiedService(const AbstractAnnotationRenderer::ServiceReferenceType &, + AbstractAnnotationRenderer::TrackedType /*tracked*/) + { + } + + void AbstractAnnotationRenderer::RemovedService(const AbstractAnnotationRenderer::ServiceReferenceType &, + AbstractAnnotationRenderer::TrackedType tracked) + { + // tracked->RemoveFromBaseRenderer() TODO19786 + m_OverlayServices.erase(std::remove(m_OverlayServices.begin(), m_OverlayServices.end(), tracked), + m_OverlayServices.end()); + } } diff --git a/Modules/Core/src/Rendering/mitkOverlay.cpp b/Modules/Core/src/Rendering/mitkOverlay.cpp index a56467609c..2a15cbbdf0 100644 --- a/Modules/Core/src/Rendering/mitkOverlay.cpp +++ b/Modules/Core/src/Rendering/mitkOverlay.cpp @@ -1,316 +1,315 @@ /*=================================================================== 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 "mitkOverlay.h" #include "usGetModuleContext.h" const std::string mitk::Overlay::US_INTERFACE_NAME = "org.mitk.services.Overlay"; -const std::string mitk::Overlay::US_PROPKEY_DEVICENAME = US_INTERFACE_NAME + ".devicename"; +const std::string mitk::Overlay::US_PROPKEY_OVERLAYNAME = US_INTERFACE_NAME + ".name"; const std::string mitk::Overlay::US_PROPKEY_ID = US_INTERFACE_NAME + ".id"; -const std::string mitk::Overlay::US_PROPKEY_ISACTIVE = US_INTERFACE_NAME + ".isActive"; +const std::string mitk::Overlay::US_PROPKEY_RENDERER_ID = US_INTERFACE_NAME + ".rendererId"; +const std::string mitk::Overlay::US_PROPKEY_AR_ID = US_INTERFACE_NAME + ".arId"; mitk::Overlay::Overlay() : m_LayoutedBy(nullptr) { m_PropertyList = mitk::PropertyList::New(); this->SetName(this->GetNameOfClass()); this->SetVisibility(true); this->SetOpacity(1.0); } mitk::Overlay::~Overlay() { this->UnRegisterMicroservice(); } void mitk::Overlay::SetUSProperty(const std::string & /*propertyKey*/, us::Any /*value*/) { if (this->m_ServiceRegistration) { - // m_ServiceRegistration.GetReference(). //TODO19786 + // m_ServiceRegistration.SetProperties( //TODO19786 } } void mitk::Overlay::SetProperty(const std::string &propertyKey, const BaseProperty::Pointer &propertyValue) { this->m_PropertyList->SetProperty(propertyKey, propertyValue); - this->m_PropertyList->Modified(); } void mitk::Overlay::ReplaceProperty(const std::string &propertyKey, const BaseProperty::Pointer &propertyValue) { this->m_PropertyList->ReplaceProperty(propertyKey, propertyValue); - this->m_PropertyList->Modified(); } void mitk::Overlay::AddProperty(const std::string &propertyKey, const BaseProperty::Pointer &propertyValue, bool overwrite) { if ((overwrite) || (GetProperty(propertyKey) == NULL)) { SetProperty(propertyKey, propertyValue); } } void mitk::Overlay::ConcatenatePropertyList(PropertyList *pList, bool replace) { m_PropertyList->ConcatenatePropertyList(pList, replace); } mitk::BaseProperty *mitk::Overlay::GetProperty(const std::string &propertyKey) const { mitk::BaseProperty::Pointer property = m_PropertyList->GetProperty(propertyKey); if (property.IsNotNull()) return property; // only to satisfy compiler! return NULL; } bool mitk::Overlay::GetBoolProperty(const std::string &propertyKey, bool &boolValue) const { mitk::BoolProperty::Pointer boolprop = dynamic_cast(GetProperty(propertyKey)); if (boolprop.IsNull()) return false; boolValue = boolprop->GetValue(); return true; } bool mitk::Overlay::GetIntProperty(const std::string &propertyKey, int &intValue) const { mitk::IntProperty::Pointer intprop = dynamic_cast(GetProperty(propertyKey)); if (intprop.IsNull()) return false; intValue = intprop->GetValue(); return true; } bool mitk::Overlay::GetFloatProperty(const std::string &propertyKey, float &floatValue) const { mitk::FloatProperty::Pointer floatprop = dynamic_cast(GetProperty(propertyKey)); if (floatprop.IsNull()) return false; floatValue = floatprop->GetValue(); return true; } bool mitk::Overlay::GetStringProperty(const std::string &propertyKey, std::string &string) const { mitk::StringProperty::Pointer stringProp = dynamic_cast(GetProperty(propertyKey)); if (stringProp.IsNull()) { return false; } else { // memcpy((void*)string, stringProp->GetValue(), strlen(stringProp->GetValue()) + 1 ); // looks dangerous string = stringProp->GetValue(); return true; } } void mitk::Overlay::SetIntProperty(const std::string &propertyKey, int intValue) { this->m_PropertyList->SetProperty(propertyKey, mitk::IntProperty::New(intValue)); Modified(); } void mitk::Overlay::SetBoolProperty(const std::string &propertyKey, bool boolValue) { this->m_PropertyList->SetProperty(propertyKey, mitk::BoolProperty::New(boolValue)); Modified(); } void mitk::Overlay::SetFloatProperty(const std::string &propertyKey, float floatValue) { this->m_PropertyList->SetProperty(propertyKey, mitk::FloatProperty::New(floatValue)); Modified(); } void mitk::Overlay::SetStringProperty(const std::string &propertyKey, const std::string &stringValue) { this->m_PropertyList->SetProperty(propertyKey, mitk::StringProperty::New(stringValue)); Modified(); } std::string mitk::Overlay::GetName() const { mitk::StringProperty *sp = dynamic_cast(this->GetProperty("name")); if (sp == NULL) return ""; return sp->GetValue(); } void mitk::Overlay::SetName(const std::string &name) { this->SetStringProperty("name", name); } bool mitk::Overlay::GetName(std::string &nodeName, const std::string &propertyKey) const { return GetStringProperty(propertyKey, nodeName); } void mitk::Overlay::SetText(std::string text) { SetStringProperty("Text", text.c_str()); } std::string mitk::Overlay::GetText() const { std::string text; GetStringProperty("Text", text); return text; } void mitk::Overlay::SetFontSize(int fontSize) { SetIntProperty("FontSize", fontSize); } int mitk::Overlay::GetFontSize() const { int fontSize = 1; GetIntProperty("FontSize", fontSize); return fontSize; } bool mitk::Overlay::GetVisibility(bool &visible, const std::string &propertyKey) const { return GetBoolProperty(propertyKey, visible); } bool mitk::Overlay::IsVisible(const std::string &propertyKey, bool defaultIsOn) const { return IsOn(propertyKey, defaultIsOn); } bool mitk::Overlay::GetColor(float rgb[], const std::string &propertyKey) const { mitk::ColorProperty::Pointer colorprop = dynamic_cast(GetProperty(propertyKey)); if (colorprop.IsNull()) return false; memcpy(rgb, colorprop->GetColor().GetDataPointer(), 3 * sizeof(float)); return true; } void mitk::Overlay::SetColor(const mitk::Color &color, const std::string &propertyKey) { mitk::ColorProperty::Pointer prop; prop = mitk::ColorProperty::New(color); this->m_PropertyList->SetProperty(propertyKey, prop); } void mitk::Overlay::SetColor(float red, float green, float blue, const std::string &propertyKey) { float color[3]; color[0] = red; color[1] = green; color[2] = blue; SetColor(color, propertyKey); } void mitk::Overlay::SetColor(const float rgb[], const std::string &propertyKey) { mitk::ColorProperty::Pointer prop; prop = mitk::ColorProperty::New(rgb); this->m_PropertyList->SetProperty(propertyKey, prop); } bool mitk::Overlay::GetOpacity(float &opacity, const std::string &propertyKey) const { mitk::FloatProperty::Pointer opacityprop = dynamic_cast(GetProperty(propertyKey)); if (opacityprop.IsNull()) return false; opacity = opacityprop->GetValue(); return true; } void mitk::Overlay::SetOpacity(float opacity, const std::string &propertyKey) { mitk::FloatProperty::Pointer prop; prop = mitk::FloatProperty::New(opacity); this->m_PropertyList->SetProperty(propertyKey, prop); } void mitk::Overlay::SetVisibility(bool visible, const std::string &propertyKey) { mitk::BoolProperty::Pointer prop; prop = mitk::BoolProperty::New(visible); this->m_PropertyList->SetProperty(propertyKey, prop); } bool mitk::Overlay::BaseLocalStorage::IsGenerateDataRequired(mitk::BaseRenderer *renderer, mitk::Overlay *overlay) { if (m_LastGenerateDataTime < overlay->GetMTime()) return true; if (m_LastGenerateDataTime < overlay->GetPropertyList()->GetMTime()) return true; if (renderer && m_LastGenerateDataTime < renderer->GetTimeStepUpdateTime()) return true; return false; } mitk::Overlay::Bounds mitk::Overlay::GetBoundsOnDisplay(mitk::BaseRenderer *) const { mitk::Overlay::Bounds bounds; bounds.Position[0] = bounds.Position[1] = bounds.Size[0] = bounds.Size[1] = 0; return bounds; } void mitk::Overlay::SetBoundsOnDisplay(mitk::BaseRenderer *, const mitk::Overlay::Bounds &) { } void mitk::Overlay::SetForceInForeground(bool forceForeground) { m_ForceInForeground = forceForeground; } bool mitk::Overlay::IsForceInForeground() const { return m_ForceInForeground; } mitk::PropertyList *mitk::Overlay::GetPropertyList() const { return m_PropertyList; } void mitk::Overlay::RegisterAsMicroservice() { // Get Context us::ModuleContext *context = us::GetModuleContext(); // Define ServiceProps us::ServiceProperties props; mitk::UIDGenerator uidGen = mitk::UIDGenerator("org.mitk.services.Overlay.id_", 16); props[US_PROPKEY_ID] = uidGen.GetUID(); m_ServiceRegistration = context->RegisterService(this, props); } void mitk::Overlay::UnRegisterMicroservice() { if (m_ServiceRegistration != NULL) m_ServiceRegistration.Unregister(); m_ServiceRegistration = 0; } diff --git a/Modules/Core/src/Rendering/mitkOverlayServiceTracker.cpp b/Modules/Core/src/Rendering/mitkOverlayServiceTracker.cpp index 1da28ad262..7f0de248e5 100644 --- a/Modules/Core/src/Rendering/mitkOverlayServiceTracker.cpp +++ b/Modules/Core/src/Rendering/mitkOverlayServiceTracker.cpp @@ -1,47 +1,53 @@ /*=================================================================== 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 "mitkOverlayServiceTracker.h" // Micro Services #include -namespace mitk { - -OverlayServiceTracker::OverlayServiceTracker(const us::LDAPFilter& filter) - : Superclass(us::GetModuleContext(),filter) +namespace mitk { -} + OverlayServiceTracker::OverlayServiceTracker(const us::LDAPFilter &filter) + : Superclass(us::GetModuleContext(), filter) + { + } -OverlayServiceTracker::TrackedType OverlayServiceTracker::AddingService(const OverlayServiceTracker::ServiceReferenceType &reference) -{ - Overlay* overlay = Superclass::AddingService(reference); - if (overlay) + OverlayServiceTracker::TrackedType OverlayServiceTracker::AddingService( + const OverlayServiceTracker::ServiceReferenceType &reference) { - m_OverlayServices.push_back(overlay); + Overlay *overlay = Superclass::AddingService(reference); + if (overlay) + { + m_OverlayServices.push_back(overlay); + } + return overlay; } - return overlay; -} -void OverlayServiceTracker::RemovedService(const OverlayServiceTracker::ServiceReferenceType &, OverlayServiceTracker::TrackedType tracked) -{ -// tracked->RemoveFromBaseRenderer() TODO19786 - m_OverlayServices.erase(std::remove(m_OverlayServices.begin(), - m_OverlayServices.end(), tracked), - m_OverlayServices.end()); -} + void OverlayServiceTracker::ModifiedService(const OverlayServiceTracker::ServiceReferenceType &, + OverlayServiceTracker::TrackedType /*tracked*/) + { + } + + void OverlayServiceTracker::RemovedService(const OverlayServiceTracker::ServiceReferenceType &, + OverlayServiceTracker::TrackedType tracked) + { + // tracked->RemoveFromBaseRenderer() TODO19786 + m_OverlayServices.erase(std::remove(m_OverlayServices.begin(), m_OverlayServices.end(), tracked), + m_OverlayServices.end()); + } } // end of namespace mitk diff --git a/Modules/Overlays/include/mitkAnnotationPlacer.h b/Modules/Overlays/include/mitkAnnotationPlacer.h index 6eeaf6dbad..71c3cf375d 100644 --- a/Modules/Overlays/include/mitkAnnotationPlacer.h +++ b/Modules/Overlays/include/mitkAnnotationPlacer.h @@ -1,51 +1,49 @@ /*=================================================================== 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 "mitkAbstractAnnotationRenderer.h" #include "mitkOverlay.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(); - const std::string GetID() const; - static AnnotationPlacer *GetAnnotationRenderer(const std::string &rendererID); private: - using AbstractAnnotationRenderer::AbstractAnnotationRenderer; + AnnotationPlacer(const std::string &rendererId); 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 f5eddcab6a..8f873baea2 100644 --- a/Modules/Overlays/include/mitkOverlayLayouter2D.h +++ b/Modules/Overlays/include/mitkOverlayLayouter2D.h @@ -1,50 +1,50 @@ /*=================================================================== 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(); const std::string GetID() const; static OverlayLayouter2D *GetAnnotationRenderer(const std::string &rendererID); - static const std::string ANNOTATIONRENDERER_ID; - private: - using AbstractAnnotationRenderer::AbstractAnnotationRenderer; + OverlayLayouter2D(const std::string &rendererId); + + static const std::string ANNOTATIONRENDERER_ID; }; } // namespace mitk #endif // OVERLAYLAYOUTER2D_H diff --git a/Modules/Overlays/src/mitkAnnotationPlacer.cpp b/Modules/Overlays/src/mitkAnnotationPlacer.cpp index a45c593f12..fd5ff305fc 100644 --- a/Modules/Overlays/src/mitkAnnotationPlacer.cpp +++ b/Modules/Overlays/src/mitkAnnotationPlacer.cpp @@ -1,44 +1,47 @@ /*=================================================================== 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 "mitkAnnotationService.h" #include "mitkOverlay2DLayouter.h" #include namespace mitk { - const std::string mitk::AnnotationPlacer::ANNOTATIONRENDERER_ID = "AnnotationPlacer"; + const std::string AnnotationPlacer::ANNOTATIONRENDERER_ID = "AnnotationPlacer"; + AnnotationPlacer::AnnotationPlacer(const std::string &rendererId) + : AbstractAnnotationRenderer(rendererId, AnnotationPlacer::ANNOTATIONRENDERER_ID) + { + } AnnotationPlacer::~AnnotationPlacer() {} - const std::string AnnotationPlacer::GetID() const { return ANNOTATIONRENDERER_ID; } AnnotationPlacer *AnnotationPlacer::GetAnnotationRenderer(const std::string &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 bc1c630a95..7ecd1c6931 100644 --- a/Modules/Overlays/src/mitkOverlayLayouter2D.cpp +++ b/Modules/Overlays/src/mitkOverlayLayouter2D.cpp @@ -1,44 +1,49 @@ /*=================================================================== 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 "mitkAnnotationService.h" #include "mitkOverlay2DLayouter.h" #include namespace mitk { - const std::string mitk::OverlayLayouter2D::ANNOTATIONRENDERER_ID = "OverlayLayouter2D"; + const std::string OverlayLayouter2D::ANNOTATIONRENDERER_ID = "OverlayLayouter2D"; + + OverlayLayouter2D::OverlayLayouter2D(const std::string &rendererId) + : AbstractAnnotationRenderer(rendererId, OverlayLayouter2D::ANNOTATIONRENDERER_ID) + { + } OverlayLayouter2D::~OverlayLayouter2D() {} const std::string OverlayLayouter2D::GetID() const { 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; } }