diff --git a/Core/Code/Rendering/mitkOverlay.cpp b/Core/Code/Rendering/mitkOverlay.cpp index af37cfa631..cfc221992f 100644 --- a/Core/Code/Rendering/mitkOverlay.cpp +++ b/Core/Code/Rendering/mitkOverlay.cpp @@ -1,305 +1,309 @@ /*=================================================================== 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" mitk::Overlay::Overlay() : m_LayoutedBy(NULL) { m_PropertyList = mitk::PropertyList::New(); } mitk::Overlay::~Overlay() { } void mitk::Overlay::SetProperty(const std::string& propertyKey, const BaseProperty::Pointer& propertyValue, const mitk::BaseRenderer* renderer) { GetPropertyList(renderer)->SetProperty(propertyKey, propertyValue); this->Modified(); } void mitk::Overlay::ReplaceProperty(const std::string& propertyKey, const BaseProperty::Pointer& propertyValue, const mitk::BaseRenderer* renderer) { GetPropertyList(renderer)->ReplaceProperty(propertyKey, propertyValue); } void mitk::Overlay::AddProperty(const std::string& propertyKey, const BaseProperty::Pointer& propertyValue, const mitk::BaseRenderer* renderer, bool overwrite) { if((overwrite) || (GetProperty(propertyKey, renderer) == NULL)) { SetProperty(propertyKey, propertyValue, renderer); } } void mitk::Overlay::ConcatenatePropertyList(PropertyList *pList, bool replace) { m_PropertyList->ConcatenatePropertyList(pList, replace); } mitk::BaseProperty* mitk::Overlay::GetProperty(const std::string& propertyKey, const mitk::BaseRenderer* renderer) const { //renderer specified? if (renderer) { std::map::const_iterator it; //check for the renderer specific property it=m_MapOfPropertyLists.find(renderer); if(it!=m_MapOfPropertyLists.end()) //found { mitk::BaseProperty::Pointer property; property=it->second->GetProperty(propertyKey); if(property.IsNotNull())//found an enabled property in the render specific list return property; else //found a renderer specific list, but not the desired property return m_PropertyList->GetProperty(propertyKey); //return renderer unspecific property } else //didn't find the property list of the given renderer { //return the renderer unspecific property if there is one return m_PropertyList->GetProperty(propertyKey); } } else //no specific renderer given; use the renderer independent one { mitk::BaseProperty::Pointer property; 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, mitk::BaseRenderer* renderer) const { mitk::BoolProperty::Pointer boolprop = dynamic_cast(GetProperty(propertyKey, renderer)); if(boolprop.IsNull()) return false; boolValue = boolprop->GetValue(); return true; } bool mitk::Overlay::GetIntProperty(const std::string& propertyKey, int &intValue, mitk::BaseRenderer* renderer) const { mitk::IntProperty::Pointer intprop = dynamic_cast(GetProperty(propertyKey, renderer)); if(intprop.IsNull()) return false; intValue = intprop->GetValue(); return true; } bool mitk::Overlay::GetFloatProperty(const std::string& propertyKey, float &floatValue, mitk::BaseRenderer* renderer) const { mitk::FloatProperty::Pointer floatprop = dynamic_cast(GetProperty(propertyKey, renderer)); if(floatprop.IsNull()) return false; floatValue = floatprop->GetValue(); return true; } bool mitk::Overlay::GetStringProperty(const std::string& propertyKey, std::string& string, mitk::BaseRenderer* renderer) const { mitk::StringProperty::Pointer stringProp = dynamic_cast(GetProperty(propertyKey, renderer)); 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, mitk::BaseRenderer* renderer) { GetPropertyList(renderer)->SetProperty(propertyKey, mitk::IntProperty::New(intValue)); + Modified(); } void mitk::Overlay::SetBoolProperty( const std::string& propertyKey, bool boolValue, mitk::BaseRenderer* renderer/*=NULL*/ ) { GetPropertyList(renderer)->SetProperty(propertyKey, mitk::BoolProperty::New(boolValue)); + Modified(); } void mitk::Overlay::SetFloatProperty( const std::string& propertyKey, float floatValue, mitk::BaseRenderer* renderer/*=NULL*/ ) { GetPropertyList(renderer)->SetProperty(propertyKey, mitk::FloatProperty::New(floatValue)); + Modified(); } void mitk::Overlay::SetStringProperty( const std::string& propertyKey, const std::string& stringValue, mitk::BaseRenderer* renderer/*=NULL*/ ) { GetPropertyList(renderer)->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, mitk::BaseRenderer* renderer, const std::string& propertyKey) const { return GetStringProperty(propertyKey, nodeName, renderer); } void mitk::Overlay::SetText(std::string text) { SetStringProperty("Overlay.Text", text.c_str()); } std::string mitk::Overlay::GetText() const { std::string text; GetPropertyList()->GetStringProperty("Overlay.Text", text); return text; } void mitk::Overlay::SetFontSize(int fontSize) { SetIntProperty("Overlay.FontSize",fontSize); } int mitk::Overlay::GetFontSize() const { int fontSize = 1; GetPropertyList()->GetIntProperty("Overlay.FontSize", fontSize); return fontSize; } bool mitk::Overlay::GetVisibility(bool& visible, mitk::BaseRenderer* renderer, const std::string& propertyKey) const { return GetBoolProperty(propertyKey, visible, renderer); } bool mitk::Overlay::IsVisible(mitk::BaseRenderer* renderer, const std::string& propertyKey, bool defaultIsOn) const { return IsOn(propertyKey, renderer, defaultIsOn); } bool mitk::Overlay::GetColor(float rgb[], mitk::BaseRenderer* renderer, const std::string& propertyKey) const { mitk::ColorProperty::Pointer colorprop = dynamic_cast(GetProperty(propertyKey, renderer)); if(colorprop.IsNull()) return false; memcpy(rgb, colorprop->GetColor().GetDataPointer(), 3*sizeof(float)); return true; } void mitk::Overlay::SetColor(const mitk::Color &color, mitk::BaseRenderer* renderer, const std::string& propertyKey) { mitk::ColorProperty::Pointer prop; prop = mitk::ColorProperty::New(color); GetPropertyList(renderer)->SetProperty(propertyKey, prop); } void mitk::Overlay::SetColor(float red, float green, float blue, mitk::BaseRenderer* renderer, const std::string& propertyKey) { float color[3]; color[0]=red; color[1]=green; color[2]=blue; SetColor(color, renderer, propertyKey); } void mitk::Overlay::SetColor(const float rgb[], mitk::BaseRenderer* renderer, const std::string& propertyKey) { mitk::ColorProperty::Pointer prop; prop = mitk::ColorProperty::New(rgb); GetPropertyList(renderer)->SetProperty(propertyKey, prop); } bool mitk::Overlay::GetOpacity(float &opacity, mitk::BaseRenderer* renderer, const std::string& propertyKey) const { mitk::FloatProperty::Pointer opacityprop = dynamic_cast(GetProperty(propertyKey, renderer)); if(opacityprop.IsNull()) return false; opacity=opacityprop->GetValue(); return true; } void mitk::Overlay::SetOpacity(float opacity, mitk::BaseRenderer* renderer, const std::string& propertyKey) { mitk::FloatProperty::Pointer prop; prop = mitk::FloatProperty::New(opacity); GetPropertyList(renderer)->SetProperty(propertyKey, prop); } void mitk::Overlay::SetVisibility(bool visible, mitk::BaseRenderer *renderer, const std::string& propertyKey) { mitk::BoolProperty::Pointer prop; prop = mitk::BoolProperty::New(visible); GetPropertyList(renderer)->SetProperty(propertyKey, prop); } mitk::PropertyList* mitk::Overlay::GetPropertyList(const mitk::BaseRenderer* renderer) const { if(renderer==NULL) return m_PropertyList; mitk::PropertyList::Pointer & propertyList = m_MapOfPropertyLists[renderer]; if(propertyList.IsNull()) propertyList = mitk::PropertyList::New(); assert(m_MapOfPropertyLists[renderer].IsNotNull()); return propertyList; } bool mitk::Overlay::BaseLocalStorage::IsGenerateDataRequired(mitk::BaseRenderer *renderer, mitk::Overlay *overlay) { if( m_LastGenerateDataTime < overlay -> 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&) { } diff --git a/Core/Code/Rendering/mitkVtkOverlay.cpp b/Core/Code/Rendering/mitkVtkOverlay.cpp index 928ca768f0..167d372b80 100644 --- a/Core/Code/Rendering/mitkVtkOverlay.cpp +++ b/Core/Code/Rendering/mitkVtkOverlay.cpp @@ -1,72 +1,73 @@ /*=================================================================== 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 "mitkVtkOverlay.h" #include #include mitk::VtkOverlay::VtkOverlay() { } mitk::VtkOverlay::~VtkOverlay() { } void mitk::VtkOverlay::Update(mitk::BaseRenderer *renderer) { vtkSmartPointer prop = GetVtkProp(renderer); if(!IsVisible(renderer)) { prop->SetVisibility(false); return; } else { prop->SetVisibility(true); UpdateVtkOverlay(renderer); } } void mitk::VtkOverlay::AddToBaseRenderer(mitk::BaseRenderer *renderer) { if(!renderer || !renderer->GetVtkRenderer()) return; Update(renderer); vtkSmartPointer vtkProp = GetVtkProp(renderer); if(renderer && renderer->GetVtkRenderer() && !renderer->GetVtkRenderer()->HasViewProp(vtkProp)) { renderer->GetVtkRenderer()->AddViewProp(vtkProp); } } void mitk::VtkOverlay::RemoveFromBaseRenderer(mitk::BaseRenderer *renderer) { if(!renderer || !renderer->GetVtkRenderer()) return; vtkSmartPointer vtkProp = GetVtkProp(renderer); if(renderer->GetVtkRenderer()->HasViewProp(vtkProp)) { renderer->GetVtkRenderer()->RemoveViewProp(vtkProp); } } void mitk::VtkOverlay::Paint( BaseRenderer* renderer ) { + GetVtkProp( renderer )->RenderOpaqueGeometry(renderer->GetVtkRenderer() ); GetVtkProp( renderer )->RenderOverlay( renderer->GetVtkRenderer() ); } diff --git a/Core/Code/Rendering/mitkVtkOverlay2D.h b/Core/Code/Rendering/mitkVtkOverlay2D.h index bc824286e5..eb1778a10a 100644 --- a/Core/Code/Rendering/mitkVtkOverlay2D.h +++ b/Core/Code/Rendering/mitkVtkOverlay2D.h @@ -1,74 +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 VTKOVERLAY2D_H #define VTKOVERLAY2D_H #include #include "mitkVtkOverlay.h" #include class vtkActor2D; class vtkProperty2D; namespace mitk { /** * @brief The VtkOverlay2D class is the basis for all VTK based Overlays which create * a vtkActor2D element that will be drawn on the renderer. */ class MITK_CORE_EXPORT VtkOverlay2D : public VtkOverlay { public: mitkClassMacro(VtkOverlay2D, VtkOverlay); virtual Overlay::Bounds GetBoundsOnDisplay(BaseRenderer *renderer) const; virtual void SetBoundsOnDisplay(BaseRenderer *renderer, const Bounds& bounds); void SetPosition2D(const Point2D& position2D, mitk::BaseRenderer* renderer = NULL); Point2D GetPosition2D(mitk::BaseRenderer* renderer = NULL) const; void SetOffsetVector(const Point2D& OffsetVector, BaseRenderer* renderer = NULL); Point2D GetOffsetVector(mitk::BaseRenderer* renderer = NULL) const; protected: - vtkProp* GetVtkProp(BaseRenderer *renderer) const; + virtual vtkProp* GetVtkProp(BaseRenderer *renderer) const; virtual void UpdateVtkOverlay(BaseRenderer *renderer); virtual void UpdateVtkOverlay2D(BaseRenderer *renderer) = 0; virtual vtkActor2D* GetVtkActor2D(BaseRenderer *renderer) const = 0; /** \brief explicit constructor which disallows implicit conversions */ explicit VtkOverlay2D(); /** \brief virtual destructor in order to derive from this class */ virtual ~VtkOverlay2D(); private: /** \brief copy constructor */ VtkOverlay2D( const VtkOverlay2D &); /** \brief assignment operator */ VtkOverlay2D &operator=(const VtkOverlay2D &); }; } // namespace mitk #endif // VTKOVERLAY2D_H diff --git a/Modules/Overlays/mitkTextOverlay2D.cpp b/Modules/Overlays/mitkTextOverlay2D.cpp index 3139956af8..b36bb03e15 100644 --- a/Modules/Overlays/mitkTextOverlay2D.cpp +++ b/Modules/Overlays/mitkTextOverlay2D.cpp @@ -1,97 +1,116 @@ /*=================================================================== 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 "mitkTextOverlay2D.h" #include #include "vtkUnicodeString.h" #include +#include mitk::TextOverlay2D::TextOverlay2D() { mitk::Point2D position; position[0] = position[1] = 0; SetPosition2D(position); SetOffsetVector(position); } mitk::TextOverlay2D::~TextOverlay2D() { } mitk::Overlay::Bounds mitk::TextOverlay2D::GetBoundsOnDisplay(mitk::BaseRenderer *renderer) const { LocalStorage* ls = this->m_LSH.GetLocalStorage(renderer); mitk::Overlay::Bounds bounds; bounds.Position = ls->m_TextActor->GetPosition(); double size[2]; ls->m_TextActor->GetSize(renderer->GetVtkRenderer(), size); bounds.Size[0] = size[0]; bounds.Size[1] = size[1]; return bounds; } void mitk::TextOverlay2D::SetBoundsOnDisplay(mitk::BaseRenderer *renderer, const mitk::Overlay::Bounds& bounds) { vtkSmartPointer actor = GetVtkActor2D(renderer); actor->SetDisplayPosition(bounds.Position[0],bounds.Position[1]); } + mitk::TextOverlay2D::LocalStorage::~LocalStorage() { } mitk::TextOverlay2D::LocalStorage::LocalStorage() { m_TextActor = vtkSmartPointer::New(); + m_TextProp = vtkSmartPointer::New(); + m_STextActor = vtkSmartPointer::New(); + m_STextProp = vtkSmartPointer::New(); + m_TextActor->SetTextProperty( m_TextProp ); + m_STextActor->SetTextProperty( m_STextProp ); + m_Assembly = vtkSmartPointer::New(); + m_Assembly->AddPart(m_STextActor); + m_Assembly->AddPart(m_TextActor); } void mitk::TextOverlay2D::UpdateVtkOverlay2D(mitk::BaseRenderer *renderer) { LocalStorage* ls = this->m_LSH.GetLocalStorage(renderer); if(ls->IsGenerateDataRequired(renderer,this)) { - vtkSmartPointer prop = vtkSmartPointer::New(); float color[3] = {0.0,1.0,0.0}; float opacity = 1.0; GetColor(color,renderer); GetOpacity(opacity,renderer); - prop->SetColor( color[0], color[1], color[2]); - prop->SetFontSize(GetFontSize()); - prop->SetOpacity(opacity); + ls->m_TextProp->SetColor( color[0], color[1], color[2]); + ls->m_STextProp->SetColor( 0,0,0 ); + ls->m_TextProp->SetFontSize(GetFontSize()); + ls->m_TextProp->SetOpacity(opacity); + ls->m_STextProp->SetFontSize(GetFontSize()); + ls->m_STextProp->SetOpacity(opacity); bool drawShadow; GetBoolProperty( "drawShadow", drawShadow ); - prop->SetShadow( drawShadow ); - - int offset[2] = {1, -1}; - prop->SetShadowOffset( offset ); + ls->m_TextProp->SetShadow( false ); + ls->m_STextProp->SetShadow( false ); + ls->m_STextActor->SetVisibility(drawShadow); ls->m_TextActor->SetInput( GetText().c_str() ); - ls->m_TextActor->SetTextProperty( prop ); + ls->m_STextActor->SetInput( GetText().c_str() ); + ls->m_TextActor->SetPosition(GetPosition2D(renderer)[0]+GetOffsetVector(renderer)[0], GetPosition2D(renderer)[1]+GetOffsetVector(renderer)[1]); + ls->m_STextActor->SetPosition(GetPosition2D(renderer)[0]+GetOffsetVector(renderer)[0]+1, GetPosition2D(renderer)[1]+GetOffsetVector(renderer)[1]-1); ls->UpdateGenerateDataTime(); } } +vtkProp *mitk::TextOverlay2D::GetVtkProp(mitk::BaseRenderer *renderer) const +{ + LocalStorage* ls = this->m_LSH.GetLocalStorage(renderer); + return ls->m_Assembly; +} + vtkActor2D* mitk::TextOverlay2D::GetVtkActor2D(BaseRenderer *renderer) const { LocalStorage* ls = this->m_LSH.GetLocalStorage(renderer); return ls->m_TextActor; } diff --git a/Modules/Overlays/mitkTextOverlay2D.h b/Modules/Overlays/mitkTextOverlay2D.h index 0d33441b11..34be208e4f 100644 --- a/Modules/Overlays/mitkTextOverlay2D.h +++ b/Modules/Overlays/mitkTextOverlay2D.h @@ -1,82 +1,92 @@ /*=================================================================== 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 TEXTOVERLAY2D_H #define TEXTOVERLAY2D_H #include #include #include #include "MitkOverlaysExports.h" class vtkTextActor; +class vtkPropAssembly; namespace mitk { /** \brief Displays text on the renderwindow */ class MitkOverlays_EXPORT TextOverlay2D : public mitk::VtkOverlay2D { public: class LocalStorage : public mitk::Overlay::BaseLocalStorage { public: /** \brief Actor of a 2D render window. */ vtkSmartPointer m_TextActor; + vtkSmartPointer m_TextProp; + + vtkSmartPointer m_STextActor; + + vtkSmartPointer m_STextProp; + + vtkSmartPointer m_Assembly; + /** \brief Timestamp of last update of stored data. */ itk::TimeStamp m_LastUpdateTime; /** \brief Default constructor of the local storage. */ LocalStorage(); /** \brief Default deconstructor of the local storage. */ ~LocalStorage(); }; mitkClassMacro(TextOverlay2D, mitk::VtkOverlay2D); itkFactorylessNewMacro(Self) itkCloneMacro(Self) virtual Overlay::Bounds GetBoundsOnDisplay(BaseRenderer *renderer) const; virtual void SetBoundsOnDisplay(BaseRenderer *renderer, const Bounds& bounds); protected: /** \brief The LocalStorageHandler holds all LocalStorages for the render windows. */ mutable mitk::LocalStorageHandler m_LSH; + vtkProp* GetVtkProp(BaseRenderer *renderer) const; virtual vtkActor2D* GetVtkActor2D(BaseRenderer *renderer) const; void UpdateVtkOverlay2D(mitk::BaseRenderer *renderer); /** \brief explicit constructor which disallows implicit conversions */ explicit TextOverlay2D(); /** \brief virtual destructor in order to derive from this class */ virtual ~TextOverlay2D(); private: /** \brief copy constructor */ TextOverlay2D( const TextOverlay2D &); /** \brief assignment operator */ TextOverlay2D &operator=(const TextOverlay2D &); }; } // namespace mitk #endif // TEXTOVERLAY2D_H